//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. Python学习 day15

    一.内置函数(共68个) 1.作用域相关(2) locals(*args, **kwargs)  --  返回本地作用域中的所有名字 globals(*args, **kwargs)  --  返回全 ...

  2. 数据备份及恢复(mongodump/mongorestore)

    说明 1.mongodump创建高保真的BSON文件,mongorestore可以用其恢复数据库.对于小型数据库的备份和恢复,这两个工具非常简单和高效,但对于大型数据库的备份并不理想.2.mongod ...

  3. 快速掌握用python写并行程序

    目录 一.大数据时代的现状 二.面对挑战的方法 2.1 并行计算 2.2 改用GPU处理计算密集型程序 3.3 分布式计算 三.用python写并行程序 3.1 进程与线程 3.2 全局解释器锁GIL ...

  4. python 正则表达式应用——缩写词扩充

    看具体示例 import re def expand_abbr(sen, abbr): lenabbr = len(abbr) ma = '' for i in range(0, lenabbr): ...

  5. jquery 使用整理机制

    短路表达式 与 多重短路表达式 短路表达式这个应该人所皆知了.在 jQuery 中,大量的使用了短路表达式与多重短路表达式. 短路表达式:作为"&&"和" ...

  6. split 将字符串分割成字符串数组

    list_name = list_name.split(","); split() 方法用于把一个字符串分割成字符串数组. 语法 stringObject.split(separa ...

  7. 流畅的python和cookbook学习笔记(四)

    1.数字的四舍五入 对于简单的舍入运算,使用内置的 round(value, ndigits) 函数即可. round 函数返回离它最近的偶数.也就是说,对 1.5 或者 2.5 的舍入运算都会得到 ...

  8. 前端js动画收藏

    值得收藏的动画

  9. 10.31NOIP模拟赛解题报告

    心路历程 预计得分:\(100 +100 +80\) 实际得分:\(30 + 100 + 80\) 天天挂分..感觉我noip要凉.. T1不难,但是太坑了 T2不难 T3不难,但是在小机房考试脑子都 ...

  10. 软件项目技术点(7)——在canvas上绘制自定义图形

    AxeSlide软件项目梳理   canvas绘图系列知识点整理 图形种类 目前我们软件可以绘制出来的形状有如下这几种,作为开发者我们一直想支持用户可以拖拽的类似word里面图形库,但目前还没有找到比 ...