ns2仿真学习(三)-不同tcp拥塞控制的竞争能力

这次实验算是对[1]的复现吧,花了一个上午,[1]将TCP的拥塞控制机制框架引入到了仿真环境。本文主要对比了四种tcp拥塞控制机制,bic(n2-n3),cubic(n4-n5),reno(n6-n7),vegas(n8-n9)。瓶颈链路带宽n0-n1(100Mb)。

仿真脚本tcp_congestion_compare.tcl

set MainBuffer 200

set TCP_Variant "Agent/TCPSink/Sack1"

set MSS 1448

set BDP 30000

set EndTime 200

#Make a NS simulator

set ns  [new Simulator]



#Open the nam file basic1.nam and the variable-trace file basic1.tr  

set namfile [open tcp_compare.nam w]  

$ns namtrace-all $namfile  

set tracefile [open tcp_compare.tr w]  

$ns trace-all $tracefile  



set  bic_file [open bic.tr w] 

set  cubic_file [open cubic.tr w]

#Define a 'finish' procedure  

proc finish {} {  

        global ns namfile tracefile  

        $ns flush-trace  

        close $namfile  

        close $tracefile  

        exit 0  

}



# Create the 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]

set n8 [$ns node]

set n9 [$ns node]





#        Create The Topology

#

#   n2                        n3

#   n4 \                    / n5

#   n6 \                    / n7

#     \n0<---100Mb 64ms--->n1 /

#   

#   n2<---200M,0ms--->n0

#   n1<----200M,0ms-->n3

#   bic cubic reno vegas





# Create the links:

$ns duplex-link $n0 $n1   100Mb  64ms DropTail



$ns duplex-link $n2 $n0   200Mb  0ms DropTail

$ns duplex-link $n4 $n0   200Mb  0ms DropTail

$ns duplex-link $n6 $n0   200Mb  0ms DropTail

$ns duplex-link $n8 $n0   200Mb  0ms DropTail



$ns duplex-link $n3 $n1   200Mb  0ms DropTail

$ns duplex-link $n5 $n1   200Mb  0ms DropTail

$ns duplex-link $n7 $n1   200Mb  0ms DropTail

$ns duplex-link $n9 $n1   200Mb  0ms DropTail



$ns queue-limit $n0 $n1 $MainBuffer



# fid_  flow id

# class_  packet color

#bic

set tcp1 [new Agent/TCP/Linux]

$tcp1 set fid_ 1   

$tcp1 set class_ 1

$tcp1 set packetSize_ $MSS

$tcp1 set window_ $BDP

$tcp1 set timestamps_ true

$ns at 0 "$tcp1 select_ca bic"

$ns attach-agent $n2 $tcp1



# Let's trace some variables

$tcp1 attach $tracefile

$tcp1 tracevar cwnd_

set sink1 [new Agent/TCPSink/Sack1]

$sink1 set class_ 1

$sink1 set ts_echo_rfc1323_ true

$ns attach-agent $n3 $sink1



# setup traffic

set ftp1 [new Application/FTP]

$ftp1 attach-agent $tcp1

$ftp1 set type_ FTP



$ns connect $tcp1 $sink1





#cubic

set tcp2 [new Agent/TCP/Linux]

$tcp2 set fid_ 2  

$tcp2 set class_ 1

$tcp2 set packetSize_ $MSS

$tcp2 set window_ $BDP

$tcp2 set timestamps_ true

$ns at 0 "$tcp2 select_ca cubic"

$ns attach-agent $n4 $tcp2



$tcp2 attach $tracefile

$tcp2 tracevar cwnd_

set sink2 [new Agent/TCPSink/Sack1]

$sink1 set class_ 1

$sink1 set ts_echo_rfc1323_ true

$ns attach-agent $n5 $sink2



# setup traffic

set ftp2 [new Application/FTP]

$ftp2 attach-agent $tcp2

$ftp2 set type_ FTP



$ns connect $tcp2 $sink2





#reno

set tcp3 [new Agent/TCP/Reno]

$tcp3 set fid_ 3   

$tcp3 set class_ 1

$tcp3 set packetSize_ $MSS

$tcp3 set window_ $BDP

$tcp3 set timestamps_ true

$ns attach-agent $n6 $tcp3



$tcp3 attach $tracefile

$tcp3 tracevar cwnd_



set sink3 [new Agent/TCPSink]

$ns attach-agent $n7 $sink3



# setup traffic

set ftp3 [new Application/FTP]

$ftp3 attach-agent $tcp3

$ftp3 set type_ FTP



$ns connect $tcp3 $sink3



#vegas

set tcp4 [new Agent/TCP/Vegas]

$tcp4 set fid_ 4  

$tcp4 set class_ 1

$tcp4 set packetSize_ $MSS

$tcp4 set window_ $BDP

$tcp4 set timestamps_ true

$ns attach-agent $n8 $tcp4



$tcp4 attach $tracefile

$tcp4 tracevar cwnd_

set sink4 [new Agent/TCPSink]

$sink4 set class_ 1

$ns attach-agent $n9 $sink4



# setup traffic

set ftp4 [new Application/FTP]

$ftp4 attach-agent $tcp4

$ftp4 set type_ FTP



$ns connect $tcp4 $sink4









# Schedule start/stop times

$ns at 0.1   "$ftp1 start"

$ns at 0.1   "$ftp2 start"

$ns at 0.1   "$ftp3 start"

$ns at 0.1   "$ftp4 start"



$ns at 29.0 "$ftp1 stop"

$ns at 29.0 "$ftp2 stop"

$ns at 29.0 "$ftp3 stop"

$ns at 29.0 "$ftp4 stop"



# Set simulation end time

$ns at 30.0 "finish"  



#Run the simulation

$ns run


运行仿真脚本。数据输出在tcp_compare.tr。

检出包含cwnd_字段的数据行。执行脚本,awk -f cwnd.awk  tcp_compare.tr>cwnd.txt。脚本cwnd.awk:

BEGIN {
     cwnd_counter = 0;
}
{
time =$1;
source=$2;
key_type=$6; #cwnd_
value=$7;
if(key_type=="cwnd_")
{
	time_array[cwnd_counter]=time;
	source_array[cwnd_counter]=source;
	cwnd[cwnd_counter]=value;
	cwnd_counter++;
}

}

END{
for(cwnd_index=0;cwnd_index<cwnd_counter;cwnd_index++)
{
printf("%f %d %s %f\n",time_array[cwnd_index],source_array[cwnd_index],"cwnd_",cwnd[cwnd_index]);
}

}
从cwnd.txt数据文件中分别检出不同节点的拥塞窗口数据。需要执行四次,每次需要修改if(source=="8")(表示数据的源头为n8,就是检出vegas的拥塞窗口数据,若更改为“2”,表示数据的源头为n2,拥塞控制机制为bic)。检出bic的拥塞窗口,cwnd_var.awk -f cwnd.txt>bic.txt 。cwnd_var.awk脚本:

BEGIN {
     cwnd_counter = 0;
}
{
time =$1;
source=$2;
key_type=$3; #cwnd_
value=$4;
if(key_type=="cwnd_")
{
	if(source=="8")
	{
	time_array[cwnd_counter]=time;
	source_array[cwnd_counter]=source;
	cwnd[cwnd_counter]=value;
	cwnd_counter++;
	}

}

}

END{
for(cwnd_index=0;cwnd_index<cwnd_counter;cwnd_index++)
{
printf("%f %f\n",time_array[cwnd_index],cwnd[cwnd_index]);
}

}

gnuplot绘图:要在同一张图片上绘制多个曲线,

plot "bic.txt" u 1:2 title "bic",  "cubic.txt" u 1:2 title "cubic","reno.txt"  u 1:2 title "reno" ,"vegas.txt" u 1:2 title "vegas"
其他命令参考之前两篇博文。

最后图形:


从图中可以看出,bic的竞争能力相当厉害。vegas的竞争能力最差。竞争能力强的流占用了过多的带宽。其实这里有些东西是可以研究的,路由器的队列管理机制,怎么保证流的带宽公平性。下次可以验证下CoDel的队列管理机制。看看CoDel对采用不同拥塞控制流的竞争能力的影响。

致谢,梁博士,最后这个画图命令是请教的他。在这入门的道路上,梁博士教会我使用做科研的基本工具,文献管理工具jabref,写论文工具latex(花了一个下午教我,可是至今也没有用上,也忘记了),使用bibtex4word在word中自动管理引用文献序号。


[1]A Linux TCP implementation for NS2

  • 1
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 24
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 24
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值