src/internet/model/ipv4-global-routing.h
changeset 10440 1e48ff9185f1
parent 8977 2bd04c7f5010
equal deleted inserted replaced
10439:73bc9e55f9bd 10440:1e48ff9185f1
    67  * \see GlobalRouteManager
    67  * \see GlobalRouteManager
    68  */
    68  */
    69 class Ipv4GlobalRouting : public Ipv4RoutingProtocol
    69 class Ipv4GlobalRouting : public Ipv4RoutingProtocol
    70 {
    70 {
    71 public:
    71 public:
       
    72   /**
       
    73    * \brief Get the type ID.
       
    74    * \return the object TypeId
       
    75    */
    72   static TypeId GetTypeId (void);
    76   static TypeId GetTypeId (void);
    73 /**
    77   /**
    74  * \brief Construct an empty Ipv4GlobalRouting routing protocol,
    78    * \brief Construct an empty Ipv4GlobalRouting routing protocol,
    75  *
    79    *
    76  * The Ipv4GlobalRouting class supports host and network unicast routes.
    80    * The Ipv4GlobalRouting class supports host and network unicast routes.
    77  * This method initializes the lists containing these routes to empty.
    81    * This method initializes the lists containing these routes to empty.
    78  *
    82    *
    79  * \see Ipv4GlobalRouting
    83    * \see Ipv4GlobalRouting
    80  */
    84    */
    81   Ipv4GlobalRouting ();
    85   Ipv4GlobalRouting ();
    82   virtual ~Ipv4GlobalRouting ();
    86   virtual ~Ipv4GlobalRouting ();
    83 
    87 
    84   // These methods inherited from base class
    88   // These methods inherited from base class
    85   virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr);
    89   virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr);
    92   virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
    96   virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
    93   virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
    97   virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
    94   virtual void SetIpv4 (Ptr<Ipv4> ipv4);
    98   virtual void SetIpv4 (Ptr<Ipv4> ipv4);
    95   virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const;
    99   virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const;
    96 
   100 
    97 /**
   101   /**
    98  * \brief Add a host route to the global routing table.
   102    * \brief Add a host route to the global routing table.
    99  *
   103    *
   100  * \param dest The Ipv4Address destination for this route.
   104    * \param dest The Ipv4Address destination for this route.
   101  * \param nextHop The Ipv4Address of the next hop in the route.
   105    * \param nextHop The Ipv4Address of the next hop in the route.
   102  * \param interface The network interface index used to send packets to the
   106    * \param interface The network interface index used to send packets to the
   103  * destination.
   107    * destination.
   104  *
   108    *
   105  * \see Ipv4Address
   109    * \see Ipv4Address
   106  */
   110    */
   107   void AddHostRouteTo (Ipv4Address dest, 
   111   void AddHostRouteTo (Ipv4Address dest, 
   108                        Ipv4Address nextHop, 
   112                        Ipv4Address nextHop, 
   109                        uint32_t interface);
   113                        uint32_t interface);
   110 /**
   114   /**
   111  * \brief Add a host route to the global routing table.
   115    * \brief Add a host route to the global routing table.
   112  *
   116    *
   113  * \param dest The Ipv4Address destination for this route.
   117    * \param dest The Ipv4Address destination for this route.
   114  * \param interface The network interface index used to send packets to the
   118    * \param interface The network interface index used to send packets to the
   115  * destination.
   119    * destination.
   116  *
   120    *
   117  * \see Ipv4Address
   121    * \see Ipv4Address
   118  */
   122    */
   119   void AddHostRouteTo (Ipv4Address dest, 
   123   void AddHostRouteTo (Ipv4Address dest, 
   120                        uint32_t interface);
   124                        uint32_t interface);
   121 
   125 
   122 /**
   126   /**
   123  * \brief Add a network route to the global routing table.
   127    * \brief Add a network route to the global routing table.
   124  *
   128    *
   125  * \param network The Ipv4Address network for this route.
   129    * \param network The Ipv4Address network for this route.
   126  * \param networkMask The Ipv4Mask to extract the network.
   130    * \param networkMask The Ipv4Mask to extract the network.
   127  * \param nextHop The next hop in the route to the destination network.
   131    * \param nextHop The next hop in the route to the destination network.
   128  * \param interface The network interface index used to send packets to the
   132    * \param interface The network interface index used to send packets to the
   129  * destination.
   133    * destination.
   130  *
   134    *
   131  * \see Ipv4Address
   135    * \see Ipv4Address
   132  */
   136    */
   133   void AddNetworkRouteTo (Ipv4Address network, 
   137   void AddNetworkRouteTo (Ipv4Address network, 
   134                           Ipv4Mask networkMask, 
   138                           Ipv4Mask networkMask, 
   135                           Ipv4Address nextHop, 
   139                           Ipv4Address nextHop, 
   136                           uint32_t interface);
   140                           uint32_t interface);
   137 
   141 
   138 /**
   142   /**
   139  * \brief Add a network route to the global routing table.
   143    * \brief Add a network route to the global routing table.
   140  *
   144    *
   141  * \param network The Ipv4Address network for this route.
   145    * \param network The Ipv4Address network for this route.
   142  * \param networkMask The Ipv4Mask to extract the network.
   146    * \param networkMask The Ipv4Mask to extract the network.
   143  * \param interface The network interface index used to send packets to the
   147    * \param interface The network interface index used to send packets to the
   144  * destination.
   148    * destination.
   145  *
   149    *
   146  * \see Ipv4Address
   150    * \see Ipv4Address
   147  */
   151    */
   148   void AddNetworkRouteTo (Ipv4Address network, 
   152   void AddNetworkRouteTo (Ipv4Address network, 
   149                           Ipv4Mask networkMask, 
   153                           Ipv4Mask networkMask, 
   150                           uint32_t interface);
   154                           uint32_t interface);
   151 
   155 
   152 /**
   156   /**
   153  * \brief Add an external route to the global routing table.
   157    * \brief Add an external route to the global routing table.
   154  *
   158    *
   155  * \param network The Ipv4Address network for this route.
   159    * \param network The Ipv4Address network for this route.
   156  * \param networkMask The Ipv4Mask to extract the network.
   160    * \param networkMask The Ipv4Mask to extract the network.
   157  * \param nextHop The next hop Ipv4Address
   161    * \param nextHop The next hop Ipv4Address
   158  * \param interface The network interface index used to send packets to the
   162    * \param interface The network interface index used to send packets to the
   159  * destination.
   163    * destination.
   160  */
   164    */
   161   void AddASExternalRouteTo (Ipv4Address network,
   165   void AddASExternalRouteTo (Ipv4Address network,
   162                              Ipv4Mask networkMask,
   166                              Ipv4Mask networkMask,
   163                              Ipv4Address nextHop,
   167                              Ipv4Address nextHop,
   164                              uint32_t interface);
   168                              uint32_t interface);
   165 
   169 
   166 /**
   170   /**
   167  * \brief Get the number of individual unicast routes that have been added
   171    * \brief Get the number of individual unicast routes that have been added
   168  * to the routing table.
   172    * to the routing table.
   169  *
   173    *
   170  * \warning The default route counts as one of the routes.
   174    * \warning The default route counts as one of the routes.
   171  */
   175    * \returns the number of routes
       
   176    */
   172   uint32_t GetNRoutes (void) const;
   177   uint32_t GetNRoutes (void) const;
   173 
   178 
   174 /**
   179   /**
   175  * \brief Get a route from the global unicast routing table.
   180    * \brief Get a route from the global unicast routing table.
   176  *
   181    *
   177  * Externally, the unicast global routing table appears simply as a table with
   182    * Externally, the unicast global routing table appears simply as a table with
   178  * n entries.  The one subtlety of note is that if a default route has been set
   183    * n entries.  The one subtlety of note is that if a default route has been set
   179  * it will appear as the zeroth entry in the table.  This means that if you
   184    * it will appear as the zeroth entry in the table.  This means that if you
   180  * add only a default route, the table will have one entry that can be accessed
   185    * add only a default route, the table will have one entry that can be accessed
   181  * either by explicitly calling GetDefaultRoute () or by calling GetRoute (0).
   186    * either by explicitly calling GetDefaultRoute () or by calling GetRoute (0).
   182  * 
   187    *
   183  * Similarly, if the default route has been set, calling RemoveRoute (0) will
   188    * Similarly, if the default route has been set, calling RemoveRoute (0) will
   184  * remove the default route.
   189    * remove the default route.
   185  *
   190    *
   186  * \param i The index (into the routing table) of the route to retrieve.  If
   191    * \param i The index (into the routing table) of the route to retrieve.  If
   187  * the default route has been set, it will occupy index zero.
   192    * the default route has been set, it will occupy index zero.
   188  * \return If route is set, a pointer to that Ipv4RoutingTableEntry is returned, otherwise
   193    * \return If route is set, a pointer to that Ipv4RoutingTableEntry is returned, otherwise
   189  * a zero pointer is returned.
   194    * a zero pointer is returned.
   190  *
   195    *
   191  * \see Ipv4RoutingTableEntry
   196    * \see Ipv4RoutingTableEntry
   192  * \see Ipv4GlobalRouting::RemoveRoute
   197    * \see Ipv4GlobalRouting::RemoveRoute
   193  */
   198    */
   194   Ipv4RoutingTableEntry *GetRoute (uint32_t i) const;
   199   Ipv4RoutingTableEntry *GetRoute (uint32_t i) const;
   195 
   200 
   196 /**
   201   /**
   197  * \brief Remove a route from the global unicast routing table.
   202    * \brief Remove a route from the global unicast routing table.
   198  *
   203    *
   199  * Externally, the unicast global routing table appears simply as a table with
   204    * Externally, the unicast global routing table appears simply as a table with
   200  * n entries.  The one subtlety of note is that if a default route has been set
   205    * n entries.  The one subtlety of note is that if a default route has been set
   201  * it will appear as the zeroth entry in the table.  This means that if the
   206    * it will appear as the zeroth entry in the table.  This means that if the
   202  * default route has been set, calling RemoveRoute (0) will remove the
   207    * default route has been set, calling RemoveRoute (0) will remove the
   203  * default route.
   208    * default route.
   204  *
   209    *
   205  * \param i The index (into the routing table) of the route to remove.  If
   210    * \param i The index (into the routing table) of the route to remove.  If
   206  * the default route has been set, it will occupy index zero.
   211    * the default route has been set, it will occupy index zero.
   207  *
   212    *
   208  * \see Ipv4RoutingTableEntry
   213    * \see Ipv4RoutingTableEntry
   209  * \see Ipv4GlobalRouting::GetRoute
   214    * \see Ipv4GlobalRouting::GetRoute
   210  * \see Ipv4GlobalRouting::AddRoute
   215    * \see Ipv4GlobalRouting::AddRoute
   211  */
   216    */
   212   void RemoveRoute (uint32_t i);
   217   void RemoveRoute (uint32_t i);
   213 
   218 
   214  /**
   219   /**
   215   * Assign a fixed random variable stream number to the random variables
   220    * Assign a fixed random variable stream number to the random variables
   216   * used by this model.  Return the number of streams (possibly zero) that
   221    * used by this model.  Return the number of streams (possibly zero) that
   217   * have been assigned.
   222    * have been assigned.
   218   *
   223    *
   219   * \param stream first stream index to use
   224    * \param stream first stream index to use
   220   * \return the number of stream indices assigned by this model
   225    * \return the number of stream indices assigned by this model
   221   */
   226    */
   222   int64_t AssignStreams (int64_t stream);
   227   int64_t AssignStreams (int64_t stream);
   223 
   228 
   224 protected:
   229 protected:
   225   void DoDispose (void);
   230   void DoDispose (void);
   226 
   231 
   230   /// Set to true if this interface should respond to interface events by globallly recomputing routes 
   235   /// Set to true if this interface should respond to interface events by globallly recomputing routes 
   231   bool m_respondToInterfaceEvents;
   236   bool m_respondToInterfaceEvents;
   232   /// A uniform random number generator for randomly routing packets among ECMP 
   237   /// A uniform random number generator for randomly routing packets among ECMP 
   233   Ptr<UniformRandomVariable> m_rand;
   238   Ptr<UniformRandomVariable> m_rand;
   234 
   239 
       
   240   /// container of Ipv4RoutingTableEntry (routes to hosts)
   235   typedef std::list<Ipv4RoutingTableEntry *> HostRoutes;
   241   typedef std::list<Ipv4RoutingTableEntry *> HostRoutes;
       
   242   /// const iterator of container of Ipv4RoutingTableEntry (routes to hosts)
   236   typedef std::list<Ipv4RoutingTableEntry *>::const_iterator HostRoutesCI;
   243   typedef std::list<Ipv4RoutingTableEntry *>::const_iterator HostRoutesCI;
       
   244   /// iterator of container of Ipv4RoutingTableEntry (routes to hosts)
   237   typedef std::list<Ipv4RoutingTableEntry *>::iterator HostRoutesI;
   245   typedef std::list<Ipv4RoutingTableEntry *>::iterator HostRoutesI;
       
   246 
       
   247   /// container of Ipv4RoutingTableEntry (routes to networks)
   238   typedef std::list<Ipv4RoutingTableEntry *> NetworkRoutes;
   248   typedef std::list<Ipv4RoutingTableEntry *> NetworkRoutes;
       
   249   /// const iterator of container of Ipv4RoutingTableEntry (routes to networks)
   239   typedef std::list<Ipv4RoutingTableEntry *>::const_iterator NetworkRoutesCI;
   250   typedef std::list<Ipv4RoutingTableEntry *>::const_iterator NetworkRoutesCI;
       
   251   /// iterator of container of Ipv4RoutingTableEntry (routes to networks)
   240   typedef std::list<Ipv4RoutingTableEntry *>::iterator NetworkRoutesI;
   252   typedef std::list<Ipv4RoutingTableEntry *>::iterator NetworkRoutesI;
       
   253 
       
   254   /// container of Ipv4RoutingTableEntry (routes to external AS)
   241   typedef std::list<Ipv4RoutingTableEntry *> ASExternalRoutes;
   255   typedef std::list<Ipv4RoutingTableEntry *> ASExternalRoutes;
       
   256   /// const iterator of container of Ipv4RoutingTableEntry (routes to external AS)
   242   typedef std::list<Ipv4RoutingTableEntry *>::const_iterator ASExternalRoutesCI;
   257   typedef std::list<Ipv4RoutingTableEntry *>::const_iterator ASExternalRoutesCI;
       
   258   /// iterator of container of Ipv4RoutingTableEntry (routes to external AS)
   243   typedef std::list<Ipv4RoutingTableEntry *>::iterator ASExternalRoutesI;
   259   typedef std::list<Ipv4RoutingTableEntry *>::iterator ASExternalRoutesI;
   244 
   260 
   245   Ptr<Ipv4Route> LookupGlobal (Ipv4Address dest, Ptr<NetDevice> oif = 0);
   261   Ptr<Ipv4Route> LookupGlobal (Ipv4Address dest, Ptr<NetDevice> oif = 0);
   246 
   262 
   247   HostRoutes m_hostRoutes;
   263   HostRoutes m_hostRoutes;             //!< Routes to hosts
   248   NetworkRoutes m_networkRoutes;
   264   NetworkRoutes m_networkRoutes;       //!< Routes to networks
   249   ASExternalRoutes m_ASexternalRoutes; // External routes imported
   265   ASExternalRoutes m_ASexternalRoutes; //!< External routes imported
   250 
   266 
   251   Ptr<Ipv4> m_ipv4;
   267   Ptr<Ipv4> m_ipv4; //!< associated IPv4 instance
   252 };
   268 };
   253 
   269 
   254 } // Namespace ns3
   270 } // Namespace ns3
   255 
   271 
   256 #endif /* IPV4_GLOBAL_ROUTING_H */
   272 #endif /* IPV4_GLOBAL_ROUTING_H */