Zak Abichar, abicharz@iastate.edu Dept of Electrical and Computer Engineering Iowa State University Ames, IA 50011
Based on a presentation by Polly Huang (2nd European ns-2 Workshop, April 2001)
Tutorial Goals
overview/intro/essentials/getting started tcl/otcl/ns-2 fundamentals designing a simulation examples
Outline
Introduction
The project, the software, the philosophy Software architecture Installation and getting started About extending ns-2
tcl/otcl/ns-2 fundamentals
Programming tcl/otcl
Follow-up projects
SAMAN: scenario and performance CONSER: educational use
4
Multi-state collaboration
AT&T Research Lawrence Berkeley National Laboratory UC Berkeley USC/ISI Xerox PARC ETH TIK (Swiss Federal Institute of Technology)
5
Project Goal
To support collaborative simulation effort
promote sharing
incorporate recent simulation models
ns-2
Discrete event simulator Packet level Link layer and up Wired and wireless
Development Status
Columbia NEST UCB REAL ns-1 ns-2
100K lines of C++ code 70K lines of otcl support code 30K lines of test suites 20K lines of documentation
8
Releases
periodic official releases nightly snapshots (probably compiles and works, but buyers beware) available from USC/ISI or UK mirror
9
Platforms
Most UNIX and UNIX-like systems
FreeBSD or *BSD Linux Sun Solaris # HP, SGI
Words of Caution
While we have considerable confidence in ns, ns is not a polished and finished product, but the result of an ongoing effort of research and development. In particular, bugs in the software are still being discovered and corrected. Users of ns are responsible for verifying for themselves that their simulations are not invalidated by bugs.
11
The downside
Cannot capture all the nuances of the real world networks. Very large scale simulations take a lot of time they may not be feasible Still in the research phase, and there may be many more bugs lurking out there Documentation not adequate No fancy user interface often perceived as unfriendly (at least by people who are new to ns-2)
15
Outline
Introduction
The project, the software, the philosophy Software architecture Installation and getting started About extending ns-2
tcl/otcl/ns-2 fundamentals
Programming tcl/otcl
Object-Oriented
+ Reusability + Maintainability Careful planning ahead Performance
17
otcl
19
otcl: Object-oriented support tclcl: C++ and otcl linkage Discrete event scheduler Data network components
20
Installation
Getting the code:
http://www.isi.edu/nsnam/ns/
Installing ns-2
http://csl.ee.iastate.edu/~cpre543/ns2_howToInstall.htm
21
Outline
Introduction
The project, the software, the philosophy Software architecture Installation and getting started About extending ns-2
tcl/otcl/ns-2 fundamentals
Programming tcl/otcl
Hello World
simple.tcl
set ns [new Simulator] $ns at 1 puts \Hello World!\ $ns at 1.5 exit $ns run
Fundamentals
tcl otcl
ftp://ftp.tns.lcs.mit.edu/pub/otcl/doc/tutorial.html
ns-2
http://www.isi.edu/nsnam/ns/ns_doc.ps.gz http://www.isi.edu/nsnam/ns/ns_doc.pdf http://www.isi.edu/nsnam/ns/doc/index.html
25
proc test {} { set a 43 set b 27 set c [expr $a + $b] set d [expr [expr $a - $b] * $c] for {set k 0} {$k < 10} {incr k} { if {$k < 5} { puts k < 5, pow= [expr pow($d, $k)] } else { puts k >= 5, mod= [expr $d % $k] } } } test
Basic tcl
k < 5, pow = 1.0 k < 5, pow = 1120.0 k < 5, pow = 1254400.0 k < 5, pow = 1404928000.0 k < 5, pow = 1573519360000.0 k > 5, mod = 0 k > 5, mod = 4 k > 5, mod = 0 k > 5, mod = 0 k > 5, mod = 4
26
Basic otcl
Class mom mom instproc init {age} { $self instvar age_ set age_ $age } mom instproc greet {} { $self instvar age_ puts $age_ years old mom: How are you doing? }
34 years old mom: How are you doing? 6 years old kid: What's up?
Class kid -superclass mom kid instproc greet {} { $self instvar age_ puts $age_ years old kid: Whats up, dude? } set a [new mom 34] set b [new kid 6] $a greet $b greet
27
Outline
Introduction
The project, the software, the philosophy Software architecture Installation and getting started About extending ns-2
tcl/otcl/ns-2 fundamentals
Programming tcl/otcl
29
Running a Simulation
Design your simulation Build NS-2 scripts Run simulation program Analyze trace files Visualize your simulation (Animation)
30
Specify Agents
Protocol
31
A simulation example
32
n1
Traffic Generation set ftp [new Application/FTP] $ftp attach-agent $tcp $ns at 0.2 "$ftp start" $ns at 1.2 exit" $ns run
33
34
35
37
38
Outline
Introduction
The project, the software, the philosophy Software architecture Installation and getting started About extending ns-2
tcl/otcl/ns-2 fundamentals
Programming tcl/otcl
A Simulation Example
40
41
42
#Setup a TCP connection set tcp [new Agent/TCP] $ns attach-agent $n0 $tcp set sink [new Agent/TCPSink] $ns attach-agent $n3 $sink $ns connect $tcp $sink #Setup a FTP over TCP connection set ftp [new Application/FTP] $ftp attach-agent $tcp
43
#Setup a CBR over UDP connection set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $cbr set packet_size_ 1000 $cbr set rate_ 1mb
44
46