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

📄 tora.cc

📁 一个EPI路由协议的实现
💻 CC
📖 第 1 页 / 共 3 页
字号:
		ep =  new EPIpkt(p);		LIST_INSERT_HEAD(copytable+h, ep, link);		SUMMSETBIT(ihave,h);#endif		// this node keeps a copy and gives it to all neighbors		fwdqadd(p);#ifdef TTL		eh->ttl = opt_hops_;		if (eh->ttl) {			--eh->ttl;			// Changed -1 to IP_BROADCAST [Felix]			forward(p->copy(), IP_BROADCAST);		}#else		fwdtoallnb(p);#endif		if (debug_fname) trace("CALL %d end of recv() - %g", ipaddr(), Scheduler::instance().clock());				return;		// --- end of EPIC ------------------------------------ [Felix]	}#ifdef TORA_DISALLOW_ROUTE_LOOP        /*         *  I received a packet that I sent.  Probably         *  a routing loop.         */	// Changed in NS: ih->src_ [Felix]        else if(ih->saddr() == ipaddr()) {		if (debug_recv) trace("recv() %.9f loop", 		       Scheduler::instance().clock());		if (debug_drop) trace("drop recv() - 1");                drop(p, DROP_RTR_ROUTE_LOOP);                return;        }#endif	/*	 *  Packet I'm forwarding...	 */	else {		if (debug_recv) trace("recv() %.9f forwarding", 		       Scheduler::instance().clock());		/*		 *  Check the TTL.  If it is zero, then discard.		 */		if(--ih->ttl_ == 0) {			if (debug_drop) trace("drop recv() - 2");			drop(p, DROP_RTR_TTL);			return;		}	}	// --- EPIC --------------------------------------------------- [Felix]	EPIpkt* ep = new EPIpkt(p);	LIST_INSERT_HEAD(&eh->master->copylist, ep, link);	eh->path_nodes[eh->path_len++]= ipaddr();#ifdef SHOWALL	trace("T %.9f _%d_ epirecv 0x%x from %d ",		      Scheduler::instance().clock(), ipaddr(), 		      eh->id,ch->prev_hop_);#endif	// --- end of EPIC -------------------------------------------- [Felix]	rt_resolve(p);	if (debug_fname) trace("CALL %d end of recv() - %g", ipaddr(), Scheduler::instance().clock());}voidtoraAgent::recvTORA(Packet *p){	if (debug_fname) trace("CALL %d recvTORA() - %g", ipaddr(), Scheduler::instance().clock());	struct hdr_ip *ih = HDR_IP(p);	struct hdr_tora *th = HDR_TORA(p);	TORADest *td;	TORANeighbor *tn;	/*	 * Fix the source IP address.	 */	// Changed in NS: ih->sport_, ih->dport_ [Felix]	assert(ih->sport() == RT_PORT);	assert(ih->dport() == RT_PORT);	// --- EPIC --------------------------------------------------- [Felix]	// EPI: in TORA all pkts are broadcast so 	// we have to drop foreign epi pkts here	// using daddr() instead of dst() [Felix]	if (ih->daddr()!=ipaddr() && (uint)ih->daddr()!=IP_BROADCAST) {		if (debug_recv) trace("recvTORA() - node %d drop tora at %g", 				       ipaddr(), Scheduler::instance().clock());		return;	}	// --- end of EPIC -------------------------------------------- [Felix]	/*	 * Incoming Packets.	 */	switch(th->th_type) {		case TORATYPE_QRY:			if (debug_recv) 				trace("recvTORA() node %d TORATYPE_QRY (%g)", 				      ipaddr(), Scheduler::instance().clock());			recvQRY(p);			Packet::free(p);			return;		// don't add/change routing state		case TORATYPE_UPD:			if (debug_recv) 				trace("recvTORA() node %d TORATYPE_UPD (%g)", 				      ipaddr(), Scheduler::instance().clock());			log_recv_upd(p);			recvUPD(p);			break;		case TORATYPE_CLR:			if (debug_recv) 				trace("recvTORA() node %d TORATYPE_CLR (%g)", 				      ipaddr(), Scheduler::instance().clock());			log_recv_clr(p);			recvCLR(p);			break;		default:			fprintf(stderr,				"%s: Invalid TORA type (%x)\n",				__PRETTY_FUNCTION__, th->th_type);			exit(1);	}	if((td = dst_find(th->th_dst)) == 0) {		Packet::free(p);		return;	}	logNextHopChange(td);	if((tn = td->nb_find_next_hop())) {		Packet *p0;		Time delay = 0.0;		while((p0 = rqueue.deque(td->index))) {                        forward(p0, tn->index, delay);			delay += ARP_SEPARATION_DELAY;		}	}	Packet::free(p);	if (debug_fname) trace("CALL %d end of rcvTORA() - %g", ipaddr(), Scheduler::instance().clock());}/* *  IETF Draft - TORA Specification, section 3.7.6 */// QRY messages in EPIC are in charge of sending the summary vector // to node potentially interesting in our packets [Felix]voidtoraAgent::recvQRY(Packet *p){	if (debug_fname) trace("CALL %d recvQRY() - %g", ipaddr(), Scheduler::instance().clock());	struct hdr_ip *ih = HDR_IP(p);	struct hdr_tora_qry *qh = HDR_TORA_QRY(p);	// --- EPIC --------------------------------------------------- [Felix]	// This method is completely redefined under Epidemic Routing	if (qh->tq_dst!=addr() && qh->tq_dst!=IP_BROADCAST) return;	trace("T %.9f _%d_ recvavail from %d",		      Scheduler::instance().clock(), ipaddr(), qh->tq_dst);#ifdef HASH	unsigned int	iwant[SUMMSIZE];	// use bzero please [Felix]	for(u_int i=0; i<SUMMSIZE; ++i)		iwant[0]=0;	for(u_int i=0; i<SUMMSIZE; ++i)		iwant[i] = (~(ihave[i]|prevask[i])) & qh->avail[i];	for(u_int i=0; i<SUMMSIZE; ++i)		if (iwant[i]) {			memcpy(prevask,iwant,sizeof(iwant));			// using saddr() instead of src_			sendUPD(ih->saddr(), iwant);#ifdef SHOWALL			// using saddr() instead of src_			trace("T %.9f _%d_ IWant bits %x from %d",			      Scheduler::instance().clock(), ipaddr(), 			      iwant[0],ih->saddr());#endif			break;			}#else	EPIpkt* ep;        for(ep = copylist.lh_first ; ep; ep = ep->link.le_next) {		Packet *k = ep->packet;		struct hdr_epi *kh = HDR_EPI(k);		if (kh->id==qh->epi_id) break;		}	if (!ep) {		// using saddr() instead of src_		sendUPD(ih->saddr(), qh->epi_id);#ifdef DEBUG		// using saddr() instead of src_		trace("T %.9f _%d_ IWant 0x%x from %d",				      Scheduler::instance().clock(), ipaddr(), 			      qh->epi_id,ih->saddr());#endif		}#endif	// --- end of EPIC -------------------------------------------- [Felix]	if (debug_fname) trace("CALL %d end of recvQRY() - %g", ipaddr(), Scheduler::instance().clock());}// --- EPIC ----------------------------------------------------------- [Felix]// Send packet to an available neighbor (after a QRY-UPD exchanged) [Felix]voidtoraAgent::fwdtonb(Packet *p, nsaddr_t nexthop, Time delay = 0.0){	if (debug_fname) trace("CALL %d fwdtonb() - %g", ipaddr(), Scheduler::instance().clock());	struct hdr_epi *eh = HDR_EPI(p);	struct hdr_ip *ih = HDR_IP(p);#ifdef TTL	// using daddr() instead of dst() [Felix]	if (eh->ttl==0 && nexthop!=ih->daddr()) {		// Seg fault if you use this one, why? [Felix]#ifdef DEBUG_MEM				// printf("1\n");#endif		// Packet::free(p);		return;	}	forward(p->copy(),nexthop,delay);	// XXX bcast:#ifdef SHOWALL	trace("T %.9f _%d_ episend 0x%x ttl %d to %d",	      Scheduler::instance().clock(), ipaddr(), 	      eh->id, eh->ttl,nexthop);#endif#else	if (prevsend==eh->id && prevdest==nexthop) { 		// [Felix]#ifdef DEBUG_MEM				printf("2\n");#endif		Packet::free(p);		return;	}	// using daddr() instead of dst() [Felix]	if (eh->copies_allowed==0 && nexthop!=ih->daddr()) { 		// [Felix]#ifdef DEBUG_MEM				printf("3\n");#endif		Packet::free(p);		return;	}	int copies_to_neighbor = eh->copies_allowed/2;	if (copies_to_neighbor) --copies_to_neighbor;	int copies_available = eh->copies_allowed;	eh->copies_allowed=copies_to_neighbor;	forward(p->copy(),nexthop,delay);	prevsend=eh->id;	prevdest=nexthop;	if (eh->copies_allowed)		eh->copies_allowed = copies_available-1-copies_to_neighbor;#ifdef SHOWALL	trace("T %.9f _%d_ episend 0x%x plus %d copies to %d",	      Scheduler::instance().clock(), ipaddr(), 	      eh->id, copies_to_neighbor,nexthop);#endif#endif	if (debug_fname) trace("CALL %d end of fwdtonb() - %g", ipaddr(), Scheduler::instance().clock());}// --- end of EPIC ---------------------------------------------------- [Felix]/* *  IETF Draft - TORA Specification, section 3.7.7 */// UPD messages in EPIC are in charged of informing a querying node about// than interests the sending node (always sent after a QRY) [Felix]voidtoraAgent::recvUPD(Packet *p){	if (debug_fname) trace("CALL %d recvUPD() - %g", ipaddr(), Scheduler::instance().clock());	struct hdr_tora_upd *uh = HDR_TORA_UPD(p);	// --- EPIC --------------------------------------------------- [Felix]	// This method is completely redefined under Epidemic Routing	// using saddr() instead of src_	nsaddr_t nexthop = HDR_IP(p)->saddr();	Time delay = 0.0;	// Using ipaddr() instead of addr_	if (uh->tu_dst!=ipaddr()) {		// [Felix]#ifdef DEBUG_MEM				printf("4\n");#endif		Packet::free(p);		return;	}	trace("T %.9f _%d_ recvwant from %d",		      Scheduler::instance().clock(), ipaddr(), uh->tu_dst);#ifdef HASH	if (nexthop==prevupd) {		// [Felix]#ifdef DEBUG_MEM				printf("5\n");#endif		Packet::free(p);		return;	}	prevupd=nexthop;	int bit=0;	for(u_int i=0; i<SUMMSIZE; ++i)	    for(u_int j=0; j<SUMMELEMBITS; ++j) {		    if ((uh->iwant[i])&(1<<j)) {			    // XXX send entire bucket			    EPIpkt* ep = copytable[bit].lh_first;			    if (ep) {				    struct hdr_epi *eh = HDR_EPI(ep->packet);				    fwdtonb(ep->packet,nexthop,delay);				    delay += .002;			    }		    }		    ++bit;	    }#else	EPIpkt* ep;        for(ep = copylist.lh_first ; ep; ep = ep->link.le_next) {		struct hdr_epi *eh = HDR_EPI(ep->packet);		if (eh->id==uh->epi_id) {			if (prevsend==eh->id && prevdest==nexthop) break;			fwdtonb(ep->packet,nexthop);			prevsend=eh->id;			prevdest=nexthop;		}	}#endif	// --- end of EPIC -------------------------------------------- [Felix]	if (debug_fname) trace("CALL %d end of recvUPD() - %g", ipaddr(), Scheduler::instance().clock());}/* *  IETF Draft - TORA Specification, section 3.7.8 */voidtoraAgent::recvCLR(Packet *p){	if (debug_fname) trace("CALL %d recvCLR() - %g", ipaddr(), Scheduler::instance().clock());	// --- EPIC --------------------------------------------------- [Felix]	// This method is not used under Epidemic Routing	// --- end of EPIC -------------------------------------------- [Felix]	if (debug_fname) trace("CALL %d end of recvCLR() - %g", ipaddr(), Scheduler::instance().clock());	}voidtoraAgent::trace(char* fmt, ...){	va_list ap;  	if (!logtarget) return;	va_start(ap, fmt);	vsprintf(logtarget->buffer(), fmt, ap);	logtarget->dump();	va_end(ap);}

⌨️ 快捷键说明

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