Feb 15, 2006

The next big step...adding a new protocol

Well, you can't really do much with NS-2 if you would just like to play around with existing protocol. I guess the next big step is to test your very own protocol and see it runs in Ns-2.

To start with adding new protocol, there is an online tutorial available (here).

To begin adding new protocol, it's advised that we are familiar with Ns-2 and some C++ knowledge. (If any problem arises, refer back to "ns Notes and Documentation" (now renamed ns Manual).

I will follow the example given on the site :

Tips from the forum :

1. Make sure your protocol agent same as the ping example given in the ns tutorials. Or you can follow one more easy way i.e. look at the codings for dsdv protocol and copy the important functionality of the coding. (You will need to define command and recv functions at least).

2. Make your own directory (say myproto) in the same directory where the directory named dsdv is residing. Put your coding (say myproto.cc and myproto.h) in the directory 'myproto'.

3. Now edit Makefile and put the things in the same way as for dsdv in there.

4. Edit file ~ns/tcl/lib/ns-lib.tcl. In this file search DSDV with the first occurrence of dsdv you will see code like source mobility/dsdv.tcl. At this moment you
don't need to write separate tcl file for your protocol therefore ignore it and go the second occurrence of dsdv in the file ~ns/tcl/lib/ns-lib.tcl and you will see a code section having switch-case control. Here just copy one more body like DSDV. There is only one line of code in the body of DSDV case. Copy the same and modify it for your protocol.

For your protocol it will look like this :
DSDV {
//coding for dsdv (calling a function like dsdv-create-node)
}
MyProto {
//coding for your protocol (calling your function)
}
DSR {
//
}

remember to put space between 'MyProto' and '{' otherwise it won't work. Now go to the third occurrence of DSDV and you will see the coding which is called from the body in switch case. Here is the definition of the func.

Define your function in the same way as for dsdv is there and comment the line containing call for dsdv-start-up because at this moment your protocol is not having any such functionality.

If you will omit 4th step you will get error message like "Wrong node routing Protocol".

5. run make in ~ns directory.

6. Make a tcl script for testing your protocol and you are done.
(extracted from here)

2 comments:

Unknown said...

Now i ve done all these 5 steps to implement fixed routing and the out files
got created..

Now in the tcl script is it enough that i give

set opt(rt) FIXRT
set val(rp) FIXRT
$ns rtproto FIXRT

or should i include some more lines ?? because if i jus give this it doesnt use
my protocol, it only uses its default DSDV..

Please do help me in this regard..

RAM said...

hi abhinaya,

ram here, am also newbie for ns2. am m.tech student, doing project on ns2.

u need to change the routing protocol name to ur protocol.