0% found this document useful (0 votes)
3 views

Ex.10

Uploaded by

maplagay18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Ex.10

Uploaded by

maplagay18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Ex.

No:10 Study of Network Simulator (NS)

Aim:

To study about NS2 simulator in detail

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. It simulates wired and wireless network.

4. It is primarily Unix based.

5. Uses TCL as its scripting language.

6. Otcl: Object oriented support

7. Tclcl: C++ and otcl linkage

8. Discrete event scheduler

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

i. For configuration, setup, or one time simulation, or

ii. To run simulation with existing NS2 modules.

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.

Initialization and Termination of TCL Script in NS-2

An ns simulation starts with the command

set ns [new Simulator]

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:

#Open the Trace file

set tracefile1 [open out.tr w]

$ns trace-all $tracefile1

#Open the NAM trace file

set namfile [open out.nam w]

$ns namtrace-all $namfile

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.

Define a “finish‟ procedure

Proc finish { } {

global ns tracefile1 namfile

$ns flush-trace Close

$tracefile1 Close

$namfile Exec nam out.nam &

Exit 0

Definition of a network of links and nodes

The way to define a node is

set n0 [$ns node]

Once we define several nodes, we can define the links that connect them. An example of a definition of a
link is:

$ns duplex-link $n0 $n2 10Mb 10ms DropTail

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:

#set Queue Size of link (n0-n2) to 20

You might also like