A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
global-route-manager-impl.h
Go to the documentation of this file.
1/*
2 * Copyright 2007 University of Washington
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Craig Dowell (craigdo@ee.washington.edu)
18 * Tom Henderson (tomhend@u.washington.edu)
19 */
20
21#ifndef GLOBAL_ROUTE_MANAGER_IMPL_H
22#define GLOBAL_ROUTE_MANAGER_IMPL_H
23
25
26#include "ns3/ipv4-address.h"
27#include "ns3/object.h"
28#include "ns3/ptr.h"
29
30#include <list>
31#include <map>
32#include <queue>
33#include <stdint.h>
34#include <vector>
35
36namespace ns3
37{
38
39const uint32_t SPF_INFINITY = 0xffffffff; //!< "infinite" distance between nodes
40
41class CandidateQueue;
43
44/**
45 * \ingroup globalrouting
46 *
47 * @brief Vertex used in shortest path first (SPF) computations. See \RFC{2328},
48 * Section 16.
49 *
50 * Each router in the simulation is associated with an SPFVertex object. When
51 * calculating routes, each of these routers is, in turn, chosen as the "root"
52 * of the calculation and routes to all of the other routers are eventually
53 * saved in the routing tables of each of the chosen nodes. Each of these
54 * routers in the calculation has an associated SPFVertex.
55 *
56 * The "Root" vertex is the SPFVertex representing the router that is having
57 * its routing tables set. The SPFVertex objects representing other routers
58 * or networks in the simulation are arranged in the SPF tree. It is this
59 * tree that represents the Shortest Paths to the other networks.
60 *
61 * Each SPFVertex has a pointer to the Global Router Link State Advertisement
62 * (LSA) that its underlying router has exported. Within these LSAs are
63 * Global Router Link Records that describe the point to point links from the
64 * underlying router to other nodes (represented by other SPFVertex objects)
65 * in the simulation topology. The combination of the arrangement of the
66 * SPFVertex objects in the SPF tree, along with the details of the link
67 * records that connect them provide the information required to construct the
68 * required routes.
69 */
71{
72 public:
73 /**
74 * @brief Enumeration of the possible types of SPFVertex objects.
75 *
76 * Currently we use VertexRouter to identify objects that represent a router
77 * in the simulation topology, and VertexNetwork to identify objects that
78 * represent a network.
79 */
81 {
82 VertexUnknown = 0, /**< Uninitialized Link Record */
83 VertexRouter, /**< Vertex representing a router in the topology */
84 VertexNetwork /**< Vertex representing a network in the topology */
85 };
86
87 /**
88 * @brief Construct an empty ("uninitialized") SPFVertex (Shortest Path First
89 * Vertex).
90 *
91 * The Vertex Type is set to VertexUnknown, the Vertex ID is set to
92 * 255.255.255.255, and the distance from root is set to infinity
93 * (UINT32_MAX). The referenced Link State Advertisement (LSA) is set to
94 * null as is the parent SPFVertex. The outgoing interface index is set to
95 * infinity, the next hop address is set to 0.0.0.0 and the list of children
96 * of the SPFVertex is initialized to empty.
97 *
98 * @see VertexType
99 */
100 SPFVertex();
101
102 /**
103 * @brief Construct an initialized SPFVertex (Shortest Path First Vertex).
104 *
105 * The Vertex Type is initialized to VertexRouter and the Vertex ID is found
106 * from the Link State ID of the Link State Advertisement (LSA) passed as a
107 * parameter. The Link State ID is set to the Router ID of the advertising
108 * router. The referenced LSA (m_lsa) is set to the given LSA. Other than
109 * these members, initialization is as in the default constructor.
110 * of the SPFVertex is initialized to empty.
111 *
112 * @see SPFVertex::SPFVertex ()
113 * @see VertexType
114 * @see GlobalRoutingLSA
115 * @param lsa The Link State Advertisement used for finding initial values.
116 */
118
119 /**
120 * @brief Destroy an SPFVertex (Shortest Path First Vertex).
121 *
122 * The children vertices of the SPFVertex are recursively deleted.
123 *
124 * @see SPFVertex::SPFVertex ()
125 */
126 ~SPFVertex();
127
128 // Delete copy constructor and assignment operator to avoid misuse
129 SPFVertex(const SPFVertex&) = delete;
130 SPFVertex& operator=(const SPFVertex&) = delete;
131
132 /**
133 * @brief Get the Vertex Type field of a SPFVertex object.
134 *
135 * The Vertex Type describes the kind of simulation object a given SPFVertex
136 * represents.
137 *
138 * @see VertexType
139 * @returns The VertexType of the current SPFVertex object.
140 */
142
143 /**
144 * @brief Set the Vertex Type field of a SPFVertex object.
145 *
146 * The Vertex Type describes the kind of simulation object a given SPFVertex
147 * represents.
148 *
149 * @see VertexType
150 * @param type The new VertexType for the current SPFVertex object.
151 */
152 void SetVertexType(VertexType type);
153
154 /**
155 * @brief Get the Vertex ID field of a SPFVertex object.
156 *
157 * The Vertex ID uniquely identifies the simulation object a given SPFVertex
158 * represents. Typically, this is the Router ID for SPFVertex objects
159 * representing routers, and comes from the Link State Advertisement of a
160 * router aggregated to a node in the simulation. These IDs are allocated
161 * automatically by the routing environment and look like IP addresses
162 * beginning at 0.0.0.0 and monotonically increasing as new routers are
163 * instantiated.
164 *
165 * @returns The Ipv4Address Vertex ID of the current SPFVertex object.
166 */
167 Ipv4Address GetVertexId() const;
168
169 /**
170 * @brief Set the Vertex ID field of a SPFVertex object.
171 *
172 * The Vertex ID uniquely identifies the simulation object a given SPFVertex
173 * represents. Typically, this is the Router ID for SPFVertex objects
174 * representing routers, and comes from the Link State Advertisement of a
175 * router aggregated to a node in the simulation. These IDs are allocated
176 * automatically by the routing environment and look like IP addresses
177 * beginning at 0.0.0.0 and monotonically increase as new routers are
178 * instantiated. This method is an explicit override of the automatically
179 * generated value.
180 *
181 * @param id The new Ipv4Address Vertex ID for the current SPFVertex object.
182 */
183 void SetVertexId(Ipv4Address id);
184
185 /**
186 * @brief Get the Global Router Link State Advertisement returned by the
187 * Global Router represented by this SPFVertex during the route discovery
188 * process.
189 *
190 * @see GlobalRouter
191 * @see GlobalRoutingLSA
192 * @see GlobalRouter::DiscoverLSAs ()
193 * @returns A pointer to the GlobalRoutingLSA found by the router represented
194 * by this SPFVertex object.
195 */
196 GlobalRoutingLSA* GetLSA() const;
197
198 /**
199 * @brief Set the Global Router Link State Advertisement returned by the
200 * Global Router represented by this SPFVertex during the route discovery
201 * process.
202 *
203 * @see SPFVertex::GetLSA ()
204 * @see GlobalRouter
205 * @see GlobalRoutingLSA
206 * @see GlobalRouter::DiscoverLSAs ()
207 * @warning Ownership of the LSA is transferred to the "this" SPFVertex. You
208 * must not delete the LSA after calling this method.
209 * @param lsa A pointer to the GlobalRoutingLSA.
210 */
211 void SetLSA(GlobalRoutingLSA* lsa);
212
213 /**
214 * @brief Get the distance from the root vertex to "this" SPFVertex object.
215 *
216 * Each router in the simulation is associated with an SPFVertex object. When
217 * calculating routes, each of these routers is, in turn, chosen as the "root"
218 * of the calculation and routes to all of the other routers are eventually
219 * saved in the routing tables of each of the chosen nodes. Each of these
220 * routers in the calculation has an associated SPFVertex.
221 *
222 * The "Root" vertex is then the SPFVertex representing the router that is
223 * having its routing tables set. The "this" SPFVertex is the vertex to which
224 * a route is being calculated from the root. The distance from the root that
225 * we're asking for is the number of hops from the root vertex to the vertex
226 * in question.
227 *
228 * The distance is calculated during route discovery and is stored in a
229 * member variable. This method simply fetches that value.
230 *
231 * @returns The distance, in hops, from the root SPFVertex to "this" SPFVertex.
232 */
234
235 /**
236 * @brief Set the distance from the root vertex to "this" SPFVertex object.
237 *
238 * Each router in the simulation is associated with an SPFVertex object. When
239 * calculating routes, each of these routers is, in turn, chosen as the "root"
240 * of the calculation and routes to all of the other routers are eventually
241 * saved in the routing tables of each of the chosen nodes. Each of these
242 * routers in the calculation has an associated SPFVertex.
243 *
244 * The "Root" vertex is then the SPFVertex representing the router that is
245 * having its routing tables set. The "this" SPFVertex is the vertex to which
246 * a route is being calculated from the root. The distance from the root that
247 * we're asking for is the number of hops from the root vertex to the vertex
248 * in question.
249 *
250 * @param distance The distance, in hops, from the root SPFVertex to "this"
251 * SPFVertex.
252 */
253 void SetDistanceFromRoot(uint32_t distance);
254
255 /**
256 * @brief Set the IP address and outgoing interface index that should be used
257 * to begin forwarding packets from the root SPFVertex to "this" SPFVertex.
258 *
259 * Each router node in the simulation is associated with an SPFVertex object.
260 * When calculating routes, each of these routers is, in turn, chosen as the
261 * "root" of the calculation and routes to all of the other routers are
262 * eventually saved in the routing tables of each of the chosen nodes.
263 *
264 * The "Root" vertex is then the SPFVertex representing the router that is
265 * having its routing tables set. The "this" SPFVertex is the vertex that
266 * represents the host or network to which a route is being calculated from
267 * the root. The IP address that we're asking for is the address on the
268 * remote side of a link off of the root node that should be used as the
269 * destination for packets along the path to "this" vertex.
270 *
271 * When initializing the root SPFVertex, the IP address used when forwarding
272 * packets is determined by examining the Global Router Link Records of the
273 * Link State Advertisement generated by the root node's GlobalRouter. This
274 * address is used to forward packets off of the root's network down those
275 * links. As other vertices / nodes are discovered which are further away
276 * from the root, they will be accessible down one of the paths via a link
277 * described by one of these Global Router Link Records.
278 *
279 * To forward packets to these hosts or networks, the root node must begin
280 * the forwarding process by sending the packets to a first hop router down
281 * an interface. This means that the first hop address and interface ID must
282 * be the same for all downstream SPFVertices. We call this "inheriting"
283 * the interface and next hop.
284 *
285 * In this method we are telling the root node which exit direction it should send
286 * should I send a packet to the network or host represented by 'this' SPFVertex.
287 *
288 * @see GlobalRouter
289 * @see GlobalRoutingLSA
290 * @see GlobalRoutingLinkRecord
291 * @param nextHop The IP address to use when forwarding packets to the host
292 * or network represented by "this" SPFVertex.
293 * @param id The interface index to use when forwarding packets to the host or
294 * network represented by "this" SPFVertex.
295 */
297
298 typedef std::pair<Ipv4Address, int32_t>
299 NodeExit_t; //!< IPv4 / interface container for exit nodes.
300
301 /**
302 * @brief Set the IP address and outgoing interface index that should be used
303 * to begin forwarding packets from the root SPFVertex to "this" SPFVertex.
304 *
305 * Each router node in the simulation is associated with an SPFVertex object.
306 * When calculating routes, each of these routers is, in turn, chosen as the
307 * "root" of the calculation and routes to all of the other routers are
308 * eventually saved in the routing tables of each of the chosen nodes.
309 *
310 * The "Root" vertex is then the SPFVertex representing the router that is
311 * having its routing tables set. The "this" SPFVertex is the vertex that
312 * represents the host or network to which a route is being calculated from
313 * the root. The IP address that we're asking for is the address on the
314 * remote side of a link off of the root node that should be used as the
315 * destination for packets along the path to "this" vertex.
316 *
317 * When initializing the root SPFVertex, the IP address used when forwarding
318 * packets is determined by examining the Global Router Link Records of the
319 * Link State Advertisement generated by the root node's GlobalRouter. This
320 * address is used to forward packets off of the root's network down those
321 * links. As other vertices / nodes are discovered which are further away
322 * from the root, they will be accessible down one of the paths via a link
323 * described by one of these Global Router Link Records.
324 *
325 * To forward packets to these hosts or networks, the root node must begin
326 * the forwarding process by sending the packets to a first hop router down
327 * an interface. This means that the first hop address and interface ID must
328 * be the same for all downstream SPFVertices. We call this "inheriting"
329 * the interface and next hop.
330 *
331 * In this method we are telling the root node which exit direction it should send
332 * should I send a packet to the network or host represented by 'this' SPFVertex.
333 *
334 * @see GlobalRouter
335 * @see GlobalRoutingLSA
336 * @see GlobalRoutingLinkRecord
337 * @param exit The pair of next-hop-IP and outgoing-interface-index to use when
338 * forwarding packets to the host or network represented by "this" SPFVertex.
339 */
341 /**
342 * \brief Obtain a pair indicating the exit direction from the root
343 *
344 * \param i An index to a pair
345 * \return A pair of next-hop-IP and outgoing-interface-index for
346 * indicating an exit direction from the root. It is 0 if the index 'i'
347 * is out-of-range
348 */
350 /**
351 * \brief Obtain a pair indicating the exit direction from the root
352 *
353 * This method assumes there is only a single exit direction from the root.
354 * Error occur if this assumption is invalid.
355 *
356 * \return The pair of next-hop-IP and outgoing-interface-index for reaching
357 * 'this' vertex from the root
358 */
360 /**
361 * \brief Merge into 'this' vertex the list of exit directions from
362 * another vertex
363 *
364 * This merge is necessary when ECMP are found.
365 *
366 * \param vertex From which the list of exit directions are obtain
367 * and are merged into 'this' vertex
368 */
369 void MergeRootExitDirections(const SPFVertex* vertex);
370 /**
371 * \brief Inherit all root exit directions from a given vertex to 'this' vertex
372 * \param vertex The vertex from which all root exit directions are to be inherited
373 *
374 * After the call of this method, the original root exit directions
375 * in 'this' vertex are all lost.
376 */
377 void InheritAllRootExitDirections(const SPFVertex* vertex);
378 /**
379 * \brief Get the number of exit directions from root for reaching 'this' vertex
380 * \return The number of exit directions from root
381 */
383
384 /**
385 * @brief Get a pointer to the SPFVector that is the parent of "this"
386 * SPFVertex.
387 *
388 * Each router node in the simulation is associated with an SPFVertex object.
389 * When calculating routes, each of these routers is, in turn, chosen as the
390 * "root" of the calculation and routes to all of the other routers are
391 * eventually saved in the routing tables of each of the chosen nodes.
392 *
393 * The "Root" vertex is then the SPFVertex representing the router that is
394 * having its routing tables set and is the root of the SPF tree.
395 *
396 * This method returns a pointer to the parent node of "this" SPFVertex
397 * (both of which reside in that SPF tree).
398 *
399 * @param i The index to one of the parents
400 * @returns A pointer to the SPFVertex that is the parent of "this" SPFVertex
401 * in the SPF tree.
402 */
403 SPFVertex* GetParent(uint32_t i = 0) const;
404
405 /**
406 * @brief Set the pointer to the SPFVector that is the parent of "this"
407 * SPFVertex.
408 *
409 * Each router node in the simulation is associated with an SPFVertex object.
410 * When calculating routes, each of these routers is, in turn, chosen as the
411 * "root" of the calculation and routes to all of the other routers are
412 * eventually saved in the routing tables of each of the chosen nodes.
413 *
414 * The "Root" vertex is then the SPFVertex representing the router that is
415 * having its routing tables set and is the root of the SPF tree.
416 *
417 * This method sets the parent pointer of "this" SPFVertex (both of which
418 * reside in that SPF tree).
419 *
420 * @param parent A pointer to the SPFVertex that is the parent of "this"
421 * SPFVertex* in the SPF tree.
422 */
423 void SetParent(SPFVertex* parent);
424 /**
425 * \brief Merge the Parent list from the v into this vertex
426 *
427 * \param v The vertex from which its list of Parent is read
428 * and then merged into the list of Parent of *this* vertex.
429 * Note that the list in v remains intact
430 */
431 void MergeParent(const SPFVertex* v);
432
433 /**
434 * @brief Get the number of children of "this" SPFVertex.
435 *
436 * Each router node in the simulation is associated with an SPFVertex object.
437 * When calculating routes, each of these routers is, in turn, chosen as the
438 * "root" of the calculation and routes to all of the other routers are
439 * eventually saved in the routing tables of each of the chosen nodes.
440 *
441 * The "Root" vertex is then the SPFVertex representing the router that is
442 * having its routing tables set and is the root of the SPF tree. Each vertex
443 * in the SPF tree can have a number of children that represent host or
444 * network routes available via that vertex.
445 *
446 * This method returns the number of children of "this" SPFVertex (which
447 * reside in the SPF tree).
448 *
449 * @returns The number of children of "this" SPFVertex (which reside in the
450 * SPF tree).
451 */
452 uint32_t GetNChildren() const;
453
454 /**
455 * @brief Get a borrowed SPFVertex pointer to the specified child of "this"
456 * SPFVertex.
457 *
458 * Each router node in the simulation is associated with an SPFVertex object.
459 * When calculating routes, each of these routers is, in turn, chosen as the
460 * "root" of the calculation and routes to all of the other routers are
461 * eventually saved in the routing tables of each of the chosen nodes.
462 *
463 * The "Root" vertex is then the SPFVertex representing the router that is
464 * having its routing tables set and is the root of the SPF tree. Each vertex
465 * in the SPF tree can have a number of children that represent host or
466 * network routes available via that vertex.
467 *
468 * This method the number of children of "this" SPFVertex (which reside in
469 * the SPF tree.
470 *
471 * @see SPFVertex::GetNChildren
472 * @param n The index (from 0 to the number of children minus 1) of the
473 * child SPFVertex to return.
474 * @warning The pointer returned by GetChild () is a borrowed pointer. You
475 * do not have any ownership of the underlying object and must not delete
476 * that object.
477 * @returns A pointer to the specified child SPFVertex (which resides in the
478 * SPF tree).
479 */
480 SPFVertex* GetChild(uint32_t n) const;
481
482 /**
483 * @brief Get a borrowed SPFVertex pointer to the specified child of "this"
484 * SPFVertex.
485 *
486 * Each router node in the simulation is associated with an SPFVertex object.
487 * When calculating routes, each of these routers is, in turn, chosen as the
488 * "root" of the calculation and routes to all of the other routers are
489 * eventually saved in the routing tables of each of the chosen nodes.
490 *
491 * The "Root" vertex is then the SPFVertex representing the router that is
492 * having its routing tables set and is the root of the SPF tree. Each vertex
493 * in the SPF tree can have a number of children that represent host or
494 * network routes available via that vertex.
495 *
496 * This method the number of children of "this" SPFVertex (which reside in
497 * the SPF tree.
498 *
499 * @see SPFVertex::GetNChildren
500 * @warning Ownership of the pointer added to the children of "this"
501 * SPFVertex is transferred to the "this" SPFVertex. You must not delete the
502 * (now) child SPFVertex after calling this method.
503 * @param child A pointer to the SPFVertex (which resides in the SPF tree) to
504 * be added to the list of children of "this" SPFVertex.
505 * @returns The number of children of "this" SPFVertex after the addition of
506 * the new child.
507 */
509
510 /**
511 * @brief Set the value of the VertexProcessed flag
512 *
513 * Flag to note whether vertex has been processed in stage two of
514 * SPF computation
515 * @param value boolean value to set the flag
516 */
517 void SetVertexProcessed(bool value);
518
519 /**
520 * @brief Check the value of the VertexProcessed flag
521 *
522 * Flag to note whether vertex has been processed in stage two of
523 * SPF computation
524 * @returns value of underlying flag
525 */
526 bool IsVertexProcessed() const;
527
528 /**
529 * @brief Clear the value of the VertexProcessed flag
530 *
531 * Flag to note whether vertex has been processed in stage two of
532 * SPF computation
533 */
535
536 private:
537 VertexType m_vertexType; //!< Vertex type
538 Ipv4Address m_vertexId; //!< Vertex ID
539 GlobalRoutingLSA* m_lsa; //!< Link State Advertisement
540 uint32_t m_distanceFromRoot; //!< Distance from root node
541 int32_t m_rootOif; //!< root Output Interface
542 Ipv4Address m_nextHop; //!< next hop
543 typedef std::list<NodeExit_t> ListOfNodeExit_t; //!< container of Exit nodes
544 ListOfNodeExit_t m_ecmpRootExits; //!< store the multiple root's exits for supporting ECMP
545 typedef std::list<SPFVertex*> ListOfSPFVertex_t; //!< container of SPFVertexes
546 ListOfSPFVertex_t m_parents; //!< parent list
547 ListOfSPFVertex_t m_children; //!< Children list
548 bool m_vertexProcessed; //!< Flag to note whether vertex has been processed in stage two of SPF
549 //!< computation
550
551 /**
552 * \brief Stream insertion operator.
553 *
554 * \param os the reference to the output stream
555 * \param vs a list of SPFVertexes
556 * \returns the reference to the output stream
557 */
558 friend std::ostream& operator<<(std::ostream& os, const SPFVertex::ListOfSPFVertex_t& vs);
559};
560
561/**
562 * @brief The Link State DataBase (LSDB) of the Global Route Manager.
563 *
564 * Each node in the simulation participating in global routing has a
565 * GlobalRouter interface. The primary job of this interface is to export
566 * Global Router Link State Advertisements (LSAs). These advertisements in
567 * turn contain a number of Global Router Link Records that describe the
568 * point to point links from the underlying node to other nodes (that will
569 * also export their own LSAs.
570 *
571 * This class implements a searchable database of LSAs gathered from every
572 * router in the simulation.
573 */
575{
576 public:
577 /**
578 * @brief Construct an empty Global Router Manager Link State Database.
579 *
580 * The database map composing the Link State Database is initialized in
581 * this constructor.
582 */
584
585 /**
586 * @brief Destroy an empty Global Router Manager Link State Database.
587 *
588 * The database map is walked and all of the Link State Advertisements stored
589 * in the database are freed; then the database map itself is clear ()ed to
590 * release any remaining resources.
591 */
593
594 // Delete copy constructor and assignment operator to avoid misuse
597
598 /**
599 * @brief Insert an IP address / Link State Advertisement pair into the Link
600 * State Database.
601 *
602 * The IPV4 address and the GlobalRoutingLSA given as parameters are converted
603 * to an STL pair and are inserted into the database map.
604 *
605 * @see GlobalRoutingLSA
606 * @see Ipv4Address
607 * @param addr The IP address associated with the LSA. Typically the Router
608 * ID.
609 * @param lsa A pointer to the Link State Advertisement for the router.
610 */
611 void Insert(Ipv4Address addr, GlobalRoutingLSA* lsa);
612
613 /**
614 * @brief Look up the Link State Advertisement associated with the given
615 * link state ID (address).
616 *
617 * The database map is searched for the given IPV4 address and corresponding
618 * GlobalRoutingLSA is returned.
619 *
620 * @see GlobalRoutingLSA
621 * @see Ipv4Address
622 * @param addr The IP address associated with the LSA. Typically the Router
623 * ID.
624 * @returns A pointer to the Link State Advertisement for the router specified
625 * by the IP address addr.
626 */
628 /**
629 * @brief Look up the Link State Advertisement associated with the given
630 * link state ID (address). This is a variation of the GetLSA call
631 * to allow the LSA to be found by matching addr with the LinkData field
632 * of the TransitNetwork link record.
633 *
634 * @see GetLSA
635 * @param addr The IP address associated with the LSA. Typically the Router
636 * @returns A pointer to the Link State Advertisement for the router specified
637 * by the IP address addr.
638 * ID.
639 */
641
642 /**
643 * @brief Set all LSA flags to an initialized state, for SPF computation
644 *
645 * This function walks the database and resets the status flags of all of the
646 * contained Link State Advertisements to LSA_SPF_NOT_EXPLORED. This is done
647 * prior to each SPF calculation to reset the state of the SPFVertex structures
648 * that will reference the LSAs during the calculation.
649 *
650 * @see GlobalRoutingLSA
651 * @see SPFVertex
652 */
653 void Initialize();
654
655 /**
656 * @brief Look up the External Link State Advertisement associated with the given
657 * index.
658 *
659 * The external database map is searched for the given index and corresponding
660 * GlobalRoutingLSA is returned.
661 *
662 * @see GlobalRoutingLSA
663 * @param index the index associated with the LSA.
664 * @returns A pointer to the Link State Advertisement.
665 */
666 GlobalRoutingLSA* GetExtLSA(uint32_t index) const;
667 /**
668 * @brief Get the number of External Link State Advertisements.
669 *
670 * @see GlobalRoutingLSA
671 * @returns the number of External Link State Advertisements.
672 */
673 uint32_t GetNumExtLSAs() const;
674
675 private:
676 typedef std::map<Ipv4Address, GlobalRoutingLSA*>
677 LSDBMap_t; //!< container of IPv4 addresses / Link State Advertisements
678 typedef std::pair<Ipv4Address, GlobalRoutingLSA*>
679 LSDBPair_t; //!< pair of IPv4 addresses / Link State Advertisements
680
681 LSDBMap_t m_database; //!< database of IPv4 addresses / Link State Advertisements
682 std::vector<GlobalRoutingLSA*>
683 m_extdatabase; //!< database of External Link State Advertisements
684};
685
686/**
687 * @brief A global router implementation.
688 *
689 * This singleton object can query interface each node in the system
690 * for a GlobalRouter interface. For those nodes, it fetches one or
691 * more Link State Advertisements and stores them in a local database.
692 * Then, it can compute shortest paths on a per-node basis to all routers,
693 * and finally configure each of the node's forwarding tables.
694 *
695 * The design is guided by OSPFv2 \RFC{2328} section 16.1.1 and quagga ospfd.
696 */
698{
699 public:
701 virtual ~GlobalRouteManagerImpl();
702
703 // Delete copy constructor and assignment operator to avoid misuse
706
707 /**
708 * @brief Delete all static routes on all nodes that have a
709 * GlobalRouterInterface
710 *
711 * \todo separate manually assigned static routes from static routes that
712 * the global routing code injects, and only delete the latter
713 */
714 virtual void DeleteGlobalRoutes();
715
716 /**
717 * @brief Build the routing database by gathering Link State Advertisements
718 * from each node exporting a GlobalRouter interface.
719 */
720 virtual void BuildGlobalRoutingDatabase();
721
722 /**
723 * @brief Compute routes using a Dijkstra SPF computation and populate
724 * per-node forwarding tables
725 */
726 virtual void InitializeRoutes();
727
728 /**
729 * @brief Debugging routine; allow client code to supply a pre-built LSDB
730 * @param lsdb the pre-built LSDB
731 */
733
734 /**
735 * @brief Debugging routine; call the core SPF from the unit tests
736 * @param root the root node to start calculations
737 */
739
740 private:
741 SPFVertex* m_spfroot; //!< the root node
742 GlobalRouteManagerLSDB* m_lsdb; //!< the Link State DataBase (LSDB) of the Global Route Manager
743
744 /**
745 * \brief Test if a node is a stub, from an OSPF sense.
746 *
747 * If there is only one link of type 1 or 2, then a default route
748 * can safely be added to the next-hop router and SPF does not need
749 * to be run
750 *
751 * \param root the root node
752 * \returns true if the node is a stub
753 */
754 bool CheckForStubNode(Ipv4Address root);
755
756 /**
757 * \brief Calculate the shortest path first (SPF) tree
758 *
759 * Equivalent to quagga ospf_spf_calculate
760 * \param root the root node
761 */
762 void SPFCalculate(Ipv4Address root);
763
764 /**
765 * \brief Process Stub nodes
766 *
767 * Processing logic from RFC 2328, page 166 and quagga ospf_spf_process_stubs ()
768 * stub link records will exist for point-to-point interfaces and for
769 * broadcast interfaces for which no neighboring router can be found
770 *
771 * \param v vertex to be processed
772 */
773 void SPFProcessStubs(SPFVertex* v);
774
775 /**
776 * \brief Process Autonomous Systems (AS) External LSA
777 *
778 * \param v vertex to be processed
779 * \param extlsa external LSA
780 */
782
783 /**
784 * \brief Examine the links in v's LSA and update the list of candidates with any
785 * vertices not already on the list
786 *
787 * \internal
788 *
789 * This method is derived from quagga ospf_spf_next (). See RFC2328 Section
790 * 16.1 (2) for further details.
791 *
792 * We're passed a parameter \a v that is a vertex which is already in the SPF
793 * tree. A vertex represents a router node. We also get a reference to the
794 * SPF candidate queue, which is a priority queue containing the shortest paths
795 * to the networks we know about.
796 *
797 * We examine the links in v's LSA and update the list of candidates with any
798 * vertices not already on the list. If a lower-cost path is found to a
799 * vertex already on the candidate list, store the new (lower) cost.
800 *
801 * \param v the vertex
802 * \param candidate the SPF candidate queue
803 */
804 void SPFNext(SPFVertex* v, CandidateQueue& candidate);
805
806 /**
807 * \brief Calculate nexthop from root through V (parent) to vertex W (destination)
808 * with given distance from root->W.
809 *
810 * This method is derived from quagga ospf_nexthop_calculation() 16.1.1.
811 * For now, this is greatly simplified from the quagga code
812 *
813 * \param v the parent
814 * \param w the destination
815 * \param l the link record
816 * \param distance the target distance
817 * \returns 1 on success
818 */
820 SPFVertex* w,
822 uint32_t distance);
823
824 /**
825 * \brief Adds a vertex to the list of children *in* each of its parents
826 *
827 * Derived from quagga ospf_vertex_add_parents ()
828 *
829 * This is a somewhat oddly named method (blame quagga). Although you might
830 * expect it to add a parent *to* something, it actually adds a vertex
831 * to the list of children *in* each of its parents.
832 *
833 * Given a pointer to a vertex, it links back to the vertex's parent that it
834 * already has set and adds itself to that vertex's list of children.
835 *
836 * \param v the vertex
837 */
839
840 /**
841 * \brief Search for a link between two vertices.
842 *
843 * This method is derived from quagga ospf_get_next_link ()
844 *
845 * First search the Global Router Link Records of vertex \a v for one
846 * representing a point-to point link to vertex \a w.
847 *
848 * What is done depends on prev_link. Contrary to appearances, prev_link just
849 * acts as a flag here. If prev_link is NULL, we return the first Global
850 * Router Link Record we find that describes a point-to-point link from \a v
851 * to \a w. If prev_link is not NULL, we return a Global Router Link Record
852 * representing a possible *second* link from \a v to \a w.
853 *
854 * \param v first vertex
855 * \param w second vertex
856 * \param prev_link the previous link in the list
857 * \returns the link's record
858 */
860 SPFVertex* w,
861 GlobalRoutingLinkRecord* prev_link);
862
863 /**
864 * \brief Add a host route to the routing tables
865 *
866 *
867 * This method is derived from quagga ospf_intra_add_router ()
868 *
869 * This is where we are actually going to add the host routes to the routing
870 * tables of the individual nodes.
871 *
872 * The vertex passed as a parameter has just been added to the SPF tree.
873 * This vertex must have a valid m_root_oid, corresponding to the outgoing
874 * interface on the root router of the tree that is the first hop on the path
875 * to the vertex. The vertex must also have a next hop address, corresponding
876 * to the next hop on the path to the vertex. The vertex has an m_lsa field
877 * that has some number of link records. For each point to point link record,
878 * the m_linkData is the local IP address of the link. This corresponds to
879 * a destination IP address, reachable from the root, to which we add a host
880 * route.
881 *
882 * \param v the vertex
883 *
884 */
886
887 /**
888 * \brief Add a transit to the routing tables
889 *
890 * \param v the vertex
891 */
893
894 /**
895 * \brief Add a stub to the routing tables
896 *
897 * \param l the global routing link record
898 * \param v the vertex
899 */
901
902 /**
903 * \brief Add an external route to the routing tables
904 *
905 * \param extlsa the external LSA
906 * \param v the vertex
907 */
909
910 /**
911 * \brief Return the interface number corresponding to a given IP address and mask
912 *
913 * This is a wrapper around GetInterfaceForPrefix(), but we first
914 * have to find the right node pointer to pass to that function.
915 * If no such interface is found, return -1 (note: unit test framework
916 * for routing assumes -1 to be a legal return value)
917 *
918 * \param a the target IP address
919 * \param amask the target subnet mask
920 * \return the outgoing interface number
921 */
922 int32_t FindOutgoingInterfaceId(Ipv4Address a, Ipv4Mask amask = Ipv4Mask("255.255.255.255"));
923};
924
925} // namespace ns3
926
927#endif /* GLOBAL_ROUTE_MANAGER_IMPL_H */
A Candidate Queue used in routing calculations.
A global router implementation.
void SPFCalculate(Ipv4Address root)
Calculate the shortest path first (SPF) tree.
void SPFAddASExternal(GlobalRoutingLSA *extlsa, SPFVertex *v)
Add an external route to the routing tables.
void ProcessASExternals(SPFVertex *v, GlobalRoutingLSA *extlsa)
Process Autonomous Systems (AS) External LSA.
virtual void InitializeRoutes()
Compute routes using a Dijkstra SPF computation and populate per-node forwarding tables.
void SPFProcessStubs(SPFVertex *v)
Process Stub nodes.
virtual void BuildGlobalRoutingDatabase()
Build the routing database by gathering Link State Advertisements from each node exporting a GlobalRo...
GlobalRoutingLinkRecord * SPFGetNextLink(SPFVertex *v, SPFVertex *w, GlobalRoutingLinkRecord *prev_link)
Search for a link between two vertices.
int32_t FindOutgoingInterfaceId(Ipv4Address a, Ipv4Mask amask=Ipv4Mask("255.255.255.255"))
Return the interface number corresponding to a given IP address and mask.
virtual void DeleteGlobalRoutes()
Delete all static routes on all nodes that have a GlobalRouterInterface.
GlobalRouteManagerImpl & operator=(const GlobalRouteManagerImpl &)=delete
GlobalRouteManagerLSDB * m_lsdb
the Link State DataBase (LSDB) of the Global Route Manager
bool CheckForStubNode(Ipv4Address root)
Test if a node is a stub, from an OSPF sense.
void DebugUseLsdb(GlobalRouteManagerLSDB *lsdb)
Debugging routine; allow client code to supply a pre-built LSDB.
SPFVertex * m_spfroot
the root node
void SPFNext(SPFVertex *v, CandidateQueue &candidate)
Examine the links in v's LSA and update the list of candidates with any vertices not already on the l...
void DebugSPFCalculate(Ipv4Address root)
Debugging routine; call the core SPF from the unit tests.
void SPFIntraAddTransit(SPFVertex *v)
Add a transit to the routing tables.
int SPFNexthopCalculation(SPFVertex *v, SPFVertex *w, GlobalRoutingLinkRecord *l, uint32_t distance)
Calculate nexthop from root through V (parent) to vertex W (destination) with given distance from roo...
void SPFIntraAddStub(GlobalRoutingLinkRecord *l, SPFVertex *v)
Add a stub to the routing tables.
GlobalRouteManagerImpl(const GlobalRouteManagerImpl &)=delete
void SPFIntraAddRouter(SPFVertex *v)
Add a host route to the routing tables.
void SPFVertexAddParent(SPFVertex *v)
Adds a vertex to the list of children in each of its parents.
The Link State DataBase (LSDB) of the Global Route Manager.
GlobalRouteManagerLSDB & operator=(const GlobalRouteManagerLSDB &)=delete
std::map< Ipv4Address, GlobalRoutingLSA * > LSDBMap_t
container of IPv4 addresses / Link State Advertisements
void Initialize()
Set all LSA flags to an initialized state, for SPF computation.
std::pair< Ipv4Address, GlobalRoutingLSA * > LSDBPair_t
pair of IPv4 addresses / Link State Advertisements
~GlobalRouteManagerLSDB()
Destroy an empty Global Router Manager Link State Database.
uint32_t GetNumExtLSAs() const
Get the number of External Link State Advertisements.
GlobalRoutingLSA * GetLSA(Ipv4Address addr) const
Look up the Link State Advertisement associated with the given link state ID (address).
std::vector< GlobalRoutingLSA * > m_extdatabase
database of External Link State Advertisements
void Insert(Ipv4Address addr, GlobalRoutingLSA *lsa)
Insert an IP address / Link State Advertisement pair into the Link State Database.
LSDBMap_t m_database
database of IPv4 addresses / Link State Advertisements
GlobalRouteManagerLSDB(const GlobalRouteManagerLSDB &)=delete
GlobalRoutingLSA * GetExtLSA(uint32_t index) const
Look up the External Link State Advertisement associated with the given index.
GlobalRouteManagerLSDB()
Construct an empty Global Router Manager Link State Database.
GlobalRoutingLSA * GetLSAByLinkData(Ipv4Address addr) const
Look up the Link State Advertisement associated with the given link state ID (address).
a Link State Advertisement (LSA) for a router, used in global routing.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Global routing protocol for IPv4 stacks.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:257
Vertex used in shortest path first (SPF) computations.
Ipv4Address GetVertexId() const
Get the Vertex ID field of a SPFVertex object.
std::pair< Ipv4Address, int32_t > NodeExit_t
IPv4 / interface container for exit nodes.
GlobalRoutingLSA * GetLSA() const
Get the Global Router Link State Advertisement returned by the Global Router represented by this SPFV...
Ipv4Address m_nextHop
next hop
void SetVertexId(Ipv4Address id)
Set the Vertex ID field of a SPFVertex object.
void MergeParent(const SPFVertex *v)
Merge the Parent list from the v into this vertex.
VertexType
Enumeration of the possible types of SPFVertex objects.
@ VertexNetwork
Vertex representing a network in the topology.
@ VertexRouter
Vertex representing a router in the topology.
@ VertexUnknown
Uninitialized Link Record.
void InheritAllRootExitDirections(const SPFVertex *vertex)
Inherit all root exit directions from a given vertex to 'this' vertex.
void SetDistanceFromRoot(uint32_t distance)
Set the distance from the root vertex to "this" SPFVertex object.
SPFVertex * GetChild(uint32_t n) const
Get a borrowed SPFVertex pointer to the specified child of "this" SPFVertex.
VertexType GetVertexType() const
Get the Vertex Type field of a SPFVertex object.
bool IsVertexProcessed() const
Check the value of the VertexProcessed flag.
void SetParent(SPFVertex *parent)
Set the pointer to the SPFVector that is the parent of "this" SPFVertex.
void MergeRootExitDirections(const SPFVertex *vertex)
Merge into 'this' vertex the list of exit directions from another vertex.
std::list< SPFVertex * > ListOfSPFVertex_t
container of SPFVertexes
uint32_t GetDistanceFromRoot() const
Get the distance from the root vertex to "this" SPFVertex object.
GlobalRoutingLSA * m_lsa
Link State Advertisement.
~SPFVertex()
Destroy an SPFVertex (Shortest Path First Vertex).
SPFVertex & operator=(const SPFVertex &)=delete
void SetRootExitDirection(Ipv4Address nextHop, int32_t id=SPF_INFINITY)
Set the IP address and outgoing interface index that should be used to begin forwarding packets from ...
void SetVertexProcessed(bool value)
Set the value of the VertexProcessed flag.
std::list< NodeExit_t > ListOfNodeExit_t
container of Exit nodes
void SetVertexType(VertexType type)
Set the Vertex Type field of a SPFVertex object.
void SetLSA(GlobalRoutingLSA *lsa)
Set the Global Router Link State Advertisement returned by the Global Router represented by this SPFV...
uint32_t GetNRootExitDirections() const
Get the number of exit directions from root for reaching 'this' vertex.
int32_t m_rootOif
root Output Interface
uint32_t m_distanceFromRoot
Distance from root node.
void ClearVertexProcessed()
Clear the value of the VertexProcessed flag.
bool m_vertexProcessed
Flag to note whether vertex has been processed in stage two of SPF computation.
friend std::ostream & operator<<(std::ostream &os, const SPFVertex::ListOfSPFVertex_t &vs)
Stream insertion operator.
SPFVertex(const SPFVertex &)=delete
uint32_t GetNChildren() const
Get the number of children of "this" SPFVertex.
Ipv4Address m_vertexId
Vertex ID.
uint32_t AddChild(SPFVertex *child)
Get a borrowed SPFVertex pointer to the specified child of "this" SPFVertex.
NodeExit_t GetRootExitDirection() const
Obtain a pair indicating the exit direction from the root.
ListOfNodeExit_t m_ecmpRootExits
store the multiple root's exits for supporting ECMP
SPFVertex * GetParent(uint32_t i=0) const
Get a pointer to the SPFVector that is the parent of "this" SPFVertex.
ListOfSPFVertex_t m_children
Children list.
VertexType m_vertexType
Vertex type.
ListOfSPFVertex_t m_parents
parent list
SPFVertex()
Construct an empty ("uninitialized") SPFVertex (Shortest Path First Vertex).
Every class exported by the ns3 library is enclosed in the ns3 namespace.
const uint32_t SPF_INFINITY
"infinite" distance between nodes