Thursday, June 7, 2012

ELF


Executable and Linkable Format (by Wiki)
In computing, the Executable and Linkable Format (ELF, formerly called Extensible Linking Format) is a common standard file format for executablesobject codeshared libraries, and core dumps. First published in the System V Application Binary Interface specification,[1] and later in the Tool Interface Standard,[2] it was quickly accepted among different vendors of Unix systems. In 1999 it was chosen as the standard binary file format for Unix and Unix-like systems on x86 by the 86open project.

Wednesday, June 6, 2012

Where and how to set vi default configuration


In ~/.exrc
      set directory=/tmp
      set cindent
      set number

WRED


Term WRED = Weighted Random Early Detection (algorithm)

(Wiki) Weighted random early detection (WRED) is a queue management algorithm with congestion avoidance capabilities.[1] It is an extension to random early detection (RED) where a single queue may have several different queue thresholds. Each queue threshold is associated to a particular traffic class.
For example, a queue may have lower thresholds for lower priority packet. A queue buildup will cause the lower priority packets to be dropped, hence protecting the higher priority packets in the same queue. In this way quality of service prioritization is made possible for important packets from a pool of packets using the same buffer.[2]
It is more likely that standard traffic will be dropped instead of higher prioritized traffic.

Functional Description
WRED proceeds in this order when a packet arrives:
§  Calculation of the average queue size.
§  The arriving packet is queued only if the average queue size is below the minimum queue threshold.
§  Depending on the packet drop probability the packet is either dropped or queued if the average queue size is between the minimum and maximum queue threshold.
§  The packet is automatically dropped if the average queue size is greater than the maximum threshold.

Friday, June 1, 2012

Delete a node from link list


int listDel(int delData) {
    NodeType *ptr;

    ptr = listHead;
    while (ptr) {
         if(ptr->data == delData) {
            printf("data = %d key found\n", ptr->data);
            if(ptr == listHead) {
               printf("This is a head\n");
               if(ptr->next) { 
                  listHead = ptr->next; 
                  (ptr->next)->prev = 0;
               }
               else {
                  listHead = 0;
               }
            }
            else if(ptr == listTail) {
               printf("This is a tail\n");
               listTail = ptr->prev;
               (ptr->prev)->next = 0;
            }
            else {
               printf("This is a middle\n");
               // connect previous to next
               (ptr->prev)->next = ptr->next;
               // connect next to previous
               ptr->next = (ptr->prev)->next;
            }

            // disconnect
            ptr->prev = 0;
            ptr->next = 0;
            free(ptr); // delete
            break;
         }
         ptr = ptr->next;
    }
    return 0;
}

int main() {
    listAdd(1);
    listAdd(2);
    listAdd(3);
    listAdd(4);
    listAdd(5);
    listAdd(6);
    listShow();
    printf("\n");
    listDel(1);
    listDel(6);
    listDel(4);
    listDel(7);
    listDel(2);
    printf("\n");
    listShow();
   
    return 0;
}


1st node added (1)
data = 1
data = 2
data = 3
data = 4
data = 5
data = 6

data = 1 key found
This is a head
data = 6 key found
This is a tail
data = 4 key found
This is a middle
data = 2 key found
This is a head

data = 3
data = 5

Free C compiler for Windows

http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express

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
******************************/