//without comments

 int chooseECNSlot()
{
double maxProgress=;
for(int i=;i<=nslot_;i++)
{
if(slot_[i]!=NULL && window_i>*count)
{
double ti=window_i/(*count);
double iProg=umap[slot_[i]]+(window_i+ti/)*ti;
for(int j=;j<=nslot_;j++)
{
if(slot_[j]!=NULL && window_j>*count)
{
double jProg=umap[slot_[j]]+(window_j+ti/)*ti;
if(jProg>iProg) break;
}
if(j==nslot_)
{
return i;
}
}
}
}//for
return -;//no flow satisfies the condition.(maybe should return the flow with max progress)
} int PortClassifier::recv(Packet* p, Handler*h)
{
NsObject* node = find(p);//find调用classify,classify返回dport。
if (node == NULL) {
Packet::free(p);
return;
} umap[node]++; if(flag)
{
hdr_flags *hf=hdr_flags::access(pickPacketForECN(p));
if(hf->ce()==)
{
hf->ce()=;
mark=chooseECNSlot();
}
if (mark != - &&node==slot_[mark])
{
hf->ce()=;
mark = -;
}
}//end of flag node->recv(p,h);
} void PortClassifier::install(int slot, NsObject* p)//install是用来向slot里赋值的。(连接agent & slot)
{
if (slot >= nslot_)
alloc(slot);
slot_[slot] = p; if (slot >= maxslot_)
maxslot_ = slot; count++;
if(count>=)
flag=; } ================================================================================================================================== 15.1. rewrite: classifier-port.h里需要添加的:
()include处
#include <unordered_map> 还要using namespace std?或者不用?在底下定义的时候用std::unordered_map<NsObject*,double> umap
#include "flags.h"//里面有很多需要的变量和函数,如ce()
()3个变量
count=; flag=; mark=-;//可以考虑用复杂些的变量名,防止别的需要include的文件里有重名的
count不止表示agent个数,同时它是server的个数!
flag用来标志receiver; //【但是这样全局变量对吗?sender那边如果使用portclassifier时会累加上吗?不会的。这方法可以。亲测有效。】
//【如果不行就用遍历slot的方法。每次遍历一下看有多少agent。】
()
unordered_map<NsObject*,double> umap;//看看用不用指定std:: ------------------------------------------------------------------------------------------------------------------------------
//with comments int chooseECNSlot()//根据umap里的统计来获取各流进度值。返回值是slot_的下标。
//这个函数还是改成专门筛选流的函数吧(筛选出需要窗口减半的流)
{
//该函数需要能访问到umap以及各流的window大小。
//注意:这里说的按进度排序不是按当前进度排序,而是按下次发生ECN的时刻的进度排序。 double maxProgress=;//初始化最大进度值maxProgress
// mark=-1;//用来标记选中的流
// int flagMax=0;
for(int i=;i<=nslot_;i++)//下标能否等于nslot?
{ //其实遍历slot就行!slot_中有一些是empty,所以虽然知道共有count个agent,还是得完整遍历一遍slot_.
if(slot_[i]!=NULL && window_i>*count)// 这是能“参赛”的流的入门条件。
{//在window大于2N的流里面找[下次ECN时刻]进度最大的。
//这里count就是server数目N。
//ASSUME flow with index[i] will be the maxProgress-flow at next ECN
double ti=window_i/(*count);//the time gap from now when next ECN happens
int newProg=umap[slot_[i]]+(window_i+ti/)*ti;
for(int j=;j<=nslot_;j++)
{
if(slot_[j]!=NULL && window_j>*count)//参赛门槛
{
double tj=window_j/(*count);
tmpProg=umap[slot_[j]]+(window_j+tj/)*tj;
if(tmpProg>newProg) break;//说明i不是下次ecn时进度最快的,假设不成立。
}
}
// if(umap[slot_[i]]>maxProgress)
// {
// maxProgress=umap[slot_[i]];//更新maxProgress
// mark=i;//标记下该流的node在slot_中对应的下标i;
// }
} // else
// {//如果没有window>2N的流,就选当前进度最大的流?这是后话。
// } }//for // if(mark!=-1)
return mark;// 返回下标
// else//没有window>2N的流
// return mark2; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int PortClassifier::recv(Packet* p, Handler*h)
{
NsObject* node = find(p);//find调用classify,classify返回dport。
if (node == NULL) {
Packet::free(p);
return;
} if(flag)//当前node是receiver时才执行下面的算法。
{
// mark=-1;//slot_下标的初始值置为-1?
umap[node]++;//需要在classifier.h中classifier类内部定义unordered_map umap<NsObject*,double>。 (但是注意,当umap里有流已传输完毕后要剔除出去,否则影响排序XXXX如果不用mark2的话那就不会影响到,因为首先是按window来看的,只有window足够大才会看进度。已经传输完成的流window应该变为0吧(如果没变要记得调整))。
hdr_flags *hf=hdr_flags::access(pickPacketForECN(p));
if(hf->ce()==)// 说明switch中发生了拥塞
{
hf->ce()=;//首先清零。然后再根据算法分配ce。
mark=chooseECNSlot();//用chooseECNSlot()选出应当减半的流。
} if (mark != - &&node==slot_[mark]) //这个recv()程序一开始就用到了find,把packet转换成了agent(这里是用node变量来表示的agent)。所以可以用这个node来和slot_[mark]直接比较。
//对每一个到来的packet都检查,直到发现是mark所标记的那个。可通过portclassifier里的classify返回dport。(参照slideshare P15,为什么通过classifier类,调用的却是portclassifier里的classify ?)
{
hf->ce()=;
mark = -;//任务完成,使mark失效。
}
}//end of flag
node->recv(p,h);
} void PortClassifier::install(int slot, NsObject* p)//install是用来向slot里赋值的。(连接agent & slot)
{
if (slot >= nslot_)
alloc(slot);
slot_[slot] = p; if (slot >= maxslot_)
maxslot_ = slot; count++;
if(count>=) flag=; } ==================================================================================================================================
//below is original source code void Classifier::recv(Packet* p, Handler*h)//original
{
NsObject* node = find(p);
if (node == NULL) {
/*
* XXX this should be "dropped" somehow. Right now,
* these events aren't traced.
*/
Packet::free(p);
return;
} node->recv(p,h);
} ///////////////////////////////////////////////////////////////////////////////////////////////////// void Classifier::install(int slot, NsObject* p)
{
if (slot >= nslot_)
alloc(slot);
slot_[slot] = p;
if (slot >= maxslot_)
maxslot_ = slot;
} //above is original source code
===============================================================================================================

updated 15.1.8

 void Classifier::recv(Packet* p, Handler*h)//original
{
NsObject* node = find(p);
if (node == NULL) {
/*
* XXX this should be "dropped" somehow. Right now,
* these events aren't traced.
*/
Packet::free(p);
return;
} node->recv(p,h);
} =============================================================================================================== int chooseECNSlot()
//这个函数还是改成专门筛选流的函数(筛选出需要窗口减半的流)
{//在打ecn的地方引入调用这个函数,通过该函数来打ECN?或者通过该函数有针对性的回调打ecn的函数。
//该函数需要能访问到umap以及各流的window大小。 //sort(window)其实不用。用下面的方法只需遍历一次,O(N)复杂度即可。如果sort要O(NlogN)。
int maxProgress=;//初始化最大进度值maxProgress
int mark=-;//用来标记选中的流s
for(i=;i<=n;i++)//其实遍历slot就行!
{
if(window>*N)//在window大于2N的流里面找进度最大的。(如何获取该流的window?)
{
if(该流的进度值(umap.second)>maxProgress)
{
maxProgress=该进度值(umap.second);//更新maxProgress
mark=i;//标记下该流的node;
}
}
else
{//如果没有window>2N的流,就选当前进度最大的流。 }
}
if(mark!=-)
return mark;
else//没有window>2N的流
return mark2; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
15.1. rewrite: #include "flags.h"//里面有很多需要的变量和函数,如ce()
void Classifier::recv(Packet* p, Handler*h)
{
NsObject* node = find(p);//find调用classify,classify返回dport。
if (node == NULL) {
Packet::free(p);
return;
}
umap[node]++;//需要在classifier.h中classifier类内部定义unordered_map umap<NsObject*,long long int>。 (但是注意,当umap里有流已传输完毕后要剔除出去,否则影响排序XXXX如果不用mark2的话那就不会影响到,因为首先是按window来看的,只有window足够大才会看进度。已经传输完成的流window应该变为0吧(如果没变要记得调整))。 hdr_flags *hf=hdr_flags::access(pickPacketForECN(p));
if(hf->ce()==)// 说明switch中发生了拥塞
{
hf->ce()=;//首先清零。然后再根据算法分配ce。
int mark=function(筛选出需要窗口减半的流的slot下标);//该函数参照上面的chooseECNSlot
} if (mark != - &&当前packet的dport==slot[mark])//对每一个到来的packet都检查,直到发现是mark所标记的那个。可通过portclassifier里的classify返回dport。(参照slideshare P15,为什么通过classifier类,调用的却是portclassifier里的classify ?)
{
hf->ce()=;
mark = -;//使mark失效。
}
node->recv(p,h);
}

http://www.slideshare.net/TBear76/20100403-classifiers

classifier.cc-recv() [ns2.35]的更多相关文章

  1. ubuntu 14.04 ns2.35 ***buffer overflow detected **: ns terminated解决办法

    1.按照如下教程安装 Install With Me !: How to Install NS-2.35 in Ubuntu-13.10 / 14.04 (in 4 easy steps) 2.运行一 ...

  2. 在ns2.35下完成柯老师lab18实验

    说明:柯志亨老师<ns2仿真实验-----多媒体和无线网络通信>这本书lab18实验为“无线网络封包传输遗失模型”的实验.该无线传输遗失模型是柯老师自己开发的,原始的ns-allinone ...

  3. 在ns2.35中添加myevalvid框架

    在用ns2进行网络视频通信仿真的时候,先要为我们自己的ns2添加evalvid或者myevalvid框架.其中myevalvid框架是由柯志亨老师整合evalvid和ns2之后得出的新框架,笔者建议大 ...

  4. Ubuntu14.04下安装ns2.35

    我选择的版本是2.35最新版本,安装环境是Ubuntu 14.04. 1.下载ns2的安装包,这里我选择的是ns-allinone-2.35.tar.gz压缩格式的all in one安装包,all ...

  5. Ubuntu12.04 LTS 32位 安装ns-2.35

    ubuntu12.04lts 32-bit默认采用gcc 4.6和g++4.6,而ns的最新版本ns 2.3.5也采用了相同到版本,所以这方面不会有版本不同到问题 收回上面这句话..../valida ...

  6. Ubuntu 16——安装——ns2.35和nam

    Ubuntu 16.04 安装ns2.35+nam 总结出以下安装步骤 1: 更新源 sudo apt-get update #更新源列表 sudo apt-get upgrade #更新已经安装的包 ...

  7. NS2安装过程中环境变量设置的问题(ns-2.35)

    nam: Can't find a usable tk.tcl in the following directories: */ns-allinone-2.35/tcl8.5.10/library/t ...

  8. ns2.35-classifier.cc

    line143:recv() /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ /* * Copyri ...

  9. NS2仿真:公交车移动周期模型及性能分析

    NS2仿真实验报告3 实验名称:公交车移动周期模型及性能分析 实验日期:2015年3月16日~2015年3月21日 实验报告日期:2015年3月22日 一.实验环境(网络平台,操作系统,网络拓扑图) ...

随机推荐

  1. ES6新特性整理,你需要了解的ES6知识

    ES6是新版本JavaScript语言的标准,上一次标准的制订还是2009年出台的ES5.目前ES6的标准化工作已经完成,14年12月份放出了正式版本. 目前主流的浏览器都支持运行ES6代码,如果你的 ...

  2. jsp基础知识总结

    1.了解jsp,jsp有什么有利的,有什么弊端. jsp是serlet的扩展,在web应用中,每个jsp页面都会有servlet容器生产对应的servlet. jsp通过在标准的html页面中插入ja ...

  3. ISE报警:关键字 unsigned不可用于verilog

    问题:关键字 unsigned不可用于verilog 解决方案:去掉unsigned

  4. unity动态加载FBX模型(Http下载到Rescources文件,场景Load直接调用):

    using UnityEngine; using System.Collections; using System.IO; using System.Net; using System; using ...

  5. 如何通过SQL命令查看数据库的文件大小[转]

    1. 查看数据文件占用(权限要求较大) DBCC showfilestats 2. 查看日志文件占用 dbcc sqlperf(logspace) 会列出所有能够查看的数据库的日志情况.. 需要挑选出 ...

  6. DBA 需要掌握的知识框架及工作内容

    知识框架 1.  数据库的工作原理以及体系结构 2.  数据库管理(管理数据库和数据库对象) 3.  数据库备份和恢复 4.  数据库故障处理 5.  数据库补丁安装及升级 6.  数据库性能 工作内 ...

  7. Oracle运算符收录(易忘记,但是又很重要的运算符)

    Create Table Test6( id ), name ), age ), sex ) ) 1. ||   符 字符串连接字符串,注意:文字和日期一定嵌入在单引号里面 select ID,Nam ...

  8. MySQL数据表的修改

    数据表的修改包括列的增加.列的删除.约束的添加.约束的删除等. 添加单列 ALTER TABLE tbl_name ADD [COLUMN] col_name column_definition [F ...

  9. android LinearLayoutForListView

    由于 scrollview 套 listview 会有很多问题,网上很多人用 LinearLayout 模拟 listview, 也可以设置 adapter. 很多人直接继承 BaseAdapter, ...

  10. CentOS6.4 安装Redis

    按照下面步骤依次执行1.检查依赖,安装依赖 [root@ecs-3c46 ~]# whereis gcc gcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc ...