• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/routing/rttable.h

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 #ifndef __rtable_h__
00040 #define __rtable_h__
00041 
00042 #include <assert.h>
00043 #include <sys/types.h>
00044 
00045 #include "config.h"
00046 #include "scheduler.h"
00047 #include "lib/bsd-list.h"
00048 
00049 #define CURRENT_TIME    Scheduler::instance().clock()
00050 #define INFINITY2        0xff
00051 
00052 /* =====================================================================
00053    Neighbor Cache Entry
00054    ===================================================================== */
00055 class Neighbor {
00056         friend class AODV;
00057         friend class rt_entry;
00058  public:
00059         Neighbor(u_int32_t a) { nb_addr = a; }
00060 
00061  protected:
00062         LIST_ENTRY(Neighbor) nb_link;
00063         nsaddr_t        nb_addr;
00064         double          nb_expire;      // ALLOWED_HELLO_LOSS * HELLO_INTERVAL
00065 };
00066 
00067 LIST_HEAD(ncache, Neighbor);
00068 
00069 
00070 /* =====================================================================
00071    Route Table Entry
00072    ===================================================================== */
00073 
00074 class rt_entry {
00075         friend class rttable;
00076         friend class AODV;
00077         friend class LocalRepairTimer;
00078  public:
00079         rt_entry();
00080         ~rt_entry();
00081 
00082         void            nb_insert(nsaddr_t id);
00083         Neighbor*       nb_lookup(nsaddr_t id);
00084 
00085  protected:
00086         LIST_ENTRY(rt_entry) rt_link;
00087         nsaddr_t        rt_dst;
00088         u_int32_t       rt_seqno;
00089         nsaddr_t        rt_nexthop;     // next hop IP address
00090 
00091         double          rt_expire;      // when entry expires
00092         u_int16_t       rt_hops;        // hop count
00093         u_int8_t        rt_flags;
00094 #define RTF_DOWN 0
00095 #define RTF_UP 1
00096 #define RTF_IN_REPAIR 2
00097 
00098         /*
00099          *  Must receive 4 errors within 3 seconds in order to mark
00100          *  the route down.
00101          */
00102         u_int8_t        rt_errors;      // error count
00103         double          rt_error_time;
00104 #define MAX_RT_ERROR            4       // errors
00105 #define MAX_RT_ERROR_TIME       3       // seconds
00106 
00107         double          rt_req_timeout;         // when I can send another req
00108         u_int8_t        rt_req_cnt;             // number of route requests
00109         int             rt_req_last_ttl;        // last ttl value used
00110 
00111 #define MAX_HISTORY     3
00112         double          rt_disc_latency[MAX_HISTORY];
00113         char            hist_indx;
00114                                 // last few route discovery latencies
00115         // double               rt_length [MAX_HISTORY];
00116                                 // last few route lengths
00117 
00118         /*
00119          * a list of neighbors that are using this route.
00120          */
00121         ncache          rt_nblist;
00122 // Mahesh - 09/11/99
00123 // This counter indicates whether route replies are sent back
00124 // for this destination, If so, how many?
00125         int error_propagate_counter;
00126 
00127 };
00128 
00129 
00130 /* =====================================================================
00131    The Routing Table
00132    ===================================================================== */
00133 class rttable {
00134  public:
00135         rttable() { LIST_INIT(&rthead); }
00136 
00137         rt_entry*       head() { return rthead.lh_first; }
00138 
00139         rt_entry*       rt_lookup(nsaddr_t id);
00140         void            rt_delete(nsaddr_t id);
00141         rt_entry*       rt_add(nsaddr_t id);
00142  private:
00143         LIST_HEAD(ncache, rt_entry) rthead;
00144 };
00145 
00146 #endif /* __rtable_h__ */

Generated on Tue Aug 10 2010 16:16:08 for ns-2.33 by  doxygen 1.7.1