A Discrete-Event Network Simulator
API
ipv4-routing-table-entry.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2005 INRIA
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19 */
20
22#include "ns3/assert.h"
23#include "ns3/log.h"
24
25namespace ns3 {
26
27NS_LOG_COMPONENT_DEFINE ("Ipv4RoutingTableEntry");
28
29/*****************************************************
30 * Network Ipv4RoutingTableEntry
31 *****************************************************/
32
34{
35 NS_LOG_FUNCTION (this);
36}
37
39 : m_dest (route.m_dest),
40 m_destNetworkMask (route.m_destNetworkMask),
41 m_gateway (route.m_gateway),
42 m_interface (route.m_interface)
43{
44 NS_LOG_FUNCTION (this << route);
45}
46
48 : m_dest (route->m_dest),
49 m_destNetworkMask (route->m_destNetworkMask),
50 m_gateway (route->m_gateway),
51 m_interface (route->m_interface)
52{
53 NS_LOG_FUNCTION (this << route);
54}
55
57 Ipv4Address gateway,
58 uint32_t interface)
59 : m_dest (dest),
60 m_destNetworkMask (Ipv4Mask::GetOnes ()),
61 m_gateway (gateway),
62 m_interface (interface)
63{
64}
66 uint32_t interface)
67 : m_dest (dest),
68 m_destNetworkMask (Ipv4Mask::GetOnes ()),
69 m_gateway (Ipv4Address::GetZero ()),
70 m_interface (interface)
71{
72}
74 Ipv4Mask networkMask,
75 Ipv4Address gateway,
76 uint32_t interface)
77 : m_dest (network),
78 m_destNetworkMask (networkMask),
79 m_gateway (gateway),
80 m_interface (interface)
81{
82 NS_LOG_FUNCTION (this << network << networkMask << gateway << interface);
83}
85 Ipv4Mask networkMask,
86 uint32_t interface)
87 : m_dest (network),
88 m_destNetworkMask (networkMask),
89 m_gateway (Ipv4Address::GetZero ()),
90 m_interface (interface)
91{
92 NS_LOG_FUNCTION (this << network << networkMask << interface);
93}
94
95bool
97{
98 NS_LOG_FUNCTION (this);
100 {
101 return true;
102 }
103 else
104 {
105 return false;
106 }
107}
110{
111 NS_LOG_FUNCTION (this);
112 return m_dest;
113}
114bool
116{
117 NS_LOG_FUNCTION (this);
118 return !IsHost ();
119}
120bool
122{
123 NS_LOG_FUNCTION (this);
125 {
126 return true;
127 }
128 else
129 {
130 return false;
131 }
132}
135{
136 NS_LOG_FUNCTION (this);
137 return m_dest;
138}
141{
142 NS_LOG_FUNCTION (this);
143 return m_destNetworkMask;
144}
145bool
147{
148 NS_LOG_FUNCTION (this);
150 {
151 return false;
152 }
153 else
154 {
155 return true;
156 }
157}
160{
161 NS_LOG_FUNCTION (this);
162 return m_gateway;
163}
166{
167 NS_LOG_FUNCTION (this);
168 return m_interface;
169}
170
173 Ipv4Address nextHop,
174 uint32_t interface)
175{
176 NS_LOG_FUNCTION (dest << nextHop << interface);
177 return Ipv4RoutingTableEntry (dest, nextHop, interface);
178}
181 uint32_t interface)
182{
183 NS_LOG_FUNCTION (dest << interface);
184 return Ipv4RoutingTableEntry (dest, interface);
185}
188 Ipv4Mask networkMask,
189 Ipv4Address nextHop,
190 uint32_t interface)
191{
192 NS_LOG_FUNCTION (network << networkMask << nextHop << interface);
193 return Ipv4RoutingTableEntry (network, networkMask,
194 nextHop, interface);
195}
198 Ipv4Mask networkMask,
199 uint32_t interface)
200{
201 NS_LOG_FUNCTION (network << networkMask << interface);
202 return Ipv4RoutingTableEntry (network, networkMask,
203 interface);
204}
207 uint32_t interface)
208{
209 NS_LOG_FUNCTION (nextHop << interface);
210 return Ipv4RoutingTableEntry (Ipv4Address::GetZero (), Ipv4Mask::GetZero (), nextHop, interface);
211}
212
213
214std::ostream& operator<< (std::ostream& os, Ipv4RoutingTableEntry const& route)
215{
216 if (route.IsDefault ())
217 {
218 NS_ASSERT (route.IsGateway ());
219 os << "default out=" << route.GetInterface () << ", next hop=" << route.GetGateway ();
220 }
221 else if (route.IsHost ())
222 {
223 if (route.IsGateway ())
224 {
225 os << "host="<< route.GetDest () <<
226 ", out=" << route.GetInterface () <<
227 ", next hop=" << route.GetGateway ();
228 }
229 else
230 {
231 os << "host="<< route.GetDest () <<
232 ", out=" << route.GetInterface ();
233 }
234 }
235 else if (route.IsNetwork ())
236 {
237 if (route.IsGateway ())
238 {
239 os << "network=" << route.GetDestNetwork () <<
240 ", mask=" << route.GetDestNetworkMask () <<
241 ",out=" << route.GetInterface () <<
242 ", next hop=" << route.GetGateway ();
243 }
244 else
245 {
246 os << "network=" << route.GetDestNetwork () <<
247 ", mask=" << route.GetDestNetworkMask () <<
248 ",out=" << route.GetInterface ();
249 }
250 }
251 else
252 {
253 NS_ASSERT (false);
254 }
255 return os;
256}
257
259{
260 return (a.GetDest () == b.GetDest () &&
262 a.GetGateway () == b.GetGateway () &&
263 a.GetInterface () == b.GetInterface ());
264}
265
266/*****************************************************
267 * Ipv4MulticastRoutingTableEntry
268 *****************************************************/
269
271{
272 NS_LOG_FUNCTION (this);
273}
274
276 :
277 m_origin (route.m_origin),
278 m_group (route.m_group),
279 m_inputInterface (route.m_inputInterface),
280 m_outputInterfaces (route.m_outputInterfaces)
281{
282 NS_LOG_FUNCTION (this << route);
283}
284
286 :
287 m_origin (route->m_origin),
288 m_group (route->m_group),
289 m_inputInterface (route->m_inputInterface),
290 m_outputInterfaces (route->m_outputInterfaces)
291{
292 NS_LOG_FUNCTION (this << route);
293}
294
296 Ipv4Address origin,
297 Ipv4Address group,
298 uint32_t inputInterface,
299 std::vector<uint32_t> outputInterfaces)
300{
301 NS_LOG_FUNCTION (this << origin << group << inputInterface << &outputInterfaces);
302 m_origin = origin;
303 m_group = group;
304 m_inputInterface = inputInterface;
305 m_outputInterfaces = outputInterfaces;
306}
307
310{
311 NS_LOG_FUNCTION (this);
312 return m_origin;
313}
314
317{
318 NS_LOG_FUNCTION (this);
319 return m_group;
320}
321
324{
325 NS_LOG_FUNCTION (this);
326 return m_inputInterface;
327}
328
331{
332 NS_LOG_FUNCTION (this);
333 return m_outputInterfaces.size ();
334}
335
338{
339 NS_LOG_FUNCTION (this << n);
341 "Ipv4MulticastRoutingTableEntry::GetOutputInterface (): index out of bounds");
342
343 return m_outputInterfaces[n];
344}
345
346std::vector<uint32_t>
348{
349 NS_LOG_FUNCTION (this);
350 return m_outputInterfaces;
351}
352
355 Ipv4Address group,
356 uint32_t inputInterface,
357 std::vector<uint32_t> outputInterfaces)
358{
359 NS_LOG_FUNCTION (origin << group << inputInterface << outputInterfaces);
360 return Ipv4MulticastRoutingTableEntry (origin, group, inputInterface, outputInterfaces);
361}
362
363std::ostream&
364operator<< (std::ostream& os, Ipv4MulticastRoutingTableEntry const& route)
365{
366 os << "origin=" << route.GetOrigin () <<
367 ", group=" << route.GetGroup () <<
368 ", input interface=" << route.GetInputInterface () <<
369 ", output interfaces=";
370
371 for (uint32_t i = 0; i < route.GetNOutputInterfaces (); ++i)
372 {
373 os << route.GetOutputInterface (i) << " ";
374
375 }
376
377 return os;
378}
379
381{
382 return (a.GetOrigin () == b.GetOrigin () &&
383 a.GetGroup () == b.GetGroup () &&
386}
387
388} // namespace ns3
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
static Ipv4Address GetZero(void)
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:256
static Ipv4Mask GetZero(void)
static Ipv4Mask GetOnes(void)
A record of an IPv4 multicast route for Ipv4GlobalRouting and Ipv4StaticRouting.
Ipv4Address GetGroup(void) const
Ipv4Address m_origin
source address
std::vector< uint32_t > m_outputInterfaces
output interfaces
std::vector< uint32_t > GetOutputInterfaces(void) const
Ipv4Address m_group
destination address
uint32_t GetOutputInterface(uint32_t n) const
Ipv4Address GetOrigin(void) const
uint32_t GetInputInterface(void) const
Ipv4MulticastRoutingTableEntry()
This constructor does nothing.
static Ipv4MulticastRoutingTableEntry CreateMulticastRoute(Ipv4Address origin, Ipv4Address group, uint32_t inputInterface, std::vector< uint32_t > outputInterfaces)
uint32_t m_inputInterface
input interface
uint32_t GetNOutputInterfaces(void) const
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
static Ipv4RoutingTableEntry CreateDefaultRoute(Ipv4Address nextHop, uint32_t interface)
Ipv4Address m_dest
destination address
Ipv4RoutingTableEntry()
This constructor does nothing.
uint32_t m_interface
output interface
bool IsNetwork(void) const
bool IsHost(void) const
bool IsDefault(void) const
uint32_t GetInterface(void) const
bool IsGateway(void) const
Ipv4Mask m_destNetworkMask
destination network mask
Ipv4Address GetDestNetwork(void) const
Ipv4Address GetDest(void) const
Ipv4Mask GetDestNetworkMask(void) 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)
Ipv4Address GetGateway(void) 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:67
#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:88
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#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:158
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:137