#产生一个仿真对象
set ns [new Simulator]
#开启一个trace文件,用来记录封包传送过程
set nd [open out.tr w]
$ns trace-all $nd
#开启3个文件用来记录3条TCP Connection的cwnd变化情况
set f0 [open cwnd0.tr w]
set f1 [open cwnd1.tr w]
set f2 [open cwnd2.tr w]
#定义一个结束程序
proc finish {} {
global ns nd f0 f1 f2
$ns flush-trace
#关闭文件
close $nd
close $f0
close $f1
close $f2
exit 0
}
#定义一个记录的程序
#每隔0.01s记录当时的cwnd
proc record {tcp_} {
global ns f0 f1 f2
upvar $tcp_ tcp
set now [$ns now]
puts $f0 "$now [$tcp(0) set cwnd_]"
puts $f1 "$now [$tcp(1) set cwnd_]"
puts $f2 "$now [$tcp(2) set cwnd_]"
$ns at [expr $now+0.01] "record tcp"
}
#设置路由节点
set r0 [$ns node]
#设置目的节点
set d0 [$ns node]
#路由与目的节点的链路属性
$ns duplex-link $r0 $d0 0.8Mb 100ms DropTail
$ns queue-limit $r0 $d0 64
for {set i 0} {$i < 3} {incr i} {
#设置源节点
set s($i) [$ns node]
set d($i) [$ns node]
$ns duplex-link $s($i) $r0 8Mb 0.1ms DropTail
#设置代理
set tcp($i) [new Agent/TCP/Vegas]
set tcpsink($i) [new Agent/TCPSink]
$ns attach-agent $s($i) $tcp($i)
$ns attach-agent $d0 $tcpsink($i)
$ns connect $tcp($i) $tcpsink($i)
$tcp($i) set fid_ $i
$tcpsink($i) set fid_ $i
#设置窗口和包大小
$tcp($i) set window_ 128
$tcp($i) set packetSize_ 500
}
for {set i 0} {$i < 3} {incr i} {
#发送数据格式为FTP
set ftp($i) [new Application/FTP]
$ftp($i) attach-agent $tcp($i)
#Schedule events for the FTP agents
$ns at 0 "$ftp($i) start"
$ns at 100.0 "$ftp($i) stop"
}
#在0.0s时调用record记录TCP的cwnd变化情况
$ns at 0.0 "record tcp"
#在100.0s调用finish结束模拟
$ns at 100.0 "finish"
#执行模拟
$ns run
TCP-Congestion-Control-Algorithm.rar_TCP 拥塞控制_TCP拥塞控制_reno_tcp c
版权申诉
187 浏览量
2022-09-23
01:16:05
上传
评论
收藏 2KB RAR 举报
JonSco
- 粉丝: 66
- 资源: 1万+