network simulator (ns-2) internet technologies 60-375
TRANSCRIPT
![Page 1: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/1.jpg)
Network Simulator (NS-2)
Internet Technologies
60-375
![Page 2: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/2.jpg)
© Varaprasad Reddy 2
Agenda
Overview of NS-2 History Current Status Platforms Supported Discrete Event Simulator NS-2 Environment NS-2 Hierarchy NS-2 Architecture
Node Architecture Multicast Node Architecture Packet Structure Links Traffic Flow
Example
![Page 3: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/3.jpg)
© Varaprasad Reddy 3
Overview of NS-2
Discrete Event Simulator Packet level Modeling Network protocols
Collection of Various protocols at multiple layers TCP(reno, tahoe, vegas, sack) MAC(802.11, 802.3, TDMA) Ad-hoc Routing (DSDV, DSR, AODV, TORA) Sensor Network (diffusion, gaf) Multicast protocols, Satellite protocols, and many others
![Page 4: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/4.jpg)
© Varaprasad Reddy 4
Overview of NS-2
Maintained through VINT project NS2 :collaborative simulation environment
Freely distributed and open sourceSupports NT research and education
Protocol design , traffic analysis etc.
Provides common reference
![Page 5: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/5.jpg)
© Varaprasad Reddy 5
History
1995 : Developed by LBL through support of DARPA
1996: NS was extended and distributed by VINT project
1997: Satellite models added @ UCB 1999: Wireless models added @ CMU Recent incorporation of emulation
![Page 6: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/6.jpg)
© Varaprasad Reddy 6
Current status
Releases:Periodic releases (currently 2.27, Jan 2004)Daily snapshots (probably compiles and
works, but “unstable”)Available from: USC/ISI, UC Berkeley, UK
mirror More than 10k users from hundreds of univs
![Page 7: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/7.jpg)
© Varaprasad Reddy 7
Platforms supported
Most UNIX and UNIX-like systems FreeBSD LinuxSolaris
Windows 98/2000/2003/XPCygwin required Some work , some doesnt
![Page 8: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/8.jpg)
© Varaprasad Reddy 8
NS-2 : Components
NS – Simulator NAM – Network AniMator
visual demonstration of NS output Preprocessing
Handwritten TCL or Topology generator
Post analysis Trace analysis using Perl/TCL/AWK/MATLAB
![Page 9: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/9.jpg)
© Varaprasad Reddy 9
User’s Perspective
From the user’s perspective, NS−2 is an OTcl interpreter that takes an OTcl script as input and produces a trace file as output.
![Page 10: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/10.jpg)
© Varaprasad Reddy 10
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 secTime: 2.0 sec
![Page 11: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/11.jpg)
© Varaprasad Reddy 11
Discrete Event Scheduler
time_, uid_, next_, handler_
head_ ->
handler_ -> handle()
time_, uid_, next_, handler_insert
head_ ->
Event Scheduler
![Page 12: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/12.jpg)
© Varaprasad Reddy 12
Event Scheduler
Non-Real time schedulers Implementations : List , Heap , Calender Calender is default
Real time schedulers Used for emulation for direct interaction with real NT.
Basic use of an event scheduler: schedule simulation events, such as when to start an
FTP application, when to finish a simulation, or for simulation scenario generation prior to a simulation run.
![Page 13: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/13.jpg)
© Varaprasad Reddy 13
NS-2 EnvironmentSimulation Scenario
Tcl Script
C++ Implementation
1 2
set ns_ [new Simulator]
set node_(0) [$ns_ node]
set node_(1) [$ns_ node]
class MobileNode : public Node {
friend class PositionHandler;public: MobileNode();
••
}
![Page 14: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/14.jpg)
© Varaprasad Reddy 14
tcl Interpreter With Extents
otcl: Object-oriented support tclcl: C++ and otcl linkage Discrete event scheduler Data network (the Internet) components
tcl8.0
otcl
tclcl
ns-2EventScheduler
Netw
orkC
omponent
![Page 15: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/15.jpg)
© Varaprasad Reddy 15
NS-2 Hierarchy
A d dr
R e p lica to r
M C a s t
M P a th
H a sh
C la ss ife r
D e la y
A ge nt
A p p lica tion
Q ue ue
T ra ce
C o n ne c to r
N S O je ct
T c lO b je ct
![Page 16: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/16.jpg)
© Varaprasad Reddy 16
NS-2 Hierarchy
U D P
R B P
R e no
R B P
V eg as
S a ck1
N e w R e no
T ap
S in k
F u llT C P
A d ap tive
S R M
T C P D S D V A O D V T O R A D S R
A ge nt
T e ln e t
E xpo n en tia l
P are to
C B R
T ra ce
T ra ff ic
F T P
A p p lica tion
D ro p ta il
R E D
F Q
S F Q
D R R
C B Q
Q ue ue
E nq
D eq
D ro p
T ra ce
![Page 17: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/17.jpg)
© Varaprasad Reddy 17
NS-2 Directory Structure
sim
tk8.0 otcl Tcltcl8.0 ns-2 nam-1
tcl
ex test lib
...
...
tcl code
example
validation test
C++ code
tcl code core
![Page 18: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/18.jpg)
© Varaprasad Reddy 18
Node Architecture
Classifier
Classifier
Agent
Link
Agent
Agent
Node
Addr
Port
Node entry point
Local
Link Link
Agents are either protocol endpoints or related objects that generate/fill-in packet fields.
Classifiers: packet demultiplexers.
![Page 19: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/19.jpg)
© Varaprasad Reddy 19
Multicast Node architecture
![Page 20: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/20.jpg)
© Varaprasad Reddy 20
Packets (events)packet
Size determined at compile time
cmn header
Size determined at compile time
tcp header
Size determined at compile time
ip header
Size determined at compile time
trace header
bits( )
accessdata( )
next_Size
determined at
simulation config time
- packet size
- timestamp
- type
- UID
- interface label
Packet Structure
![Page 21: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/21.jpg)
© Varaprasad Reddy 21
Links
Enq Trace Deq Trace Rcv Trace
Drp Trace
Delay TTL
Drop head
QueueLink entry point
Links: keeps track of “from” and “to” node objects.blocked
![Page 22: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/22.jpg)
© Varaprasad Reddy 22
Link
Link
Application
N1 N2
Classifier
Classifier
Agent
Node
Addr
Port
LocalC
lassifier
Classifier
Agent
Node
Addr
Port
Local
Enq Trace Deq Trace Rcv Trace
Drp Trace
Delay TTL
Drop head
Queue
Application
![Page 23: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/23.jpg)
© Varaprasad Reddy 23
C++ is used for the creation of objects because of speed and efficiency.
NS-2 : C++ / OTCL
NS-2 Code contains two sets of languages, namely C++ and OTcl.
OTcl is used as a front-end to setup the simulator, configure objects and schedule events because of its ease of use.
![Page 24: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/24.jpg)
© Varaprasad Reddy 24
Why two languages? (Tcl & C++)
C++: Detailed protocol simulations require systems programming language byte manipulation, packet processing, algorithm
implementation Run time speed is important Turn around 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
![Page 25: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/25.jpg)
© Varaprasad Reddy 25
Tcl or C++?
TclSimple Configuration, Setup, Scenario If it’s something that can be done without
modifying existing Tcl module. C++
Anything that requires processing each packet
Needs to change behavior of existing module
![Page 26: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/26.jpg)
© Varaprasad Reddy 26
Shadowing
TclObject
Agent
Agent/DSDV
Agent/DSDV OTcl shadow object
Agent/DSDV C++ object
TclObject()
Agent()
DSDVAgent()
OTcl classhierarchy
C++ classhierarchy
![Page 27: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/27.jpg)
© Varaprasad Reddy 27
Agent/DSDVConstructor
AgentConstructor
Invoke parent
TclObjectConstructor
Invoke parent
AgentDSDV()Constructor
Create C++
Agent()Constructor
Invoke parent
TCL
C++
TclObject()Constructor
Invoke parentDo nothing,
returnbind and return
bind and return
OTcl shadow init complete init complete
Object Correspondence
![Page 28: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/28.jpg)
© Varaprasad Reddy 28
Outline
![Page 29: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/29.jpg)
© Varaprasad Reddy 29
NS-2 Directory Structure
sim
tk8.0 otcl Tcltcl8.0 ns-2 nam-1
tcl
ex test lib
...
...
tcl code
example
validation test
C++ code
tcl code core
![Page 30: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/30.jpg)
© Varaprasad Reddy 30
Making Changes in C++ Space
Existing coderecompile
Additionchange Makefile and recompile
![Page 31: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/31.jpg)
© Varaprasad Reddy 31
Making Changes in otcl Space
Existing coderecompilesource
Additionsourcechange Makefile (NS_TCL_LIB), tcl/ns-
lib.tcl (source) and recompile
![Page 32: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/32.jpg)
© Varaprasad Reddy 32
Installation
Unix variantsDownload NS-allinone-2.27 packageContains
TCL/TK 8.4.5 oTCL 1.8 Tclcl 1.15 Ns2 Nam -1
![Page 33: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/33.jpg)
© Varaprasad Reddy 33
Installation
After successful downloading and unzipping install allinone package , install NS by
install by calling ~/ns-allinone-2.27/install
After successful installation , Validate the scripts by running ./validate in ~/ns-allinone-2.27/ns-2.27/
Its now all set to work with NS
![Page 34: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/34.jpg)
© Varaprasad Reddy 34
Code for simple topology
Creating a Simulator Object set ns [new Simulator]
Setting up files for trace & NAM set trace_nam [open out.nam w] set trace_all [open all.tr w]
Tracing files using their commands $ns namtrace-all $trace_nam $ns trace-all $trace_all
![Page 35: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/35.jpg)
© Varaprasad Reddy 35
Code for simple topology
Closing trace file and starting NAMproc finish { } {
global ns trace_nam trace_all $ns flush-trace close $trace_nam close $trace_all exec nam out.nam & exit 0 }
![Page 36: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/36.jpg)
© Varaprasad Reddy 36
Code for simple topology
Creating LINK & NODE topologyCreating NODES
set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] set n4 [$ns node] set r1 [$ns node] set r2 [$ns node]
![Page 37: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/37.jpg)
© Varaprasad Reddy 37
Code for simple topology
Creating LINKS $ns duplex-link $N1 $R1 2Mb 5ms DropTail set DuplexLink0 [$ns link $N1 $R1] $ns duplex-link $N2 $R1 2Mb 5ms DropTail set DuplexLink1 [$ns link $N2 $R1] $ns duplex-link $R1 $R2 1Mb 10ms DropTail set DuplexLink2 [$ns link $R1 $R2] $ns duplex-link $R2 $N3 2Mb 5ms DropTail set DuplexLink3 [$ns link $R2 $N3] $ns duplex-link $R2 $N4 2Mb 5ms DropTail set DuplexLink4 [$ns link $R2 $N4]
![Page 38: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/38.jpg)
© Varaprasad Reddy 38
Code for simple topology
Orientation of links $ns duplex-link-op $N1 $R1 orient right-
down$ns duplex-link-op $N2 $R1 orient right-up$ns duplex-link-op $R1 $R2 orient right$ns duplex-link-op $R2 $N3 orient right-up$ns duplex-link-op $R2 $N4 orient right-down
![Page 39: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/39.jpg)
© Varaprasad Reddy 39
Final topology Generated
![Page 40: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/40.jpg)
© Varaprasad Reddy 40
Traffic topology aimed at
![Page 41: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/41.jpg)
© Varaprasad Reddy 41
Generating Traffic
Attaching AGENT TCP to NODE 1 set TCP1 [new Agent/TCP] $ns attach-agent $N1 $TCP1
Attaching AGENT TCP to NODE 2 set TCP2 [new Agent/TCP] $ns attach-agent $N2 $TCP2
Attaching AGENT TCP to NODE 3 set TCP3 [new Agent/TCPSink] $ns attach-agent $N2 $TCP3
Attaching AGENT TCP to NODE 4 set TCP4 [new Agent/TCPSink] $ns attach-agent $N2 $TCP4
![Page 42: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/42.jpg)
© Varaprasad Reddy 42
Generating Traffic
Attaching Application (FTP)set FTP0 [new Application/FTP]set FTP1 [new Application/FTP]$FTP0 attach-agent $TCP0$FTP1 attach-agent $TCP1
![Page 43: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/43.jpg)
© Varaprasad Reddy 43
Setting simulation times
$ns at 0.5 "$FTP0 start" $ns at 0.5 "$FTP1 start" $ns at 10.0 "$FTP0 stop" $ns at 10.0 "$FTP1 stop“ $ns at 10.0 “finish” Making NS run
$ns run
![Page 44: Network Simulator (NS-2) Internet Technologies 60-375](https://reader035.vdocuments.net/reader035/viewer/2022062219/551b3d8c550346d41a8b5543/html5/thumbnails/44.jpg)
© Varaprasad Reddy 44