Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set ns [new Simulator]
- #Tell the simulator to use dynamic routing
- $ns rtproto Session
- set f [open ass1.tr w]
- set nf [open ass1.nam w]
- $ns namtrace-all $nf
- $ns trace-all $f
- proc finish { } {
- global ns f
- $ns flush-trace
- close $f
- exec nam ass1.nam &
- exit 0
- }
- set n0 [$ns node]
- set n1 [$ns node]
- set n2 [$ns node]
- set n3 [$ns node]
- set n4 [$ns node]
- set n5 [$ns node]
- set n6 [$ns node]
- set n7 [$ns node]
- set n8 [$ns node]
- set n9 [$ns node]
- # Node colors
- #$n0 color white
- $n0 color red
- $n1 color cyan
- $n2 color green
- $n5 color green
- $n6 color cyan
- $n9 color red
- #Duplex-links (bidirectional)
- $ns duplex-link $n0 $n1 20mb 10ms DropTail
- $ns duplex-link $n2 $n3 20mb 10ms DropTail
- $ns duplex-link $n3 $n4 20mb 10ms DropTail
- $ns duplex-link $n4 $n5 20mb 10ms DropTail
- $ns duplex-link $n0 $n3 20mb 10ms DropTail
- $ns duplex-link $n1 $n4 20mb 10ms DropTail
- $ns duplex-link $n7 $n8 20mb 10ms DropTail
- #Simplex-links (unidirectional)
- $ns simplex-link $n2 $n6 10mb 5ms SFQ
- $ns simplex-link $n3 $n7 10mb 5ms SFQ
- $ns simplex-link $n8 $n4 10mb 5ms SFQ
- $ns simplex-link $n5 $n9 10mb 5ms SFQ
- $ns simplex-link $n6 $n7 10mb 5ms SFQ
- $ns simplex-link $n9 $n8 10mb 5ms SFQ
- # Orientation
- $ns duplex-link-op $n0 $n1 orient right
- $ns duplex-link-op $n2 $n3 orient right
- $ns duplex-link-op $n3 $n4 orient right
- $ns duplex-link-op $n4 $n5 orient right
- $ns duplex-link-op $n0 $n3 orient down
- $ns duplex-link-op $n1 $n4 orient down
- $ns duplex-link-op $n7 $n8 orient right
- $ns simplex-link-op $n2 $n6 orient down
- $ns simplex-link-op $n3 $n7 orient down
- $ns simplex-link-op $n8 $n4 orient up
- $ns simplex-link-op $n5 $n9 orient down
- $ns simplex-link-op $n6 $n7 orient right
- $ns simplex-link-op $n9 $n8 orient left
- # Link colors
- $ns duplex-link-op $n3 $n4 color "magenta"
- $ns duplex-link-op $n7 $n8 color "magenta"
- # Link Label
- $ns duplex-link-op $n3 $n4 label "fail"
- $ns duplex-link-op $n7 $n8 label "fail"
- # fid colors
- $ns color 1 Red
- $ns color 2 Blue
- $ns color 3 green
- #TCP
- set tcp [new Agent/TCP]
- $ns attach-agent $n0 $tcp
- set sink [new Agent/TCPSink]
- $ns attach-agent $n9 $sink
- $ns connect $tcp $sink
- $tcp set fid_ 1
- $tcp set packetSize_ 1024
- #FTP
- set ftp [new Application/FTP]
- $ftp attach-agent $tcp
- $ftp set rate_ 0.02mb
- $ftp set type_ FTP
- $ftp set random_ true
- $ns at 0.0 "$ftp start"
- #UDP1
- set udp1 [new Agent/UDP]
- $ns attach-agent $n1 $udp1
- set null1 [new Agent/Null]
- $ns attach-agent $n6 $null1
- $ns connect $udp1 $null1
- $udp1 set fid_ 2
- #CBR1
- set cbr1 [new Application/Traffic/CBR]
- $cbr1 attach-agent $udp1
- $cbr1 set packetSize_ 512
- $cbr1 set rate_ 0.01mb
- $cbr1 set random_ false
- #UDP2
- set udp2 [new Agent/UDP]
- $ns attach-agent $n2 $udp2
- set null2 [new Agent/Null]
- $ns attach-agent $n5 $null2
- $ns connect $udp2 $null2
- $udp2 set fid_ 3
- #CBR2
- set cbr2 [new Application/Traffic/CBR]
- $cbr2 attach-agent $udp2
- $cbr2 set packetSize_ 512
- $cbr2 set rate_ 0.01mb
- $cbr2 set random_ true
- #Schedule events for the CBR agent and the network dynamics
- $ns at 0.0 "$cbr1 start"
- $ns at 0.0 "$cbr2 start"
- $ns rtmodel-at 5.0 down $n3 $n4
- $ns rtmodel-at 55.0 up $n3 $n4
- $ns rtmodel-at 20.0 down $n7 $n8
- $ns rtmodel-at 40.0 up $n7 $n8
- $ns at 100.0 "$cbr1 stop"
- $ns at 100.0 "$cbr2 stop"
- $ns at 100.0 "finish"
- $ns run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement