A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
21
#include "
ipv4-routing-table-entry.h
"
22
#include "ns3/assert.h"
23
#include "ns3/log.h"
24
25
NS_LOG_COMPONENT_DEFINE
(
"Ipv4RoutingTableEntry"
);
26
27
namespace
ns3 {
28
29
/*****************************************************
30
* Network Ipv4RoutingTableEntry
31
*****************************************************/
32
33
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry
()
34
{
35
NS_LOG_FUNCTION
(
this
);
36
}
37
38
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry
(
Ipv4RoutingTableEntry
const
&route)
39
: m_dest (route.m_dest),
40
m_destNetworkMask (route.m_destNetworkMask),
41
m_gateway (route.m_gateway),
42
m_interface (route.m_interface)
43
{
44
NS_LOG_FUNCTION
(
this
<< route);
45
}
46
47
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry
(
Ipv4RoutingTableEntry
const
*route)
48
: m_dest (route->m_dest),
49
m_destNetworkMask (route->m_destNetworkMask),
50
m_gateway (route->m_gateway),
51
m_interface (route->m_interface)
52
{
53
NS_LOG_FUNCTION
(
this
<< route);
54
}
55
56
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry
(
Ipv4Address
dest,
57
Ipv4Address
gateway,
58
uint32_t interface)
59
: m_dest (dest),
60
m_destNetworkMask (
Ipv4Mask
::GetOnes ()),
61
m_gateway (gateway),
62
m_interface (interface)
63
{
64
}
65
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry
(
Ipv4Address
dest,
66
uint32_t interface)
67
: m_dest (dest),
68
m_destNetworkMask (
Ipv4Mask
::GetOnes ()),
69
m_gateway (
Ipv4Address
::GetZero ()),
70
m_interface (interface)
71
{
72
}
73
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry
(
Ipv4Address
network,
74
Ipv4Mask
networkMask,
75
Ipv4Address
gateway,
76
uint32_t interface)
77
: m_dest (network),
78
m_destNetworkMask (networkMask),
79
m_gateway (gateway),
80
m_interface (interface)
81
{
82
NS_LOG_FUNCTION
(
this
<< network << networkMask << gateway << interface);
83
}
84
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry
(
Ipv4Address
network,
85
Ipv4Mask
networkMask,
86
uint32_t interface)
87
: m_dest (network),
88
m_destNetworkMask (networkMask),
89
m_gateway (
Ipv4Address
::GetZero ()),
90
m_interface (interface)
91
{
92
NS_LOG_FUNCTION
(
this
<< network << networkMask << interface);
93
}
94
95
bool
96
Ipv4RoutingTableEntry::IsHost
(
void
)
const
97
{
98
NS_LOG_FUNCTION
(
this
);
99
if
(
m_destNetworkMask
.
IsEqual
(
Ipv4Mask::GetOnes
()))
100
{
101
return
true
;
102
}
103
else
104
{
105
return
false
;
106
}
107
}
108
Ipv4Address
109
Ipv4RoutingTableEntry::GetDest
(
void
)
const
110
{
111
NS_LOG_FUNCTION
(
this
);
112
return
m_dest
;
113
}
114
bool
115
Ipv4RoutingTableEntry::IsNetwork
(
void
)
const
116
{
117
NS_LOG_FUNCTION
(
this
);
118
return
!
IsHost
();
119
}
120
bool
121
Ipv4RoutingTableEntry::IsDefault
(
void
)
const
122
{
123
NS_LOG_FUNCTION
(
this
);
124
if
(
m_dest
.
IsEqual
(
Ipv4Address::GetZero
()))
125
{
126
return
true
;
127
}
128
else
129
{
130
return
false
;
131
}
132
}
133
Ipv4Address
134
Ipv4RoutingTableEntry::GetDestNetwork
(
void
)
const
135
{
136
NS_LOG_FUNCTION
(
this
);
137
return
m_dest
;
138
}
139
Ipv4Mask
140
Ipv4RoutingTableEntry::GetDestNetworkMask
(
void
)
const
141
{
142
NS_LOG_FUNCTION
(
this
);
143
return
m_destNetworkMask
;
144
}
145
bool
146
Ipv4RoutingTableEntry::IsGateway
(
void
)
const
147
{
148
NS_LOG_FUNCTION
(
this
);
149
if
(
m_gateway
.
IsEqual
(
Ipv4Address::GetZero
()))
150
{
151
return
false
;
152
}
153
else
154
{
155
return
true
;
156
}
157
}
158
Ipv4Address
159
Ipv4RoutingTableEntry::GetGateway
(
void
)
const
160
{
161
NS_LOG_FUNCTION
(
this
);
162
return
m_gateway
;
163
}
164
uint32_t
165
Ipv4RoutingTableEntry::GetInterface
(
void
)
const
166
{
167
NS_LOG_FUNCTION
(
this
);
168
return
m_interface
;
169
}
170
171
Ipv4RoutingTableEntry
172
Ipv4RoutingTableEntry::CreateHostRouteTo
(
Ipv4Address
dest,
173
Ipv4Address
nextHop,
174
uint32_t interface)
175
{
176
NS_LOG_FUNCTION_NOARGS
();
177
return
Ipv4RoutingTableEntry
(dest, nextHop, interface);
178
}
179
Ipv4RoutingTableEntry
180
Ipv4RoutingTableEntry::CreateHostRouteTo
(
Ipv4Address
dest,
181
uint32_t interface)
182
{
183
NS_LOG_FUNCTION_NOARGS
();
184
return
Ipv4RoutingTableEntry
(dest, interface);
185
}
186
Ipv4RoutingTableEntry
187
Ipv4RoutingTableEntry::CreateNetworkRouteTo
(
Ipv4Address
network,
188
Ipv4Mask
networkMask,
189
Ipv4Address
nextHop,
190
uint32_t interface)
191
{
192
NS_LOG_FUNCTION_NOARGS
();
193
return
Ipv4RoutingTableEntry
(network, networkMask,
194
nextHop, interface);
195
}
196
Ipv4RoutingTableEntry
197
Ipv4RoutingTableEntry::CreateNetworkRouteTo
(
Ipv4Address
network,
198
Ipv4Mask
networkMask,
199
uint32_t interface)
200
{
201
NS_LOG_FUNCTION_NOARGS
();
202
return
Ipv4RoutingTableEntry
(network, networkMask,
203
interface);
204
}
205
Ipv4RoutingTableEntry
206
Ipv4RoutingTableEntry::CreateDefaultRoute
(
Ipv4Address
nextHop,
207
uint32_t interface)
208
{
209
NS_LOG_FUNCTION_NOARGS
();
210
return
Ipv4RoutingTableEntry
(
Ipv4Address::GetZero
(), nextHop, interface);
211
}
212
213
214
std::ostream&
operator<<
(std::ostream& os,
Ipv4RoutingTableEntry
const
& route)
215
{
216
if
(route.
IsDefault
())
217
{
218
NS_ASSERT
(route.
IsGateway
());
219
os <<
"default out="
<< route.
GetInterface
() <<
", next hop="
<< route.
GetGateway
();
220
}
221
else
if
(route.
IsHost
())
222
{
223
if
(route.
IsGateway
())
224
{
225
os <<
"host="
<< route.
GetDest
() <<
226
", out="
<< route.
GetInterface
() <<
227
", next hop="
<< route.
GetGateway
();
228
}
229
else
230
{
231
os <<
"host="
<< route.
GetDest
() <<
232
", out="
<< route.
GetInterface
();
233
}
234
}
235
else
if
(route.
IsNetwork
())
236
{
237
if
(route.
IsGateway
())
238
{
239
os <<
"network="
<< route.
GetDestNetwork
() <<
240
", mask="
<< route.
GetDestNetworkMask
() <<
241
",out="
<< route.
GetInterface
() <<
242
", next hop="
<< route.
GetGateway
();
243
}
244
else
245
{
246
os <<
"network="
<< route.
GetDestNetwork
() <<
247
", mask="
<< route.
GetDestNetworkMask
() <<
248
",out="
<< route.
GetInterface
();
249
}
250
}
251
else
252
{
253
NS_ASSERT
(
false
);
254
}
255
return
os;
256
}
257
258
/*****************************************************
259
* Ipv4MulticastRoutingTableEntry
260
*****************************************************/
261
262
Ipv4MulticastRoutingTableEntry::Ipv4MulticastRoutingTableEntry
()
263
{
264
NS_LOG_FUNCTION
(
this
);
265
}
266
267
Ipv4MulticastRoutingTableEntry::Ipv4MulticastRoutingTableEntry
(
Ipv4MulticastRoutingTableEntry
const
&route)
268
:
269
m_origin (route.m_origin),
270
m_group (route.m_group),
271
m_inputInterface (route.m_inputInterface),
272
m_outputInterfaces (route.m_outputInterfaces)
273
{
274
NS_LOG_FUNCTION
(
this
<< route);
275
}
276
277
Ipv4MulticastRoutingTableEntry::Ipv4MulticastRoutingTableEntry
(
Ipv4MulticastRoutingTableEntry
const
*route)
278
:
279
m_origin (route->m_origin),
280
m_group (route->m_group),
281
m_inputInterface (route->m_inputInterface),
282
m_outputInterfaces (route->m_outputInterfaces)
283
{
284
NS_LOG_FUNCTION
(
this
<< route);
285
}
286
287
Ipv4MulticastRoutingTableEntry::Ipv4MulticastRoutingTableEntry
(
288
Ipv4Address
origin,
289
Ipv4Address
group
,
290
uint32_t inputInterface,
291
std::vector<uint32_t> outputInterfaces)
292
{
293
NS_LOG_FUNCTION
(
this
<< origin << group << inputInterface << &outputInterfaces);
294
m_origin
= origin;
295
m_group
=
group
;
296
m_inputInterface
= inputInterface;
297
m_outputInterfaces
= outputInterfaces;
298
}
299
300
Ipv4Address
301
Ipv4MulticastRoutingTableEntry::GetOrigin
(
void
)
const
302
{
303
NS_LOG_FUNCTION
(
this
);
304
return
m_origin
;
305
}
306
307
Ipv4Address
308
Ipv4MulticastRoutingTableEntry::GetGroup
(
void
)
const
309
{
310
NS_LOG_FUNCTION
(
this
);
311
return
m_group
;
312
}
313
314
uint32_t
315
Ipv4MulticastRoutingTableEntry::GetInputInterface
(
void
)
const
316
{
317
NS_LOG_FUNCTION
(
this
);
318
return
m_inputInterface
;
319
}
320
321
uint32_t
322
Ipv4MulticastRoutingTableEntry::GetNOutputInterfaces
(
void
)
const
323
{
324
NS_LOG_FUNCTION
(
this
);
325
return
m_outputInterfaces
.size ();
326
}
327
328
uint32_t
329
Ipv4MulticastRoutingTableEntry::GetOutputInterface
(uint32_t n)
const
330
{
331
NS_LOG_FUNCTION
(
this
<< n);
332
NS_ASSERT_MSG
(n <
m_outputInterfaces
.size (),
333
"Ipv4MulticastRoutingTableEntry::GetOutputInterface (): index out of bounds"
);
334
335
return
m_outputInterfaces
[n];
336
}
337
338
std::vector<uint32_t>
339
Ipv4MulticastRoutingTableEntry::GetOutputInterfaces
(
void
)
const
340
{
341
NS_LOG_FUNCTION
(
this
);
342
return
m_outputInterfaces
;
343
}
344
345
Ipv4MulticastRoutingTableEntry
346
Ipv4MulticastRoutingTableEntry::CreateMulticastRoute
(
347
Ipv4Address
origin,
348
Ipv4Address
group
,
349
uint32_t inputInterface,
350
std::vector<uint32_t> outputInterfaces)
351
{
352
NS_LOG_FUNCTION_NOARGS
();
353
return
Ipv4MulticastRoutingTableEntry
(origin, group, inputInterface, outputInterfaces);
354
}
355
356
std::ostream&
357
operator<<
(std::ostream& os,
Ipv4MulticastRoutingTableEntry
const
& route)
358
{
359
os <<
"origin="
<< route.
GetOrigin
() <<
360
", group="
<< route.
GetGroup
() <<
361
", input interface="
<< route.
GetInputInterface
() <<
362
", output interfaces="
;
363
364
for
(uint32_t i = 0; i < route.
GetNOutputInterfaces
(); ++i)
365
{
366
os << route.
GetOutputInterface
(i) <<
" "
;
367
368
}
369
370
return
os;
371
}
372
373
}
// namespace ns3
src
internet
model
ipv4-routing-table-entry.cc
Generated on Tue May 14 2013 11:08:22 for ns-3 by
1.8.1.2