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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Craig Dowell (craigdo@ee.washington.edu)
7 * Tom Henderson (tomhend@u.washington.edu)
8 */
9
10#ifndef GLOBAL_ROUTE_MANAGER_IMPL_H
11#define GLOBAL_ROUTE_MANAGER_IMPL_H
12
14#include "ipv4-l3-protocol.h"
16#include "ipv6-l3-protocol.h"
18
19#include "ns3/ipv4-address.h"
20#include "ns3/ipv4-routing-helper.h"
21#include "ns3/object.h"
22#include "ns3/ptr.h"
23
24#include <algorithm>
25#include <iomanip>
26#include <iostream>
27#include <list>
28#include <map>
29#include <queue>
30#include <stdint.h>
31#include <utility>
32#include <vector>
33
34namespace ns3
35{
36
37const uint32_t SPF_INFINITY = 0xffffffff; //!< "infinite" distance between nodes
38
39template <typename T>
40class CandidateQueue;
41template <typename>
42class GlobalRouting;
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 */
70template <typename T>
72{
73 static_assert(std::is_same_v<T, Ipv4Manager> || std::is_same_v<T, Ipv6Manager>,
74 "T must be either Ipv4Manager or Ipv6Manager In SPFVertex");
75
76 /// Alias for determining whether the parent is Ipv4RoutingProtocol or Ipv6RoutingProtocol
77 static constexpr bool IsIpv4 = std::is_same_v<Ipv4Manager, T>;
78
79 /// Alias for Ipv4Manager and Ipv6Manager classes
80 using IpManager = typename std::conditional_t<IsIpv4, Ipv4Manager, Ipv6Manager>;
81
82 /// Alias for Ipv4 and Ipv6 classes
83 using Ip = typename std::conditional_t<IsIpv4, Ipv4, Ipv6>;
84
85 /// Alias for Ipv4Address and Ipv6Address classes
86 using IpAddress = typename std::conditional_t<IsIpv4, Ipv4Address, Ipv6Address>;
87
88 /// Alias for Ipv4Route and Ipv6Route classes
89 using IpRoute = typename std::conditional_t<IsIpv4, Ipv4Route, Ipv6Route>;
90
91 /// Alias for Ipv4Header and Ipv6Header classes
92 using IpHeader = typename std::conditional_t<IsIpv4, Ipv4Header, Ipv6Header>;
93
94 /// Alias for Ipv4InterfaceAddress and Ipv6InterfaceAddress classes
96 typename std::conditional_t<IsIpv4, Ipv4InterfaceAddress, Ipv6InterfaceAddress>;
97
98 /// Alias for Ipv4RoutingTableEntry and Ipv6RoutingTableEntry classes
100 typename std::conditional_t<IsIpv4, Ipv4RoutingTableEntry, Ipv6RoutingTableEntry>;
101
102 /// Alias for Ipv4Mask And Ipv6Prefix
103 using IpMaskOrPrefix = typename std::conditional_t<IsIpv4, Ipv4Mask, Ipv6Prefix>;
104
105 public:
106 /**
107 * @brief Enumeration of the possible types of SPFVertex objects.
108 *
109 * Currently we use VertexRouter to identify objects that represent a router
110 * in the simulation topology, and VertexNetwork to identify objects that
111 * represent a network.
112 */
114 {
115 VertexUnknown = 0, /**< Uninitialized Link Record */
116 VertexRouter, /**< Vertex representing a router in the topology */
117 VertexNetwork /**< Vertex representing a network in the topology */
118 };
119
120 /**
121 * @brief Construct an empty ("uninitialized") SPFVertex (Shortest Path First
122 * Vertex).
123 *
124 * The Vertex Type is set to VertexUnknown, the Vertex ID is set to
125 * 255.255.255.255, and the distance from root is set to infinity
126 * (UINT32_MAX). The referenced Link State Advertisement (LSA) is set to
127 * null as is the parent SPFVertex. The outgoing interface index is set to
128 * infinity, the next hop address is set to 0.0.0.0 and the list of children
129 * of the SPFVertex is initialized to empty.
130 *
131 * @see VertexType
132 */
133 SPFVertex();
134
135 /**
136 * @brief Construct an initialized SPFVertex (Shortest Path First Vertex).
137 *
138 * The Vertex Type is initialized to VertexRouter and the Vertex ID is found
139 * from the Link State ID of the Link State Advertisement (LSA) passed as a
140 * parameter. The Link State ID is set to the Router ID of the advertising
141 * router. The referenced LSA (m_lsa) is set to the given LSA. Other than
142 * these members, initialization is as in the default constructor.
143 * of the SPFVertex is initialized to empty.
144 *
145 * @see SPFVertex::SPFVertex ()
146 * @see VertexType
147 * @see GlobalRoutingLSA
148 * @param lsa The Link State Advertisement used for finding initial values.
149 */
151
152 /**
153 * @brief Destroy an SPFVertex (Shortest Path First Vertex).
154 *
155 * The children vertices of the SPFVertex are recursively deleted.
156 *
157 * @see SPFVertex::SPFVertex ()
158 */
159 ~SPFVertex();
160
161 // Delete copy constructor and assignment operator to avoid misuse
162 SPFVertex(const SPFVertex&) = delete;
163 SPFVertex& operator=(const SPFVertex&) = delete;
164
165 /**
166 * @brief Get the Vertex Type field of a SPFVertex object.
167 *
168 * The Vertex Type describes the kind of simulation object a given SPFVertex
169 * represents.
170 *
171 * @see VertexType
172 * @returns The VertexType of the current SPFVertex object.
173 */
175
176 /**
177 * @brief Set the Vertex Type field of a SPFVertex object.
178 *
179 * The Vertex Type describes the kind of simulation object a given SPFVertex
180 * represents.
181 *
182 * @see VertexType
183 * @param type The new VertexType for the current SPFVertex object.
184 */
185 void SetVertexType(VertexType type);
186
187 /**
188 * @brief Get the Vertex ID field of a SPFVertex object.
189 *
190 * The Vertex ID uniquely identifies the simulation object a given SPFVertex
191 * represents. Typically, this is the Router ID for SPFVertex objects
192 * representing routers, and comes from the Link State Advertisement of a
193 * router aggregated to a node in the simulation. These IDs are allocated
194 * automatically by the routing environment and look like IP addresses
195 * beginning at 0.0.0.0 and monotonically increasing as new routers are
196 * instantiated.
197 *
198 * @returns The Ipv4Address Vertex ID of the current SPFVertex object.
199 */
200 IpAddress GetVertexId() const;
201
202 /**
203 * @brief Set the Vertex ID field of a SPFVertex object.
204 *
205 * The Vertex ID uniquely identifies the simulation object a given SPFVertex
206 * represents. Typically, this is the Router ID for SPFVertex objects
207 * representing routers, and comes from the Link State Advertisement of a
208 * router aggregated to a node in the simulation. These IDs are allocated
209 * automatically by the routing environment and look like IP addresses
210 * beginning at 0.0.0.0 and monotonically increase as new routers are
211 * instantiated. This method is an explicit override of the automatically
212 * generated value.
213 *
214 * @param id The new Ipv4Address Vertex ID for the current SPFVertex object.
215 */
216 void SetVertexId(IpAddress id);
217
218 /**
219 * @brief Get the Global Router Link State Advertisement returned by the
220 * Global Router represented by this SPFVertex during the route discovery
221 * process.
222 *
223 * @see GlobalRouter
224 * @see GlobalRoutingLSA
225 * @see GlobalRouter::DiscoverLSAs ()
226 * @returns A pointer to the GlobalRoutingLSA found by the router represented
227 * by this SPFVertex object.
228 */
230
231 /**
232 * @brief Set the Global Router Link State Advertisement returned by the
233 * Global Router represented by this SPFVertex during the route discovery
234 * process.
235 *
236 * @see SPFVertex::GetLSA ()
237 * @see GlobalRouter
238 * @see GlobalRoutingLSA
239 * @see GlobalRouter::DiscoverLSAs ()
240 * @warning Ownership of the LSA is transferred to the "this" SPFVertex. You
241 * must not delete the LSA after calling this method.
242 * @param lsa A pointer to the GlobalRoutingLSA.
243 */
245
246 /**
247 * @brief Get the distance from the root vertex to "this" SPFVertex object.
248 *
249 * Each router in the simulation is associated with an SPFVertex object. When
250 * calculating routes, each of these routers is, in turn, chosen as the "root"
251 * of the calculation and routes to all of the other routers are eventually
252 * saved in the routing tables of each of the chosen nodes. Each of these
253 * routers in the calculation has an associated SPFVertex.
254 *
255 * The "Root" vertex is then the SPFVertex representing the router that is
256 * having its routing tables set. The "this" SPFVertex is the vertex to which
257 * a route is being calculated from the root. The distance from the root that
258 * we're asking for is the number of hops from the root vertex to the vertex
259 * in question.
260 *
261 * The distance is calculated during route discovery and is stored in a
262 * member variable. This method simply fetches that value.
263 *
264 * @returns The distance, in hops, from the root SPFVertex to "this" SPFVertex.
265 */
267
268 /**
269 * @brief Set the distance from the root vertex to "this" SPFVertex object.
270 *
271 * Each router in the simulation is associated with an SPFVertex object. When
272 * calculating routes, each of these routers is, in turn, chosen as the "root"
273 * of the calculation and routes to all of the other routers are eventually
274 * saved in the routing tables of each of the chosen nodes. Each of these
275 * routers in the calculation has an associated SPFVertex.
276 *
277 * The "Root" vertex is then the SPFVertex representing the router that is
278 * having its routing tables set. The "this" SPFVertex is the vertex to which
279 * a route is being calculated from the root. The distance from the root that
280 * we're asking for is the number of hops from the root vertex to the vertex
281 * in question.
282 *
283 * @param distance The distance, in hops, from the root SPFVertex to "this"
284 * SPFVertex.
285 */
286 void SetDistanceFromRoot(uint32_t distance);
287
288 /**
289 * @brief Set the IP address and outgoing interface index that should be used
290 * to begin forwarding packets from the root SPFVertex to "this" SPFVertex.
291 *
292 * Each router node in the simulation is associated with an SPFVertex object.
293 * When calculating routes, each of these routers is, in turn, chosen as the
294 * "root" of the calculation and routes to all of the other routers are
295 * eventually saved in the routing tables of each of the chosen nodes.
296 *
297 * The "Root" vertex is then the SPFVertex representing the router that is
298 * having its routing tables set. The "this" SPFVertex is the vertex that
299 * represents the host or network to which a route is being calculated from
300 * the root. The IP address that we're asking for is the address on the
301 * remote side of a link off of the root node that should be used as the
302 * destination for packets along the path to "this" vertex.
303 *
304 * When initializing the root SPFVertex, the IP address used when forwarding
305 * packets is determined by examining the Global Router Link Records of the
306 * Link State Advertisement generated by the root node's GlobalRouter. This
307 * address is used to forward packets off of the root's network down those
308 * links. As other vertices / nodes are discovered which are further away
309 * from the root, they will be accessible down one of the paths via a link
310 * described by one of these Global Router Link Records.
311 *
312 * To forward packets to these hosts or networks, the root node must begin
313 * the forwarding process by sending the packets to a first hop router down
314 * an interface. This means that the first hop address and interface ID must
315 * be the same for all downstream SPFVertices. We call this "inheriting"
316 * the interface and next hop.
317 *
318 * In this method we are telling the root node which exit direction it should send
319 * should I send a packet to the network or host represented by 'this' SPFVertex.
320 *
321 * @see GlobalRouter
322 * @see GlobalRoutingLSA
323 * @see GlobalRoutingLinkRecord
324 * @param nextHop The IP address to use when forwarding packets to the host
325 * or network represented by "this" SPFVertex.
326 * @param id The interface index to use when forwarding packets to the host or
327 * network represented by "this" SPFVertex.
328 */
330
331 typedef std::pair<IpAddress, int32_t>
332 NodeExit_t; //!< IPv4 / interface container for exit nodes.
333
334 /**
335 * @brief Set the IP address and outgoing interface index that should be used
336 * to begin forwarding packets from the root SPFVertex to "this" SPFVertex.
337 *
338 * Each router node in the simulation is associated with an SPFVertex object.
339 * When calculating routes, each of these routers is, in turn, chosen as the
340 * "root" of the calculation and routes to all of the other routers are
341 * eventually saved in the routing tables of each of the chosen nodes.
342 *
343 * The "Root" vertex is then the SPFVertex representing the router that is
344 * having its routing tables set. The "this" SPFVertex is the vertex that
345 * represents the host or network to which a route is being calculated from
346 * the root. The IP address that we're asking for is the address on the
347 * remote side of a link off of the root node that should be used as the
348 * destination for packets along the path to "this" vertex.
349 *
350 * When initializing the root SPFVertex, the IP address used when forwarding
351 * packets is determined by examining the Global Router Link Records of the
352 * Link State Advertisement generated by the root node's GlobalRouter. This
353 * address is used to forward packets off of the root's network down those
354 * links. As other vertices / nodes are discovered which are further away
355 * from the root, they will be accessible down one of the paths via a link
356 * described by one of these Global Router Link Records.
357 *
358 * To forward packets to these hosts or networks, the root node must begin
359 * the forwarding process by sending the packets to a first hop router down
360 * an interface. This means that the first hop address and interface ID must
361 * be the same for all downstream SPFVertices. We call this "inheriting"
362 * the interface and next hop.
363 *
364 * In this method we are telling the root node which exit direction it should send
365 * should I send a packet to the network or host represented by 'this' SPFVertex.
366 *
367 * @see GlobalRouter
368 * @see GlobalRoutingLSA
369 * @see GlobalRoutingLinkRecord
370 * @param exit The pair of next-hop-IP and outgoing-interface-index to use when
371 * forwarding packets to the host or network represented by "this" SPFVertex.
372 */
374 /**
375 * @brief Obtain a pair indicating the exit direction from the root
376 *
377 * @param i An index to a pair
378 * @return A pair of next-hop-IP and outgoing-interface-index for
379 * indicating an exit direction from the root. It is 0 if the index 'i'
380 * is out-of-range
381 */
383 /**
384 * @brief Obtain a pair indicating the exit direction from the root
385 *
386 * This method assumes there is only a single exit direction from the root.
387 * Error occur if this assumption is invalid.
388 *
389 * @return The pair of next-hop-IP and outgoing-interface-index for reaching
390 * 'this' vertex from the root
391 */
393 /**
394 * @brief Merge into 'this' vertex the list of exit directions from
395 * another vertex
396 *
397 * This merge is necessary when ECMP are found.
398 *
399 * @param vertex From which the list of exit directions are obtain
400 * and are merged into 'this' vertex
401 */
402 void MergeRootExitDirections(const SPFVertex<T>* vertex);
403 /**
404 * @brief Inherit all root exit directions from a given vertex to 'this' vertex
405 * @param vertex The vertex from which all root exit directions are to be inherited
406 *
407 * After the call of this method, the original root exit directions
408 * in 'this' vertex are all lost.
409 */
410 void InheritAllRootExitDirections(const SPFVertex<T>* vertex);
411 /**
412 * @brief Get the number of exit directions from root for reaching 'this' vertex
413 * @return The number of exit directions from root
414 */
416
417 /**
418 * @brief Get a pointer to the SPFVector that is the parent of "this"
419 * SPFVertex.
420 *
421 * Each router node in the simulation is associated with an SPFVertex object.
422 * When calculating routes, each of these routers is, in turn, chosen as the
423 * "root" of the calculation and routes to all of the other routers are
424 * eventually saved in the routing tables of each of the chosen nodes.
425 *
426 * The "Root" vertex is then the SPFVertex representing the router that is
427 * having its routing tables set and is the root of the SPF tree.
428 *
429 * This method returns a pointer to the parent node of "this" SPFVertex
430 * (both of which reside in that SPF tree).
431 *
432 * @param i The index to one of the parents
433 * @returns A pointer to the SPFVertex that is the parent of "this" SPFVertex
434 * in the SPF tree.
435 */
436 SPFVertex* GetParent(uint32_t i = 0) const;
437
438 /**
439 * @brief Set the pointer to the SPFVector that is the parent of "this"
440 * SPFVertex.
441 *
442 * Each router node in the simulation is associated with an SPFVertex object.
443 * When calculating routes, each of these routers is, in turn, chosen as the
444 * "root" of the calculation and routes to all of the other routers are
445 * eventually saved in the routing tables of each of the chosen nodes.
446 *
447 * The "Root" vertex is then the SPFVertex representing the router that is
448 * having its routing tables set and is the root of the SPF tree.
449 *
450 * This method sets the parent pointer of "this" SPFVertex (both of which
451 * reside in that SPF tree).
452 *
453 * @param parent A pointer to the SPFVertex that is the parent of "this"
454 * SPFVertex* in the SPF tree.
455 */
456 void SetParent(SPFVertex<T>* parent);
457 /**
458 * @brief Merge the Parent list from the v into this vertex
459 *
460 * @param v The vertex from which its list of Parent is read
461 * and then merged into the list of Parent of *this* vertex.
462 * Note that the list in v remains intact
463 */
464 void MergeParent(const SPFVertex<T>* v);
465
466 /**
467 * @brief Get the number of children of "this" SPFVertex.
468 *
469 * Each router node in the simulation is associated with an SPFVertex object.
470 * When calculating routes, each of these routers is, in turn, chosen as the
471 * "root" of the calculation and routes to all of the other routers are
472 * eventually saved in the routing tables of each of the chosen nodes.
473 *
474 * The "Root" vertex is then the SPFVertex representing the router that is
475 * having its routing tables set and is the root of the SPF tree. Each vertex
476 * in the SPF tree can have a number of children that represent host or
477 * network routes available via that vertex.
478 *
479 * This method returns the number of children of "this" SPFVertex (which
480 * reside in the SPF tree).
481 *
482 * @returns The number of children of "this" SPFVertex (which reside in the
483 * SPF tree).
484 */
485 uint32_t GetNChildren() const;
486
487 /**
488 * @brief Get a borrowed SPFVertex pointer to the specified child of "this"
489 * SPFVertex.
490 *
491 * Each router node in the simulation is associated with an SPFVertex object.
492 * When calculating routes, each of these routers is, in turn, chosen as the
493 * "root" of the calculation and routes to all of the other routers are
494 * eventually saved in the routing tables of each of the chosen nodes.
495 *
496 * The "Root" vertex is then the SPFVertex representing the router that is
497 * having its routing tables set and is the root of the SPF tree. Each vertex
498 * in the SPF tree can have a number of children that represent host or
499 * network routes available via that vertex.
500 *
501 * This method the number of children of "this" SPFVertex (which reside in
502 * the SPF tree.
503 *
504 * @see SPFVertex::GetNChildren
505 * @param n The index (from 0 to the number of children minus 1) of the
506 * child SPFVertex to return.
507 * @warning The pointer returned by GetChild () is a borrowed pointer. You
508 * do not have any ownership of the underlying object and must not delete
509 * that object.
510 * @returns A pointer to the specified child SPFVertex (which resides in the
511 * SPF tree).
512 */
514
515 /**
516 * @brief Get a borrowed SPFVertex pointer to the specified child of "this"
517 * SPFVertex.
518 *
519 * Each router node in the simulation is associated with an SPFVertex object.
520 * When calculating routes, each of these routers is, in turn, chosen as the
521 * "root" of the calculation and routes to all of the other routers are
522 * eventually saved in the routing tables of each of the chosen nodes.
523 *
524 * The "Root" vertex is then the SPFVertex representing the router that is
525 * having its routing tables set and is the root of the SPF tree. Each vertex
526 * in the SPF tree can have a number of children that represent host or
527 * network routes available via that vertex.
528 *
529 * This method the number of children of "this" SPFVertex (which reside in
530 * the SPF tree.
531 *
532 * @see SPFVertex::GetNChildren
533 * @warning Ownership of the pointer added to the children of "this"
534 * SPFVertex is transferred to the "this" SPFVertex. You must not delete the
535 * (now) child SPFVertex after calling this method.
536 * @param child A pointer to the SPFVertex (which resides in the SPF tree) to
537 * be added to the list of children of "this" SPFVertex.
538 * @returns The number of children of "this" SPFVertex after the addition of
539 * the new child.
540 */
542
543 /**
544 * @brief Set the value of the VertexProcessed flag
545 *
546 * Flag to note whether vertex has been processed in stage two of
547 * SPF computation
548 * @param value boolean value to set the flag
549 */
550 void SetVertexProcessed(bool value);
551
552 /**
553 * @brief Check the value of the VertexProcessed flag
554 *
555 * Flag to note whether vertex has been processed in stage two of
556 * SPF computation
557 * @returns value of underlying flag
558 */
559 bool IsVertexProcessed() const;
560
561 /**
562 * @brief Clear the value of the VertexProcessed flag
563 *
564 * Flag to note whether vertex has been processed in stage two of
565 * SPF computation
566 */
568
569 /**
570 * @brief Get the node pointer corresponding to this Vertex
571 * @returns the node pointer corresponding to this Vertex
572 */
573 Ptr<Node> GetNode() const;
574
575 private:
576 VertexType m_vertexType; //!< Vertex type
577 IpAddress m_vertexId; //!< Vertex ID
578 GlobalRoutingLSA<IpManager>* m_lsa; //!< Link State Advertisement
579 uint32_t m_distanceFromRoot; //!< Distance from root node
580 int32_t m_rootOif; //!< root Output Interface
581 IpAddress m_nextHop; //!< next hop
582 typedef std::list<NodeExit_t> ListOfNodeExit_t; //!< container of Exit nodes
583 ListOfNodeExit_t m_ecmpRootExits; //!< store the multiple root's exits for supporting ECMP
584 typedef std::list<SPFVertex<T>*> ListOfSPFVertex_t; //!< container of SPFVertex items
585 ListOfSPFVertex_t m_parents; //!< parent list
586 ListOfSPFVertex_t m_children; //!< Children list
587 bool m_vertexProcessed; //!< Flag to note whether vertex has been processed in stage two of SPF
588 //!< computation
589 Ptr<Node> m_node; //!< node pointer corresponding to the this Vertex
590
591 /**
592 * @brief Stream insertion operator.
593 * @param os the reference to the output stream
594 * @param vs a list of SPFVertex items
595 * @returns the reference to the output stream
596 */
597 friend std::ostream& operator<<(std::ostream& os,
598 const typename SPFVertex<T>::ListOfSPFVertex_t& vs)
599 {
600 os << "{";
601 for (auto iter = vs.begin(); iter != vs.end();)
602 {
603 os << (*iter)->m_vertexId;
604 if (++iter != vs.end())
605 {
606 os << ", ";
607 }
608 else
609 {
610 break;
611 }
612 }
613 os << "}";
614 return os;
615 }
616};
617
618/**
619 * @brief The Link State DataBase (LSDB) of the Global Route Manager.
620 *
621 * Each node in the simulation participating in global routing has a
622 * GlobalRouter interface. The primary job of this interface is to export
623 * Global Router Link State Advertisements (LSAs). These advertisements in
624 * turn contain a number of Global Router Link Records that describe the
625 * point to point links from the underlying node to other nodes (that will
626 * also export their own LSAs.
627 *
628 * This class implements a searchable database of LSAs gathered from every
629 * router in the simulation.
630 */
631template <typename T>
633{
634 static_assert(std::is_same_v<T, Ipv4Manager> || std::is_same_v<T, Ipv6Manager>,
635 "T must be either Ipv4Manager or Ipv6Manager In GlobalRouteManagerLSDB");
636 /// Alias for determining whether the parent is Ipv4RoutingProtocol or Ipv6RoutingProtocol
637 static constexpr bool IsIpv4 = std::is_same_v<Ipv4Manager, T>;
638
639 /// Alias for Ipv4Manager and Ipv6Manager classes
640 using IpManager = typename std::conditional_t<IsIpv4, Ipv4Manager, Ipv6Manager>;
641
642 /// Alias for Ipv4 and Ipv6 classes
643 using Ip = typename std::conditional_t<IsIpv4, Ipv4, Ipv6>;
644
645 /// Alias for Ipv4Address and Ipv6Address classes
646 using IpAddress = typename std::conditional_t<IsIpv4, Ipv4Address, Ipv6Address>;
647
648 /// Alias for Ipv4Route and Ipv6Route classes
649 using IpRoute = typename std::conditional_t<IsIpv4, Ipv4Route, Ipv6Route>;
650
651 /// Alias for Ipv4Header and Ipv6Header classes
652 using IpHeader = typename std::conditional_t<IsIpv4, Ipv4Header, Ipv6Header>;
653
654 /// Alias for Ipv4InterfaceAddress and Ipv6InterfaceAddress classes
656 typename std::conditional_t<IsIpv4, Ipv4InterfaceAddress, Ipv6InterfaceAddress>;
657
658 /// Alias for Ipv4RoutingTableEntry and Ipv6RoutingTableEntry classes
660 typename std::conditional_t<IsIpv4, Ipv4RoutingTableEntry, Ipv6RoutingTableEntry>;
661
662 /// Alias for Ipv4Mask And Ipv6Prefix
663 using IpMaskOrPrefix = typename std::conditional_t<IsIpv4, Ipv4Mask, Ipv6Prefix>;
664
665 public:
666 /**
667 * @brief Construct an empty Global Router Manager Link State Database.
668 *
669 * The database map composing the Link State Database is initialized in
670 * this constructor.
671 */
673
674 /**
675 * @brief Destroy an empty Global Router Manager Link State Database.
676 *
677 * The database map is walked and all of the Link State Advertisements stored
678 * in the database are freed; then the database map itself is clear ()ed to
679 * release any remaining resources.
680 */
682
683 // Delete copy constructor and assignment operator to avoid misuse
686
687 /**
688 * @brief Insert an IP address / Link State Advertisement pair into the Link
689 * State Database.
690 *
691 * The IPV4 address and the GlobalRoutingLSA given as parameters are converted
692 * to an STL pair and are inserted into the database map.
693 *
694 * @see GlobalRoutingLSA
695 * @see Ipv4Address
696 * @param addr The IP address associated with the LSA. Typically the Router
697 * ID.
698 * @param lsa A pointer to the Link State Advertisement for the router.
699 */
701
702 /**
703 * @brief Look up the Link State Advertisement associated with the given
704 * link state ID (address).
705 *
706 * The database map is searched for the given IPV4 address and corresponding
707 * GlobalRoutingLSA is returned.
708 *
709 * @see GlobalRoutingLSA
710 * @see Ipv4Address
711 * @param addr The IP address associated with the LSA. Typically the Router
712 * ID.
713 * @returns A pointer to the Link State Advertisement for the router specified
714 * by the IP address addr.
715 */
717 /**
718 * @brief Look up the Link State Advertisement associated with the given
719 * link state ID (address). This is a variation of the GetLSA call
720 * to allow the LSA to be found by matching addr with the LinkData field
721 * of the TransitNetwork link record.
722 *
723 * @see GetLSA
724 * @param addr The IP address associated with the LSA. Typically the Router
725 * @returns A pointer to the Link State Advertisement for the router specified
726 * by the IP address addr.
727 * ID.
728 */
730
731 /**
732 * @brief Set all LSA flags to an initialized state, for SPF computation
733 *
734 * This function walks the database and resets the status flags of all of the
735 * contained Link State Advertisements to LSA_SPF_NOT_EXPLORED. This is done
736 * prior to each SPF calculation to reset the state of the SPFVertex structures
737 * that will reference the LSAs during the calculation.
738 *
739 * @see GlobalRoutingLSA
740 * @see SPFVertex
741 */
742 void Initialize();
743
744 /**
745 * @brief Look up the External Link State Advertisement associated with the given
746 * index.
747 *
748 * The external database map is searched for the given index and corresponding
749 * GlobalRoutingLSA is returned.
750 *
751 * @see GlobalRoutingLSA
752 * @param index the index associated with the LSA.
753 * @returns A pointer to the Link State Advertisement.
754 */
756 /**
757 * @brief Get the number of External Link State Advertisements.
758 *
759 * @see GlobalRoutingLSA
760 * @returns the number of External Link State Advertisements.
761 */
762 uint32_t GetNumExtLSAs() const;
763
764 private:
765 typedef std::map<IpAddress, GlobalRoutingLSA<IpManager>*>
766 LSDBMap_t; //!< container of IPv4 addresses / Link State Advertisements
767 typedef std::pair<IpAddress, GlobalRoutingLSA<IpManager>*>
768 LSDBPair_t; //!< pair of IPv4 addresses / Link State Advertisements
769
770 LSDBMap_t m_database; //!< database of IPv4 addresses / Link State Advertisements
771 std::vector<GlobalRoutingLSA<IpManager>*>
772 m_extdatabase; //!< database of External Link State Advertisements
773};
774
775/**
776 * @brief A global router implementation.
777 *
778 * This singleton object can query interface each node in the system
779 * for a GlobalRouter interface. For those nodes, it fetches one or
780 * more Link State Advertisements and stores them in a local database.
781 * Then, it can compute shortest paths on a per-node basis to all routers,
782 * and finally configure each of the node's forwarding tables.
783 *
784 * The design is guided by OSPFv2 \RFC{2328} section 16.1.1 and quagga ospfd.
785 */
786template <typename T>
788{
789 static_assert(
790 std::is_same_v<T, Ipv4Manager> || std::is_same_v<T, Ipv6Manager>,
791 "T must be either Ipv4Manager or Ipv6Manager when calling GlobalRouteManagerImpl");
792 /// Alias for determining whether the parent is Ipv4RoutingProtocol or Ipv6RoutingProtocol
793 static constexpr bool IsIpv4 = std::is_same_v<Ipv4Manager, T>;
794
795 /// Alias for Ipv4 and Ipv6 classes
796 using Ip = typename std::conditional_t<IsIpv4, Ipv4, Ipv6>;
797
798 /// Alias for Ipv4Manager and Ipv6Manager classes
799 using IpManager = typename std::conditional_t<IsIpv4, Ipv4Manager, Ipv6Manager>;
800
801 /// Alias for Ipv4Address and Ipv6Address classes
802 using IpAddress = typename std::conditional_t<IsIpv4, Ipv4Address, Ipv6Address>;
803
804 /// Alias for Ipv4Route and Ipv6Route classes
805 using IpRoute = typename std::conditional_t<IsIpv4, Ipv4Route, Ipv6Route>;
806
807 /// Alias for Ipv4Header and Ipv6Header classes
808 using IpHeader = typename std::conditional_t<IsIpv4, Ipv4Header, Ipv6Header>;
809
810 /// Alias for Ipv4InterfaceAddress and Ipv6InterfaceAddress classes
812 typename std::conditional_t<IsIpv4, Ipv4InterfaceAddress, Ipv6InterfaceAddress>;
813
814 /// Alias for Ipv4RoutingTableEntry and Ipv6RoutingTableEntry classes
816 typename std::conditional_t<IsIpv4, Ipv4RoutingTableEntry, Ipv6RoutingTableEntry>;
817
818 /// Alias for Ipv4Mask And Ipv6Prefix
819 using IpMaskOrPrefix = typename std::conditional_t<IsIpv4, Ipv4Mask, Ipv6Prefix>;
820
821 /// Alias for Ipv4ListRouting and Ipv6ListRouting classes
822 using IpListRouting = typename std::conditional_t<IsIpv4, Ipv4ListRouting, Ipv6ListRouting>;
823
824 /// Alias for Ipv4l3Protocol and Ipv6l3Protocol classes
825 using IpL3Protocol = typename std::conditional_t<IsIpv4, Ipv4L3Protocol, Ipv6L3Protocol>;
826
827 /// Alias for Ipv4RoutingProtocol and Ipv6RoutingProtocol classes
829 typename std::conditional_t<IsIpv4, Ipv4RoutingProtocol, Ipv6RoutingProtocol>;
830
831 /// Alias for Ipv4GlobalRouting and Ipv6GlobalRouting classes
833
834 public:
836 virtual ~GlobalRouteManagerImpl();
837
838 // Delete copy constructor and assignment operator to avoid misuse
841
842 /**
843 * @brief Delete all static routes on all nodes that have a
844 * GlobalRouterInterface
845 *
846 * @todo separate manually assigned static routes from static routes that
847 * the global routing code injects, and only delete the latter
848 */
849 virtual void DeleteGlobalRoutes();
850
851 /**
852 * @brief Build the routing database by gathering Link State Advertisements
853 * from each node exporting a GlobalRouter interface.
854 */
855 virtual void BuildGlobalRoutingDatabase();
856
857 /**
858 * @brief Compute routes using a Dijkstra SPF computation and populate
859 * per-node forwarding tables
860 */
861 virtual void InitializeRoutes();
862
863 /**
864 * @brief Debugging routine; allow client code to supply a pre-built LSDB
865 * @param lsdb the pre-built LSDB
866 */
868
869 /**
870 * @brief Debugging routine; call the core SPF from the unit tests
871 * @param root the root node to start calculations
872 */
873 void DebugSPFCalculate(IpAddress root);
874
875 /**
876 * @brief prints the path from this node to the destination node at a particular time.
877 * @param sourceNode the source node
878 * @param dest the destination node
879 * @param stream The output stream to which the routing path will be written.
880 * @param nodeIdLookup Print the Node Id
881 * @param unit The time unit for timestamps in the printed output.
882 * @see Ipv4GlobalRoutingHelper::PrintRoute
883 */
884 void PrintRoute(Ptr<Node> sourceNode,
885 Ptr<Node> dest,
887 bool nodeIdLookup,
888 Time::Unit unit);
889
890 /**
891 * @brief prints the path from this node to the destination node at a particular time.
892 * @param sourceNode the source node
893 * @param dest the destination nodes ipv4 address
894 * @param stream The output stream to which the routing path will be written.
895 * @param nodeIdLookup Print the node id
896 * @param unit The time unit for timestamps in the printed output.
897 * @see Ipv4GlobalRoutingHelper::PrintRoute
898 */
899 void PrintRoute(Ptr<Node> sourceNode,
900 IpAddress dest,
902 bool nodeIdLookup,
903 Time::Unit unit);
904
905 /**
906 * @brief initialize all nodes as routers. this method queries all the nodes in the simulation
907 * and enables ipv6 forwarding on all of them.
908 */
909 void InitializeRouters();
910
911 private:
912 SPFVertex<T>* m_spfroot; //!< the root node
914 m_lsdb; //!< the Link State DataBase (LSDB) of the Global Route Manager
915
916 /**
917 * @brief Test if a node is a stub, from an OSPF sense.
918 *
919 * If there is only one link of type 1 or 2, then a default route
920 * can safely be added to the next-hop router and SPF does not need
921 * to be run
922 *
923 * @param root the root node
924 * @returns true if the node is a stub
925 */
926 bool CheckForStubNode(IpAddress root);
927
928 /**
929 * @brief Calculate the shortest path first (SPF) tree
930 *
931 * Equivalent to quagga ospf_spf_calculate
932 * @param root the root node
933 */
934 void SPFCalculate(IpAddress root);
935
936 /**
937 * @brief Process Stub nodes
938 *
939 * Processing logic from RFC 2328, page 166 and quagga ospf_spf_process_stubs ()
940 * stub link records will exist for point-to-point interfaces and for
941 * broadcast interfaces for which no neighboring router can be found
942 *
943 * @param v vertex to be processed
944 */
946
947 /**
948 * @brief Process Autonomous Systems (AS) External LSA
949 *
950 * @param v vertex to be processed
951 * @param extlsa external LSA
952 */
954
955 /**
956 * @brief Examine the links in v's LSA and update the list of candidates with any
957 * vertices not already on the list
958 *
959 * @internal
960 *
961 * This method is derived from quagga ospf_spf_next (). See RFC2328 Section
962 * 16.1 (2) for further details.
963 *
964 * We're passed a parameter \a v that is a vertex which is already in the SPF
965 * tree. A vertex represents a router node. We also get a reference to the
966 * SPF candidate queue, which is a priority queue containing the shortest paths
967 * to the networks we know about.
968 *
969 * We examine the links in v's LSA and update the list of candidates with any
970 * vertices not already on the list. If a lower-cost path is found to a
971 * vertex already on the candidate list, store the new (lower) cost.
972 *
973 * @param v the vertex
974 * @param candidate the SPF candidate queue
975 */
976 void SPFNext(SPFVertex<T>* v, CandidateQueue<T>& candidate);
977
978 /**
979 * @brief Calculate nexthop from root through V (parent) to vertex W (destination)
980 * with given distance from root->W.
981 *
982 * This method is derived from quagga ospf_nexthop_calculation() 16.1.1.
983 * For now, this is greatly simplified from the quagga code
984 *
985 * @param v the parent
986 * @param w the destination
987 * @param l the link record
988 * @param distance the target distance
989 * @returns 1 on success
990 */
992 SPFVertex<T>* w,
994 uint32_t distance);
995
996 /**
997 * @brief Adds a vertex to the list of children *in* each of its parents
998 *
999 * Derived from quagga ospf_vertex_add_parents ()
1000 *
1001 * This is a somewhat oddly named method (blame quagga). Although you might
1002 * expect it to add a parent *to* something, it actually adds a vertex
1003 * to the list of children *in* each of its parents.
1004 *
1005 * Given a pointer to a vertex, it links back to the vertex's parent that it
1006 * already has set and adds itself to that vertex's list of children.
1007 *
1008 * @param v the vertex
1009 */
1011
1012 /**
1013 * @brief Search for a link between two vertices.
1014 *
1015 * This method is derived from quagga ospf_get_next_link ()
1016 *
1017 * First search the Global Router Link Records of vertex \a v for one
1018 * representing a point-to point link to vertex \a w.
1019 *
1020 * What is done depends on prev_link. Contrary to appearances, prev_link just
1021 * acts as a flag here. If prev_link is NULL, we return the first Global
1022 * Router Link Record we find that describes a point-to-point link from \a v
1023 * to \a w. If prev_link is not NULL, we return a Global Router Link Record
1024 * representing a possible *second* link from \a v to \a w.
1025 *
1026 * @param v first vertex
1027 * @param w second vertex
1028 * @param prev_link the previous link in the list
1029 * @returns the link's record
1030 */
1032 SPFVertex<T>* v,
1033 SPFVertex<T>* w,
1035
1036 /**
1037 * @brief Add a host route to the routing tables
1038 *
1039 *
1040 * This method is derived from quagga ospf_intra_add_router ()
1041 *
1042 * This is where we are actually going to add the host routes to the routing
1043 * tables of the individual nodes.
1044 *
1045 * The vertex passed as a parameter has just been added to the SPF tree.
1046 * This vertex must have a valid m_root_oid, corresponding to the outgoing
1047 * interface on the root router of the tree that is the first hop on the path
1048 * to the vertex. The vertex must also have a next hop address, corresponding
1049 * to the next hop on the path to the vertex. The vertex has an m_lsa field
1050 * that has some number of link records. For each point to point link record,
1051 * the m_linkData is the local IP address of the link. This corresponds to
1052 * a destination IP address, reachable from the root, to which we add a host
1053 * route.
1054 *
1055 * @param v the vertex
1056 *
1057 */
1059
1060 /**
1061 * @brief Add a transit to the routing tables
1062 *
1063 * @param v the vertex
1064 */
1066
1067 /**
1068 * @brief Add a stub to the routing tables
1069 *
1070 * @param l the global routing link record
1071 * @param v the vertex
1072 */
1074
1075 /**
1076 * @brief Add an external route to the routing tables
1077 *
1078 * @param extlsa the external LSA
1079 * @param v the vertex
1080 */
1082
1083 /**
1084 * @brief Return the interface number corresponding to a given IP address and mask
1085 *
1086 * This is a wrapper around GetInterfaceForPrefix(), but we first
1087 * have to find the right node pointer to pass to that function.
1088 * If no such interface is found, return -1 (note: unit test framework
1089 * for routing assumes -1 to be a legal return value)
1090 *
1091 * @param a the target IP address
1092 * @param amask the target subnet mask
1093 * @return the outgoing interface number
1094 */
1095 int32_t FindOutgoingInterfaceId(IpAddress a, IpMaskOrPrefix amask = IpMaskOrPrefix::GetOnes());
1096
1097 /**
1098 * @brief given IP it iterates through the node list to find the node associated with the ip
1099 * @param source ip address associated with the node we want to find
1100 * @returns the node pointer to the ip
1101 */
1102 Ptr<Node> GetNodeByIp(const IpAddress& source);
1103
1104 /**
1105 * @brief Is used by PrintRoute() to get the global routing protocol associated with it or
1106 * returns nullptr if not found.
1107 * @param node the node pointer
1108 * @returns the global routing protocol associated with the node
1109 */
1111
1112 /**
1113 * @brief Is used by PrintRoute() to check if the destination is on the source node itself
1114 * @param ip the ip stack of the source node
1115 * @param dest the destination
1116 * @returns true if the destination is on the source node itself
1117 */
1118 bool IsLocalDelivery(Ptr<Ip> ip, IpAddress dest);
1119
1120 /**
1121 * @brief Is used by PrintRoute() to check if the source node has an ipv4 address
1122 * @param ip the ip stack of the source node
1123 * @returns true if the source node has an ipv4 address
1124 */
1126
1127 /**
1128 * @brief Is used by PrintRoute() to check if the destination is on the same subnet as the
1129 * source node
1130 * @param ipCurrentNode the current node
1131 * @param dest the destination
1132 * @returns true if the destination is on the same subnet as the source node
1133 */
1134 bool IsOnSameSubnet(Ptr<Ip> ipCurrentNode, IpAddress dest);
1135};
1136
1137} // namespace ns3
1138
1139#endif /* GLOBAL_ROUTE_MANAGER_IMPL_H */
uint32_t v
A Candidate Queue used in routing calculations.
void SPFProcessStubs(SPFVertex< T > *v)
Process Stub nodes.
typename std::conditional_t< IsIpv4, Ipv4Manager, Ipv6Manager > IpManager
Alias for Ipv4Manager and Ipv6Manager classes.
typename std::conditional_t< IsIpv4, Ipv4InterfaceAddress, Ipv6InterfaceAddress > IpInterfaceAddress
Alias for Ipv4InterfaceAddress and Ipv6InterfaceAddress classes.
int32_t FindOutgoingInterfaceId(IpAddress a, IpMaskOrPrefix amask=IpMaskOrPrefix::GetOnes())
Return the interface number corresponding to a given IP address and mask.
typename std::conditional_t< IsIpv4, Ipv4Route, Ipv6Route > IpRoute
Alias for Ipv4Route and Ipv6Route classes.
void SPFIntraAddTransit(SPFVertex< T > *v)
Add a transit to the routing tables.
typename std::conditional_t< IsIpv4, Ipv4L3Protocol, Ipv6L3Protocol > IpL3Protocol
Alias for Ipv4l3Protocol and Ipv6l3Protocol classes.
GlobalRouteManagerImpl & operator=(const GlobalRouteManagerImpl &)=delete
void SPFIntraAddStub(GlobalRoutingLinkRecord< IpManager > *l, SPFVertex< T > *v)
Add a stub to the routing tables.
void DebugSPFCalculate(IpAddress root)
Debugging routine; call the core SPF from the unit tests.
virtual void BuildGlobalRoutingDatabase()
Build the routing database by gathering Link State Advertisements from each node exporting a GlobalRo...
void PrintRoute(Ptr< Node > sourceNode, Ptr< Node > dest, Ptr< OutputStreamWrapper > stream, bool nodeIdLookup, Time::Unit unit)
prints the path from this node to the destination node at a particular time.
typename std::conditional_t< IsIpv4, Ipv4ListRouting, Ipv6ListRouting > IpListRouting
Alias for Ipv4ListRouting and Ipv6ListRouting classes.
GlobalRoutingLinkRecord< IpManager > * SPFGetNextLink(SPFVertex< T > *v, SPFVertex< T > *w, GlobalRoutingLinkRecord< IpManager > *prev_link)
Search for a link between two vertices.
void SPFCalculate(IpAddress root)
Calculate the shortest path first (SPF) tree.
void SPFNext(SPFVertex< T > *v, CandidateQueue< T > &candidate)
Examine the links in v's LSA and update the list of candidates with any vertices not already on the l...
GlobalRouteManagerImpl(const GlobalRouteManagerImpl &)=delete
void InitializeRouters()
initialize all nodes as routers.
int SPFNexthopCalculation(SPFVertex< T > *v, SPFVertex< T > *w, GlobalRoutingLinkRecord< IpManager > *l, uint32_t distance)
Calculate nexthop from root through V (parent) to vertex W (destination) with given distance from roo...
virtual void InitializeRoutes()
Compute routes using a Dijkstra SPF computation and populate per-node forwarding tables.
Ptr< Node > GetNodeByIp(const IpAddress &source)
given IP it iterates through the node list to find the node associated with the ip
virtual void DeleteGlobalRoutes()
Delete all static routes on all nodes that have a GlobalRouterInterface.
GlobalRouteManagerLSDB< IpManager > * m_lsdb
the Link State DataBase (LSDB) of the Global Route Manager
void SPFVertexAddParent(SPFVertex< T > *v)
Adds a vertex to the list of children in each of its parents.
void SPFIntraAddRouter(SPFVertex< T > *v)
Add a host route to the routing tables.
SPFVertex< T > * m_spfroot
the root node
void DebugUseLsdb(GlobalRouteManagerLSDB< T > *lsdb)
Debugging routine; allow client code to supply a pre-built LSDB.
void SPFAddASExternal(GlobalRoutingLSA< IpManager > *extlsa, SPFVertex< T > *v)
Add an external route to the routing tables.
static constexpr bool IsIpv4
Alias for determining whether the parent is Ipv4RoutingProtocol or Ipv6RoutingProtocol.
bool CheckForStubNode(IpAddress root)
Test if a node is a stub, from an OSPF sense.
typename std::conditional_t< IsIpv4, Ipv4RoutingTableEntry, Ipv6RoutingTableEntry > IpRoutingTableEntry
Alias for Ipv4RoutingTableEntry and Ipv6RoutingTableEntry classes.
typename std::conditional_t< IsIpv4, Ipv4Mask, Ipv6Prefix > IpMaskOrPrefix
Alias for Ipv4Mask And Ipv6Prefix.
typename std::conditional_t< IsIpv4, Ipv4RoutingProtocol, Ipv6RoutingProtocol > IpRoutingProtocol
Alias for Ipv4RoutingProtocol and Ipv6RoutingProtocol classes.
GlobalRouting< IpRoutingProtocol > IpGlobalRouting
Alias for Ipv4GlobalRouting and Ipv6GlobalRouting classes.
bool ValidateSourceNodeHasIpAddress(Ptr< Ip > ip)
Is used by PrintRoute() to check if the source node has an ipv4 address.
Ptr< IpGlobalRouting > GetGlobalRoutingForNode(Ptr< Node > node)
Is used by PrintRoute() to get the global routing protocol associated with it or returns nullptr if n...
bool IsOnSameSubnet(Ptr< Ip > ipCurrentNode, IpAddress dest)
Is used by PrintRoute() to check if the destination is on the same subnet as the source node.
typename std::conditional_t< IsIpv4, Ipv4Header, Ipv6Header > IpHeader
Alias for Ipv4Header and Ipv6Header classes.
bool IsLocalDelivery(Ptr< Ip > ip, IpAddress dest)
Is used by PrintRoute() to check if the destination is on the source node itself.
typename std::conditional_t< IsIpv4, Ipv4, Ipv6 > Ip
Alias for Ipv4 and Ipv6 classes.
typename std::conditional_t< IsIpv4, Ipv4Address, Ipv6Address > IpAddress
Alias for Ipv4Address and Ipv6Address classes.
void ProcessASExternals(SPFVertex< T > *v, GlobalRoutingLSA< IpManager > *extlsa)
Process Autonomous Systems (AS) External LSA.
The Link State DataBase (LSDB) of the Global Route Manager.
typename std::conditional_t< IsIpv4, Ipv4InterfaceAddress, Ipv6InterfaceAddress > IpInterfaceAddress
Alias for Ipv4InterfaceAddress and Ipv6InterfaceAddress classes.
std::pair< IpAddress, GlobalRoutingLSA< IpManager > * > LSDBPair_t
pair of IPv4 addresses / Link State Advertisements
std::map< IpAddress, GlobalRoutingLSA< IpManager > * > LSDBMap_t
container of IPv4 addresses / Link State Advertisements
GlobalRoutingLSA< IpManager > * GetLSA(IpAddress addr) const
Look up the Link State Advertisement associated with the given link state ID (address).
~GlobalRouteManagerLSDB()
Destroy an empty Global Router Manager Link State Database.
GlobalRoutingLSA< IpManager > * GetExtLSA(uint32_t index) const
Look up the External Link State Advertisement associated with the given index.
GlobalRouteManagerLSDB(const GlobalRouteManagerLSDB &)=delete
GlobalRouteManagerLSDB & operator=(const GlobalRouteManagerLSDB &)=delete
uint32_t GetNumExtLSAs() const
Get the number of External Link State Advertisements.
typename std::conditional_t< IsIpv4, Ipv4Header, Ipv6Header > IpHeader
Alias for Ipv4Header and Ipv6Header classes.
typename std::conditional_t< IsIpv4, Ipv4Mask, Ipv6Prefix > IpMaskOrPrefix
Alias for Ipv4Mask And Ipv6Prefix.
void Initialize()
Set all LSA flags to an initialized state, for SPF computation.
GlobalRoutingLSA< IpManager > * GetLSAByLinkData(IpAddress addr) const
Look up the Link State Advertisement associated with the given link state ID (address).
typename std::conditional_t< IsIpv4, Ipv4RoutingTableEntry, Ipv6RoutingTableEntry > IpRoutingTableEntry
Alias for Ipv4RoutingTableEntry and Ipv6RoutingTableEntry classes.
LSDBMap_t m_database
database of IPv4 addresses / Link State Advertisements
std::vector< GlobalRoutingLSA< IpManager > * > m_extdatabase
database of External Link State Advertisements
typename std::conditional_t< IsIpv4, Ipv4, Ipv6 > Ip
Alias for Ipv4 and Ipv6 classes.
typename std::conditional_t< IsIpv4, Ipv4Route, Ipv6Route > IpRoute
Alias for Ipv4Route and Ipv6Route classes.
typename std::conditional_t< IsIpv4, Ipv4Address, Ipv6Address > IpAddress
Alias for Ipv4Address and Ipv6Address classes.
GlobalRouteManagerLSDB()
Construct an empty Global Router Manager Link State Database.
static constexpr bool IsIpv4
Alias for determining whether the parent is Ipv4RoutingProtocol or Ipv6RoutingProtocol.
void Insert(IpAddress addr, GlobalRoutingLSA< IpManager > *lsa)
Insert an IP address / Link State Advertisement pair into the Link State Database.
typename std::conditional_t< IsIpv4, Ipv4Manager, Ipv6Manager > IpManager
Alias for Ipv4Manager and Ipv6Manager classes.
Global routing protocol for IPv4 stacks.
a Link State Advertisement (LSA) for a router, used in global routing.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Vertex used in shortest path first (SPF) computations.
bool m_vertexProcessed
Flag to note whether vertex has been processed in stage two of SPF computation.
SPFVertex & operator=(const SPFVertex &)=delete
VertexType m_vertexType
Vertex type.
SPFVertex * GetParent(uint32_t i=0) const
Get a pointer to the SPFVector that is the parent of "this" SPFVertex.
SPFVertex()
Construct an empty ("uninitialized") SPFVertex (Shortest Path First Vertex).
IpAddress GetVertexId() const
Get the Vertex ID field of a SPFVertex object.
SPFVertex< T > * GetChild(uint32_t n) const
Get a borrowed SPFVertex pointer to the specified child of "this" SPFVertex.
~SPFVertex()
Destroy an SPFVertex (Shortest Path First Vertex).
uint32_t m_distanceFromRoot
Distance from root node.
VertexType
Enumeration of the possible types of SPFVertex objects.
@ VertexNetwork
Vertex representing a network in the topology.
@ VertexUnknown
Uninitialized Link Record.
@ VertexRouter
Vertex representing a router in the topology.
void InheritAllRootExitDirections(const SPFVertex< T > *vertex)
Inherit all root exit directions from a given vertex to 'this' vertex.
GlobalRoutingLSA< IpManager > * m_lsa
Link State Advertisement.
void SetRootExitDirection(IpAddress nextHop, int32_t id=SPF_INFINITY)
Set the IP address and outgoing interface index that should be used to begin forwarding packets from ...
void SetVertexId(IpAddress id)
Set the Vertex ID field of a SPFVertex object.
uint32_t GetDistanceFromRoot() const
Get the distance from the root vertex to "this" SPFVertex object.
typename std::conditional_t< IsIpv4, Ipv4, Ipv6 > Ip
Alias for Ipv4 and Ipv6 classes.
IpAddress m_nextHop
next hop
typename std::conditional_t< IsIpv4, Ipv4Route, Ipv6Route > IpRoute
Alias for Ipv4Route and Ipv6Route classes.
bool IsVertexProcessed() const
Check the value of the VertexProcessed flag.
void SetDistanceFromRoot(uint32_t distance)
Set the distance from the root vertex to "this" SPFVertex object.
typename std::conditional_t< IsIpv4, Ipv4RoutingTableEntry, Ipv6RoutingTableEntry > IpRoutingTableEntry
Alias for Ipv4RoutingTableEntry and Ipv6RoutingTableEntry classes.
void SetRootExitDirection(SPFVertex::NodeExit_t exit)
Set the IP address and outgoing interface index that should be used to begin forwarding packets from ...
typename std::conditional_t< IsIpv4, Ipv4Manager, Ipv6Manager > IpManager
Alias for Ipv4Manager and Ipv6Manager classes.
ListOfNodeExit_t m_ecmpRootExits
store the multiple root's exits for supporting ECMP
Ptr< Node > m_node
node pointer corresponding to the this Vertex
void SetVertexType(VertexType type)
Set the Vertex Type field of a SPFVertex object.
typename std::conditional_t< IsIpv4, Ipv4Address, Ipv6Address > IpAddress
Alias for Ipv4Address and Ipv6Address classes.
uint32_t AddChild(SPFVertex< T > *child)
Get a borrowed SPFVertex pointer to the specified child of "this" SPFVertex.
uint32_t GetNChildren() const
Get the number of children of "this" SPFVertex.
typename std::conditional_t< IsIpv4, Ipv4Header, Ipv6Header > IpHeader
Alias for Ipv4Header and Ipv6Header classes.
int32_t m_rootOif
root Output Interface
std::list< SPFVertex< T > * > ListOfSPFVertex_t
container of SPFVertex items
uint32_t GetNRootExitDirections() const
Get the number of exit directions from root for reaching 'this' vertex.
void SetLSA(GlobalRoutingLSA< IpManager > *lsa)
Set the Global Router Link State Advertisement returned by the Global Router represented by this SPFV...
void MergeParent(const SPFVertex< T > *v)
Merge the Parent list from the v into this vertex.
GlobalRoutingLSA< T > * GetLSA() const
Get the Global Router Link State Advertisement returned by the Global Router represented by this SPFV...
friend std::ostream & operator<<(std::ostream &os, const typename SPFVertex< T >::ListOfSPFVertex_t &vs)
Stream insertion operator.
void MergeRootExitDirections(const SPFVertex< T > *vertex)
Merge into 'this' vertex the list of exit directions from another vertex.
void SetVertexProcessed(bool value)
Set the value of the VertexProcessed flag.
static constexpr bool IsIpv4
Alias for determining whether the parent is Ipv4RoutingProtocol or Ipv6RoutingProtocol.
std::list< NodeExit_t > ListOfNodeExit_t
container of Exit nodes
VertexType GetVertexType() const
Get the Vertex Type field of a SPFVertex object.
typename std::conditional_t< IsIpv4, Ipv4InterfaceAddress, Ipv6InterfaceAddress > IpInterfaceAddress
Alias for Ipv4InterfaceAddress and Ipv6InterfaceAddress classes.
SPFVertex(const SPFVertex &)=delete
void ClearVertexProcessed()
Clear the value of the VertexProcessed flag.
IpAddress m_vertexId
Vertex ID.
NodeExit_t GetRootExitDirection() const
Obtain a pair indicating the exit direction from the root.
std::pair< IpAddress, int32_t > NodeExit_t
IPv4 / interface container for exit nodes.
typename std::conditional_t< IsIpv4, Ipv4Mask, Ipv6Prefix > IpMaskOrPrefix
Alias for Ipv4Mask And Ipv6Prefix.
void SetParent(SPFVertex< T > *parent)
Set the pointer to the SPFVector that is the parent of "this" SPFVertex.
ListOfSPFVertex_t m_parents
parent list
Ptr< Node > GetNode() const
Get the node pointer corresponding to this Vertex.
ListOfSPFVertex_t m_children
Children list.
Unit
The unit to use to interpret a number representing time.
Definition nstime.h:101
Every class exported by the ns3 library is enclosed in the ns3 namespace.
const uint32_t SPF_INFINITY
"infinite" distance between nodes