ns2仿真学习(二)-tcp拥塞窗口的跟踪
来源:互联网 发布:淘宝女童服装 编辑:程序博客网 时间:2024/06/01 10:01
本文主要处理[1]的输出结果。
仿真脚本 basic1.tcl
# basic1.tcl simulation: A---R---B#Create a simulator objectset ns [new Simulator]#Open the nam file basic1.nam and the variable-trace file basic1.trset namfile [open basic1.nam w]$ns namtrace-all $namfileset tracefile [open basic1.tr w]$ns trace-all $tracefile#Define a 'finish' procedureproc finish {} { global ns namfile tracefile $ns flush-trace close $namfile close $tracefile exit 0}#Create the network nodesset A [$ns node]set R [$ns node]set B [$ns node]#Create a duplex link between the nodes$ns duplex-link $A $R 10Mb 10ms DropTail$ns duplex-link $R $B 800Kb 50ms DropTail# The queue size at $R is to be 7, including the packet being sent$ns queue-limit $R $B 7# some hints for nam# color packets of flow 0 red$ns color 0 Red$ns duplex-link-op $A $R orient right$ns duplex-link-op $R $B orient right$ns duplex-link-op $R $B queuePos 0.5# Create a TCP sending agent and attach it to Aset tcp0 [new Agent/TCP/Reno]# We make our one-and-only flow be flow 0$tcp0 set class_ 0$tcp0 set window_ 100$tcp0 set packetSize_ 960$ns attach-agent $A $tcp0# Let's trace some variables$tcp0 attach $tracefile$tcp0 tracevar cwnd_$tcp0 tracevar ssthresh_$tcp0 tracevar ack_$tcp0 tracevar maxseq_#Create a TCP receive agent (a traffic sink) and attach it to Bset end0 [new Agent/TCPSink]$ns attach-agent $B $end0#Connect the traffic source with the traffic sink$ns connect $tcp0 $end0#Schedule the connection data flow; start sending data at T=0, stop at T=10.0set myftp [new Application/FTP]$myftp attach-agent $tcp0$ns at 0.0 "$myftp start"$ns at 10.0 "finish"#Run the simulation$ns run仿真运行 ./ns basic1.tcl
数据输出,basic1.tr,数据处理脚本,检出cwnd的值。
cwnd.awk
BEGIN { cwnd_counter = 0;}{time =$1;key_type=$6; #cwnd_value=$7;if(key_type=="cwnd_"){time_array[cwnd_counter]=time;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]);}}运行,awk -f cwnd.awk basic.tr>cwnd.txt。
采用gnuplot绘图:
gnuplot
set xlabel "time"
set ylabel “cwnd”
set yrange [0:30]
set term png
set output "cwnd.png"
plot "cwnd.txt" using 1:2 with lines
最后输出的图形:
找了个计算速率的脚本[2]:throughput.pl
# Usage: ## perl throughput.pl <trfile> <destNode> <srcNode.port#> <destNode.port#> # <granularity> ## Example: plot the throughput of connection 2.0 - 1.0 every 0.5 sec##perl throughput.pl out.tr 1 2.0 1.0 0.5## cs558000 example:## Tracefile:# r 0.351867 3 4 tcp 40 ------- 0 0.0 4.0 0 0# ^ ^^^ ^^^# Use:#perl throughput.pl out.tr 4 0.0 4.0 0.5# ############################################################## Get input file (first arg) $infile=$ARGV[0];# ############################################################## Get node that receives packets (second arg) $destnode=$ARGV[1]; $fromport=$ARGV[2]; $toport=$ARGV[3];# ############################################################## Get time granularity (time interval width $granularity=$ARGV[4];# ########################################################################## We compute how many bytes were transmitted during time interval specified# by granularity parameter in seconds $sum=0; $grantsum=0; $clock=0;# ########################################################################## Open input file open (DATA,"<$infile") || die "Can't open $infile $!"; while (<DATA>) {# Tokenize line using space as separator @x = split(' ');# column 1 is time if ($x[1]-$clock <= $granularity) {# checking if the event (column 0) corresponds to a reception if ($x[0] eq 'r') { # checking if the destination (column 3) corresponds to node in arg 1 if ($x[3] eq $destnode && $x[8] eq $fromport && $x[9] eq $toport) { #checking if the packet type is TCP if ($x[4] eq 'tcp') { $sum=$sum+$x[5]; $grantsum=$grantsum+$x[5]; } } } } else# One interval has passed, compute throughput { $throughput=0.000008*$sum/$granularity; print STDOUT "$clock $throughput\n"; $clock=$clock+$granularity; if ($x[0] eq 'r' && $x[3] eq $destnode && $x[8] eq $fromport && $x[9] eq $toport && $x[4] eq 'tcp') { $sum=$x[5]; $grantsum=$grantsum+$x[5]; } else { $sum=0; } while ($x[1]-$clock > $granularity) { print STDOUT "$clock 0.0\n"; $clock=$clock+$granularity; } } } $throughput=0.000008*$sum/$granularity; print STDOUT "$clock $throughput\n"; $clock=$clock+$granularity; print STDERR "Avg throughput $fromport - $toport = ", 0.000008*$grantsum/$clock,"MBytes/sec \n"; close DATA; exit(0);
使用方法,perl throughput.pl trfile destNode srcNode.port# destNode.port time-granularity ,具体本例子,perl throughput.pl basic1.tr 2 0.0 2.0 0.5 >out.txt
最后画出的TCP的速率如下;
[1]An Introduction to Computer Networks.
[2]Studying TCP's Throughput and Goodput using NS
阅读全文
0 0
- ns2仿真学习(二)-tcp拥塞窗口的跟踪
- ns2仿真学习(三)-不同tcp拥塞控制的竞争能力
- NS2中TCP拥塞控制仿真过程中盲点解析
- TCP的滑动窗口与拥塞窗口
- TCP的滑动窗口与拥塞窗口
- TCP的滑动窗口与拥塞窗口
- TCP的滑动窗口与拥塞窗口
- TCP的滑动窗口与拥塞窗口
- 对有线连接的TCP协议拥塞窗口进行的仿真——慢启动和非慢启动
- tcp的拥塞窗口和慢启动
- TCP窗口拥塞控制:
- NS3 -- TCP拥塞控制跟踪
- ns2仿真学习(四)-CoDel的队列管理仿真
- 一站式学习Wireshark(五):TCP窗口与拥塞处理
- 一站式学习Wireshark(五):TCP窗口与拥塞处理
- 学习Wireshark(五):TCP窗口与拥塞处理
- 一站式学习Wireshark(五):TCP窗口与拥塞处理
- 一站式学习Wireshark(五):TCP窗口与拥塞处理
- MONGODB内存溢出
- Unicode 和 UTF 的区别
- ios自带排序 :sortedArrayUsingComparator
- 在Intellij Idea中怎么引入c标签
- [bzoj3626][LNOI2014]LCA 树链剖分
- ns2仿真学习(二)-tcp拥塞窗口的跟踪
- 接口限流算法总结
- NOIP模拟 最佳序列【二分答案+线段树(单调队列)】
- PID算法Demo
- openGL之glsl入门2--helloworld
- Spring整合ehcache
- nodeJS入门教程
- 学习阿里巴巴开发手册-12
- 2013NOIP普级组第一题--计数问题(参考洛谷题解)