Showing posts with label wireless. Show all posts
Showing posts with label wireless. Show all posts
, , , ,

Installation of ns3 in Windows 10 and Windows 11 OS using WSL (Windows Subsystem for Linux)

This post shows how to install ns-3.33 in Windows 10 through WSL (Windows Subsystem for Linux)
This posts works for Windows 11 also (I have tested it on a Windows 11 ISO and it works the Same way as mentioned in the following post.)
This post will work for ns-3.3x version.
Prerequisites:
Install Windows Subsystem for Linux with GUI: Please refer the following video 



System Information:
OS used: Windows 10 and WSL (Ubuntu 20.04)
GUI: XServer for Windows
NS3 Version: ns-3.33

See the following complete video on how to install ns3 in Windows 10


Step 0 : Open XLaunch
Step 1 :  Open WSL using PowerShell and open it as Administrator

Command:/ wsl
$ xfce4-session

The GUI of Ubuntu Opens within Windows 10 OS.

Step 2 : Download ns3 from nsnam.org website through Mozilla Firefox browser

Step 3: Open a Terminal 
$ sudo apt update
$ sudo apt install build-essential autoconf automake libxmu-dev python3-pygraphviz cvs mercurial bzr git cmake p7zip-full python3-matplotlib python-tk python3-dev qt5-qmake qt5-default gnuplot-x11 wireshark

Step 4: Move the ns3 file from Downloads/ folder to Home folder (/home/pradeepkumar) and unzip it there itself, Right Click -- Extract Here

Step 5: Go to the terminal that is already open and issue the following commands 

$ cd 
$ cd ns-allinone-3.33/
$ ./build.py --enable-examples --enable-tests
It might take 10 to 20 minutes for installing, may be in between there might be errors as well. 

Once the installation over, check for the following command for the working of ns3.

$ cd ns-3.33
$ ./waf --run hello-simulator

Also check for first.cc file, move the file from ns-3.33/examples/tutorial. folder to ns-3.33/scratch folder

$ ./waf --run scratch/first
You should get 4 lines of output between the client and server interaction

Then you can try for NetAnim as well as per the video.
In the first.cc file, include the following lines so work for NetAnim
#include "ns3/netanim-module.h"

and the following line above the Simulator::Run() function

AnimationInterface anim("first.xml");
After the above changes, compile the file again using 

$ ./waf --run scratch/first
A file named first.xml would have created and it can be opened using NetAnim. To run NetAnim, try the following:
Open a new Terminal 
$ cd ns-allinone-3.33/netanim-3.108/
$./NetAnim

Open the first.xml file and you can check the output. 

Thanks are watching and please subscribe to my channel and share it to your friends....
, ,

TORA Protocol in NS-2.35 (NS2)

This post tells you how to enable the TORA (Temporally ordered routing Algorithm) protocol in Network Simulator 2 (ns-2.35)

TORA is a protocol in wireless adhoc networks that works with timing parameters. NS-2.35 comes with the TORA protocol by default but it has to be tweaked manually to make it run.
This post will help you to do that.

You can watch this video for detailed instructions:


Step 1: Generate a Scenario for TORA protoco using NS2 Scenario Generator NSG Software.
We have created a tcl file using NSG2.1.jar

$] java -jar NSG2.1.jar

Three files have to be modified
  • ~ns-2.35/tora/tora.cc
  • ~ns-2.35/tora/tora.h
  • ~ns-2.35/imep/imep.cc
There are various websites that tells you how to configure TORA by making changes to the above three files. 
Change 1: tora.h
In the tora.h file, go to the end of the File before the agent completes, include these two lines

#include <classifier/classifier-port.h>

protected:
PortClassifier *dmux_;

tora.h
Tora.h Change

Change 2: tora.cc
Open the tora.cc and include the following lines in the "int toraAgent::command(int argc, const char*const* argv) " function as indicated in the figure below.
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;
            }
tora
Tora.cc Change

Change 3: imep.cc
In the file imep.cc, change the following line 


rexmitTimer.start(rexat - CURRENT_TIME);

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

imep
IMEP Change

Step 3: 
We need to recompile ns2 using the command make from the folder ns-2.35/

Once the changes are made, Open the Terminal and go to ~ns-2.35 and execute the command  

prompt$] make 

Step 4: Run the tcl file now

$] ns TORA.tcl
This file is generated in Step 1

I will give all these files to you for your simulation.

Copy the tora.cc and tora.h file in your ns-2.35/tora folder

then copy the imep.cc file in to the ns-2.35/imep folder 

and then copy the TORA.tcl file in your home folder or any folder.

Then do the compilation $] make 
and then run the TORA.tcl file using $] ns TORA.tcl


Thanks for watching. Please subscribe and click the bell button for further updates.


TORA
TORA Protocol Animation


T S Pradeep Kumar
, , , , ,

AODV simulation in NS2 (Part 1) - NS2 Tutorial # 11

Lecture 11 - AODV - Part 1
Todays topic on AODV protocol

AODV - Adhoc Ondemand Distance Vector
the location of the source code for Aodv is in the folder

~ns-2.35/aodv/

My suggestion is
Always try to understand the header file first.. later you can move on to source file (.cc files)
I will go through aodv.h file first and then aodv.cc file next....
let me explain....

I should know where my work is residing, for example in AODV

should I work on


  • Routing Table
  • Energy Management
  • Quality oif Service
  • Link Failure
  • Logs or tracing
  • Neighbour management
  • Attacks (Black hole, gray hole, etc...)
  • Security

so prefer to stay at the header files first...
Now the action begins.
how do i modify the AODV protocol as per my small piece of algorithm...
I would like to print the nodes that are forwarding the packets.
Two information will be recorded in a text file separately..

Name of the file: aodv_output.dat data recorded will be: forwarded packet, node index (node number).

For this, please open the aodv.h and aodv.cc file.

Step 1:
add a variable called as pkt_count as an integer in protected scope inside the aodv.h file.

int pkt_count;
Step 2:

Initialize pkt_count with a value 0 in the aodv.cc file (preferably in the constructor)

pkt_count=0;

Step 3:

Since I am going to get the packet counts in a file, i need to create a file pointer. But first let me get the data in the terminal itself. later i will create it in the file.

Also, only during the forwarding of packets, i am going to get the count, so my code will be running inside the forward() function.

Add the following line to the forward() function of aodv.cc

printf("I am packet no %d and from node number %d\n",pkt_count++,index);


Step 4:
Now recompile ns2 using the command make

$] cd ns-allinone-2.35/ns-2.35/

$] make


Once, there are no errors, your code is compiled successfully....

Then, run any wireless tcl script that has the routing protocol as AODV.
I am running AODV.tcl file that was generated in LEcture number 9.

to run that just
$] ns AODV.tcl

$] nam AODV.nam

I need to get this output in a file called as aodv_output.dat
How to do that... Again the same step open, aodv.cc and aodv.h

Declare a file pointer inside the aodv.h file

FILE *fp;

Initialize this file pointer in aodv.cc constructor

fp = fopen ("aodv_output.dat","w");

include the following line in the forward() function of aodv.cc


fprintf(fp,"I am packet no %d and from node number %d\n",pkt_count++,index);

and run the AODV.tcl file and check for a file called aodv_output.dat is created in the same folder where the AODV.tcl is residing.


Thank you for watching..
To download the codes, visit https://www.nsnam.com

and share and subscribe to my youtube channel
Youtube.com/tspradeepkumar
Stay Tuned for more lectures...

T S Pradeep Kumar
, , , , ,

Comparison of AODV, DSR and DSDV in ns2 - NS2 Tutorial # 9

Performance Evaluation of Adhoc Routing Protocols using NS2

Very old Project as well as a topic, but this will give an idea of how to compare multiple protocols or agents.

1 hour Project*

See the video for the full project


* - you should know ns2 already
should know how to write AWK scripts
Should know about energy model
Should know about wireless networks and protocols

To know the above concepts, check my Ns2 Lecture series videos in Youtube and come back to this video

Youtube.com/tspradeepkumar

AODV, DSDV and DSR
AODV - Adhoc On Demand Distance Vector
DSDV - Destination Sequenced Distance Vector
DSR - Dynamic Source Routing

Lcture 8 - AWK Scripts
Average throughput
Instant throughput
Residual Energy
Packet Delivery ratio

To download the source codes, visit https://www.nsnam.com

Going inside the project

Step 1:
Use the same network and same disntace, energy, etc when you compare multiple protocols

Step 2:
Generate Scenario, You need not write the code in TCL (of course you can modify).
We use NSG for creating a network. Refer my lecture series on NSG (NS2 scenario Generator)

$] java -jar NSG2.1.jar

As seen in the GUI, Create a network (for example with 17 nodes) and two nodes are moving
with a interference of 550 metres and tranmission range of 250metres.

Create a network with a AODV protocol

Create two copies of AODV protocol and name it as DSR.tcl and DSDV.tcl

$] cp AODV.tcl DSR.tcl
$] cp AODV.tcl DSDV.tcl


Three files are ready now called
AODV.tcl, DSR.tcl, DSDV.tcl

and now these three files using ns filename.tcl

$] ns AODV.tcl
$] ns DSR.tcl
$] ns DSDV.tcl
I have the three files and got 9 files namely
AODV.tr, DSDV.tr and DSR.tr
AODV.nam, DSDV.nam and DSR.nam

There is no energy coding, i need to implement that

DSR does not obey the queue model as specified for AODV,
Queue/DropTail/PriQueue  is not supported by DSR, we have to go for CMUPriQueue

DSR supports this queue called CMUPriQueue, it should reflect in the tcl code.

All the tcl files run successfully. now we are going to analyse the results and sometime plot the graphs too.

we have already written AWK scripts for Average throughput, instant throughput , residual energy and packet delivery ratio

average_throu.awk
instant_throu.awk
pdr.awk
resenergy.awk

To run these scripts we need awk interpreter as below

$] gawk -f resenergy.awk AODV.tr
$] gawk -f resenergy.awk DSDV.tr
$] gawk -f resenergy.awk DSR.tr

Whenvern you compare multiple protocols
Use three different sets of nodes

Small number of nodes (10 nos)
Medium number of nodes (20 to 30 nos)
Huge number of nodes (upto 100)

beyond 100 nodes, ns2 suffers.

in this case, we did it for 17 nodes only. You can do the rest.
So we are coming to the conclusion

Comparing protocols needs
1. Three minimum protocols (AODV, DSR, DSDV)
TCP, TCPReno, TCPVegas, FullTCP
2. number of nodes (small, medium and huge) as mentioned above, 10 nodes, 30 nodes, 100 nodes
3. Atleast three performance metrics, in this case we have, average throghput, instant througput, residual energy and packet delivery ratio
4. Strong knowledge on the protocols
5. AWK scripts to be known or atleast to be downloaded.
6. Design the network rather than coding the network, use scenario generators for ns2.

Our project is complete!!! Stay tuned
Share and subscribe my youtube channel

Youtube.com/tspradeepkumar
nsnam.com
pradeepkumar.org

pradeepkumarts@gmail.com

Thank you !!! More lectures to come!!!!

Download the TCL Codes from here
https://drive.google.com/open?id=1B4HN87qBg8Pc5LpfWq6ldOSe33ZYtv-6

T S Pradeep Kumar
, , , ,

Wireless network Coding in ns2 - NS2 Tutorial # 5

This post shows you how to write TCL code for Wireless simulations in ns2. It also explains the various aspects of wireless network.

It is part of a lecture series in network simulator 2.

The following image is shown for explanation

Wireless Networks
Wireless Networks
Download the Source code for Wireless Networks

#Example of Wireless networks
#Step 1 initialize variables
#Step 2 - Create a Simulator object
#step 3 - Create Tracing and animation file
#step 4 - topography
#step 5 - GOD - General Operations Director
#step 6 - Create nodes
#Step 7 - Create Channel (Communication PATH)
#step 8 - Position of the nodes (Wireless nodes needs a location)
#step 9 - Any mobility codes (if the nodes are moving)
#step 10 - TCP, UDP Traffic
#run the simulation

#initialize the variables
set val(chan)           Channel/WirelessChannel    ;#Channel Type
set val(prop)           Propagation/TwoRayGround   ;# radio-propagation model
set val(netif)          Phy/WirelessPhy            ;# network interface type WAVELAN DSSS 2.4GHz
set val(mac)            Mac/802_11                 ;# MAC type
set val(ifq)            Queue/DropTail/PriQueue    ;# interface queue type
set val(ll)             LL                         ;# link layer type
set val(ant)            Antenna/OmniAntenna        ;# antenna model
set val(ifqlen)         50                         ;# max packet in ifq
set val(nn)             6                          ;# number of mobilenodes
set val(rp)             AODV                       ;# routing protocol
set val(x) 500 ;# in metres
set val(y) 500 ;# in metres
#Adhoc OnDemand Distance Vector

#creation of Simulator
set ns [new Simulator]

#creation of Trace and namfile 
set tracefile [open wireless.tr w]
$ns trace-all $tracefile

#Creation of Network Animation file
set namfile [open wireless.nam w]
$ns namtrace-all-wireless $namfile $val(x) $val(y)

#create topography
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)

#GOD Creation - General Operations Director
create-god $val(nn)

set channel1 [new $val(chan)]
set channel2 [new $val(chan)]
set channel3 [new $val(chan)]

#configure the node
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-topoInstance $topo \
-agentTrace ON \
-macTrace ON \
-routerTrace ON \
-movementTrace ON \
-channel $channel1 

set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]

$n0 random-motion 0
$n1 random-motion 0
$n2 random-motion 0
$n3 random-motion 0
$n4 random-motion 0
$n5 random-motion 0

$ns initial_node_pos $n0 20
$ns initial_node_pos $n1 20
$ns initial_node_pos $n2 20
$ns initial_node_pos $n3 20
$ns initial_node_pos $n4 20
$ns initial_node_pos $n5 50

#initial coordinates of the nodes 
$n0 set X_ 10.0
$n0 set Y_ 20.0
$n0 set Z_ 0.0

$n1 set X_ 210.0
$n1 set Y_ 230.0
$n1 set Z_ 0.0

$n2 set X_ 100.0
$n2 set Y_ 200.0
$n2 set Z_ 0.0

$n3 set X_ 150.0
$n3 set Y_ 230.0
$n3 set Z_ 0.0

$n4 set X_ 430.0
$n4 set Y_ 320.0
$n4 set Z_ 0.0

$n5 set X_ 270.0
$n5 set Y_ 120.0
$n5 set Z_ 0.0
#Dont mention any values above than 500 because in this example, we use X and Y as 500,500

#mobility of the nodes
#At what Time? Which node? Where to? at What Speed?
$ns at 1.0 "$n1 setdest 490.0 340.0 25.0"
$ns at 1.0 "$n4 setdest 300.0 130.0 5.0"
$ns at 1.0 "$n5 setdest 190.0 440.0 15.0"
#the nodes can move any number of times at any location during the simulation (runtime)
$ns at 20.0 "$n5 setdest 100.0 200.0 30.0"

#creation of agents
set tcp [new Agent/TCP]
set sink [new Agent/TCPSink]
$ns attach-agent $n0 $tcp
$ns attach-agent $n5 $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 1.0 "$ftp start"

set udp [new Agent/UDP]
set null [new Agent/Null]
$ns attach-agent $n2 $udp
$ns attach-agent $n3 $null
$ns connect $udp $null
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$ns at 1.0 "$cbr start"

$ns at 30.0 "finish"

proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exit 0
}

puts "Starting Simulation"
$ns run




T S Pradeep Kumar
, , , ,

Network Simulator 2 - presentation Slides

I have gone across more than 80 institutions in the country to give hands on session, workshop, seminars related to network simulator 2. Mostly I will try different simulations, different models for simulation, etc.

But basically, every researcher/students needs some basics to get to know about ns2.

These slides make you understand the basics of ns2. Still in the country, there are so many universities uses ns2 as their simulated platform for the networking course, wireless networks course, etc. reading these slides make you know the basics of ns2.

These slides can be downloaded from my slideshare profile.

Introduction to Network Simulator 2



Installation of Network Simulator 2


Wired and Wireless Network Examples in ns2


OTCL and C++ Linkages in ns2


Recompiling Network Simulator 2




Mannasim for NS2

T S Pradeep Kumar
, , ,

SUMO, Open Street Maps and NS2 - A Real Traffic Simulation

SUMO is the Simulation of Urban mobility software that enables to simulate the road traffic. Open Street map (www.openstreetmap.org)  provides the xml based .osm file for any part of the world selected through their website. #openstreetmap

#SUMO can able to convert the osm file to its native xml file. The post tells you the simulation of a real traffic network and how it is ported to #ns2 for network animation and tracing.

Step 1: Prerequisites

  • SUMO to be installed - in my case I installed sumo this way 
sudo add-apt-repository pap:sumo/stable
sudo apt-get update
sudo apt-get install sumo sumo-doc sumo-tools

Also, Download the sumo source sumo-src-0.26.tar.gz from this link and unzip or untar it to the home directory (/home/pradeepkumar). There are some python files that are needed to generate random trips and to export xml files to tcl files. the commands sumo, sumo-gui will run only the graphical simulation.
Once the software is unzipped, set the SUMO_HOME in the environment, Open /home/pradeepkumar/.profile (for Linux Mint) and /home/pradeepkumar/.bashrc (for Ubuntu) and give this command (in my case the home is pradeepkumar, it might be different for you)
export SUMO_HOME=/home/pradeepkumar/sumo-0.26.0 

Step 2: Steps to create a Traffic

  1. Open browser and type http://www.openstreetmap.org and search a particular area and click export in the top. 
  2. click "Manually select an area" and select the area (as shown in the video below) and click export again (it will download a file called map.osm, rename this file as per your convenience)
  3. Open the terminal and type the commands one by one (assume my file name is guindy.osm, so i maintain the same file name guindy for all the xml files)
$] netconvert --osm-files guindy.osm -o guindy.net.xml

Now, copy the osmPolyconvert.typ.xml from the $SUMO_HOME/data/typemap/ and copy it to the folder where you put all the files. 


$] polyconvert --osm-files guindy.osm --net-file guindy.net.xml --type-file osmPolyconvert.typ.xml -o guindy.poly.xml



$] python $SUMO_HOME/tools/randomTrips.py -n guindy.net.xml -r guindy.rou.xml -e 100 -l

Now, create a new file (to be named as guindy.sumo.cfg) and paste the following lines 

 <configuration>
     <input>
         <net-file value="guindy.net.xml"/>
<route-files value="guindy.rou.xml"/>
         <additional-files value="guindy.poly.xml"/>
     </input>
<time>
<begin value="0"/>
<end value="100"/>
<step-length value="0.1"/>
</time>
 </configuration>

Now you can run the above using sumo-gui guindy.sumo.cfg (now you can see as per the following screenshot)
sumo
SUMO

, , , ,

LEACH protocol installation in ns2 (ns-2.35)

This post shows you the method to install the LEACH protocol developed by MIT called MIT-uAMPS which was developed in the year 2000. So you may face some problem in installing this protocol in recent Operating Systems.

I have tried to compile this protocol in ns-2.35 which was running under Ubuntu 14.04 64 bit OS
Here is the requirement before you proceed to install.
Assumptions:
Assuming that you have successfully installed ns-2.35 before you start compiling LEACH. If you need any help in installing ns2, refer this post. http://www.nsnam.com/2014/11/ns2-installation-in-ubuntu-1404.html

  • Install gcc-4.4 and g++-4.4 for compiling this LEACH (but the recommended is gcc-4.3 but it is not there in the synaptic package manager)
  • To install the above, first you tries these packages
sudo apt-get update 
sudo apt-get install build-essential autoconf automake libxmu-dev gcc-4.4 g++-4.4

Please see the video for more instructions 




Installation of LEACH in ns-2.35 

From the downloaded files , copy both the leach-setup.sh and the ns-leach-2.35.tar.gz in the same folder. Open the terminal and run as shown below.

$] sh leach-setup.sh
After the above step, all files will be unzipped and copied to their locations and now an 

Important Step

The following four files contains some path information about other files, these path information have to be updated in these files. Also these four files are located at two different locations. 
Location1: /home/pradeepkumar/ns-allinone-2.35/ns-2.35/mit/uAMPS/ 
Location2: /home/pradeepkumar/ns-allinone-2.35/ns-2.35/tcl/mobility/ 
Change the paths as mentioned in the video and replace the files at both the location with the updated path information.  
leach.tcl
leach-c.tcl
mte.tcl
stat-clus.tcl 

To test LEACH Protocol

To test leach protocol, go to this folder
$] cd ns-allinone-2.35/ns-2.35/
$] ./leach_test

once done, go to the folder
$] cd mit/leach_sims/
LEACH
Leach Protocol

open the files leach.out or anything with the name leach.* (these data are relevant to LEACH), if you want to run leach-c, change the line alg=leach-c in the file leach_test  

Thats it!!!!! 

I have given the elaborate information on LEACH, for any doubts, refer http://www.nsnam.com,

Please comment below, if you got any further inputs or updates. 
Thanks to http://anupamasikchi.blogspot.in/ (for information related to LEACH, all the particulars given in this link is reflected in my code).

T S Pradeep Kumar
, ,

Printing the Routing Table in DSDV protocol

Printing the routing table for any protocol is quite a easier task if the data structure is known. You may read the post on "printing the routing table for AODV protocol" 

Now this post will let you know how to print the routing table when using DSDV protocol. As you know, the DSDV protocol is a table driven protocol in which each node maintains a Routing table for a given source to destination and the table gets updated periodically to maintain the routes.

But AODV protocol is a on demand routing protocol that deals with Route Request, Route Reply for forming the routes. So printing the routing table takes a minor tweak. But the DSDV protocol handles the routing table as a data structure, here is the steps to do it.

OS Used : Linux Mint 17 - 64 bit
NS2 Used : ns-2.35
Files to be modified: dsdv.cc and dsdv.h

Step 1:
The folder where ns2 installed on my machine /home/pradeepkumar/ns-allinone-2.35/ns-2.35
Execute these commands to access the DSDV protocol
$prompt] cd /home/pradeepkumar/ns-allinone-2.35/ns-2.35
$prompt] cd dsdv
$prompt] ls 
This commands will list you all the files in the folder ~dsdv/
Now open the files dsdv.cc and dsdv.h

Step 2: dsdv.h 
We will be printing the routing table in a file called dsdv.txt
include this line in the class DSDV_Agent{....
under protected mode as given below
.........
protected:
FILE *fp;
......

Step 3: dsdv.cc

input the following line inside the constructor DSDV_Agent() as shown below

DSDV_Agent::DSDV_Agent (): Agent (PT_MESSAGE), ll_queue (0), seqno_ (0),
  myaddr_ (0), subnet_ (0), node_ (0), port_dmux_(0),
  periodic_callback_ (0), be_random_ (1),
  use_mac_ (0), verbose_ (1), trace_wst_ (0), lasttup_ (-10),
  alpha_ (0.875),  wst0_ (6), perup_ (15),
  min_update_periods_ (3) // constants
 {

fp=fopen("dsdv.txt","w");

Step 4: dsdv.cc
There is a function called updateRoute(), include the red colored line given below in to the function as shown below.

void
DSDV_Agent::updateRoute(rtable_ent *old_rte, rtable_ent *new_rte)
{
  int negvalue = -1;
  assert(new_rte);

  Time now = Scheduler::instance().clock();

  char buf[1024];
  //  snprintf (buf, 1024, "%c %.5f _%d_ (%d,%d->%d,%d->%d,%d->%d,%lf)",
  snprintf (buf, 1024, "%c %.5f _%d_ (%d,%d->%d,%d->%d,%d->%d,%f)",
   (new_rte->metric != BIG
    && (!old_rte || old_rte->metric != BIG)) ? 'D' : 'U',
   now, myaddr_, new_rte->dst,
   old_rte ? old_rte->metric : negvalue, new_rte->metric,
   old_rte ? old_rte->seqnum : negvalue,  new_rte->seqnum,
   old_rte ? old_rte->hop : -1,  new_rte->hop,
   new_rte->advertise_ok_at);
fprintf (fp, "%c %.5f _%d_ (%d,%d->%d,%d->%d,%d->%d,%f)\n",
   (new_rte->metric != BIG 
    && (!old_rte || old_rte->metric != BIG)) ? 'D' : 'U', 
   now, myaddr_, new_rte->dst, 
   old_rte ? old_rte->metric : negvalue, new_rte->metric, 
   old_rte ? old_rte->seqnum : negvalue,  new_rte->seqnum,
   old_rte ? old_rte->hop : -1,  new_rte->hop, 
   new_rte->advertise_ok_at);

  table_->AddEntry (*new_rte);
fprintf(fp,"(%d),Route table updated..\n",myaddr_);
fprintf (fp,"VWST %.12lf frm %d to %d wst %.12lf nxthp %d [of %d]\n",now, myaddr_, new_rte->dst, new_rte->wst, new_rte->hop, new_rte->metric);

  if (trace_wst_)
    trace ("VWST %.12lf frm %d to %d wst %.12lf nxthp %d [of %d]",
  now, myaddr_, new_rte->dst, new_rte->wst, new_rte->hop,
  new_rte->metric);
  if (verbose_)
    trace ("VS%s", buf);
}

Step 4: compile and make
Execute the following steps one by one
$prompt] cd /home/pradeepkumar/ns-allinone-2.35/ns-2.35
$prompt] make
if there is no error, execute any tcl file that has the dsdv protocol as the routing protocol and run it  using ns filename.tcl
here is a sample output of the pradeep.txt file

D 0.03011 _0_ (1,-1->1,-1->4,-1->1,12.030111)
(0),Route table updated..
VWST 0.030110562161 frm 0 to 1 wst 6.000000000000 nxthp 1 [of 1]
D 12.95121 _0_ (1,1->1,4->6,1->1,23.451213)
(0),Route table updated..
VWST 12.951212565148 frm 0 to 1 wst 5.250000000000 nxthp 1 [of 1]
D 25.24463 _0_ (1,1->1,6->8,1->1,34.432132)
(0),Route table updated..
VWST 25.244631607088 frm 0 to 1 wst 4.593750000000 nxthp 1 [of 1]

Here is the screenshot of the simulation
DSDV Routing table
DSDV Routing table
If you are unsure how to do it, you may send your email address through the comment section or contact page to receive these files. 

T S Pradeep Kumar 
, , ,

Printing Routing Table in AODV: NS2

There are no automatic provisioning to print a routing table for a given node in ns2. However, using the tracefile generated using ns2, routing table can be printed, but one should be good enough in processing a file using awk, python or any other scripts.

The following code will make you print the routing table when you are using AODV Protocol.

Files to be modified:
~ns-2.35/aodv/aodv.h
~ns-2.35/aodv/aodv.cc

The RED colored code indicates the addition of these lines in to the existing codes.

The following line can be added to the aodv.h file inside the class AODV in the protected scope.  probably add the line after the rt_down() function.

void rt_print(nsaddr_t nodeid);

In the aodv.cc file, add the following entry anywhere, but probably after the end of rt_down() function. 
void  AODV::rt_print(nsaddr_t nodeid) {
FILE *fp;
fp = fopen("route_table.txt", "a");
aodv_rt_entry *rt;
for (rt=rtable.head();rt; rt = rt->rt_link.le_next) {
fprintf(fp, "NODE: %i %f %i %i %i %i %i %f %d \n", nodeid, CURRENT_TIME, rt->rt_dst, rt->rt_nexthop, rt->rt_hops, rt->rt_seqno, rt->rt_expire, rt->rt_flags);
}
fclose(fp);
}

The above function records the routing table entry in to a file called route_table.txt. 
The above code 
  • creates a file pointer inturn a file called route_table.txt under append mode.
  • it creates an pointer to routing table entry. 
  • processes from the head of the queue to the last and print these information to the file with pointer fp and 
  • finally close the file pointer. 
Finally the rt_print() function have to be called. This can be called from anywhere. Here is the function call in aodv.cc file. 
It is inside the void AODV::recvReply(Packet *p) {

if (ih->daddr() == index) { // If I am the original source
  // Update the route discovery latency statistics
  // rp->rp_timestamp is the time of request origination
    rt_print(index); // print this nodes whole routing table
    rt->rt_disc_latency[(unsigned char)rt->hist_indx] = (CURRENT_TIME - rp->rp_timestamp)
                                         / (double) rp->rp_hop_count;
    // increment indx for next time
    rt->hist_indx = (rt->hist_indx + 1) % MAX_HISTORY;
  } 

Once the above steps are done.  Open the terminal and go to the ~ns-2.35. folder and type the following commands one by one
prompt$] make
Once the compilation is successful, test any of the wireless tcl files with AODV protocol is the routing and run it using ns filename.tcl
If you need a testing file, download here
Here is the sample screenshot of the routing table
routing table
Print Routing Table in AODV

This post is taken and modified from www.elmurod.net
T S Pradeep Kumar
, , ,

Adding a malicious node in NS2 in AODV Protocol

Adding a malicious node is ns2 using aodv protocol. The node which is declared as malicious will simply drop the router packet (DROP_RTR_ROUTE_LOOP).

Two files have to be modified.
1. aodv.h
2. aodv.cc

aodv.h file changes
Declare a boolean variable malicious as shown below in the protected scope in the class AODV

bool malicious;

aodv.cc file changes
1. Initialize the malicious varible with a value "false". Declare it inside the constructor as shown below
AODV::AODV(nsaddr_t id):Agent(PT_AODV)...
{
.......
malicious = false;
}

2. Add the following statement to the aodv.cc file in the "if(argc==2)" statment.

if(strcmp(argv[1], "malicious") == 0) {
    malicious = true;
   return TCL_OK;
}

3. Implement the behavior of the malicious node by setting the following code in the rt_resolve(Packet *p) function. The malicious node will simply drop the packet as indicated below.

if(malicious==true)
{
drop(p,DROP_RTR_ROUTE_LOOP);
}

Once done, recompile ns2 as given below
Open Terminal -> Go to ~ns-2.35/ directory and type the command make to compile
$] cd /home/pradeep/ns-allinone-2.35/ns-2.35/
$] make

Once the compilation is done, Check the malicious behavior using the Tcl Script by setting any one node as malicious node. The command to set the malicious node is
$ns at 0.0 "[$n2 set ragent_] malicious"
The variable referred for node2 is n2 (set n2 [$ns node])

Result Analysis of Malicious Node behavior
The results of the above algorithm is analysed using tracegraph. For a given network, the malicious behavior is set.
You can download the entire files here.
1. Copy the aodv.h and aodv.cc file in the ~ns-2.35/aodv/ directory
2. Download the Tcl files for malicious and non malicious
See this post: http://www.nsnam.com/2013/10/tracegraph-installation-in-ubuntu-1310.html
Here is the screenshot shown from the tracegraph
non malicious
Non Malicious simulation

malicious
Malicious behavior
Here is the text info for the above graph:
Non Malicious
Number of generated packets: 8493
Number of sent packets: 8493
Number of forwarded packets: 0
Number of received packets: 8401
Number of dropped packets: 4
Number of lost packets: 0
Number of sent bytes: 461918
Number of forwarded bytes: 0
Number of received bytes: 2435044
Number of dropped bytes: 164
Minimal packet size: 28
Maximal packet size: 1040

Average packet size: 171.4787

Malicious
Simulation length in seconds: 21.052766
Number of nodes: 2
Number of sending nodes: 2
Number of receiving nodes: 2
Number of generated packets: 67
Number of sent packets: 54
Number of forwarded packets: 0
Number of dropped packets: 16
Number of lost packets: 0
Minimal packet size: 0
Maximal packet size: 1098
Average packet size: 125.76
Number of sent bytes: 8102
Number of forwarded bytes: 0
Number of dropped bytes: 480
Packets dropping nodes: 1

It is clear from the results that malicious is simply dropping the packet, though it generates packet and are not sent.
This post is a reproduction from www.elmurod.net with added result analysis

T S Pradeep Kumar
, ,

WSN Flooding Routing Protocol (WFRP) in Network Simulator (NS-2.35)

Installation of WFRP (WSN flooding routing protocol) as given in the site http://elmurod.net/en/index.php/archives/157.
This post will help you to install the wfrp protocol in the Network Simulator 2.35 (ns-2.35) and you can run this without any bug or error
Here are the files to be corrected and downloaded: Download this Zip file and uncompress it and copy it to the relevant folders as given below (Instead of manual changes, you can copy the files and recompile) – Please take a backup of your NS-2.35 folder as these changes may affect your existing recompiled sources.
Copy these three files (wfrp.cc, wfrp.h, wfrp_packet.h)  in the folder called ~ns-2.35/wfrp
  • ~ns-2.35/Makefile.in
  • ~ns-2.35/queue/priqueue.cc
  • ~ns-2.35/common/packet.h
  • ~ns-2.35/trace/cmu-trace.h
  • ~ns-2.35/trace/cmu-trace.cc
  • ~ns-2.35/tcl/lib/ns-packet.tcl
  • ~ns-2.35/tcl/lib/ns-lib.tcl
  • ~ns-2.35/tcl/lib/ns-agent.tcl
  • ~ns-2.35/tcl/lib/ns-mobilenode.tcl
Here are the following changes (changes gives in the Black Circle) in ~ns-2.35/queue/priqueue.cc
wfrp1
here are the 3 changes in the ~ns-2.35/common/packet.h file
wfrp2
wfrp3
wfrp4
changes in the ~ns-2.35/trace/cmu-trace.cc  file
wfrp5
~ns-2.35/trace/cmu-trace.h
wfrp6
~ns-2.35/tcl/lib/ns-packet.tcl
wfrp7
~ns-2.35/tcl/lib/ns-lib.tcl (two changes)
wfrp9
wfrp10
~ns-2.35/tcl/lib/ns-mobile.tcl
wfrp11
Here is the Makefile.in changes
wfrp12
If you don’t have patience to see the images above, please look the video for doing the WFRP Protocol
Once all these steps are completed, Open the terminal and go to the ~ns-2.35/ folder and give these commands one by one
$ ./configure
$ make
If no errors in the compilation, execute the wfrp_802_15_4.tcl (given in the zip file), using
$ ns wfrp_802_15_4.tcl 
This file will generate the trace and nam file. Use the NAM file to see the animation using
$ nam filename.nam