NS2- A Discrete Event Simulator
Presented By
Parmpreet Singh
Univ. Roll No. 11171058
Department of Computer
Engineering
University College of Engineering,
PUNJABI UNIVERSITY
 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
*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
*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
NETWORK SIMULATION
OPEN SOURCE COMMERCIAL
Network Simulator
Network simulators name
Commercial OPNET, QualNet
Open source NS2, NS3, OMNeT++, SSFNet, J-Sim
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)
© Varaprasad Reddy 7
DISCRETE EVENT SIMULATOR
 ns-2 is an discrete event driven simulation
◦ Physical activities are translated to events
◦ Events are queued and processed in the order of their scheduled
occurrences
◦ Time progresses as the events are processed
1 2
Time: 1.5 sec Time: 1.7 sec
Time: 1.8 sec
Time: 2.0 sec
BASIC ARCHITECTURE AND TOOLS
Basic Architecture of NS2
Flow of events for a Tcl file run in NS
C++/OTcl linkage
 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
NAM Tool Description
 Nscript
 Topology Generators
 XGraph
SOME OTHER TOOLS
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
 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..)
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
 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]
}
 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..
Vacha Dave, University of Te 19
A simple Example – Creating the topology
n1 n2
Bandwidth:1Mbps
Latency: 10ms
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
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
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
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
 #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..
NAM OUTPUT
COMPARISON WITH SOME OTHER NETWORK
SIMULATORS
● 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
[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
THANK YOU

More Related Content

PPT
Network Simulator Tutorial
PPT
NS2-tutorial.ppt
PPT
Tut hemant ns2
PDF
NS2-tutorial.pdf
PPT
Ns 2 Network Simulator An Introduction
PPTX
NErwork Lab Simulation Introduction.pptx
PPTX
Ns2 ns3 training in mohali
PDF
Introduction to ns2
Network Simulator Tutorial
NS2-tutorial.ppt
Tut hemant ns2
NS2-tutorial.pdf
Ns 2 Network Simulator An Introduction
NErwork Lab Simulation Introduction.pptx
Ns2 ns3 training in mohali
Introduction to ns2

Similar to Network Simulator overview and its working (20)

PDF
18CSL51 - Network Lab Manual.pdf
PPT
ns2-lecture.ppt
PPTX
Working with NS2
PPT
Ns2
PDF
Ns2pre
PPT
Ns network simulator
PDF
Cs757 ns2-tutorial-exercise
PDF
Ns tutorial
PPT
PPT
Venkat ns2
PPTX
Network simulator 2
PDF
cscn1819.pdf
PPT
Network simulator 2
PPT
Network simulator 2
PDF
Ns2: OTCL - PArt II
DOCX
NS2 (1).docx
PPTX
PPT
NS2 Overview - Network Simulator Tutorial
18CSL51 - Network Lab Manual.pdf
ns2-lecture.ppt
Working with NS2
Ns2
Ns2pre
Ns network simulator
Cs757 ns2-tutorial-exercise
Ns tutorial
Venkat ns2
Network simulator 2
cscn1819.pdf
Network simulator 2
Network simulator 2
Ns2: OTCL - PArt II
NS2 (1).docx
NS2 Overview - Network Simulator Tutorial
Ad

Recently uploaded (20)

PPTX
WN UNIT-II CH4_MKaruna_BapatlaEngineeringCollege.pptx
PPTX
SE unit 1.pptx aaahshdhajdviwhsiehebeiwheiebeiev
PPTX
chapter 1.pptx dotnet technology introduction
PDF
VTU IOT LAB MANUAL (BCS701) Computer science and Engineering
PPTX
Module1.pptxrjkeieuekwkwoowkemehehehrjrjrj
PDF
LS-6-Digital-Literacy (1) K12 CURRICULUM .pdf
PDF
ST MNCWANGO P2 WIL (MEPR302) FINAL REPORT.pdf
PPTX
SE unit 1.pptx by d.y.p.akurdi aaaaaaaaaaaa
PPTX
Design ,Art Across Digital Realities and eXtended Reality
PDF
ASPEN PLUS USER GUIDE - PROCESS SIMULATIONS
PDF
Beginners-Guide-to-Artificial-Intelligence.pdf
PDF
IAE-V2500 Engine for Airbus Family 319/320
PPTX
Unit IImachinemachinetoolopeartions.pptx
PDF
AIGA 012_04 Cleaning of equipment for oxygen service_reformat Jan 12.pdf
PDF
Engineering Solutions for Ethical Dilemmas in Healthcare (www.kiu.ac.ug)
PDF
Cryptography and Network Security-Module-I.pdf
PPTX
Wireless sensor networks (WSN) SRM unit 2
PPTX
AI-Reporting for Emerging Technologies(BS Computer Engineering)
PDF
ECT443_instrumentation_Engg_mod-1.pdf indroduction to instrumentation
PDF
Software defined netwoks is useful to learn NFV and virtual Lans
WN UNIT-II CH4_MKaruna_BapatlaEngineeringCollege.pptx
SE unit 1.pptx aaahshdhajdviwhsiehebeiwheiebeiev
chapter 1.pptx dotnet technology introduction
VTU IOT LAB MANUAL (BCS701) Computer science and Engineering
Module1.pptxrjkeieuekwkwoowkemehehehrjrjrj
LS-6-Digital-Literacy (1) K12 CURRICULUM .pdf
ST MNCWANGO P2 WIL (MEPR302) FINAL REPORT.pdf
SE unit 1.pptx by d.y.p.akurdi aaaaaaaaaaaa
Design ,Art Across Digital Realities and eXtended Reality
ASPEN PLUS USER GUIDE - PROCESS SIMULATIONS
Beginners-Guide-to-Artificial-Intelligence.pdf
IAE-V2500 Engine for Airbus Family 319/320
Unit IImachinemachinetoolopeartions.pptx
AIGA 012_04 Cleaning of equipment for oxygen service_reformat Jan 12.pdf
Engineering Solutions for Ethical Dilemmas in Healthcare (www.kiu.ac.ug)
Cryptography and Network Security-Module-I.pdf
Wireless sensor networks (WSN) SRM unit 2
AI-Reporting for Emerging Technologies(BS Computer Engineering)
ECT443_instrumentation_Engg_mod-1.pdf indroduction to instrumentation
Software defined netwoks is useful to learn NFV and virtual Lans
Ad

Network Simulator overview and its working

  • 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)
  • 7. © Varaprasad Reddy 7 DISCRETE EVENT SIMULATOR  ns-2 is an discrete event driven simulation ◦ Physical activities are translated to events ◦ Events are queued and processed in the order of their scheduled occurrences ◦ Time progresses as the events are processed 1 2 Time: 1.5 sec Time: 1.7 sec Time: 1.8 sec Time: 2.0 sec
  • 8. BASIC ARCHITECTURE AND TOOLS Basic Architecture of NS2
  • 9. Flow of events for a Tcl file run in NS
  • 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
  • 13.  Nscript  Topology Generators  XGraph SOME OTHER TOOLS
  • 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..
  • 26. COMPARISON WITH SOME OTHER NETWORK SIMULATORS
  • 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

Editor's Notes

  • #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.