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

📄 dsragent.cc

📁 柯老师网站上找到的
💻 CC
📖 第 1 页 / 共 5 页
字号:
      Packet::free(p.pkt);  // pkt is a route request we've already processed      p.pkt = 0;      return; // drop silently    }    // we're going to process this request now, so record the req_num  request_table.insert(p.src, p.src, srh->rtreq_seq());  /*  - if it's a Ring 0 search, check the rt$ for a reply and use it if     possible.  There's not much point in doing Ring 0 search if you're      not going to check the cache.  See the comment about turning off all     reply from cache behavior near the definition of d_r_f_c_o_p (if your      workload had really good spatial locality, it might still make      sense 'cause your target is probably sitting next to you)      - if reply from cache is on, check the cache and reply if possible      - otherwise, just propagate if possible. */  if ((srh->max_propagation() == 0 || dsragent_reply_from_cache_on_propagating)      && replyFromRouteCache(p))	  return;			// all done  // does the orginator want us to propagate?  if (p.route.length() > srh->max_propagation())    { 	// no propagation      if (verbose_srr)         trace("SRR %.5f _%s_ dropped %s #%d (prop limit exceeded)",              Scheduler::instance().clock(), net_id.dump(), p.src.dump(),              srh->rtreq_seq());      Packet::free(p.pkt); // pkt isn't for us, and isn't data carrying      p.pkt = 0;      return;		    }  // can we propagate?  if (p.route.full())    { 	// no propagation      trace("SRR %.5f _%s_ dropped %s #%d (SR full)",            Scheduler::instance().clock(), net_id.dump(), p.src.dump(),	    srh->rtreq_seq());      /* pkt is a rt req, even if data carrying, we don't want to log 	 the drop using drop() since many nodes could be dropping the 	 packet in this fashion */      Packet::free(p.pkt);      p.pkt = 0;      return;		    }  // add ourselves to the source route  p.route.appendToPath(net_id);  if (verbose_srr)    trace("SRR %.5f _%s_ rebroadcast %s #%d ->%s %s",          Scheduler::instance().clock(), net_id.dump(), p.src.dump(),          srh->rtreq_seq(), p.dest.dump(), p.route.dump());  sendOutPacketWithRoute(p, false);  return;      }/*===========================================================================  Helpers---------------------------------------------------------------------------*/boolDSRAgent::ignoreRouteRequestp(SRPacket &p)// should we ignore this route request?{  hdr_sr *srh =  (hdr_sr*)p.pkt->access(off_sr_);  if (request_table.get(p.src) >= srh->rtreq_seq())    { // we've already processed a copy of this reqest so      // we should drop the request silently      return true;    }  if (p.route.member(net_id,MAC_id))    { // we're already on the route, drop silently      return true;    }  if (p.route.full())    { // there won't be room for us to put our address into      // the route      // so drop silently - sigh, so close, and yet so far...      // Note that since we don't record the req_id of this message yet,      // we'll process the request if it gets to us on a shorter path      return true;    }  return false;}boolDSRAgent::replyFromRouteCache(SRPacket &p)  /* - see if can reply to this route request from our cache     if so, do it and return true, otherwise, return false      - frees or hands off p iff returns true */{  Path rest_of_route;  Path complete_route = p.route;  /* we shouldn't yet be on on the pkt's current source route */  assert(!p.route.member(net_id, MAC_id));  // do we have a cached route the target?  /* XXX what if we have more than 1?  (and one is legal for reply from     cache and one isn't?) 1/28/97 -dam */  if (!route_cache->findRoute(p.dest, rest_of_route, 0))    { // no route => we're done      return false;    }  /* but we should be on on the remainder of the route (and should be at   the start of the route */  assert(rest_of_route[0] == net_id || rest_of_route[0] == MAC_id);  if (rest_of_route.length() + p.route.length() > MAX_SR_LEN)    return false; // too long to work with...  // add our suggested completion to the route so far  complete_route.appendPath(rest_of_route);  // call compressPath to remove any double backs  ::compressPath(complete_route);  if (!complete_route.member(net_id, MAC_id))    { // we're not on the suggested route, so we can't return it      return false;    }  // if there is any other information piggybacked into the  // route request pkt, we need to forward it on to the dst  hdr_cmn *cmh =  (hdr_cmn*)p.pkt->access(off_cmn_);  hdr_sr *srh =  (hdr_sr*)p.pkt->access(off_sr_);  int request_seqnum = srh->rtreq_seq();    if (PT_DSR != cmh->ptype()	// there's data      || srh->route_reply()      || (srh->route_error() && 	  srh->down_links()[srh->num_route_errors()-1].tell_addr 	  != GRAT_ROUTE_ERROR))    { // must forward the packet on      SRPacket p_copy = p;      p.pkt = 0;      srh->route_request() = 0;      p_copy.route = complete_route;      p_copy.route.setIterator(p.route.length());      assert(p.route[p.route.index()] == net_id);            if (verbose) trace("Sdebug %.9f _%s_ splitting %s to %s",                         Scheduler::instance().clock(), net_id.dump(),                         p.route.dump(), p_copy.route.dump());      sendOutPacketWithRoute(p_copy,false);    }  else     {      Packet::free(p.pkt);  // free the rcvd rt req before making rt reply      p.pkt = 0;    }  // make up and send out a route reply  p.route.appendToPath(net_id);  p.route.reverseInPlace();  route_cache->addRoute(p.route, Scheduler::instance().clock(), net_id);  p.dest = p.src;  p.src = net_id;  p.pkt = allocpkt();  hdr_ip *iph =  (hdr_ip*)p.pkt->access(off_ip_);  iph->saddr() = Address::instance().create_ipaddr(p.src.addr,RT_PORT);  iph->sport() = RT_PORT;  iph->daddr() = Address::instance().create_ipaddr(p.dest.addr,RT_PORT);  iph->dport() = RT_PORT;  iph->ttl() = 255;  srh = (hdr_sr*)p.pkt->access(off_sr_);  srh->init();  for (int i = 0 ; i < complete_route.length() ; i++)    complete_route[i].fillSRAddr(srh->reply_addrs()[i]);  srh->route_reply_len() = complete_route.length();  srh->route_reply() = 1;  // propagate the request sequence number in the reply for analysis purposes  srh->rtreq_seq() = request_seqnum;  hdr_cmn *cmnh =  (hdr_cmn*)p.pkt->access(off_cmn_);  cmnh->ptype() = PT_DSR;  cmnh->size() = IP_HDR_LEN;  trace("SRR %.9f _%s_ cache-reply-sent %s -> %s #%d (len %d) %s",	Scheduler::instance().clock(), net_id.dump(),	p.src.dump(), p.dest.dump(), request_seqnum, complete_route.length(),	complete_route.dump());  sendOutPacketWithRoute(p, true);  return true;}voidDSRAgent::sendOutPacketWithRoute(SRPacket& p, bool fresh, Time delay)     // take packet and send it out, packet must a have a route in it     // return value is not very meaningful     // if fresh is true then reset the path before using it, if fresh     //  is false then our caller wants us use a path with the index     //  set as it currently is{  hdr_sr *srh =  (hdr_sr*)p.pkt->access(off_sr_);  hdr_cmn *cmnh = (hdr_cmn*)p.pkt->access(off_cmn_);  assert(srh->valid());  assert(cmnh->size() > 0);  ID dest;  if (diff_subnet(p.dest,net_id)) {	  //dest = ID(node_->base_stn()->address(),::IP);	  dest = ID(node_->base_stn(),::IP);	  if (dest == net_id) 		  // Iam the base-station		  dest = p.dest;  }  else	  dest = p.dest;  if (dest == net_id)    { // it doesn't need to go on the wire, 'cause it's for us      recv(p.pkt, (Handler *) 0);      p.pkt = 0;      return;    }  if (fresh)    {      p.route.resetIterator();      if (verbose && !srh->route_request())	{	  trace("SO %.9f _%s_ originating %s %s", 		Scheduler::instance().clock(), 		net_id.dump(), packet_info.name(cmnh->ptype()), p.route.dump());	}    }  p.route.fillSR(srh);  cmnh->size() += srh->size();  // set direction of pkt to DOWN , i.e downward  cmnh->direction() = hdr_cmn::DOWN;    if (srh->route_request())    { // broadcast forward      cmnh->xmit_failure_ = 0;      cmnh->next_hop() = MAC_BROADCAST;      cmnh->addr_type() = NS_AF_ILINK;    }  else    { // forward according to source route      cmnh->xmit_failure_ = XmitFailureCallback;      cmnh->xmit_failure_data_ = (void *) this;      cmnh->next_hop() = srh->get_next_addr();            cmnh->addr_type() = srh->get_next_type();      srh->cur_addr() = srh->cur_addr() + 1;    }  /* put route errors at the head of the ifq somehow? -dam 4/13/98 */  // make sure we aren't cycling packets  //assert(p.pkt->incoming == 0); // this is an outgoing packet  //assert(cmnh->direction() == hdr_cmn::DOWN);  if (ifq->length() > 25)    trace("SIFQ %.5f _%s_ len %d",          Scheduler::instance().clock(), net_id.dump(), ifq->length());  // off it goes!  if (srh->route_request())    { // route requests need to be jittered a bit      Scheduler::instance().schedule(ll, p.pkt, 				     Random::uniform(RREQ_JITTER) + delay);    }  else    { // no jitter required       Scheduler::instance().schedule(ll, p.pkt, delay);    }  p.pkt = NULL; /* packet sent off */}voidDSRAgent::getRouteForPacket(SRPacket &p, ID dest, bool retry)  /* try to obtain a route for packet     pkt is freed or handed off as needed, unless retry == true     in which case it is not touched */{  // since we'll commonly be only one hop away, we should  // arp first before route discovery as an optimization...  Entry *e = request_table.getEntry(dest);  Time time = Scheduler::instance().clock();    /* for now, no piggybacking at all, queue all pkts */  if (!retry)     {      stickPacketInSendBuffer(p);      p.pkt = 0; // pkt is handled for now (it's in sendbuffer)    }#if 0  /* pre 4/13/98 logic -dam removed b/c it seemed more complicated than     needed since we're not doing piggybacking and we're returning     route replies via a reversed route (the copy in this code is     critical if we need to piggyback route replies on the route request to     discover the return path) */  /* make the route request packet */  SRPacket rrp = p;  rrp.pkt = p.pkt->copy();  hdr_sr *srh =  (hdr_sr*)rrp.pkt->access(off_sr_);  hdr_ip *iph =  (hdr_ip*)rrp.pkt->access(off_ip_);  hdr_cmn *cmnh =  (hdr_cmn*)rrp.pkt->access(off_cmn_);  iph->daddr() = Address::instance().create_ipaddr(dest.getNSAddr_t(),RT_PORT);  iph->dport() = RT_PORT;  iph->saddr() = Address::instance().create_ipaddr(net_id.getNSAddr_t(),RT_PORT);  iph->sport() = RT_PORT;  cmnh->ptype() = PT_DSR;  cmnh->size() = size_;  cmnh->num_forwards() = 0;#endif  /* make the route request packet */  SRPacket rrp;  rrp.dest = dest;  rrp.src = net_id;  rrp.pkt = allocpkt();  hdr_sr *srh =  (hdr_sr*)rrp.pkt->access(off_sr_);  hdr_ip *iph =  (hdr_ip*)rrp.pkt->access(off_ip_);  hdr_cmn *cmnh =  (hdr_cmn*)rrp.pkt->access(off_cmn_);    iph->daddr() = Address::instance().create_ipaddr(dest.getNSAddr_t(),RT_PORT);    iph->dport() = RT_PORT;  iph->saddr() =	  Address::instance().create_ipaddr(net_id.getNSAddr_t(),RT_PORT);   iph->sport() = RT_PORT;  cmnh->ptype() = PT_DSR;  cmnh->size() = size_ + IP_HDR_LEN; // add in IP header  cmnh->num_forwards() = 0;    srh->init();  if (BackOffTest(e, time))    { // it's time to start another route request cycle      if (dsragent_ring_zero_search)	{ // do a ring zero search	  e->last_type = LIMIT0;	  sendOutRtReq(rrp, 0);	}      else 	{ // do a propagating route request right now	  e->last_type = UNLIMIT;	  sendOutRtReq(rrp, MAX_SR_LEN);	}      e->last_arp = time;    }   else if (LIMIT0 == e->last_type && (time - e->last_arp) > arp_timeout)   { // try propagating rt req since we haven't heard back from limited one     e->last_type = UNLIMIT;     sendOutRtReq(rrp, MAX_SR_LEN);   }  else    { // it's not time to send another route request...      if (!retry && verbose_srr)	trace("SRR %.5f _%s_ RR-not-sent %s -> %s", 	      Scheduler::instance().clock(), 	      net_id.dump(), rrp.src.dump(), rrp.dest.dump());      Packet::free(rrp.pkt); // dump the route request packet we made up      rrp.pkt = 0;      return;    }}voidDSRAgent::sendOutRtReq(SRPacket &p, int max_prop)  // turn p into a route request and launch it, max_prop of request is  // set as specified  // p.pkt is freed or handed off{  hdr_sr *srh =  (hdr_sr*)p.pkt->access(off_sr_);  assert(srh->valid());  srh->route_request() = 1;  srh->rtreq_seq() = route_request_num++;  srh->max_propagation() = max_prop;  p.route.reset();  p.route.appendToPath(net_id);  if (dsragent_propagate_last_error && route_error_held       && Scheduler::instance().clock() - route_error_data_time  < max_err_hold)    {      assert(srh->num_route_errors() < MAX_ROUTE_ERRORS);      srh->route_error() = 1;      link_down *deadlink = &(srh->down_links()[srh->num_route_errors()]);      deadlink->addr_type = NS_AF_INET;      deadlink->from_addr = err_from.getNSAddr_t();      deadlink->to_addr = err_to.getNSAddr_t();      deadlink->tell_addr = GRAT_ROUTE_ERROR;

⌨️ 快捷键说明

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