A Tutorial on Network A Tutorial on Network A Tutorial on Network A Tutorial on Network Simulator Simulator Simulator Simulator ---- nsnsnsns----2222
Oct, 2001Wendy Huang ( [email protected] )
Anthony Liu ( [email protected] )
2001/10/18 NS2 Tutorial by WIRE Laboratory 2
Contents
1.Ns-2 Components2.Ns-2 Installation3.Objects4.The Language
5.Ns-2 by Examples6.References
2001/10/18 NS2 Tutorial by WIRE Laboratory 3
1.Ns-2 Components
Tcl/TkotclTclCL (formerly known as libTcl) ns-2nam-1 (optional) xgraph (optional)perl (optional)
Though some are optional, we suggest you install all-in-onepackage. Also, though ns2 is available for Windows platforms, we do not suggest because it’s tricky to install and use it on those platforms.
Though some are optional, we suggest you install all-in-onepackage. Also, though ns2 is available for Windows platforms, we do not suggest because it’s tricky to install and use it on those platforms.
2001/10/18 NS2 Tutorial by WIRE Laboratory 4
1.Ns-2 Components (Cont.)
tcl-debug (optional)dmalloc (optional)sgb2ns conversion program (optional)tiers2ns conversion program(optional)Cweb and sgb source code (optional)
2001/10/18 NS2 Tutorial by WIRE Laboratory 6
1.Ns-2 Components (Cont.)
To provide components better performance, C++ and OTcl are glued together.
To provide components better performance, C++ and OTcl are glued together.
The compound architecture of ns2The compound architecture of ns2
2001/10/18 NS2 Tutorial by WIRE Laboratory 7
2.Ns-2 Installation
Get the all-in-one package from website:http://www.isi.edu/nsnam/dist/ns-allinone-2.1b8a.tar.gz
Untar with the following command on Unix like platforms:tar zxf ns-allinone-2.1b8a.tar.gz
Move directory ns-2.1b8a to a place with enough space (Requires 200MB)
Build with:cd ns-2.1b8a ; ./install The 200MB requirement does
not include source tar ball.The 200MB requirement does not include source tar ball.
2001/10/18 NS2 Tutorial by WIRE Laboratory 8
2.Ns-2 Installation (Cont.)
After compilation, validation is also needed.For any problem or troubleshooting, please contact your nearest computer freak classmates. ☺
You might need to configure your environment variables to accommodate ns-2 execution requirements.
You might need to configure your environment variables to accommodate ns-2 execution requirements.
Ns-2 is installed on CS workstations!!! Further info required by T.A.’s.
Ns-2 is installed on CS workstations!!! Further info required by T.A.’s.
Validation would not pass on Linux with CLE. RedHat7.1 English version is successfully validated.
Validation would not pass on Linux with CLE. RedHat7.1 English version is successfully validated.
2001/10/18 NS2 Tutorial by WIRE Laboratory 9
3.Objects
SimulatorNodesLinksAgentsTraffics
The objects are interconnected by using member functions to attach each other.
The Simulator is an exceptions, which is a container object
The objects are interconnected by using member functions to attach each other.
The Simulator is an exceptions, which is a container object
2001/10/18 NS2 Tutorial by WIRE Laboratory 10
3.Objects (Cont.)
The relationship between objects of ns-2 can be uncovered from this figure.
The relationship between objects of ns-2 can be uncovered from this figure. I’ll be back.I’ll be back.
2001/10/18 NS2 Tutorial by WIRE Laboratory 12
4.The Language
OTclNo declaration needed in advanceVariables declared as usedVariables referred with $ as prefixObject creation: [new CLASS_NAME]Comments starting with #
2001/10/18 NS2 Tutorial by WIRE Laboratory 13
4.1 Language Basics
Variables referred with $ as prefixVariables referred with $ as prefix
Procedure SupportedProcedure Supported
No declaration needed in advanceNo declaration needed in advance
Variables declared as usedVariables declared as used
Comments with #Comments with #
2001/10/18 NS2 Tutorial by WIRE Laboratory 14
4.1 Language Basics (Cont.)
Object creation: [new CLASS_NAME]Object creation: [new CLASS_NAME]
Instproc Member functionInstproc Member function
Inherit with -superclassInherit with -superclass
Class defines a classClass defines a class
Self reference with $selfSelf reference with $self
puts message outputs message out
Classwide variable with instvarClasswide variable with instvar
Calling member function Calling member function
2001/10/18 NS2 Tutorial by WIRE Laboratory 15
4.2 Total Recall
Variables (declarations, references)
Class (declarations, references, member functions , self reference, classwide variables)
Objects (Create, calling a member function, )
I still have no idea about syntax !!! (Have you ever heard two functions called copy and paste?)
Piece of Cake? (Cheese flavor please)
2001/10/18 NS2 Tutorial by WIRE Laboratory 16
5.Ns-2 by Examples
Ex: Two Nodes with trafficEx: XGraph example (graph only)EX: XGraph plus Nam (graph only)
2001/10/18 NS2 Tutorial by WIRE Laboratory 17
5.1 Ex1 Sourceset ns [new Simulator]
set nf [open ex1.nam w]
$ns namtrace-all $nf
proc finish {} {global ns nf
$ns flush-traceclose $nfexec nam ex1.nam &exit 0
}
# Create two nodes: 0, 1set n0 [$ns node]set n1 [$ns node]
# Connect $n0 and $n1$ns duplex-link $n0 $n1 1Mb 10ms DropTail
# Create a UDP agent and attach# it to node n0set udp0 [new Agent/UDP]$ns attach-agent $n0 $udp0
# Create a CBR traffic source# and attach it to udp0set cbr0 [new Application/Traffic/CBR]$cbr0 set packetSize_ 500$cbr0 set interval_ 0.005$cbr0 attach-agent $udp0
# Create a Null agent which acts # as traffic sink and attach it to node n1set null0 [new Agent/Null]$ns attach-agent $n1 $null0# Now the two agents have to # be connected with each other$ns connect $udp0 $null0
# Timer bound is 5 seconds.$ns at 5.0 "finish"
# Start Simulation$ns at 0.5 "$cbr0 start"$ns at 4.5 "$cbr0 stop"
$ns run
Save this file as ex1.tcl, run ‘ns ex1.tcl’ on X Window, you will see.
Save this file as ex1.tcl, run ‘ns ex1.tcl’ on X Window, you will see.
Two Nodes with traffic
2001/10/18 NS2 Tutorial by WIRE Laboratory 18
Ex 1 Screen Shot A single nam console occurs after the execution. And an animation window occurs for the ex1.tcl, click the play and adjust the step, see what happends!
A single nam console occurs after the execution. And an animation window occurs for the ex1.tcl, click the play and adjust the step, see what happends!
2001/10/18 NS2 Tutorial by WIRE Laboratory 19
More Screen Shot
One nam console instance with 2 nam animator instances (can be more, of course.)
One nam console instance with 2 nam animator instances (can be more, of course.)
Multiple Nam Instances
2001/10/18 NS2 Tutorial by WIRE Laboratory 22
6.ReferencesNs-2 Homesite: � http://www.isi.edu/nsnam/ns/
OTcl Tutorials:� MIT Version: ftp://ftp.tns.lcs.mit.edu/pub/otcl/README.html� Berkeley Version: http://bmrc.berkeley.edu/research/cmt/cmtdoc/otcl
Ns-2 By Examples: � http://nile.wpi.edu/NS/
Ns-2 Tutorial (By Marc Gresis): � http://www.isi.edu/nsnam/ns/tutorial/index.html
Ns-2 Manual: � http://www.isi.edu/nsnam/ns/doc/index.html