- set ns [new Simulator]
- $ns color 1 Blue
- $ns color 2 Red
- $ns color 3 Green
- set nf [open out.nam w]
- $ns namtrace-all $nf
- set tf [open out.tr w]
- $ns trace-all $tf
- proc finish {} {
- global ns nf tf
- $ns flush-trace
- close $nf
- close $tf
- exec nam out.nam &
- exit 0
- }
- set r1 [$ns node]
- set m1 [$ns node]
- set n1 [$ns node]
- set n2 [$ns node]
- set n3 [$ns node]
- set n4 [$ns node]
- set r2 [$ns node]
- set m2 [$ns node]
- set n5 [$ns node]
- set n6 [$ns node]
- set n7 [$ns node]
- set n8 [$ns node]
- set r3 [$ns node]
- set m3 [$ns node]
- set n9 [$ns node]
- set n10 [$ns node]
- set n11 [$ns node]
- set n12 [$ns node]
- set lan0 [$ns newLan "$r1 $r2 $r3 " 1Mb 10ms LL Queue/DropTail MAC/Csma/Ca Channel]
- set lan1 [$ns newLan "$r1 $m1 $n1 $n2 $n3 $n4" 1.5Mb 10ms LL Queue/DropTail MAC/Csma/Ca Channel]
- set lan2 [$ns newLan "$r2 $m2 $n5 $n6 $n7 $n8" 1.5Mb 10ms LL Queue/DropTail MAC/Csma/Ca Channel]
- set lan3 [$ns newLan "$r3 $m3 $n9 $n10 $n11 $n12" 1.5Mb 10ms LL Queue/DropTail MAC/Csma/Ca Channel]
- set tcp [new Agent/TCP]
- $ns attach-agent $n1 $tcp
- set sink1 [new Agent/TCPSink]
- set sink2 [new Agent/TCPSink]
- $ns attach-agent $n9 $sink1
- $ns attach-agent $n12 $sink2
- $ns connect $tcp $sink1
- $ns connect $tcp $sink2
- $tcp set fid_ 1
- set ftp [new Application/FTP]
- $ftp attach-agent $tcp
- $ftp set type_ FTP
- set udp1 [new Agent/UDP]
- $ns attach-agent $m1 $udp1
- set udp2 [new Agent/UDP]
- $ns attach-agent $n2 $udp2
- set null1 [new Agent/Null]
- set null2 [new Agent/Null]
- set null3 [new Agent/Null]
- $ns attach-agent $n6 $null1
- $ns attach-agent $n12 $null2
- $ns connect $udp1 $null1
- $ns connect $udp2 $null2
- $udp1 set fid_ 2
- $udp2 set fid_ 3
- set cbr1 [new Application/Traffic/CBR]
- $cbr1 attach-agent $udp1
- $cbr1 set type_ CBR
- $cbr1 set packet_size_ 1000
- $cbr1 set rate_ 1mb
- $cbr1 set random_ 1
- set cbr2 [new Application/Traffic/CBR]
- $cbr2 attach-agent $udp2
- $cbr2 set type_ CBR
- $cbr2 set packet_size_ 1000
- $cbr2 set rate_ 1mb
- $cbr2 set random_ 1
- $ns at 0.1 "$ftp start"
- $ns at 1 "$cbr1 start"
- $ns at 2 "$cbr2 start"
- $ns at 4 "$ftp stop"
- $ns at 3 "$cbr1 stop"
- $ns at 5.0 "$cbr2 stop"
- $ns at 5.5 "finish"
- $ns run