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

📄 tora_api.cc

📁 一个EPI路由协议的实现
💻 CC
字号:
/* * Modified by Felix Hernandez-Campos (fhernand@cs.unc.edu) * during the porting and extension of Duke's Epidemic Routing   * implementation (by Amin Vahdat and David Becker) * * Fall 2000 *//* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- *//* * Copyright (c) 1997 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *      This product includes software developed by the Computer Systems *      Engineering Group at Lawrence Berkeley Laboratory. * 4. Neither the name of the University nor of the Laboratory may be used *    to endorse or promote products derived from this software without *    specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. *//* Ported from CMU/Monarch's code*//*    tora_api.cc   $Id: tora_api.cc,v 1.3 1999/09/09 04:02:52 salehi Exp $      Implement the API used by IMEP   */#include <tora/tora.h>// --- EPIC ----------------------------------------------------------- [Felix]//#define DEBUG//#define SHOWLINKS// --- end of EPIC ---------------------------------------------------- [Felix]#define	CURRENT_TIME	Scheduler::instance().clock()// notifies the routing agent in this node that // there is now a direct link with node index [Felix]voidtoraAgent::rtNotifyLinkUP(nsaddr_t index){ 	// --- EPIC --------------------------------------------------- [Felix]	// This method is completely redefined under Epidemic Routing	TORADest *td = new TORADest(index, this);	assert(td);#ifdef SHOWLINKS	trace("T %.9f _%d_ linkup %d<->%d ",	      Scheduler::instance().clock(), ipaddr(), ipaddr(), index);#endif	LIST_INSERT_HEAD(&nblist, td, link);	++nbcnt;	if (prevnb==index) return;	prevnb=index;#ifdef HASH#ifdef SHOWLINKS	trace("rtNotifyLinkUP() node %d sending QRY (%g) %d HASH", 	      ipaddr(), Scheduler::instance().clock(), index);#endif	sendQRY(index,0);#else	EPIpkt *ep;        for(ep = copylist.lh_first ; ep; ep = ep->link.le_next) {		// if the new neighbor is packet destination, deliver		// it and move on to the next packet		// in list.		Packet *p = ep->packet;		struct hdr_ip *ih = HDR_IP(p);		struct hdr_epi *eh = HDR_EPI(p);#ifdef FWDDIRECT		// using daddr() instead of dst() [Felix]		if (ih->daddr()==index) {			if (!eh->master->delivered)				forward(ep->packet->copy(),index);			// eh->master->delivered++;			// using saddr() and daddr() instead of 			// src() and dst() [Felix]			trace("T %.9f _%d_ epinbdeliver %d->%d fwd to %d",			      Scheduler::instance().clock(), ipaddr(), 			      ih->saddr(), ih->daddr(),td->index);			eh->path_nodes[eh->path_len++]= index;			traceroute(eh);			}		else if (eh->copies_allowed)#else		// using daddr() instead of dst() [Felix]		if (eh->copies_allowed || (ih->daddr()==index))#endif			 {		// this ep is not to a neighbor.		// infect neighbor if under the copy limit#ifdef BLIND			// Look for neighbors who have it already			int i;			for(i=0; i<eh->hits; ++i)				if (index==eh->node_hit[i]) break;			if (index!=eh->node_hit[i]) {				eh->node_hit[eh->hits++] = index;				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(ep->packet->copy(),index);				eh->copies_allowed = copies_available-1-copies_to_neighbor;#ifdef DEBUG				// using saddr() and daddr() instead of 				// src() and dst() [Felix]				trace("T %.9f _%d_ epinbfwd %d->%d fwd %d copies to %d",				      Scheduler::instance().clock(), ipaddr(), 				      ih->saddr(), ih->daddr(),copies_to_neighbor,td->index);#endif				}#else		// ask neighbor if they want a copy#ifdef SHOWLINKS			trace("rtNotifyLinkUP() node %d sending QRY (%g) %d", 			      ipaddr(), Scheduler::instance().clock(), index);#endif			sendQRY(index,p);#endif			}		}#endif 	// --- end of EPIC -------------------------------------------- [Felix]}voidtoraAgent::rtNotifyLinkDN(nsaddr_t index){	TORADest *td = dstlist.lh_first; 	// --- EPIC --------------------------------------------------- [Felix]#ifdef SHOWLINKS	trace("T %.9f _%d_ linkdown %d<->%d ",	      Scheduler::instance().clock(), ipaddr(), ipaddr(), index);#endif 	// --- end of EPIC -------------------------------------------- [Felix]        /*         *  Purge each Destination's Neighbor List         */        for( ; td; td = td->link.le_next) {		// --- EPIC ------------------------------------------- [Felix]		if(td->index == index) {			LIST_REMOVE(td, link);			--nbcnt;			delete td;			break;		}		// --- end of EPIC ------------------------------------ [Felix]        }	/*	 *  Now purge the Network Interface queues that	 *  may have packets destined for this broken	 *  neighbor.	 */        {                Packet *head = 0;                Packet *p;                Packet *np = 0;		// Changed in NS: filter() instead of prq_get_nexthop() [Felix]                while((p = ifqueue->filter(index))) {                        p->next_ = head;                        head = p;                }                for(p = head; p; p = np) {                        np = p->next_;                        /*                         * This make a lot of sense for TORA since we                         * will almost always have multiple routes to                         * a destination.                         */                        log_link_layer_recycle(p);                        rt_resolve(p);			// --- EPIC ----------------------------------- [Felix]			struct hdr_ip *ih = HDR_IP(p);			struct hdr_cmn *ch = HDR_CMN(p);			// using .addr_ [Felix]			trace("T %.9f _%d_ epireclaim %d->%d was hop to %d",			      Scheduler::instance().clock(), ipaddr(),			      ih->src_.addr_, ih->dst_.addr_, ch->next_hop_);			// epiXXX used to call rt_resolve here			// need something here to reclaim copies and			// reset node_hit as in rtRoutePacket			// problem may be inside the forwarding loop			// and cannot alter the outgoing copies_allowed			// since that would screw up the copy count math in			// rt_resolve			// --- end of EPIC ---------------------------- [Felix]                }        }}voidtoraAgent::rtNotifyLinkStatus(nsaddr_t /* index */, u_int32_t /* status */){	// [Felix]	fprintf(stderr, "abort() in toraAgent::rtNotifyLinkStatus\n");	abort();}voidtoraAgent::rtRoutePacket(Packet *p){	struct hdr_cmn *ch = HDR_CMN(p);	// --- EPIC --------------------------------------------------- [Felix]	struct hdr_ip *ih = HDR_IP(p);	struct hdr_epi *eh = HDR_EPI(p);	// using daddr() instead of dst() [Felix]	if (ch->next_hop_==ih->daddr()) {//		eh->master->delivered--;		}	else	{		eh->copies_allowed++;		eh->path_len--;#ifdef BLIND		if (eh->node_hit[eh->hits-1] == ch->next_hop_)			eh->hits--;#endif		}#ifdef DEBUG	trace("T %.9f _%d_ epibounced 0x%x by %d copies now %d",	      Scheduler::instance().clock(), ipaddr(), eh->id, ch->next_hop_, 	      eh->copies_allowed);#endif	// free packet ??? [Felix]	// --- end of EPIC -------------------------------------------- [Felix]}

⌨️ 快捷键说明

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