Monday, February 14, 2011

Exchanging Cross-layer information in NS2

I used this document to achieve cross-layer exchange of info in my wireless simulation in ns2. As an example, the routing layer and mac layer will be considered. This piece of code was based on the posts on the link below, but if you copy paste the code, there will be errors, and your simulation will not run. I made some corrections on the syntax and made it work in ns2.34.

http://jsun74.blogspot.com/2010/10/cross-layer-design-in-ns2-how-can.html

the author above requests that these sites be referred to instead:

http://blog.chinaunix.net/u3/94593/showart_2199303.html
http://www.baisi.net/thread-2471888-1-2.html

1. Accessing MAC Layer from Routing Layer.

Here the 802.11 mac and AODV routing protocol are used as an example:

a) Include in the aodv.h header file the mac-802_11.h file

# Include "mac/mac-802_11.h"

then, declare a mac object within the aodv class

Mac802_11 * this_mac;

b) Add the following code in the command () function in aodv.cc

int

AODV:: command (int argc, const char * const * argv) {
. . .
. . .
else if (argc == 3) {
if (strcmp (argv [1], "index") == 0) {
index = atoi (argv [2]);
return TCL_OK;
}
else if (strcmp (argv [1], "access-mac") == 0) {
this_mac = (Mac802_11 *) TclObject:: lookup (argv [2]);
if (this_mac == 0) {
fprintf (stderr, "Agent: %s lookup %s failed. \ n", argv [1], argv[2]);
return TCL_ERROR;
}
else {
printf ("This node's mac bss_id: %d \ n", this_mac-> bss_id ());
return TCL_OK;
}
}
. . .
. . .
}

c) Sample tcl script

# get the routing layer protocol
set rt ($i) [$ node_ ($ i) agent 255]
# establish access path to the mac
$rt ($i) acess-mac [$ node_ ($ i) set mac_ (0)]

d) this_mac can now be used from aodv to access 802.11 mac information

other method exists, that would be my topic on my succeding posts.