A Discrete-Event Network Simulator
API
ipv6-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) 2007-2009 Strasbourg University
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: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19  */
20 
21 #include "ns3/assert.h"
22 
24 
25 namespace ns3
26 {
27 
29 {
30 }
31 
33  : m_dest (route.m_dest),
34  m_destNetworkPrefix (route.m_destNetworkPrefix),
35  m_gateway (route.m_gateway),
36  m_interface (route.m_interface),
37  m_prefixToUse (route.m_prefixToUse)
38 {
39 }
40 
42  : m_dest (route->m_dest),
43  m_destNetworkPrefix (route->m_destNetworkPrefix),
44  m_gateway (route->m_gateway),
45  m_interface (route->m_interface),
46  m_prefixToUse (route->m_prefixToUse)
47 {
48 }
49 
51  : m_dest (dest),
52  m_destNetworkPrefix (Ipv6Prefix::GetZero ()),
53  m_gateway (gateway),
54  m_interface (interface),
55  m_prefixToUse (Ipv6Address ("::"))
56 {
57 }
58 
60  : m_dest (dest),
61  m_destNetworkPrefix (Ipv6Prefix::GetOnes ()),
62  m_gateway (Ipv6Address::GetZero ()),
63  m_interface (interface),
64  m_prefixToUse (Ipv6Address ("::"))
65 {
66 }
67 
68 Ipv6RoutingTableEntry::Ipv6RoutingTableEntry (Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address gateway, uint32_t interface, Ipv6Address prefixToUse)
69  : m_dest (network),
70  m_destNetworkPrefix (networkPrefix),
71  m_gateway (gateway),
72  m_interface (interface),
73  m_prefixToUse (prefixToUse)
74 {
75 }
76 
77 Ipv6RoutingTableEntry::Ipv6RoutingTableEntry (Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address gateway, uint32_t interface)
78  : m_dest (network),
79  m_destNetworkPrefix (networkPrefix),
80  m_gateway (gateway),
81  m_interface (interface),
82  m_prefixToUse (Ipv6Address::GetZero ())
83 {
84 }
85 
86 
87 Ipv6RoutingTableEntry::Ipv6RoutingTableEntry (Ipv6Address network, Ipv6Prefix networkPrefix, uint32_t interface, Ipv6Address prefixToUse)
88  : m_dest (network),
89  m_destNetworkPrefix (networkPrefix),
90  m_gateway (Ipv6Address::GetZero ()),
91  m_interface (interface),
92  m_prefixToUse (prefixToUse)
93 {
94 }
95 
96 Ipv6RoutingTableEntry::Ipv6RoutingTableEntry (Ipv6Address network, Ipv6Prefix networkPrefix, uint32_t interface)
97  : m_dest (network),
98  m_destNetworkPrefix (networkPrefix),
99  m_gateway (Ipv6Address::GetZero ()),
100  m_interface (interface),
101  m_prefixToUse (Ipv6Address ("::"))
102 {
103 }
104 
106 {
107 }
108 
110 {
112  {
113  return true;
114  }
115  return false;
116 }
117 
119 {
120  return m_dest;
121 }
122 
124 {
125  return m_prefixToUse;
126 }
127 
129 {
130  m_prefixToUse = prefix;
131 }
132 
134 {
135  return !IsHost ();
136 }
137 
139 {
141  {
142  return true;
143  }
144  return false;
145 }
146 
148 {
149  return m_dest;
150 }
151 
153 {
154  return m_destNetworkPrefix;
155 }
156 
158 {
160  {
161  return false;
162  }
163  return true;
164 }
165 
167 {
168  return m_gateway;
169 }
170 
172 {
173  return Ipv6RoutingTableEntry (dest, Ipv6Prefix::GetOnes (), nextHop, interface, prefixToUse);
174 }
175 
177 {
178  return Ipv6RoutingTableEntry (dest, interface);
179 }
180 
182 {
183  return Ipv6RoutingTableEntry (network, networkPrefix, nextHop, interface);
184 }
185 
186 Ipv6RoutingTableEntry Ipv6RoutingTableEntry::CreateNetworkRouteTo (Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse)
187 {
188  return Ipv6RoutingTableEntry (network, networkPrefix, nextHop, interface, prefixToUse);
189 }
190 
192 {
193  return Ipv6RoutingTableEntry (network, networkPrefix, interface, network);
194 }
195 
197 {
198  return Ipv6RoutingTableEntry (Ipv6Address::GetZero (), nextHop, interface);
199 }
200 
202 {
203  return m_interface;
204 }
205 
206 std::ostream& operator<< (std::ostream& os, Ipv6RoutingTableEntry const& route)
207 {
208  if (route.IsDefault ())
209  {
210  NS_ASSERT (route.IsGateway ());
211  os << "default out: " << route.GetInterface () << ", next hop: " << route.GetGateway ();
212  }
213  else if (route.IsHost ())
214  {
215  if (route.IsGateway ())
216  {
217  os << "host: "<< route.GetDest () <<
218  ", out: " << route.GetInterface () <<
219  ", next hop: " << route.GetGateway ();
220  }
221  else
222  {
223  os << "host: " << route.GetDest () <<
224  ", out: " << route.GetInterface ();
225  }
226  }
227  else if (route.IsNetwork ())
228  {
229  if (route.IsGateway ())
230  {
231  os << "network: " << route.GetDestNetwork () <<
232  "/ " << int(route.GetDestNetworkPrefix ().GetPrefixLength ()) <<
233  ", out: " << route.GetInterface () <<
234  ", next hop: " << route.GetGateway ();
235  }
236  else
237  {
238  os << "network: " << route.GetDestNetwork () <<
239  "/" << int(route.GetDestNetworkPrefix ().GetPrefixLength ()) <<
240  ", out: " << route.GetInterface ();
241  }
242  }
243  else
244  {
245  NS_ASSERT (false);
246  }
247  return os;
248 }
249 
251 {
252 }
253 
255  : m_origin (route.m_origin),
256  m_group (route.m_group),
257  m_inputInterface (route.m_inputInterface),
258  m_outputInterfaces (route.m_outputInterfaces)
259 {
260 }
261 
263  : m_origin (route->m_origin),
264  m_group (route->m_group),
265  m_inputInterface (route->m_inputInterface),
266  m_outputInterfaces (route->m_outputInterfaces)
267 {
268 }
269 
270 Ipv6MulticastRoutingTableEntry::Ipv6MulticastRoutingTableEntry (Ipv6Address origin, Ipv6Address group, uint32_t inputInterface, std::vector<uint32_t> outputInterfaces)
271  : m_origin (origin),
272  m_group (group),
273  m_inputInterface (inputInterface),
274  m_outputInterfaces (outputInterfaces)
275 {
276 }
277 
279 {
280  return m_origin;
281 }
282 
284 {
285  return m_group;
286 }
287 
289 {
290  return m_inputInterface;
291 }
292 
294 {
295  return m_outputInterfaces.size ();
296 }
297 
299 {
300  NS_ASSERT_MSG (n < m_outputInterfaces.size (), "Ipv6MulticastRoutingTableEntry::GetOutputInterface () : index out of bounds");
301 
302  return m_outputInterfaces[n];
303 }
304 
306 {
307  return m_outputInterfaces;
308 }
309 
310 Ipv6MulticastRoutingTableEntry Ipv6MulticastRoutingTableEntry::CreateMulticastRoute (Ipv6Address origin, Ipv6Address group, uint32_t inputInterface, std::vector<uint32_t> outputInterfaces)
311 {
312  return Ipv6MulticastRoutingTableEntry (origin, group, inputInterface, outputInterfaces);
313 }
314 
315 std::ostream& operator<< (std::ostream& os, Ipv6MulticastRoutingTableEntry const& route)
316 {
317  os << "origin: " << route.GetOrigin () <<
318  ", group: " << route.GetGroup () <<
319  ", input interface: " << route.GetInputInterface () <<
320  ", output interfaces: ";
321 
322  for (uint32_t i = 0; i < route.GetNOutputInterfaces (); ++i)
323  {
324  os << route.GetOutputInterface (i) << " ";
325  }
326 
327  return os;
328 }
329 
330 } /* namespace ns3 */
331 
void SetPrefixToUse(Ipv6Address prefix)
Set the prefix to use.
bool IsGateway() const
Is it the gateway ?
Ipv6Address GetGroup() const
Get the group.
Ipv6Address GetPrefixToUse() const
Get the prefix to use (for multihomed link).
static Ipv6RoutingTableEntry CreateNetworkRouteTo(Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface)
Create a route to a network.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
A record of an IPv6 multicast route.
Ipv6RoutingTableEntry()
Constructor.
static Ipv6RoutingTableEntry CreateHostRouteTo(Ipv6Address dest, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address())
Create a route to a host.
#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
bool IsNetwork() const
Is the route entry correspond to a network ?
Ipv6MulticastRoutingTableEntry()
Constructor.
static Ipv6MulticastRoutingTableEntry CreateMulticastRoute(Ipv6Address origin, Ipv6Address group, uint32_t inputInterface, std::vector< uint32_t > outputInterfaces)
Create a multicast route.
uint32_t m_inputInterface
The input interface.
Ipv6Address GetDestNetwork() const
Get the destination network.
Ipv6Address m_prefixToUse
Prefix to use.
Ipv6Address GetOrigin() const
Get the source of this route.
A record of an IPv6 route.
Ipv6Address m_group
The IPv6 address of the group.
Ipv6Prefix m_destNetworkPrefix
IPv6 prefix of the destination.
bool IsEqual(const Ipv6Address &other) const
Comparison operation between two Ipv6Addresses.
Ipv6Address GetDest() const
Get the destination.
bool IsHost() const
Is the route entry correspond to a host ?
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
Ipv6Address GetGateway() const
Get the gateway.
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
bool IsDefault() const
Is it the default route ?
static Ipv6RoutingTableEntry CreateDefaultRoute(Ipv6Address nextHop, uint32_t interface)
Create a default route.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ipv6Address m_origin
The IPv6 address of the source.
Ipv6Address m_gateway
IPv6 address of the gateway.
uint8_t GetPrefixLength() const
Get prefix length.
bool IsEqual(const Ipv6Prefix &other) const
Comparison operation between two Ipv6Prefix.
Describes an IPv6 address.
Definition: ipv6-address.h:49
static Ipv6Prefix GetOnes()
Get the "all-1" IPv6 mask (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
uint32_t GetInputInterface() const
Get the input interface address.
uint32_t m_interface
The interface index.
virtual ~Ipv6RoutingTableEntry()
Destructor.
Describes an IPv6 prefix.
Definition: ipv6-address.h:428
std::vector< uint32_t > m_outputInterfaces
The output interfaces.
Ipv6Prefix GetDestNetworkPrefix() const
Get the destination prefix.
Ipv6Address m_dest
IPv6 address of the destination.
uint32_t GetNOutputInterfaces() const
Get the number of output interfaces of this route.
uint32_t GetInterface() const
Get the interface index.
uint32_t GetOutputInterface(uint32_t n) const
Get a specified output interface.
std::vector< uint32_t > GetOutputInterfaces() const
Get all of the output interfaces of this route.