Académique Documents
Professionnel Documents
Culture Documents
NS by example /
How the simulator works How to setup simulation networks Where to look for further information How to create new network components
Overview (1)
NS (version 2)
Object-oriented Discrete event driven network simulator Written in C++/OTcl LAN/WAN simulation Emulation Analysis/animation results (e.g. NAM)
Overview (2)
Wired world
Routing (ip, multicast routing) Transportation: TCP UDP, multicast transport Traffic sources: web, ftp, telnet, CBR, stochastic Queuing disciplines: drop-tail, RED, FQ, SFQ QoS: IntServ Diffserv Ad hoc routing and mobile IP Directed diffucion, sensor-MAC
Wireless
Architectural View of NS
<user>
Basic Tcl
variables: set x 10 puts x is $x functions and expressions: set y [pow x 2] set y [expr x*x]
procedures: proc pow {x n} { if {$n == 1} { return $x } set part [pow x [expr $n-1]] return [expr $x*$part] }
. network topologies traffic models.
control flow: if {$x > 0} { return $x } else { return [expr -$x] } while { $x > 0 } { puts $x incr x 1 }
Sandra:> ns ex-tcl.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
Sandra:> ns ex-otcl.tcl 45 year old mom say: How are you doing? 15 year old kid say: Whats up dude?
Hello World
Interactive mode:
sandra% ns % set ns [new Simulator] _o3 % $ns at 1 puts \Hello World!\ 1 % $ns at 1.5 exit 2 % $ns run Hello World! sandra%
exit 0
} #Create nodes and link set n0 [$ns node] set n1 [$ns node] $ns duplex-link $n0 $n1 1Mb 10ms DropTail #Create a UDP agent and attach it to node n0 set udp0 [new Agent/UDP] $ns attach-agent $n0 $udp0
$ns duplex-link $n0 $n2 1Mb 10ms DropTail $ns duplex-link $n1 $n2 1Mb 10ms DropTail $ns duplex-link $n3 $n2 1Mb 10ms DropTail
#Create a UDP agent and attach it to node n1 set udp1 [new Agent/UDP] $ns attach-agent $n1 $udp1 $ns at 0.5 "$cbr0 start" $ns at 1.0 "$cbr1 start" $ns at 4.0 "$cbr1 stop" $ns at 4.5 "$cbr0 stop"
Queue management
$ns duplex-link-op $n2 $n3 queuePos 0.5
#Open the NAM trace file set nf [open out.nam w] $ns namtrace-all $nf
#Define a 'finish' procedure proc finish {} { global ns nf $ns flush-trace #Close the NAM trace file close $nf #Execute NAM on the trace file exec nam out.nam & exit 0 }
$ns color fid color $ns namtrace-all file-descriptor proc finish {} set n0 [$ns node] $ns duplex-link node1 node2 bandwidth delay queue-type $ns queue-limit node1 node2 number $ns duplex-link-op node1 node2 ...
set tcp [new Agent/TCP] $ns attach-agent node agent $ns connect agent1 agent2
Event Scheduler
Simulator-Scheduler Functions
# return scheduler's notion of current time # schedule execution of code at specified time
Links
Tracing
Queue Monitor
NS Packet Format
LAN Example
set opt(app)
FTP
proc finish {} { global ns opt trfd ntrfd $ns flush-trace close $trfd close $ntrfd exec nam $opt(namtr) & exit 0
}
}