A Discrete-Event Network Simulator
API
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 return true;
105 }
106 else
107 {
108 return false;
109 }
110}
111
114{
115 NS_LOG_FUNCTION(this);
116 return m_dest;
117}
118
119bool
121{
122 NS_LOG_FUNCTION(this);
123 return !IsHost();
124}
125
126bool
128{
129 NS_LOG_FUNCTION(this);
131 {
132 return true;
133 }
134 else
135 {
136 return false;
137 }
138}
139
142{
143 NS_LOG_FUNCTION(this);
144 return m_dest;
145}
146
149{
150 NS_LOG_FUNCTION(this);
151 return m_destNetworkMask;
152}
153
154bool
156{
157 NS_LOG_FUNCTION(this);
159 {
160 return false;
161 }
162 else
163 {
164 return true;
165 }
166}
167
170{
171 NS_LOG_FUNCTION(this);
172 return m_gateway;
173}
174
177{
178 NS_LOG_FUNCTION(this);
179 return m_interface;
180}
181
184{
185 NS_LOG_FUNCTION(dest << nextHop << interface);
186 return Ipv4RoutingTableEntry(dest, nextHop, interface);
187}
188
191{
192 NS_LOG_FUNCTION(dest << interface);
193 return Ipv4RoutingTableEntry(dest, interface);
194}
195
198 Ipv4Mask networkMask,
199 Ipv4Address nextHop,
200 uint32_t interface)
201{
202 NS_LOG_FUNCTION(network << networkMask << nextHop << interface);
203 return Ipv4RoutingTableEntry(network, networkMask, nextHop, interface);
204}
205
208 Ipv4Mask networkMask,
209 uint32_t interface)
210{
211 NS_LOG_FUNCTION(network << networkMask << interface);
212 return Ipv4RoutingTableEntry(network, networkMask, interface);
213}
214
217{
218 NS_LOG_FUNCTION(nextHop << interface);
219 return Ipv4RoutingTableEntry(Ipv4Address::GetZero(), Ipv4Mask::GetZero(), nextHop, interface);
220}
221
222std::ostream&
223operator<<(std::ostream& os, const Ipv4RoutingTableEntry& route)
224{
225 if (route.IsDefault())
226 {
227 NS_ASSERT(route.IsGateway());
228 os << "default out=" << route.GetInterface() << ", next hop=" << route.GetGateway();
229 }
230 else if (route.IsHost())
231 {
232 if (route.IsGateway())
233 {
234 os << "host=" << route.GetDest() << ", out=" << route.GetInterface()
235 << ", next hop=" << route.GetGateway();
236 }
237 else
238 {
239 os << "host=" << route.GetDest() << ", out=" << route.GetInterface();
240 }
241 }
242 else if (route.IsNetwork())
243 {
244 if (route.IsGateway())
245 {
246 os << "network=" << route.GetDestNetwork() << ", mask=" << route.GetDestNetworkMask()
247 << ",out=" << route.GetInterface() << ", next hop=" << route.GetGateway();
248 }
249 else
250 {
251 os << "network=" << route.GetDestNetwork() << ", mask=" << route.GetDestNetworkMask()
252 << ",out=" << route.GetInterface();
253 }
254 }
255 else
256 {
257 NS_ASSERT(false);
258 }
259 return os;
260}
261
262bool
264{
265 return (a.GetDest() == b.GetDest() && a.GetDestNetworkMask() == b.GetDestNetworkMask() &&
266 a.GetGateway() == b.GetGateway() && a.GetInterface() == b.GetInterface());
267}
268
269/*****************************************************
270 * Ipv4MulticastRoutingTableEntry
271 *****************************************************/
272
274{
275 NS_LOG_FUNCTION(this);
276}
277
280 : m_origin(route.m_origin),
281 m_group(route.m_group),
282 m_inputInterface(route.m_inputInterface),
283 m_outputInterfaces(route.m_outputInterfaces)
284{
285 NS_LOG_FUNCTION(this << route);
286}
287
290 : m_origin(route->m_origin),
291 m_group(route->m_group),
292 m_inputInterface(route->m_inputInterface),
293 m_outputInterfaces(route->m_outputInterfaces)
294{
295 NS_LOG_FUNCTION(this << route);
296}
297
299 Ipv4Address origin,
300 Ipv4Address group,
301 uint32_t inputInterface,
302 std::vector<uint32_t> outputInterfaces)
303{
304 NS_LOG_FUNCTION(this << origin << group << inputInterface << &outputInterfaces);
305 m_origin = origin;
306 m_group = group;
307 m_inputInterface = inputInterface;
308 m_outputInterfaces = outputInterfaces;
309}
310
313{
314 NS_LOG_FUNCTION(this);
315 return m_origin;
316}
317
320{
321 NS_LOG_FUNCTION(this);
322 return m_group;
323}
324
327{
328 NS_LOG_FUNCTION(this);
329 return m_inputInterface;
330}
331
334{
335 NS_LOG_FUNCTION(this);
336 return m_outputInterfaces.size();
337}
338
341{
342 NS_LOG_FUNCTION(this << n);
344 "Ipv4MulticastRoutingTableEntry::GetOutputInterface (): index out of bounds");
345
346 return m_outputInterfaces[n];
347}
348
349std::vector<uint32_t>
351{
352 NS_LOG_FUNCTION(this);
353 return m_outputInterfaces;
354}
355
358 Ipv4Address group,
359 uint32_t inputInterface,
360 std::vector<uint32_t> outputInterfaces)
361{
362 NS_LOG_FUNCTION(origin << group << inputInterface << outputInterfaces);
363 return Ipv4MulticastRoutingTableEntry(origin, group, inputInterface, outputInterfaces);
364}
365
366std::ostream&
367operator<<(std::ostream& os, const Ipv4MulticastRoutingTableEntry& route)
368{
369 os << "origin=" << route.GetOrigin() << ", group=" << route.GetGroup()
370 << ", input interface=" << route.GetInputInterface() << ", output interfaces=";
371
372 for (uint32_t i = 0; i < route.GetNOutputInterfaces(); ++i)
373 {
374 os << route.GetOutputInterface(i) << " ";
375 }
376
377 return os;
378}
379
380bool
382{
383 return (a.GetOrigin() == b.GetOrigin() && a.GetGroup() == b.GetGroup() &&
386}
387
388} // namespace ns3
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:43
static Ipv4Address GetZero()
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:258
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:129