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日 一.实验环境(网络平台,操作系统,网络拓扑图) ...
随机推荐
- iozone文件系统测试工具在AM335x上的移植
IOzone下载 下载地址:http://www.iozone.org 如下: 解压iozone,并进入到解压路径下的src/current 我的是 iozone3_487 命令:cd i ...
- J15W-J45W铜截止阀厂家,J15W-J45W铜截止阀价格 - 专题栏目 - 无极资讯网
无极资讯网 首页 最新资讯 最新图集 最新标签 搜索 J15W-J45W铜截止阀 无极资讯网精心为您挑选了(J15W-J45W铜截止阀)信息,其中包含了(J15W-J45W铜截止阀)厂家,(J15 ...
- node 基础小结
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- Binder 驱动(三)
Binder 驱动是 Binder 的最终实现, ServiceManager 和 Client/Service 进程间通信最终都是由 Binder 驱动投递的. Binder 驱动的代码位于 ker ...
- CentOS6.4 安装Maven及Nexus仓库代理
本文安装的apache-maven-3.5.0-bin.tar.gz,nexus-2.9.0-04-bundle.tar.gz 1.由于网络并不是特别好我这边是通过本地下载过来,通过sftp上传至Ce ...
- oracle系统包——dbms_alert用法
oracle内部提供的在数据库内部和应用程序间通信的方式有以下几种:1.警报,就是DBMS_ALERT包提供的功能:2.管道,由DBMS_PIPE提供:3.高级队列,这个就很复杂,当然提供的功能也是很 ...
- input输入提示历史记录
一般便于用户的输入习惯,我们都会提示历史消息,让用户有更好的使用体验,以前可能比较多朋友会用js来实现,现在HTML5的datalist可以轻松帮我们实现这个功能!只需以下几行代码 <!doct ...
- golang学习之rpc实例
rpc(远程过程调用),可以像调用本地程序一样调用远端服务,rpc分为http方式和tcp连接方式,使用http的rpc调用如下: 首先是server端: // rpc_server project ...
- Java基础(六)包装类
一.包装类 JAVA是一种面向对象语言,java中的类把方法与数据连接在一起,但在JAVA中不能定义基本类型对象,为了能将基本类型视为对象进行处理,java为每个基本类型都提供了包装类. 对应关系如下 ...
- IDEA 2017的插件mybatis plugin(绿色免安装)
https://blog.csdn.net/u014365133/article/details/78885189 插件下载 https://files.cnblogs.com/files/techl ...