Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

aodv.h

Go to the documentation of this file.
00001 /*
00002 Copyright (c) 1997, 1998 Carnegie Mellon University.  All Rights
00003 Reserved. 
00004 
00005 Permission to use, copy, modify, and distribute this
00006 software and its documentation is hereby granted (including for
00007 commercial or for-profit use), provided that both the copyright notice and this permission notice appear in all copies of the software, derivative works, or modified versions, and any portions thereof, and that both notices appear in supporting documentation, and that credit is given to Carnegie Mellon University in all publications reporting on direct or indirect use of this code or its derivatives.
00008 
00009 ALL CODE, SOFTWARE, PROTOCOLS, AND ARCHITECTURES DEVELOPED BY THE CMU
00010 MONARCH PROJECT ARE EXPERIMENTAL AND ARE KNOWN TO HAVE BUGS, SOME OF
00011 WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON PROVIDES THIS
00012 SOFTWARE OR OTHER INTELLECTUAL PROPERTY IN ITS ``AS IS'' CONDITION,
00013 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00014 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00015 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
00016 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00017 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00018 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
00019 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00020 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00021 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE OR
00022 INTELLECTUAL PROPERTY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00023 DAMAGE.
00024 
00025 Carnegie Mellon encourages (but does not require) users of this
00026 software or intellectual property to return any improvements or
00027 extensions that they make, and to grant Carnegie Mellon the rights to redistribute these changes without encumbrance.
00028 
00029 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.
00030 
00031 */
00032 
00033 #ifndef __aodv_h__
00034 #define __aodv_h__
00035 
00036 //#include <agent.h>
00037 //#include <packet.h>
00038 //#include <sys/types.h>
00039 //#include <cmu/list.h>
00040 //#include <scheduler.h>
00041 
00042 #include <cmu-trace.h>
00043 #include <priqueue.h>
00044 #include <aodv/aodv_rtable.h>
00045 #include <aodv/aodv_rqueue.h>
00046 
00047 /*
00048   Allows local repair of routes 
00049 */
00050 #define AODV_LOCAL_REPAIR
00051 
00052 /*
00053   Allows AODV to use link-layer (802.11) feedback in determining when
00054   links are up/down.
00055 */
00056 #define AODV_LINK_LAYER_DETECTION
00057 
00058 /*
00059   Causes AODV to apply a "smoothing" function to the link layer feedback
00060   that is generated by 802.11.  In essence, it requires that RT_MAX_ERROR
00061   errors occurs within a window of RT_MAX_ERROR_TIME before the link
00062   is considered bad.
00063 */
00064 #define AODV_USE_LL_METRIC
00065 
00066 /*
00067   Only applies if AODV_USE_LL_METRIC is defined.
00068   Causes AODV to apply omniscient knowledge to the feedback received
00069   from 802.11.  This may be flawed, because it does not account for
00070   congestion.
00071 */
00072 //#define AODV_USE_GOD_FEEDBACK
00073 
00074 
00075 class AODV;
00076 
00077 #define MY_ROUTE_TIMEOUT        10                              // 100 seconds
00078 #define ACTIVE_ROUTE_TIMEOUT    10                              // 50 seconds
00079 #define REV_ROUTE_LIFE          6                               // 5  seconds
00080 #define BCAST_ID_SAVE           6                               // 3 seconds
00081 
00082 
00083 // No. of times to do network-wide search before timing out for 
00084 // MAX_RREQ_TIMEOUT sec. 
00085 #define RREQ_RETRIES            3  
00086 // timeout after doing network-wide search RREQ_RETRIES times
00087 #define MAX_RREQ_TIMEOUT        10.0 //sec
00088 
00089 /* Various constants used for the expanding ring search */
00090 #define TTL_START     5
00091 #define TTL_THRESHOLD 7
00092 #define TTL_INCREMENT 2 
00093 
00094 // This should be somewhat related to arp timeout
00095 #define NODE_TRAVERSAL_TIME     0.03             // 30 ms
00096 #define LOCAL_REPAIR_WAIT_TIME  0.15 //sec
00097 
00098 // Should be set by the user using best guess (conservative) 
00099 #define NETWORK_DIAMETER        30             // 30 hops
00100 
00101 // Must be larger than the time difference between a node propagates a route 
00102 // request and gets the route reply back.
00103 
00104 //#define RREP_WAIT_TIME     (3 * NODE_TRAVERSAL_TIME * NETWORK_DIAMETER) // ms
00105 //#define RREP_WAIT_TIME     (2 * REV_ROUTE_LIFE)  // seconds
00106 #define RREP_WAIT_TIME         1.0  // sec
00107 
00108 #define ID_NOT_FOUND    0x00
00109 #define ID_FOUND        0x01
00110 //#define INFINITY        0xff
00111 
00112 // The followings are used for the forward() function. Controls pacing.
00113 #define DELAY 1.0           // random delay
00114 #define NO_DELAY -1.0       // no delay 
00115 
00116 // think it should be 30 ms
00117 #define ARP_DELAY 0.01      // fixed delay to keep arp happy
00118 
00119 
00120 #define HELLO_INTERVAL          1               // 1000 ms
00121 #define ALLOWED_HELLO_LOSS      3               // packets
00122 #define BAD_LINK_LIFETIME       3               // 3000 ms
00123 #define MaxHelloInterval        (1.25 * HELLO_INTERVAL)
00124 #define MinHelloInterval        (0.75 * HELLO_INTERVAL)
00125 
00126 /*
00127   Timers (Broadcast ID, Hello, Neighbor Cache, Route Cache)
00128 */
00129 class BroadcastTimer : public Handler {
00130 public:
00131         BroadcastTimer(AODV* a) : agent(a) {}
00132         void    handle(Event*);
00133 private:
00134         AODV    *agent;
00135         Event   intr;
00136 };
00137 
00138 class HelloTimer : public Handler {
00139 public:
00140         HelloTimer(AODV* a) : agent(a) {}
00141         void    handle(Event*);
00142 private:
00143         AODV    *agent;
00144         Event   intr;
00145 };
00146 
00147 class NeighborTimer : public Handler {
00148 public:
00149         NeighborTimer(AODV* a) : agent(a) {}
00150         void    handle(Event*);
00151 private:
00152         AODV    *agent;
00153         Event   intr;
00154 };
00155 
00156 class RouteCacheTimer : public Handler {
00157 public:
00158         RouteCacheTimer(AODV* a) : agent(a) {}
00159         void    handle(Event*);
00160 private:
00161         AODV    *agent;
00162         Event   intr;
00163 };
00164 
00165 class LocalRepairTimer : public Handler {
00166 public:
00167         LocalRepairTimer(AODV* a) : agent(a) {}
00168         void    handle(Event*);
00169 private:
00170         AODV    *agent;
00171         Event   intr;
00172 };
00173 
00174 
00175 /*
00176   Broadcast ID Cache
00177 */
00178 class BroadcastID {
00179         friend class AODV;
00180  public:
00181         BroadcastID(nsaddr_t i, u_int32_t b) { src = i; id = b;  }
00182  protected:
00183         LIST_ENTRY(BroadcastID) link;
00184         nsaddr_t        src;
00185         u_int32_t       id;
00186         double          expire;         // now + BCAST_ID_SAVE s
00187 };
00188 
00189 LIST_HEAD(aodv_bcache, BroadcastID);
00190 
00191 
00192 /*
00193   The Routing Agent
00194 */
00195 class AODV: public Agent {
00196 
00197   /*
00198    * make some friends first 
00199    */
00200 
00201         friend class aodv_rt_entry;
00202         friend class BroadcastTimer;
00203         friend class HelloTimer;
00204         friend class NeighborTimer;
00205         friend class RouteCacheTimer;
00206         friend class LocalRepairTimer;
00207 
00208  public:
00209         AODV(nsaddr_t id);
00210 
00211         void            recv(Packet *p, Handler *);
00212 
00213  protected:
00214         int             command(int, const char *const *);
00215         int             initialized() { return 1 && target_; }
00216 
00217         /*
00218          * Route Table Management
00219          */
00220         void            rt_resolve(Packet *p);
00221         void            rt_update(aodv_rt_entry *rt, u_int32_t seqnum,
00222                                 u_int16_t metric, nsaddr_t nexthop,
00223                                 double expire_time);
00224         void            rt_down(aodv_rt_entry *rt);
00225         void            local_rt_repair(aodv_rt_entry *rt, Packet *p);
00226  public:
00227         void            rt_ll_failed(Packet *p);
00228         void            handle_link_failure(nsaddr_t id);
00229  protected:
00230         void            rt_purge(void);
00231 
00232         void            enque(aodv_rt_entry *rt, Packet *p);
00233         Packet*         deque(aodv_rt_entry *rt);
00234 
00235         /*
00236          * Neighbor Management
00237          */
00238         void            nb_insert(nsaddr_t id);
00239         AODV_Neighbor*       nb_lookup(nsaddr_t id);
00240         void            nb_delete(nsaddr_t id);
00241         void            nb_purge(void);
00242 
00243         /*
00244          * Broadcast ID Management
00245          */
00246 
00247         void            id_insert(nsaddr_t id, u_int32_t bid);
00248         bool            id_lookup(nsaddr_t id, u_int32_t bid);
00249         void            id_purge(void);
00250 
00251         /*
00252          * Packet TX Routines
00253          */
00254         void            forward(aodv_rt_entry *rt, Packet *p, double delay);
00255         void            sendHello(void);
00256         void            sendRequest(nsaddr_t dst);
00257 
00258         void            sendReply(nsaddr_t ipdst, u_int32_t hop_count,
00259                                   nsaddr_t rpdst, u_int32_t rpseq,
00260                                   u_int32_t lifetime, double timestamp);
00261         void            sendError(Packet *p, bool jitter = true);
00262                                           
00263         /*
00264          * Packet RX Routines
00265          */
00266         void            recvAODV(Packet *p);
00267         void            recvHello(Packet *p);
00268         void            recvRequest(Packet *p);
00269         void            recvReply(Packet *p);
00270         void            recvError(Packet *p);
00271 
00272         /*
00273          * History management
00274          */
00275         
00276         double          PerHopTime(aodv_rt_entry *rt);
00277 
00278 
00279         nsaddr_t        index;                  // IP Address of this node
00280         u_int32_t       seqno;                  // Sequence Number
00281         int             bid;                    // Broadcast ID
00282 
00283         aodv_rtable         rthead;                 // routing table
00284         aodv_ncache         nbhead;                 // Neighbor Cache
00285         aodv_bcache          bihead;                 // Broadcast ID Cache
00286 
00287         /*
00288          * Timers
00289          */
00290         BroadcastTimer  btimer;
00291         HelloTimer      htimer;
00292         NeighborTimer   ntimer;
00293         RouteCacheTimer rtimer;
00294         LocalRepairTimer lrtimer;
00295 
00296         /*
00297          * Routing Table
00298          */
00299         aodv_rtable          rtable;
00300         /*
00301          *  A "drop-front" queue used by the routing layer to buffer
00302          *  packets to which it does not have a route.
00303          */
00304         aodv_rqueue         rqueue;
00305 
00306         /*
00307          * A mechanism for logging the contents of the routing
00308          * table.
00309          */
00310         Trace           *logtarget;
00311 
00312         /*
00313          * A pointer to the network interface queue that sits
00314          * between the "classifier" and the "link layer".
00315          */
00316         PriQueue        *ifqueue;
00317 
00318         /*
00319          * Logging stuff
00320          */
00321         void            log_link_del(nsaddr_t dst);
00322         void            log_link_broke(Packet *p);
00323         void            log_link_kept(nsaddr_t dst);
00324 };
00325 
00326 #endif /* __aodv_h__ */

Generated on Tue Apr 20 12:14:10 2004 for NS2.26SourcesOriginal by doxygen 1.3.3