~ubuntu-branches/ubuntu/quantal/ns3/quantal

« back to all changes in this revision

Viewing changes to ns-3.12.1/src/internet/model/ipv4-routing-table-entry.cc

  • Committer: Package Import Robot
  • Author(s): YunQiang Su, Aron Xu, YunQiang Su, Upstream
  • Date: 2012-01-06 00:35:42 UTC
  • mfrom: (10.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20120106003542-vcn5g03mhapm991h
Tags: 3.13+dfsg-1
[ Aron Xu ]:
        add tag binary and binary-indep, 
  for not build doc when --binary-arch (Closes: #654493).
[ YunQiang Su ]
        add waf 1.5/1.6 source to debian directory, 
  and build waf from there (Closes: #642217).
[ Upstream ]
  Successfully link with --as-needed option (Closes: #642225).

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
21
 
#include "ipv4-routing-table-entry.h"
22
 
#include "ns3/assert.h"
23
 
 
24
 
namespace ns3 {
25
 
 
26
 
/*****************************************************
27
 
 *     Network Ipv4RoutingTableEntry
28
 
 *****************************************************/
29
 
 
30
 
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry ()
31
 
{
32
 
}
33
 
 
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)
39
 
{
40
 
}
41
 
 
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)
47
 
{
48
 
}
49
 
 
50
 
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry (Ipv4Address dest,
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
 
}
59
 
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry (Ipv4Address dest,
60
 
                                              uint32_t interface)
61
 
  : m_dest (dest),
62
 
    m_destNetworkMask (Ipv4Mask::GetOnes ()),
63
 
    m_gateway (Ipv4Address::GetZero ()),
64
 
    m_interface (interface)
65
 
{
66
 
}
67
 
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry (Ipv4Address network,
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
 
}
77
 
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry (Ipv4Address network,
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
88
 
Ipv4RoutingTableEntry::IsHost (void) const
89
 
{
90
 
  if (m_destNetworkMask.IsEqual (Ipv4Mask::GetOnes ()))
91
 
    {
92
 
      return true;
93
 
    }
94
 
  else
95
 
    {
96
 
      return false;
97
 
    }
98
 
}
99
 
Ipv4Address
100
 
Ipv4RoutingTableEntry::GetDest (void) const
101
 
{
102
 
  return m_dest;
103
 
}
104
 
bool
105
 
Ipv4RoutingTableEntry::IsNetwork (void) const
106
 
{
107
 
  return !IsHost ();
108
 
}
109
 
bool
110
 
Ipv4RoutingTableEntry::IsDefault (void) const
111
 
{
112
 
  if (m_dest.IsEqual (Ipv4Address::GetZero ()))
113
 
    {
114
 
      return true;
115
 
    }
116
 
  else
117
 
    {
118
 
      return false;
119
 
    }
120
 
}
121
 
Ipv4Address
122
 
Ipv4RoutingTableEntry::GetDestNetwork (void) const
123
 
{
124
 
  return m_dest;
125
 
}
126
 
Ipv4Mask
127
 
Ipv4RoutingTableEntry::GetDestNetworkMask (void) const
128
 
{
129
 
  return m_destNetworkMask;
130
 
}
131
 
bool
132
 
Ipv4RoutingTableEntry::IsGateway (void) const
133
 
{
134
 
  if (m_gateway.IsEqual (Ipv4Address::GetZero ()))
135
 
    {
136
 
      return false;
137
 
    }
138
 
  else
139
 
    {
140
 
      return true;
141
 
    }
142
 
}
143
 
Ipv4Address
144
 
Ipv4RoutingTableEntry::GetGateway (void) const
145
 
{
146
 
  return m_gateway;
147
 
}
148
 
uint32_t
149
 
Ipv4RoutingTableEntry::GetInterface (void) const
150
 
{
151
 
  return m_interface;
152
 
}
153
 
 
154
 
Ipv4RoutingTableEntry 
155
 
Ipv4RoutingTableEntry::CreateHostRouteTo (Ipv4Address dest, 
156
 
                                          Ipv4Address nextHop,
157
 
                                          uint32_t interface)
158
 
{
159
 
  return Ipv4RoutingTableEntry (dest, nextHop, interface);
160
 
}
161
 
Ipv4RoutingTableEntry 
162
 
Ipv4RoutingTableEntry::CreateHostRouteTo (Ipv4Address dest,
163
 
                                          uint32_t interface)
164
 
{
165
 
  return Ipv4RoutingTableEntry (dest, interface);
166
 
}
167
 
Ipv4RoutingTableEntry 
168
 
Ipv4RoutingTableEntry::CreateNetworkRouteTo (Ipv4Address network, 
169
 
                                             Ipv4Mask networkMask,
170
 
                                             Ipv4Address nextHop,
171
 
                                             uint32_t interface)
172
 
{
173
 
  return Ipv4RoutingTableEntry (network, networkMask, 
174
 
                                nextHop, interface);
175
 
}
176
 
Ipv4RoutingTableEntry 
177
 
Ipv4RoutingTableEntry::CreateNetworkRouteTo (Ipv4Address network, 
178
 
                                             Ipv4Mask networkMask,
179
 
                                             uint32_t interface)
180
 
{
181
 
  return Ipv4RoutingTableEntry (network, networkMask, 
182
 
                                interface);
183
 
}
184
 
Ipv4RoutingTableEntry 
185
 
Ipv4RoutingTableEntry::CreateDefaultRoute (Ipv4Address nextHop, 
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
 
 
240
 
Ipv4MulticastRoutingTableEntry::Ipv4MulticastRoutingTableEntry ()
241
 
{
242
 
}
243
 
 
244
 
Ipv4MulticastRoutingTableEntry::Ipv4MulticastRoutingTableEntry (Ipv4MulticastRoutingTableEntry const &route)
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
 
 
253
 
Ipv4MulticastRoutingTableEntry::Ipv4MulticastRoutingTableEntry (Ipv4MulticastRoutingTableEntry const *route)
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
 
 
262
 
Ipv4MulticastRoutingTableEntry::Ipv4MulticastRoutingTableEntry (
263
 
  Ipv4Address origin, 
264
 
  Ipv4Address group, 
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
 
 
274
 
Ipv4Address 
275
 
Ipv4MulticastRoutingTableEntry::GetOrigin (void) const
276
 
{
277
 
  return m_origin;
278
 
}
279
 
 
280
 
Ipv4Address 
281
 
Ipv4MulticastRoutingTableEntry::GetGroup (void) const
282
 
{
283
 
  return m_group;
284
 
}
285
 
 
286
 
uint32_t 
287
 
Ipv4MulticastRoutingTableEntry::GetInputInterface (void) const
288
 
{
289
 
  return m_inputInterface;
290
 
}
291
 
 
292
 
uint32_t
293
 
Ipv4MulticastRoutingTableEntry::GetNOutputInterfaces (void) const
294
 
{
295
 
  return m_outputInterfaces.size ();
296
 
}
297
 
 
298
 
uint32_t
299
 
Ipv4MulticastRoutingTableEntry::GetOutputInterface (uint32_t n) const
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>
308
 
Ipv4MulticastRoutingTableEntry::GetOutputInterfaces (void) const
309
 
{
310
 
  return m_outputInterfaces;
311
 
}
312
 
 
313
 
Ipv4MulticastRoutingTableEntry 
314
 
Ipv4MulticastRoutingTableEntry::CreateMulticastRoute (
315
 
  Ipv4Address origin, 
316
 
  Ipv4Address group, 
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