rttable.cc

Go to the documentation of this file.
00001 
00002 /* The AODV code developed by the CMU/MONARCH group was optimized
00003  * and tuned by Samir Das (UTSA) and Mahesh Marina (UTSA). The 
00004  * work was partially done in Sun Microsystems.
00005  * 
00006  * The original CMU copyright is below. 
00007  */
00008 
00009 /*
00010 Copyright (c) 1997, 1998 Carnegie Mellon University.  All Rights
00011 Reserved. 
00012 
00013 Redistribution and use in source and binary forms, with or without
00014 modification, are permitted provided that the following conditions are met:
00015 
00016 1. Redistributions of source code must retain the above copyright notice,
00017 this list of conditions and the following disclaimer.
00018 2. Redistributions in binary form must reproduce the above copyright notice,
00019 this list of conditions and the following disclaimer in the documentation
00020 and/or other materials provided with the distribution.
00021 3. The name of the author may not be used to endorse or promote products
00022 derived from this software without specific prior written permission.
00023 
00024 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00025 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00026 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00027 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00028 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00029 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00030 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00031 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00032 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00033 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 
00035 */
00036 
00037 /* ported into VINT ns by Ya Xu, Sept. 1999 */
00038 
00039 #include <rttable.h>
00040 
00041 /* =====================================================================
00042    The Routing Table
00043    ===================================================================== */
00044 
00045 rt_entry::rt_entry()
00046 {
00047     int i;
00048 
00049         rt_dst = 0;
00050         rt_seqno = 0;
00051         rt_nexthop = 0;
00052         rt_expire = 0.0;
00053         rt_hops = INFINITY2;
00054         rt_flags = RTF_DOWN;
00055 
00056         rt_errors = 0;
00057         rt_error_time = 0.0;
00058 
00059         rt_req_timeout = 0.0;
00060         rt_req_cnt = 0;
00061     rt_req_last_ttl = 0;
00062     hist_indx = 0;
00063 
00064     for (i=0; i < MAX_HISTORY; i++) {
00065         // rt_length[i] = 0;
00066         rt_disc_latency[i] = 0.0;
00067     }
00068         error_propagate_counter = 0;
00069         LIST_INIT(&rt_nblist);
00070 };
00071 
00072 
00073 rt_entry::~rt_entry()
00074 {
00075         Neighbor *nb;
00076 
00077         while((nb = rt_nblist.lh_first)) {
00078                 LIST_REMOVE(nb, nb_link);
00079                 delete nb;
00080         }
00081 }
00082 
00083 
00084 void
00085 rt_entry::nb_insert(nsaddr_t id)
00086 {
00087         Neighbor *nb = new Neighbor(id);
00088         assert(nb);
00089 
00090         nb->nb_expire = 0;
00091         LIST_INSERT_HEAD(&rt_nblist, nb, nb_link);
00092 }
00093 
00094 
00095 Neighbor*
00096 rt_entry::nb_lookup(nsaddr_t id)
00097 {
00098         Neighbor *nb = rt_nblist.lh_first;
00099 
00100         for(; nb; nb = nb->nb_link.le_next) {
00101                 if(nb->nb_addr == id)
00102                         break;
00103         }
00104         return nb;
00105 }
00106 
00107 /* =====================================================================
00108    The Routing Table
00109    ===================================================================== */
00110 rt_entry*
00111 rttable::rt_lookup(nsaddr_t id)
00112 {
00113         rt_entry *rt = rthead.lh_first;
00114 
00115         for(; rt; rt = rt->rt_link.le_next) {
00116                 if(rt->rt_dst == id)
00117                         break;
00118         }
00119         return rt;
00120 }
00121 
00122 void
00123 rttable::rt_delete(nsaddr_t id)
00124 {
00125         rt_entry *rt = rt_lookup(id);
00126 
00127         if(rt) {
00128                 LIST_REMOVE(rt, rt_link);
00129                 delete rt;
00130         }
00131 }
00132 
00133 rt_entry*
00134 rttable::rt_add(nsaddr_t id)
00135 {
00136         rt_entry *rt;
00137 
00138         assert(rt_lookup(id) == 0);
00139 
00140         rt = new rt_entry;
00141         assert(rt);
00142 
00143         rt->rt_dst = id;
00144         LIST_INSERT_HEAD(&rthead, rt, rt_link);
00145 
00146         return rt;
00147 }

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