Wednesday, May 30, 2012

Ixia tips


1.       Before create statistic view window, do not forget to create Group View to group the ports of interest.
2.       May need to clear the “Ownership” of the ports to start traffic

Some c tips


Right-sift 10 (>>10) means divide by 1024.
Left-shift 10(<<10) means times 1024.

To printf “%” sign
printf(“%%\n”);

Set up VNC


vncserver -geometry 2048x1024 :60
(or vncserver -geometry 2048x1024)
vncpasswd
Password:
Verify:

xterm


xterm -sb -sl 3000 -bg blue -fg white &
xterm -sb -sl 3000 -bg lightblue &
xterm -sb -sl 3000 -bg lightgreen &
xterm -sb -sl 3000 -bg pink &

How to launch Graphical vi manager

/usr/local/bin/vim -g -bg lightblue &

giga bytes


(Wiki)

The gigabyte is a multiple of the unit byte for digital information storage. The prefix giga means 109 in the International System of Units (SI), therefore 1gigabyte is 1000000000bytes.
Historically, the term has also been used in some fields of computer science and information technology to denote the gibibyte, or 1073741824 (10243 or 230) bytes. 

the International Electrotechnical Commission has been promoting the use of the term gibibyte for the binary definition. This position is endorsed by other standards organizations including the IEEE, the International Committee for Weights and Measures (CIPM) and the U.S.National Institute of Standards and Technology (NIST), but the binary prefixes have seen limited acceptance. The JEDEC industry consortium continues to recommend the IEEE 100 nomenclature of using the metric prefixes kilo, mega and giga in their binary interpretation for memory manufacturing designations.


Multiples of bytes
Name
(Symbol)
Value
Name
(Symbol)
Value
kilobyte (kB)
103
210
kibibyte (KiB)
210
megabyte (MB)
106
220
mebibyte (MiB)
220
gigabyte (GB)
109
230
gibibyte (GiB)
230
terabyte (TB)
1012
240
tebibyte (TiB)
240
petabyte (PB)
1015
250
pebibyte (PiB)
250
exabyte (EB)
1018
260
exbibyte (EiB)
260
zettabyte (ZB)
1021
270
zebibyte (ZiB)
270
yottabyte (YB)
1024
280
yobibyte (YiB)
280

Tuesday, May 22, 2012

Deletion of the node in link list

When Key found (current node is ptr)

next: ptr->next
previous: ptr->prev
previous's next: (ptr->prev)->next
next's previous (ptr->next)->prev


  • Create connection 

If the key is head,
1. set head to the next
2. set next's previous to null

If key is tail
1. set tail to the previous
2. set previous's next to null

If key is in the middle
1. set previous's next to next
2. set next's previous to previous


  • Disconnect the current node 

1. set current's next to null
2. set current's previous to null


  • Delete current node 

free(ptr);

Traversing link list


  • Get pointer of the list head to local ptr, and traverse while ptr is not NULL.
  • At least following are necessary:


#include <stdio.h>
#include <stdlib.h>

typedef struct node {
  int data;
  struct node *next;
  struct node *prev;
} NodeType;

NodeType *listHead=0, *listTail=0;

int listShow(void) {
    NodeType *ptr;
        
        ptr = listHead;

        if(ptr == 0) {
           // print "empty" and return 0;
        } 

        while (ptr) {
               printf("data = %d\n", ptr->data);
               ptr = ptr->next;
        }

    return 0;
}

cscope


Setup:
#! /bin/sh
rm cscope.files
find . -name "*.[c|h]" -print > cscope.files
/usr/bin/cscope

Usage:
cscope –d
TAB to move to lower area from upper area
Ctrl + d to exit

Monday, May 21, 2012

Link list: 3 steps of listAdd operation


 1. Allocate memory for the new element

                        - can be done in the add routine  

 2. Fill the structure data/prev/next fields for the new element

 3. Connect in the linklist as follows:


     Check listHead == 0 --> 1st elm --> both head and tail equal to the new elm
                                != 0  --> not 1st elm --> put in after tail. then this new elm become tail.




#include <stdio.h>
#include <stdlib.h> // for malloc

// minimum needed as follows:
typedef struct node {
  int data;
  struct node *next;
  struct node *prev;
} NodeType;

NodeType *listHead=0, *listTail=0; // this is convenient


int listAdd(int newData) {
    NodeType *newNode;

    newNode = (NodeType *) malloc(sizeof(NodeType));
   // TBD check NULL and return if so
    newNode->data = newData;
    newNode->next = 0;
    newNode->prev = 0;

    if(listHead == 0) {
       listHead = newNode;
       listTail = newNode;
       printf("1st node added (%d)\n", listHead->data);
       return 0;
    }

    listTail->next = newNode;
    newNode->prev = listTail;
    // do not forget to set new listTail
    listTail = listTail->next;

    return 0;
}

Function pointer


FORMAT:
int realFunc(<params>) { return 0; }
int (*funcName)(<params>);
funcName = realFunc; 

EXAMPLES:
int lbkStubFunc(int port, int mode) { return 0; }

int (*drv_eth_port_set_loopback)(int port, int mode) = lbkStubFunc;

or
drv_eth_port_set_loopback = lbkStubFunc;


FORMAT using typedef: 
Int stub(<API interface>) { return 0; }
typedef int (*FUNCPTR) (<API interface>);

FUNCPTR tmp;
tmp = (FUNCPTR) stub;

Putting 4 bytes on the location in the buf


#include <stdio.h>
#include <string.h>

// Experiment (Linux)
// Putting 4 bytes on the location in the buf
// Getting 4 bytes from the char buf to uint32

#define DATA32 0x1234abcd;
int main(void) {
    char *ptr;
    char buf[16];
    int i;
    unsigned int value;

    memset((char *)buf, 0, 16);
    ptr = buf;

    // put
    *(unsigned int *) ptr = DATA32;

    printf("*ptr     = 0x%x\n", *ptr);
    printf("*(ptr+1) = 0x%x\n", *(ptr+1));
    printf("*(ptr+2) = 0x%x\n", *(ptr+2));
    printf("*(ptr+3) = 0x%x\n", *(ptr+3));


    for(i=0; i<16; i++) {
        printf("buf[%d]: 0x%x\n", i, buf[i]);
    }

    // get
    value = *(unsigned int *) ptr;

    printf("value = 0x%x\n", value);



    return 0;
}

/*****************************
Output
#[600]a.out
*ptr     = 0xffffffcd
*(ptr+1) = 0xffffffab
*(ptr+2) = 0x34
*(ptr+3) = 0x12
buf[0]: 0xffffffcd
buf[1]: 0xffffffab
buf[2]: 0x34
buf[3]: 0x12
buf[4]: 0x0
buf[5]: 0x0
buf[6]: 0x0
buf[7]: 0x0
buf[8]: 0x0
buf[9]: 0x0
buf[10]: 0x0
buf[11]: 0x0
buf[12]: 0x0
buf[13]: 0x0
buf[14]: 0x0
buf[15]: 0x0
value = 0x1234abcd
******************************/

Saturday, May 19, 2012

Thread Safe?


"Every function that uses files in some way. This  includes printf, scanf, getchar, and putchar (unsafe). The functions sprintf and  sscanf are not included (safe)." They (former) need mutex in a certain way to serialize these operations. 

  • Thread(or task) is an entity in multi-tasking and they can share memory (global variable) with mutex mechanism. / threads are under the same application.
  • An application (process) can launch multiple threads.
  • Process is a standalone self-contained application and it "cannot" share the global variables. (They run on the different contexts -  属性 ) They can only communicate thru IPC channel.
  • Multiple processes can run on a CPU.



Friday, May 18, 2012

C String Lib Reference


Vlan setting for Ixia

  • Check Vlan table
#sh vlan 
Codes: * - Default VLAN, G - GVRP VLANs
Q: U - Untagged, T - Tagged
x - Dot1x untagged, X - Dot1x tagged
G - GVRP tagged, M - Vlan-stack
NUM Status Description Q Ports
* 1 Inactive
2 Inactive U Te 5/0,3
3 Inactive U Te 5/1-2
  • Change to L2 mode
#conf
(conf)#int vlan [entry id]
(conf)#int vlan 4
FORMAT: (conf-if-vl-4)#int rang te [slot] /[port] – [port]
(conf-if-vl-4)#int rang te 10/0 - 3
(conf-if-range-te-10/0-3)#no shut
(conf-if-range-te-10/0-3)#sw
03:16:50: %RPM0-P:CP %IFMGR-5-ACTIVE: Changed Vlan interface state to active: Vl 1
(conf-if-range-te-10/0-3)#exit
  • Add a new entry to Vlan table
(conf)#int vlan [id]
(conf)#int vlan 4
(conf-if-vl-4)#untag ten 10/0
03:17:38: %RPM0-P:CP %IFMGR-5-ACTIVE: Changed Vlan interface state to active: Vl 4
(conf-if-vl-4)#untag ten 10/3
(conf-if-vl-4)#exit
  • Show Vlan Table
(conf)#exit
#03:18:07: %RPM0-P:CP %SYS-5-CONFIG_I: Configured from console by console
#sh vlan
Codes: * - Default VLAN, G - GVRP VLANs
Q: U - Untagged, T - Tagged
x - Dot1x untagged, X - Dot1x tagged
G - GVRP tagged, M - Vlan-stack
NUM Status Description Q Ports
* 1 Active U Te 10/1-2
2 Inactive U Te 5/0,3
3 Inactive U Te 5/1-2
4 Active U Te 10/0,3
  • Increase MTU
#conf
FORMAT: (conf)#int range ten  [slot]/[port]  - [port]   // Need space -
(conf)#int range ten 10/0 - 3
(conf-if-range-te-10/0-3)#mtu 9252
(conf-if-range-te-10/0-3)#exit
(conf)#exit
  • Check line rate
#sh int tengiga | grep line-rate|TenGi
#sh int tengiga 10 | grep line-rate|TenGi
TenGigabitEthernet 10/0 is up, line protocol is up
Input 9956.00 Mbits/sec, 248909 packets/sec, 99.90% of line-rate
Output 9956.00 Mbits/sec, 248899 packets/sec, 99.90% of line-rate
TenGigabitEthernet 10/1 is up, line protocol is up
Input 9956.00 Mbits/sec, 248898 packets/sec, 99.90% of line-rate
Output 9956.00 Mbits/sec, 248909 packets/sec, 99.90% of line-rate
TenGigabitEthernet 10/2 is up, line protocol is up
Input 9956.00 Mbits/sec, 248909 packets/sec, 99.90% of line-rate
Output 9956.00 Mbits/sec, 248898 packets/sec, 99.90% of line-rate
TenGigabitEthernet 10/3 is up, line protocol is up
Input 9956.00 Mbits/sec, 248898 packets/sec, 99.90% of line-rate
Output 9956.00 Mbits/sec, 248909 packets/sec, 99.90% of line-rate
  • Delete an entry in Vlan table
#conf
(conf)#no int vlan [id]
(conf)#end

How to change pattern in Ixia







  • Before create statistic view window, do not forget to create Group View to group the ports of interest.
  • May need to clear the “Ownership” of the ports to start traffic



(Menu) Stream Static View
In StatView window
Column B: mouse right click
(Menu) Edit Stream è Pattern (Random/Fix/Repeating), Size (Random/Fix) – (in Frame tab) and Rate (100%) – (in Control tab)
Start/Stop traffic è need to select column
Takes time (5 minutes or so) to reach 100% (99%) line rate

Before create statistic view window, do not forget to create Group View to group the ports of interest.
May need to clear the “Ownership” of the ports to start traffic