A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
global-router-interface.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_ROUTER_INTERFACE_H
11#define GLOBAL_ROUTER_INTERFACE_H
12
16#include "ipv6-l3-protocol.h"
19#include "ipv6.h"
20
21#include "ns3/bridge-net-device.h"
22#include "ns3/channel.h"
23#include "ns3/ipv4-address.h"
24#include "ns3/net-device-container.h"
25#include "ns3/node.h"
26#include "ns3/object.h"
27#include "ns3/ptr.h"
28
29#include <list>
30#include <stdint.h>
31
32namespace ns3
33{
34template <typename T>
35class GlobalRouter;
36template <typename>
37class GlobalRouting;
38
39/**
40 * @ingroup globalrouting
41 *
42 * @brief A single link record for a link state advertisement.
43 *
44 * The GlobalRoutingLinkRecord is modeled after the OSPF link record field of
45 * a Link State Advertisement. Right now we will only see two types of link
46 * records corresponding to a stub network and a point-to-point link (channel).
47 */
48template <typename T>
50{
51 static_assert(
52 std::is_same_v<T, Ipv4Manager> || std::is_same_v<T, Ipv6Manager>,
53 "T must be either Ipv4Manager or Ipv6Manager when calling GlobalRoutingLinkRecord");
54 /// Alias for determining whether the parent is Ipv4RoutingProtocol or Ipv6RoutingProtocol
55 static constexpr bool IsIpv4 = std::is_same_v<Ipv4Manager, T>;
56
57 /// Alias for Ipv4 and Ipv6 classes
58 using Ip = typename std::conditional_t<IsIpv4, Ipv4, Ipv6>;
59
60 /// Alias for Ipv4Address and Ipv6Address classes
61 using IpAddress = typename std::conditional_t<IsIpv4, Ipv4Address, Ipv6Address>;
62
63 /// Alias for Ipv4Route and Ipv6Route classes
64 using IpRoute = typename std::conditional_t<IsIpv4, Ipv4Route, Ipv6Route>;
65
66 /// Alias for Ipv4Header and Ipv6Header classes
67 using IpHeader = typename std::conditional_t<IsIpv4, Ipv4Header, Ipv6Header>;
68
69 /// Alias for Ipv4InterfaceAddress and Ipv6InterfaceAddress classes
71 typename std::conditional_t<IsIpv4, Ipv4InterfaceAddress, Ipv6InterfaceAddress>;
72
73 /// Alias for Ipv4RoutingTableEntry and Ipv6RoutingTableEntry classes
75 typename std::conditional_t<IsIpv4, Ipv4RoutingTableEntry, Ipv6RoutingTableEntry>;
76
77 /// Alias for Ipv4Mask And Ipv6Prefix
78 using IpMaskOrPrefix = typename std::conditional_t<IsIpv4, Ipv4Mask, Ipv6Prefix>;
79
80 public:
81 template <typename>
82 friend class GlobalRoutingLSA; //!< Friend class.
83
84 /**
85 * @enum LinkType
86 * @brief Enumeration of the possible types of Global Routing Link Records.
87 *
88 * These values are defined in the OSPF spec. We currently only use
89 * PointToPoint and StubNetwork types.
90 */
92 {
93 Unknown = 0, /**< Uninitialized Link Record */
94 PointToPoint, /**< Record representing a point to point channel */
95 TransitNetwork, /**< Unused -- for future OSPF compatibility */
96 StubNetwork, /**< Record represents a leaf node network */
97 VirtualLink /**< Unused -- for future OSPF compatibility */
98 };
99
100 /**
101 * @brief Construct an empty ("uninitialized") Global Routing Link Record.
102 *
103 * The Link ID and Link Data Ipv4 addresses are set to "0.0.0.0";
104 * The Link Type is set to Unknown;
105 * The metric is set to 0.
106 */
108
109 /**
110 * Construct an initialized Global Routing Link Record.
111 *
112 * @param linkType The type of link record to construct.
113 * @param linkId The link ID for the record.
114 * @param linkData The link data field for the record.
115 * @param metric The metric field for the record.
116 * @see LinkType
117 * @see SetLinkId
118 * @see SetLinkData
119 */
120 GlobalRoutingLinkRecord(LinkType linkType,
121 IpAddress linkId,
122 IpAddress linkData,
123 uint16_t metric);
124
125 /**
126 * Construct an initialized Global Routing Link Record.
127 *
128 * @param linkType The type of link record to construct.
129 * @param linkId The link ID for the record.
130 * @param linkData The link data field for the record.
131 * @param linkLocData The link local data field for the record.
132 * @param metric The metric field for the record.
133 * @see LinkType
134 * @see SetLinkId
135 * @see SetLinkData
136 */
137 GlobalRoutingLinkRecord(LinkType linkType,
138 IpAddress linkId,
139 IpAddress linkData,
140 IpAddress linkLocData,
141 uint16_t metric);
142
143 /**
144 * @brief Destroy a Global Routing Link Record.
145 *
146 * Currently does nothing. Here as a placeholder only.
147 */
149
150 /**
151 * Get the Link ID field of the Global Routing Link Record.
152 *
153 * For an OSPF type 1 link (PointToPoint) the Link ID will be the Router ID
154 * of the neighboring router.
155 *
156 * For an OSPF type 3 link (StubNetwork), the Link ID will be the adjacent
157 * neighbor's IP address
158 *
159 * @returns The Ipv4Address corresponding to the Link ID field of the record.
160 */
161 IpAddress GetLinkId() const;
162
163 /**
164 * @brief Set the Link ID field of the Global Routing Link Record.
165 *
166 * For an OSPF type 1 link (PointToPoint) the Link ID must be the Router ID
167 * of the neighboring router.
168 *
169 * For an OSPF type 3 link (StubNetwork), the Link ID must be the adjacent
170 * neighbor's IP address
171 *
172 * @param addr An Ipv4Address to store in the Link ID field of the record.
173 */
174 void SetLinkId(IpAddress addr);
175
176 /**
177 * @brief Get the Link Data field of the Global Routing Link Record.
178 *
179 * For an OSPF type 1 link (PointToPoint) the Link Data will be the IP
180 * address of the node of the local side of the link.
181 *
182 * For an OSPF type 3 link (StubNetwork), the Link Data will be the
183 * network mask
184 *
185 * @returns The Ipv4Address corresponding to the Link Data field of the record.
186 */
187 IpAddress GetLinkData() const;
188
189 /**
190 * @brief Set the Link Data field of the Global Routing Link Record.
191 *
192 * For an OSPF type 1 link (PointToPoint) the Link Data must be the IP
193 * address of the node of the local side of the link.
194 *
195 * For an OSPF type 3 link (StubNetwork), the Link Data must be set to the
196 * network mask
197 *
198 * @param addr An Ipv4Address to store in the Link Data field of the record.
199 */
200 void SetLinkData(IpAddress addr);
201
202 /**
203 * @brief Get the Link Type field of the Global Routing Link Record.
204 *
205 * The Link Type describes the kind of link a given record represents. The
206 * values are defined by OSPF.
207 *
208 * @see LinkType
209 * @returns The LinkType of the current Global Routing Link Record.
210 */
211 LinkType GetLinkType() const;
212
213 /**
214 * @brief Set the Link Type field of the Global Routing Link Record.
215 *
216 * The Link Type describes the kind of link a given record represents. The
217 * values are defined by OSPF.
218 *
219 * @see LinkType
220 * @param linkType The new LinkType for the current Global Routing Link Record.
221 */
222 void SetLinkType(LinkType linkType);
223
224 /**
225 * @brief Get the Metric Data field of the Global Routing Link Record.
226 *
227 * The metric is an abstract cost associated with forwarding a packet across
228 * a link. A sum of metrics must have a well-defined meaning. That is, you
229 * shouldn't use bandwidth as a metric (how does the sum of the bandwidth of
230 * two hops relate to the cost of sending a packet); rather you should use
231 * something like delay.
232 *
233 * @returns The metric field of the Global Routing Link Record.
234 */
235 uint16_t GetMetric() const;
236
237 /**
238 * @brief Set the Metric Data field of the Global Routing Link Record.
239 *
240 * The metric is an abstract cost associated with forwarding a packet across
241 * a link. A sum of metrics must have a well-defined meaning. That is, you
242 * shouldn't use bandwidth as a metric (how does the sum of the bandwidth of
243 * two hops relate to the cost of sending a packet); rather you should use
244 * something like delay.
245 *
246 * @param metric The new metric for the current Global Routing Link Record.
247 */
248 void SetMetric(uint16_t metric);
249
250 /**
251 * @brief Set the Link Local Data field of the Global Routing Link Record.
252 *
253 * For an OSPF type 1 link (PointToPoint) the Link Local Data must be the Link Local IP
254 * address of the node of the local side of the link.
255 *
256 * For an OSPF type 3 link (StubNetwork), the Link Local data field is not used.
257 *
258 * @param addr An Ipv6Address to store in the Link Data field of the record.
259 */
260 void SetLinkLocData(IpAddress addr);
261
262 /**
263 * @brief Set the Link Local Data field of the Global Routing Link Record.
264 *
265 * For an OSPF type 1 link (PointToPoint) the Link Local Data must be the Link Local IP
266 * address of the node of the local side of the link.
267 *
268 * For an OSPF type 3 link (StubNetwork), the Link Local data field is not used.
269 *
270 * @returns addr An Ipv6Address to store in the Link Data field of the record.
271 */
273
274 private:
275 /**
276 * m_linkId and m_linkData are defined by OSPF to have different meanings
277 * depending on the type of link a given link records represents. They work
278 * together.
279 *
280 * For Type 1 link (PointToPoint), set m_linkId to Router ID of
281 * neighboring router.
282 *
283 * For Type 3 link (Stub), set m_linkId to neighbor's IP address
284 */
286
287 /**
288 * m_linkId and m_linkData are defined by OSPF to have different meanings
289 * depending on the type of link a given link records represents. They work
290 * together.
291 *
292 * For Type 1 link (PointToPoint), set m_linkData to local IP address
293 *
294 * For Type 3 link (Stub), set m_linkData to mask
295 */
296 IpAddress m_linkData; // for links to RouterLSA,
297
298 /**
299 * m_linkLocData is not defined by the OSPF spec. This field is used to store the link local
300 * address associated with the link on the local side.
301 *
302 * For Type 1 link (PointToPoint), set m_linkLocData to Link local IP address on the local side
303 *
304 * For Type 3 link (Stub), this is not used.
305 */
307 m_linkLocData; // for the Link local address associated with the link on the local side
308
309 /**
310 * The type of the Global Routing Link Record. Defined in the OSPF spec.
311 * We currently only use PointToPoint and StubNetwork types.
312 */
314
315 /**
316 * The metric for a given link.
317 *
318 * A metric is abstract cost associated with forwarding a packet across a
319 * link. A sum of metrics must have a well-defined meaning. That is, you
320 * shouldn't use bandwidth as a metric (how does the sum of the bandwidth
321 * of two hops relate to the cost of sending a packet); rather you should
322 * use something like delay.
323 */
324 uint16_t m_metric;
325};
326
327/**
328 * @brief a Link State Advertisement (LSA) for a router, used in global
329 * routing.
330 *
331 * Roughly equivalent to a global incarnation of the OSPF link state header
332 * combined with a list of Link Records. Since it's global, there's
333 * no need for age or sequence number. See \RFC{2328}, Appendix A.
334 */
335template <typename T>
337{
338 static_assert(std::is_same_v<T, Ipv4Manager> || std::is_same_v<T, Ipv6Manager>,
339 "T must be either Ipv4Manager or Ipv6Manager when calling GlobalRoutingLSA");
340 /// Alias for determining whether the parent is Ipv4RoutingProtocol or Ipv6RoutingProtocol
341 static constexpr bool IsIpv4 = std::is_same_v<Ipv4Manager, T>;
342
343 /// Alias for Ipv4 and Ipv6 classes
344 using Ip = typename std::conditional_t<IsIpv4, Ipv4, Ipv6>;
345
346 /// Alias for Ipv4Address and Ipv6Address classes
347 using IpAddress = typename std::conditional_t<IsIpv4, Ipv4Address, Ipv6Address>;
348
349 /// Alias for Ipv4Route and Ipv6Route classes
350 using IpRoute = typename std::conditional_t<IsIpv4, Ipv4Route, Ipv6Route>;
351
352 /// Alias for Ipv4Header and Ipv6Header classes
353 using IpHeader = typename std::conditional_t<IsIpv4, Ipv4Header, Ipv6Header>;
354
355 /// Alias for Ipv4InterfaceAddress and Ipv6InterfaceAddress classes
357 typename std::conditional_t<IsIpv4, Ipv4InterfaceAddress, Ipv6InterfaceAddress>;
358
359 /// Alias for Ipv4RoutingTableEntry and Ipv6RoutingTableEntry classes
361 typename std::conditional_t<IsIpv4, Ipv4RoutingTableEntry, Ipv6RoutingTableEntry>;
362
363 /// Alias for Ipv4Mask And Ipv6Prefix
364 using IpMaskOrPrefix = typename std::conditional_t<IsIpv4, Ipv4Mask, Ipv6Prefix>;
365
366 public:
367 /**
368 * @enum LSType
369 * @brief corresponds to LS type field of \RFC{2328} OSPF LSA header
370 */
380
381 /**
382 * @enum SPFStatus
383 * @brief Enumeration of the possible values of the status flag in the Routing
384 * Link State Advertisements.
385 */
387 {
388 LSA_SPF_NOT_EXPLORED = 0, /**< New vertex not yet considered */
389 LSA_SPF_CANDIDATE, /**< Vertex is in the SPF candidate queue */
390 LSA_SPF_IN_SPFTREE /**< Vertex is in the SPF tree */
391 };
392
393 /**
394 * @brief Create a blank Global Routing Link State Advertisement.
395 *
396 * On completion Ipv4Address variables initialized to 0.0.0.0 and the
397 * list of Link State Records is empty.
398 */
400
401 /**
402 * @brief Create an initialized Global Routing Link State Advertisement.
403 *
404 * On completion the list of Link State Records is empty.
405 *
406 * @param status The status to of the new LSA.
407 * @param linkStateId The Ipv4Address for the link state ID field.
408 * @param advertisingRtr The Ipv4Address for the advertising router field.
409 */
410 GlobalRoutingLSA(SPFStatus status, IpAddress linkStateId, IpAddress advertisingRtr);
411
412 /**
413 * @brief Copy constructor for a Global Routing Link State Advertisement.
414 *
415 * Takes a piece of memory and constructs a semantically identical copy of
416 * the given LSA.
417 *
418 * @param lsa The existing LSA to be used as the source.
419 */
421
422 /**
423 * @brief Destroy an existing Global Routing Link State Advertisement.
424 *
425 * Any Global Routing Link Records present in the list are freed.
426 */
428
429 /**
430 * @brief Assignment operator for a Global Routing Link State Advertisement.
431 *
432 * Takes an existing Global Routing Link State Advertisement and overwrites
433 * it to make a semantically identical copy of a given prototype LSA.
434 *
435 * If there are any Global Routing Link Records present in the existing
436 * LSA, they are freed before the assignment happens.
437 *
438 * @param lsa The existing LSA to be used as the source.
439 * @returns Reference to the overwritten LSA.
440 */
442
443 /**
444 * @brief Copy any Global Routing Link Records in a given Global Routing Link
445 * State Advertisement to the current LSA.
446 *
447 * Existing Link Records are not deleted -- this is a concatenation of Link
448 * Records.
449 *
450 * @see ClearLinkRecords ()
451 * @param lsa The LSA to copy the Link Records from.
452 */
453 void CopyLinkRecords(const GlobalRoutingLSA& lsa);
454
455 /**
456 * @brief Add a given Global Routing Link Record to the LSA.
457 *
458 * @param lr The Global Routing Link Record to be added.
459 * @returns The number of link records in the list.
460 */
462
463 /**
464 * @brief Return the number of Global Routing Link Records in the LSA.
465 *
466 * @returns The number of link records in the list.
467 */
469
470 /**
471 * @brief Return a pointer to the specified Global Routing Link Record.
472 *
473 * @param n The LSA number desired.
474 * @returns The number of link records in the list.
475 */
477
478 /**
479 * @brief Release all of the Global Routing Link Records present in the Global
480 * Routing Link State Advertisement and make the list of link records empty.
481 */
482 void ClearLinkRecords();
483
484 /**
485 * @brief Check to see if the list of Global Routing Link Records present in the
486 * Global Routing Link State Advertisement is empty.
487 *
488 * @returns True if the list is empty, false otherwise.
489 */
490 bool IsEmpty() const;
491
492 /**
493 * @brief Print the contents of the Global Routing Link State Advertisement and
494 * any Global Routing Link Records present in the list. Quite verbose.
495 * @param os the output stream
496 */
497 void Print(std::ostream& os) const;
498
499 /**
500 * @brief Return the LSType field of the LSA
501 * @returns The LS Type.
502 */
503 LSType GetLSType() const;
504 /**
505 * @brief Set the LS type field of the LSA
506 * @param typ the LS Type.
507 */
508 void SetLSType(LSType typ);
509
510 /**
511 * @brief Get the Link State ID as defined by the OSPF spec. We always set it
512 * to the router ID of the router making the advertisement.
513 *
514 * @see RoutingEnvironment::AllocateRouterId ()
515 * @see GlobalRouting::GetRouterId ()
516 * @returns The Ipv4Address stored as the link state ID.
517 */
519
520 /**
521 * @brief Set the Link State ID is defined by the OSPF spec. We always set it
522 * to the router ID of the router making the advertisement.
523 * @param addr IPv4 address which will act as ID
524 * @see RoutingEnvironment::AllocateRouterId ()
525 * @see GlobalRouting::GetRouterId ()
526 */
527 void SetLinkStateId(IpAddress addr);
528
529 /**
530 * @brief Get the Advertising Router as defined by the OSPF spec. We always
531 * set it to the router ID of the router making the advertisement.
532 *
533 * @see RoutingEnvironment::AllocateRouterId ()
534 * @see GlobalRouting::GetRouterId ()
535 * @returns The Ipv4Address stored as the advertising router.
536 */
538
539 /**
540 * @brief Set the Advertising Router as defined by the OSPF spec. We always
541 * set it to the router ID of the router making the advertisement.
542 *
543 * @param rtr ID of the router making advertisement
544 * @see RoutingEnvironment::AllocateRouterId ()
545 * @see GlobalRouting::GetRouterId ()
546 */
548
549 /**
550 * @brief For a Network LSA, set the Network Mask field that precedes
551 * the list of attached routers.
552 * @param mask the Network Mask field.
553 */
555
556 /**
557 * @brief For a Network LSA, get the Network Mask field that precedes
558 * the list of attached routers.
559 *
560 * @returns the NetworkLSANetworkMask
561 */
563
564 /**
565 * @brief Add an attached router to the list in the NetworkLSA
566 *
567 * @param addr The Ipv4Address of the interface on the network link
568 * @returns The number of addresses in the list.
569 */
571
572 /**
573 * @brief Return the number of attached routers listed in the NetworkLSA
574 *
575 * @returns The number of attached routers.
576 */
578
579 /**
580 * @brief Return an Ipv4Address corresponding to the specified attached router
581 *
582 * @param n The attached router number desired (number in the list).
583 * @returns The Ipv4Address of the requested router
584 */
586
587 /**
588 * @brief Get the SPF status of the advertisement.
589 *
590 * @see SPFStatus
591 * @returns The SPFStatus of the LSA.
592 */
593 SPFStatus GetStatus() const;
594
595 /**
596 * @brief Set the SPF status of the advertisement
597 * @param status SPF status to set
598 * @see SPFStatus
599 */
600 void SetStatus(SPFStatus status);
601
602 /**
603 * @brief Get the Node pointer of the node that originated this LSA
604 * @returns Node pointer
605 */
606 Ptr<Node> GetNode() const;
607
608 /**
609 * @brief Set the Node pointer of the node that originated this LSA
610 * @param node Node pointer
611 */
612 void SetNode(Ptr<Node> node);
613
614 private:
615 /**
616 * The type of the LSA. Each LSA type has a separate advertisement
617 * format.
618 */
620 /**
621 * The Link State ID is defined by the OSPF spec. We always set it to the
622 * router ID of the router making the advertisement.
623 *
624 * @see RoutingEnvironment::AllocateRouterId ()
625 * @see GlobalRouting::GetRouterId ()
626 */
628
629 /**
630 * The Advertising Router is defined by the OSPF spec. We always set it to
631 * the router ID of the router making the advertisement.
632 *
633 * @see RoutingEnvironment::AllocateRouterId ()
634 * @see GlobalRouting::GetRouterId ()
635 */
637
638 /**
639 * A convenience typedef to avoid too much writers cramp.
640 */
641 typedef std::list<GlobalRoutingLinkRecord<T>*> ListOfLinkRecords_t;
642
643 /**
644 * Each Link State Advertisement contains a number of Link Records that
645 * describe the kinds of links that are attached to a given node. We
646 * consider PointToPoint and StubNetwork links.
647 *
648 * m_linkRecords is an STL list container to hold the Link Records that have
649 * been discovered and prepared for the advertisement.
650 *
651 * @see GlobalRouting::DiscoverLSAs ()
652 */
654
655 /**
656 * Each Network LSA contains the network mask of the attached network
657 */
659
660 /**
661 * A convenience typedef to avoid too much writers cramp.
662 */
663 typedef std::list<IpAddress> ListOfAttachedRouters_t;
664
665 /**
666 * Each Network LSA contains a list of attached routers
667 *
668 * m_attachedRouters is an STL list container to hold the addresses that have
669 * been discovered and prepared for the advertisement.
670 *
671 * @see GlobalRouting::DiscoverLSAs ()
672 */
674
675 /**
676 * This is a tristate flag used internally in the SPF computation to mark
677 * if an SPFVertex (a data structure representing a vertex in the SPF tree
678 * -- a router) is new, is a candidate for a shortest path, or is in its
679 * proper position in the tree.
680 */
682 uint32_t m_node_id; //!< node ID
683};
684
685/**
686 * @brief Stream insertion operator.
687 *
688 * @param os the reference to the output stream
689 * @param lsa the LSA
690 * @returns the reference to the output stream
691 */
692template <typename T>
693std::ostream& operator<<(std::ostream& os, GlobalRoutingLSA<T>& lsa);
694
695/**
696 * @brief An interface aggregated to a node to provide global routing info
697 *
698 * An interface aggregated to a node that provides global routing information
699 * to a global route manager. The presence of the interface indicates that
700 * the node is a router. The interface is the mechanism by which the router
701 * advertises its connections to neighboring routers. We're basically
702 * allowing the route manager to query for link state advertisements.
703 */
704template <typename T>
705class GlobalRouter : public Object
706{
707 static_assert(std::is_same_v<T, Ipv4Manager> || std::is_same_v<T, Ipv6Manager>,
708 "T must be either Ipv4Manager or Ipv6Manager when calling GlobalRouter");
709
710 /// Alias for determining whether the parent is Ipv4RoutingProtocol or Ipv6RoutingProtocol
711 static constexpr bool IsIpv4 = std::is_same_v<Ipv4Manager, T>;
712
713 /// Alias for Ipv4 and Ipv6 classes
714 using Ip = typename std::conditional_t<IsIpv4, Ipv4, Ipv6>;
715
716 /// Alias for Ipv4Address and Ipv6Address classes
717 using IpAddress = typename std::conditional_t<IsIpv4, Ipv4Address, Ipv6Address>;
718
719 /// Alias for Ipv4Route and Ipv6Route classes
720 using IpRoute = typename std::conditional_t<IsIpv4, Ipv4Route, Ipv6Route>;
721
722 /// Alias for Ipv4Header and Ipv6Header classes
723 using IpHeader = typename std::conditional_t<IsIpv4, Ipv4Header, Ipv6Header>;
724
725 /// Alias for Ipv4InterfaceAddress and Ipv6InterfaceAddress classes
727 typename std::conditional_t<IsIpv4, Ipv4InterfaceAddress, Ipv6InterfaceAddress>;
728
729 /// Alias for Ipv4RoutingTableEntry and Ipv6RoutingTableEntry classes
731 typename std::conditional_t<IsIpv4, Ipv4RoutingTableEntry, Ipv6RoutingTableEntry>;
732
733 /// Alias for Ipv4Mask And Ipv6Prefix
734 using IpMaskOrPrefix = typename std::conditional_t<IsIpv4, Ipv4Mask, Ipv6Prefix>;
735
736 /// Alias for Ipv4RoutingProtocol and Ipv6RoutingProtocol classes
738 typename std::conditional_t<IsIpv4, Ipv4RoutingProtocol, Ipv6RoutingProtocol>;
739
740 public:
741 /**
742 * @brief Get the type ID.
743 * @return the object TypeId
744 */
746
747 /**
748 * @brief Create a Global Router class
749 */
751
752 // Delete copy constructor and assignment operator to avoid misuse
753 GlobalRouter(const GlobalRouter&) = delete;
755
756 /**
757 * @brief Set the specific Global Routing Protocol to be used
758 * @param routing the routing protocol
759 */
761
762 /**
763 * @brief Get the specific Global Routing Protocol used
764 * @returns the routing protocol
765 */
767
768 /**
769 * @brief Get the Router ID associated with this Global Router.
770 *
771 * The Router IDs are allocated in the RoutingEnvironment -- one per Router,
772 * starting at 0.0.0.1 and incrementing with each instantiation of a router.
773 *
774 * @see RoutingEnvironment::AllocateRouterId ()
775 * @returns The Router ID associated with the Global Router.
776 */
778
779 /**
780 * @brief Walk the connected channels, discover the adjacent routers and build
781 * the associated number of Global Routing Link State Advertisements that
782 * this router can export.
783 *
784 * This is a fairly expensive operation in that every time it is called
785 * the current list of LSAs is built by walking connected point-to-point
786 * channels and peeking into adjacent IPV4 stacks to get address information.
787 * This is done to allow for limited dynamics of the Global Routing
788 * environment. By that we mean that you can discover new link state
789 * advertisements after a network topology change by calling DiscoverLSAs
790 * and then by reading those advertisements.
791 *
792 * @see GlobalRoutingLSA
793 * @see GlobalRouter::GetLSA ()
794 * @returns The number of Global Routing Link State Advertisements.
795 */
797
798 /**
799 * @brief Get the Number of Global Routing Link State Advertisements that this
800 * router can export.
801 *
802 * To get meaningful information you must have previously called DiscoverLSAs.
803 * After you know how many LSAs are present in the router, you may call
804 * GetLSA () to retrieve the actual advertisement.
805 *
806 * @see GlobalRouterLSA
807 * @see GlobalRouting::DiscoverLSAs ()
808 * @see GlobalRouting::GetLSA ()
809 * @returns The number of Global Routing Link State Advertisements.
810 */
812
813 /**
814 * @brief Get a Global Routing Link State Advertisements that this router has
815 * said that it can export.
816 *
817 * This is a fairly inexpensive expensive operation in that the hard work
818 * was done in GetNumLSAs. We just copy the indicated Global Routing Link
819 * State Advertisement into the requested GlobalRoutingLSA object.
820 *
821 * You must call GlobalRouter::GetNumLSAs before calling this method in
822 * order to discover the adjacent routers and build the advertisements.
823 * GetNumLSAs will return the number of LSAs this router advertises.
824 * The parameter n (requested LSA number) must be in the range 0 to
825 * GetNumLSAs() - 1.
826 *
827 * @see GlobalRoutingLSA
828 * @see GlobalRouting::GetNumLSAs ()
829 * @param n The index number of the LSA you want to read.
830 * @param lsa The GlobalRoutingLSA class to receive the LSA information.
831 * @returns The number of Global Router Link State Advertisements.
832 */
834
835 /**
836 * @brief Inject a route to be circulated to other routers as an external
837 * route
838 *
839 * @param network The Network to inject
840 * @param networkMask The Network Mask to inject
841 */
842 void InjectRoute(IpAddress network, IpMaskOrPrefix networkMask);
843
844 /**
845 * @brief Get the number of injected routes that have been added
846 * to the routing table.
847 * @return number of injected routes
848 */
850
851 /**
852 * @brief Return the injected route indexed by i
853 * @param i the index of the route
854 * @return a pointer to that Ipv4RoutingTableEntry is returned
855 *
856 */
858
859 /**
860 * @brief Withdraw a route from the global unicast routing table.
861 *
862 * Calling this function will cause all indexed routes numbered above
863 * index i to have their index decremented. For instance, it is possible to
864 * remove N injected routes by calling RemoveInjectedRoute (0) N times.
865 *
866 * @param i The index (into the injected routing list) of the route to remove.
867 *
868 * @see GlobalRouter::WithdrawRoute ()
869 */
871
872 /**
873 * @brief Withdraw a route from the global unicast routing table.
874 *
875 * @param network The Network to withdraw
876 * @param networkMask The Network Mask to withdraw
877 * @return whether the operation succeeded (will return false if no such route)
878 *
879 * @see GlobalRouter::RemoveInjectedRoute ()
880 */
881 bool WithdrawRoute(IpAddress network, IpMaskOrPrefix networkMask);
882
883 private:
884 ~GlobalRouter() override;
885
886 /**
887 * @brief Clear list of LSAs
888 */
889 void ClearLSAs();
890
891 /**
892 * @brief Link through the given channel and find the net device that's on the other end.
893 *
894 * This only makes sense with a point-to-point channel.
895 *
896 * @param nd outgoing NetDevice
897 * @param ch channel
898 * @returns the NetDevice on the other end
899 */
901
902 /**
903 * @brief Finds a designated router
904 *
905 * Given a local net device, we need to walk the channel to which the net device is
906 * attached and look for nodes with GlobalRouter interfaces on them (one of them
907 * will be us). Of these, the router with the lowest IP address on the net device
908 * connecting to the channel becomes the designated router for the link.
909 *
910 * @param ndLocal local NetDevice to scan
911 * @returns the IP address of the designated router
912 */
914
915 /**
916 * @brief Checks for the presence of another router on the NetDevice
917 *
918 * Given a node and an attached net device, take a look off in the channel to
919 * which the net device is attached and look for a node on the other side
920 * that has a GlobalRouter interface aggregated.
921 *
922 * @param nd NetDevice to scan
923 * @returns true if a router is found
924 */
926
927 /**
928 * @brief Process a generic broadcast link
929 *
930 * @param nd the NetDevice
931 * @param pLSA the Global LSA
932 * @param c the returned NetDevice container
933 */
935
936 /**
937 * @brief Process a single broadcast link
938 *
939 * @param nd the NetDevice
940 * @param pLSA the Global LSA
941 * @param c the returned NetDevice container
942 */
946
947 /**
948 * @brief Process a bridged broadcast link
949 *
950 * @param nd the NetDevice
951 * @param pLSA the Global LSA
952 * @param c the returned NetDevice container
953 */
957
958 /**
959 * @brief Process a point to point link
960 *
961 * @param ndLocal the NetDevice
962 * @param pLSA the Global LSA
963 */
965
966 /**
967 * @brief Build one NetworkLSA for each net device talking to a network that we are the
968 * designated router for.
969 *
970 * @param c the devices.
971 */
973
974 /**
975 * @brief Return a container of all non-bridged NetDevices on a link
976 *
977 * This method will recursively find all of the 'edge' devices in an
978 * L2 broadcast domain. If there are no bridged devices, then the
979 * container returned is simply the set of devices on the channel
980 * passed in as an argument. If the link has bridges on it
981 * (and therefore multiple ns3::Channel objects interconnected by
982 * bridges), the method will find all of the non-bridged devices
983 * in the L2 broadcast domain.
984 *
985 * @param ch a channel from the link
986 * @returns the NetDeviceContainer.
987 */
989
990 /**
991 * @brief Decide whether or not a given net device is being bridged by a BridgeNetDevice.
992 *
993 * @param nd the NetDevice
994 * @returns the BridgeNetDevice smart pointer or null if not found
995 */
997
998 typedef std::list<GlobalRoutingLSA<T>*> ListOfLSAs_t; //!< container for the GlobalRoutingLSAs
999 ListOfLSAs_t m_LSAs; //!< database of GlobalRoutingLSAs
1000
1001 IpAddress m_routerId; //!< router ID (its IPv4 address)
1003
1004 typedef std::list<IpRoutingTableEntry*> InjectedRoutes; //!< container of Ipv4RoutingTableEntry
1005 typedef std::list<IpRoutingTableEntry*>::const_iterator
1006 InjectedRoutesCI; //!< Const Iterator to container of Ipv4RoutingTableEntry
1007 typedef std::list<IpRoutingTableEntry*>::iterator
1008 InjectedRoutesI; //!< Iterator to container of Ipv4RoutingTableEntry
1009 InjectedRoutes m_injectedRoutes; //!< Routes we are exporting
1010
1011 // Declared mutable so that const member functions can clear it
1012 // (supporting the logical constness of the search methods of this class)
1013 /**
1014 * Container of bridges visited.
1015 */
1016 mutable std::vector<Ptr<BridgeNetDevice>> m_bridgesVisited;
1017 /**
1018 * Clear the list of bridges visited on the link
1019 */
1021 /**
1022 * When recursively checking for devices on the link, check whether a
1023 * given device has already been visited.
1024 *
1025 * @param device the bridge device to check
1026 * @return true if bridge has already been visited
1027 */
1029 /**
1030 * When recursively checking for devices on the link, mark a given device
1031 * as having been visited.
1032 *
1033 * @param device the bridge device to mark
1034 */
1036
1037 // inherited from Object
1038 void DoDispose() override;
1039};
1040
1041/**
1042 * @ingroup globalrouting
1043 * Create the typedef Ipv4GlobalRouting with T as Ipv4RoutingProtocol
1044 */
1046
1047} // namespace ns3
1048
1049#endif /* GLOBAL_ROUTER_INTERFACE_H */
An interface aggregated to a node to provide global routing info.
uint32_t DiscoverLSAs()
Walk the connected channels, discover the adjacent routers and build the associated number of Global ...
Ptr< GlobalRouting< IpRoutingProtocol > > m_routingProtocol
Ptr< NetDevice > GetAdjacent(Ptr< NetDevice > nd, Ptr< Channel > ch) const
Link through the given channel and find the net device that's on the other end.
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.
IpRoutingTableEntry * GetInjectedRoute(uint32_t i)
Return the injected route indexed by i.
typename std::conditional_t< IsIpv4, Ipv4RoutingProtocol, Ipv6RoutingProtocol > IpRoutingProtocol
Alias for Ipv4RoutingProtocol and Ipv6RoutingProtocol classes.
std::vector< Ptr< BridgeNetDevice > > m_bridgesVisited
std::list< IpRoutingTableEntry * >::iterator InjectedRoutesI
Iterator to container of Ipv4RoutingTableEntry.
std::list< IpRoutingTableEntry * > InjectedRoutes
container of Ipv4RoutingTableEntry
void ProcessSingleBroadcastLink(Ptr< NetDevice > nd, GlobalRoutingLSA< T > *pLSA, NetDeviceContainer &c)
Process a single broadcast link.
bool BridgeHasAlreadyBeenVisited(Ptr< BridgeNetDevice > device) const
When recursively checking for devices on the link, check whether a given device has already been visi...
bool WithdrawRoute(IpAddress network, IpMaskOrPrefix networkMask)
Withdraw a route from the global unicast routing table.
std::list< IpRoutingTableEntry * >::const_iterator InjectedRoutesCI
Const Iterator to container of Ipv4RoutingTableEntry.
uint32_t GetNumLSAs() const
Get the Number of Global Routing Link State Advertisements that this router can export.
GlobalRouter()
Create a Global Router class.
typename std::conditional_t< IsIpv4, Ipv4InterfaceAddress, Ipv6InterfaceAddress > IpInterfaceAddress
Alias for Ipv4InterfaceAddress and Ipv6InterfaceAddress classes.
void ProcessBroadcastLink(Ptr< NetDevice > nd, GlobalRoutingLSA< T > *pLSA, NetDeviceContainer &c)
Process a generic broadcast link.
bool AnotherRouterOnLink(Ptr< NetDevice > nd) const
Checks for the presence of another router on the NetDevice.
void ProcessBridgedBroadcastLink(Ptr< NetDevice > nd, GlobalRoutingLSA< T > *pLSA, NetDeviceContainer &c)
Process a bridged broadcast link.
uint32_t GetNInjectedRoutes()
Get the number of injected routes that have been added to the routing table.
Ptr< BridgeNetDevice > NetDeviceIsBridged(Ptr< NetDevice > nd) const
Decide whether or not a given net device is being bridged by a BridgeNetDevice.
void ClearBridgesVisited() const
Clear the list of bridges visited on the link.
NetDeviceContainer FindAllNonBridgedDevicesOnLink(Ptr< Channel > ch) const
Return a container of all non-bridged NetDevices on a link.
IpAddress FindDesignatedRouterForLink(Ptr< NetDevice > ndLocal) const
Finds a designated router.
bool GetLSA(uint32_t n, GlobalRoutingLSA< T > &lsa) const
Get a Global Routing Link State Advertisements that this router has said that it can export.
void BuildNetworkLSAs(NetDeviceContainer c)
Build one NetworkLSA for each net device talking to a network that we are the designated router for.
typename std::conditional_t< IsIpv4, Ipv4Mask, Ipv6Prefix > IpMaskOrPrefix
Alias for Ipv4Mask And Ipv6Prefix.
void ClearLSAs()
Clear list of LSAs.
void InjectRoute(IpAddress network, IpMaskOrPrefix networkMask)
Inject a route to be circulated to other routers as an external route.
static TypeId GetTypeId()
Get the type ID.
Ptr< GlobalRouting< IpRoutingProtocol > > GetRoutingProtocol()
Get the specific Global Routing Protocol used.
void SetRoutingProtocol(Ptr< GlobalRouting< IpRoutingProtocol > > routing)
Set the specific Global Routing Protocol to be used.
IpAddress GetRouterId() const
Get the Router ID associated with this Global Router.
void DoDispose() override
Destructor implementation.
GlobalRouter(const GlobalRouter &)=delete
typename std::conditional_t< IsIpv4, Ipv4RoutingTableEntry, Ipv6RoutingTableEntry > IpRoutingTableEntry
Alias for Ipv4RoutingTableEntry and Ipv6RoutingTableEntry classes.
std::list< GlobalRoutingLSA< T > * > ListOfLSAs_t
container for the GlobalRoutingLSAs
typename std::conditional_t< IsIpv4, Ipv4Address, Ipv6Address > IpAddress
Alias for Ipv4Address and Ipv6Address classes.
void RemoveInjectedRoute(uint32_t i)
Withdraw a route from the global unicast routing table.
typename std::conditional_t< IsIpv4, Ipv4Header, Ipv6Header > IpHeader
Alias for Ipv4Header and Ipv6Header classes.
void MarkBridgeAsVisited(Ptr< BridgeNetDevice > device) const
When recursively checking for devices on the link, mark a given device as having been visited.
GlobalRouter & operator=(const GlobalRouter &)=delete
void ProcessPointToPointLink(Ptr< NetDevice > ndLocal, GlobalRoutingLSA< T > *pLSA)
Process a point to point link.
Global routing protocol for IPv4 stacks.
a Link State Advertisement (LSA) for a router, used in global routing.
GlobalRoutingLinkRecord< T > * GetLinkRecord(uint32_t n) const
Return a pointer to the specified Global Routing Link Record.
typename std::conditional_t< IsIpv4, Ipv4, Ipv6 > Ip
Alias for Ipv4 and Ipv6 classes.
SPFStatus
Enumeration of the possible values of the status flag in the Routing Link State Advertisements.
@ LSA_SPF_CANDIDATE
Vertex is in the SPF candidate queue.
@ LSA_SPF_IN_SPFTREE
Vertex is in the SPF tree.
@ LSA_SPF_NOT_EXPLORED
New vertex not yet considered.
IpAddress m_advertisingRtr
The Advertising Router is defined by the OSPF spec.
void SetLSType(LSType typ)
Set the LS type field of the LSA.
void ClearLinkRecords()
Release all of the Global Routing Link Records present in the Global Routing Link State Advertisement...
SPFStatus GetStatus() const
Get the SPF status of the advertisement.
typename std::conditional_t< IsIpv4, Ipv4Address, Ipv6Address > IpAddress
Alias for Ipv4Address and Ipv6Address classes.
LSType
corresponds to LS type field of RFC 2328 OSPF LSA header
void SetNetworkLSANetworkMask(IpMaskOrPrefix mask)
For a Network LSA, set the Network Mask field that precedes the list of attached routers.
void SetAdvertisingRouter(IpAddress rtr)
Set the Advertising Router as defined by the OSPF spec.
uint32_t GetNLinkRecords() const
Return the number of Global Routing Link Records in the LSA.
ListOfLinkRecords_t m_linkRecords
Each Link State Advertisement contains a number of Link Records that describe the kinds of links that...
uint32_t AddLinkRecord(GlobalRoutingLinkRecord< T > *lr)
Add a given Global Routing Link Record to the LSA.
IpAddress GetLinkStateId() const
Get the Link State ID as defined by the OSPF spec.
void SetLinkStateId(IpAddress addr)
Set the Link State ID is defined by the OSPF spec.
typename std::conditional_t< IsIpv4, Ipv4Mask, Ipv6Prefix > IpMaskOrPrefix
Alias for Ipv4Mask And Ipv6Prefix.
Ptr< Node > GetNode() const
Get the Node pointer of the node that originated this LSA.
void Print(std::ostream &os) const
Print the contents of the Global Routing Link State Advertisement and any Global Routing Link Records...
GlobalRoutingLSA & operator=(const GlobalRoutingLSA &lsa)
Assignment operator for a Global Routing Link State Advertisement.
IpMaskOrPrefix m_networkLSANetworkMask
Each Network LSA contains the network mask of the attached network.
typename std::conditional_t< IsIpv4, Ipv4Route, Ipv6Route > IpRoute
Alias for Ipv4Route and Ipv6Route classes.
LSType GetLSType() const
Return the LSType field of the LSA.
typename std::conditional_t< IsIpv4, Ipv4InterfaceAddress, Ipv6InterfaceAddress > IpInterfaceAddress
Alias for Ipv4InterfaceAddress and Ipv6InterfaceAddress classes.
GlobalRoutingLSA()
Create a blank Global Routing Link State Advertisement.
IpAddress GetAdvertisingRouter() const
Get the Advertising Router as defined by the OSPF spec.
std::list< IpAddress > ListOfAttachedRouters_t
A convenience typedef to avoid too much writers cramp.
uint32_t GetNAttachedRouters() const
Return the number of attached routers listed in the NetworkLSA.
typename std::conditional_t< IsIpv4, Ipv4RoutingTableEntry, Ipv6RoutingTableEntry > IpRoutingTableEntry
Alias for Ipv4RoutingTableEntry and Ipv6RoutingTableEntry classes.
SPFStatus m_status
This is a tristate flag used internally in the SPF computation to mark if an SPFVertex (a data struct...
IpAddress m_linkStateId
The Link State ID is defined by the OSPF spec.
static constexpr bool IsIpv4
Alias for determining whether the parent is Ipv4RoutingProtocol or Ipv6RoutingProtocol.
typename std::conditional_t< IsIpv4, Ipv4Header, Ipv6Header > IpHeader
Alias for Ipv4Header and Ipv6Header classes.
void SetStatus(SPFStatus status)
Set the SPF status of the advertisement.
ListOfAttachedRouters_t m_attachedRouters
Each Network LSA contains a list of attached routers.
bool IsEmpty() const
Check to see if the list of Global Routing Link Records present in the Global Routing Link State Adve...
~GlobalRoutingLSA()
Destroy an existing Global Routing Link State Advertisement.
std::list< GlobalRoutingLinkRecord< T > * > ListOfLinkRecords_t
A convenience typedef to avoid too much writers cramp.
void CopyLinkRecords(const GlobalRoutingLSA &lsa)
Copy any Global Routing Link Records in a given Global Routing Link State Advertisement to the curren...
void SetNode(Ptr< Node > node)
Set the Node pointer of the node that originated this LSA.
IpMaskOrPrefix GetNetworkLSANetworkMask() const
For a Network LSA, get the Network Mask field that precedes the list of attached routers.
IpAddress GetAttachedRouter(uint32_t n) const
Return an Ipv4Address corresponding to the specified attached router.
uint32_t AddAttachedRouter(IpAddress addr)
Add an attached router to the list in the NetworkLSA.
LSType m_lsType
The type of the LSA.
holds a vector of ns3::NetDevice pointers
Object()
Caller graph was not generated because of its size.
Definition object.cc:93
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
a unique identifier for an interface.
Definition type-id.h:50
GlobalRouter< Ipv4Manager > Ipv4GlobalRouter
Create the typedef Ipv4GlobalRouting with T as Ipv4RoutingProtocol.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148