Saturday 25 August 2012

IP Routing in NS2



I know. I know. IP is “the most” widely used routing in the computer industry. But, we as people in academic need to be a bit more precise when using buzz words.

IP: refers to IP address. It is different from routing mechanism. IP address is just a hierarchical way of defining an endpoint.
Routing mechanism: is a way of determining the route to get to a given destination. It works according to an underlying routing table.
Routing algorithm: computes a routing table.
Routing protocol: is a set of communication rules, which shall be followed under a certain condition such as a route failure.

Here is a example set of parameters in practice:

Addressing = IP Address
Routing mechanism = Routing table; Route Summary
Routing algorithm = Dijkstra
Routing protocol = OSPF

What about NS2?

By default, NS2 uses the following setting

Addressing = Flat address (1,2,3,…)
Routing mechanism = Address classifiers
Routing algorithm = Dijkstra
Routing protocol = Static (The condition of all the nodes does not change throughout the simulation)

Do You Really Need IP?

I have received quite a few questions like “How do I implement IP in NS2?” My first response would be “this is too vague”. You really have to break down your questions. At least, you have to identify which of the above 4 topics you would like to study.

For example, if you would like to study routing protocols, you’d probably refer to OSPF or BGP routing protocols. If your focus is on the communiation protocols of the routing, you can use the following setting

Addressing: Flat
Routing Mechansism: Classifier
Routing Algrithm: Dijkstra (used by default as a part of OSPF)

which are the default setting of NS2.

Routing in NS2

The default routing protocol of NS2 is static routing. This means that there would be no change in topology throughout the simulation. In this case, NS2 configures the routing information once when the simulation start with the OTcl statement “$ns run”. The process proceeds as follows:

Step 1: [OTcl] Simulator::run
Step 2: [OTcl] Routelogic::configure
Step 3: [OTcl] Agent/rtProto/Static::init-all
Step 4: [OTcl] Simulator::compute-routes
Step 5: [OTcl] Simulator::computer-flat-route
Step 6: [OTcl] RouteLogic::compute
Step 7: [OTcl] Simulator::populate-flat-classifier

Step 6: The OTcl class RouteLogic is bound to the C++ class with the same name (see file ns-2.35/routing/route.cc,h). The OTcl command compute simply executes the funciton compute_routes(…) in the C++ domain. From this point, you have look closely of what NS2 does and apply necessary changes to fit your needs.

Step 7: See how NS2 populate the routing information to all the Nodes. You will need to look into this step to see how routing information are delivered to all related Nodes.

Network Simulator 2 Tutorials

1.  For Learning about Network Simulator 2 basics you can use Marc Greis Tutorials here.

2. You can use following materials

Install Mannasim Patch in NS 2.34 for Wireless Sensor Network Simmulation


1. Download Mannsim Patch for NS 2.34 here.

2. Type the following command on the ns-allinone-2.29 folder:
  • patch -p1 < ns2.34-mannasim-gcc4.3.patch
3. Install NS 2.34 as shown in previous post . 

To test MannaSim installation two simulation scripts are provided bellow. The first one simulates a flat network of homogeneous sensors and the second a hierarchical network composed of two diferent classes of sensor nodes.

If you have any installation problem then post comments......

Install NS 2.34 in Ubuntu 10.10

1. Download & install some packages from repository by following commands :
  • $ sudo apt-get update
  • $ sudo apt-get install build-essential autoconf automake libxmu-dev 
2. Download  ns-2.34 and extract in your home directory.

3. Install the development files for X Windows plus the g++ compiler:
  • sudo apt-get install xorg-dev g++ xgraph
4.  Edit line 6304 of "otcl-1.13/configure"  from SHLIB_LD="gcc -shared" to SHLIB_LD="ld -shared"

5. Now run command in terminal : 
  • $  ./install
6. Set environment variables
  • $ gedit ~/.bashrc
7. Add the following lines to the end of the file. Remember replace “/your/path” by the folder where you have     stored extracted the ns-2 file (For example, if your Linux account name is blackpearl, and you have
    extracted  the file to your home directory, you have to change /your path to /home/blackpearl).

# LD_LIBRARY_PATH
OTCL_LIB=/your/path/ns-allinone-2.35/otcl-1.14
NS2_LIB=/your/path/ns-allinone-2.35/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=/your/path/ns-allinone-2.35/tcl8.5.10/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB
# PATH
XGRAPH=/your/path/ns-allinone-2.35/bin:/your/path/ns-allinone-2.35/tcl8.5.10/unix:/your/path/ns-allinone-2.35/tk8.5.10/unix
NS=/your/path/ns-allinone-2.35/ns-2.35/
NAM=/your/path/ns-allinone-2.35/nam-1.15/
export PATH=$PATH:$XGRAPH:$NS:$NAM

8. Ensure that it immediately takes effect:
  • $ source ~/.bashrc
9. You can test the installation by doing the following:
  • $ cd ns-2.35
  • $ ./validate