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 * 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 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19
21
22#include "ns3/assert.h"
23#include "ns3/log.h"
24
25namespace ns3
26{
27
28NS_LOG_COMPONENT_DEFINE("Ipv4RoutingTableEntry");
29
30/*****************************************************
31 * Network Ipv4RoutingTableEntry
32 *****************************************************/
33
35{
36 NS_LOG_FUNCTION(this);
37}
38
40 : m_dest(route.m_dest),
41 m_destNetworkMask(route.m_destNetworkMask),
42 m_gateway(route.m_gateway),
43 m_interface(route.m_interface)
44{
45 NS_LOG_FUNCTION(this << route);
46}
47
49 : m_dest(route->m_dest),
50 m_destNetworkMask(route->m_destNetworkMask),
51 m_gateway(route->m_gateway),
52 m_interface(route->m_interface)
53{
54 NS_LOG_FUNCTION(this << route);
55}
56
58 Ipv4Address gateway,
59 uint32_t interface)
60 : m_dest(dest),
61 m_destNetworkMask(Ipv4Mask::GetOnes()),
62 m_gateway(gateway),
63 m_interface(interface)
64{
65}
66
68 : m_dest(dest),
69 m_destNetworkMask(Ipv4Mask::GetOnes()),
70 m_gateway(Ipv4Address::GetZero()),
71 m_interface(interface)
72{
73}
74
76 Ipv4Mask networkMask,
77 Ipv4Address gateway,
78 uint32_t interface)
79 : m_dest(network),
80 m_destNetworkMask(networkMask),
81 m_gateway(gateway),
82 m_interface(interface)
83{
84 NS_LOG_FUNCTION(this << network << networkMask << gateway << interface);
85}
86
88 Ipv4Mask networkMask,
89 uint32_t interface)
90 : m_dest(network),
91 m_destNetworkMask(networkMask),
92 m_gateway(Ipv4Address::GetZero()),
93 m_interface(interface)
94{
95 NS_LOG_FUNCTION(this << network << networkMask << interface);
96}
97
98bool
100{
101 NS_LOG_FUNCTION(this);
103}
104
107{
108 NS_LOG_FUNCTION(this);
109 return m_dest;
110}
111
112bool
114{
115 NS_LOG_FUNCTION(this);
116 return !IsHost();
117}
118
119bool
121{
122 NS_LOG_FUNCTION(this);
123 return m_dest == Ipv4Address::GetZero();
124}
125
128{
129 NS_LOG_FUNCTION(this);
130 return m_dest;
131}
132
135{
136 NS_LOG_FUNCTION(this);
137 return m_destNetworkMask;
138}
139
140bool
142{
143 NS_LOG_FUNCTION(this);
145}
146
149{
150 NS_LOG_FUNCTION(this);
151 return m_gateway;
152}
153
156{
157 NS_LOG_FUNCTION(this);
158 return m_interface;
159}
160
163{
164 NS_LOG_FUNCTION(dest << nextHop << interface);
165 return Ipv4RoutingTableEntry(dest, nextHop, interface);
166}
167
170{
171 NS_LOG_FUNCTION(dest << interface);
172 return Ipv4RoutingTableEntry(dest, interface);
173}
174
177 Ipv4Mask networkMask,
178 Ipv4Address nextHop,
179 uint32_t interface)
180{
181 NS_LOG_FUNCTION(network << networkMask << nextHop << interface);
182 return Ipv4RoutingTableEntry(network, networkMask, nextHop, interface);
183}
184
187 Ipv4Mask networkMask,
188 uint32_t interface)
189{
190 NS_LOG_FUNCTION(network << networkMask << interface);
191 return Ipv4RoutingTableEntry(network, networkMask, interface);
192}
193
196{
197 NS_LOG_FUNCTION(nextHop << interface);
198 return Ipv4RoutingTableEntry(Ipv4Address::GetZero(), Ipv4Mask::GetZero(), nextHop, interface);
199}
200
201std::ostream&
202operator<<(std::ostream& os, const Ipv4RoutingTableEntry& route)
203{
204 if (route.IsDefault())
205 {
206 NS_ASSERT(route.IsGateway());
207 os << "default out=" << route.GetInterface() << ", next hop=" << route.GetGateway();
208 }
209 else if (route.IsHost())
210 {
211 if (route.IsGateway())
212 {
213 os << "host=" << route.GetDest() << ", out=" << route.GetInterface()
214 << ", next hop=" << route.GetGateway();
215 }
216 else
217 {
218 os << "host=" << route.GetDest() << ", out=" << route.GetInterface();
219 }
220 }
221 else if (route.IsNetwork())
222 {
223 if (route.IsGateway())
224 {
225 os << "network=" << route.GetDestNetwork() << ", mask=" << route.GetDestNetworkMask()
226 << ",out=" << route.GetInterface() << ", next hop=" << route.GetGateway();
227 }
228 else
229 {
230 os << "network=" << route.GetDestNetwork() << ", mask=" << route.GetDestNetworkMask()
231 << ",out=" << route.GetInterface();
232 }
233 }
234 else
235 {
236 NS_ASSERT(false);
237 }
238 return os;
239}
240
241bool
243{
244 return (a.GetDest() == b.GetDest() && a.GetDestNetworkMask() == b.GetDestNetworkMask() &&
245 a.GetGateway() == b.GetGateway() && a.GetInterface() == b.GetInterface());
246}
247
248/*****************************************************
249 * Ipv4MulticastRoutingTableEntry
250 *****************************************************/
251
253{
254 NS_LOG_FUNCTION(this);
255}
256
259 : m_origin(route.m_origin),
260 m_group(route.m_group),
261 m_inputInterface(route.m_inputInterface),
262 m_outputInterfaces(route.m_outputInterfaces)
263{
264 NS_LOG_FUNCTION(this << route);
265}
266
269 : m_origin(route->m_origin),
270 m_group(route->m_group),
271 m_inputInterface(route->m_inputInterface),
272 m_outputInterfaces(route->m_outputInterfaces)
273{
274 NS_LOG_FUNCTION(this << route);
275}
276
278 Ipv4Address origin,
279 Ipv4Address group,
280 uint32_t inputInterface,
281 std::vector<uint32_t> outputInterfaces)
282{
283 NS_LOG_FUNCTION(this << origin << group << inputInterface << &outputInterfaces);
284 m_origin = origin;
285 m_group = group;
286 m_inputInterface = inputInterface;
287 m_outputInterfaces = outputInterfaces;
288}
289
292{
293 NS_LOG_FUNCTION(this);
294 return m_origin;
295}
296
299{
300 NS_LOG_FUNCTION(this);
301 return m_group;
302}
303
306{
307 NS_LOG_FUNCTION(this);
308 return m_inputInterface;
309}
310
313{
314 NS_LOG_FUNCTION(this);
315 return m_outputInterfaces.size();
316}
317
320{
321 NS_LOG_FUNCTION(this << n);
323 "Ipv4MulticastRoutingTableEntry::GetOutputInterface (): index out of bounds");
324
325 return m_outputInterfaces[n];
326}
327
328std::vector<uint32_t>
330{
331 NS_LOG_FUNCTION(this);
332 return m_outputInterfaces;
333}
334
337 Ipv4Address group,
338 uint32_t inputInterface,
339 std::vector<uint32_t> outputInterfaces)
340{
341 NS_LOG_FUNCTION(origin << group << inputInterface << outputInterfaces);
342 return Ipv4MulticastRoutingTableEntry(origin, group, inputInterface, outputInterfaces);
343}
344
345std::ostream&
346operator<<(std::ostream& os, const Ipv4MulticastRoutingTableEntry& route)
347{
348 os << "origin=" << route.GetOrigin() << ", group=" << route.GetGroup()
349 << ", input interface=" << route.GetInputInterface() << ", output interfaces=";
350
351 for (uint32_t i = 0; i < route.GetNOutputInterfaces(); ++i)
352 {
353 os << route.GetOutputInterface(i) << " ";
354 }
355
356 return os;
357}
358
359bool
361{
362 return (a.GetOrigin() == b.GetOrigin() && a.GetGroup() == b.GetGroup() &&
365}
366
367} // namespace ns3
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
static Ipv4Address GetZero()
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:257
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:66
#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:86
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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:157
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159