Monday 18 March 2013

Simulating TORA in NS2

Step-1: 


To resolve the issue,Implement PORT-DEMUX in command function of “tora.cc” file.


Modified Command function-
   
int
toraAgent::command(int argc, const char*const* argv)
{
    if(argc == 2) {
        Tcl& tcl = Tcl::instance();

        if(strncasecmp(argv[1], "id", 2) == 0) {
            tcl.resultf("%d", index);
            return TCL_OK;
        }
    }
    else if(argc == 3) {

        if(strcmp(argv[1], "log-target") == 0 || strcmp(argv[1], "tracetarget") == 0 ) {
            logtarget = (Trace*) TclObject::lookup(argv[2]);
            if(logtarget == 0)
                return TCL_ERROR;
            return TCL_OK;
        }
        else if(strcmp(argv[1], "drop-target") == 0) {
                int stat = rqueue.command(argc,argv);
            if (stat != TCL_OK) return stat;
                    return Agent::command(argc, argv);
        }
        else if(strcmp(argv[1], "if-queue") == 0) {
            ifqueue = (PriQueue*) TclObject::lookup(argv[2]);
            if(ifqueue == 0)
                return TCL_ERROR;
            return TCL_OK;
        }
        else if(strcmp(argv[1], "imep-agent") == 0) {
            imepagent = (imepAgent*) TclObject::lookup(argv[2]);
            if(imepagent == 0)
                return TCL_ERROR;
            imepagent->imepRegister((rtAgent*) this);
            return TCL_OK;
        }  /*** Extra code to implement port demux ***/
        else if (strcmp(argv[1], "port-dmux") == 0) {
                dmux_ = (PortClassifier *)TclObject::lookup(argv[2]);
            if (dmux_ == 0) {
                fprintf (stderr, "%s: %s lookup of %s failed\n", __FILE__, argv[1], argv[2]);
                return TCL_ERROR;
            }
            return TCL_OK;
            }
    }
    return Agent::command(argc, argv);
}


Also edit tora.h file, add the header classifier/classifier-port.h at the first portion and protected: PortClassifier *dmux_; at the end of this file to add the support for port demuxing.

First portion of tora.h file for my case looks like-
   
#include <tora/tora_dest.h>
#include <classifier/classifier-port.h>

LIST_HEAD(td_head, TORADest);

End portion of tora.h file for my case looks like-

   
    void        logNextHopChange(TORADest *td);
    void        logNbDeletedLastDN(TORADest *td);
    void        logToraDest(TORADest *td);
    void        logToraNeighbor(TORANeighbor *tn);
    
protected:
    /* for passing packets up to agents */
    PortClassifier *dmux_;
};

#endif /* __tora_h__ */

Step-2: 


Now simulation script for TORA protocol works fine but the simulation enters into a eternal infinite loop. To avoid this eternal loop, modify imep.cc file.

Fix the line (504 no line in gedit) in ns-2.34/imep/imep.cc which reads
   
rexmitTimer.start(rexat - CURRENT_TIME);</code>

If rexat – CURRENT_TIME is 0, then the same function is called immediately without increasing the simulation time, creating an eternal loop. I would have replaced the line with the following lines:

if (rexat-CURRENT_TIME<0.000001) // Preventing eternal loop.
rexmitTimer.start(0.000001);
else
rexmitTimer.start(rexat - CURRENT_TIME);


Or download the modified tora.cc and tora.h file and replace the content of original files of tora with the downloaded file’s content if you face any problem to do the above modifications.

Step-3: 


Recompile the ns-2.34 with make command. Its better to run “make clean”  command before running “make” command so that all the edited file take the effect.

   
byuvraj@byuvraj-laptop:~$ cd /home/byuvraj/ns-allinone-2.34/ns-2.34
byuvraj@byuvraj-laptop:~$ make clean
byuvraj@byuvraj-laptop:~$ make

Now Everything is Ready. You can run simulation script for TORA routing protocol in NS2.

                                Download

1 comment:

  1. can u give me a sample code for sending & receiving user defined application data over AODV in manets

    ReplyDelete