A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
global-route-manager.h
Go to the documentation of this file.
1/*
2 * Copyright 2007 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Craig Dowell (craigdo@ee.washington.edu)
7 * Tom Henderson (tomhend@u.washington.edu)
8 */
9
10#ifndef GLOBAL_ROUTE_MANAGER_H
11#define GLOBAL_ROUTE_MANAGER_H
12
13#include "ipv6.h"
14
15#include "ns3/ipv4-routing-helper.h"
16#include "ns3/ipv6-routing-helper.h"
17
18#include <cstdint>
19
20namespace ns3
21{
22
23/**
24 * Empty struct used as a template parameter
25 */
27{
28};
29
30/**
31 * Empty struct used as a template parameter
32 */
34{
35};
36
37/**
38 * @ingroup globalrouting
39 *
40 * @brief A global global router
41 *
42 * This singleton object can query interface each node in the system
43 * for a GlobalRouter interface. For those nodes, it fetches one or
44 * more Link State Advertisements and stores them in a local database.
45 * Then, it can compute shortest paths on a per-node basis to all routers,
46 * and finally configure each of the node's forwarding tables.
47 *
48 * The design is guided by OSPFv2 \RFC{2328} section 16.1.1 and quagga ospfd.
49 */
50
51template <typename T>
53{
54 static_assert(std::is_same_v<T, Ipv4Manager> || std::is_same_v<T, Ipv6Manager>,
55 "T must be either Ipv4Manager or Ipv6Manager when calling GlobalRouteManager");
56 /// Alias for determining whether the parent is Ipv4RoutingProtocol or Ipv6RoutingProtocol
57 static constexpr bool IsIpv4 = std::is_same_v<Ipv4Manager, T>;
58
59 /// Alias for Ipv4 and Ipv6 classes
60 using Ip = typename std::conditional_t<IsIpv4, Ipv4, Ipv6>;
61
62 /// Alias for Ipv4Address and Ipv6Address classes
63 using IpAddress = typename std::conditional_t<IsIpv4, Ipv4Address, Ipv6Address>;
64
65 /// Alias for Ipv4Manager and Ipv6Manager classes
66 using IpManager = typename std::conditional_t<IsIpv4, Ipv4Manager, Ipv6Manager>;
67
68 public:
69 // Delete copy constructor and assignment operator to avoid misuse
72
73 /**
74 * @brief Allocate a 32-bit router ID from monotonically increasing counter.
75 * @returns A new new RouterId.
76 */
78
79 /**
80 * @brief Delete all static routes on all nodes that have a
81 * GlobalRouterInterface
82 *
83 */
84 static void DeleteGlobalRoutes();
85
86 /**
87 * @brief Build the routing database by gathering Link State Advertisements
88 * from each node exporting a GlobalRouter interface.
89 */
91
92 /**
93 * @brief Compute routes using a Dijkstra SPF computation and populate
94 * per-node forwarding tables
95 */
96 static void InitializeRoutes();
97
98 /**
99 * @brief Reset the router ID counter to zero. This should only be called by tests to reset the
100 * router ID counter between simulations within the same program. This function should not be
101 * called In typical simulations or when using the GlobalRouting helper.
102 */
103 static void ResetRouterId();
104
105 /**
106 * @brief initialize all nodes as routers. this method queries all the nodes in the simulation
107 * and enables ipv6 forwarding on all of them.
108 */
109 static void InitializeRouters();
110
111 /**
112 * @brief prints the path from this node to the destination node at a particular time.
113 * @param sourceNode The source node.
114 * @param dest The IPv4 address of the destination node.
115 * @param stream The output stream to which the routing path will be written.
116 * @param nodeIdLookup Print the Node Id
117 * @param unit The time unit for timestamps in the printed output.
118 * @see Ipv4GlobalRoutingHelper::PrintRoute
119 */
120 static void PrintRoute(Ptr<Node> sourceNode,
121 IpAddress dest,
123 bool nodeIdLookup = true,
124 Time::Unit unit = Time::S);
125
126 /**
127 *@brief prints the path from this node to the destination node at a particular time.
128 * @param sourceNode The source node.
129 * @param dest The IP address of the destination node.
130 * @param nodeIdLookup Print the Node Id
131 * @param unit The time unit for timestamps in the printed output.
132 * @see Ipv4GlobalRoutingHelper::PrintRoute
133 */
134 static void PrintRoute(Ptr<Node> sourceNode,
135 IpAddress dest,
136 bool nodeIdLookup = true,
137 Time::Unit unit = Time::S);
138
139 /**
140 *@brief prints the path from this node to the destination node at a particular time.
141 * @param sourceNode The source node.
142 * @param dest The destination node.
143 * @param stream The output stream to which the routing path will be written.
144 * @param nodeIdLookup Print the Node Id
145 * @param unit The time unit for timestamps in the printed output.
146 * @see Ipv4GlobalRoutingHelper::PrintRoute
147 */
148 static void PrintRoute(Ptr<Node> sourceNode,
149 Ptr<Node> dest,
151 bool nodeIdLookup = true,
152 Time::Unit unit = Time::S);
153
154 /**
155 *@brief prints the path from this node to the destination node at a particular time.
156 * @param sourceNode The source node.
157 * @param dest The destination node.
158 * @param nodeIdLookup Print the Node Id
159 * @param unit The time unit for timestamps in the printed output.
160 * @see Ipv4GlobalRoutingHelper::PrintRoute
161 */
162 static void PrintRoute(Ptr<Node> sourceNode,
163 Ptr<Node> dest,
164 bool nodeIdLookup = true,
165 Time::Unit unit = Time::S);
166
167 private:
168 static uint32_t routerId; //!< Router ID counter
169};
170
171/**
172 * @ingroup globalrouting
173 * Create the typedef Ipv4GlobalRouting with T as Ipv4RoutingProtocol
174 */
176
177} // namespace ns3
178
179#endif /* GLOBAL_ROUTE_MANAGER_H */
A global global router.
static void PrintRoute(Ptr< Node > sourceNode, Ptr< Node > dest, Ptr< OutputStreamWrapper > stream, bool nodeIdLookup=true, Time::Unit unit=Time::S)
prints the path from this node to the destination node at a particular time.
typename std::conditional_t< IsIpv4, Ipv4Manager, Ipv6Manager > IpManager
Alias for Ipv4Manager and Ipv6Manager classes.
typename std::conditional_t< IsIpv4, Ipv4, Ipv6 > Ip
Alias for Ipv4 and Ipv6 classes.
typename std::conditional_t< IsIpv4, Ipv4Address, Ipv6Address > IpAddress
Alias for Ipv4Address and Ipv6Address classes.
static void ResetRouterId()
Reset the router ID counter to zero.
static void PrintRoute(Ptr< Node > sourceNode, Ptr< Node > dest, bool nodeIdLookup=true, Time::Unit unit=Time::S)
prints the path from this node to the destination node at a particular time.
GlobalRouteManager & operator=(const GlobalRouteManager< T > &)=delete
static void BuildGlobalRoutingDatabase()
Build the routing database by gathering Link State Advertisements from each node exporting a GlobalRo...
static void PrintRoute(Ptr< Node > sourceNode, IpAddress dest, Ptr< OutputStreamWrapper > stream, bool nodeIdLookup=true, Time::Unit unit=Time::S)
prints the path from this node to the destination node at a particular time.
static void PrintRoute(Ptr< Node > sourceNode, IpAddress dest, bool nodeIdLookup=true, Time::Unit unit=Time::S)
prints the path from this node to the destination node at a particular time.
static void InitializeRoutes()
Compute routes using a Dijkstra SPF computation and populate per-node forwarding tables.
static void DeleteGlobalRoutes()
Delete all static routes on all nodes that have a GlobalRouterInterface.
GlobalRouteManager(const GlobalRouteManager< T > &)=delete
static uint32_t AllocateRouterId()
Allocate a 32-bit router ID from monotonically increasing counter.
static void InitializeRouters()
initialize all nodes as routers.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Unit
The unit to use to interpret a number representing time.
Definition nstime.h:101
@ S
second
Definition nstime.h:106
GlobalRouteManager< Ipv4Manager > Ipv4GlobalRouteManager
Create the typedef Ipv4GlobalRouting with T as Ipv4RoutingProtocol.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Empty struct used as a template parameter.
Empty struct used as a template parameter.