Introduction to Network Simulator 2
In this post
- Introduction
to Network Simulator 2 and its architecture
- Installation
of Network Simulator 2 in various Operating Systems
- How to simulate a given network with available libraries of NS2
The network simulator 2 (ns) addresses large number of protocols,
applications, agents, queues, etc. These are called as “simulated objects”
either in the C++ or OTCL. This book will let the users to code the ns Tcl
scripts for wired and wireless networks. This book is intended for students,
researchers who need better understanding of networks.
NS is a discrete event simulator developed towards
the research and development in networking. NS supports various supports on
wired, wireless networks, protocols, unicast/multicast networks, satellite
networks. The recent versions of ns2 support latest wireless networks.
NS evolves in 1989 as REAL network simulator. Later
in the year 1995 ns development was supported by DARPA through the VINT
project at LBL, Xerox PARC, UCB, and USC/ISI.
While ns is favorable to
researchers right through the inception it is still not a finished or a
polished product. Still the bugs are being discovered and corrected by the
researchers. Sometimes the simulations
may be invalidated by the bugs. Users are responsible for verifying themselves
to correct these.
The main purpose of this book is to provide the readers the basic knowledge and architecture on ns2. This book provides with Tcl scripts for various networks that were available as modules within ns2. The best way to start learning NS2 is through the Ns Manual [1] provided by the http://www.isi.edu/nsnam/ns. However, this book will help you to simulate these networks that were available in ns2 software.
Installation of NS2
NS2 uses two languages OTCL and C++, in which OTCL provides the front end and C++ runs in the backend. For more details, please refer Chapter 3.
OTCL is
·
Interpreted language also
called as interpreted hierarchy
·
OTcl is Object Oriented Tcl
·
Preferable for beginners to
simply test the protocols, wired, wireless networks, etc
· Interpretation is fast and execution is slow (so prefer to run in the front end)
C++
·
Compiled hierarchy
·
Preferable when dealing with
packet, agent, application, protocol, routing, etc.
· Compilation is slow, but execution is faster (so prefer to run in the backend)
TclCL is
·
Provides some classes for
interfacing between C++ and OTcl
· Consists of classes with methods Tcl and members to does the mapping between the other two languages.
The fig1.1 will
describe the same.
NS2 |
Fig 1.1 – Architecture of
NS2
As shown in the
fig1.1, the input is the Tcl script and the output is to plot the graph or
animate the network.
·
Develop the .tcl file.
·
Execute the file using ns
filename.tcl
·
There are two output files
·
A file with nam as extension to
show the animation
·
To execute the nam file, nam
filename.nam
·
A file with .tr or .xg or any
other as specified to plot the graph and to identify the performance
characteristics
·
To see the graph, either to use
xgraph
or tracegraph or gnuplot
· The trace file can also be processed using awk script by analyzing the text information from the file and predict the performance metrics of the networks
Directory Structure of NS2
This book deals with the latest ns package with version 2.35. The NS is a free tool that can be downloaded from [3]. It can be installed on various operating systems like Linux, Unix, Mac Systems, Windows, etc. This book unless otherwise specified, uses Linux as the Operating System for using NS2.
NS comes with two different forms,
·
All in one package
·
The current version is ns-2.35
·
The various packages comes
along with the allinone package
·
nam-1.15
·
ns-2.35
·
otcl-1.14
·
tcl-8.5.10
·
tk-8.5.10
·
tclcl-1.20
·
xgraph-12.2
·
All these packages comes in a
single bundle and it contains a install script that compiles all the packages
using the make utility and generate the binaries for ns, nam, xgraph, etc.
·
Component wise package suite
· In this all the packages have to be compiled separately
NS2 has the directory structure with ns-allinone-2.35 is the top
level and there are subsequent levels. The fig 1.2 shows the directory
structure of ns-2.35
NS2 Directory Structure |
The ns-2.35 folder contains all the simulated modules in the compiled form and there are so many other folders within the ns-2.35. If anyone is working on the networks, then they can retain themselves within this ns-2.35 directory, because that contains almost everything related to the network.
Some other folders of use are
·
Ns-2.35 /
·
aodv – that contains the code
of the routing algorithm AODV
·
dsdv – contains the code for
the routing DSDV
·
mac – contains all the mac
layer codes , Ex. 802.11, etc
·
queue – codes that contain all
the queuing nodes
·
mobile – information about the
mobile parameters of the node.
·
tcl – all the simulation
modules in the interpreted hierarchy
·
lib – all the TCL simulation
objects
· ex – contains the tcl scripts for various networks
Installation of NS2 on a UNIX
like platform
To install the ns2 software on a UNIX like platform, the install
script has to be executed using the make utility
Shell> ./install
To install all the required software and to create the binaries.
Shell> ./validate
This is to validate the all the required functionalities that were
installed during the ./install
process.
Please refer, Appendix A for detailed installation instructions for most of the Operating systems.
Starting with NS2
Starting with ns,
the user need to know lot many things. Listed are some important ideas and
techniques before proceeding to program ns.
·
set tcp1 [new Agent/TCP]
·
In the above statement, [new Agent/TCP] creates a shadow object
from the TcpClass Agent class.
·
When this statement is dealt
with, there are many parameters to be noted.
·
Where is the actual agent (in
which source file the agent was written).
·
TcpClass was written in C++ and the code
is located at ~ns-2.35/tcp/tcp.cc
·
When new Agent/TCP is called in
OTCL, the TcpClass runs in the
backend and thus creates a shadow object which returns the TcpAgent.
·
There are many parameters
executes when the agent is created. TcpAgent
also has many parameters initialized and modified during the simulation of
network. However, not all the parameters are relevant for the research when
simulating the network.
·
All those parameters default
values are located in the ~ns-2.35/tcl/lib/ns-default.tcl
file. These values can be overwritten within the tcl script when the user
is writing.
·
For example, Agent/TCP
set numdupacks_ 3 (this is the line taken from the ns-default.tcl file
and specifies that the number of duplicate acknowledgment is 3 and if the user
wanted to change it to 5, the code has to be included in the tcl file like this
·
$tcp0 set numdupacks_ 5 (as tcp0 is the handler for the Agent/TCP)
· There may be more number of C++ classes running in the background when the Tcl file is interpreting and the researchers are advised to go through the source code if they are programming a given network.
The following table tells the Agent name and their corresponding
file location.
Agent/TCP |
TcpClass |
~ns-2.35/tcp/tcp.cc |
Agent/TCP/Reno |
RenoTcpClass |
~ns-2.35/tcp/tcp-reno.cc |
Agent/UDP |
UdpAgentClass |
~ns-2.35/apps/udp.cc |
Table 1.1 – Otcl - C++ Class names
Let us go through a simple example of a wired network that exchange packets between the nodes.
Listing 1.1 – TCP with FTP Traffic between two nodes
#create a new
simulator object ns
set ns [new Simulator]
# creation of two
nodes n0 and n1
set n0 [$ns node]
set n1 [$ns node]
#Open the files
for tracing in write mode, if the file already exits, it will be overwritten,
else a #new file will be created
set tracefile [open out.tr w]
$ns trace-all $tracefile
#Open the files
for network animation
set namfile [open out.nam w]
$ns namtrace-all $namfile
#Create a duplex
link between nodes n0 and n1
$ns duplex-link $n0 $n1 2MB 10ms DropTail
#Creates TCP Agent
and attach it to node 0
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
#creates TCP Sink
Agent and attach that agent to node 1
set tcpsink0 [new Agent/TCPSink]
$ns attach-agent $n1 $tcpsink0
# Set the Traffic
for FTP and attach it to TCP Agent
set ftp [new Application/FTP]
$ftp attach-agent $tcp0
#connect the
source and the sink
$ns connect $tcp0 $tcpsink0
#Start the traffic
at 1.0seconds.
$ns at 1.0 "$ftp start"
#call the finish
procedure at 4.0 sec
$ns at 4.0 "finish"
#Procedure
finish{}
proc finish {} {
global
ns tracefile namfile
exec
nam out.nam &; #execute the animation within the procedure
exit
0
}
#Run the
simulation
$ns run
Conclusion
This chapter gives you the short glimpse of what is ns2 and how it is installed under various operating system. This chapter deals with the directory structure of ns2 with various other packages that are of important to Network simulator for its operation. Also this chapter shows the two languages used in ns2 OTcl and C++ and demonstrates a wired Tcl script with Network animation screenshot.
Comments
Post a Comment