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 
24 namespace ns3 {
25 
26 /*****************************************************
27  * Network Ipv4RoutingTableEntry
28  *****************************************************/
29 
31 {
32 }
33 
35  : m_dest (route.m_dest),
36  m_destNetworkMask (route.m_destNetworkMask),
37  m_gateway (route.m_gateway),
38  m_interface (route.m_interface)
39 {
40 }
41 
43  : m_dest (route->m_dest),
44  m_destNetworkMask (route->m_destNetworkMask),
45  m_gateway (route->m_gateway),
46  m_interface (route->m_interface)
47 {
48 }
49 
51  Ipv4Address gateway,
52  uint32_t interface)
53  : m_dest (dest),
54  m_destNetworkMask (Ipv4Mask::GetOnes ()),
55  m_gateway (gateway),
56  m_interface (interface)
57 {
58 }
60  uint32_t interface)
61  : m_dest (dest),
62  m_destNetworkMask (Ipv4Mask::GetOnes ()),
63  m_gateway (Ipv4Address::GetZero ()),
64  m_interface (interface)
65 {
66 }
68  Ipv4Mask networkMask,
69  Ipv4Address gateway,
70  uint32_t interface)
71  : m_dest (network),
72  m_destNetworkMask (networkMask),
73  m_gateway (gateway),
74  m_interface (interface)
75 {
76 }
78  Ipv4Mask networkMask,
79  uint32_t interface)
80  : m_dest (network),
81  m_destNetworkMask (networkMask),
82  m_gateway (Ipv4Address::GetZero ()),
83  m_interface (interface)
84 {
85 }
86 
87 bool
89 {
91  {
92  return true;
93  }
94  else
95  {
96  return false;
97  }
98 }
101 {
102  return m_dest;
103 }
104 bool
106 {
107  return !IsHost ();
108 }
109 bool
111 {
113  {
114  return true;
115  }
116  else
117  {
118  return false;
119  }
120 }
123 {
124  return m_dest;
125 }
126 Ipv4Mask
128 {
129  return m_destNetworkMask;
130 }
131 bool
133 {
135  {
136  return false;
137  }
138  else
139  {
140  return true;
141  }
142 }
145 {
146  return m_gateway;
147 }
148 uint32_t
150 {
151  return m_interface;
152 }
153 
156  Ipv4Address nextHop,
157  uint32_t interface)
158 {
159  return Ipv4RoutingTableEntry (dest, nextHop, interface);
160 }
163  uint32_t interface)
164 {
165  return Ipv4RoutingTableEntry (dest, interface);
166 }
169  Ipv4Mask networkMask,
170  Ipv4Address nextHop,
171  uint32_t interface)
172 {
173  return Ipv4RoutingTableEntry (network, networkMask,
174  nextHop, interface);
175 }
178  Ipv4Mask networkMask,
179  uint32_t interface)
180 {
181  return Ipv4RoutingTableEntry (network, networkMask,
182  interface);
183 }
186  uint32_t interface)
187 {
188  return Ipv4RoutingTableEntry (Ipv4Address::GetZero (), nextHop, interface);
189 }
190 
191 
192 std::ostream& operator<< (std::ostream& os, Ipv4RoutingTableEntry const& route)
193 {
194  if (route.IsDefault ())
195  {
196  NS_ASSERT (route.IsGateway ());
197  os << "default out=" << route.GetInterface () << ", next hop=" << route.GetGateway ();
198  }
199  else if (route.IsHost ())
200  {
201  if (route.IsGateway ())
202  {
203  os << "host="<< route.GetDest () <<
204  ", out=" << route.GetInterface () <<
205  ", next hop=" << route.GetGateway ();
206  }
207  else
208  {
209  os << "host="<< route.GetDest () <<
210  ", out=" << route.GetInterface ();
211  }
212  }
213  else if (route.IsNetwork ())
214  {
215  if (route.IsGateway ())
216  {
217  os << "network=" << route.GetDestNetwork () <<
218  ", mask=" << route.GetDestNetworkMask () <<
219  ",out=" << route.GetInterface () <<
220  ", next hop=" << route.GetGateway ();
221  }
222  else
223  {
224  os << "network=" << route.GetDestNetwork () <<
225  ", mask=" << route.GetDestNetworkMask () <<
226  ",out=" << route.GetInterface ();
227  }
228  }
229  else
230  {
231  NS_ASSERT (false);
232  }
233  return os;
234 }
235 
236 /*****************************************************
237  * Ipv4MulticastRoutingTableEntry
238  *****************************************************/
239 
241 {
242 }
243 
245  :
246  m_origin (route.m_origin),
247  m_group (route.m_group),
248  m_inputInterface (route.m_inputInterface),
249  m_outputInterfaces (route.m_outputInterfaces)
250 {
251 }
252 
254  :
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  Ipv4Address origin,
265  uint32_t inputInterface,
266  std::vector<uint32_t> outputInterfaces)
267 {
268  m_origin = origin;
269  m_group = group;
270  m_inputInterface = inputInterface;
271  m_outputInterfaces = outputInterfaces;
272 }
273 
276 {
277  return m_origin;
278 }
279 
282 {
283  return m_group;
284 }
285 
286 uint32_t
288 {
289  return m_inputInterface;
290 }
291 
292 uint32_t
294 {
295  return m_outputInterfaces.size ();
296 }
297 
298 uint32_t
300 {
301  NS_ASSERT_MSG (n < m_outputInterfaces.size (),
302  "Ipv4MulticastRoutingTableEntry::GetOutputInterface (): index out of bounds");
303 
304  return m_outputInterfaces[n];
305 }
306 
307 std::vector<uint32_t>
309 {
310  return m_outputInterfaces;
311 }
312 
315  Ipv4Address origin,
317  uint32_t inputInterface,
318  std::vector<uint32_t> outputInterfaces)
319 {
320  return Ipv4MulticastRoutingTableEntry (origin, group, inputInterface, outputInterfaces);
321 }
322 
323 std::ostream&
324 operator<< (std::ostream& os, Ipv4MulticastRoutingTableEntry const& route)
325 {
326  os << "origin=" << route.GetOrigin () <<
327  ", group=" << route.GetGroup () <<
328  ", input interface=" << route.GetInputInterface () <<
329  ", output interfaces=";
330 
331  for (uint32_t i = 0; i < route.GetNOutputInterfaces (); ++i)
332  {
333  os << route.GetOutputInterface (i) << " ";
334 
335  }
336 
337  return os;
338 }
339 
340 } // namespace ns3