1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3
* Copyright (c) 2005 INRIA
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;
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.
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
18
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
21
#include "ipv4-routing-table-entry.h"
22
#include "ns3/assert.h"
26
/*****************************************************
27
* Network Ipv4RoutingTableEntry
28
*****************************************************/
30
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry ()
34
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry (Ipv4RoutingTableEntry const &route)
35
: m_dest (route.m_dest),
36
m_destNetworkMask (route.m_destNetworkMask),
37
m_gateway (route.m_gateway),
38
m_interface (route.m_interface)
42
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry (Ipv4RoutingTableEntry const *route)
43
: m_dest (route->m_dest),
44
m_destNetworkMask (route->m_destNetworkMask),
45
m_gateway (route->m_gateway),
46
m_interface (route->m_interface)
50
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry (Ipv4Address dest,
54
m_destNetworkMask (Ipv4Mask::GetOnes ()),
56
m_interface (interface)
59
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry (Ipv4Address dest,
62
m_destNetworkMask (Ipv4Mask::GetOnes ()),
63
m_gateway (Ipv4Address::GetZero ()),
64
m_interface (interface)
67
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry (Ipv4Address network,
72
m_destNetworkMask (networkMask),
74
m_interface (interface)
77
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry (Ipv4Address network,
81
m_destNetworkMask (networkMask),
82
m_gateway (Ipv4Address::GetZero ()),
83
m_interface (interface)
88
Ipv4RoutingTableEntry::IsHost (void) const
90
if (m_destNetworkMask.IsEqual (Ipv4Mask::GetOnes ()))
100
Ipv4RoutingTableEntry::GetDest (void) const
105
Ipv4RoutingTableEntry::IsNetwork (void) const
110
Ipv4RoutingTableEntry::IsDefault (void) const
112
if (m_dest.IsEqual (Ipv4Address::GetZero ()))
122
Ipv4RoutingTableEntry::GetDestNetwork (void) const
127
Ipv4RoutingTableEntry::GetDestNetworkMask (void) const
129
return m_destNetworkMask;
132
Ipv4RoutingTableEntry::IsGateway (void) const
134
if (m_gateway.IsEqual (Ipv4Address::GetZero ()))
144
Ipv4RoutingTableEntry::GetGateway (void) const
149
Ipv4RoutingTableEntry::GetInterface (void) const
154
Ipv4RoutingTableEntry
155
Ipv4RoutingTableEntry::CreateHostRouteTo (Ipv4Address dest,
159
return Ipv4RoutingTableEntry (dest, nextHop, interface);
161
Ipv4RoutingTableEntry
162
Ipv4RoutingTableEntry::CreateHostRouteTo (Ipv4Address dest,
165
return Ipv4RoutingTableEntry (dest, interface);
167
Ipv4RoutingTableEntry
168
Ipv4RoutingTableEntry::CreateNetworkRouteTo (Ipv4Address network,
169
Ipv4Mask networkMask,
173
return Ipv4RoutingTableEntry (network, networkMask,
176
Ipv4RoutingTableEntry
177
Ipv4RoutingTableEntry::CreateNetworkRouteTo (Ipv4Address network,
178
Ipv4Mask networkMask,
181
return Ipv4RoutingTableEntry (network, networkMask,
184
Ipv4RoutingTableEntry
185
Ipv4RoutingTableEntry::CreateDefaultRoute (Ipv4Address nextHop,
188
return Ipv4RoutingTableEntry (Ipv4Address::GetZero (), nextHop, interface);
192
std::ostream& operator<< (std::ostream& os, Ipv4RoutingTableEntry const& route)
194
if (route.IsDefault ())
196
NS_ASSERT (route.IsGateway ());
197
os << "default out=" << route.GetInterface () << ", next hop=" << route.GetGateway ();
199
else if (route.IsHost ())
201
if (route.IsGateway ())
203
os << "host="<< route.GetDest () <<
204
", out=" << route.GetInterface () <<
205
", next hop=" << route.GetGateway ();
209
os << "host="<< route.GetDest () <<
210
", out=" << route.GetInterface ();
213
else if (route.IsNetwork ())
215
if (route.IsGateway ())
217
os << "network=" << route.GetDestNetwork () <<
218
", mask=" << route.GetDestNetworkMask () <<
219
",out=" << route.GetInterface () <<
220
", next hop=" << route.GetGateway ();
224
os << "network=" << route.GetDestNetwork () <<
225
", mask=" << route.GetDestNetworkMask () <<
226
",out=" << route.GetInterface ();
236
/*****************************************************
237
* Ipv4MulticastRoutingTableEntry
238
*****************************************************/
240
Ipv4MulticastRoutingTableEntry::Ipv4MulticastRoutingTableEntry ()
244
Ipv4MulticastRoutingTableEntry::Ipv4MulticastRoutingTableEntry (Ipv4MulticastRoutingTableEntry const &route)
246
m_origin (route.m_origin),
247
m_group (route.m_group),
248
m_inputInterface (route.m_inputInterface),
249
m_outputInterfaces (route.m_outputInterfaces)
253
Ipv4MulticastRoutingTableEntry::Ipv4MulticastRoutingTableEntry (Ipv4MulticastRoutingTableEntry const *route)
255
m_origin (route->m_origin),
256
m_group (route->m_group),
257
m_inputInterface (route->m_inputInterface),
258
m_outputInterfaces (route->m_outputInterfaces)
262
Ipv4MulticastRoutingTableEntry::Ipv4MulticastRoutingTableEntry (
265
uint32_t inputInterface,
266
std::vector<uint32_t> outputInterfaces)
270
m_inputInterface = inputInterface;
271
m_outputInterfaces = outputInterfaces;
275
Ipv4MulticastRoutingTableEntry::GetOrigin (void) const
281
Ipv4MulticastRoutingTableEntry::GetGroup (void) const
287
Ipv4MulticastRoutingTableEntry::GetInputInterface (void) const
289
return m_inputInterface;
293
Ipv4MulticastRoutingTableEntry::GetNOutputInterfaces (void) const
295
return m_outputInterfaces.size ();
299
Ipv4MulticastRoutingTableEntry::GetOutputInterface (uint32_t n) const
301
NS_ASSERT_MSG (n < m_outputInterfaces.size (),
302
"Ipv4MulticastRoutingTableEntry::GetOutputInterface (): index out of bounds");
304
return m_outputInterfaces[n];
307
std::vector<uint32_t>
308
Ipv4MulticastRoutingTableEntry::GetOutputInterfaces (void) const
310
return m_outputInterfaces;
313
Ipv4MulticastRoutingTableEntry
314
Ipv4MulticastRoutingTableEntry::CreateMulticastRoute (
317
uint32_t inputInterface,
318
std::vector<uint32_t> outputInterfaces)
320
return Ipv4MulticastRoutingTableEntry (origin, group, inputInterface, outputInterfaces);
324
operator<< (std::ostream& os, Ipv4MulticastRoutingTableEntry const& route)
326
os << "origin=" << route.GetOrigin () <<
327
", group=" << route.GetGroup () <<
328
", input interface=" << route.GetInputInterface () <<
329
", output interfaces=";
331
for (uint32_t i = 0; i < route.GetNOutputInterfaces (); ++i)
333
os << route.GetOutputInterface (i) << " ";