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日 一.实验环境(网络平台,操作系统,网络拓扑图) ...
随机推荐
- 删除centos 7 系统自带的 openjdk
1. 查看是否系统自带openjdk. java -version 2. 查看jdk位置 rpm -qa | grep java 3. 删除jdk rpm -e --nodeps java--ope ...
- 微信公共平台注册 bug: 验证码不应该输入后,就立即检查其有效性
本文链接: https://www.cnblogs.com/hchengmx/p/10793037.html 刚刚想注册个微信公众号,就发现了这个问题,在这里记录一下. 已经发到testhome了,链 ...
- Apache-jmeter3.3安装
一.首先检查机子上是否有安装jdk 检查方式,在cmd中输入java,出现如下信息,即已经安装好jdk 若未安装jdk,则看如下步骤 步骤一: 1.下载jdk,到官网下载jdk,地址:http://w ...
- ztree树样式的设计
ztree的功能虽然很是强大,但是唯一有一点就是样式有点普通,所以如果我们需要修改样式,那么就只能进行样式重新覆盖了 样式代码,这些都是根据实际样式进行覆盖 /** * tree的选中样式 */ .c ...
- 9.1_the end
选择题 1.考察正则,书写一个6位数的邮箱 a var mail=/\d{6}/; b var mail=new RegExp("/\d{6}/"); 分析:对a,应该要添加开头和 ...
- Maven的目录结构和常用命令
一.Maven项目的目录结构 1.顶级目录结构 src:该目录主要存放的是项目的源代码文件. target:该目录是项目编译后产生的一个目录,主要存放的是编译后的.class文件. pom.xm ...
- mysql服务器运维简单命令介绍
1.mysql>show processlist; 此处关注查询时间,关注谁锁住了表,谁最多: 2.查看开启的日志 mysql>show global variables like '%l ...
- jsp继承rapid库
如果jsp不使用继承方式开发,而是用标准的指令或动作元素去include,实在是太多重复代码. rapid-framework是谷歌的一个项目,可以实现jsp网页的继承,也就是书写模板页. 但是在ma ...
- [转]Oracle中没有 if exists(...)
本文转自:http://blog.csdn.net/hollboy/article/details/7550171 对于Oracle中没有 if exists(...) 的语法,目前有许多种解决方法, ...
- url字符转义
作者在做短链接功能时,url参数里带了&字符,结果无法转换.后来查了一下,发现可以用其它符号代替.下面是对应表 + URL 中+号表示空格 ...