00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <aodv/aodv_rtable.h>
00032
00033
00034
00035
00036
00037
00038 aodv_rt_entry::aodv_rt_entry()
00039 {
00040 int i;
00041
00042 rt_req_timeout = 0.0;
00043 rt_req_cnt = 0;
00044
00045 rt_dst = 0;
00046 rt_seqno = 0;
00047 rt_hops = rt_last_hop_count = INFINITY2;
00048 rt_nexthop = 0;
00049 LIST_INIT(&rt_pclist);
00050 rt_expire = 0.0;
00051 rt_flags = RTF_DOWN;
00052
00053
00054
00055
00056
00057
00058
00059 for (i=0; i < MAX_HISTORY; i++) {
00060 rt_disc_latency[i] = 0.0;
00061 }
00062 hist_indx = 0;
00063 rt_req_last_ttl = 0;
00064
00065 LIST_INIT(&rt_nblist);
00066
00067 };
00068
00069
00070 aodv_rt_entry::~aodv_rt_entry()
00071 {
00072 AODV_Neighbor *nb;
00073
00074 while((nb = rt_nblist.lh_first)) {
00075 LIST_REMOVE(nb, nb_link);
00076 delete nb;
00077 }
00078
00079 AODV_Precursor *pc;
00080
00081 while((pc = rt_pclist.lh_first)) {
00082 LIST_REMOVE(pc, pc_link);
00083 delete pc;
00084 }
00085
00086 }
00087
00088
00089 void
00090 aodv_rt_entry::nb_insert(nsaddr_t id)
00091 {
00092 AODV_Neighbor *nb = new AODV_Neighbor(id);
00093
00094 assert(nb);
00095 nb->nb_expire = 0;
00096 LIST_INSERT_HEAD(&rt_nblist, nb, nb_link);
00097
00098 }
00099
00100
00101 AODV_Neighbor*
00102 aodv_rt_entry::nb_lookup(nsaddr_t id)
00103 {
00104 AODV_Neighbor *nb = rt_nblist.lh_first;
00105
00106 for(; nb; nb = nb->nb_link.le_next) {
00107 if(nb->nb_addr == id)
00108 break;
00109 }
00110 return nb;
00111
00112 }
00113
00114
00115 void
00116 aodv_rt_entry::pc_insert(nsaddr_t id)
00117 {
00118 if (pc_lookup(id) == NULL) {
00119 AODV_Precursor *pc = new AODV_Precursor(id);
00120
00121 assert(pc);
00122 LIST_INSERT_HEAD(&rt_pclist, pc, pc_link);
00123 }
00124 }
00125
00126
00127 AODV_Precursor*
00128 aodv_rt_entry::pc_lookup(nsaddr_t id)
00129 {
00130 AODV_Precursor *pc = rt_pclist.lh_first;
00131
00132 for(; pc; pc = pc->pc_link.le_next) {
00133 if(pc->pc_addr == id)
00134 return pc;
00135 }
00136 return NULL;
00137
00138 }
00139
00140 void
00141 aodv_rt_entry::pc_delete(nsaddr_t id) {
00142 AODV_Precursor *pc = rt_pclist.lh_first;
00143
00144 for(; pc; pc = pc->pc_link.le_next) {
00145 if(pc->pc_addr == id) {
00146 LIST_REMOVE(pc,pc_link);
00147 delete pc;
00148 break;
00149 }
00150 }
00151
00152 }
00153
00154 void
00155 aodv_rt_entry::pc_delete(void) {
00156 AODV_Precursor *pc;
00157
00158 while((pc = rt_pclist.lh_first)) {
00159 LIST_REMOVE(pc, pc_link);
00160 delete pc;
00161 }
00162 }
00163
00164 bool
00165 aodv_rt_entry::pc_empty(void) {
00166 AODV_Precursor *pc;
00167
00168 if ((pc = rt_pclist.lh_first)) return false;
00169 else return true;
00170 }
00171
00172
00173
00174
00175
00176 aodv_rt_entry*
00177 aodv_rtable::rt_lookup(nsaddr_t id)
00178 {
00179 aodv_rt_entry *rt = rthead.lh_first;
00180
00181 for(; rt; rt = rt->rt_link.le_next) {
00182 if(rt->rt_dst == id)
00183 break;
00184 }
00185 return rt;
00186
00187 }
00188
00189 void
00190 aodv_rtable::rt_delete(nsaddr_t id)
00191 {
00192 aodv_rt_entry *rt = rt_lookup(id);
00193
00194 if(rt) {
00195 LIST_REMOVE(rt, rt_link);
00196 delete rt;
00197 }
00198
00199 }
00200
00201 aodv_rt_entry*
00202 aodv_rtable::rt_add(nsaddr_t id)
00203 {
00204 aodv_rt_entry *rt;
00205
00206 assert(rt_lookup(id) == 0);
00207 rt = new aodv_rt_entry;
00208 assert(rt);
00209 rt->rt_dst = id;
00210 LIST_INSERT_HEAD(&rthead, rt, rt_link);
00211 return rt;
00212 }