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日 一.实验环境(网络平台,操作系统,网络拓扑图) ...
随机推荐
- 08-oracle统计函数(单组分组函数)
--count时尽量count(列名),count(*)也可以. --count,max,min,sum,avg,median(中位数) select count(empno),count(disti ...
- 如何使一个div能够铺满整个页面? && 模态框的制作 && outerHTML
说明: 使用 ele.outerHTML = '' 这样的方法可以很容易的清除一个元素. 当然也可以使用parent.removeChild() ,但是相较而言,还是使用 outerHTML = '' ...
- Jmeter测试计划中的元素
测试计划中的元素(elements of a test plan) 本节描述测试计划不同的部分. 最小测试将包括测试计划.线程组和一个或多个采样器. 1 测试计划(Test Plan) 测试计划对象有 ...
- 【CSS】 元素块与文字的各种居中解决方案
元素块的居中 首先有这样一个200*200px的元素块在界面内. 元素块的水平居中: 如果想要让其水平居中,则有三种方法: 第一种是知道屏幕的长宽,则根据计算,(屏幕宽X-元素块宽Y)/ 2的结果是元 ...
- 深入redis内部--初始化服务器
初始化服务器代码如下: void initServer() { int j; signal(SIGHUP, SIG_IGN); signal(SIGPIPE, SIG_IGN); setupSigna ...
- Windows开启telnet命令
1.点击开始 → 运行 → 输入telnet,回车. 2.点击启用或关闭Windows功能 3.找到Telnet客户端,勾选,点击确认 4.搞定,测试一下 打开CMD,在出来的DOS界面里,输入tel ...
- Linux文件夹和文件创建删除命令
Linux删除文件夹命令 linux删除目录很简单,很多人还是习惯用rmdir,不过一旦目录非空,就陷入深深的苦恼之中,现在使用rm -rf命令即可.直接rm就可以了,不过要加两个参数-rf 即:rm ...
- ASP.NET MVC4 新手入门教程之四 ---4.添加一个模型
在本节中,您将添加一些类,用于管理数据库中的电影.这些类将 ASP.NET MVC 应用程序的"模型"部分. 您将使用一种称为实体框架的.NET 框架数据接入技术来定义和使用这些模 ...
- 使用eclipse创建maven web项目
1.新建项目: 2.选择模板: 3.输入项目信息: 4.新建的项目结构,发现index.jsp报错,直接删除重新创建一个index.jsp文件后,发现仍然报错,再在pom/xml文件中添加相应的ser ...
- Oracle 数据库字典 sys.col$ 表中关于type#的解释
sys.col$ 表是oracle基础数据字典表中的列表,表中描述了数据库中各列信息,其中type#是列的数据类型.以下表格说明了各个数值的含义,以供参考. 值 说明 1 如果列 charsetfor ...