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

routing.h

Go to the documentation of this file.
00001 // GENERAL PUBLIC LICENSE AGREEMENT
00002 // 
00003 // PLEASE READ THIS DOCUMENT CAREFULLY BEFORE UTILIZING THE PROGRAM
00004 // 
00005 // BY UTILIZING THIS PROGRAM, YOU AGREE TO BECOME BOUND BY THE TERMS OF
00006 // THIS LICENSE.  IF YOU DO NOT AGREE TO THE TERMS OF THIS LICENSE, DO
00007 // NOT USE THIS PROGRAM OR ANY PORTION THEREOF IN ANY FORM OR MANNER.
00008 // 
00009 // This Program is licensed, not sold to you by GEORGIA TECH RESEARCH
00010 // CORPORATION ("GTRC"), owner of all code and accompanying documentation
00011 // (hereinafter "Program"), for use only under the terms of this License,
00012 // and GTRC reserves any rights not expressly granted to you.
00013 // 
00014 // 1.  This License allows you to:
00015 // 
00016 // (a) make copies and distribute copies of the Program's source code
00017 // provide that any such copy clearly displays any and all appropriate
00018 // copyright notices and disclaimer of warranty as set forth in Article 5
00019 // and 6 of this License.  All notices that refer to this License and to
00020 // the absence of any warranty must be kept intact at all times.  A copy
00021 // of this License must accompany any and all copies of the Program
00022 // distributed to third parties.
00023 // 
00024 // A fee may be charged to cover the cost associated with the physical
00025 // act of transferring a copy to a third party.  At no time shall the
00026 // program be sold for commercial gain either alone or incorporated with
00027 // other program(s) without entering into a separate agreement with GTRC.
00028 //  
00029 // 
00030 // (b) modify the original copy or copies of the Program or any portion
00031 // thereof ("Modification(s)").  Modifications may be copied and
00032 // distributed under the terms and conditions as set forth above,
00033 // provided the following conditions are met:
00034 // 
00035 //     i) any and all modified files must be affixed with prominent
00036 // notices that you have changed the files and the date that the changes
00037 // occurred.
00038 //              
00039 //     ii) any work that you distribute, publish, or make available, that
00040 // in whole or in part contains portions of the Program or derivative
00041 // work thereof, must be licensed at no charge to all third parties under
00042 // the terms of this License.
00043 // 
00044 //    iii) if the modified program normally reads commands interactively
00045 // when run, you must cause it, when started running for such interactive
00046 // use in the most ordinary way, to display and/or print an announcement
00047 // with all appropriate copyright notices and disclaimer of warranty as
00048 // set forth in Article 5 and 6 of this License to be clearly displayed.
00049 // In addition, you must provide reasonable access to this License to the
00050 // user.
00051 // 
00052 // Any portion of a Modification that can be reasonably considered
00053 // independent of the Program and separate work in and of itself is not
00054 // subject to the terms and conditions set forth in this License as long
00055 // as it is not distributed with the Program or any portion thereof.
00056 // 
00057 // 
00058 // 2. This License further allows you to copy and distribute the Program
00059 //    or a work based on it, as set forth in Article 1 Section b in
00060 //    object code or executable form under the terms of Article 1 above
00061 //    provided that you also either:
00062 // 
00063 //    i) accompany it with complete corresponding machine-readable source
00064 // code, which must be distributed under the terms of Article 1, on a
00065 // medium customarily used for software interchange; or,
00066 // 
00067 //   ii) accompany it with a written offer, valid for no less than three
00068 // (3) years from the time of distribution, to give any third party, for
00069 // no consideration greater than the cost of physical transfer, a
00070 // complete machine-readable copy of the corresponding source code, to be
00071 // distributed under the terms of Article 1 on a medium customarily used
00072 // for software interchange; or,
00073 // 
00074 // 
00075 // 3.  Export Law Assurance.
00076 // 
00077 // You agree that the Software will not be shipped, transferred or
00078 // exported, directly into any country prohibited by the United States
00079 // Export Administration Act and the regulations thereunder nor will be
00080 // used for any purpose prohibited by the Act.
00081 //  
00082 // 4.  Termination.
00083 // 
00084 // If at anytime you are unable to comply with any portion of this
00085 // License you must immediately cease use of the Program and all
00086 // distribution activities involving the Program or any portion thereof.
00087 // 
00088 // 
00089 // 5.  Disclaimer of Warranties and Limitation on Liability.
00090 // 
00091 // YOU ACCEPT THE PROGRAM ON AN "AS IS" BASIS.  GTRC MAKES NO WARRANTY
00092 // THAT ALL ERRORS CAN BE OR HAVE BEEN ELIMINATED FROM PROGRAM.  GTRC
00093 // SHALL NOT BE RESPONSIBLE FOR LOSSES OF ANY KIND RESULTING FROM THE USE
00094 // OF PROGRAM AND ITS ACCOMPANYING DOCUMENT(S), AND CAN IN NO WAY PROVIDE
00095 // COMPENSATION FOR ANY LOSSES SUSTAINED, INCLUDING BUT NOT LIMITED TO
00096 // ANY OBLIGATION, LIABILITY, RIGHT, CLAIM OR REMEDY FOR TORT, OR FOR ANY
00097 // ACTUAL OR ALLEGED INFRINGEMENT OF PATENTS, COPYRIGHTS, TRADE SECRETS,
00098 // OR SIMILAR RIGHTS OF THIRD PARTIES, NOR ANY BUSINESS EXPENSE, MACHINE
00099 // DOWNTIME OR DAMAGES CAUSED TO YOU BY ANY DEFICIENCY, DEFECT OR ERROR
00100 // IN PROGRAM OR MALFUNCTION THEREOF, NOR ANY INCIDENTAL OR CONSEQUENTIAL
00101 // DAMAGES, HOWEVER CAUSED.  GTRC DISCLAIMS ALL WARRANTIES, BOTH EXPRESS
00102 // AND IMPLIED RESPECTING THE USE AND OPERATION OF PROGRAM AND ITS
00103 // ACCOMPANYING DOCUMENTATION, INCLUDING ALL IMPLIED WARRANTIES OF
00104 // MERCHANTABILITY AND FITNESS FOR PARTICULAR PURPOSE AND ANY IMPLIED
00105 // WARRANTY ARISING FROM COURSE OF PERFORMANCE, COURSE OF DEALING OR
00106 // USAGE OF TRADE.  GTRC MAKES NO WARRANTY THAT PROGRAM IS ADEQUATELY OR
00107 // COMPLETELY DESCRIBED IN, OR BEHAVES IN ACCORDANCE WITH ANY
00108 // ACCOMPANYING DOCUMENTATION.  THE USER OF PROGRAM IS EXPECTED TO MAKE
00109 // THE FINAL EVALUATION OF PROGRAM'S USEFULNESS IN USER'S OWN
00110 // ENVIRONMENT.
00111 // 
00112 // GTRC represents that, to the best of its knowledge, the software
00113 // furnished hereunder does not infringe any copyright or patent.
00114 // 
00115 // GTRC shall have no obligation for support or maintenance of Program.
00116 // 
00117 // 6.  Copyright Notice.
00118 // 
00119 // THE SOFTWARE AND ACCOMPANYING DOCUMENTATION ARE COPYRIGHTED WITH ALL
00120 // RIGHTS RESERVED BY GTRC.  UNDER UNITED STATES COPYRIGHT LAWS, THE
00121 // SOFTWARE AND ITS ACCOMPANYING DOCUMENTATION MAY NOT BE COPIED EXCEPT
00122 // AS GRANTED HEREIN.
00123 // 
00124 // You acknowledge that GTRC is the sole owner of Program, including all
00125 // copyrights subsisting therein.  Any and all copies or partial copies
00126 // of Program made by you shall bear the copyright notice set forth below
00127 // and affixed to the original version or such other notice as GTRC shall
00128 // designate.  Such notice shall also be affixed to all improvements or
00129 // enhancements of Program made by you or portions thereof in such a
00130 // manner and location as to give reasonable notice of GTRC's copyright
00131 // as set forth in Article 1.
00132 // 
00133 // Said copyright notice shall read as follows:
00134 // 
00135 // Copyright 2004
00136 // Dr. George F. Riley
00137 // Georgia Tech Research Corporation
00138 // Atlanta, Georgia 30332-0415
00139 // All Rights Reserved
00140 //
00141 // $Id: routing.h,v 1.11 2006/03/05 22:28:49 sunithab Exp $
00142 
00143 
00144 
00145 // Georgia Tech Network Simulator - Routing base class
00146 // George F. Riley.  Georgia Tech, Spring 2002
00147 
00148 // Virtual Base class for all routing interfaces
00149 
00150 #ifndef __routing_h__
00151 #define __routing_h__
00152 
00153 #include <vector>
00154 #include <list>
00155 #include <map>
00156 #include <algorithm>
00157 
00158 #include "debug.h"
00159 #include "common-defs.h"
00160 #include "globalstats.h"
00161 
00162 class Interface;
00163 class PDU;
00164 class Node;
00165 class Packet;
00166 
00167 //Doc:ClassXRef
00168 class RoutingEntry {
00169 //Doc:Class This class defines each entry in the routing table. Currently
00170 //Doc:Class this class supports only IPv4 addresses. It essentially
00171 //Doc:Class defines the destination address and the interface to use to
00172 //Doc:Class reach it.
00173 #ifndef WIN32
00174 public:
00175   RoutingEntry() : interface(0), nexthop(IPADDR_NONE)
00176     { DBG((Stats::routingEntAllocated++));}
00177   RoutingEntry(Interface* i, IPAddr_t a) 
00178     : interface(i), nexthop(a)
00179     { DBG((Stats::routingEntAllocated++));}
00180   RoutingEntry(const RoutingEntry& c)
00181     : interface(c.interface), nexthop(c.nexthop)
00182     { DBG((Stats::routingEntAllocated++));}
00183   ~RoutingEntry() { DBG((Stats::routingEntDeleted++));}
00184 public:
00185   Interface* interface;  // Interface for route
00186   IPAddr_t   nexthop;    // Next hop IP Address
00187 };
00188 
00189 #else
00190 
00191 public:
00192 
00193 #ifndef WIN32
00194   RoutingEntry() : interface(0), nexthop(IPADDR_NONE)
00195     { DBG((Stats::routingEntAllocated++));}
00196   RoutingEntry(Interface* i, IPAddr_t a) 
00197     : interface(i), nexthop(a)
00198     { DBG((Stats::routingEntAllocated++));}
00199   RoutingEntry(const RoutingEntry& c)
00200     : interface(c.interface), nexthop(c.nexthop)
00201     { DBG((Stats::routingEntAllocated++));}
00202 #else
00203   RoutingEntry() : interface_(0), nexthop(IPADDR_NONE)
00204     { DBG((Stats::routingEntAllocated++));}
00205   RoutingEntry(Interface* i, IPAddr_t a) 
00206     : interface_(i), nexthop(a)
00207     { DBG((Stats::routingEntAllocated++));}
00208   RoutingEntry(const RoutingEntry& c)
00209     : interface_(c.interface_), nexthop(c.nexthop)
00210     { DBG((Stats::routingEntAllocated++));}
00211 #endif
00212   ~RoutingEntry() { DBG((Stats::routingEntDeleted++));}
00213 public:
00214 #ifndef WIN32
00215   Interface* interface;  // Interface for route
00216 #else
00217         Interface* interface_;  // Interface for route
00218 #endif
00219 
00220   IPAddr_t   nexthop;    // Next hop IP Address
00221 };
00222 
00223 
00224 #endif
00225 
00226 typedef std::map<IPAddr_t, RoutingEntry> FIB_t; // Forwarding Information base
00227 typedef std::vector<FIB_t>       FIBVec_t;      // One FIB per mask length 
00228 typedef std::map<Count_t, FIB_t> FIBMap_t;      // One FIB per mask length
00229 
00230 
00231 // Virtual base class for all routing
00232 //Doc:ClassXRef
00233 class Routing {
00234 //Doc:Class The class {\tt Routing} is a virtual base class for all the
00235 //Doc:Class routing protocols that may be needed for a simulation. Each of
00236 //Doc:Class these routing protocols have to derive from this class and define
00237 //Doc:Class the routing protocol procedures
00238 public:
00239   // Routing types
00240   typedef enum { STATIC, DYNAMIC, MANUAL, NIXVECTOR, NVR, DSR, EIGRP } RType_t;
00241 public:
00242   //Doc:Method
00243   Routing();
00244   //Doc:Desc This method is the default constructor for class {\tt Routing}.
00245 
00246   //Doc:Method
00247   virtual ~Routing();
00248   //Doc:Desc This is the default destructor. Each routing protocol must
00249   //Doc:Desc define its own destructor.
00250   
00251 public:
00252   //Doc:Method
00253   virtual void Default( RoutingEntry r) = 0;     // Specify default route
00254   //Doc:Desc This method adds the default route to a particular node.
00255   //Doc:Arg1 The default routing entry or the default gateway
00256   
00257   //Doc:Method
00258   virtual RoutingEntry GetDefault() = 0;         // Get default route
00259   //Doc:Desc This method returns the default route for this node
00260   //Doc:return The default routing entry or the default gateway
00261   
00262   //Doc:Method
00263   virtual void Add( IPAddr_t, Count_t,
00264                     Interface*, IPAddr_t) = 0;   // Add a routing entry
00265   //Doc:Desc This method is used to add a routing entry into the routing
00266   //Doc:Desc table.
00267   //Doc:Arg1 The destination IP Address
00268   //Doc:Arg2 The subnet Mask of the destination IP Address
00269   //Doc:Arg3 The interface to use
00270   //Doc:Arg4 The next hop IP Address
00271 
00272         virtual void Delete( IPAddr_t, Count_t) {};
00273   
00274   //Doc:Method
00275   virtual RoutingEntry Lookup(Node*, IPAddr_t) = 0; // Find a routing entry
00276   //Doc:Desc This method implements the lookup mechanism at a  node
00277   //Doc:Desc for a given destination IP address
00278   //Doc:Arg1 Node which is looking up the routing table
00279   //Doc:Arg2 Destination IP address
00280   //Doc:Return The corresponding routing entry or nil
00281   
00282   //Doc:Method
00283   virtual RoutingEntry LookupFromPDU(PDU*) = 0;  // Find from PDU (NixVector)
00284   //Doc:Desc This method uses the PDU to look up the next route. Such a
00285   //Doc:Desc mechanism is used in routing protocols like nix vector routing
00286   //Doc:Arg1 The pointer to the PDU
00287   //Doc:Return The corresponding routing entry or nil
00288   
00289   //Doc:Method
00290   virtual Routing* Clone() = 0;                  // Get a clone of the object
00291   //Doc:Desc This method is used to make copies of the routing object.
00292   //Doc:Desc Such a mechanism is useful for example, in topology creation
00293   //Doc:Return A pointer to the cloned object
00294   
00295   //Doc:Method
00296   virtual RType_t Type() = 0;                    // Find out routing type
00297   //Doc:Desc This method enables to query the routing object of the
00298   //Doc:Desc routing protocol it implements
00299   //Doc:Return the routing type
00300   
00301   //Doc:Method
00302   virtual void    InitializeRoutes(Node*);       // Initialization
00303   //Doc:Desc This method initializes the routes and the routing table at a
00304   //Doc:Desc given node
00305   //Doc:Arg1 The pointer to the Node at which the routes are to be initialized
00306   
00307   //Doc:Method
00308   virtual void    ReInitializeRoutes(Node*, bool);// Re-Initialization
00309   //Doc:Desc This method responds to topology changes and re-computes
00310   //Doc:Desc routes as needed.
00311   //Doc:Arg1 Node pointer for which the routes are to be re-calculated
00312   //Doc:Arg2 True if node or interface UP, false if DOWN
00313   
00314   //Doc:Method
00315   virtual bool    NeedInit();                    // True if init needed
00316   //Doc:Desc This method determines if initialization is needed and returns
00317   //Doc:Desc a bool
00318   //Doc:Return true if initialization is needed
00319   
00320   virtual bool    NeedReInit();
00321   //Doc:Desc This method determines if re-initialization is needed and returns
00322   //Doc:Desc a bool true if this routing protocol needs to re-initialize
00323   //Doc:Desc in response to a topology change
00324   //Doc:Return true if initialization is needed
00325 
00326   // Statistics
00327   //Doc:Method
00328   virtual Size_t  Size() const = 0;              // Total size (bytes) of FIB
00329   //Doc:Desc This method gives the size of the routing table. or the
00330   //Doc:Desc Forwarding Information Base
00331   //Doc:Desc Size of the FIB
00332 
00333   virtual void    DataRequest(Node* n, Packet* p, void* v) {}
00334   virtual bool    DataIndication(Interface* i, Packet* p) { return true; }
00335 
00336 public:
00337   // Get the default routing pointer
00338   //Doc:Method
00339   static Routing* Default();
00340   //Doc:Desc This method returns the default routing protocol object
00341   //Doc:Desc used by default
00342   //Doc:Return A pointer to the default routing object
00343 
00344   //Doc:Method
00345   static void SetRouting( Routing*);      // Set a new active protocol
00346   //Doc:Desc This method is used to set a new routing protocol for a simulation
00347   //Doc:Arg1 A pointer to the new routing protocol object
00348 
00349   //Doc:Method
00350   static void TopologyChanged(bool);
00351     //Doc:Desc Notify the routing object that topology has changed.
00352     //Doc:Desc Will call the re-initializatoin for each  node.
00353     //Doc:Arg1  True if node or interface UP, false if DOWN
00354 
00355 public:
00356   Node*  node;                                   // Node to which it's attached
00357 
00358 private:
00359   static Routing* defaultRouting;                // Points to active protocol
00360 };
00361 
00362 
00363 /*-------- Routing Overhaul -1  -- SDR -----------*/
00364 
00365 /* Destination IP prefix ?? can be optimized using a hash func.?? */
00366 
00367 
00368 class rt_key_t {
00369  public:
00370         rt_key_t():addr(0), count(0) {}
00371         rt_key_t(IPAddr_t addr_):addr(addr_), count(32) {}
00372         rt_key_t(IPAddr_t addr_, unsigned int count_):
00373                 addr(addr_), count(count_) {}
00374  public:
00375         IPAddr_t addr;
00376         unsigned int count; // The key is in addr/count format.
00377 };
00378 
00379 struct ltrt_key_t
00380 {
00381 #ifndef WIN32
00382         bool operator()(const rt_key_t* rk1, const rt_key_t* rk2) 
00383 #else
00384         bool operator()(const rt_key_t* rk1, const rt_key_t* rk2) const
00385 #endif
00386 
00387 
00388         {
00389                 return ( (rk1->addr < rk2->addr) ||
00390                          ((rk1->addr == rk2->addr) &&
00391                           (rk1->count < rk2->count)) );
00392         }
00393 };
00394 
00395 #define RT_BLANK   0x00
00396 #define RT_USABLE  0x01
00397 #define RT_GATEWAY 0x02
00398 #define RT_STATIC  0x80
00399 
00400 
00401 class rt_value_t {
00402  public:
00403         rt_value_t():nexthop(0), iface(NULL), mtu(0), lifetime(0),
00404                 flags(RT_USABLE), maxwin(0), irtt(0){}
00405         rt_value_t(IPAddr_t addr_, Interface* iface_):
00406                 nexthop(addr_), iface(iface_), mtu(0), lifetime(0),
00407                 flags(RT_USABLE), maxwin(0), irtt(0){}
00408         
00409  public:
00410         IPAddr_t nexthop;
00411         Interface* iface;
00412         unsigned int mtu;
00413         unsigned long  lifetime;        
00414         unsigned char flags;
00415         unsigned long  maxwin; /* Window clamp */
00416         unsigned short irtt; /* initial round trip time */
00417 };
00418 
00419 typedef std::list<rt_value_t*> rt_valuelist_t;
00420 typedef std::map<rt_key_t*, rt_valuelist_t*, ltrt_key_t> NewFIB_t;
00421 
00422 class RouteTable { /* Was called FIB earlier */
00423   public:
00424          RouteTable();
00425          ~RouteTable();
00426 
00427          /* Called only from policy processes (application-routing here) */
00428          void AddRoute(rt_key_t*, rt_value_t*, bool aggr=false);
00429          void DelRoute(rt_key_t* , bool aggr=false);
00430          void Flush(void); /* Empties the routing table */
00431          void Dump(void);  /* Dump the entries of the FIB */
00432          int Size(void);  /* return the size of the FIB */
00433 
00434          /* Called during forwarding , returns a list */
00435          rt_valuelist_t* LookupRoute(rt_key_t* key, bool aggr=false); 
00436 
00437   public:
00438          NewFIB_t fib;
00439 };
00440 
00441 /*-------- Routing Overhaul -1  -- SDR -----------*/
00442 
00443 #endif
00444 
00445 

Generated on Wed Aug 27 16:17:14 2008 for Georgia Tech Network Simulator (GTNetS) by  doxygen 1.3.9.1