A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv4-routing-table-entry.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8
10
11#include "ns3/assert.h"
12#include "ns3/log.h"
13
14namespace ns3
15{
16
17NS_LOG_COMPONENT_DEFINE("Ipv4RoutingTableEntry");
18
19/*****************************************************
20 * Network Ipv4RoutingTableEntry
21 *****************************************************/
22
27
29 : m_dest(route.m_dest),
30 m_destNetworkMask(route.m_destNetworkMask),
31 m_gateway(route.m_gateway),
32 m_interface(route.m_interface)
33{
34 NS_LOG_FUNCTION(this << route);
35}
36
38 : m_dest(route->m_dest),
39 m_destNetworkMask(route->m_destNetworkMask),
40 m_gateway(route->m_gateway),
41 m_interface(route->m_interface)
42{
43 NS_LOG_FUNCTION(this << route);
44}
45
47 Ipv4Address gateway,
48 uint32_t interface)
49 : m_dest(dest),
50 m_destNetworkMask(Ipv4Mask::GetOnes()),
51 m_gateway(gateway),
52 m_interface(interface)
53{
54}
55
57 : m_dest(dest),
58 m_destNetworkMask(Ipv4Mask::GetOnes()),
59 m_gateway(Ipv4Address::GetZero()),
60 m_interface(interface)
61{
62}
63
65 Ipv4Mask networkMask,
66 Ipv4Address gateway,
67 uint32_t interface)
68 : m_dest(network),
69 m_destNetworkMask(networkMask),
70 m_gateway(gateway),
71 m_interface(interface)
72{
73 NS_LOG_FUNCTION(this << network << networkMask << gateway << interface);
74}
75
77 Ipv4Mask networkMask,
78 uint32_t interface)
79 : m_dest(network),
80 m_destNetworkMask(networkMask),
81 m_gateway(Ipv4Address::GetZero()),
82 m_interface(interface)
83{
84 NS_LOG_FUNCTION(this << network << networkMask << interface);
85}
86
87bool
93
96{
97 NS_LOG_FUNCTION(this);
98 return m_dest;
99}
100
101bool
103{
104 NS_LOG_FUNCTION(this);
105 return !IsHost();
106}
107
108bool
114
117{
118 NS_LOG_FUNCTION(this);
119 return m_dest;
120}
121
128
129bool
135
138{
139 NS_LOG_FUNCTION(this);
140 return m_gateway;
141}
142
145{
146 NS_LOG_FUNCTION(this);
147 return m_interface;
148}
149
152{
153 NS_LOG_FUNCTION(dest << nextHop << interface);
154 return Ipv4RoutingTableEntry(dest, nextHop, interface);
155}
156
159{
160 NS_LOG_FUNCTION(dest << interface);
161 return Ipv4RoutingTableEntry(dest, interface);
162}
163
166 Ipv4Mask networkMask,
167 Ipv4Address nextHop,
168 uint32_t interface)
169{
170 NS_LOG_FUNCTION(network << networkMask << nextHop << interface);
171 return Ipv4RoutingTableEntry(network, networkMask, nextHop, interface);
172}
173
176 Ipv4Mask networkMask,
177 uint32_t interface)
178{
179 NS_LOG_FUNCTION(network << networkMask << interface);
180 return Ipv4RoutingTableEntry(network, networkMask, interface);
181}
182
185{
186 NS_LOG_FUNCTION(nextHop << interface);
187 return Ipv4RoutingTableEntry(Ipv4Address::GetZero(), Ipv4Mask::GetZero(), nextHop, interface);
188}
189
190std::ostream&
191operator<<(std::ostream& os, const Ipv4RoutingTableEntry& route)
192{
193 if (route.IsDefault())
194 {
195 NS_ASSERT(route.IsGateway());
196 os << "default out=" << route.GetInterface() << ", next hop=" << route.GetGateway();
197 }
198 else if (route.IsHost())
199 {
200 if (route.IsGateway())
201 {
202 os << "host=" << route.GetDest() << ", out=" << route.GetInterface()
203 << ", next hop=" << route.GetGateway();
204 }
205 else
206 {
207 os << "host=" << route.GetDest() << ", out=" << route.GetInterface();
208 }
209 }
210 else if (route.IsNetwork())
211 {
212 if (route.IsGateway())
213 {
214 os << "network=" << route.GetDestNetwork() << ", mask=" << route.GetDestNetworkMask()
215 << ",out=" << route.GetInterface() << ", next hop=" << route.GetGateway();
216 }
217 else
218 {
219 os << "network=" << route.GetDestNetwork() << ", mask=" << route.GetDestNetworkMask()
220 << ",out=" << route.GetInterface();
221 }
222 }
223 else
224 {
225 NS_ASSERT(false);
226 }
227 return os;
228}
229
230bool
232{
233 return (a.GetDest() == b.GetDest() && a.GetDestNetworkMask() == b.GetDestNetworkMask() &&
234 a.GetGateway() == b.GetGateway() && a.GetInterface() == b.GetInterface());
235}
236
237/*****************************************************
238 * Ipv4MulticastRoutingTableEntry
239 *****************************************************/
240
245
248 : m_origin(route.m_origin),
249 m_group(route.m_group),
250 m_inputInterface(route.m_inputInterface),
251 m_outputInterfaces(route.m_outputInterfaces)
252{
253 NS_LOG_FUNCTION(this << route);
254}
255
258 : m_origin(route->m_origin),
259 m_group(route->m_group),
260 m_inputInterface(route->m_inputInterface),
261 m_outputInterfaces(route->m_outputInterfaces)
262{
263 NS_LOG_FUNCTION(this << route);
264}
265
267 Ipv4Address origin,
268 Ipv4Address group,
269 uint32_t inputInterface,
270 std::vector<uint32_t> outputInterfaces)
271{
272 NS_LOG_FUNCTION(this << origin << group << inputInterface << &outputInterfaces);
273 m_origin = origin;
274 m_group = group;
275 m_inputInterface = inputInterface;
276 m_outputInterfaces = outputInterfaces;
277}
278
285
288{
289 NS_LOG_FUNCTION(this);
290 return m_group;
291}
292
299
306
309{
310 NS_LOG_FUNCTION(this << n);
312 "Ipv4MulticastRoutingTableEntry::GetOutputInterface (): index out of bounds");
313
314 return m_outputInterfaces[n];
315}
316
317std::vector<uint32_t>
323
326 Ipv4Address group,
327 uint32_t inputInterface,
328 std::vector<uint32_t> outputInterfaces)
329{
330 NS_LOG_FUNCTION(origin << group << inputInterface << outputInterfaces);
331 return Ipv4MulticastRoutingTableEntry(origin, group, inputInterface, outputInterfaces);
332}
333
334std::ostream&
335operator<<(std::ostream& os, const Ipv4MulticastRoutingTableEntry& route)
336{
337 os << "origin=" << route.GetOrigin() << ", group=" << route.GetGroup()
338 << ", input interface=" << route.GetInputInterface() << ", output interfaces=";
339
340 for (uint32_t i = 0; i < route.GetNOutputInterfaces(); ++i)
341 {
342 os << route.GetOutputInterface(i) << " ";
343 }
344
345 return os;
346}
347
348bool
355
356} // namespace ns3
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetZero()
a class to represent an Ipv4 address mask
static Ipv4Mask GetOnes()
static Ipv4Mask GetZero()
A record of an IPv4 multicast route for Ipv4GlobalRouting and Ipv4StaticRouting.
Ipv4Address m_origin
source address
Ipv4Address GetGroup() const
Ipv4Address GetOrigin() const
std::vector< uint32_t > m_outputInterfaces
output interfaces
std::vector< uint32_t > GetOutputInterfaces() const
Ipv4Address m_group
destination address
uint32_t GetOutputInterface(uint32_t n) const
Ipv4MulticastRoutingTableEntry()
This constructor does nothing.
static Ipv4MulticastRoutingTableEntry CreateMulticastRoute(Ipv4Address origin, Ipv4Address group, uint32_t inputInterface, std::vector< uint32_t > outputInterfaces)
uint32_t GetNOutputInterfaces() const
uint32_t GetInputInterface() const
uint32_t m_inputInterface
input interface
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
Ipv4Address GetDest() const
Ipv4Address GetGateway() const
static Ipv4RoutingTableEntry CreateDefaultRoute(Ipv4Address nextHop, uint32_t interface)
bool IsHost() const
Ipv4Address m_dest
destination address
Ipv4RoutingTableEntry()
This constructor does nothing.
bool IsNetwork() const
uint32_t m_interface
output interface
bool IsGateway() const
Ipv4Mask m_destNetworkMask
destination network mask
Ipv4Address GetDestNetwork() const
uint32_t GetInterface() const
Ipv4Address m_gateway
gateway
static Ipv4RoutingTableEntry CreateNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface)
static Ipv4RoutingTableEntry CreateHostRouteTo(Ipv4Address dest, Ipv4Address nextHop, uint32_t interface)
bool IsDefault() const
Ipv4Mask GetDestNetworkMask() const
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator==(const EventId &a, const EventId &b)
Definition event-id.h:155
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148