Tag Archives: Ns (simulator)

[How To] Display Routing Table of AODV in ns-2.34

Hi Folks,

In this post I shall tell about how to display routing table of nodes while using AODV protocol. I read various tutorials online but most of them failed to exactly display the routing tables or were unable to exactly specify where to put the print_routing_table() function. And by using these methods I kept getting segmentation faults or huge files displaying routing tables even when the node count was 5 with only 1 traffic source. However i have used some of those tutorials and modded them to work fine “cuz u know no one writes code from scratch”. My grandfather did that and he is old by now.

Let’s begin:

Step 1) Open file aodv_rtable.h . Go to class aodv_rtable and in its public scope declare a member function

void rt_display(nsaddr_t id);

Step 2) Open file aodv_rtable.cc . Go to end and type this (read copy-paste 🙂 )

void
aodv_rtable::rt_display(nsaddr_t id)
{
FILE *dumpFile;
dumpFile = fopen("rtable.txt", "a+");
aodv_rt_entry *rt = rthead.lh_first;
for(; rt; rt = rt->rt_link.le_next) {
// You can add more route table entries if you want to. See aodv_rtable.h for more entries.
fprintf(dumpFile, "NODE: %d \t %f \t %d \t %d \t %d \t %d \t %.4f \t %d \n", id, CURRENT_TIME,
rt->rt_dst, rt->rt_nexthop, rt->rt_hops, rt->rt_seqno, rt->rt_expire, rt->rt_flags);
}
fclose(dumpFile);
}

Step 3) (Important One) Open file aodv.cc . Go to the function
AODV::rt_update(aodv_rt_entry *rt, .... )

At the end of inside this function call the rt_display() function as:

rtable.rt_display(index);

Step 4) Compile using make and sudo make install inside the ns-2.34 directory.

Step 5) run your tcl file (here is the file if u want to test). The rtable.txt should look like this rtable.txt  ..

[GUIDE TO] Installing ns-2.34 (network simulator) in Ubuntu 12.04 LTS (specifically)..

Hi Folks,

Recently, I had been trying to install ns-2.34 in my ubuntu 12.04 which i have on a HP G62 pavilion notebook. Although i successfully installed it many a times but it was just a basic install (i.e. for a noob to work upon with basic tcl scripting and viewing simulations). Installing it completely without any compilation errors was the most challenging task as in order to modify ns2 u have to install it flawlessly.

In this post I shall teach you how to install ns-2.34 in ubuntu 12.04 (specifically).

First of all u need to download my version of ns-2.34 from the link given below. In this version of ns-2.34, I have made all the necessary changes (i.e. to Makefile and certain other files in ns-2.34 directory).

Download it from here.

The package is a complete ns-allinone-package with all changes done without the need of having u to make any further changes. If the following steps are followed in order u might get a full clean install of ns2.

Note : We shall install ns-2.34 in the home directory and no where else. So please copy the downloaded file in your home directory. And if u do not know where the home directory is u can google it 🙂 .

Step 1) Remove any previous ns2 versions installed on your OS

rm -rf /home/<your-homedirectory-name>/ns-allinone-2.34

instead of ns-allinone-2.34 u can put prior versions of ns2 if installed. And to find your home directory open terminal using Ctrl + Alt + T and then type pwd in it.

Step 2) After step 1, enter the following commands

sudo apt-get update

sudo apt-get install build-essential autoconf automake libxmu-dev libxt-dev libx11-dev xorg-dev xgraph gcc g++

The above command will install all necessary dependencies in order for ns-2.34 to run and install successfully.

Step 3) Now unzip the downloaded ns-allinone-2.34.tar.gz folder by right clicking on it and selecting open with archive manager and extract it in your home folder. Then open terminal using Ctrl + Alt + T.

Browse to the ns-allinone-2.34 directory by typing :

cd ns-allinone-2.34

now browse to ns-2.34 directory by typing :

cd ns-2.34

now type the following commands in order.

./configure

make clean

make depend

make

They should run successfully without showing any error. If you get any problems ask in comments.

Now go back to ns-allinone-2.34 directory by typing

cd ..

Now install ns-2.34 by typing

./install

It should install successfully. Now close the terminal by typing exit. If u get any errors ask in comments section.

Step 4) Now its time to setup your environment variables. This is the tricky part.

open terminal by pressing Ctrl + Alt + T. And enter the following command:

sudo gedit ~/.bashrc

bashrc file would open in gedit. At the end of the file add the following lines (Do it carefully)

# LD_LIBRARY_PATH
OTCL_LIB=/home/arya/ns-allinone-2.34/otcl-1.13
NS2_LIB=/home/arya/ns-allinone-2.34/lib
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:$USR_LOCAL_LIB
# TCL_LIBRARY
TCL_LIB=/home/arya/ns-allinone-2.34/tcl8.4.18/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB
# PATH
XGRAPH=/home/arya/ns-allinone-2.34/bin:/home/arya/ns-allinone-2.34/tcl8.4.18/unix:/home/arya/ns-allinone-2.34/tk8.4.18/unix:/home/arya/ns-allinone-2.34/xgraph-12.1/
NS=/home/arya/ns-allinone-2.34/ns-2.34/
NAM=/home/arya/ns-allinone-2.34/nam-1.13/
export PATH=$PATH:$XGRAPH:$NS:$NAM

NOTE: change arya in the above paths to your home directory’s name. (DO NOT FORGET THAT).

Close the bashrc file. Log off and log in again.

Step 5) Now open terminal using Ctrl + Alt + T and type ns.

A % sign should appears and that marks a clean installation of ns-2.34.

Voila! Success.

In the next post, I shall write about configuring ns-2.34 in Eclipse (Galileo version) for development purposes and for modifying and compiling ns-2.34 from eclipse.