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