ns2仿真学习(二)-tcp拥塞窗口的跟踪

2023-10-27

本文主要处理[1]的输出结果。

仿真脚本 basic1.tcl

# basic1.tcl simulation: A---R---B

#Create a simulator object
set ns [new Simulator]

#Open the nam file basic1.nam and the variable-trace file basic1.tr
set namfile [open basic1.nam w]
$ns namtrace-all $namfile
set tracefile [open basic1.tr w]
$ns trace-all $tracefile

#Define a 'finish' procedure
proc finish {} {
        global ns namfile tracefile
        $ns flush-trace
        close $namfile
        close $tracefile
        exit 0
}

#Create the network nodes
set 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 A
set 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 B
set 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.0
set 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


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ns2仿真学习(二)-tcp拥塞窗口的跟踪 的相关文章

随机推荐

  • maven 配置多镜像

    1 配置maven的setting xml
  • Activity之任务和返回栈

    一个应用程序中会有多个activity 每个activity一般都有自己独立的功能 我们可以用activity启动自己应用中的另一个activity 例如 从一个数据列表界面 跳转到一个数据详情界面 也可以用我们的activity去打开其他
  • 深入理解javascript对象

    理解对象 对象被定义为一组属性的无序集合 对象就是一组没有特定顺序的值 对象的每个value值都由一个key来标识 一个key映射一个value值 1 Object 创建对象 创建了一个名为 person 的对象 而且有三个属性 name
  • Android adb实现原理

    adb定义 adb Android Debug Bridge 安卓调试桥 包含adb client adb server和adbd三部分 adb client 运行在PC上 即DDMS或者在Windows dos下启动的adb shell
  • Mysql Connector/J 源码分析(Failover)

    文章目录 前言 一 什么是Failover 二 Failover的主要结构 三 异常处理 3 1 构造连接阶段 小结 3 2 使用连接阶段 小结 四 四元素判定 小结 五 专有选择项 六 官网的态度 总结 前言 本文讨论Connector
  • restful接口客户端和服务端开发,HttpURLConnection,HttpClient,post ,get方式调用

    Restful服务端及客户端调用实例 1 新建web工程作为服务端 创建服务端代码 前情提示 GET SELECT 从服务器取出资源 一项或多项 POST CREATE 在服务器新建一个资源 PUT UPDATE 在服务器更新资源 客户端提
  • Parti 水记

    Parti 水记 Scaling Autoregressive Models for Content Rich Text to Image Generation 主页 https parti research google 论文 https
  • 【图像处理】【图像去模糊】 总结

    本人最近由于做相关去卷积工作 查阅了上百篇文献 发现在这个领域 可能也是 水太深 了 并没有一篇较好的综述 现在做以下总结 只对高斯与散焦模糊的非盲去卷积领域 对于运动模糊并未做总结 但实际上除了点扩散函数的估计有区别 实际上这三类去模糊甚
  • Dart基础语法2

    类 mixin 被mixin 混入 的类不能有构造函数 class A void a print A 的a方法 class B void b print b方法 void a print B 的a方法 满足了我们的多继承的需求 class
  • 运维架构

    首先 后端程序及客户端都是分成三个版本 内部测试版 线上测试版 线上稳定版 线上测试版是小范围更新 经过一天测试没问题 然后再推到线上稳定版 更新其他服 一般游戏也都是按这个流程来更新的 运维管理后台 记录了区服信息 提供各种简单API接口
  • Linux脚本和环境变量

    目录 一 可执行脚本 二 脚本程序解释器 三 SHELL语言 四 shell语言的变量 1 环境变量 2 用户环境变量 一 可执行脚本 脚本script 是一种解释执行的程序 linux中有三种常见的脚本 Shell脚本 sh Python
  • 第八章 基于项的图形视图

    对于用户自定义的窗口部件和绘制一个或者几个项来说 使用QPainter是理想的 在绘图中 如果需要处理从几个到几万个项时 而且要求用户能够单击拖动选取想 Qt的视图类提供了这一解决方案 Qt的视图体系包括一个由QGraphicsScene充
  • javafx事件总线之EventBus

    JAVAFX EventBus是一个轻量级的事件总线框架 用于在JavaFX应用程序中实现基于事件的通信和解耦 它提供了一种简单的方式 让组件能够订阅和发布事件 从而使得应用程序中的各个组件能够相互通信 而不需要相互依赖 JAVAFX Ev
  • node require报错为936的解决方式之一

    node internal modules cjs loader 936 Error Cannot find module crypto js 1 有一种是 你去检查一下你npm下面的node modules是不是又多了个node modu
  • SQL使用视图的优缺点

    INNER JOIN left Join 联接多个表 关于SQL的执行计划 查看SQL语句的具体执行过程 工作原理 SQL使用视图的优缺点 2010 06 04 10 56 43 分类 SQL 标签 字号大中小 订阅 在做数据库开发中使用视
  • 【华为OD机试题】最低位排序 Java代码实现

    题目描述 给定一个非空数组 列表 起元素数据类型为整型 请按照数组元素十进制最低位从小到大进行排序 十进制最低位相同的元素 相对位置保持不变 当数组元素为负值时 十进制最低为等同于去除符号位后对应十进制值最低位 输入 给定一个非空数组 列表
  • (二十三)槽函数的书写规则导致槽函数触发2次的问题

    在创建QT的信号和槽时 经常无意间保留着QT书写槽函数的习惯 或者在QT设计界面直接右键 转到槽 去创建槽函数 但是后期需要用到disconnect时 又重新写了一遍connect函数 那么你会发现实际槽函数执行了2遍 首先来看下这种QT的
  • JavaScript属性描述符【待补充】

    前言 很多学习过vue的同学 在学习vue响应式数据 或者双向绑定 的原理时 都接触过get set Object defineProperty这句个函数 并且大概知道它们的用法 但是一提到属性描述符 大家就很陌生了 今天详细的给大家讲解一
  • c++11新特性之独占指针unique_ptr

    独占智能指针unique ptr 独占智能指针不允许其他智能指针共享内部的指针 可以通过它的构造函数初始化一个独占智能指针对象 但是不允许通过赋值将一个unique ptr赋值给另一个unique ptr unique ptr不允许复制 但
  • ns2仿真学习(二)-tcp拥塞窗口的跟踪

    本文主要处理 1 的输出结果 仿真脚本 basic1 tcl basic1 tcl simulation A R B Create a simulator object set ns new Simulator Open the nam f