1. NS2- A Discrete Event Simulator
Presented By
Parmpreet Singh
Univ. Roll No. 11171058
Department of Computer
Engineering
University College of Engineering,
PUNJABI UNIVERSITY
2. Introduction
Basic Architecture and Tools
Installation
OTcl Scripting with NS-2
NS-2 OTcl Script example
Comparison Some other network simulators
Motivation & Scope
References
AGENDA
3. *Jim Kurose, University of M 3
SIMULATION
system under study
(has deterministic rules
governing its behavior)
exogenous inputs
to system
(the environment)
system boundary
observer
“real” life
computer program
simulates deterministic
rules governing behavior
psuedo random inputs
to system
(models environment)
program boundary
observer
“simulated” life
4. *Jim Kurose, University of M 4
WHY SIMULATION? *
real-system not available, is complex/costly or dangerous
(eg: space simulations, flight simulations)
quickly evaluate design alternatives (eg: different system
configurations)
evaluate complex functions for which closed form formulas
or numerical techniques not available
5. NETWORK SIMULATION
OPEN SOURCE COMMERCIAL
Network Simulator
Network simulators name
Commercial OPNET, QualNet
Open source NS2, NS3, OMNeT++, SSFNet, J-Sim
6. Network Simulator (Version 2), widely known as NS2, is simply an
event driven simulation tool that has proved useful in studying the
dynamic nature of communication networks. Simulation of wired as
well as wireless network functions and protocols .
support networking research and education
◦ protocol design, traffic studies, etc.
◦ protocol comparison
provide a collaborative environment
◦ freely distributed, open source
◦ share code, protocols, models, etc.
◦ allow easy comparision of similar protocols
◦ increase confidence in results
◦ models provide useful results in several situations
NETWORK SIMULATOR 2(NS2)
11. NAM:-
NAM provides a visual interpretation of the network topology created
Provides a visual interpretation of the network created
Can be executed directly from a Tcl script
Controls include play, stop ff, rw, pause, a display speed controller and a
packet monitor facility.
Presents information such as throughput, number packets on each link.
Provides a drag and drop interface for creating topologies
SOFTWARE TOOLS USED WITH NS-2
14. 1) Download the NS2 all-in-one package.
2) Extract the contents of the tar file in your home folder: parm@parm:~$
(in my case)
3) Open terminal and change your directory to parm@parm:~/ns-allinone-
2.34$
4) The first reason for unsuccessful installation of ns2 is due to gcc compiler.
You need to have gcc-4.3 compiler to install ns2.
parm@parm:~/ns-allinone-2.34$ sudo apt-get install build-essential
autoconf automake libxmu-dev gcc-4.3
INSTALLATION
15. 5) Go to the particular folder : parm@parm:~/ns-allinone-2.34/otcl-1.13 and open the
file Makefile.in
Change this line
CC= @CC@ to CC= gcc-4.3
Now NS2 knows which particular version of gcc it has to use.
6) Go to parm@parm:~/ns-allinone-2.34 and type the command
i) sudo su
ii) ./install
7) Go to bashrc file add path
8) Type the command
parm@parm:~$ source .bashrc
Now type ns in terminal. A ‘%’ symbol will be displayed denoting that interpreter is
working. Installation Success!!
INSTALLATION(CONT..)
16. STEPS TO SET UP THE SIMULATION
Initialize the simulator
Define files for output (tracing)
Set up the topology
Set up the “agents”
Set up the traffic between the nodes
Start the simulation
Analyze the trace files to compute the parameters of interest
17. Node Creation
OTCL SCRIPTING WITH NS-2
set n0 [$ns node]
set n1 [$ns node]
The following creates 5 nodes, with handles n0-n4
for {set i 0} {$i<5} {incr i} {
Set n($i) [$ns node]
}
18. Node links
A unidirectional link between the two nodes is created as follows
A Simplex link (one way) -> $ns simplex-link $n0 $n1 <bandwidth>
<delay> <queue_type>
A bi-directional link between the two nodes is created as follows
A duplex link (both ways) ->$ns duplex-link $n0 $n1
<bandwidth> <delay> <queue_type>
Network Agents
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0 # attach the udp0 agent to node 0
CONT..
19. Vacha Dave, University of Te 19
A simple Example – Creating the topology
n1 n2
Bandwidth:1Mbps
Latency: 10ms
20. Vacha Dave, University of Te 20
#create a new simulator object
set ns [new Simulator]
#open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#close the trace file
close $nf
#execute nam on the trace file
exec nam out.nam &
exit 0
}
Creating the topology
21. Vacha Dave, University of Te 21
Creating the topology (Contd)
#create two nodes
set n0 [$ns node]
set n1 [$ns node]
#create a duplex link between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
22. Vacha Dave, University of Te 22
Adding traffic
n1 n2
1Mbps,10ms
udp
null
cbr
Packet Size: 500 bytes
rate: 800Kbps
cbr traffic
0.0
0.5
5.0
4.5 time
node
agent
source
link
23. Vacha Dave, University of Te 23
Putting it together..
#create a udp agent and attach it to node n0
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
#Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
#create a Null agent(a traffic sink) and attach it to node n1
set null0 [new Agent/Null]
$ns attach-agent $n1 $null0
24. #Connect the traffic source to the sink
$ns connect $udp0 $null0
#Schedule events for CBR traffic
$ns at 0.5 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"
#call the finish procedure after 5 secs of simulated time
$ns at 5.0 "finish"
#run the simulation
$ns run
Putting it together..
27. ● Cheap does not require costly equipment
● Complex scenarios can be easily tested
● Results can be quickly obtained – more ideas can be tested in a smaller
timeframe
● The real thing isn't yet available
● Controlled experimental conditions– Repeatability helps aid debugging
Generation 3 of NS (NS3) is available now but it has many drawbacks
that’s why NS2 is still in demand and has good future scope
MOTIVATION AND SCOPE
28. [1] http://www.isi.edu/nsnam/vint/ Virtual Internetwork Testbed collaboration
[2] http://www.Tcl.tk TCL homepage
[3] http://www.micosoft.com Microsoft website
[4] http://www.linux.org Linux homepage
[5] http://www.isi.edu/nsnam/nam/ NAM Network Animator
[6] http://msdn.microsoft.com/visualc/ Visual Studio C++ homepage
[7] http://www.winzip.com/ WinZip homepage
[8] http://www.rarlab.com/ Winrar homepage
[9] http://www.isi.edu/nsnam/ns/ns-tutorial/ucb-tutorial.html 5th UCB/LBNL
Network Simulator (NS): June 1999 Tutorial
[10] http://www.isi.edu/nsnam/xgraph/ XGraph homepage
[11] http://www.geocities.com/tracegraph/ TraceGraph homepage
[12] http://home.gwu.edu/~ecamposn/software.html Nscript NS-2 scripting
tool
[13] http://java.sun.com/ Java Sun Microsystems homepage
References
#3:We want to study the behaviour of system under a given set of external factors
- For Internet, our system is the way we have placed nodes, routers, our protocols running on them (HTTP, TCP) etc.
- Our “exogenous” behaviour” can be, for exampe – how users are using the system – for example growth of online streaming video with youtube.
- We want to model the system so that we can engineer better systems
- Its clear that simulation becomes harder as we have large systems and varied inputs. We should be able to distiguish between the important and the non-imp. Properties, so that we can observe the relevant ones
#4:We should go ahead and observe tha actual system if possible, but we can’t do so for a variety of reasons.
More importantly, Simulation can let you abstract out some of the complexity.
Simulation is repeatable – When studying flash crowds, its hard to create flash crowds again and again, but its possible to simulate them as many times as needed
#19:So lets start by creating a topology is NS2, we’re just defining stuff, no packets are going through yet
#20:set ns [new Simulator]: generates an NS simulator object instance, and assigns it to variable ns (italics is used for variables and values in this section). What this line does is the following:
Create a scheduler (default is calendar scheduler)
The "Simulator" object has member functions that do the following:
Create compound objects such as nodes and links (described later)
Connect network component objects created (ex. attach-agent)
Set network component parameters (mostly for compound objects)
Create connections between agents (ex. make connection between a "tcp" and "sink")
#21:set n0 [$ns node]: The member function node creates a node. A node in NS is compound object made of address and port classifiers (described in a later section). Users can create a node by separately creating an address and a port classifier objects and connecting them together. However, this member function of Simulator object makes the job easier.
$ns duplex-link node1 node2 bandwidth delay queue-type: creates two simplex links of specified bandwidth and delay, and connects the two specified nodes. In NS, the output queue of a node is implemented as a part of a link, therefore users should specify the queue-type when creating links. In the above simulation script, DropTail queue is used. If the reader wants to use a RED queue, simply replace the word DropTail with RED.
#22:We are going to extend the example now: we are going to attach a udp agent to n1 and a sink at n2. (agents are abstractions – of “sockets” that are present in unix)
We are going to use udp to send constant bit-rate traffic – what this means is – that the rate is constant and packet size is constant (we will set these parameters)
#23:$ns attach-agent node agent: The attach-agent member function attaches an agent object created to a node object. Actually, what this function does is call the attach member function of specified node, which attaches the given agent to itself. Therefore, a user can do the same thing by, for example, $n0 attach $tcp. Similarly, each agent object has a member function attach-agent that attaches a traffic source object to itself.
$ns connect agent1 agent2: After two agents that will communicate with each other are created, the next thing is to establish a logical network connection between them. This line establishes a network connection by setting the destination address to each others' network and port address pair.