原链接:http://blog.chinaunix.net/u3/105477/showart_2092522.html
拥塞控制是网络层协议必备的一个功能,TCP采用拥塞窗口机制避免接收方被数据淹没! 同时为了更高效的传送数据,网络协议的设计者们引入了非常实用的加性增、乘性减的机制,取得了很好的效果!
2. 运行的命令格式:
$ns tcpsim.tcl bandwidth delay window simulation_time
如: ns tcpsim.tcl 1Mb 100ms 64 5
3. 使用 TCP/RFC793edu 协议获得文件 TCP_RFC793edu.tr
4. 使用 TCP/Reno 协议获得文件 TCP_Reno.tr
5. 绘图比较的命令: xgraph TCP_RFC793edu.tr TCP_Reno.tr -geometry 800x400
#TCP滑动窗口及慢启动算法的模拟
#场景:
# 两个节点: n0, n1,
# 在这两个节点间创建一条TCP连接,
# 通过命令行传参数的方式对操作窗口大小进行设置;
# 运行的命令格式:
# $ns tcpsim.tcl bandwidth delay window simulation_time
# 如: ns tcpsim.tcl 1Mb 100ms 64 5
#
#处理命令行部分:
if { $argc==4} {
set bandwidth [lindex $argv 0]
set delay [lindex $argv 1]
set window [lindex $argv 2]
set time [lindex $argv 3]
} else {
puts " bandwidth "
puts " n0-----------n1"
puts " Usage: $argv0 bandwidth delay window simulation_time"
exit 1
}
set ns [new Simulator]
set nf [open tcpsimnam.nam w]
$ns namtrace-all $nf
set ftr [open tcpsim_slidewin.tr w]
$ns trace-all $ftr
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam tcpsimnam.nam &
exit 0
}
#以下部分的代码, 很明了, 如有问题,请查看前面的博客!
set n0 [$ns node]
set n1 [$ns node]
$ns duplex-link $n0 $n1 $bandwidth $delay DropTail
$ns duplex-link-op $n0 $n1 orient left-right
#3. 使用 TCP/RFC793edu 协议获得文件 TCP_RFC793edu.tr
#4. 使用 TCP/Reno 协议获得文件 TCP_Reno.tr
set tcp [$ns create-connection TCP/RFC793edu $n0 TCPSink $n1 1]
$tcp set window_ $window
$tcp set ssthresh_ 60
$tcp set packetSize_ 500
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
#用于统计和绘图, 每隔0.1s后采样窗口大小,并写入文件 f0 中
#3. 使用 TCP/RFC793edu 协议获得文件 TCP_RFC793edu.tr
#4. 使用 TCP/Reno 协议获得文件 TCP_Reno.tr
set f0 [open TCP_RFC793edu.tr w]
proc Record {} {
global f0 tcp ns
set intval 0.1
set now [$ns now]
set cwnd [$tcp set cwnd_]
puts $f0 "$now $cwnd"
$ns at [expr $now+$intval] "Record"
}
$ns at 0.1 "Record"
$ns at 0.5 "$ftp start"
$ns at $time "finish"
$ns run
注意: 其中,慢启动曲线,指数增长到的最大值是我们设定的window值, 而不是理论上应该有的慢启动门限值ssthresh的值, 为什么?
347



被折叠的 条评论
为什么被折叠?



