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 
25 namespace ns3 {
26 
27 NS_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 
95 bool
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 }
114 bool
116 {
117  NS_LOG_FUNCTION (this);
118  return !IsHost ();
119 }
120 bool
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 }
139 Ipv4Mask
141 {
142  NS_LOG_FUNCTION (this);
143  return m_destNetworkMask;
144 }
145 bool
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 }
164 uint32_t
166 {
167  NS_LOG_FUNCTION (this);
168  return m_interface;
169 }
170 
173  Ipv4Address nextHop,
174  uint32_t interface)
175 {
177  return Ipv4RoutingTableEntry (dest, nextHop, interface);
178 }
181  uint32_t interface)
182 {
184  return Ipv4RoutingTableEntry (dest, interface);
185 }
188  Ipv4Mask networkMask,
189  Ipv4Address nextHop,
190  uint32_t interface)
191 {
193  return Ipv4RoutingTableEntry (network, networkMask,
194  nextHop, interface);
195 }
198  Ipv4Mask networkMask,
199  uint32_t interface)
200 {
202  return Ipv4RoutingTableEntry (network, networkMask,
203  interface);
204 }
207  uint32_t interface)
208 {
210  return Ipv4RoutingTableEntry (Ipv4Address::GetZero (), Ipv4Mask::GetZero (), nextHop, interface);
211 }
212 
213 
214 std::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 () &&
261  a.GetDestNetworkMask () == b.GetDestNetworkMask () &&
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 
322 uint32_t
324 {
325  NS_LOG_FUNCTION (this);
326  return m_inputInterface;
327 }
328 
329 uint32_t
331 {
332  NS_LOG_FUNCTION (this);
333  return m_outputInterfaces.size ();
334 }
335 
336 uint32_t
338 {
339  NS_LOG_FUNCTION (this << n);
341  "Ipv4MulticastRoutingTableEntry::GetOutputInterface (): index out of bounds");
342 
343  return m_outputInterfaces[n];
344 }
345 
346 std::vector<uint32_t>
348 {
349  NS_LOG_FUNCTION (this);
350  return m_outputInterfaces;
351 }
352 
355  Ipv4Address origin,
356  Ipv4Address group,
357  uint32_t inputInterface,
358  std::vector<uint32_t> outputInterfaces)
359 {
361  return Ipv4MulticastRoutingTableEntry (origin, group, inputInterface, outputInterfaces);
362 }
363 
364 std::ostream&
365 operator<< (std::ostream& os, Ipv4MulticastRoutingTableEntry const& route)
366 {
367  os << "origin=" << route.GetOrigin () <<
368  ", group=" << route.GetGroup () <<
369  ", input interface=" << route.GetInputInterface () <<
370  ", output interfaces=";
371 
372  for (uint32_t i = 0; i < route.GetNOutputInterfaces (); ++i)
373  {
374  os << route.GetOutputInterface (i) << " ";
375 
376  }
377 
378  return os;
379 }
380 
382 {
383  return (a.GetOrigin () == b.GetOrigin () &&
384  a.GetGroup () == b.GetGroup () &&
385  a.GetInputInterface () == b.GetInputInterface () &&
387 }
388 
389 } // namespace ns3
uint32_t GetOutputInterface(uint32_t n) const
Ipv4Address m_origin
source address
static Ipv4Mask GetOnes(void)
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint32_t m_inputInterface
input interface
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:258
bool IsNetwork(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_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Ipv4Address GetDest(void) const
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Ipv4Address GetDestNetwork(void) const
Ipv4Address GetGateway(void) const
uint32_t m_interface
output interface
static Ipv4MulticastRoutingTableEntry CreateMulticastRoute(Ipv4Address origin, Ipv4Address group, uint32_t inputInterface, std::vector< uint32_t > outputInterfaces)
Ipv4Address m_group
destination address
bool IsDefault(void) const
Ipv4Mask GetDestNetworkMask(void) const
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
Ipv4Address GetGroup(void) const
bool IsEqual(Ipv4Mask other) const
bool IsHost(void) const
static Ipv4RoutingTableEntry CreateHostRouteTo(Ipv4Address dest, Ipv4Address nextHop, uint32_t interface)
static Ipv4RoutingTableEntry CreateNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface)
static Ipv4Mask GetZero(void)
std::vector< uint32_t > m_outputInterfaces
output interfaces
std::vector< uint32_t > GetOutputInterfaces(void) const
uint32_t GetInputInterface(void) const
uint32_t GetNOutputInterfaces(void) const
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
Ipv4Address m_gateway
gateway
Ipv4MulticastRoutingTableEntry()
This constructor does nothing.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t GetInterface(void) const
Ipv4Mask m_destNetworkMask
destination network mask
static Ipv4RoutingTableEntry CreateDefaultRoute(Ipv4Address nextHop, uint32_t interface)
static Ipv4Address GetZero(void)
A record of an IPv4 multicast route for Ipv4GlobalRouting and Ipv4StaticRouting.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
Ipv4Address GetOrigin(void) const
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:135
bool IsGateway(void) const
Ipv4Address m_dest
destination address
bool IsEqual(const Ipv4Address &other) const
Comparison operation between two Ipv4Addresses.
Definition: ipv4-address.h:83
Ipv4RoutingTableEntry()
This constructor does nothing.