Ex.10
Ex.10
Aim:
NS2 stands for Network Simulator Version 2. It is an open-source event-driven simulator designed
specifically for research in computer communication networks.
2. Features of NS2
1. It is a discrete event simulator for networking research.
2. It provides substantial support to simulate bunch of protocols like TCP, FTP, UDP, https and
DSR.
3. Basic Architecture
NS2 consists of two key languages: C++ and Object-oriented Tool Command Language (OTcl).
While the C++ defines the internal mechanism (i.e., a backend) of the simulation objects, the OTcl
sets up simulation by assembling and configuring the objects as well as scheduling discrete events.
The C++ and the OTcl are linked together using TclCL
NS2 uses OTcl to create and configure a network, and uses C++ to run simulation. All C++ codes need
to be compiled and linked to create an executable file.
Use OTcl
This option is preferable for most beginners, since it does not involve complicated internal mechanism
of NS2. Unfortunately, existing NS2 modules are fairly limited. This option is perhaps not sufficient for
most researchers.
Use C++
i. When you are dealing with a packet, or - when you need to modify existing NS2 modules.
This option perhaps discourages most of the beginners from using NS2. This book particularly aims at
helping the readers understand the structure of NS2 and feel more comfortable in modifying NS2
modules.
Which is thus the first line in the tcl script. This line declares a new variable as using the set command, you
can call this variable as you wish, In general people declares it as ns because it is an instance of the
Simulator class, so an object the code[new Simulator] is indeed the installation of the class Simulator using
the reserved word new.
In order to have output files with data on the simulation (trace files) or files used for visualization (nam
files), we need to create the files using ―open command:
The above creates a dta trace file called out.tr and a nam visualization trace file called out.nam. Within the
tcl script, these files are not called explicitly by their names, but instead by pointers that are declared
above and called ―tracefile1 and ―namfile respectively. Remark that they begins with a # symbol. The
second line open the file ―out.tr to be used for writing, declared with the letter ―w. The third line uses a
simulator method called trace-all that have as parameter the name of the file where the traces will go.
Proc finish { } {
$tracefile1 Close
Exit 0
Once we define several nodes, we can define the links that connect them. An example of a definition of a
link is:
Which means that $n0 and $n2 are connected using a bi-directional link that has 10ms of propagation
delay and a capacity of 10Mb per sec for each direction.
To define a directional link instead of a bi-directional one, we should replace ―duplex-link by ―simplex-
link.
In ns, an output queue of a node is implemented as a part of each link whose input is that node. We should
also define the buffer capacity of the queue related to each link. An example would be: