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