📄 dsragent.cc
字号:
return TCL_OK; } if (strcasecmp(argv[1], "reset") == 0) { Terminate(); return Agent::command(argc, argv); } if (strcasecmp(argv[1], "check-cache") == 0) { return route_cache->command(argc, argv); } if (strcasecmp(argv[1], "startdsr") == 0) { if (ID(1,::IP) == net_id) { // log the configuration parameters of the dsragent trace("Sconfig %.5f tap: %s snoop: rts? %s errs? %s", Scheduler::instance().clock(), dsragent_use_tap ? "on" : "off", dsragent_snoop_source_routes ? "on" : "off", dsragent_snoop_forwarded_errors ? "on" : "off"); trace("Sconfig %.5f salvage: %s !bd replies? %s", Scheduler::instance().clock(), dsragent_salvage_with_cache ? "on" : "off", dsragent_dont_salvage_bad_replies ? "on" : "off"); trace("Sconfig %.5f grat error: %s grat reply: %s", Scheduler::instance().clock(), dsragent_propagate_last_error ? "on" : "off", dsragent_send_grat_replies ? "on" : "off"); trace("Sconfig %.5f $reply for props: %s ring 0 search: %s", Scheduler::instance().clock(), dsragent_reply_from_cache_on_propagating ? "on" : "off", dsragent_ring_zero_search ? "on" : "off"); } // cheap source of jitter send_buf_timer.sched(BUFFER_CHECK + BUFFER_CHECK * Random::uniform(1.0)); return route_cache->command(argc,argv); } } else if(argc == 3) { if (strcasecmp(argv[1], "addr") == 0) { int temp; temp = Address::instance().str2addr(argv[2]); net_id = ID(temp, ::IP); route_cache->net_id = net_id; return TCL_OK; } else if(strcasecmp(argv[1], "mac-addr") == 0) { MAC_id = ID(atoi(argv[2]), ::MAC); route_cache->MAC_id = MAC_id; return TCL_OK; } if( (obj = TclObject::lookup(argv[2])) == 0) { fprintf(stderr, "DSRAgent: %s lookup of %s failed\n", argv[1], argv[2]); return TCL_ERROR; } if (strcasecmp(argv[1], "log-target") == 0 ) { logtarget = (Trace*) obj; return route_cache->command(argc, argv); } else if (strcasecmp(argv[1], "tracetarget") == 0 ) { logtarget = (Trace*) obj; return route_cache->command(argc, argv); } else if (strcasecmp(argv[1], "install-tap") == 0) { Mac *m = (Mac*) obj; m->installTap(this); return TCL_OK; } else if (strcasecmp(argv[1], "node") == 0) { node_ = (MobileNode *) obj; return TCL_OK; } else if (strcasecmp (argv[1], "port-dmux") == 0) { port_dmux_ = (NsObject *) obj; return TCL_OK; } } else if (argc == 4) { if (strcasecmp(argv[1], "add-ll") == 0) { if( (obj = TclObject::lookup(argv[2])) == 0) { fprintf(stderr, "DSRAgent: %s lookup of %s failed\n", argv[1], argv[2]); return TCL_ERROR; } ll = (NsObject*) obj; if( (obj = TclObject::lookup(argv[3])) == 0) { fprintf(stderr, "DSRAgent: %s lookup of %s failed\n", argv[1], argv[3]); return TCL_ERROR; } ifq = (PriQueue *) obj; return TCL_OK; } } return Agent::command(argc, argv);}intDSRAgent::diff_subnet(ID dest, ID myid) { int dst = dest.addr; int id = myid.addr; char* dstnet = Address::instance().get_subnetaddr(dst); char * subnet = Address::instance().get_subnetaddr(id); if (subnet != NULL) { if (dstnet != NULL) { if (strcmp(dstnet, subnet) != 0) { delete [] dstnet; return 1; } delete [] dstnet; } delete [] subnet; } assert(dstnet == NULL); return 0;}voidDSRAgent::sendOutBCastPkt(Packet *p){ // no jitter required Scheduler::instance().schedule(ll, p, 0.0);}voidDSRAgent::recv(Packet* packet, Handler*) /* handle packets with a MAC destination address of this host, or the MAC broadcast addr */{ 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_); assert(cmh->size() >= 0); SRPacket p(packet, srh); p.dest = ID((Address::instance().get_nodeaddr(iph->daddr())),::IP); p.src = ID((Address::instance().get_nodeaddr(iph->saddr())),::IP); assert(logtarget != 0); if (srh->valid() != 1) { unsigned int dst = cmh->next_hop(); if (dst == IP_BROADCAST) { // extensions for mobileIP --Padma, 04/99. // Brdcast pkt - treat differently if (p.src == net_id) // I have originated this pkt sendOutBCastPkt(packet); else //hand it over to port-dmux port_dmux_->recv(packet, (Handler*)0); } else { // this must be an outgoing packet, it doesn't have a SR header on it srh->init(); // give packet an SR header now cmh->size() += IP_HDR_LEN; // add on IP header size if (verbose) trace("S %.9f _%s_ originating %s -> %s", Scheduler::instance().clock(), net_id.dump(), p.src.dump(), p.dest.dump()); handlePktWithoutSR(p, false); goto done; } } else if (srh->valid() == 1) { if (p.dest == net_id || p.dest == IP_broadcast) { // this packet is intended for us handlePacketReceipt(p); goto done; } // should we check to see if it's an error packet we're handling // and if so call processBrokenRouteError to snoop if (dsragent_snoop_forwarded_errors && srh->route_error()) { processBrokenRouteError(p); } if (srh->route_request()) { // propagate a route_request that's not for us // DISABLE:drop rte-req if from outside subnet // if (diff_subnet(p.src,net_id)) {// // from outside our subnet, drop pkt// Packet::free(p.pkt);// p.pkt = 0;// return;// } handleRouteRequest(p); } else { // we're not the intended final recpt, but we're a hop handleForwarding(p); } } else { // some invalid pkt has reached here fprintf(stderr,"dsragent: Error-received Invalid pkt!\n"); Packet::free(p.pkt); p.pkt =0; // drop silently }done: assert(p.pkt == 0); p.pkt = 0; return;}/*=========================================================================== handlers for each class of packet---------------------------------------------------------------------------*/voidDSRAgent::handlePktWithoutSR(SRPacket& p, bool retry) /* obtain a source route to p's destination and send it off. this should be a retry if the packet is already in the sendbuffer */{ hdr_sr *srh = (hdr_sr*)p.pkt->access(off_sr_); assert(srh->valid()); if (p.dest == net_id) { // it doesn't need a source route, 'cause it's for us handlePacketReceipt(p); return; } // Extensions for wired cum wireless simulation mode //if pkt dst outside my subnet, route to base_stn ID dest; if (diff_subnet(p.dest,net_id)) { dest = ID(node_->base_stn(),::IP); if (dest == net_id) // Iam the base-station dest = p.dest; } else dest = p.dest; if (route_cache->findRoute(dest, p.route, 1)) { // we've got a route... if (verbose) trace("S$hit %.5f _%s_ %s -> %s %s", Scheduler::instance().clock(), net_id.dump(), p.src.dump(), dest.dump(), p.route.dump()); sendOutPacketWithRoute(p, true); return; } // end if we have a route else { // we don't have a route... if (verbose) trace("S$miss %.5f _%s_ %s -> %s", Scheduler::instance().clock(), net_id.dump(), net_id.dump(), p.dest.dump()); getRouteForPacket(p, dest, retry); return; } // end of we don't have a route}voidDSRAgent::handlePacketReceipt(SRPacket& p) /* Handle a packet destined to us */{ hdr_sr *srh = (hdr_sr*)p.pkt->access(off_sr_); //hdr_ip *iph = HDR_IP(p.pkt); if (srh->route_reply()) { // we got a route_reply piggybacked on a route_request // accept the new source route before we do anything else // (we'll send off any packet's we have queued and waiting) acceptRouteReply(p); } if (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 { request_table.insert(p.src, p.src, srh->rtreq_seq()); returnSrcRouteToRequestor(p); } } if (srh->route_error()) { // register the dead route processBrokenRouteError(p); } /* give the data in the packet to our higher layer (our port dmuxer, most likely) */ handPktToDmux(p);}void DSRAgent::handPktToDmux(SRPacket &p){ // hdr_ip *iph = HDR_IP(p.pkt); assert(p.dest == net_id || p.dest == MAC_id);#if 0 if (iph->dport() == 255) { int mask = Address::instance().portmask(); int shift = Address::instance().portshift(); iph->daddr() = ((iph->dport() & mask) << shift) | ((~(mask) << shift) & iph->dst()); }#endif target_->recv(p.pkt, (Handler*)0); p.pkt = 0;}void BS_DSRAgent::handPktToDmux(SRPacket &p){ //since the demux has handed this pkt to the DSRagent, // silently drop this pkt. Packet::free(p.pkt); p.pkt = 0;}voidDSRAgent::handleForwarding(SRPacket &p) /* forward packet on to next host in source route, snooping as appropriate */{ hdr_sr *srh = (hdr_sr*)p.pkt->access(off_sr_); hdr_cmn *cmh = (hdr_cmn*)p.pkt->access(off_cmn_); trace("SF %.9f _%s_ --- %d [%s -> %s] %s", Scheduler::instance().clock(), net_id.dump(), cmh->uid(), p.src.dump(), p.dest.dump(), srh->dump()); // first make sure we are the ``current'' host along the source route. // if we're not, the previous node set up the source route incorrectly. assert(p.route[p.route.index()] == net_id || p.route[p.route.index()] == MAC_id); if (p.route.index() >= p.route.length()) { fprintf(stderr,"dfu: ran off the end of a source route\n"); trace("SDFU: ran off the end of a source route\n"); drop(p.pkt, DROP_RTR_ROUTE_LOOP); p.pkt = 0; // maybe we should send this packet back as an error... return; } // if there's a source route, maybe we should snoop it too if (dsragent_snoop_source_routes) route_cache->noticeRouteUsed(p.route, Scheduler::instance().clock(), net_id); // sendOutPacketWithRoute will add in the size of the src hdr, so // we have to subtract it out here struct hdr_cmn *ch = HDR_CMN(p.pkt); ch->size() -= srh->size(); // now forward the packet... sendOutPacketWithRoute(p, false);}voidDSRAgent::handleRouteRequest(SRPacket &p) /* process a route request that isn't targeted at us */{ hdr_sr *srh = (hdr_sr*)p.pkt->access(off_sr_); assert (srh->route_request()); if (ignoreRouteRequestp(p)) { if (verbose_srr) trace("SRR %.5f _%s_ dropped %s #%d (ignored)", Scheduler::instance().clock(), net_id.dump(), p.src.dump(), srh->rtreq_seq());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -