module-aodv.h

00001 /*
00002 Copyright (c) 1997, 1998 Carnegie Mellon University.  All Rights
00003 Reserved. 
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007 
00008 1. Redistributions of source code must retain the above copyright notice,
00009 this list of conditions and the following disclaimer.
00010 2. Redistributions in binary form must reproduce the above copyright notice,
00011 this list of conditions and the following disclaimer in the documentation
00012 and/or other materials provided with the distribution.
00013 3. The name of the author may not be used to endorse or promote products
00014 derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00017 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00018 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00019 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00020 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00021 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00022 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00023 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00024 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00025 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 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.
00028 
00029 */
00030 
00037 #ifndef _MRCL_AODV_
00038 #define _MRCL_AODV_
00039 
00040 #include <routing-module.h>
00041 #include "aodv-rt-table.h"
00042 #include <hop-count-metric.h>
00043 #include <priqueue.h>
00044 //#include "aodv-metrics.h"
00045 
00046 #define BCAST_ID_SAVE 6
00047 
00048 #define AODV_GOT_MY_REQUEST_VERBOSITY 10
00049 #define AODV_GOT_MY_REQUEST "MyREQ"
00050 #define AODV_DISCARD_REQUEST_VERBOSITY 10
00051 #define AODV_DISCARD_REQUEST "REQ"
00052 #define AODV_RECEIVED_REQUEST_VERBOSITY 10
00053 #define AODV_RECEIVED_REQUEST "RREQ"
00054 #define AODV_RECEIVED_REQUEST_RESOLVED "RQRV"
00055 #define AODV_DROP_RTR_TTL_VERBOSITY 10
00056 #define AODV_DROP_RTR_TTL "TTL"
00057 #define AODV_REPLY_FOR_ME_VERBOSITY 20
00058 #define AODV_REPLY_FOR_ME "MyREP"
00059 #define AODV_SUPPRESS_REPLY_VERBOSITY 10
00060 #define AODV_SUPPRESS_REPLY "SREP"
00061 #define AODV_DROP_RTR_NO_ROUTE_VERBOSITY 10
00062 #define DROP_RTR_NO_ROUTE "NRTE"
00063 #define AODV_RECV_ERROR_VERBOSITY 20
00064 #define AODV_RECV_ERROR "RERR"
00065 #define AODV_RECV_HELLO_VERBOSITY 20
00066 #define AODV_RECV_HELLO "RHELLO"
00067 #define AODV_DROP_RTR_NO_ROUTE "NRTE"  // no route
00068 #define AODV_DROP_RTR_NO_ROUTE_VEROSITY 10
00069 #define DROP_RTR_MAC_CALLBACK           "CBK"   // MAC callback (from cmu-trace.h, ns2 standard distribution)
00070 #define DROP_RTR_MAC_CALLBACK_VERBOSITY 10
00071 
00072 #define REV_ROUTE_LIFE          6                               // 5  seconds
00073 #define ARP_DELAY 0.01      // fixed delay to keep arp happy
00074 #define HELLO_INTERVAL          1               // 1000 ms
00075 #define ALLOWED_HELLO_LOSS      3               // packets
00076 #define ACTIVE_ROUTE_TIMEOUT    10                              // 50 seconds
00077 #define MY_ROUTE_TIMEOUT        10                              // 100 seconds
00078 
00079 
00080 // Should be set by the user using best guess (conservative) 
00081 #define NETWORK_DIAMETER        30             // 30 hops
00082 
00083 #define RREQ_RETRIES            3  
00084 // timeout after doing network-wide search RREQ_RETRIES times
00085 #define MAX_RREQ_TIMEOUT        10.0 //sec
00086 
00087 
00088 /* Various constants used for the expanding ring search */
00089 #define TTL_START     5
00090 #define TTL_THRESHOLD 7
00091 #define TTL_INCREMENT 2 
00092 
00093 // This should be somewhat related to arp timeout
00094 #define NODE_TRAVERSAL_TIME     0.03             // 30 ms
00095 
00096 class AodvModule;
00097 
00098 /*
00099   Timers (Broadcast ID, Hello, Neighbor Cache, Route Cache)
00100 */
00101 class MrclBroadcastTimer : public Handler {
00102 public:
00103         MrclBroadcastTimer(AodvModule* a) : module(a) {}
00104         void    handle(Event*);
00105 private:
00106         AodvModule    *module;
00107         Event   intr;
00108 };
00109 
00110 class MrclHelloTimer : public Handler {
00111 public:
00112         MrclHelloTimer(AodvModule* a) : module(a) {}
00113         void    handle(Event*);
00114 private:
00115         AodvModule    *module;
00116         Event   intr;
00117 };
00118 
00119 class MrclNeighborTimer : public Handler {
00120 public:
00121         MrclNeighborTimer(AodvModule* a) : module(a) {}
00122         void    handle(Event*);
00123 private:
00124         AodvModule    *module;
00125         Event   intr;
00126 };
00127 
00128 class MrclRouteCacheTimer : public Handler {
00129 public:
00130         MrclRouteCacheTimer(AodvModule* a) : module(a) {}
00131         void    handle(Event*);
00132 private:
00133         AodvModule    *module;
00134         Event   intr;
00135 };
00136 
00137 class MrclLocalRepairTimer : public Handler {
00138 public:
00139         MrclLocalRepairTimer(AodvModule* a) : module(a) {}
00140         void    handle(Event*);
00141 private:
00142         AodvModule    *module;
00143         Event   intr;
00144 };
00145 
00146 
00147 
00148 class AodvModule : public MrclRouting
00149 {
00150         friend class MrclBroadcastTimer;
00151         friend class MrclHelloTimer;
00152         friend class MrclNeighborTimer;
00153         friend class MrclRouteCacheTimer;
00154         friend class MrclLocalRepairTimer;
00155 
00156 public:
00157         AodvModule();
00158         virtual ~AodvModule();
00159         virtual int command(int argc, const char *const *argv);
00160         
00161         void rt_ll_failed(Packet *p);
00162         void handle_link_failure(char* id);
00163         void local_rt_repair(Aodv_rt_entry *rt, Packet *p);
00164         
00165 
00166 protected:
00167         virtual int controlPacket(Packet *p);
00168         virtual void forward(Packet *p);
00169         virtual void resolve(Packet *p);
00170         virtual void forward(Packet *p, Aodv_rt_entry *re, double delay = 0.0);
00171 
00172         virtual char *getNextHop(Packet *p);
00173         virtual int canIReach(char *a, Metric ***m);
00174         
00175         virtual void recvAodv(Packet *p);
00176         virtual void recvRequest(Packet *p);
00177         virtual void recvReply(Packet *p);
00178         virtual void recvError(Packet *p);
00179         virtual void recvHello(Packet *p);
00180         
00181         virtual void sendHello();
00182         
00183 //      virtual void enque(Aodv_rt_entry *rt, Packet *p);
00184 //      virtual Packet* deque(Aodv_rt_entry *rt);
00185 
00186         virtual void sendReply(char *dst, int hop_count, char *rp_dst, int rpseq, int lifetime, double timestamp);
00187         virtual void sendRequest(char *dst);
00188         virtual void sendError(Packet *p, int jitter = 1);
00189         int id_lookup(char *addr, int bid);
00190         void id_insert(char *addr, int bid);
00191 //      void id_delete(char *id);
00192         void id_delete(AddrList *a);
00193         void id_purge(void);
00194         void rt_update(Aodv_rt_entry *rt, int seqnum, int metric, char *nexthop, double expire_time);
00195         void rt_down(Aodv_rt_entry *rt);
00196         void rt_purge();
00197         Aodv_rt_entry* rtable_lookup(char *addr) {return (rtable_.rt_lookup(addr));};
00198 //      void rt_resolve(Packet *p);
00199 
00200         void nb_insert(char *id);
00201         AddrList *nb_lookup(char *id);
00202         void nb_delete(char *id);
00203         void nb_delete(AddrList *a);
00204         void nb_purge();
00205  
00206         double perHopTime(Aodv_rt_entry *rt);
00207         
00208         double minHelloInterval() {return (helloInterval_ * minHelloIntervalRatio_);};
00209         double maxHelloInterval() {return (helloInterval_ * maxHelloIntervalRatio_);};
00210         double routeCacheFrequency() {return (routeCacheFrequency_);};
00211         
00212         int debug(){return (debug_);};
00213 
00214         HopCountMetric **m_;
00215         AddrList *ncache_;              // neighbour cache
00216         AddrList *bcache_;              // broadcast ID cache
00217         RoutingQueue rqueue_;
00218         Aodv_rtable rtable_;
00219         PriQueue* ifqueue_;     // pointer to radio interface queue (used to delete packet just 
00220         // resolved destinated(or which exploits) to link failed) 
00221         MrclAddress *broadcastAddr_;
00222         int seqno_;
00223         int RREQ_GRAT_RREP;
00224         int bid_;
00225 
00226         int AODV_LINK_LAYER_DETECTION;
00227         // TRUE:                allows AODV to use link-layer (802.11) feedback in determining when links are up/down.
00228         // FALSE:       when standard AODV link layer detection has to be used (HELLO packets)
00229 
00230         int AODV_LOCAL_REPAIR;                  // when TRUE allows local repair of routes (default = TRUE)
00231 
00232         int AODV_MIRACLE_ROUTING;                       // when TRUE 
00233                                                                                                 // AODV can fully exploit MrclRouting funtionalities
00234                                                                                                 // and therefore relay packet to other routing module within
00235                                                                                                 // the same MIRACLE routing framework in case of they can
00236                                                                                                 // solve the packet, the route request is estended to all
00237                                                                                                 // the routign modules.
00238                                                                                                 // 
00239                                                                                                 // when FALSE
00240                                                                                                 // AODV works as in standard ns2, this meas that it do not propagate
00241                                                                                                 // route request to (possible) others routing module within the 
00242                                                                                                 // same MIRACLE routing framework and therefore realaying across
00243                                                                                                 // different interface is avoided.
00244         // Timers
00245         MrclBroadcastTimer  btimer;
00246         MrclHelloTimer      htimer;
00247         MrclNeighborTimer   ntimer;
00248         MrclRouteCacheTimer rtimer;
00249         MrclLocalRepairTimer lrtimer;
00250 
00251         // Timers Variable
00252         double minHelloIntervalRatio_;
00253         double maxHelloIntervalRatio_;
00254         double helloInterval_;
00255         double routeCacheFrequency_;
00256         
00257         int debugout;
00258 };
00259 
00260 
00261 #endif
00262 

Generated on Wed Nov 26 15:47:27 2008 for NS-MIRACLE library by  doxygen 1.5.2