⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 channel.cc

📁 ns2.1b5版本中cbrp碼
💻 CC
字号:
/*  channel.cc  $Id: channel.cc,v 1.6 1998/11/19 06:22:10 dmaltz Exp $  */#include <float.h>#include <delay.h>#include <object.h>#include <packet.h>#include <trace.h>#include <cmu/debug.h>#include <cmu/list.h>#include <cmu/net-if.h>#include <cmu/arp.h>#include <cmu/topography.h>#include <cmu/node.h>#include <cmu/channel.h>static class ChannelClass : public TclClass {public:        ChannelClass() : TclClass("Channel") {}        TclObject* create(int, const char*const*) {                return (new Channel);        }} class_channel;/* ======================================================================   NS Initialization Functions   ====================================================================== */intChannel::command(int argc, const char*const* argv){	if(argc == 2) {		Tcl& tcl = Tcl::instance();		if(strncasecmp(argv[1], "id", 2) == 0) {			tcl.resultf("%d", index);			return TCL_OK;		}	}	else if(argc == 3) {		TclObject *obj;		if( (obj = TclObject::lookup(argv[2])) == 0) {			fprintf(stderr, "%s lookup failed\n", argv[1]);			return TCL_ERROR;		}		if(strncasecmp(argv[1], "addif", 5) == 0) {			((NetIf*) obj)->insertchnl(this, &ifhead);			return TCL_OK;		}	}	return TclObject::command(argc, argv);}/* ======================================================================   Other class functions   ====================================================================== */static int ChannelIndex = 0;Channel::Channel(){	index = ChannelIndex++;	LIST_INIT(&ifhead);}voidChannel::recv(Packet *p, NetIf *tifp){	send(p, tifp);}voidChannel::send(Packet* p, NetIf *tifp){	Scheduler	&s = Scheduler::instance();	MobileNode	*tnode = tifp->node();	NetIf		*rifp = ifhead.lh_first;	MobileNode	*rnode = 0;	double		propdelay;	Packet		*newp;	for( ; rifp; rifp = rifp->nextchnl()) {		rnode = rifp->node();		if(rnode == tnode)			continue;		/*		 * Each node needs to get their own copy of this packet.		 * Since collisions occur at the receiver, we can have		 * two nodes canceling and freeing the *same* simulation		 * event.		 *		 */		newp = p->copy();		/*		 * Each node on the channel receives a copy of the		 * packet.  The propagation delay determines exactly		 * when the receiver's interface detects the first		 * bit of this packet.		 */		propdelay = tnode->propdelay(rnode);		assert(propdelay >= 0.0);		if (propdelay == 0.0) {		  /* if the propdelay is 0 b/c two nodes are on top of 		     each other, move them slightly apart -dam 7/28/98 */		  propdelay = 2 * DBL_EPSILON;		  printf ("propdelay 0: %d->%d at %f\n",			  tnode->index(), rnode->index(), s.clock());		}		s.schedule(rifp, newp, propdelay);	}	Packet::free(p);}voidChannel::dump(void){	NetIf *n;	fprintf(stdout, "Network Interface List\n"); 	for(n = ifhead.lh_first; n; n = n->nextchnl() )		n->dump();	fprintf(stdout, "--------------------------------------------------\n");}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -