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