• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/routealgo/rlookup.h

00001 // Define classes for routing table representation and lookup
00002 // George F. Riley, Georgia Tech, Winter 2000
00003 
00004 // Defines several variations on routing table representations
00005 // and a method to determine the most memory efficient.
00006 
00007 #ifndef __RLOOKUP_H__
00008 #define __RLOOKUP_H__
00009 
00010 #include "routealgo/rnode.h"
00011 #include "routealgo/rbitmap.h"
00012 
00013 #include <iostream>
00014 #ifdef USE_HASH_MAP
00015 #include <hash_map>
00016 #include <hash_set>
00017 #else
00018 #include <map>
00019 #include <set>
00020 #endif
00021 
00022 typedef enum {
00023   RL_NULL, RL_FIXED, RL_BITMAP, RL_HASH, RL_NEXTHOP, RL_LAST}
00024 RLookup_Types;
00025 
00026 typedef pair<nodeid_t, nodeid_t> LookupPair_t; // Node/NextHop Pair
00027 
00028 // Define an abstract base class that specifies functionality needed
00029 class RLookup {
00030 public :
00031   RLookup();
00032   virtual ~RLookup();
00033   virtual RLookup_Types WhatType() const = 0; // Identifies the type of lookup
00034   virtual void Populate(  // Popluate the table
00035                         RoutingVec_t& r, // NextHop table
00036                         RoutingVec_t& p, // Population counts
00037                         nodeid_t d = NODE_NONE, // Default route
00038                         nodeid_t o = NODE_NONE, // Routing table owner
00039                         nodeid_t f = NODE_NONE, // First non-default
00040                         nodeid_t l = NODE_NONE) // Last non-default
00041                         = 0;
00042   virtual void Populate(istream& is);           // Populate from log
00043   virtual nodeid_t Lookup(nodeid_t) = 0;        // Return next hop given target
00044   virtual size_t   Size() = 0;                  // Estimate size
00045   virtual size_t   NumberEntries(){return 0;}   // Number of entries in table
00046   virtual void     Log( ostream&);              // Log to ostream
00047   static void Analyze(RoutingVec_t&,
00048                       RoutingVec_t&,            // Population counts
00049                       nodeid_t&, nodeid_t&, nodeid_t, nodeid_t&,nodeid_t&);
00050   //  friend ostream& operator<<(ostream&, const RLookup& ); // Output a routing table
00051 };
00052 
00053 // The "Null" lookup is used when there is no routing table.
00054 // Handles the pathological case for a node with no neighbors
00055 
00056 class NOLookup : public RLookup {
00057 public :
00058   NOLookup();
00059   virtual ~NOLookup();
00060   virtual RLookup_Types WhatType() const;
00061   virtual void Populate(  // Popluate the table
00062                         RoutingVec_t& r, // NextHop table
00063                         RoutingVec_t& p, // Population counts
00064                         nodeid_t d = NODE_NONE, // Default route
00065                         nodeid_t o = NODE_NONE, // Routing table owner
00066                         nodeid_t f = NODE_NONE, // First non-default
00067                         nodeid_t l = NODE_NONE);// Last non-default
00068   virtual nodeid_t Lookup(nodeid_t);
00069   virtual size_t Size();
00070   virtual void   Log( ostream&);              // Log to ostream
00071 };
00072 
00073 // The "Fixed" lookup is used when all routes are the same
00074 // Will always be the case for "leaf" nodes with only one neighbor
00075 class FRLookup : public  RLookup {
00076 public :
00077   FRLookup();
00078   virtual ~FRLookup();
00079   nodeid_t Default() const { return m_Default;}
00080   virtual RLookup_Types WhatType() const;
00081   virtual void Populate(  // Popluate the table
00082                         RoutingVec_t& r, // NextHop table
00083                         RoutingVec_t& p, // Population counts
00084                         nodeid_t d = NODE_NONE, // Default route
00085                         nodeid_t o = NODE_NONE, // Routing table owner
00086                         nodeid_t f = NODE_NONE, // First non-default
00087                         nodeid_t l = NODE_NONE);// Last non-default
00088   virtual nodeid_t Lookup(nodeid_t);
00089   virtual size_t Size();
00090   virtual void   Log( ostream&);              // Log to ostream
00091   static  size_t EstimateSize(
00092                         RoutingVec_t& r, // NextHop table
00093                         RoutingVec_t& p, // Population counts
00094                         nodeid_t d,      // Default route
00095                         nodeid_t n,      // Number default
00096                         nodeid_t o,      // Routing table owner
00097                         nodeid_t f,      // First non-default
00098                         nodeid_t l);     // Last non-default
00099   //  friend ostream& operator<<(ostream&, const FRLookup& ); // Output a routing table
00100 private:
00101   nodeid_t m_Default;  
00102 };
00103 
00104 // The "Bitmap" lookup is used when there are many "default" entries
00105 // and a few non-defaults clustered in a small range
00106 class BMLookup : public  RLookup {
00107 public :
00108   BMLookup();
00109   virtual ~BMLookup();
00110   virtual RLookup_Types WhatType() const; // Identifies the type of lookup
00111   virtual void Populate(  // Popluate the table
00112                         RoutingVec_t& r, // NextHop table
00113                         RoutingVec_t& p, // Population counts
00114                         nodeid_t d = NODE_NONE, // Default route
00115                         nodeid_t o = NODE_NONE, // Routing table owner
00116                         nodeid_t f = NODE_NONE, // First non-default
00117                         nodeid_t l = NODE_NONE);// Last non-default
00118   virtual nodeid_t Lookup(nodeid_t);
00119   virtual size_t   Size();
00120   virtual size_t   NumberEntries();             // Number of entries in table
00121   virtual void     Log( ostream&);              // Log to ostream
00122   static  size_t   EstimateSize(
00123                         RoutingVec_t& r, // NextHop table
00124                         RoutingVec_t& p, // Population counts
00125                         nodeid_t d,      // Default route
00126                         nodeid_t n,      // Number default
00127                         nodeid_t o,      // Routing table owner
00128                         nodeid_t f,      // First non-default
00129                         nodeid_t l);     // Last non-default
00130   //  friend ostream& operator<<(ostream&, const BMLookup& ); // Output a bitmap routing table
00131 private:
00132   nodeid_t     m_Default;  
00133   nodeid_t     m_FirstNonDefault;
00134   nodeid_t     m_LastNonDefault;
00135   RoutingVec_t m_NVec;  // Neighbor vector
00136   BitMap*      m_pBitMap; // Bitmap of non-default entries
00137 };
00138 
00139 // The "HashMap" lookup is used when the previous two methods do not work.
00140 // Uses the STL "hash_map" associative container to store non-default routes.
00141 // By default, this is OFF because hash_map is an SGI extension to STL,
00142 // not part of standard STL.
00143 #ifdef USE_HASH_MAP
00144 typedef hash_map<nodeid_t, nodeid_t,
00145                  hash<nodeid_t>, equal_to<nodeid_t> > RouteMap_t;
00146 #else
00147 typedef map<nodeid_t, nodeid_t,  equal_to<nodeid_t> > RouteMap_t;
00148 #endif
00149 
00150 typedef RouteMap_t::iterator                          RouteMap_it;
00151 typedef RouteMap_t::value_type                        RoutePair_t;
00152 
00153 class HMLookup : public  RLookup {
00154 public :
00155   HMLookup();
00156   virtual ~HMLookup();
00157   virtual RLookup_Types WhatType() const; // Identifies the type of lookup
00158   virtual void Populate(  // Popluate the table
00159                         RoutingVec_t& r, // NextHop table
00160                         RoutingVec_t& p, // Population counts
00161                         nodeid_t d = NODE_NONE, // Default route
00162                         nodeid_t o = NODE_NONE, // Routing table owner
00163                         nodeid_t f = NODE_NONE, // First non-default
00164                         nodeid_t l = NODE_NONE);// Last non-default
00165   virtual nodeid_t Lookup(nodeid_t);
00166   virtual size_t   Size();
00167   virtual size_t   NumberEntries();             // Number of entries in table
00168   virtual void     Log( ostream&);              // Log to ostream
00169   static  size_t   EstimateSize(
00170                         RoutingVec_t& r, // NextHop table
00171                         RoutingVec_t& p, // Population counts
00172                         nodeid_t d,      // Default route
00173                         nodeid_t n,      // Number default
00174                         nodeid_t o,      // Routing table owner
00175                         nodeid_t f,      // First non-default
00176                         nodeid_t l);     // Last non-default
00177   //  friend ostream& operator<<(ostream&, const HMLookup& ); // Output a routing table
00178 private:
00179   nodeid_t     m_Default;  
00180   RouteMap_t   m_RouteMap;
00181 };
00182 
00183 // Also included is the "inefficient" version for memory usage comparisons
00184 // NHLookup (NextHop) lookup just stores the next hop in a lookup array
00185 class NHLookup : public  RLookup {
00186 public :
00187   NHLookup();
00188   virtual ~NHLookup();
00189   virtual RLookup_Types WhatType() const; // Identifies the type of lookup
00190   virtual void Populate(  // Popluate the table
00191                         RoutingVec_t& r, // NextHop table
00192                         RoutingVec_t& p, // Population counts
00193                         nodeid_t d = NODE_NONE, // Default route
00194                         nodeid_t o = NODE_NONE, // Routing table owner
00195                         nodeid_t f = NODE_NONE, // First non-default
00196                         nodeid_t l = NODE_NONE);// Last non-default
00197   virtual void Populate(istream& is);           // Populate from log
00198   virtual nodeid_t Lookup(nodeid_t);
00199   virtual size_t   Size();
00200   virtual size_t   NumberEntries();             // Number of entries in table
00201   virtual void     Log( ostream&);              // Log to ostream
00202   static  size_t   EstimateSize(
00203                         RoutingVec_t& r, // NextHop table
00204                         RoutingVec_t& p, // Population counts
00205                         nodeid_t d,      // Default route
00206                         nodeid_t n,      // Number default
00207                         nodeid_t o,      // Routing table owner
00208                         nodeid_t f,      // First non-default
00209                         nodeid_t l);     // Last non-default
00210 private:
00211   RoutingVec_t   m_RouteTable;
00212 };
00213 
00214 
00215 
00216 #endif

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