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
uan-net-device.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2009 University of Washington
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: Leonard Tracy <lentracy@gmail.com>
19
*/
20
21
#include "ns3/trace-source-accessor.h"
22
#include "ns3/traced-callback.h"
23
#include "ns3/pointer.h"
24
#include "ns3/node.h"
25
#include "ns3/assert.h"
26
#include "
uan-net-device.h
"
27
#include "
uan-phy.h
"
28
#include "
uan-mac.h
"
29
#include "
uan-channel.h
"
30
#include "
uan-transducer.h
"
31
#include "ns3/log.h"
32
33
NS_LOG_COMPONENT_DEFINE
(
"UanNetDevice"
);
34
35
namespace
ns3 {
36
37
NS_OBJECT_ENSURE_REGISTERED
(UanNetDevice);
38
39
UanNetDevice::UanNetDevice
()
40
:
NetDevice
(),
41
m_mtu (64000),
42
m_cleared (false)
43
{
44
}
45
46
UanNetDevice::~UanNetDevice
()
47
{
48
}
49
50
void
51
UanNetDevice::Clear
()
52
{
53
if
(
m_cleared
)
54
{
55
return
;
56
}
57
m_cleared
=
true
;
58
m_node
= 0;
59
if
(
m_channel
)
60
{
61
m_channel
->
Clear
();
62
m_channel
= 0;
63
}
64
if
(
m_mac
)
65
{
66
m_mac
->
Clear
();
67
m_mac
= 0;
68
}
69
if
(
m_phy
)
70
{
71
m_phy
->
Clear
();
72
m_phy
= 0;
73
}
74
if
(
m_trans
)
75
{
76
m_trans
->
Clear
();
77
m_trans
= 0;
78
}
79
}
80
81
void
82
UanNetDevice::DoDispose
()
83
{
84
Clear
();
85
NetDevice::DoDispose
();
86
}
87
88
TypeId
89
UanNetDevice::GetTypeId
()
90
{
91
92
93
static
TypeId
tid =
TypeId
(
"ns3::UanNetDevice"
)
94
.
SetParent
<
NetDevice
> ()
95
.AddAttribute (
"Channel"
,
"The channel attached to this device"
,
96
PointerValue
(),
97
MakePointerAccessor (&
UanNetDevice::DoGetChannel
, &
UanNetDevice::SetChannel
),
98
MakePointerChecker<UanChannel> ())
99
.AddAttribute (
"Phy"
,
"The PHY layer attached to this device."
,
100
PointerValue
(),
101
MakePointerAccessor (&
UanNetDevice::GetPhy
, &
UanNetDevice::SetPhy
),
102
MakePointerChecker<UanPhy> ())
103
.AddAttribute (
"Mac"
,
"The MAC layer attached to this device."
,
104
PointerValue
(),
105
MakePointerAccessor (&
UanNetDevice::GetMac
, &
UanNetDevice::SetMac
),
106
MakePointerChecker<UanMac> ())
107
.AddAttribute (
"Transducer"
,
"The Transducer attached to this device."
,
108
PointerValue
(),
109
MakePointerAccessor (&
UanNetDevice::GetTransducer
,
110
&
UanNetDevice::SetTransducer
),
111
MakePointerChecker<UanTransducer> ())
112
.AddTraceSource (
"Rx"
,
"Received payload from the MAC layer."
,
113
MakeTraceSourceAccessor
(&
UanNetDevice::m_rxLogger
))
114
.AddTraceSource (
"Tx"
,
"Send payload to the MAC layer."
,
115
MakeTraceSourceAccessor
(&
UanNetDevice::m_txLogger
))
116
;
117
return
tid;
118
}
119
120
void
121
UanNetDevice::SetMac
(
Ptr<UanMac>
mac)
122
{
123
if
(mac != 0)
124
{
125
m_mac
= mac;
126
NS_LOG_DEBUG
(
"Set MAC"
);
127
128
if
(
m_phy
!= 0)
129
{
130
m_phy
->
SetMac
(mac);
131
m_mac
->
AttachPhy
(
m_phy
);
132
NS_LOG_DEBUG
(
"Attached MAC to PHY"
);
133
}
134
m_mac
->
SetForwardUpCb
(
MakeCallback
(&
UanNetDevice::ForwardUp
,
this
));
135
}
136
137
}
138
139
void
140
UanNetDevice::SetPhy
(
Ptr<UanPhy>
phy)
141
{
142
if
(phy != 0)
143
{
144
m_phy
= phy;
145
m_phy
->
SetDevice
(
Ptr<UanNetDevice>
(
this
));
146
NS_LOG_DEBUG
(
"Set PHY"
);
147
if
(
m_mac
!= 0)
148
{
149
m_mac
->
AttachPhy
(phy);
150
m_phy
->
SetMac
(
m_mac
);
151
NS_LOG_DEBUG
(
"Attached PHY to MAC"
);
152
}
153
if
(
m_trans
!= 0)
154
{
155
m_phy
->
SetTransducer
(
m_trans
);
156
NS_LOG_DEBUG
(
"Added PHY to trans"
);
157
}
158
159
}
160
}
161
162
void
163
UanNetDevice::SetChannel
(
Ptr<UanChannel>
channel)
164
{
165
if
(channel != 0)
166
{
167
m_channel
= channel;
168
NS_LOG_DEBUG
(
"Set CHANNEL"
);
169
if
(
m_trans
!= 0)
170
{
171
172
m_channel
->
AddDevice
(
this
,
m_trans
);
173
NS_LOG_DEBUG
(
"Added self to channel device list"
);
174
m_trans
->
SetChannel
(
m_channel
);
175
NS_LOG_DEBUG
(
"Set Transducer channel"
);
176
}
177
if
(
m_phy
!= 0 )
178
{
179
m_phy
->
SetChannel
(channel);
180
}
181
}
182
}
183
184
Ptr<UanChannel>
185
UanNetDevice::DoGetChannel
(
void
)
const
186
{
187
return
m_channel
;
188
189
}
190
Ptr<UanMac>
191
UanNetDevice::GetMac
()
const
192
{
193
return
m_mac
;
194
}
195
196
Ptr<UanPhy>
197
UanNetDevice::GetPhy
()
const
198
{
199
return
m_phy
;
200
}
201
202
void
203
UanNetDevice::SetIfIndex
(uint32_t index)
204
{
205
m_ifIndex
= index;
206
}
207
208
uint32_t
209
UanNetDevice::GetIfIndex
()
const
210
{
211
return
m_ifIndex
;
212
}
213
214
Ptr<Channel>
215
UanNetDevice::GetChannel
()
const
216
{
217
return
m_channel
;
218
}
219
220
Address
221
UanNetDevice::GetAddress
()
const
222
{
223
return
m_mac
->
GetAddress
();
224
}
225
226
bool
227
UanNetDevice::SetMtu
(uint16_t mtu)
228
{
229
// TODO: Check this in MAC
230
NS_LOG_WARN
(
"UanNetDevice: MTU is not implemented"
);
231
m_mtu
= mtu;
232
return
true
;
233
}
234
235
uint16_t
236
UanNetDevice::GetMtu
()
const
237
{
238
return
m_mtu
;
239
}
240
241
bool
242
UanNetDevice::IsLinkUp
()
const
243
{
244
return
(
m_linkup
&& (
m_phy
!= 0));
245
}
246
247
bool
248
UanNetDevice::IsBroadcast
()
const
249
{
250
return
true
;
251
}
252
253
Address
254
UanNetDevice::GetBroadcast
()
const
255
{
256
return
m_mac
->
GetBroadcast
();
257
}
258
259
bool
260
UanNetDevice::IsMulticast
()
const
261
{
262
return
false
;
263
}
264
265
Address
266
UanNetDevice::GetMulticast
(
Ipv4Address
multicastGroup)
const
267
{
268
NS_FATAL_ERROR
(
"UanNetDevice does not support multicast"
);
269
return
m_mac
->
GetBroadcast
();
270
}
271
272
Address
273
UanNetDevice::GetMulticast
(
Ipv6Address
addr)
const
274
{
275
NS_FATAL_ERROR
(
"UanNetDevice does not support multicast"
);
276
return
m_mac
->
GetBroadcast
();
277
}
278
279
bool
280
UanNetDevice::IsBridge
(
void
)
const
281
{
282
return
false
;
283
}
284
bool
285
UanNetDevice::IsPointToPoint
()
const
286
{
287
return
false
;
288
}
289
290
bool
291
UanNetDevice::Send
(
Ptr<Packet>
packet,
const
Address
&dest, uint16_t protocolNumber)
292
{
293
return
m_mac
->
Enqueue
(packet, dest, protocolNumber);
294
}
295
296
bool
297
UanNetDevice::SendFrom
(
Ptr<Packet>
packet,
const
Address
& source,
const
Address
& dest, uint16_t protocolNumber)
298
{
299
// Not yet implemented
300
NS_ASSERT_MSG
(0,
"Not yet implemented"
);
301
return
false
;
302
}
303
Ptr<Node>
304
UanNetDevice::GetNode
()
const
305
{
306
return
m_node
;
307
}
308
309
void
310
UanNetDevice::SetNode
(
Ptr<Node>
node)
311
{
312
m_node
= node;
313
}
314
315
bool
316
UanNetDevice::NeedsArp
()
const
317
{
318
return
false
;
319
}
320
321
void
322
UanNetDevice::SetReceiveCallback
(
NetDevice::ReceiveCallback
cb)
323
{
324
m_forwardUp
= cb;
325
}
326
327
void
328
UanNetDevice::ForwardUp
(
Ptr<Packet>
pkt,
const
UanAddress
&src)
329
{
330
NS_LOG_DEBUG
(
"Forwarding packet up to application"
);
331
m_rxLogger
(pkt, src);
332
m_forwardUp
(
this
, pkt, 0, src);
333
334
}
335
336
Ptr<UanTransducer>
337
UanNetDevice::GetTransducer
(
void
)
const
338
{
339
return
m_trans
;
340
}
341
void
342
UanNetDevice::SetTransducer
(
Ptr<UanTransducer>
trans)
343
{
344
345
if
(trans != 0)
346
{
347
m_trans
= trans;
348
NS_LOG_DEBUG
(
"Set Transducer"
);
349
if
(
m_phy
!= 0)
350
{
351
m_phy
->
SetTransducer
(
m_trans
);
352
NS_LOG_DEBUG
(
"Attached Phy to transducer"
);
353
}
354
355
if
(
m_channel
!= 0)
356
{
357
m_channel
->
AddDevice
(
this
,
m_trans
);
358
m_trans
->
SetChannel
(
m_channel
);
359
NS_LOG_DEBUG
(
"Added self to channel device list"
);
360
}
361
}
362
363
}
364
365
void
366
UanNetDevice::AddLinkChangeCallback
(
Callback<void>
callback)
367
{
368
m_linkChanges
.
ConnectWithoutContext
(callback);
369
}
370
371
372
void
373
UanNetDevice::SetPromiscReceiveCallback
(
PromiscReceiveCallback
cb)
374
{
375
// Not implemented yet
376
NS_ASSERT_MSG
(0,
"Not yet implemented"
);
377
}
378
379
bool
380
UanNetDevice::SupportsSendFrom
(
void
)
const
381
{
382
return
false
;
383
}
384
385
void
386
UanNetDevice::SetAddress
(
Address
address)
387
{
388
NS_ASSERT_MSG
(0,
"Tried to set MAC address with no MAC"
);
389
m_mac
->
SetAddress
(
UanAddress::ConvertFrom
(address));
390
}
391
392
void
393
UanNetDevice::SetSleepMode
(
bool
sleep)
394
{
395
m_phy
->
SetSleepMode
(sleep);
396
}
397
398
}
// namespace ns3
399
src
uan
model
uan-net-device.cc
Generated on Tue May 14 2013 11:08:34 for ns-3 by
1.8.1.2