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

📄 sharedmedia.cc

📁 ns2.1b5版本中cbrp碼
💻 CC
字号:
/*    SharedMedia.cc   $Id: sharedmedia.cc,v 1.2 1998/08/12 06:48:49 dmaltz Exp $   */#include <math.h>#include <packet.h>#include <cmu/node.h>#include <cmu/net-if.h>#include <cmu/propagation.h>#include <cmu/modulation.h>#include <cmu/omni-antenna.h>#include <cmu/sharedmedia.h>/* ======================================================================   SharedMedia Interface   ====================================================================== */static class SharedMediaClass: public TclClass {public:        SharedMediaClass() : TclClass("NetIf/SharedMedia") {}        TclObject* create(int, const char*const*) {                return (new SharedMedia);        }} class_SharedMedia;SharedMedia::SharedMedia(void) : NetIf(){    Rb = 2*1e6;		                  // 2 Mb  Pt = pow(10, 2.45) * 1e-3;		  // 24.5 dbm, ~ 281.8mw  lambda = SPEED_OF_LIGHT / (914 * 1e6);  // 914 mHz  L = 1.0;  freq = -1.0;  /*   *  It sounds like 10db should be the capture threshold.   *   *  If a node is presently receiving a packet a a power level   *  Pa, and a packet at power level Pb arrives, the following   *  comparion must be made to determine whether or not capture   *  occurs:   *   *    10 * log(Pa) - 10 * log(Pb) > 10db   *   *  OR equivalently   *   *    Pa/Pb > 10.   *   */  CPThresh = 10.0;  CSThresh = 1.559e-11;  RXThresh = 3.652e-10;  bind("CPThresh_", &CPThresh);  bind("CSThresh_", &CSThresh);  bind("RXThresh_", &RXThresh);  bind("Rb_", &Rb);  bind("Pt_", &Pt);  bind("freq_", &freq);  bind("L_", &L);  if (freq != -1.0)     { // freq was set by tcl code      lambda = SPEED_OF_LIGHT / freq;    }}intSharedMedia::command(int argc, const char*const* argv){  TclObject *obj;    if(argc == 3)     {      if( (obj = TclObject::lookup(argv[2])) == 0) 	{	  fprintf(stderr, "SharedMedia: %s lookup of %s failed\n", argv[1],		  argv[2]);	  return TCL_ERROR;	}      if (strcasecmp(argv[1], "antenna") == 0) 	{	  ant = (Antenna*) obj;	  return TCL_OK;	}    }  return NetIf::command(argc,argv);} void SharedMedia::xmitPacket(Packet *p){  /*   *  Stamp the packet with the interface arguments   */  p->txinfo.stamp(node_, ant->copy(), Pt, lambda);    // Send the packet  channel_->recv(p, this);}int SharedMedia::recvPacket(Packet *p, double *RxPr){  PacketStamp s;  double Pr;  int pkt_recvd = 0;  if(propagation_) {    s.stamp(node_, ant, 0, lambda);        Pr = propagation_->Pr(&p->txinfo, &s, this);        if (Pr < CSThresh) {      pkt_recvd = 0;      goto DONE;    }    if (Pr < RXThresh) {      /*       * We can detect, but not successfully receive       * this packet.       */      hdr_cmn *hdr = HDR_CMN(p);      hdr->error() = 1;#if DEBUG > 3      printf("SM %f.9 _%d_ drop pkt from %d low POWER %e/%e\n",	     Scheduler::instance().clock(), node_->index(),	     p->txinfo.getNode()->index(),	     Pr,RXThresh);#endif    }  }    if(modulation) {    hdr_cmn *hdr = HDR_CMN(p);    hdr->error() = modulation->BitError(Pr);  }    /*   * The MAC layer must be notified of the packet reception   * now - ie; when the first bit has been detected - so that   * it can properly do Collision Avoidance / Detection.   */  pkt_recvd = 1;DONE:  p->txinfo.getAntenna()->release();  *RxPr = Pr;  /* WILD HACK: The following two variables are a wild hack.     They will go away in the next release...     They're used by the mac-802_11 object to determine     capture.  This will be moved into the net-if family of      objects in the future. */  p->txinfo.RxPr = Pr;  p->txinfo.CPThresh = CPThresh;  return pkt_recvd;}voidSharedMedia::dump(void) const{  NetIf::dump();  fprintf(stdout,	  "\tPt: %f, Gt: %f, Gr: %f, lambda: %f, L: %f\n",	  Pt, ant->getTxGain(0,0,0,lambda), ant->getRxGain(0,0,0,lambda), lambda, L);  fprintf(stdout, "\tRb: %f\n", Rb);  fprintf(stdout, "--------------------------------------------------\n");}

⌨️ 快捷键说明

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