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

📄 aodv.h

📁 一个无线自组网aodv路由的扩展版---AOMDV(多径路由协议)。
💻 H
字号:
/* The AODV code developed by the CMU/MONARCH group was optimized * and tuned by Samir Das and Mahesh Marina, University of Cincinnati. The  * work was partially done in Sun Microsystems. *  * The original CMU copyright is below.  *//*Copyright (c) 1997, 1998 Carnegie Mellon University.  All RightsReserved. Permission to use, copy, modify, and distribute thissoftware and its documentation is hereby granted (including forcommercial or for-profit use), provided that both the copyright noticeand this permission notice appear in all copies of the software,derivative works, or modified versions, and any portions thereof, andthat both notices appear in supporting documentation, and that creditis given to Carnegie Mellon University in all publications reportingon direct or indirect use of this code or its derivatives.ALL CODE, SOFTWARE, PROTOCOLS, AND ARCHITECTURES DEVELOPED BY THE CMUMONARCH PROJECT ARE EXPERIMENTAL AND ARE KNOWN TO HAVE BUGS, SOME OFWHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON PROVIDES THISSOFTWARE OR OTHER INTELLECTUAL PROPERTY IN ITS ``AS IS'' CONDITION,AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULARPURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITYBE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, ORCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OFSUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; ORBUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCEOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE ORINTELLECTUAL PROPERTY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCHDAMAGE.Carnegie Mellon encourages (but does not require) users of thissoftware or intellectual property to return any improvements orextensions that they make, and to grant Carnegie Mellon the rights toredistribute these changes without encumbrance.*/#ifndef __aodv_h__#define __aodv_h__#include <cmu/cmu-trace.h>#include <cmu/priqueue.h>#include <cmu/aodv/aodv_rtable.h>#include <cmu/aodv/aodv_rqueue.h>#ifdef AOMDV#define AOMDV_PACKET_SALVAGING#define AOMDV_MAX_SALVAGE_COUNT	10#endif // AOMDV/*  Allows AODV to use link-layer (802.11) feedback in determining when  links are up/down.*/#define AODV_LINK_LAYER_DETECTION#define AODV_HELLO/*  Allows local repair of routes *///#define AODV_LOCAL_REPAIR/*  Causes AODV to apply a "smoothing" function to the link layer feedback  that is generated by 802.11.  In essence, it requires that RT_MAX_ERROR  errors occurs within a window of RT_MAX_ERROR_TIME before the link  is considered bad.*///#define AODV_USE_LL_METRIC/*  Only applies if AODV_USE_LL_METRIC is defined.  Causes AODV to apply omniscient knowledge to the feedback received  from 802.11.  This may be flawed, because it does not account for  congestion.*///#define AODV_USE_GOD_FEEDBACKclass AODV;#define AODV_HDR_LEN   		1024      // amount of space allocated in the pkt hdr#define BCAST_ID_SAVE           10				// 10 seconds/* * Route discovery parameters */#define RREQ_RETRIES            2		// 2  // Should be set by the user using best guess (conservative) #define NETWORK_DIAMETER        35             // 35 hops/* Various constants used for the expanding ring search */#ifdef AODV_EXPANDING_RING_SEARCH#define TTL_START     		5		// 5#define TTL_INCREMENT 		2 		// 2#else // NO EXPANDING RING SEARCH#define TTL_START     		NETWORK_DIAMETER		// 5#define TTL_INCREMENT 		NETWORK_DIAMETER 		// 2#endif // NO EXPANDING RING SEARCH#define TTL_THRESHOLD 		7// This should be somewhat related to arp timeout#define NODE_TRAVERSAL_TIME     0.04           // 40 ms//#define DYNAMIC_RREQ_RETRY_TIMEOUT// timeout after doing network-wide search RREQ_RETRIES times//#define MAX_RREQ_TIMEOUT	10.0 		//sec#define LOCAL_REPAIR_WAIT_TIME  0.15 //sec// Must be larger than the time difference between a node propagates a route // request and gets the route reply back.//#define RREP_WAIT_TIME     (3 * NODE_TRAVERSAL_TIME * NETWORK_DIAMETER) // ms//#define RREP_WAIT_TIME     (2 * REV_ROUTE_LIFE)  // seconds//#define RREP_WAIT_TIME         1.0  // sec/* * Route expiration timeout values */#define ACTIVE_ROUTE_TIMEOUT   	3  // 3 sec#define MY_ROUTE_TIMEOUT	(2 * ACTIVE_ROUTE_TIMEOUT)  // sec#define REV_ROUTE_LIFE       	6  // 6 sec#define ID_NOT_FOUND    0x00#define ID_FOUND        0x01#define INFINITY        0xff// The followings are used for the forward() function. Controls pacing.#define DELAY 1.0           // random delay#define NO_DELAY -1.0       // no delay // think it should be 30 ms#define ARP_DELAY 0.0      // fixed delay to keep arp happy#define HELLO_INTERVAL          1             // 1000 ms#define ALLOWED_HELLO_LOSS      2               // packets#define MaxHelloInterval        (1.25 * HELLO_INTERVAL)#define MinHelloInterval        (0.75 * HELLO_INTERVAL)#define BAD_LINK_LIFETIME       3               // 3000 ms/*  Timers (Broadcast ID, Hello, Neighbor Cache, Route Cache)*/class BroadcastTimer : public Handler {public:        BroadcastTimer(AODV* a) : agent(a) {}        void	handle(Event*);private:        AODV    *agent;	Event	intr;};class HelloTimer : public Handler {public:        HelloTimer(AODV* a) : agent(a) {}        void	handle(Event*);private:        AODV    *agent;	Event	intr;};class NeighborTimer : public Handler {public:        NeighborTimer(AODV* a) : agent(a) {}        void	handle(Event*);private:        AODV    *agent;	Event	intr;};class RouteCacheTimer : public Handler {public:        RouteCacheTimer(AODV* a) : agent(a) {}        void	handle(Event*);private:        AODV    *agent;	Event	intr;};class LocalRepairTimer : public Handler {public:        LocalRepairTimer(AODV* a) : agent(a) {}        void	handle(Event*);private:        AODV    *agent;	Event	intr;};#ifdef AOMDV/*  Route List*/class AODV_Route {        friend class BroadcastID; public:        AODV_Route(nsaddr_t nexthop, nsaddr_t lasthop=0) { nh_addr = nexthop; lh_addr = lasthop;} protected:        LIST_ENTRY(AODV_Route) route_link;        nsaddr_t        nh_addr;        nsaddr_t        lh_addr;};LIST_HEAD(aodv_routes, AODV_Route);#endif // AOMDV/*  Broadcast ID Cache*/class BroadcastID {        friend class AODV; public:        BroadcastID(nsaddr_t i, u_int32_t b) { 		src = i; id = b;#ifdef AOMDV		count=0;    		LIST_INIT(&reverse_path_list);  		LIST_INIT(&forward_path_list);#endif // AOMDV	} protected:        LIST_ENTRY(BroadcastID) link;        nsaddr_t        src;        u_int32_t       id;        double          expire;         // now + BCAST_ID_SAVE s#ifdef AOMDV	int 		count;        aodv_routes     reverse_path_list;     // List of reverse paths used for forwarding replies        aodv_routes     forward_path_list;     // List of forward paths advertised already        inline AODV_Route*	reverse_path_insert(nsaddr_t nexthop, nsaddr_t lasthop=0) {	AODV_Route* route = new AODV_Route(nexthop, lasthop); 		assert(route); 		LIST_INSERT_HEAD(&reverse_path_list, route, route_link); 		return route;	}        inline AODV_Route*	reverse_path_lookup(nsaddr_t nexthop, nsaddr_t lasthop=0) {	AODV_Route *route = reverse_path_list.lh_first;  		// Search the list for a match of id 		for( ; route; route = route->route_link.le_next) {   			if ( (route->nh_addr == nexthop) &&			     (route->lh_addr == lasthop) ) return route;      		} 		return NULL;	}        inline AODV_Route*	forward_path_insert(nsaddr_t nexthop, nsaddr_t lasthop=0) {	AODV_Route* route = new AODV_Route(nexthop, lasthop); 		assert(route); 		LIST_INSERT_HEAD(&forward_path_list, route, route_link); 		return route;	}        inline AODV_Route*	forward_path_lookup(nsaddr_t nexthop, nsaddr_t lasthop=0) {	AODV_Route *route = forward_path_list.lh_first;  		// Search the list for a match of id 		for( ; route; route = route->route_link.le_next) {   			if ( (route->nh_addr == nexthop) &&			     (route->lh_addr == lasthop) ) return route;      		} 		return NULL;	}#endif // AOMDV};LIST_HEAD(bcache, BroadcastID);/*  The Routing Agent*/class AODV: public Agent {  /*   * make some friends first    */        friend class aodv_rt_entry;        friend class BroadcastTimer;        friend class HelloTimer;        friend class NeighborTimer;        friend class RouteCacheTimer;        friend class LocalRepairTimer; public:        /*         * HDR offsets         */        int             off_AODV_;        AODV(nsaddr_t id); protected:        int             command(int, const char *const *);        int             initialized() { return index && target_; } public:        void		recv(Packet *p, Handler *); protected:        void            recvAODV(Packet *p);        void            rt_resolve(Packet *p);        void            forward(aodv_rt_entry *rt, Packet *p, double delay);        void            sendRequest(nsaddr_t dst);	double 		PerHopTime(aodv_rt_entry *rt);        void            recvRequest(Packet *p);#ifndef AOMDV        void            sendReply(nsaddr_t ipdst, u_int32_t hop_count,                                  nsaddr_t rpdst, u_int32_t rpseq,                                  u_int32_t lifetime, double timestamp);#else // AOMDV        void            sendReply(nsaddr_t ipdst, u_int32_t hop_count,                                  nsaddr_t rpdst, u_int32_t rpseq,                                  u_int32_t lifetime, double timestamp,				  nsaddr_t nexthop, u_int32_t bcast_id, nsaddr_t rp_first_hop);#endif // AOMDV        void            recvReply(Packet *p);#ifndef AOMDV        void            rt_update(aodv_rt_entry *rt,		       	 	  u_int32_t seqnum, u_int16_t metric, nsaddr_t nexthop,				  double expire_time);#endif // AOMDV public:        void            rt_ll_failed(Packet *p);        //void            handle_link_failure(nsaddr_t id);        void            handle_link_failure(nsaddr_t id, bool error=true); protected:        void            rt_down(aodv_rt_entry *rt);        void            sendError(Packet *p, bool jitter = true);        void            recvError(Packet *p);        void            rt_purge(void);        void            enque(aodv_rt_entry *rt, Packet *p);        Packet*         deque(aodv_rt_entry *rt);        /*         * Broadcast ID Management         */        BroadcastID*    id_insert(nsaddr_t id, u_int32_t bid);        BroadcastID*    id_lookup(nsaddr_t id, u_int32_t bid);        void            id_purge(void);	void 		id_delete(nsaddr_t id, u_int32_t bid);        void            sendHello(void);        void            recvHello(Packet *p);        /*         * Neighbor Management         */        AODV_Neighbor*  nb_insert(nsaddr_t id);        AODV_Neighbor*  nb_lookup(nsaddr_t id);        void            nb_delete(nsaddr_t id);        void            nb_purge(void);        void            local_rt_repair(aodv_rt_entry *rt, Packet *p);        nsaddr_t        index;                  // IP Address of this node        u_int32_t       seqno;                  // Sequence Number        int             bid;                    // Broadcast ID        // aodv_rtable     rthead;                 // routing table        aodv_ncache     nbhead;                 // Neighbor Cache        bcache          bihead;                 // Broadcast ID Cache        /*         * Timers         */        BroadcastTimer  btimer;        HelloTimer      htimer;        NeighborTimer   ntimer;        RouteCacheTimer rtimer;        LocalRepairTimer lrtimer;        /*         * Routing Table         */        aodv_rtable          rtable;        /*         *  A "drop-front" queue used by the routing layer to buffer         *  packets to which it does not have a route.         */        aodv_rqueue         rqueue;        /*         * A mechanism for logging the contents of the routing         * table.         */        Trace           *logtarget;        /*         * A pointer to the network interface queue that sits         * between the "classifier" and the "link layer".         */        PriQueue        *ifqueue;        /*         * Logging stuff         */        void            log_link_del(nsaddr_t dst);        void            log_link_broke(Packet *p);        void            log_link_kept(nsaddr_t dst);	int send_buffer_size_;	double send_buffer_timeout_;#ifdef AOMDV	int aomdv_max_paths_;	int aomdv_prim_alt_path_len_diff_;#endif AOMDV};#endif /* __aodv_h__ */

⌨️ 快捷键说明

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