ns2.35-classifier.cc
line143:recv()
/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
/*
* Copyright (c) 1996 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the MASH Research
* Group at the University of California Berkeley.
* 4. Neither the name of the University nor of the Research Group may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/ #ifndef lint
static const char rcsid[] =
"@(#) $Header: /cvsroot/nsnam/ns-2/classifier/classifier.cc,v 1.44 2010/03/08 05:54:49 tom_henderson Exp $";
#endif #include <stdlib.h>
#include "config.h"
#include "classifier.h"
#include "packet.h"
#include "link/cell_header.h" static class ClassifierClass : public TclClass {
public:
ClassifierClass() : TclClass("Classifier") {}
TclObject* create(int, const char*const*) {
return (new Classifier());
}
} class_classifier; Classifier::Classifier() :
slot_(), nslot_(), maxslot_(-), shift_(), mask_(0xffffffff), nsize_()
{
default_target_ = ; bind("offset_", &offset_);
bind("shift_", &shift_);
bind("mask_", &mask_);
} int Classifier::classify(Packet *p)
{
return (mshift(*((int*) p->access(offset_))));
} Classifier::~Classifier()
{
delete [] slot_;
} void Classifier::set_table_size(int nn)
{
nsize_ = nn;
} void Classifier::alloc(int slot)
{
NsObject** old = slot_;
int n = nslot_;
if (old == )
{
if (nsize_ != ) {
//printf("classifier %x set to %d....%dth visit\n", this, nsize_, i++);
nslot_ = nsize_;
}
else {
//printf("classifier %x set to 32....%dth visit\n", this, j++);
nslot_ = ;
}
}
while (nslot_ <= slot)
nslot_ <<= ;
slot_ = new NsObject*[nslot_];
memset(slot_, , nslot_ * sizeof(NsObject*));
for (int i = ; i < n; ++i)
slot_[i] = old[i];
delete [] old;
} void Classifier::install(int slot, NsObject* p)
{
if (slot >= nslot_)
alloc(slot);
slot_[slot] = p;
if (slot >= maxslot_)
maxslot_ = slot;
} void Classifier::clear(int slot)
{
slot_[slot] = ;
if (slot == maxslot_) {
while (--maxslot_ >= && slot_[maxslot_] == )
;
}
} int Classifier::allocPort (NsObject *nullagent)
{
return getnxt (nullagent);
} int Classifier::getnxt(NsObject *nullagent)
{
int i;
for (i=; i < nslot_; i++)
if (slot_[i]== || slot_[i]==nullagent)
return i;
i=nslot_;
alloc(nslot_);
return i;
} /*
* objects only ever see "packet" events, which come either
* from an incoming link or a local agent (i.e., packet source).
*/
void Classifier::recv(Packet* p, Handler*h)
{
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);
} /*
* perform the mapping from packet to object
* perform upcall if no mapping
*/ NsObject* Classifier::find(Packet* p)
{
NsObject* node = NULL;
int cl = classify(p);
if (cl < || cl >= nslot_ || (node = slot_[cl]) == ) {
if (default_target_)
return default_target_;
/*
* Sigh. Can't pass the pkt out to tcl because it's
* not an object.
*/
Tcl::instance().evalf("%s no-slot %ld", name(), cl);
if (cl == TWICE) {
/*
* Try again. Maybe callback patched up the table.
*/
cl = classify(p);
if (cl < || cl >= nslot_ || (node = slot_[cl]) == )
return (NULL);
}
}
return (node);
} int Classifier::install_next(NsObject *node) {
int slot = maxslot_ + ;
install(slot, node);
return (slot);
} int Classifier::command(int argc, const char*const* argv)
{
Tcl& tcl = Tcl::instance();
if(argc == ) {
if (strcmp(argv[], "defaulttarget") == ) {
if (default_target_ != )
tcl.result(default_target_->name());
return (TCL_OK);
}
} else if (argc == ) {
/*
* $classifier alloc-port nullagent
*/
if (strcmp(argv[],"alloc-port") == ) {
int slot;
NsObject* nullagent =
(NsObject*)TclObject::lookup(argv[]);
slot = getnxt(nullagent);
tcl.resultf("%u",slot);
return(TCL_OK);
}
/*
* $classifier clear $slot
*/
if (strcmp(argv[], "clear") == ) {
int slot = atoi(argv[]);
clear(slot);
return (TCL_OK);
}
/*
* $classifier installNext $node
*/
if (strcmp(argv[], "installNext") == ) {
//int slot = maxslot_ + 1;
NsObject* node = (NsObject*)TclObject::lookup(argv[]);
if (node == NULL) {
tcl.resultf("Classifier::installNext attempt "
"to install non-object %s into classifier", argv[]);
return TCL_ERROR;
};
int slot = install_next(node);
tcl.resultf("%u", slot);
return TCL_OK;
}
/*
* $classifier slot snum
* returns the name of the object in slot # snum
*/
if (strcmp(argv[], "slot") == ) {
int slot = atoi(argv[]);
if (slot >= && slot < nslot_ && slot_[slot] != NULL) {
tcl.resultf("%s", slot_[slot]->name());
return TCL_OK;
}
tcl.resultf("Classifier: no object at slot %d", slot);
return (TCL_ERROR);
}
/*
* $classifier findslot $node
* finds the slot containing $node
*/
if (strcmp(argv[], "findslot") == ) {
int slot = ;
NsObject* node = (NsObject*)TclObject::lookup(argv[]);
if (node == NULL) {
return (TCL_ERROR);
}
while (slot < nslot_) {
// check if the slot is empty (xuanc, 1/14/02)
// fix contributed by Frank A. Zdarsky
// <frank.zdarsky@kom.tu-darmstadt.de>
if (slot_[slot] &&
strcmp(slot_[slot]->name(), argv[]) == ){
tcl.resultf("%u", slot);
return (TCL_OK);
}
slot++;
}
tcl.result("-1");
return (TCL_OK);
}
if (strcmp(argv[], "defaulttarget") == ) {
default_target_=(NsObject*)TclObject::lookup(argv[]);
if (default_target_ == )
return TCL_ERROR;
return TCL_OK;
}
} else if (argc == ) {
/*
* $classifier install $slot $node
*/
if (strcmp(argv[], "install") == ) {
int slot = atoi(argv[]);
NsObject* node = (NsObject*)TclObject::lookup(argv[]);
install(slot, node);
return (TCL_OK);
}
}
return (NsObject::command(argc, argv));
} void Classifier::set_table_size(int, int)
{}
ns2.35-classifier.cc的更多相关文章
- 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.运行一 ...
- 在ns2.35下完成柯老师lab18实验
说明:柯志亨老师<ns2仿真实验-----多媒体和无线网络通信>这本书lab18实验为“无线网络封包传输遗失模型”的实验.该无线传输遗失模型是柯老师自己开发的,原始的ns-allinone ...
- 在ns2.35中添加myevalvid框架
在用ns2进行网络视频通信仿真的时候,先要为我们自己的ns2添加evalvid或者myevalvid框架.其中myevalvid框架是由柯志亨老师整合evalvid和ns2之后得出的新框架,笔者建议大 ...
- Ubuntu14.04下安装ns2.35
我选择的版本是2.35最新版本,安装环境是Ubuntu 14.04. 1.下载ns2的安装包,这里我选择的是ns-allinone-2.35.tar.gz压缩格式的all in one安装包,all ...
- Ubuntu12.04 LTS 32位 安装ns-2.35
ubuntu12.04lts 32-bit默认采用gcc 4.6和g++4.6,而ns的最新版本ns 2.3.5也采用了相同到版本,所以这方面不会有版本不同到问题 收回上面这句话..../valida ...
- Ubuntu 16——安装——ns2.35和nam
Ubuntu 16.04 安装ns2.35+nam 总结出以下安装步骤 1: 更新源 sudo apt-get update #更新源列表 sudo apt-get upgrade #更新已经安装的包 ...
- classifier.cc-recv() [ns2.35]
//without comments int chooseECNSlot() { ; ;i<=nslot_;i++) { *count) { *count); )*ti; ;j<=nslo ...
- 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 ...
- NS2仿真:公交车移动周期模型及性能分析
NS2仿真实验报告3 实验名称:公交车移动周期模型及性能分析 实验日期:2015年3月16日~2015年3月21日 实验报告日期:2015年3月22日 一.实验环境(网络平台,操作系统,网络拓扑图) ...
随机推荐
- em,rem,px的实际应用
看了好多的文章,就只是在看他们的换算,没有实际做出例子所以一直很疑惑,不知道到底是怎么写的.今天写了一个demo.务必彻底弄清楚. 先说三者的区别: 首先是我们常见的px. px: em:相对长度单位 ...
- Unity QualitySettings.antiAliasing 抗锯齿
QualitySettings.antiAliasing 抗锯齿 Description 描述 Set The AA Filtering option. 设置AA过滤选项. The AntiAliaz ...
- (转)Python random模块
原文:https://my.oschina.net/cuffica/blog/33336 https://www.cnblogs.com/renpingsheng/p/7105296.html ran ...
- Array【数组】和Object【对象】的特性比较
数组是JavaScript提供的一个内部对象,它是一个标准的集合,我们可以添加(push).删除(shift)里面元素,我们还可以通过for循环遍历里面的元素. 那么除了数组我们在JavaScript ...
- 批量修改dos文件到unix
1. 安装dos2unix 2. 执行:find ./ -type f | xargs dos2unix
- 入门系列之在Nginx配置Gzip
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由小铁匠米兰的v 发表于云+社区专栏 简介 网站加载的速度取决于浏览器必须下载的所有文件的大小.减少要传输的文件的大小可以使网站不仅加载 ...
- Spark Streaming初探
1. 介绍 Spark Streaming是Spark生态系统中一个重要的框架,建立在Spark Core之上,与Spark SQL.GraphX.MLib相并列. Spark Streaming是 ...
- Java入门系列-27-反射
咱们可能都用过 Spring AOP ,底层的实现原理是怎样的呢? 反射常用于编写工具,企业级开发要用到的 Mybatis.Spring 等框架,底层的实现都用到了反射.能用好反射,就能提高我们编码的 ...
- Java入门系列-19-泛型集合
集合 如何存储每天的新闻信息?每天的新闻总数是不固定的,太少浪费空间,太多空间不足. 如果并不知道程序运行时会需要多少对象,或者需要更复杂方式存储对象,可以使用Java集合框架. Java 集合框架提 ...
- 查找正序排列的List中缺失的日期数据的一个算法
Code: public List<DateTime> getMissDateData() { DateTime[] keys = { DateTime.Now.AddDays(-5), ...