Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

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 Permission to use, copy, modify, and distribute this
00006 software and its documentation is hereby granted (including for
00007 commercial or for-profit use), provided that both the copyright notice and this permission notice appear in all copies of the software, derivative works, or modified versions, and any portions thereof, and that both notices appear in supporting documentation, and that credit is given to Carnegie Mellon University in all publications reporting on direct or indirect use of this code or its derivatives.
00008 
00009 ALL CODE, SOFTWARE, PROTOCOLS, AND ARCHITECTURES DEVELOPED BY THE CMU
00010 MONARCH PROJECT ARE EXPERIMENTAL AND ARE KNOWN TO HAVE BUGS, SOME OF
00011 WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON PROVIDES THIS
00012 SOFTWARE OR OTHER INTELLECTUAL PROPERTY IN ITS ``AS IS'' CONDITION,
00013 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00014 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00015 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
00016 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00017 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00018 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
00019 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00020 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00021 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE OR
00022 INTELLECTUAL PROPERTY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00023 DAMAGE.
00024 
00025 Carnegie Mellon encourages (but does not require) users of this
00026 software or intellectual property to return any improvements or
00027 extensions that they make, and to grant Carnegie Mellon the rights to redistribute these changes without encumbrance.
00028 
00029 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.
00030 */
00031 
00032 
00033 #include <aodv/aodv_rtable.h>
00034 //#include <cmu/aodv/aodv.h>
00035 
00036 /*
00037   The Routing Table
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  rt_errors = 0;
00057  rt_error_time = 0.0;
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   The Routing Table
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 }

Generated on Tue Apr 20 12:14:10 2004 for NS2.26SourcesOriginal by doxygen 1.3.3