Lab Exercise
1. Introduction NS-2(Network Simulator- version 2)
NS overview
o Platform support
FreeBSD, Linux, Solaris, Windows and Mac
Ns functionalities
o Wired
Routing, Transportation, Traffic sources, Queuing disciplines, QoS
o Wireless
Ad hoc routing, mobile IP, sensor-MAC
Tracing, visualization and various utilities
o One of the most popular simulator among networking researchers
Open source, free
o Discrete event, Packet level simulator
Events like ‘received an ack packet’, ‘enqueued a data packet’
o Network protocol stack written in C++
o Tcl (Tool Command Language) used for specifying scenarios and events.
Setting up a network to do some real experiments is the best way for studying about communication
in internet. However, setting a network is not easy and costly. For this reason, a virtual network
provided by network simulator is used for experiment in only one computer. Specially, NS2 which is
free and easy to use is the popular all over the world.
Numerous state of the art simulation tools are available for network research. Among the available
simulators, NS-2 is the widely used and highly recognized open source network simulator.
Network Simulator Version 2, also known as NS-2. NS-2 is an event driven packet level network
simulator
The simulation behavior of NS-2 is highly trusted within the research community. It is a dependable
and realistic discrete event based simulator tool and proves to be more practicable. It is primarily
designed based on OSI model to support wired networks.
1
Network simulators are tools used to simulate discrete events in a network and which helps to predict
the behaviours of a computer network. Generally the simulated networks have entities like links,
switches, hubs, applications, etc.
Once the simulation model is complete, it is executed to analyse the performance. Administrators can
then customize the simulator to suit their needs. Network simulators typically come with support for
the most popular protocols and networks in use today, such as WLAN, UDP, TCP, IP, WAN, etc.
NS2 Guide
NS2 is an open-source event-driven simulator designed specifically for research in computer
communication networks.
NS2 has continuously gained tremendous interest from industry, academia, and government.
Having been under constant investigation and enhancement for years, NS2 now contains
modules for numerous network components such as routing, transport layer protocol,
application, etc. To investigate network performance, researchers can simply use an easy-to-
use scripting language to configure a network, and observe results generated by NS2.
Undoubtedly, NS2 has become the most widely used open source network simulator, and one
of the most widely used network simulators.
Unfortunately, most research needs simulation modules which are beyond the scope of the
built-in NS2 modules. Incorporating these modules into NS2 requires profound
understanding of NS2 architecture. Currently, most NS2 beginners rely on online tutorials.
2
Most of the available information mainly explains how to configure a network and collect
results, but does not include sufficient information for building additional modules in NS2.
Despite its details about NS2 modules, the formal documentation of NS2 is mainly written
as a reference book, and does not provide much information for beginners. The lack of
guidelines for extending NS2 is perhaps the greatest obstacle, which discourages numerous
researchers from using NS2. At this moment, there is no guide book which can help the
beginners understand the architecture of NS2 in depth.
NS2 by itself contains numerous modules. As time elapses, researchers keep developing new
NS2 modules.
ns-2 is often criticized because modelling is a very complex and time-consuming task, since
it has no GUI and one needs to learn scripting language, queuing theory and modelling
techniques.
1.1 “Ns-2” Components
Ns, the simulator itself
Nam, the network animator
Visualize ns (or other) output
Nam editor: GUI interface to generate ns scripts
Since we only run ns2 in remote Unix server, we will not introduce Nam
usage in this class
Pre-processing:
Traffic and topology generators
Post-processing:
Simple trace analysis, often in Awk, Perl, or Tcl
You can also use grep (under linux), or C/java
3
NS2 use Tcl language for creating simulation scenario file (for example, sample.tcl).
Network topology, transmission time, using protocol etc... are defined in scenario file. If we
execute this scenario file, the simulation result will be output to finlename.tr and
filename.nam file.
filename.tr all the information about communication is written in this file. We can find out
the way a packet was forwarded. This file is called as trace file.
filename.nam contains the data for animation of the experiment result. This file can be
execute by Nam, an animation software. The state of forwarding packet in Nam is shown
in Fig.1.
4
Fig1
If simulation use TCP, we can also observe the state of TCP congestion control by a trace
file.
Ns2 Quick start
5
Hello World – Create a simulator
1.2 Wired Network in ns2
Wired network can be created using a simple topology with n number of nodes connected by a
wired link. Any two nodes in the network can be connected using a duplex link and the link
characteristics include bandwidth, delay and queue type.
1.3 How to create Wireless Network in ns2
The wireless networking model can be created using Tool Command Language (TCL) script with
fixed number of nodes. The sample code discussed below models the wireless network with 2
nodes. Nodes are configured with the components of channel, networking interface, radio
propagation model, Medium Access Control (MAC) protocol, adhoc routing protocol, interface
queue, link layer, topography object, and antenna type. The wireless network with 2 nodes can be
viewed in the Network Animator (NAM) window after executing the file sample1.tcl
2. C++ and OTcl Separation
“data” / control separation
C++ for “data”:
per packet processing, core of ns
fast to run, detailed, complete control
OTcl for control:
6
Simulation scenario configurations
Periodic or triggered action
Manipulating existing C++ objects
fast to write and change