?? 6node-multipath.tcl
字號:
#Create a simulator object
set ns [new Simulator]
#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
#Open the NAM trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#open a trace file
set tf [open out.tr w]
$ns trace-all $tf
#Define a 'finish' procedure
proc finish {} {
global ns nf tf
$ns flush-trace
#Close the NAM trace file
close $nf
close $tf
#Execute NAM on the trace file
exec nam out.nam &
exit 0
}
$ns rtproto DV
Node set multiPath_ 0
#Create four nodes
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]
#Create links between the nodes
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n5 2Mb 20ms DropTail
$ns duplex-link $n5 $n3 2Mb 25ms DropTail
$ns duplex-link $n2 $n4 2Mb 25ms DropTail
$ns duplex-link $n4 $n3 0.1Mb 20ms DropTail
$ns duplex-link $n2 $n6 2Mb 25ms DropTail
$ns duplex-link $n6 $n3 2Mb 20ms DropTail
$ns duplex-link $n3 $n7 2Mb 20ms DropTail
#Set Queue Size of link (n2-n3) to 10
$ns queue-limit $n2 $n4 10
$ns queue-limit $n2 $n5 10
#Give node position (for NAM)
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
#$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n2 $n4 orient right-up
$ns duplex-link-op $n4 $n3 orient right-down
$ns duplex-link-op $n3 $n5 orient right-up
$ns duplex-link-op $n2 $n5 orient right-down
$ns duplex-link-op $n2 $n6 orient right
$ns duplex-link-op $n6 $n3 orient right
$ns duplex-link-op $n3 $n7 orient right
#Monitor the queue for link (n2-n3). (for NAM)
$ns duplex-link-op $n2 $n4 queuePos 0.01
$ns duplex-link-op $n2 $n5 queuePos 0.01
$ns duplex-link-op $n2 $n6 queuePos 0.01
#Setup a TCP connection
set tcp [new Agent/TCP]
$tcp set class_ 2
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n7 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
#Setup a TCP connection //han
set tcp1 [new Agent/TCP]
$tcp1 set class_ 2
$ns attach-agent $n1 $tcp1
set sink1 [new Agent/TCPSink]
$ns attach-agent $n7 $sink1
$ns connect $tcp1 $sink1
$tcp1 set fid_ 2
#Setup a FTP over TCP connection
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ftp1 set type_ FTP
#Setup a UDP connection
#set udp [new Agent/UDP]
#$ns attach-agent $n1 $udp
#set null [new Agent/Null]
#$ns attach-agent $n7 $null
#$ns connect $udp $null
#$udp set fid_ 2
#Setup a CBR over UDP connection
#set cbr [new Application/Traffic/CBR]
#$cbr attach-agent $udp
#$cbr set type_ CBR
#$cbr set packet_size_ 1000
#$cbr set rate_ 10mb
#$cbr set random_ true
#Schedule events for the CBR and FTP agents
$ns at 0.1 "$ftp1 start"
$ns at 0.2 "$ftp start"
$ns at 4.0 "$ftp stop"
$ns at 4.5 "$ftp1 stop"
#Detach tcp and sink agents (not really necessary)
$ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n7 $sink"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Print CBR packet size and interval
#puts "CBR packet size = [$ftp1 set packet_size_]"
#puts "CBR interval = [$ftp1 set interval_]"
#Run the simulation
$ns run
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -