📄 dsragent.cc
字号:
srh->num_route_errors() += 1; /* * Make sure that the Route Error gets on a propagating request. */ if(max_prop > 0) route_error_held = false; } trace("SRR %.5f _%s_ new-request %d %s #%d -> %s", Scheduler::instance().clock(), net_id.dump(), max_prop, p.src.dump(), srh->rtreq_seq(), p.dest.dump()); sendOutPacketWithRoute(p, false);}// XXX not used currentlyvoidDSRAgent::handleRteRequestForOutsideDomain(SRPacket& p){ /* process a route request for a outside-domain dst*/ hdr_sr *srh = (hdr_sr*)p.pkt->access(off_sr_); assert (srh->route_request()); if (dsragent_reply_only_to_first_rtreq && ignoreRouteRequestp(p)) { //we only respond to the first route request // we receive from a host Packet::free(p.pkt); // drop silently p.pkt = 0; return; } else { // we're going to process this request now, so record the req_num request_table.insert(p.src, p.src, srh->rtreq_seq()); returnSrcRteForOutsideDomainToRequestor(p); } if (srh->route_error()) { // register the dead route processBrokenRouteError(p); }}// XXX not used currentlyvoidDSRAgent::returnSrcRteForOutsideDomainToRequestor(SRPacket &p){ // take the route in p, add us and the destination outside subnet // to the end of it and return the route to the sender of p // doesn't free p.pkt hdr_sr *old_srh = (hdr_sr*)p.pkt->access(off_sr_); if (p.route.full()) return; // alas, the route would be to long once we add ourselves SRPacket p_copy = p; p_copy.pkt = allocpkt(); //p_copy.dest = p.src; //p_copy.src = ID(old_srh->req_dest(),::IP); p_copy.route.appendToPath(net_id); p_copy.route.appendToPath(p_copy.src); hdr_ip *new_iph = (hdr_ip*)p_copy.pkt->access(off_ip_); new_iph->daddr() = Address::instance().create_ipaddr(p_copy.dest.getNSAddr_t(),RT_PORT); new_iph->dport() = RT_PORT; new_iph->saddr() = Address::instance().create_ipaddr(p_copy.src.getNSAddr_t(),RT_PORT); new_iph->sport() = RT_PORT; new_iph->ttl() = 255; hdr_sr *new_srh = (hdr_sr*)p_copy.pkt->access(off_sr_); new_srh->init(); for (int i = 0 ; i < p_copy.route.length() ; i++) p_copy.route[i].fillSRAddr(new_srh->reply_addrs()[i]); new_srh->route_reply_len() = p_copy.route.length(); new_srh->route_reply() = 1; // propagate the request sequence number in the reply for analysis purposes new_srh->rtreq_seq() = old_srh->rtreq_seq(); hdr_cmn *new_cmnh = (hdr_cmn*)p_copy.pkt->access(off_cmn_); new_cmnh->ptype() = PT_DSR; new_cmnh->size() = IP_HDR_LEN; trace("SRR %.9f _%s_ reply-sent %s -> %s #%d (len %d) %s", Scheduler::instance().clock(), net_id.dump(), p_copy.src.dump(), p_copy.dest.dump(), old_srh->rtreq_seq(), p_copy.route.length(), p_copy.route.dump()); // flip the route around for the return to the requestor, and // cache the route for future use p_copy.route.reverseInPlace(); route_cache->addRoute(p_copy.route, Scheduler::instance().clock(), net_id); p_copy.route.resetIterator(); p_copy.route.fillSR(new_srh); new_cmnh->size() += new_srh->size(); /* we now want to jitter when we first originate route replies, since they are a transmission we make in response to a broadcast packet -dam 4/23/98 sendOutPacketWithRoute(p_copy, true); */ Scheduler::instance().schedule(this, p_copy.pkt, Random::uniform(RREQ_JITTER));}voidDSRAgent::returnSrcRouteToRequestor(SRPacket &p) // take the route in p, add us to the end of it and return the // route to the sender of p // doesn't free p.pkt{ hdr_sr *old_srh = (hdr_sr*)p.pkt->access(off_sr_); if (p.route.full()) return; // alas, the route would be to long once we add ourselves SRPacket p_copy = p; p_copy.pkt = allocpkt(); p_copy.dest = p.src; p_copy.src = net_id; p_copy.route.appendToPath(net_id); hdr_ip *new_iph = (hdr_ip*)p_copy.pkt->access(off_ip_); new_iph->daddr() = Address::instance().create_ipaddr(p_copy.dest.getNSAddr_t(),RT_PORT); new_iph->dport() = RT_PORT; new_iph->saddr() = Address::instance().create_ipaddr(p_copy.src.getNSAddr_t(),RT_PORT); new_iph->sport() = RT_PORT; new_iph->ttl() = 255; hdr_sr *new_srh = (hdr_sr*)p_copy.pkt->access(off_sr_); new_srh->init(); for (int i = 0 ; i < p_copy.route.length() ; i++) p_copy.route[i].fillSRAddr(new_srh->reply_addrs()[i]); new_srh->route_reply_len() = p_copy.route.length(); new_srh->route_reply() = 1; // propagate the request sequence number in the reply for analysis purposes new_srh->rtreq_seq() = old_srh->rtreq_seq(); hdr_cmn *new_cmnh = (hdr_cmn*)p_copy.pkt->access(off_cmn_); new_cmnh->ptype() = PT_DSR; new_cmnh->size() = IP_HDR_LEN; trace("SRR %.9f _%s_ reply-sent %s -> %s #%d (len %d) %s", Scheduler::instance().clock(), net_id.dump(), p_copy.src.dump(), p_copy.dest.dump(), old_srh->rtreq_seq(), p_copy.route.length(), p_copy.route.dump()); // flip the route around for the return to the requestor, and // cache the route for future use p_copy.route.reverseInPlace(); route_cache->addRoute(p_copy.route, Scheduler::instance().clock(), net_id); p_copy.route.resetIterator(); p_copy.route.fillSR(new_srh); new_cmnh->size() += new_srh->size(); /* we now want to jitter when we first originate route replies, since they are a transmission we make in response to a broadcast packet -dam 4/23/98 sendOutPacketWithRoute(p_copy, true); */ Scheduler::instance().schedule(this, p_copy.pkt, Random::uniform(RREQ_JITTER));}voidDSRAgent::acceptRouteReply(SRPacket &p) /* - enter the packet's source route into our cache - see if any packets are waiting to be sent out with this source route - doesn't free the pkt */{ hdr_sr *srh = (hdr_sr*)p.pkt->access(off_sr_); Path reply_route(srh->reply_addrs(), srh->route_reply_len()); if (!srh->route_reply()) { // somethings wrong... trace("SDFU non route containing packet given to acceptRouteReply"); fprintf(stderr, "dfu: non route containing packet given to acceptRouteReply\n"); } /* check to see if this reply is valid or not using god info */ bool good_reply = true;#ifdef USE_GOD_FEEDBACK int i; for (i = 0; i < reply_route.length()-1 ; i++) if (God::instance()->hops(reply_route[i].getNSAddr_t(), reply_route[i+1].getNSAddr_t()) != 1) { good_reply = false; break; }#endif trace("SRR %.9f _%s_ reply-received %d from %s %s #%d -> %s %s", Scheduler::instance().clock(), net_id.dump(), good_reply ? 1 : 0, p.src.dump(), reply_route[0].dump(), srh->rtreq_seq(), reply_route[reply_route.length()-1].dump(), reply_route.dump()); // add the new route into our cache route_cache->addRoute(reply_route, Scheduler::instance().clock(), p.src); // back down the route request counters Entry *e = request_table.getEntry(reply_route[reply_route.length()-1]); e->rt_reqs_outstanding = 0; e->last_rt_req = 0.0; // see if the addtion of this route allows us to send out // any of the packets we have waiting Time delay = 0.0; ID dest; for (int c = 0; c < SEND_BUF_SIZE; c++) { if (send_buf[c].p.pkt == NULL) continue; // check if pkt is destined to outside domain if (diff_subnet(send_buf[c].p.dest,net_id)) { dest = ID(node_->base_stn(),::IP); if (dest == net_id) // Iam the base-station dest = send_buf[c].p.dest; } else dest = send_buf[c].p.dest; if (route_cache->findRoute(dest, send_buf[c].p.route, 1)) { // we have a route!#ifdef DEBUG struct hdr_cmn *ch = HDR_CMN(send_buf[c].p.pkt); if(ch->size() < 0) { drop(send_buf[c].p.pkt, "XXX"); abort(); }#endif if (verbose) trace("Sdebug %.9f _%s_ liberated from sendbuf %s->%s %s", Scheduler::instance().clock(), net_id.dump(), send_buf[c].p.src.dump(), send_buf[c].p.dest.dump(), send_buf[c].p.route.dump()); /* we need to spread out the rate at which we send packets in to the link layer to give ARP time to complete. If we dump all the packets in at once, all but the last one will be dropped. XXX THIS IS A MASSIVE HACK -dam 4/14/98 */ sendOutPacketWithRoute(send_buf[c].p, true, delay); delay += arp_timeout; send_buf[c].p.pkt = NULL; } }}voidDSRAgent::processBrokenRouteError(SRPacket& p)// take the error packet and proccess our part of it.// if needed, send the remainder of the errors to the next person// doesn't free p.pkt{ hdr_sr *srh = (hdr_sr*)p.pkt->access(off_sr_); if (!srh->route_error()) return; // what happened?? /* if we hear A->B is dead, should we also run the link B->A through the cache as being dead, since 802.11 requires bidirectional links XXX -dam 4/23/98 */ // since CPU time is cheaper than network time, we'll process // all the dead links in the error packet assert(srh->num_route_errors() > 0); for (int c = 0 ; c < srh->num_route_errors() ; c++) { assert(srh->down_links()[c].addr_type == NS_AF_INET); route_cache->noticeDeadLink(ID(srh->down_links()[c].from_addr,::IP), ID(srh->down_links()[c].to_addr,::IP), Scheduler::instance().clock()); // I'll assume everything's of type NS_AF_INET for the printout... XXX if (verbose_srr) trace("SRR %.9f _%s_ dead-link tell %d %d -> %d", Scheduler::instance().clock(), net_id.dump(), srh->down_links()[c].tell_addr, srh->down_links()[c].from_addr, srh->down_links()[c].to_addr); } ID who = ID(srh->down_links()[srh->num_route_errors()-1].tell_addr, ::IP); if (who != net_id && who != MAC_id) { // this error packet wasn't meant for us to deal with // since the outer entry doesn't list our name return; } // record this route error data for possible propagation on our next // route request route_error_held = true; err_from = ID(srh->down_links()[srh->num_route_errors()-1].from_addr,::IP); err_to = ID(srh->down_links()[srh->num_route_errors()-1].to_addr,::IP); route_error_data_time = Scheduler::instance().clock(); if (1 == srh->num_route_errors()) { // this error packet has done its job // it's either for us, in which case we've done what it sez // or it's not for us, in which case we still don't have to forward // it to whoever it is for return; } /* make a copy of the packet and send it to the next tell_addr on the error list. the copy is needed in case there is other data in the packet (such as nested route errors) that need to be delivered */ if (verbose) trace("Sdebug %.5f _%s_ unwrapping nested route error", Scheduler::instance().clock(), net_id.dump()); SRPacket p_copy = p; p_copy.pkt = p.pkt->copy(); hdr_sr *new_srh = (hdr_sr*)p_copy.pkt->access(off_sr_); hdr_ip *new_iph = (hdr_ip*)p_copy.pkt->access(off_ip_); // remove us from the list of errors new_srh->num_route_errors() -= 1; // send the packet to the person listed in what's now the last entry p_copy.dest = ID(new_srh->down_links()[new_srh->num_route_errors()-1].tell_addr, ::IP); p_copy.src = net_id; //new_iph->dst() = (p_copy.dest.addr) << Address::instance().nodeshift(); new_iph->daddr() = Address::instance().create_ipaddr(p_copy.dest.getNSAddr_t(),RT_PORT); new_iph->dport() = RT_PORT; //new_iph->src() = (p_copy.src.addr) << Address::instance().nodeshift(); new_iph->saddr() = Address::instance().create_ipaddr(p_copy.src.getNSAddr_t(),RT_PORT); new_iph->sport() = RT_PORT; new_iph->ttl() = 255; // an error packet is a first class citizen, so we'll // use handlePktWOSR to obtain a route if needed handlePktWithoutSR(p_copy, false);}void DSRAgent::tap(const Packet *packet) /* process packets that are promiscously listened to from the MAC layer tap *** do not change or free packet *** */{ hdr_sr *srh = (hdr_sr*)packet->access(off_sr_); hdr_ip *iph = (hdr_ip*)packet->access(off_ip_); hdr_cmn *cmh = (hdr_cmn*)packet->access(off_cmn_); if (!dsragent_use_tap) return; if (srh->valid() != 1) return; // can't do anything with it // don't trouble me with packets I'm about to receive anyway /* this change added 5/13/98 -dam */ ID next_hop(srh->addrs[srh->cur_addr()]); if (next_hop == net_id || next_hop == MAC_id) return; SRPacket p((Packet *) packet, srh); p.dest = ID((Address::instance().get_nodeaddr(iph->daddr())),::IP); p.src = ID((Address::instance().get_nodeaddr(iph->saddr())),::IP); // don't trouble me with my own packets if (p.src == net_id) return; /* snoop on the SR data */ if (srh->route_error()) { if (verbose) trace("Sdebug _%s_ tap saw error %d", net_id.dump(), cmh->uid()); processBrokenRouteError(p); } if (srh->route_reply()) { Path reply_path(srh->reply_addrs(), srh->route_reply_len()); if(verbose) trace("Sdebug _%s_ tap saw route reply %d %s", net_id.dump(), cmh->uid(), reply_path.dump()); route_cache->noticeRouteUsed(reply_path, Scheduler::instance().clock(), p.src); } /* we can't decide whether we should snoop on the src routes in route requests. We've seen cases where we hear a route req from a node, but can't complete an arp with that node (and so can't actually deliver packets through it if called on to do so) -dam 4/16/98 */ if (srh->route_request()) return; // don't path shorten route requests // the logic is wrong for shortening rtreq's anyway, cur_addr always = 0 if (dsragent_snoop_source_routes) { if (verbose) trace("Sdebug _%s_ tap saw route use %d %s", net_id.dump(), cmh->uid(), p.route.dump()); route_cache->noticeRouteUsed(p.route, Scheduler::instance().clock(), net_id); } if (PT_DSR == cmh->ptype()) return; // no route shortening on any // DSR packet
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -