Study of Network Simulator Package-2: R.Ram Kumar 411614104018
Study of Network Simulator Package-2: R.Ram Kumar 411614104018
Ram Kumar
411614104018
AIM:
To make a descriptive study of the network simulator Ns-2.
OVERVIEW:
Ns-2 stands for Network Simulator version 2.Network simulator is a
discrete event simulator for networking research and work at packet level. It also
provides substantial support to simulate bunch of protocols like TCP, UDP, FTP,
HTTP and DSR. It can also able to simulate wired and wireless network.
It is primarily UNIX based and uses TCL as its scripting language.
Ns-2 is a standard experiment environment in research community. It uses
two languages Object-oriented support with otcl and C++ with otcl linkage. It is a
discrete event scheduler. An event in NS is a packet ID that is unique for a packet
with scheduled time and the pointer to an object that handles the event.
In NS an events in the event queue scheduled for the current time invoked by
appropriate network components, which usually are the ones who issued the
events, and let them do the appropriate action with packet pointed by the event.
C++ is protocol simulations require systems programming language
byte manipulation, packet processing, and algorithm implementation Run time
speed is important. Turnaround time (run simulation, find bug, fix bug, recompile,
re-run) is slower. Tcl: Simulation of slightly varying parameters or configurations
quickly exploring a number of scenarios iteration time (change the model and re
-run) is more important.
CS6411-NETWORKS LABORATORY
R.Ram Kumar
411614104018
Architectural view of NS
NS is written not only in OTcl but in C++ also. For efficiency reasoning
separates the data path implementation from control path implementations. In order
to reduce packet and event scheduler and the basic network component object in
the data path are written and compiled using C++.these compiled objects are made
available to the OTcl interpreter through an OTcl linkage that creates a matching
OTcl objects for each of the C++ objects and make control function. The object in
C++ that do not be controlled by simulation. An object can be entire;y
implemented in OTcl.
CS6411-NETWORKS LABORATORY
R.Ram Kumar
411614104018
Usually the first non comment statement in Ns-2 script is to initialize the packet
format and create a scheduler (defaults a calendar scheduler). Turning on a trace
file by opening Own trace, nam trace, ns trace files.
CS6411-NETWORKS LABORATORY
R.Ram Kumar
411614104018
Creating a network
CS6411-NETWORKS LABORATORY
R.Ram Kumar
411614104018
CS6411-NETWORKS LABORATORY
R.Ram Kumar
411614104018
CS6411-NETWORKS LABORATORY
R.Ram Kumar
411614104018
CS6411-NETWORKS LABORATORY
R.Ram Kumar
411614104018
emulate using real hardware for instance, simulation effect of a sudden burst in
traffic or a DOS attack on a network service.
NS-2
Ns-2 is a discrete event simulator targeted at networking research. Ns provides
substantial
support for simulation of TCP, routing, and multicast protocols over wired and
wireless (local and satellite) networks.
NS-2 ARCHITECTURE
Downloading/Installing ns&nam
One can build ns either from the various packages (Tcl/Tk, otcl, etc.), or can
download an 'all-in-one'package. web page: http://www.isi.edu/nsnam/ns/ns-
build.html
Starting ns
Start ns with the command 'ns <tclscript>', where '<tclscript>' is the name of a Tcl
script file
which defines the simulation scenario (i.e. the topology and the events). Just start
ns without any arguments and enter the Tcl commands in the Tcl shell, but that is
CS6411-NETWORKS LABORATORY
R.Ram Kumar
411614104018
definitely less comfortable.Everything else depends on the Tcl script. The script
might create some output on stdout, it might write a trace file or it might start nam
to visualize the simulation.
Starting nam
One can either start nam with the command 'nam <nam-file>' where '<nam-file>' is
the name of a nam trace file that was generated by ns, or one can execute it directly
out of the Tcl simulation script for the simulation which you want to visualize.
CS6411-NETWORKS LABORATORY
R.Ram Kumar
411614104018
The first line opens the file 'out.nam' for writing and gives it the file handle 'nf'. In
the second line we tell the simulator object that we created above to write all
simulation data that is going to be relevant for nam into this file.
The next step is to add a 'finish' procedure that closes the trace file and starts nam.
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam out.nam &
exit 0
}
You don't really have to understand all of the above code yet. It will get clearer
to you once you see what the code does.The next line tells the simulator object
to execute the 'finish' procedure after 5.0 seconds of simulation time.
$ns at 5.0 "finish"
You probably understand what this line does just by looking at it. ns provides you
with a very simple way to schedule events with the 'at' command.
The last line finally starts the simulation.
$ns run
Ns-2 MAIN CONSOLE WITH NETWORK ANIMATOR
CS6411-NETWORKS LABORATORY
R.Ram Kumar
411614104018
PROGRAM:
FTPTCP LS.tcl
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exit 0
$ns rtproto LS
CS6411-NETWORKS LABORATORY
R.Ram Kumar
411614104018
CS6411-NETWORKS LABORATORY
R.Ram Kumar
411614104018
$ns run
CS6411-NETWORKS LABORATORY
R.Ram Kumar
411614104018
OUTPUT:
administrator@ubuntu:~$ ns FTPTCPLS.tcl
administrator@ubuntu:~$
CS6411-NETWORKS LABORATORY
R.Ram Kumar
411614104018
PROGRAM:
FTPTFPDV.tcl
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exit 0
$ns rtproto DV
CS6411-NETWORKS LABORATORY
R.Ram Kumar
411614104018
CS6411-NETWORKS LABORATORY
R.Ram Kumar
411614104018
$ns run
CS6411-NETWORKS LABORATORY
R.Ram Kumar
411614104018
OUTPUT:
administrator@ubuntu:~$ ns FTPTCPDV.tcl
CS6411-NETWORKS LABORATORY
R.Ram Kumar
411614104018
CS6411-NETWORKS LABORATORY
R.Ram Kumar
411614104018
CS6411-NETWORKS LABORATORY