ns2-lecture
ns2-lecture
n0 n1
n0 n1
n0 n1
udp
udp
n0 n1
udp
udp
cbr
cbr
n0 n1
udp
udp null
null
cbr
cbr
n0 n1
udp
udp null
null
cbr
cbr
n2 n3
router receiver
n1
sender
n2 n3
router receiver
n1
sender
n2 n3
router receiver
n1
sender
# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
Simulate a simple topology – UDP Traffic
sender
n0
n2 n3
router receiver
n1
sender
n2 n3
router receiver
n1
sender
# Create a CBR traffic source and attach it to udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr1 attach-agent $udp1
Simulate a simple topology – UDP
sender
Traffic
n0
n2 n3
router receiver
n1
sender
#Create a Null agent (a traffic sink) and attach it to node
n3
set null0 [new Agent/Null]
$ns attach-agent $n3 $null0
Simulate a simple topology – UDP
sender
Traffic
n0
n2 n3
router receiver
n1
sender
s2 G r
sender gateway receiver
s3
sender
• 0, 1, 2 are senders
• 3 is a Gateway
• 4 receiver
TCP Traffic
• #Create a TCP agent and attach it to node s1
• set tcp1 [new Agent/TCP/Reno]
• $ns attach-agent $s1 $tcp1
• $tcp1 set window_ 8
• $tcp1 set fid_ 1
TCP Traffic
• #Create a TCP agent and attach it to node s2
• set tcp2 [new Agent/TCP/Reno]
• $ns attach-agent $s2 $tcp2
• $tcp2 set window_ 8
• $tcp2 set fid_ 2
sender
0
6 1
5 2
4 3 receiver
Complex topology and link failure
#Create a simulator object
set ns [new Simulator]
#Tell the simulator to use dynamic routing
$ns rtproto DV
#Define a 'finish' procedure
proc finish {} {
global ns
$ns flush-trace
exit 0
}
Complex topology and link failure
#Create seven nodes
for {set i 0} {$i < 7} {incr i} {
set n($i) [$ns node]
}
#Create links between the nodes
for {set i 0} {$i < 7} {incr i} {
$ns duplex-link $n($i) $n([expr ($i+1)%7]) 1Mb 10ms
DropTail
}
Complex topology and link failure
• #Create a UDP agent and attach it to node n(0)
• # Create a CBR traffic source and attach it to udp0
• #Create a Null agent (a traffic sink) and attach it to node n(3)
• #Connect the traffic source with the traffic sink
#Schedule events for the CBR agent and the network dynamics
$ns at 0.5 "$cbr0 start"
$ns rtmodel-at 1.0 down $n(1) $n(2)
$ns rtmodel-at 2.0 up $n(1) $n(2)
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulation
$ns run
Wireless Linear Topology
1 2 3 4 … n