Академический Документы
Профессиональный Документы
Культура Документы
*some slides are from a presentation by Haobo Yu & Nader Salehi, USC/ISI
Installation instructions
Using related tools (nam, xgraph, etc) NS-2 official website and documentation
Part I: ns Primer
What is ns?
Object-oriented, discrete event-driven network simulator Written in C++ and OTcl By VINT: Virtual InterNet Testbed
ns Architecture
What is ns?
Object-oriented, discrete event-driven network simulator Written in C++ and OTcl By VINT: Virtual InterNet Testbed
ns Architecture
ns Architecture
ns [new Simulator]
at 1 puts \Hello World!\ at 1.5 exit
run World!
bash-shell$
bash-shell$ ns simple.tcl
Hello World!
bash-shell$
Basic OTcl
Class Mom Mom instproc greet {} { $self instvar age_ puts $age_ years old mom: How are you doing? } Class Kid -superclass Mom Kid instproc greet {} { $self instvar age_ puts $age_ years old kid: Whats up, dude? } set mom [new Mom] $mom set age_ 45 set kid [new Kid] $kid set age_ 15 $mom greet $kid greet
Create Simulator object [Turn on tracing] Create topology [Setup packet loss, link dynamics] Create routing agents Create application and/or traffic sources Post-processing procedures (i.e. nam) Start simulation
Step2: Tracing
Step2: Tracing
Create Simulator object [Turn on tracing] Create topology [Setup packet loss, link dynamics] Create routing agents Create application and/or traffic sources Post-processing procedures (i.e. nam) Start simulation
n1
n0
Nodes
n1
Create Simulator object [Turn on tracing] Create topology [Setup packet loss, link dynamics] Create routing agents Create application and/or traffic sources Post-processing procedures (i.e. nam) Start simulation
Link failures Hooks in routing module to reflect routing changes $ns rtmodel-at <time> up|down $n0 $n1 For example:
$ns rtmodel-at 1.0 down $n0 $n1 $ns rtmodel-at 2.0 up $n0 $n1
n0
cbr
udp
n0
null
n0
ftp
FTP set ftp [new Application/FTP] $ftp attach-agent $tcp Telnet set telnet [new Application/Telnet] $telnet attach-agent $tcp
tcp
n0
n1
sink
set ns [new Simulator] [Turn on tracing] Create topology [Setup packet loss, link dynamics] Create agents Create application and/or traffic sources Post-processing procedures (i.e. nam) Start simulation
Examples
Post-Processing Procedures
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 }
Run Simulation
Schedule Events
Call finish $ns at 5.0 "finish" Run the simulation $ns run
set ns [new Simulator] [Turn on tracing] Create topology [Setup packet loss, link dynamics] Create routing agents Create application and/or traffic sources Post-processing procedures (i.e. nam) Start simulation
Examples
Visualization Tools
xgraph
Color
$node color red
Color $ns duplex-link-op $n0 $n1 color "green" Label $ns duplex-link-op $n0 $n1 label backbone"
Simulation Example
Examples
C++ ns
OTcl
TclObject
Agent
Agent/TCP _o123
Agent/TCP OTcl shadow object
TcpAgent *tcp
Agent/TCP C++ object
Extending ns
In OTcl In C++
ns-allinone
Tcl8.0
TK8.0
OTcl tcl
ns-2
nam-1
C++ code
ex
examples
test
validation tests
mcast
OTcl code
...
Extending ns in OTcl
tclcl ...
ns-2
nam-1
C++ code
test
validation tests
mysrc msg.tcl
lib
mcast
OTcl code
...
Extending ns in C++
Modifying code
OTcl Linkage
set the default value for the variables in the "ns-2/tcl/lib/ns-lib.tcl" file
Step 5: Compile
Save above code as ex-linkage.cc Open "Makefile", add "ex-linkage.o" at the end of object file list. Re-compile NS using the "make" command.