• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/aodv/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 
00031 #ifndef __aodv_h__
00032 #define __aodv_h__
00033 
00034 //#include <agent.h>
00035 //#include <packet.h>
00036 //#include <sys/types.h>
00037 //#include <cmu/list.h>
00038 //#include <scheduler.h>
00039 
00040 #include <cmu-trace.h>
00041 #include <priqueue.h>
00042 #include <aodv/aodv_rtable.h>
00043 #include <aodv/aodv_rqueue.h>
00044 #include <classifier/classifier-port.h>
00045 
00046 /*
00047   Allows local repair of routes 
00048 */
00049 #define AODV_LOCAL_REPAIR
00050 
00051 /*
00052   Allows AODV to use link-layer (802.11) feedback in determining when
00053   links are up/down.
00054 */
00055 #define AODV_LINK_LAYER_DETECTION
00056 
00057 /*
00058   Causes AODV to apply a "smoothing" function to the link layer feedback
00059   that is generated by 802.11.  In essence, it requires that RT_MAX_ERROR
00060   errors occurs within a window of RT_MAX_ERROR_TIME before the link
00061   is considered bad.
00062 */
00063 #define AODV_USE_LL_METRIC
00064 
00065 /*
00066   Only applies if AODV_USE_LL_METRIC is defined.
00067   Causes AODV to apply omniscient knowledge to the feedback received
00068   from 802.11.  This may be flawed, because it does not account for
00069   congestion.
00070 */
00071 //#define AODV_USE_GOD_FEEDBACK
00072 
00073 
00074 class AODV;
00075 
00076 #define MY_ROUTE_TIMEOUT        10                              // 100 seconds
00077 #define ACTIVE_ROUTE_TIMEOUT    10                              // 50 seconds
00078 #define REV_ROUTE_LIFE          6                               // 5  seconds
00079 #define BCAST_ID_SAVE           6                               // 3 seconds
00080 
00081 
00082 // No. of times to do network-wide search before timing out for 
00083 // MAX_RREQ_TIMEOUT sec. 
00084 #define RREQ_RETRIES            3  
00085 // timeout after doing network-wide search RREQ_RETRIES times
00086 #define MAX_RREQ_TIMEOUT        10.0 //sec
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 #define LOCAL_REPAIR_WAIT_TIME  0.15 //sec
00096 
00097 // Should be set by the user using best guess (conservative) 
00098 #define NETWORK_DIAMETER        30             // 30 hops
00099 
00100 // Must be larger than the time difference between a node propagates a route 
00101 // request and gets the route reply back.
00102 
00103 //#define RREP_WAIT_TIME     (3 * NODE_TRAVERSAL_TIME * NETWORK_DIAMETER) // ms
00104 //#define RREP_WAIT_TIME     (2 * REV_ROUTE_LIFE)  // seconds
00105 #define RREP_WAIT_TIME         1.0  // sec
00106 
00107 #define ID_NOT_FOUND    0x00
00108 #define ID_FOUND        0x01
00109 //#define INFINITY        0xff
00110 
00111 // The followings are used for the forward() function. Controls pacing.
00112 #define DELAY 1.0           // random delay
00113 #define NO_DELAY -1.0       // no delay 
00114 
00115 // think it should be 30 ms
00116 #define ARP_DELAY 0.01      // fixed delay to keep arp happy
00117 
00118 
00119 #define HELLO_INTERVAL          1               // 1000 ms
00120 #define ALLOWED_HELLO_LOSS      3               // packets
00121 #define BAD_LINK_LIFETIME       3               // 3000 ms
00122 #define MaxHelloInterval        (1.25 * HELLO_INTERVAL)
00123 #define MinHelloInterval        (0.75 * HELLO_INTERVAL)
00124 
00125 /*
00126   Timers (Broadcast ID, Hello, Neighbor Cache, Route Cache)
00127 */
00128 class BroadcastTimer : public Handler {
00129 public:
00130         BroadcastTimer(AODV* a) : agent(a) {}
00131         void    handle(Event*);
00132 private:
00133         AODV    *agent;
00134         Event   intr;
00135 };
00136 
00137 class HelloTimer : public Handler {
00138 public:
00139         HelloTimer(AODV* a) : agent(a) {}
00140         void    handle(Event*);
00141 private:
00142         AODV    *agent;
00143         Event   intr;
00144 };
00145 
00146 class NeighborTimer : public Handler {
00147 public:
00148         NeighborTimer(AODV* a) : agent(a) {}
00149         void    handle(Event*);
00150 private:
00151         AODV    *agent;
00152         Event   intr;
00153 };
00154 
00155 class RouteCacheTimer : public Handler {
00156 public:
00157         RouteCacheTimer(AODV* a) : agent(a) {}
00158         void    handle(Event*);
00159 private:
00160         AODV    *agent;
00161         Event   intr;
00162 };
00163 
00164 class LocalRepairTimer : public Handler {
00165 public:
00166         LocalRepairTimer(AODV* a) : agent(a) {}
00167         void    handle(Event*);
00168 private:
00169         AODV    *agent;
00170         Event   intr;
00171 };
00172 
00173 
00174 /*
00175   Broadcast ID Cache
00176 */
00177 class BroadcastID {
00178         friend class AODV;
00179  public:
00180         BroadcastID(nsaddr_t i, u_int32_t b) { src = i; id = b;  }
00181  protected:
00182         LIST_ENTRY(BroadcastID) link;
00183         nsaddr_t        src;
00184         u_int32_t       id;
00185         double          expire;         // now + BCAST_ID_SAVE s
00186 };
00187 
00188 LIST_HEAD(aodv_bcache, BroadcastID);
00189 
00190 
00191 /*
00192   The Routing Agent
00193 */
00194 class AODV: public Agent {
00195 
00196   /*
00197    * make some friends first 
00198    */
00199 
00200         friend class aodv_rt_entry;
00201         friend class BroadcastTimer;
00202         friend class HelloTimer;
00203         friend class NeighborTimer;
00204         friend class RouteCacheTimer;
00205         friend class LocalRepairTimer;
00206 
00207  public:
00208         AODV(nsaddr_t id);
00209 
00210         void            recv(Packet *p, Handler *);
00211 
00212  protected:
00213         int             command(int, const char *const *);
00214         int             initialized() { return 1 && target_; }
00215 
00216         /*
00217          * Route Table Management
00218          */
00219         void            rt_resolve(Packet *p);
00220         void            rt_update(aodv_rt_entry *rt, u_int32_t seqnum,
00221                                 u_int16_t metric, nsaddr_t nexthop,
00222                                 double expire_time);
00223         void            rt_down(aodv_rt_entry *rt);
00224         void            local_rt_repair(aodv_rt_entry *rt, Packet *p);
00225  public:
00226         void            rt_ll_failed(Packet *p);
00227         void            handle_link_failure(nsaddr_t id);
00228  protected:
00229         void            rt_purge(void);
00230 
00231         void            enque(aodv_rt_entry *rt, Packet *p);
00232         Packet*         deque(aodv_rt_entry *rt);
00233 
00234         /*
00235          * Neighbor Management
00236          */
00237         void            nb_insert(nsaddr_t id);
00238         AODV_Neighbor*       nb_lookup(nsaddr_t id);
00239         void            nb_delete(nsaddr_t id);
00240         void            nb_purge(void);
00241 
00242         /*
00243          * Broadcast ID Management
00244          */
00245 
00246         void            id_insert(nsaddr_t id, u_int32_t bid);
00247         bool            id_lookup(nsaddr_t id, u_int32_t bid);
00248         void            id_purge(void);
00249 
00250         /*
00251          * Packet TX Routines
00252          */
00253         void            forward(aodv_rt_entry *rt, Packet *p, double delay);
00254         void            sendHello(void);
00255         void            sendRequest(nsaddr_t dst);
00256 
00257         void            sendReply(nsaddr_t ipdst, u_int32_t hop_count,
00258                                   nsaddr_t rpdst, u_int32_t rpseq,
00259                                   u_int32_t lifetime, double timestamp);
00260         void            sendError(Packet *p, bool jitter = true);
00261                                           
00262         /*
00263          * Packet RX Routines
00264          */
00265         void            recvAODV(Packet *p);
00266         void            recvHello(Packet *p);
00267         void            recvRequest(Packet *p);
00268         void            recvReply(Packet *p);
00269         void            recvError(Packet *p);
00270 
00271         /*
00272          * History management
00273          */
00274         
00275         double          PerHopTime(aodv_rt_entry *rt);
00276 
00277 
00278         nsaddr_t        index;                  // IP Address of this node
00279         u_int32_t       seqno;                  // Sequence Number
00280         int             bid;                    // Broadcast ID
00281 
00282         aodv_rtable         rthead;                 // routing table
00283         aodv_ncache         nbhead;                 // Neighbor Cache
00284         aodv_bcache          bihead;                 // Broadcast ID Cache
00285 
00286         /*
00287          * Timers
00288          */
00289         BroadcastTimer  btimer;
00290         HelloTimer      htimer;
00291         NeighborTimer   ntimer;
00292         RouteCacheTimer rtimer;
00293         LocalRepairTimer lrtimer;
00294 
00295         /*
00296          * Routing Table
00297          */
00298         aodv_rtable          rtable;
00299         /*
00300          *  A "drop-front" queue used by the routing layer to buffer
00301          *  packets to which it does not have a route.
00302          */
00303         aodv_rqueue         rqueue;
00304 
00305         /*
00306          * A mechanism for logging the contents of the routing
00307          * table.
00308          */
00309         Trace           *logtarget;
00310 
00311         /*
00312          * A pointer to the network interface queue that sits
00313          * between the "classifier" and the "link layer".
00314          */
00315         PriQueue        *ifqueue;
00316 
00317         /*
00318          * Logging stuff
00319          */
00320         void            log_link_del(nsaddr_t dst);
00321         void            log_link_broke(Packet *p);
00322         void            log_link_kept(nsaddr_t dst);
00323 
00324         /* for passing packets up to agents */
00325         PortClassifier *dmux_;
00326 
00327 };
00328 
00329 #endif /* __aodv_h__ */

Generated on Tue Aug 10 2010 16:16:06 for ns-2.33 by  doxygen 1.7.1