Friday 29 March 2013

Energy Model in NS2

The energy model is used through the node-config API. An example is shown as follows

      $ns_ node-config -adhocRouting DumbAgent \
    -llType $opt(ll) \
    -macType Mac/SMAC \
    -ifqType $opt(ifq) \
    -ifqLen $opt(ifqlen) \
    -antType $opt(ant) \
    -propType $opt(prop) \
    -phyType $opt(netif) \
    -channelType $opt(chan) \
    -topoInstance $topo_ \
    -agentTrace ON \
    -routerTrace ON \
    -macTrace ON \
    -energyModel $opt(energymodel) \
    -idlePower 1.0 \
    -rxPower 1.0 \
    -txPower 2.0 \
             -sleepPower 0.001 \
             -transitionPower 0.2 \
             -transitionTime 0.005 \
    -initialEnergy $opt(initialenergy)
The following parameters are newly added:
-sleepPower: power consumption (Watt) in sleep state
-transitionPower: power consumption (Watt) in state transition from sleep to idle (active)
-transitionTime: time (second) used in state transition from sleep to idle (active)



Analysis through Trace files


In addition to the total energy, now users will be able to see the energy consumption in different states at a given time. Following is an example from a trace file on energy.

 [energy 979.917000 ei 20.074 es 0.000 et 0.003 er 0.006]
The meaning of each item is as follows:
energy: total remaining energy
ei: energy consumption in IDLE state
es: energy consumption in SLEEP state
et: energy consumed in transmitting packets
er: energy consumed in receiving packets

Sample TCL script : Click Here

Rate Control Protocol patch in NS2

RCP's patch for NS2 is available on the above link for NS-2.28 and NS-2.30 versions.

Follow the steps given below to apply RCP's patch to NS-2.35:

1. Download ns-allinone-2.35.tar.gz

2. Download rcp-ns2-35.patch

3. Unzip ns-allinone-2.35.tar.gz. You will get a folder named ns-allinone-2.35

4. Paste the downloaded RCP patch in the above mentioned folder.

5. Give the following command:

patch -p1 < rcp-ns2-35.patch

6. Go in ns-allinone-2.35 via terminal and give the following command (It is always recommended to be in root mode while giving the below command):

./install

If you already have an installed copy of ns-allinone-2.35, then follow the steps given below to apply the RCP patch:

1. Paste the downloaded RCP patch in ns-allinone-2.35 directory.

2. Give the following command:

patch -p1 < rcp-ns2-35.patch

3. Go in ns-allinone-2.35/ns-2.35 directory and give the following commands:

./configure
make clean
make
make install

You are done with it!

Sample TCL Scripts:
Use the sample TCL Scripts provided on the official website of RCP. Following is the link:

http://yuba.stanford.edu/rcp/#implementation

rcp-ns-2.30.tar.gz must be downloaded from the above link. It contains a folder named "example-tcl-files" which contains the sample TCL Scripts.

A Note on the installation of ns-allinone-2.35:
You may or may not get installation errors depending on which version of gcc is used in your OS. With Ubuntu 10.04 (gcc 4.4.3), the installation procedure did not give any error. However, with later versions of Ubuntu there are chances that you may get a few errors.

Ant Colony Installation in NS2

 

Wednesday 27 March 2013

NS2 Simulation Environment Setup


NS2 Performance Metrics(throughput ,packetloss,end-to-end delay,nrl)


  • Calculating packet delivery ratio 
  • Calculating End-to-end Delay
  • Calculating Throughput
  • Calculating Normalized routing load









Tags: Throughput for AODV, packet loss for AODV , jitter for AODV, throughput for AODV,DSR, end to end delay download, throughput formula

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

TORA installation in NS2

1 step: patch TORA code

Open a bash shell (click here to watch how) and type at prompt:
su
cd /usr/share/ns-2.30/tora/
mv tora.h tora.old.h mv tora.cc tora.old.cc wget http://wpage.unina.it/marcello.caleffi/ns2/tora.cc
wget http://wpage.unina.it/marcello.caleffi/ns2/tora.h
Then you should have the patched file in the TORA folder

2 step: recompile ns

Open the bash shell and type at prompt:
su
cd /usr/share/ns-2.30/
make make install

Saturday 16 March 2013

Multicast Routing protocols in NS2

Multicast Routing protocols


Below mentioned in the tree structure of Multicast routing protocols . By Default NS2 provides only Unicast protocols in the ns-allinone suite but one can install mulitcast protocol in NS2 as a patch . 


Simulation Functionalities in NS2