Monday, November 14, 2011

NS2: How add/implement a new protocol into ns2 network simulator

I have tried adding new protocol called "MyPing" using existing code of "ping" protocol. I have followed following procedure :

1. copy the ping.h & ping.cc to ns2-xx/apps and renamed it myping.h & myping.cc respectively.

2. Define MyPing Packet type in packet.h as:


a)       // insert new packet types here
          static const packet_t PT_MYPING = 62;
          static packet_t       PT_NTYPE = 63; // This MUST be the LAST one

b)         class p_info {  .........
              static bool data_packet(packet_t type) {
              ..................................
              (type) == PT_MYPING\
             -----------------------------
           static void initName()
           ------------------------------
           name_[PT_MYPING]="MyPing";
     //------------------------------------
           name_[PT_NTYPE]= "undefined";
          .....................................................


c)      #define DATA_PACKET(type) ( (type) == PT_TCP || \
            ...........................................
             (type) == PT_MYPING \
             ...........................................


3)  Define default value of MyPing agent in ns-default.tcl
    Agent/MyPing packet_size 64


4) Edit Makefile inside ns2-xx dir and add "apps/myping.o"  next to "apps/ping.o" 


5) make clean and then make


You may follow these links for more information related to implementation:
http://www.isi.edu/nsnam/ns/tutorial/nsnew.html
http://nile.wpi.edu/NS/

Thanks
--