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

📄 omni_mcast.cc

📁 ns下的dd协议代码 可以进行wsn路由协议的仿真
💻 CC
📖 第 1 页 / 共 2 页
字号:
  if (pkt==NULL) return NULL;  hdr_cmn*  cmh = HDR_CMN(pkt);  cmh->size() = 36;  hdr_cdiff* dfh = HDR_CDIFF(pkt);  dfh->ts_ = NOW;  return pkt;}void OmniMcastAgent::MACprepare(Packet *pkt, nsaddr_t next_hop, 				unsigned int type, bool lk_dtct){  hdr_cdiff* dfh = HDR_CDIFF(pkt);  hdr_cmn* cmh = HDR_CMN(pkt);  hdr_ip*  iph = HDR_IP(pkt);  dfh->forward_agent_id = here_;   if (type == NS_AF_ILINK && next_hop == (nsaddr_t)MAC_BROADCAST) {      cmh->xmit_failure_ = 0;      cmh->next_hop() = MAC_BROADCAST;      cmh->addr_type() = NS_AF_ILINK;      cmh->direction() = hdr_cmn::DOWN;            iph->src_ = here_;      iph->dst_.addr_ = next_hop;      iph->dst_.port_ = ROUTING_PORT;      dfh->num_next = 1;      dfh->next_nodes[0] = next_hop;      return;       }    if (lk_dtct != 0) {    cmh->xmit_failure_ = OmniMcastXmitFailedCallback;    cmh->xmit_failure_data_ = (void *) this;  }  else {    cmh->xmit_failure_ = 0;  }  cmh->direction() = hdr_cmn::DOWN;  cmh->next_hop() = next_hop;  cmh->addr_type() = type;    iph->src_ = here_;  iph->dst_.addr_ = next_hop;  iph->dst_.port_ = ROUTING_PORT;    dfh->num_next = 1;  dfh->next_nodes[0] = next_hop;}void OmniMcastAgent::MACsend(Packet *pkt, Time delay){  hdr_cmn*  cmh = HDR_CMN(pkt);  hdr_cdiff* dfh = HDR_CDIFF(pkt);  if (dfh->mess_type == DATA)    cmh->size() = (God::instance()->data_pkt_size) + 4*(dfh->num_next - 1);  else    cmh->size() = 36 + 4*(dfh->num_next -1);  Scheduler::instance().schedule(ll, pkt, delay);}void OmniMcastAgent::xmitFailed(Packet *pkt){  // For future extension if needed.}void OmniMcastAgent::StickPacketInArpBuffer(Packet *pkt){  Time min = DBL_MAX;  int  min_index = 0;  int  c;  for (c=0; c < ARP_BUF_SIZE; c++) {    if (arp_buf[c].p == NULL) {      arp_buf[c].t = NOW;      arp_buf[c].attempt = 1;      arp_buf[c].p = pkt;      return;    }    else if (arp_buf[c].t < min) {      min = arp_buf[c].t;      min_index = c;    }  }  // Before killing somebody, let him get a last chance to send.  ARPEntry *llinfo;  hdr_cmn*  cmh = HDR_CMN(arp_buf[min_index].p);  llinfo= arp_table->arplookup(cmh->next_hop());  if (llinfo == 0) {    // printf("ARP fails. And must give up slot.\n");      xmitFailed(arp_buf[min_index].p);  }  else      MACsend(arp_buf[min_index].p, 0);  // The new packet is taking over the slot of the dead guy.  arp_buf[min_index].t = NOW;  arp_buf[min_index].attempt = 1;  arp_buf[min_index].p = pkt;}void OmniMcastAgent::ArpBufferCheck(){  int c;  ARPEntry *llinfo;  hdr_cmn*  cmh;  for (c = 0; c < ARP_BUF_SIZE; c++) {    if (arp_buf[c].p == NULL)      continue;        cmh = HDR_CMN(arp_buf[c].p);    llinfo= arp_table->arplookup(cmh->next_hop());    if (llinfo != 0) {      MACsend(arp_buf[c].p, 0);      arp_buf[c].p = NULL;      continue;}        if (arp_buf[c].attempt > ARP_MAX_ATTEMPT) {      // printf("ARP fails. Too many attempts.\n");      xmitFailed(arp_buf[c].p);      arp_buf[c].p = NULL;      continue;    }    arp_table->arprequest(THIS_NODE, cmh->next_hop(), (LL *)ll);    arp_buf[c].attempt ++;  }}void OmniMcastAgent::StickPacketInSendBuffer(Packet *p){  Time min = DBL_MAX;  int min_index = 0;  int c;  for (c = 0 ; c < SEND_BUF_SIZE ; c ++) {    if (send_buf[c].p  == NULL)      {	send_buf[c].t = NOW;	send_buf[c].p = p;	return;      }    else if (send_buf[c].t < min)      {	min = send_buf[c].t;	min_index = c;      }  }  // Before killing somebody, you'd better give him the last chance.  if (send_buf[min_index].p != NULL) {    MACsend(send_buf[min_index].p, 0);  }  // A new packet is taking over the slot.  send_buf[min_index].t = Scheduler::instance().clock();  send_buf[min_index].p = p;}void OmniMcastAgent::SendBufferCheck(){  for (int c = 0; c < SEND_BUF_SIZE; c++) {    if (send_buf[c].p != NULL) {      MACsend(send_buf[c].p, 0);      send_buf[c].p = NULL;    }  }}void OmniMcastAgent::trace (char *fmt,...){  va_list ap;  if (!tracetarget)    return;  va_start (ap, fmt);  vsprintf (tracetarget->pt_->buffer (), fmt, ap);  tracetarget->pt_->dump ();  va_end (ap);}int OmniMcastAgent::command(int argc, const char*const* argv){    Tcl& tcl =  Tcl::instance();  if (argc == 2) {    if (strcasecmp(argv[1], "reset-state")==0) {      reset();      return TCL_OK;    }    if (strcasecmp(argv[1], "reset")==0) {      return Agent::command(argc, argv);    }    if (strcasecmp(argv[1], "start")==0) {      Start();      return TCL_OK;    }    if (strcasecmp(argv[1], "stop")==0) {      return TCL_OK;    }    if (strcasecmp(argv[1], "terminate")==0) {      Terminate();      return TCL_OK;    }    if (strcasecmp(argv[1], "stop-source")==0) {      StopSource();      return TCL_OK;    }  } else if (argc == 3) {    if (strcasecmp(argv[1], "on-node")==0) {      node = (Node *)tcl.lookup(argv[2]);      return TCL_OK;    }    if (strcasecmp(argv[1], "add-ll") == 0) {      TclObject *obj;      if ( (obj = TclObject::lookup(argv[2])) == 0) {	fprintf(stderr, "OmniMcast Node: %d lookup of %s failed\n", THIS_NODE,		argv[2]);	return TCL_ERROR;      }      ll = (NsObject *) obj;      // What a hack !!!      arp_table = ((LL *)ll)->arp_table();      if (arp_table == NULL) 	return TCL_ERROR;     return TCL_OK;    }    if (strcasecmp (argv[1], "tracetarget") == 0) {      TclObject *obj;      if ((obj = TclObject::lookup (argv[2])) == 0) {	  fprintf (stderr, "%s: %s lookup of %s failed\n", __FILE__, argv[1],		   argv[2]);	  return TCL_ERROR;      }      tracetarget = (Trace *) obj;      return TCL_OK;    }    if (strcasecmp(argv[1], "port-dmux") == 0) {      TclObject *obj;      if ( (obj = TclObject::lookup(argv[2])) == 0) {	fprintf(stderr, "OmniMcast Node: %d lookup of %s failed\n", THIS_NODE,		argv[2]);	return TCL_ERROR;      }      port_dmux = (NsObject *) obj;      return TCL_OK;    }  }   return Agent::command(argc, argv);}void OmniMcastAgent::reset(){  PktTable.reset();  for (int i=0; i<MAX_DATA_TYPE; i++) {    routing_table[i].reset();  }  clear_arp_buf();  clear_send_buf();}void OmniMcastAgent::clear_arp_buf(){  for (int i=0; i<ARP_BUF_SIZE; i++) {    arp_buf[i].t = 0;    arp_buf[i].attempt = 0;    if (arp_buf[i].p != NULL)       Packet::free(arp_buf[i].p);    arp_buf[i].p = NULL;  }}void OmniMcastAgent::clear_send_buf(){  for (int i=0; i<SEND_BUF_SIZE; i++) {    send_buf[i].t = 0;    if (send_buf[i].p != NULL)      Packet::free(send_buf[i].p);    send_buf[i].p = NULL;  }}				    void OmniMcast_Entry::reset(){  clear_agentlist(source);  clear_agentlist(sink);  source = NULL;  sink = NULL;}void OmniMcast_Entry::clear_agentlist(Agent_List *list){  Agent_List *cur=list;  Agent_List *temp = NULL;  while (cur != NULL) {    temp = AGENT_NEXT(cur);    delete cur;    cur = temp;  }}

⌨️ 快捷键说明

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