A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("Ipv4RoutingTableEntry");
26 
27 namespace ns3 {
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 (), 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 
258 /*****************************************************
259  * Ipv4MulticastRoutingTableEntry
260  *****************************************************/
261 
263 {
264  NS_LOG_FUNCTION (this);
265 }
266 
268  :
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  :
279  m_origin (route->m_origin),
280  m_group (route->m_group),
281  m_inputInterface (route->m_inputInterface),
282  m_outputInterfaces (route->m_outputInterfaces)
283 {
284  NS_LOG_FUNCTION (this << route);
285 }
286 
288  Ipv4Address origin,
290  uint32_t inputInterface,
291  std::vector<uint32_t> outputInterfaces)
292 {
293  NS_LOG_FUNCTION (this << origin << group << inputInterface << &outputInterfaces);
294  m_origin = origin;
295  m_group = group;
296  m_inputInterface = inputInterface;
297  m_outputInterfaces = outputInterfaces;
298 }
299 
302 {
303  NS_LOG_FUNCTION (this);
304  return m_origin;
305 }
306 
309 {
310  NS_LOG_FUNCTION (this);
311  return m_group;
312 }
313 
314 uint32_t
316 {
317  NS_LOG_FUNCTION (this);
318  return m_inputInterface;
319 }
320 
321 uint32_t
323 {
324  NS_LOG_FUNCTION (this);
325  return m_outputInterfaces.size ();
326 }
327 
328 uint32_t
330 {
331  NS_LOG_FUNCTION (this << n);
332  NS_ASSERT_MSG (n < m_outputInterfaces.size (),
333  "Ipv4MulticastRoutingTableEntry::GetOutputInterface (): index out of bounds");
334 
335  return m_outputInterfaces[n];
336 }
337 
338 std::vector<uint32_t>
340 {
341  NS_LOG_FUNCTION (this);
342  return m_outputInterfaces;
343 }
344 
347  Ipv4Address origin,
349  uint32_t inputInterface,
350  std::vector<uint32_t> outputInterfaces)
351 {
353  return Ipv4MulticastRoutingTableEntry (origin, group, inputInterface, outputInterfaces);
354 }
355 
356 std::ostream&
357 operator<< (std::ostream& os, Ipv4MulticastRoutingTableEntry const& route)
358 {
359  os << "origin=" << route.GetOrigin () <<
360  ", group=" << route.GetGroup () <<
361  ", input interface=" << route.GetInputInterface () <<
362  ", output interfaces=";
363 
364  for (uint32_t i = 0; i < route.GetNOutputInterfaces (); ++i)
365  {
366  os << route.GetOutputInterface (i) << " ";
367 
368  }
369 
370  return os;
371 }
372 
373 } // namespace ns3
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
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:222
Ipv4Address GetOrigin(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:61
Ipv4Address GetDestNetwork(void) const
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
uint32_t GetInputInterface(void) const
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
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
uint32_t GetInterface(void) const
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
bool IsGateway(void) const
static Ipv4RoutingTableEntry CreateHostRouteTo(Ipv4Address dest, Ipv4Address nextHop, uint32_t interface)
static Ipv4RoutingTableEntry CreateNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface)
std::vector< uint32_t > m_outputInterfaces
output interfaces
bool IsNetwork(void) const
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:43
Ipv4Address m_gateway
gateway
Ipv4MulticastRoutingTableEntry()
This constructor does nothing.
uint32_t GetOutputInterface(uint32_t n) const
bool IsEqual(const Ipv4Address &other) const
Comparison operation between two Ipv4Addresses.
Definition: ipv4-address.h:81
Ipv4Mask m_destNetworkMask
destination network mask
static Ipv4RoutingTableEntry CreateDefaultRoute(Ipv4Address nextHop, uint32_t interface)
Ipv4Address GetDest(void) const
static Ipv4Address GetZero(void)
A record of an IPv4 multicast route for Ipv4GlobalRouting and Ipv4StaticRouting.
#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:84
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
bool IsEqual(Ipv4Mask other) const
Ipv4Address GetGroup(void) const
Ipv4Address GetGateway(void) const
Ipv4Address m_dest
destination address
uint32_t GetNOutputInterfaces(void) const
bool IsHost(void) const
Ipv4Mask GetDestNetworkMask(void) const
bool IsDefault(void) const
std::vector< uint32_t > GetOutputInterfaces(void) const
Ipv4RoutingTableEntry()
This constructor does nothing.