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