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_rtable_h__ 00032 #define __aodv_rtable_h__ 00033 00034 #include <assert.h> 00035 #include <sys/types.h> 00036 #include <config.h> 00037 #include <lib/bsd-list.h> 00038 #include <scheduler.h> 00039 00040 #define CURRENT_TIME Scheduler::instance().clock() 00041 #define INFINITY2 0xff 00042 00043 /* 00044 AODV Neighbor Cache Entry 00045 */ 00046 class AODV_Neighbor { 00047 friend class AODV; 00048 friend class aodv_rt_entry; 00049 public: 00050 AODV_Neighbor(u_int32_t a) { nb_addr = a; } 00051 00052 protected: 00053 LIST_ENTRY(AODV_Neighbor) nb_link; 00054 nsaddr_t nb_addr; 00055 double nb_expire; // ALLOWED_HELLO_LOSS * HELLO_INTERVAL 00056 }; 00057 00058 LIST_HEAD(aodv_ncache, AODV_Neighbor); 00059 00060 /* 00061 AODV Precursor list data structure 00062 */ 00063 class AODV_Precursor { 00064 friend class AODV; 00065 friend class aodv_rt_entry; 00066 public: 00067 AODV_Precursor(u_int32_t a) { pc_addr = a; } 00068 00069 protected: 00070 LIST_ENTRY(AODV_Precursor) pc_link; 00071 nsaddr_t pc_addr; // precursor address 00072 }; 00073 00074 LIST_HEAD(aodv_precursors, AODV_Precursor); 00075 00076 00077 /* 00078 Route Table Entry 00079 */ 00080 00081 class aodv_rt_entry { 00082 friend class aodv_rtable; 00083 friend class AODV; 00084 friend class LocalRepairTimer; 00085 public: 00086 aodv_rt_entry(); 00087 ~aodv_rt_entry(); 00088 00089 void nb_insert(nsaddr_t id); 00090 AODV_Neighbor* nb_lookup(nsaddr_t id); 00091 00092 void pc_insert(nsaddr_t id); 00093 AODV_Precursor* pc_lookup(nsaddr_t id); 00094 void pc_delete(nsaddr_t id); 00095 void pc_delete(void); 00096 bool pc_empty(void); 00097 00098 double rt_req_timeout; // when I can send another req 00099 u_int8_t rt_req_cnt; // number of route requests 00100 00101 protected: 00102 LIST_ENTRY(aodv_rt_entry) rt_link; 00103 00104 nsaddr_t rt_dst; 00105 u_int32_t rt_seqno; 00106 /* u_int8_t rt_interface; */ 00107 u_int16_t rt_hops; // hop count 00108 int rt_last_hop_count; // last valid hop count 00109 nsaddr_t rt_nexthop; // next hop IP address 00110 /* list of precursors */ 00111 aodv_precursors rt_pclist; 00112 double rt_expire; // when entry expires 00113 u_int8_t rt_flags; 00114 00115 #define RTF_DOWN 0 00116 #define RTF_UP 1 00117 #define RTF_IN_REPAIR 2 00118 00119 /* 00120 * Must receive 4 errors within 3 seconds in order to mark 00121 * the route down. 00122 u_int8_t rt_errors; // error count 00123 double rt_error_time; 00124 #define MAX_RT_ERROR 4 // errors 00125 #define MAX_RT_ERROR_TIME 3 // seconds 00126 */ 00127 00128 #define MAX_HISTORY 3 00129 double rt_disc_latency[MAX_HISTORY]; 00130 char hist_indx; 00131 int rt_req_last_ttl; // last ttl value used 00132 // last few route discovery latencies 00133 // double rt_length [MAX_HISTORY]; 00134 // last few route lengths 00135 00136 /* 00137 * a list of neighbors that are using this route. 00138 */ 00139 aodv_ncache rt_nblist; 00140 }; 00141 00142 00143 /* 00144 The Routing Table 00145 */ 00146 00147 class aodv_rtable { 00148 public: 00149 aodv_rtable() { LIST_INIT(&rthead); } 00150 00151 aodv_rt_entry* head() { return rthead.lh_first; } 00152 00153 aodv_rt_entry* rt_add(nsaddr_t id); 00154 void rt_delete(nsaddr_t id); 00155 aodv_rt_entry* rt_lookup(nsaddr_t id); 00156 00157 private: 00158 LIST_HEAD(aodv_rthead, aodv_rt_entry) rthead; 00159 }; 00160 00161 #endif /* _aodv__rtable_h__ */
1.4.6