當前的佇列管理演算法可以分為兩大類:被動式佇列管理(Passive Queue Management,PQM)和主動式佇列管理(Active Queue Management,AQM)。管理路由器佇列長度的傳統技術是對每個佇列設置一個最大值(以封包為單位),然後接受封包進入佇列直到佇列長達到最大值,接下來到達的封包就會被拒絕進入佇列直到佇列的長度下降。這種技術也就是所謂的"去尾"(drop-tail)演算法。雖然這個方法在當前Internet上得到了廣泛的使用,但其存在幾個重大缺陷,其中之一就是全局同步(global synchronization)問題:由於Internet上數據(Traffic)的突發本質(Burstiness),到達路由器的封包也往往是突發的。如果佇列是滿的或者幾乎是滿的,就會導致在短時間內連續大量地丟封包。而TCP流具有自適應特性(Adaptiveness),來源端發現封包丟失就急劇地減小發送窗口(congestion window),封包到達速率就會迅速下降,於是網絡擁塞得以解除,但來源端得知網路不再擁塞後又開始增加發送速度,最終又造成網路擁塞,而且這種現象常常會週而復始地進行下去,從而在一段時間內網路處於網路利用率(Network Utilization)很低的用狀態,降低了整體吞吐量(Throughput),這就是所謂地"TCP全局同步"現象。
而本小節最主要的目的就是要利用NS2把Global Synchronziation的現象展現出來。
[Network Topology]
[Tcl Script]
#number of connections
set n_con 2
#Create a simulator object
set ns [new Simulator]
#Define a 'finish' procedure
proc finish {output_} {
upvar $output_ output
global ns n_con
for {set i 0} {$i < $n_con} {incr i} {
close $output($i)
}
$ns flush-trace
exit 0
}
proc record {tcp_ output_} {
upvar $tcp_ tcp
upvar $output_ output
global ns n_con
#Set the time after which the procedure should be called again
set time 0.02
#Get the current time
set now [$ns now]
for {set i 0} {$i < $n_con} {incr i} {
puts $output($i) "$now [$tcp($i) set cwnd_]"
}
#puts "$now cwnd_=[$tcp(0) set cwnd_]"
#Re-schedule the procedure
$ns at [expr $now+$time] "record tcp output"
}
#Create four nodes
set r0 [$ns node]
set r1 [$ns node]
#Create links between the nodes
$ns duplex-link $r0 $r1 1.5Mb 40ms DropTail
#Set Queue Size of link (r0-r1) to 20
$ns queue-limit $r0 $r1 20
for {set i 0} {$i < $n_con} {incr i} {
set s($i) [$ns node]
set d($i) [$ns node]
$ns duplex-link $s($i) $r0 10Mb 0.4ms DropTail
$ns duplex-link $r1 $d($i) 10Mb 0.4ms DropTail
set output($i) [open output$i.ns w]
}
for {set i 0} {$i < $n_con} {incr i} {
set tcp($i) [new Agent/TCP]
set sink($i) [new Agent/TCPSink]
$ns attach-agent $s($i) $tcp($i)
$ns attach-agent $d($i) $sink($i)
$ns connect $tcp($i) $sink($i)
$tcp($i) set fid_ $i
$tcp($i) set window_ 128
$tcp($i) set packetSize_ 512
#Setup a FTP over TCP connection
set ftp($i) [new Application/FTP]
$ftp($i) attach-agent $tcp($i)
$ftp($i) set type_ FTP
}
#Schedule events for the FTP agents
$ns at 0.0 "record tcp output"
$ns at 0.0 "$ftp(0) start"
for {set i 0} {$i < $n_con} {incr i} {
$ns at 0.0 "$ftp($i) start"
}
$ns at 30.0 "finish output"
#Run the simulation
$ns run
[實驗結果]
當只有兩條Flows,兩條TCP congestion window的變化情況。從下圖可看出,兩條TCP flow的congestion window在約15秒以後,變化情況就一致了。
當有四條Flows,四條TCP congestion window的變化情況。變化情況如同兩條TCP flow,只不過一致的時間提早了。