Académique Documents
Professionnel Documents
Culture Documents
Goals
Extending NS2
Schedule
Presentation (60 min) Group Assignments (10 min) Practices (1 Hr) Q & A session (~15 min)
Talk Overview
What is ns-2? (the evolution) Architecture Basic Tcl/Otcl commands Elements of an ns-2 simulation Example Online Resources & Documentation
What is ns?
A discrete event, packet-level simulator Targeted at networking research Supports the simulation of intserv/diffserv, Multicast, Transport, Applications, Wireless (fixed, mobile, satellite) REAL variant (1989)DARPA (LBL, Xerox PARC, UCB, and USC/ISI) (1995) Ns-3 Project (Ongoing)
Status
ns-2
100K lines of C++ 70K lines of OTcl 50K+ lines of test suite, examples, docs
Platforms
Most UNIX and UNIX-like systems (FreeBSD, Linux, Sun Solaris) Window 95/98/NT with Cygwin (Emulation only for FreeBSD for now)
Remember!
A simulator model of a real-world system is necessarily a simplification. For example, in simulating TCP
Bugs: Users of ns are responsible for verifying for themselves that their simulations are not invalidated by bugs.
7
Architecture: Object-Oriented
C++
OTcl
ns
9
11
Basic Tcl
set a 43 set b 27 proc test { a b } { 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 43 27
12
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
13
14
Create the event scheduler [Turn on tracing] Create network Setup routing Insert errors Create transport connection Create traffic Transmit application-level data
15
set ns [new Simulator] $ns at <time> <event> <event>: any legitimate ns/tcl commands $ns run
Schedule events
Start scheduler
16
Tracing
<event> <time> <from> <to> <pkt> <size> + 1 0 2 cbr 210 ------- 0 0.0 3.1 0 - 1 0 2 cbr 210 ------- 0 0.0 3.1 0 r 1.00234 0 2 cbr 210 ------- 0 0.0
Tracing
18
Creating Network
Nodes
set n0 [$ns node] set n1 [$ns node] $ns duplex-link $n0 $n1 <bandwidth> <delay> <queue_type> <queue_type>: DropTail, RED, CBQ, FQ, SFQ, DRR
19
LAN
$ns make-lan <node_list> <bandwidth> <delay> <ll_type> <ifq_type> <mac_type> <channel_type> <ll_type>: LL <ifq_type>: Queue/DropTail, <mac_type>: MAC/802_3 <channel_type>: Channel
20
set loss_module [new ErrorModel] $loss_module set rate_ 0.01 $loss_module unit pkt $loss_module ranvar [new RandomVariable/Uniform] $loss_module drop-target [new Agent/Null] $ns lossmodel $loss_module $n0 $n1
21
Network Dynamics
Link failures
Four models
$ns $ns $ns $ns
Parameter list
[<start>] <up_interval> <down_interval> [<finish>]
22
Setup Routing
Unicast
$ns rtproto <type> <type>: Static, Session, DV, cost, multi-path $ns multicast (right after [new Simulator])
Multicast
$ns mrtproto <type> <type>: CtrMcast, DM, ST, BST (centralized,dense mode, shared tree
23
UDP
set udp [new Agent/UDP] set null [new Agent/Null] $ns attach-agent $n0 $udp $ns attach-agent $n1 $null $ns connect $udp $null
24
CBR
set src [new Application/Traffic/CBR] set src [new Application/Traffic/Exponential] set src [new Application/Traffic/Pareto]
25
TCP
set tcp [new Agent/TCP] set tcpsink [new Agent/TCPSink] $ns attach-agent $n0 $tcp $ns attach-agent $n1 $tcpsink $ns connect $tcp $tcpsink
26
FTP
set ftp [new Application/FTP] $ftp attach-agent $tcp set telnet [new Application/Telnet] $telnet attach-agent $tcp
Telnet
27
Trace driven
set tfile [new Tracefile] $tfile filename <file> set src [new Application/Traffic/Trace] $src attach-tracefile $tfile Binary format (native!) inter-packet time (msec) and packet size (byte)
<file>:
28
Application-Level Simulation
Features
Build on top of existing transport protocol Transmit user data, e.g., HTTP header TCP: Application/TcpApp UDP: Agent/Message
29
30
31
4x4 grid
240m
11 13 14
8 4 2 3
11
7
33
Example: Step 1
Define Parameters
set set set set cbr_size 500 cbr_interval 0.002 num_row 4 time_duration 100
34
Example: Step 2
Protocol Options
set val(chan) Channel/WirelessChannel ;# channel type set val(prop) Propagation/TwoRayGround ;# radiopropagation model set val(netif) Phy/WirelessPhy ;# network interface type set val(mac) Mac/802_11 ;# MAC type set val(ifq) Queue/DropTail/PriQueue ;# interface queue type set val(ll) LL ;# link layer type set val(ant) Antenna/OmniAntenna ;# antenna model set val(ifqlen) 50 ;# max packet in ifq set val(rp) DSDV ;# routing protocol
35
Example: Step 3
36
Example: Step 4
Example: Step 5
Create Topology
set k 0; while {$k < $num_row } { for {set i 0} {$i < $num_row } {incr i} { set m [expr $i+$k*$num_row]; $node_($m) set X_ [expr $i*240]; $node_($m) set Y_ [expr $k*240+20.0]; $node_($m) set Z_ 0.0 } incr k; };
38
Example: Step 6
Create Mobility
#Move node 11 from its original place to top-right corner $ns_ at 60.0 "$node_(11) setdest 990.0 990.0 15.0
Example: Step 7
for {set i 0} {$i < $num_row } {incr i} { set udp_($i) [new Agent/UDP] set null_($i) [new Agent/Null] } $ns_ attach-agent $node_(8) $udp_(0) $ns_ attach-agent $node_(4) $udp_(1) $ns_ attach-agent $node_(13) $udp_(2) $ns_ attach-agent $node_(14) $udp_(3) $ns_ attach-agent $node_(11) $null_(0) $ns_ attach-agent $node_(7) $null_(1) $ns_ attach-agent $node_(2) $null_(2) $ns_ attach-agent $node_(3) $null_(3) for {set i 0} {$i < $num_row } {incr i} { $ns_ connect $udp_($i) $null_($i) } 40
Example: Step 8
for {set i 0} {$i < $num_row } {incr i} { set cbr_($i) [new Application/Traffic/CBR] $cbr_($i) set packetSize_ $cbr_size $cbr_($i) set interval_ 0.5 $cbr_($i) attach-agent $udp_($i) } $ns_ at 11.0234 "$cbr_(0) start" $ns_ at 10.4578 "$cbr_(1) start" $ns_ at 12.7184 "$cbr_(2) start" $ns_ at 12.2456 "$cbr_(3) start"
41
Example: Step 9
42
Auxiliary Tools
setdest
used to generate the positions of nodes and their moving speed and moving directions.
setdest -v 1 -n 50 -p 0 -M 20 -t 900 -x 1500 -y 300
cbrgen.tcl
ns cbrgen.tcl [-type cbr|tcp] [-nn nodes] [-seed seed] [-mc connections] [-rate rate]
43
Resources
44
Documentation
http://dev.scriptics.com/scripting
~otcl/doc/tutorial.html (in distribution) Included in distribution: ~ns/doc http://www.isi.edu/~salehi/ns_doc.ps.gz
45
ns manual
Advanced Topics
Trace analysis Architecture of Mobilenode Object Extending NS-2 with new protocols and algorithms More complex changes:
46
Group Assignments
Download simple.tcl
http://www.winlab.rutgers.edu/~zhibinwu/simple.tcl
Modifications Node-Configure changes Random topology generation 40-node within 1000x1000 area Random Node Mobility Changeprotocol from UDP to TCP Dynamic Traffic change
47