A Discrete-Event Network Simulator
API
ipv6-routing-table-entry.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007-2009 Strasbourg University
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: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
18  */
19 
21 
22 #include "ns3/assert.h"
23 
24 namespace ns3
25 {
26 
28 {
29 }
30 
32  : m_dest(route.m_dest),
33  m_destNetworkPrefix(route.m_destNetworkPrefix),
34  m_gateway(route.m_gateway),
35  m_interface(route.m_interface),
36  m_prefixToUse(route.m_prefixToUse)
37 {
38 }
39 
41  : m_dest(route->m_dest),
42  m_destNetworkPrefix(route->m_destNetworkPrefix),
43  m_gateway(route->m_gateway),
44  m_interface(route->m_interface),
45  m_prefixToUse(route->m_prefixToUse)
46 {
47 }
48 
50  Ipv6Address gateway,
51  uint32_t interface)
52  : m_dest(dest),
53  m_destNetworkPrefix(Ipv6Prefix::GetZero()),
54  m_gateway(gateway),
55  m_interface(interface),
56  m_prefixToUse(Ipv6Address("::"))
57 {
58 }
59 
61  : m_dest(dest),
62  m_destNetworkPrefix(Ipv6Prefix::GetOnes()),
63  m_gateway(Ipv6Address::GetZero()),
64  m_interface(interface),
65  m_prefixToUse(Ipv6Address("::"))
66 {
67 }
68 
70  Ipv6Prefix networkPrefix,
71  Ipv6Address gateway,
72  uint32_t interface,
73  Ipv6Address prefixToUse)
74  : m_dest(network),
75  m_destNetworkPrefix(networkPrefix),
76  m_gateway(gateway),
77  m_interface(interface),
78  m_prefixToUse(prefixToUse)
79 {
80 }
81 
83  Ipv6Prefix networkPrefix,
84  Ipv6Address gateway,
85  uint32_t interface)
86  : m_dest(network),
87  m_destNetworkPrefix(networkPrefix),
88  m_gateway(gateway),
89  m_interface(interface),
90  m_prefixToUse(Ipv6Address::GetZero())
91 {
92 }
93 
95  Ipv6Prefix networkPrefix,
96  uint32_t interface,
97  Ipv6Address prefixToUse)
98  : m_dest(network),
99  m_destNetworkPrefix(networkPrefix),
100  m_gateway(Ipv6Address::GetZero()),
101  m_interface(interface),
102  m_prefixToUse(prefixToUse)
103 {
104 }
105 
107  Ipv6Prefix networkPrefix,
108  uint32_t interface)
109  : m_dest(network),
110  m_destNetworkPrefix(networkPrefix),
111  m_gateway(Ipv6Address::GetZero()),
112  m_interface(interface),
113  m_prefixToUse(Ipv6Address("::"))
114 {
115 }
116 
118 {
119 }
120 
121 bool
123 {
125 }
126 
129 {
130  return m_dest;
131 }
132 
135 {
136  return m_prefixToUse;
137 }
138 
139 void
141 {
142  m_prefixToUse = prefix;
143 }
144 
145 bool
147 {
148  return !IsHost();
149 }
150 
151 bool
153 {
154  return m_dest == Ipv6Address::GetZero();
155 }
156 
159 {
160  return m_dest;
161 }
162 
165 {
166  return m_destNetworkPrefix;
167 }
168 
169 bool
171 {
172  return m_gateway != Ipv6Address::GetZero();
173 }
174 
177 {
178  return m_gateway;
179 }
180 
183  Ipv6Address nextHop,
184  uint32_t interface,
185  Ipv6Address prefixToUse)
186 {
187  return Ipv6RoutingTableEntry(dest, Ipv6Prefix::GetOnes(), nextHop, interface, prefixToUse);
188 }
189 
192 {
193  return Ipv6RoutingTableEntry(dest, interface);
194 }
195 
198  Ipv6Prefix networkPrefix,
199  Ipv6Address nextHop,
200  uint32_t interface)
201 {
202  return Ipv6RoutingTableEntry(network, networkPrefix, nextHop, interface);
203 }
204 
207  Ipv6Prefix networkPrefix,
208  Ipv6Address nextHop,
209  uint32_t interface,
210  Ipv6Address prefixToUse)
211 {
212  return Ipv6RoutingTableEntry(network, networkPrefix, nextHop, interface, prefixToUse);
213 }
214 
217  Ipv6Prefix networkPrefix,
218  uint32_t interface)
219 {
220  return Ipv6RoutingTableEntry(network, networkPrefix, interface, network);
221 }
222 
225 {
226  return Ipv6RoutingTableEntry(Ipv6Address::GetZero(), nextHop, interface);
227 }
228 
229 uint32_t
231 {
232  return m_interface;
233 }
234 
235 std::ostream&
236 operator<<(std::ostream& os, const Ipv6RoutingTableEntry& route)
237 {
238  if (route.IsDefault())
239  {
240  NS_ASSERT(route.IsGateway());
241  os << "default out: " << route.GetInterface() << ", next hop: " << route.GetGateway();
242  }
243  else if (route.IsHost())
244  {
245  if (route.IsGateway())
246  {
247  os << "host: " << route.GetDest() << ", out: " << route.GetInterface()
248  << ", next hop: " << route.GetGateway();
249  }
250  else
251  {
252  os << "host: " << route.GetDest() << ", out: " << route.GetInterface();
253  }
254  }
255  else if (route.IsNetwork())
256  {
257  if (route.IsGateway())
258  {
259  os << "network: " << route.GetDestNetwork() << "/ "
260  << int(route.GetDestNetworkPrefix().GetPrefixLength())
261  << ", out: " << route.GetInterface() << ", next hop: " << route.GetGateway();
262  }
263  else
264  {
265  os << "network: " << route.GetDestNetwork() << "/"
266  << int(route.GetDestNetworkPrefix().GetPrefixLength())
267  << ", out: " << route.GetInterface();
268  }
269  }
270  else
271  {
272  NS_ASSERT(false);
273  }
274  return os;
275 }
276 
278 {
279 }
280 
282  const Ipv6MulticastRoutingTableEntry& route)
283  : m_origin(route.m_origin),
284  m_group(route.m_group),
285  m_inputInterface(route.m_inputInterface),
286  m_outputInterfaces(route.m_outputInterfaces)
287 {
288 }
289 
291  const Ipv6MulticastRoutingTableEntry* route)
292  : m_origin(route->m_origin),
293  m_group(route->m_group),
294  m_inputInterface(route->m_inputInterface),
295  m_outputInterfaces(route->m_outputInterfaces)
296 {
297 }
298 
300  Ipv6Address origin,
301  Ipv6Address group,
302  uint32_t inputInterface,
303  std::vector<uint32_t> outputInterfaces)
304  : m_origin(origin),
305  m_group(group),
306  m_inputInterface(inputInterface),
307  m_outputInterfaces(outputInterfaces)
308 {
309 }
310 
313 {
314  return m_origin;
315 }
316 
319 {
320  return m_group;
321 }
322 
323 uint32_t
325 {
326  return m_inputInterface;
327 }
328 
329 uint32_t
331 {
332  return m_outputInterfaces.size();
333 }
334 
335 uint32_t
337 {
339  "Ipv6MulticastRoutingTableEntry::GetOutputInterface () : index out of bounds");
340 
341  return m_outputInterfaces[n];
342 }
343 
344 std::vector<uint32_t>
346 {
347  return m_outputInterfaces;
348 }
349 
352  Ipv6Address group,
353  uint32_t inputInterface,
354  std::vector<uint32_t> outputInterfaces)
355 {
356  return Ipv6MulticastRoutingTableEntry(origin, group, inputInterface, outputInterfaces);
357 }
358 
359 std::ostream&
360 operator<<(std::ostream& os, const Ipv6MulticastRoutingTableEntry& route)
361 {
362  os << "origin: " << route.GetOrigin() << ", group: " << route.GetGroup()
363  << ", input interface: " << route.GetInputInterface() << ", output interfaces: ";
364 
365  for (uint32_t i = 0; i < route.GetNOutputInterfaces(); ++i)
366  {
367  os << route.GetOutputInterface(i) << " ";
368  }
369 
370  return os;
371 }
372 
373 } /* namespace ns3 */
Describes an IPv6 address.
Definition: ipv6-address.h:49
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
A record of an IPv6 multicast route.
uint32_t GetInputInterface() const
Get the input interface address.
uint32_t GetOutputInterface(uint32_t n) const
Get a specified output interface.
Ipv6Address GetGroup() const
Get the group.
uint32_t m_inputInterface
The input interface.
Ipv6MulticastRoutingTableEntry()
Constructor.
std::vector< uint32_t > GetOutputInterfaces() const
Get all of the output interfaces of this route.
static Ipv6MulticastRoutingTableEntry CreateMulticastRoute(Ipv6Address origin, Ipv6Address group, uint32_t inputInterface, std::vector< uint32_t > outputInterfaces)
Create a multicast route.
std::vector< uint32_t > m_outputInterfaces
The output interfaces.
uint32_t GetNOutputInterfaces() const
Get the number of output interfaces of this route.
Ipv6Address GetOrigin() const
Get the source of this route.
Ipv6Address m_group
The IPv6 address of the group.
Ipv6Address m_origin
The IPv6 address of the source.
Describes an IPv6 prefix.
Definition: ipv6-address.h:455
uint8_t GetPrefixLength() const
Get prefix length.
static Ipv6Prefix GetOnes()
Get the "all-1" IPv6 mask (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
A record of an IPv6 route.
bool IsNetwork() const
Is the route entry correspond to a network ?
static Ipv6RoutingTableEntry CreateDefaultRoute(Ipv6Address nextHop, uint32_t interface)
Create a default route.
Ipv6Address m_gateway
IPv6 address of the gateway.
bool IsDefault() const
Is it the default route ?
Ipv6RoutingTableEntry()
Constructor.
Ipv6Address GetDest() const
Get the destination.
Ipv6Address GetDestNetwork() const
Get the destination network.
Ipv6Address GetPrefixToUse() const
Get the prefix to use (for multihomed link).
Ipv6Address m_dest
IPv6 address of the destination.
static Ipv6RoutingTableEntry CreateHostRouteTo(Ipv6Address dest, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address())
Create a route to a host.
bool IsHost() const
Is the route entry correspond to a host ?
void SetPrefixToUse(Ipv6Address prefix)
Set the prefix to use.
uint32_t GetInterface() const
Get the interface index.
Ipv6Address m_prefixToUse
Prefix to use.
Ipv6Prefix m_destNetworkPrefix
IPv6 prefix of the destination.
virtual ~Ipv6RoutingTableEntry()
Destructor.
uint32_t m_interface
The interface index.
Ipv6Prefix GetDestNetworkPrefix() const
Get the destination prefix.
static Ipv6RoutingTableEntry CreateNetworkRouteTo(Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface)
Create a route to a network.
Ipv6Address GetGateway() const
Get the gateway.
bool IsGateway() const
Is it the gateway ?
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159