00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright 2007 University of Washington 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Authors: Craig Dowell (craigdo@ee.washington.edu) 00019 * Tom Henderson (tomhend@u.washington.edu) 00020 */ 00021 00022 #ifndef GLOBAL_ROUTE_MANAGER_IMPL_H 00023 #define GLOBAL_ROUTE_MANAGER_IMPL_H 00024 00025 #include <stdint.h> 00026 #include <list> 00027 #include <queue> 00028 #include <map> 00029 #include "ns3/object.h" 00030 #include "ns3/ptr.h" 00031 #include "ns3/ipv4-address.h" 00032 #include "ns3/node-container.h" 00033 #include "global-router-interface.h" 00034 00035 namespace ns3 { 00036 00037 const uint32_t SPF_INFINITY = 0xffffffff; 00038 00039 class CandidateQueue; 00040 class Ipv4GlobalRouting; 00041 00042 /** 00043 * @brief Vertex used in shortest path first (SPF) computations. See RFC 2328, 00044 * Section 16. 00045 * 00046 * Each router in the simulation is associated with an SPFVertex object. When 00047 * calculating routes, each of these routers is, in turn, chosen as the "root" 00048 * of the calculation and routes to all of the other routers are eventually 00049 * saved in the routing tables of each of the chosen nodes. Each of these 00050 * routers in the calculation has an associated SPFVertex. 00051 * 00052 * The "Root" vertex is the SPFVertex representing the router that is having 00053 * its routing tables set. The SPFVertex objects representing other routers 00054 * or networks in the simulation are arranged in the SPF tree. It is this 00055 * tree that represents the Shortest Paths to the other networks. 00056 * 00057 * Each SPFVertex has a pointer to the Global Router Link State Advertisement 00058 * (LSA) that its underlying router has exported. Within these LSAs are 00059 * Global Router Link Records that describe the point to point links from the 00060 * underlying router to other nodes (represented by other SPFVertex objects) 00061 * in the simulation topology. The combination of the arrangement of the 00062 * SPFVertex objects in the SPF tree, along with the details of the link 00063 * records that connect them provide the information required to construct the 00064 * required routes. 00065 */ 00066 class SPFVertex 00067 { 00068 public: 00069 /** 00070 * @brief Enumeration of the possible types of SPFVertex objects. 00071 * @internal 00072 * 00073 * Currently we use VertexRouter to identify objects that represent a router 00074 * in the simulation topology, and VertexNetwork to identify objects that 00075 * represent a network. 00076 */ 00077 enum VertexType { 00078 VertexUnknown = 0, /**< Uninitialized Link Record */ 00079 VertexRouter, /**< Vertex representing a router in the topology */ 00080 VertexNetwork /**< Vertex representing a network in the topology */ 00081 }; 00082 00083 /** 00084 * @brief Construct an empty ("uninitialized") SPFVertex (Shortest Path First 00085 * Vertex). 00086 * @internal 00087 * 00088 * The Vertex Type is set to VertexUnknown, the Vertex ID is set to 00089 * 255.255.255.255, and the distance from root is set to infinity 00090 * (UINT32_MAX). The referenced Link State Advertisement (LSA) is set to 00091 * null as is the parent SPFVertex. The outgoing interface index is set to 00092 * infinity, the next hop address is set to 0.0.0.0 and the list of children 00093 * of the SPFVertex is initialized to empty. 00094 * 00095 * @see VertexType 00096 */ 00097 SPFVertex(); 00098 00099 /** 00100 * @brief Construct an initialized SPFVertex (Shortest Path First Vertex). 00101 * @internal 00102 * 00103 * The Vertex Type is initialized to VertexRouter and the Vertex ID is found 00104 * from the Link State ID of the Link State Advertisement (LSA) passed as a 00105 * parameter. The Link State ID is set to the Router ID of the advertising 00106 * router. The referenced LSA (m_lsa) is set to the given LSA. Other than 00107 * these members, initialization is as in the default constructor. 00108 * of the SPFVertex is initialized to empty. 00109 * 00110 * @see SPFVertex::SPFVertex () 00111 * @see VertexType 00112 * @see GlobalRoutingLSA 00113 * @param lsa The Link State Advertisement used for finding initial values. 00114 */ 00115 SPFVertex(GlobalRoutingLSA* lsa); 00116 00117 /** 00118 * @brief Destroy an SPFVertex (Shortest Path First Vertex). 00119 * @internal 00120 * 00121 * The children vertices of the SPFVertex are recursively deleted. 00122 * 00123 * @see SPFVertex::SPFVertex () 00124 */ 00125 ~SPFVertex(); 00126 00127 /** 00128 * @brief Get the Vertex Type field of a SPFVertex object. 00129 * @internal 00130 * 00131 * The Vertex Type describes the kind of simulation object a given SPFVertex 00132 * represents. 00133 * 00134 * @see VertexType 00135 * @returns The VertexType of the current SPFVertex object. 00136 */ 00137 VertexType GetVertexType (void) const; 00138 00139 /** 00140 * @brief Set the Vertex Type field of a SPFVertex object. 00141 * @internal 00142 * 00143 * The Vertex Type describes the kind of simulation object a given SPFVertex 00144 * represents. 00145 * 00146 * @see VertexType 00147 * @param type The new VertexType for the current SPFVertex object. 00148 */ 00149 void SetVertexType (VertexType type); 00150 00151 /** 00152 * @brief Get the Vertex ID field of a SPFVertex object. 00153 * @internal 00154 * 00155 * The Vertex ID uniquely identifies the simulation object a given SPFVertex 00156 * represents. Typically, this is the Router ID for SPFVertex objects 00157 * representing routers, and comes from the Link State Advertisement of a 00158 * router aggregated to a node in the simulation. These IDs are allocated 00159 * automatically by the routing environment and look like IP addresses 00160 * beginning at 0.0.0.0 and monotonically increasing as new routers are 00161 * instantiated. 00162 * 00163 * @returns The Ipv4Address Vertex ID of the current SPFVertex object. 00164 */ 00165 Ipv4Address GetVertexId (void) const; 00166 00167 /** 00168 * @brief Set the Vertex ID field of a SPFVertex object. 00169 * @internal 00170 * 00171 * The Vertex ID uniquely identifies the simulation object a given SPFVertex 00172 * represents. Typically, this is the Router ID for SPFVertex objects 00173 * representing routers, and comes from the Link State Advertisement of a 00174 * router aggregated to a node in the simulation. These IDs are allocated 00175 * automatically by the routing environment and look like IP addresses 00176 * beginning at 0.0.0.0 and monotonically increase as new routers are 00177 * instantiated. This method is an explicit override of the automatically 00178 * generated value. 00179 * 00180 * @param id The new Ipv4Address Vertex ID for the current SPFVertex object. 00181 */ 00182 void SetVertexId (Ipv4Address id); 00183 00184 /** 00185 * @brief Get the Global Router Link State Advertisement returned by the 00186 * Global Router represented by this SPFVertex during the route discovery 00187 * process. 00188 * @internal 00189 * 00190 * @see GlobalRouter 00191 * @see GlobalRoutingLSA 00192 * @see GlobalRouter::DiscoverLSAs () 00193 * @returns A pointer to the GlobalRoutingLSA found by the router represented 00194 * by this SPFVertex object. 00195 */ 00196 GlobalRoutingLSA* GetLSA (void) const; 00197 00198 /** 00199 * @brief Set the Global Router Link State Advertisement returned by the 00200 * Global Router represented by this SPFVertex during the route discovery 00201 * process. 00202 * @internal 00203 * 00204 * @see SPFVertex::GetLSA () 00205 * @see GlobalRouter 00206 * @see GlobalRoutingLSA 00207 * @see GlobalRouter::DiscoverLSAs () 00208 * @warning Ownership of the LSA is transferred to the "this" SPFVertex. You 00209 * must not delete the LSA after calling this method. 00210 * @param lsa A pointer to the GlobalRoutingLSA. 00211 */ 00212 void SetLSA (GlobalRoutingLSA* lsa); 00213 00214 /** 00215 * @brief Get the distance from the root vertex to "this" SPFVertex object. 00216 * @internal 00217 * 00218 * Each router in the simulation is associated with an SPFVertex object. When 00219 * calculating routes, each of these routers is, in turn, chosen as the "root" 00220 * of the calculation and routes to all of the other routers are eventually 00221 * saved in the routing tables of each of the chosen nodes. Each of these 00222 * routers in the calculation has an associated SPFVertex. 00223 * 00224 * The "Root" vertex is then the SPFVertex representing the router that is 00225 * having its routing tables set. The "this" SPFVertex is the vertex to which 00226 * a route is being calculated from the root. The distance from the root that 00227 * we're asking for is the number of hops from the root vertex to the vertex 00228 * in question. 00229 * 00230 * The distance is calculated during route discovery and is stored in a 00231 * member variable. This method simply fetches that value. 00232 * 00233 * @returns The distance, in hops, from the root SPFVertex to "this" SPFVertex. 00234 */ 00235 uint32_t GetDistanceFromRoot (void) const; 00236 00237 /** 00238 * @brief Set the distance from the root vertex to "this" SPFVertex object. 00239 * @internal 00240 * 00241 * Each router in the simulation is associated with an SPFVertex object. When 00242 * calculating routes, each of these routers is, in turn, chosen as the "root" 00243 * of the calculation and routes to all of the other routers are eventually 00244 * saved in the routing tables of each of the chosen nodes. Each of these 00245 * routers in the calculation has an associated SPFVertex. 00246 * 00247 * The "Root" vertex is then the SPFVertex representing the router that is 00248 * having its routing tables set. The "this" SPFVertex is the vertex to which 00249 * a route is being calculated from the root. The distance from the root that 00250 * we're asking for is the number of hops from the root vertex to the vertex 00251 * in question. 00252 * 00253 * @param distance The distance, in hops, from the root SPFVertex to "this" 00254 * SPFVertex. 00255 */ 00256 void SetDistanceFromRoot (uint32_t distance); 00257 00258 /** 00259 * @brief Get the interface ID that should be used to begin forwarding packets 00260 * from the root SPFVertex to "this" SPFVertex. 00261 * @internal 00262 * 00263 * Each router node in the simulation is associated with an SPFVertex object. 00264 * When calculating routes, each of these routers is, in turn, chosen as the 00265 * "root" of the calculation and routes to all of the other routers are 00266 * eventually saved in the routing tables of each of the chosen nodes. 00267 * 00268 * The "Root" vertex is then the SPFVertex representing the router that is 00269 * having its routing tables set. The "this" SPFVertex is the vertex that 00270 * represents the host or network to which a route is being calculated from 00271 * the root. The outgoing interface that we're asking for is the interface 00272 * index on the root node that should be used to start packets along the 00273 * path to "this" vertex. 00274 * 00275 * When initializing the root SPFVertex, the interface ID is determined by 00276 * examining the Global Router Link Records of the Link State Advertisement 00277 * generated by the root node's GlobalRouter. These interfaces are used to 00278 * forward packets off of the root's network down those links. As other 00279 * vertices are discovered which are further away from the root, they will 00280 * be accessible down one of the paths begun by a Global Router Link Record. 00281 * 00282 * To forward packets to these hosts or networks, the root node must begin 00283 * the forwarding process by sending the packets to the interface of that 00284 * first hop. This means that the first hop address and interface ID must 00285 * be the same for all downstream SPFVertices. We call this "inheriting" 00286 * the interface and next hop. 00287 * 00288 * In this method, the root node is asking, "which of my local interfaces 00289 * should I use to get a packet to the network or host represented by 'this' 00290 * SPFVertex." 00291 * 00292 * @see GlobalRouter 00293 * @see GlobalRoutingLSA 00294 * @see GlobalRoutingLinkRecord 00295 * @returns The interface index to use when forwarding packets to the host 00296 * or network represented by "this" SPFVertex. 00297 */ 00298 uint32_t GetOutgoingTypeId (void) const; 00299 00300 /** 00301 * @brief Set the interface ID that should be used to begin forwarding packets 00302 * from the root SPFVertex to "this" SPFVertex. 00303 * @internal 00304 * 00305 * Each router node in the simulation is associated with an SPFVertex object. 00306 * When calculating routes, each of these routers is, in turn, chosen as the 00307 * "root" of the calculation and routes to all of the other routers are 00308 * eventually saved in the routing tables of each of the chosen nodes. 00309 * 00310 * The "Root" vertex is then the SPFVertex representing the router that is 00311 * having its routing tables set. The "this" SPFVertex is the vertex that 00312 * represents the host or network to which a route is being calculated from 00313 * the root. The outgoing interface that we're asking for is the interface 00314 * index on the root node that should be used to start packets along the 00315 * path to "this" vertex. 00316 * 00317 * When initializing the root SPFVertex, the interface ID is determined by 00318 * examining the Global Router Link Records of the Link State Advertisement 00319 * generated by the root node's GlobalRouter. These interfaces are used to 00320 * forward packets off of the root's network down those links. As other 00321 * vertices are discovered which are further away from the root, they will 00322 * be accessible down one of the paths begun by a Global Router Link Record. 00323 * 00324 * To forward packets to these hosts or networks, the root node must begin 00325 * the forwarding process by sending the packets to the interface of that 00326 * first hop. This means that the first hop address and interface ID must 00327 * be the same for all downstream SPFVertices. We call this "inheriting" 00328 * the interface and next hop. 00329 * 00330 * In this method, we are letting the root node know which of its local 00331 * interfaces it should use to get a packet to the network or host represented 00332 * by "this" SPFVertex. 00333 * 00334 * @see GlobalRouter 00335 * @see GlobalRoutingLSA 00336 * @see GlobalRoutingLinkRecord 00337 * @param id The interface index to use when forwarding packets to the host or 00338 * network represented by "this" SPFVertex. 00339 */ 00340 void SetOutgoingTypeId (uint32_t id); 00341 00342 /** 00343 * @brief Get the IP address that should be used to begin forwarding packets 00344 * from the root SPFVertex to "this" SPFVertex. 00345 * @internal 00346 * 00347 * Each router node in the simulation is associated with an SPFVertex object. 00348 * When calculating routes, each of these routers is, in turn, chosen as the 00349 * "root" of the calculation and routes to all of the other routers are 00350 * eventually saved in the routing tables of each of the chosen nodes. 00351 * 00352 * The "Root" vertex is then the SPFVertex representing the router that is 00353 * having its routing tables set. The "this" SPFVertex is the vertex that 00354 * represents the host or network to which a route is being calculated from 00355 * the root. The IP address that we're asking for is the address on the 00356 * remote side of a link off of the root node that should be used as the 00357 * destination for packets along the path to "this" vertex. 00358 * 00359 * When initializing the root SPFVertex, the IP address used when forwarding 00360 * packets is determined by examining the Global Router Link Records of the 00361 * Link State Advertisement generated by the root node's GlobalRouter. This 00362 * address is used to forward packets off of the root's network down those 00363 * links. As other vertices / nodes are discovered which are further away 00364 * from the root, they will be accessible down one of the paths via a link 00365 * described by one of these Global Router Link Records. 00366 * 00367 * To forward packets to these hosts or networks, the root node must begin 00368 * the forwarding process by sending the packets to a first hop router down 00369 * an interface. This means that the first hop address and interface ID must 00370 * be the same for all downstream SPFVertices. We call this "inheriting" 00371 * the interface and next hop. 00372 * 00373 * In this method, the root node is asking, "which router should I send a 00374 * packet to in order to get that packet to the network or host represented 00375 * by 'this' SPFVertex." 00376 * 00377 * @see GlobalRouter 00378 * @see GlobalRoutingLSA 00379 * @see GlobalRoutingLinkRecord 00380 * @returns The IP address to use when forwarding packets to the host 00381 * or network represented by "this" SPFVertex. 00382 */ 00383 Ipv4Address GetNextHop (void) const; 00384 00385 /** 00386 * @brief Set the IP address that should be used to begin forwarding packets 00387 * from the root SPFVertex to "this" SPFVertex. 00388 * @internal 00389 * 00390 * Each router node in the simulation is associated with an SPFVertex object. 00391 * When calculating routes, each of these routers is, in turn, chosen as the 00392 * "root" of the calculation and routes to all of the other routers are 00393 * eventually saved in the routing tables of each of the chosen nodes. 00394 * 00395 * The "Root" vertex is then the SPFVertex representing the router that is 00396 * having its routing tables set. The "this" SPFVertex is the vertex that 00397 * represents the host or network to which a route is being calculated from 00398 * the root. The IP address that we're asking for is the address on the 00399 * remote side of a link off of the root node that should be used as the 00400 * destination for packets along the path to "this" vertex. 00401 * 00402 * When initializing the root SPFVertex, the IP address used when forwarding 00403 * packets is determined by examining the Global Router Link Records of the 00404 * Link State Advertisement generated by the root node's GlobalRouter. This 00405 * address is used to forward packets off of the root's network down those 00406 * links. As other vertices / nodes are discovered which are further away 00407 * from the root, they will be accessible down one of the paths via a link 00408 * described by one of these Global Router Link Records. 00409 * 00410 * To forward packets to these hosts or networks, the root node must begin 00411 * the forwarding process by sending the packets to a first hop router down 00412 * an interface. This means that the first hop address and interface ID must 00413 * be the same for all downstream SPFVertices. We call this "inheriting" 00414 * the interface and next hop. 00415 * 00416 * In this method we are telling the root node which router it should send 00417 * should I send a packet to in order to get that packet to the network or 00418 * host represented by 'this' SPFVertex." 00419 * 00420 * @see GlobalRouter 00421 * @see GlobalRoutingLSA 00422 * @see GlobalRoutingLinkRecord 00423 * @param nextHop The IP address to use when forwarding packets to the host 00424 * or network represented by "this" SPFVertex. 00425 */ 00426 void SetNextHop (Ipv4Address nextHop); 00427 00428 /** 00429 * @brief Get a pointer to the SPFVector that is the parent of "this" 00430 * SPFVertex. 00431 * @internal 00432 * 00433 * Each router node in the simulation is associated with an SPFVertex object. 00434 * When calculating routes, each of these routers is, in turn, chosen as the 00435 * "root" of the calculation and routes to all of the other routers are 00436 * eventually saved in the routing tables of each of the chosen nodes. 00437 * 00438 * The "Root" vertex is then the SPFVertex representing the router that is 00439 * having its routing tables set and is the root of the SPF tree. 00440 * 00441 * This method returns a pointer to the parent node of "this" SPFVertex 00442 * (both of which reside in that SPF tree). 00443 * 00444 * @returns A pointer to the SPFVertex that is the parent of "this" SPFVertex 00445 * in the SPF tree. 00446 */ 00447 SPFVertex* GetParent (void) const; 00448 00449 /** 00450 * @brief Set the pointer to the SPFVector that is the parent of "this" 00451 * SPFVertex. 00452 * @internal 00453 * 00454 * Each router node in the simulation is associated with an SPFVertex object. 00455 * When calculating routes, each of these routers is, in turn, chosen as the 00456 * "root" of the calculation and routes to all of the other routers are 00457 * eventually saved in the routing tables of each of the chosen nodes. 00458 * 00459 * The "Root" vertex is then the SPFVertex representing the router that is 00460 * having its routing tables set and is the root of the SPF tree. 00461 * 00462 * This method sets the parent pointer of "this" SPFVertex (both of which 00463 * reside in that SPF tree). 00464 * 00465 * @param parent A pointer to the SPFVertex that is the parent of "this" 00466 * SPFVertex* in the SPF tree. 00467 */ 00468 void SetParent (SPFVertex* parent); 00469 00470 /** 00471 * @brief Get the number of children of "this" SPFVertex. 00472 * @internal 00473 * 00474 * Each router node in the simulation is associated with an SPFVertex object. 00475 * When calculating routes, each of these routers is, in turn, chosen as the 00476 * "root" of the calculation and routes to all of the other routers are 00477 * eventually saved in the routing tables of each of the chosen nodes. 00478 * 00479 * The "Root" vertex is then the SPFVertex representing the router that is 00480 * having its routing tables set and is the root of the SPF tree. Each vertex 00481 * in the SPF tree can have a number of children that represent host or 00482 * network routes available via that vertex. 00483 * 00484 * This method returns the number of children of "this" SPFVertex (which 00485 * reside in the SPF tree). 00486 * 00487 * @returns The number of children of "this" SPFVertex (which reside in the 00488 * SPF tree). 00489 */ 00490 uint32_t GetNChildren (void) const; 00491 00492 /** 00493 * @brief Get a borrowed SPFVertex pointer to the specified child of "this" 00494 * SPFVertex. 00495 * @internal 00496 * 00497 * Each router node in the simulation is associated with an SPFVertex object. 00498 * When calculating routes, each of these routers is, in turn, chosen as the 00499 * "root" of the calculation and routes to all of the other routers are 00500 * eventually saved in the routing tables of each of the chosen nodes. 00501 * 00502 * The "Root" vertex is then the SPFVertex representing the router that is 00503 * having its routing tables set and is the root of the SPF tree. Each vertex 00504 * in the SPF tree can have a number of children that represent host or 00505 * network routes available via that vertex. 00506 * 00507 * This method the number of children of "this" SPFVertex (which reside in 00508 * the SPF tree. 00509 * 00510 * @see SPFVertex::GetNChildren 00511 * @param n The index (from 0 to the number of children minus 1) of the 00512 * child SPFVertex to return. 00513 * @warning The pointer returned by GetChild () is a borrowed pointer. You 00514 * do not have any ownership of the underlying object and must not delete 00515 * that object. 00516 * @returns A pointer to the specified child SPFVertex (which resides in the 00517 * SPF tree). 00518 */ 00519 SPFVertex* GetChild (uint32_t n) const; 00520 00521 /** 00522 * @brief Get a borrowed SPFVertex pointer to the specified child of "this" 00523 * SPFVertex. 00524 * @internal 00525 * 00526 * Each router node in the simulation is associated with an SPFVertex object. 00527 * When calculating routes, each of these routers is, in turn, chosen as the 00528 * "root" of the calculation and routes to all of the other routers are 00529 * eventually saved in the routing tables of each of the chosen nodes. 00530 * 00531 * The "Root" vertex is then the SPFVertex representing the router that is 00532 * having its routing tables set and is the root of the SPF tree. Each vertex 00533 * in the SPF tree can have a number of children that represent host or 00534 * network routes available via that vertex. 00535 * 00536 * This method the number of children of "this" SPFVertex (which reside in 00537 * the SPF tree. 00538 * 00539 * @see SPFVertex::GetNChildren 00540 * @warning Ownership of the pointer added to the children of "this" 00541 * SPFVertex is transferred to the "this" SPFVertex. You must not delete the 00542 * (now) child SPFVertex after calling this method. 00543 * @param child A pointer to the SPFVertex (which resides in the SPF tree) to 00544 * be added to the list of children of "this" SPFVertex. 00545 * @returns The number of children of "this" SPFVertex after the addition of 00546 * the new child. 00547 */ 00548 uint32_t AddChild (SPFVertex* child); 00549 00550 /** 00551 * @brief Set the value of the VertexProcessed flag 00552 * 00553 * Flag to note whether vertex has been processed in stage two of 00554 * SPF computation 00555 * @param value boolean value to set the flag 00556 */ 00557 void SetVertexProcessed (bool value); 00558 00559 /** 00560 * @brief Check the value of the VertexProcessed flag 00561 * 00562 * Flag to note whether vertex has been processed in stage two of 00563 * SPF computation 00564 * @returns value of underlying flag 00565 */ 00566 bool IsVertexProcessed (void) const; 00567 private: 00568 VertexType m_vertexType; 00569 Ipv4Address m_vertexId; 00570 GlobalRoutingLSA* m_lsa; 00571 uint32_t m_distanceFromRoot; 00572 uint32_t m_rootOif; 00573 Ipv4Address m_nextHop; 00574 SPFVertex* m_parent; 00575 typedef std::list<SPFVertex*> ListOfSPFVertex_t; 00576 ListOfSPFVertex_t m_children; 00577 bool m_vertexProcessed; 00578 00579 /** 00580 * @brief The SPFVertex copy construction is disallowed. There's no need for 00581 * it and a compiler provided shallow copy would be wrong. 00582 */ 00583 SPFVertex (SPFVertex& v); 00584 00585 /** 00586 * @brief The SPFVertex copy assignment operator is disallowed. There's no 00587 * need for it and a compiler provided shallow copy would be wrong. 00588 */ 00589 SPFVertex& operator= (SPFVertex& v); 00590 }; 00591 00592 /** 00593 * @brief The Link State DataBase (LSDB) of the Global Route Manager. 00594 * 00595 * Each node in the simulation participating in global routing has a 00596 * GlobalRouter interface. The primary job of this interface is to export 00597 * Global Router Link State Advertisements (LSAs). These advertisements in 00598 * turn contain a number of Global Router Link Records that describe the 00599 * point to point links from the underlying node to other nodes (that will 00600 * also export their own LSAs. 00601 * 00602 * This class implements a searchable database of LSAs gathered from every 00603 * router in the simulation. 00604 */ 00605 class GlobalRouteManagerLSDB 00606 { 00607 public: 00608 /** 00609 * @brief Construct an empty Global Router Manager Link State Database. 00610 * @internal 00611 * 00612 * The database map composing the Link State Database is initialized in 00613 * this constructor. 00614 */ 00615 GlobalRouteManagerLSDB (); 00616 00617 /** 00618 * @brief Destroy an empty Global Router Manager Link State Database. 00619 * @internal 00620 * 00621 * The database map is walked and all of the Link State Advertisements stored 00622 * in the database are freed; then the database map itself is clear ()ed to 00623 * release any remaining resources. 00624 */ 00625 ~GlobalRouteManagerLSDB (); 00626 00627 /** 00628 * @brief Insert an IP address / Link State Advertisement pair into the Link 00629 * State Database. 00630 * @internal 00631 * 00632 * The IPV4 address and the GlobalRoutingLSA given as parameters are converted 00633 * to an STL pair and are inserted into the database map. 00634 * 00635 * @see GlobalRoutingLSA 00636 * @see Ipv4Address 00637 * @param addr The IP address associated with the LSA. Typically the Router 00638 * ID. 00639 * @param lsa A pointer to the Link State Advertisement for the router. 00640 */ 00641 void Insert(Ipv4Address addr, GlobalRoutingLSA* lsa); 00642 00643 /** 00644 * @brief Look up the Link State Advertisement associated with the given 00645 * link state ID (address). 00646 * @internal 00647 * 00648 * The database map is searched for the given IPV4 address and corresponding 00649 * GlobalRoutingLSA is returned. 00650 * 00651 * @see GlobalRoutingLSA 00652 * @see Ipv4Address 00653 * @param addr The IP address associated with the LSA. Typically the Router 00654 * ID. 00655 * @returns A pointer to the Link State Advertisement for the router specified 00656 * by the IP address addr. 00657 */ 00658 GlobalRoutingLSA* GetLSA (Ipv4Address addr) const; 00659 /** 00660 * @brief Look up the Link State Advertisement associated with the given 00661 * link state ID (address). This is a variation of the GetLSA call 00662 * to allow the LSA to be found by matching addr with the LinkData field 00663 * of the TransitNetwork link record. 00664 * @internal 00665 * 00666 * @see GetLSA 00667 * @param addr The IP address associated with the LSA. Typically the Router 00668 * @returns A pointer to the Link State Advertisement for the router specified 00669 * by the IP address addr. 00670 * ID. 00671 */ 00672 GlobalRoutingLSA* GetLSAByLinkData (Ipv4Address addr) const; 00673 00674 /** 00675 * @brief Set all LSA flags to an initialized state, for SPF computation 00676 * @internal 00677 * 00678 * This function walks the database and resets the status flags of all of the 00679 * contained Link State Advertisements to LSA_SPF_NOT_EXPLORED. This is done 00680 * prior to each SPF calculation to reset the state of the SPFVertex structures 00681 * that will reference the LSAs during the calculation. 00682 * 00683 * @see GlobalRoutingLSA 00684 * @see SPFVertex 00685 */ 00686 void Initialize (); 00687 00688 private: 00689 typedef std::map<Ipv4Address, GlobalRoutingLSA*> LSDBMap_t; 00690 typedef std::pair<Ipv4Address, GlobalRoutingLSA*> LSDBPair_t; 00691 00692 LSDBMap_t m_database; 00693 /** 00694 * @brief GlobalRouteManagerLSDB copy construction is disallowed. There's no 00695 * need for it and a compiler provided shallow copy would be wrong. 00696 */ 00697 GlobalRouteManagerLSDB (GlobalRouteManagerLSDB& lsdb); 00698 00699 /** 00700 * @brief The SPFVertex copy assignment operator is disallowed. There's no 00701 * need for it and a compiler provided shallow copy would be wrong. 00702 */ 00703 GlobalRouteManagerLSDB& operator= (GlobalRouteManagerLSDB& lsdb); 00704 }; 00705 00706 /** 00707 * @brief A global router implementation. 00708 * 00709 * This singleton object can query interface each node in the system 00710 * for a GlobalRouter interface. For those nodes, it fetches one or 00711 * more Link State Advertisements and stores them in a local database. 00712 * Then, it can compute shortest paths on a per-node basis to all routers, 00713 * and finally configure each of the node's forwarding tables. 00714 * 00715 * The design is guided by OSPFv2 RFC 2328 section 16.1.1 and quagga ospfd. 00716 */ 00717 class GlobalRouteManagerImpl 00718 { 00719 public: 00720 GlobalRouteManagerImpl (); 00721 virtual ~GlobalRouteManagerImpl (); 00722 /** 00723 * @brief Delete all static routes on all nodes that have a 00724 * GlobalRouterInterface 00725 * 00726 * TODO: separate manually assigned static routes from static routes that 00727 * the global routing code injects, and only delete the latter 00728 * @internal 00729 * 00730 */ 00731 virtual void DeleteGlobalRoutes (); 00732 /** 00733 * @brief Select which nodes in the system are to be router nodes and 00734 * aggregate the appropriate interfaces onto those nodes. 00735 * @internal 00736 * 00737 */ 00738 virtual void SelectRouterNodes (); 00739 00740 /** 00741 * @brief Select which nodes in the system are to be router nodes and 00742 * aggregate the appropriate interfaces onto those nodes. 00743 * @internal 00744 * 00745 */ 00746 virtual void SelectRouterNodes (NodeContainer c); 00747 00748 /** 00749 * @brief Build the routing database by gathering Link State Advertisements 00750 * from each node exporting a GlobalRouter interface. 00751 * @internal 00752 */ 00753 virtual void BuildGlobalRoutingDatabase (); 00754 00755 /** 00756 * @brief Compute routes using a Dijkstra SPF computation and populate 00757 * per-node forwarding tables 00758 * @internal 00759 */ 00760 virtual void InitializeRoutes (); 00761 00762 /** 00763 * @brief Debugging routine; allow client code to supply a pre-built LSDB 00764 * @internal 00765 */ 00766 void DebugUseLsdb (GlobalRouteManagerLSDB*); 00767 00768 /** 00769 * @brief Debugging routine; call the core SPF from the unit tests 00770 * @internal 00771 */ 00772 void DebugSPFCalculate (Ipv4Address root); 00773 00774 private: 00775 /** 00776 * @brief GlobalRouteManagerImpl copy construction is disallowed. 00777 * There's no need for it and a compiler provided shallow copy would be 00778 * wrong. 00779 */ 00780 GlobalRouteManagerImpl (GlobalRouteManagerImpl& srmi); 00781 00782 /** 00783 * @brief Global Route Manager Implementation assignment operator is 00784 * disallowed. There's no need for it and a compiler provided shallow copy 00785 * would be hopelessly wrong. 00786 */ 00787 GlobalRouteManagerImpl& operator= (GlobalRouteManagerImpl& srmi); 00788 00789 SPFVertex* m_spfroot; 00790 GlobalRouteManagerLSDB* m_lsdb; 00791 void SPFCalculate (Ipv4Address root); 00792 void SPFProcessStubs (SPFVertex* v); 00793 void SPFNext (SPFVertex*, CandidateQueue&); 00794 int SPFNexthopCalculation (SPFVertex* v, SPFVertex* w, 00795 GlobalRoutingLinkRecord* l, uint32_t distance); 00796 void SPFVertexAddParent (SPFVertex* v); 00797 GlobalRoutingLinkRecord* SPFGetNextLink (SPFVertex* v, SPFVertex* w, 00798 GlobalRoutingLinkRecord* prev_link); 00799 void SPFIntraAddRouter (SPFVertex* v); 00800 void SPFIntraAddTransit (SPFVertex* v); 00801 void SPFIntraAddStub (GlobalRoutingLinkRecord *l, SPFVertex* v); 00802 uint32_t FindOutgoingTypeId (Ipv4Address a, 00803 Ipv4Mask amask = Ipv4Mask("255.255.255.255")); 00804 00805 // Local cache of the Ipv4GlobalRouting objects, indexed by nodeId 00806 typedef std::list< std::pair< uint32_t, Ptr<Ipv4GlobalRouting> > > Ipv4GlobalRoutingList; 00807 void AddGlobalRoutingProtocol (uint32_t nodeId, Ptr<Ipv4GlobalRouting> proto); 00808 Ptr<Ipv4GlobalRouting> GetGlobalRoutingProtocol (uint32_t nodeId); 00809 Ipv4GlobalRoutingList m_routingProtocols; 00810 }; 00811 00812 } // namespace ns3 00813 00814 #endif /* GLOBAL_ROUTE_MANAGER_IMPL_H */