aodv_rtable.cc

Go to the documentation of this file.
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 #include <aodv/aodv_rtable.h>
00032 //#include <cmu/aodv/aodv.h>
00033 
00034 /*
00035   The Routing Table
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  rt_errors = 0;
00055  rt_error_time = 0.0;
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   The Routing Table
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 }

Generated on Tue Mar 6 16:47:43 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6