实验三 TCP Tahoe与Reno 运行机制对比分析(附带完整可用代码)

实验目的:
学习TCP的拥塞控制机制并了解TCP Tahoe和TCP Reno协议的运行机制。

实验环境:
WindowsXP SP3+Cygwin2.416+NS2 2.29

实验步骤:

首先安装ns2,没必要通过源码编译来安装,只需10s安装,安装过程可参考博文:
https://blog.csdn.net/qq_40323844/article/details/89326416

安装好之后开始实验,
首先实验给的实例代码是有些格式问题的,修改如下:

if { $argc !=1} {
puts "Usage:ns lab11.tcl tcpversion"

exit

}

set par1 [lindex $argv 0]

set ns [new Simulator]

#打开一个trace文件,用来记录数据报传送的过程

set nd [open $par1.tr w]

$ns trace-all $nd

#打开一个文件用来记录cwnd变化情况

set f0 [open cwnd-$par1.tr w]

#定义一个结束的程序

proc finish {} {

global ns nd f0 tcp

puts [format "average throughput:%.1f Kbps" \ [expr [$tcp set ack_]*([$tcp set packetSize_])*8/1000/10]]

$ns flush-trace 

close $nd

close $f0

exit 0

}

#定义一个记录的程序 

proc record {} {

global ns tcp f0

set now [$ns now]

puts $f0 "$now [$tcp set cwnd_]"

$ns at [expr $now+0.01] "record"

}

#产生传送结点,路由器r1和r2和接收结点

set n0 [$ns node]

set r0 [$ns node] 

set r1 [$ns node]

set n1 [$ns node]

#建立链路

$ns duplex-link $n0 $r0 20Mb 1ms DropTail

$ns duplex-link $r0 $r1 1Mb 4ms DropTail

$ns duplex-link $r1 $n1 20Mb 1ms DropTail

#设置队列长度为18个封包大小

set queue 18

$ns queue-limit $r0 $r1 $queue

#根据用户的设置,指定TCP版本,并建立相应的Agent

if { $par1 == "Tahoe" } {

set tcp [new Agent/TCP] 

set tcpsink [new Agent/TCPSink] 

} elseif { $par1 == "Reno" } {

set tcp [new Agent/TCP/Reno]

set tcpsink [new Agent/TCPSink]

}

$ns attach-agent $n0 $tcp

$ns attach-agent $n1 $tcpsink

$ns connect $tcp $tcpsink

#建立FTP应用程序

set ftp [new Application/FTP]

$ftp attach-agent $tcp

$ns at 0.0 "$ftp start"

$ns at 10.0 "$ftp stop"

#在0.0s时调用record来记录TCP的cwnd变化情况

$ns at 0.0 "record"

$ns at 10.0 "finish"

$ns run

代码保存之后,开始实验。

**$ns lab11.tcl Tahoe
结果为:average throughput: 946.4kbps
使用gnuplot观察cwnd的变化值:
$Startxwin.bat
$gnuplot
Gnuplot>set title “Tahoe”
Gnuplot>set xlabel “time”
Gnuplot>set ylabel “cwnd”
Gnuplot>set terminal gif
Gnuplot>set output “cwnd-Tahoe.gif”
Gnuplot>plot “cwnd-Tahoe.tr” with linespoints 1
**

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值