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
wimax-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) 2007,2008,2009 INRIA, UDcast
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
* Authors: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
19
* Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
20
* <amine.ismail@UDcast.com>
21
*/
22
23
#include "ns3/llc-snap-header.h"
24
#include "ns3/simulator.h"
25
#include "ns3/callback.h"
26
#include "ns3/node.h"
27
#include "ns3/packet.h"
28
#include "
wimax-net-device.h
"
29
#include "
wimax-channel.h
"
30
#include "ns3/packet-burst.h"
31
#include "
burst-profile-manager.h
"
32
#include <list>
33
#include "
send-params.h
"
34
#include "ns3/uinteger.h"
35
#include "ns3/trace-source-accessor.h"
36
#include "ns3/pointer.h"
37
#include "ns3/enum.h"
38
#include "
service-flow-manager.h
"
39
#include "
connection-manager.h
"
40
#include "
bandwidth-manager.h
"
41
42
NS_LOG_COMPONENT_DEFINE
(
"WimaxNetDevice"
);
43
44
namespace
ns3 {
45
46
NS_OBJECT_ENSURE_REGISTERED
(WimaxNetDevice);
47
48
uint32_t
WimaxNetDevice::m_nrFrames
= 0;
49
uint8_t
WimaxNetDevice::m_direction
= ~0;
50
Time
WimaxNetDevice::m_frameStartTime
=
Seconds
(0);
51
52
TypeId
WimaxNetDevice::GetTypeId
(
void
)
53
{
54
static
TypeId
55
tid =
56
TypeId
(
"ns3::WimaxNetDevice"
)
57
58
.
SetParent
<
NetDevice
> ()
59
60
.AddAttribute (
"Mtu"
,
"The MAC-level Maximum Transmission Unit"
,
61
UintegerValue
(
DEFAULT_MSDU_SIZE
),
62
MakeUintegerAccessor (&
WimaxNetDevice::SetMtu
,
63
&
WimaxNetDevice::GetMtu
),
64
MakeUintegerChecker<uint16_t> (0,
MAX_MSDU_SIZE
))
65
66
.AddAttribute (
"Phy"
,
67
"The PHY layer attached to this device."
,
68
PointerValue
(),
69
MakePointerAccessor (&
WimaxNetDevice::GetPhy
, &
WimaxNetDevice::SetPhy
),
70
MakePointerChecker<WimaxPhy> ())
71
72
.AddAttribute (
"Channel"
,
73
"The channel attached to this device."
,
74
PointerValue
(),
75
MakePointerAccessor (&
WimaxNetDevice::GetPhyChannel
, &
WimaxNetDevice::SetChannel
),
76
MakePointerChecker<WimaxChannel> ())
77
78
.AddAttribute (
"RTG"
,
79
"receive/transmit transition gap."
,
80
UintegerValue
(0),
81
MakeUintegerAccessor (&
WimaxNetDevice::GetRtg
, &
WimaxNetDevice::SetRtg
),
82
MakeUintegerChecker<uint16_t> (0, 120))
83
84
.AddAttribute (
"TTG"
,
85
"transmit/receive transition gap."
,
86
UintegerValue
(0),
87
MakeUintegerAccessor (&
WimaxNetDevice::GetTtg
, &
WimaxNetDevice::SetTtg
),
88
MakeUintegerChecker<uint16_t> (0, 120))
89
90
.AddAttribute (
"ConnectionManager"
,
91
"The connection manager attached to this device."
,
92
PointerValue
(),
93
MakePointerAccessor (&
WimaxNetDevice::GetConnectionManager
,
94
&
WimaxNetDevice::SetConnectionManager
),
95
MakePointerChecker<ConnectionManager> ())
96
97
.AddAttribute (
"BurstProfileManager"
,
98
"The burst profile manager attached to this device."
,
99
PointerValue
(),
100
MakePointerAccessor (&
WimaxNetDevice::GetBurstProfileManager
,
101
&
WimaxNetDevice::SetBurstProfileManager
),
102
MakePointerChecker<BurstProfileManager> ())
103
104
.AddAttribute (
"BandwidthManager"
,
105
"The bandwidth manager attached to this device."
,
106
PointerValue
(),
107
MakePointerAccessor (&
WimaxNetDevice::GetBandwidthManager
,
108
&
WimaxNetDevice::SetBandwidthManager
),
109
MakePointerChecker<BandwidthManager> ())
110
111
.AddAttribute (
"InitialRangingConnection"
,
112
"Initial ranging connection"
,
113
PointerValue
(),
114
MakePointerAccessor (&
WimaxNetDevice::m_initialRangingConnection
),
115
MakePointerChecker<WimaxConnection> ())
116
117
.AddAttribute (
"BroadcastConnection"
,
118
"Broadcast connection"
,
119
PointerValue
(),
120
MakePointerAccessor (&
WimaxNetDevice::m_broadcastConnection
),
121
MakePointerChecker<WimaxConnection> ())
122
123
.AddTraceSource (
"Rx"
,
"Receive trace"
,
MakeTraceSourceAccessor
(&
WimaxNetDevice::m_traceRx
))
124
125
.AddTraceSource (
"Tx"
,
"Transmit trace"
,
MakeTraceSourceAccessor
(&
WimaxNetDevice::m_traceTx
));
126
return
tid;
127
}
128
129
WimaxNetDevice::WimaxNetDevice
(
void
)
130
: m_state (0),
131
m_symbolIndex (0),
132
m_ttg (0),
133
m_rtg (0)
134
{
135
InitializeChannels
();
136
m_connectionManager
= CreateObject<ConnectionManager> ();
137
m_burstProfileManager
= CreateObject<BurstProfileManager> (
this
);
138
m_bandwidthManager
= CreateObject<BandwidthManager> (
this
);
139
m_nrFrames
= 0;
140
m_direction
= ~0;
141
m_frameStartTime
=
Seconds
(0);
142
}
143
144
WimaxNetDevice::~WimaxNetDevice
(
void
)
145
{
146
}
147
148
void
149
WimaxNetDevice::DoDispose
(
void
)
150
{
151
152
m_phy
->
Dispose
();
153
m_phy
= 0;
154
m_node
= 0;
155
m_initialRangingConnection
= 0;
156
m_broadcastConnection
= 0;
157
m_connectionManager
= 0;
158
m_burstProfileManager
= 0;
159
m_bandwidthManager
= 0;
160
m_connectionManager
= 0;
161
m_bandwidthManager
= 0;
162
163
NetDevice::DoDispose
();
164
}
165
166
167
void
168
WimaxNetDevice::SetTtg
(uint16_t ttg)
169
{
170
m_ttg
= ttg;
171
}
172
173
uint16_t
174
WimaxNetDevice::GetTtg
(
void
)
const
175
{
176
return
m_ttg
;
177
}
178
179
void
180
WimaxNetDevice::SetRtg
(uint16_t rtg)
181
{
182
m_rtg
= rtg;
183
}
184
185
uint16_t
186
WimaxNetDevice::GetRtg
(
void
)
const
187
{
188
return
m_rtg
;
189
}
190
191
void
192
WimaxNetDevice::SetName
(
const
std::string name)
193
{
194
m_name
= name;
195
}
196
197
std::string
198
WimaxNetDevice::GetName
(
void
)
const
199
{
200
return
m_name
;
201
}
202
203
void
204
WimaxNetDevice::SetIfIndex
(
const
uint32_t index)
205
{
206
m_ifIndex
= index;
207
}
208
209
uint32_t
210
WimaxNetDevice::GetIfIndex
(
void
)
const
211
{
212
return
m_ifIndex
;
213
}
214
215
Ptr<Channel>
216
WimaxNetDevice::GetChannel
(
void
)
const
217
{
218
return
DoGetChannel
();
219
}
220
221
Ptr<Channel>
222
WimaxNetDevice::GetPhyChannel
(
void
)
const
223
{
224
return
DoGetChannel
();
225
}
226
227
bool
228
WimaxNetDevice::SetMtu
(
const
uint16_t mtu)
229
{
230
if
(mtu >
MAX_MSDU_SIZE
)
231
{
232
return
false
;
233
}
234
m_mtu
= mtu;
235
return
true
;
236
}
237
238
uint16_t
239
WimaxNetDevice::GetMtu
(
void
)
const
240
{
241
return
m_mtu
;
242
}
243
244
bool
245
WimaxNetDevice::IsLinkUp
(
void
)
const
246
{
247
248
return
m_phy
!= 0 &&
m_linkUp
;
249
250
}
251
252
void
253
WimaxNetDevice::SetLinkChangeCallback
(
Callback<void>
callback)
254
{
255
m_linkChange
= callback;
256
}
257
258
bool
259
WimaxNetDevice::IsBroadcast
(
void
)
const
260
{
261
return
true
;
262
}
263
264
Address
265
WimaxNetDevice::GetBroadcast
(
void
)
const
266
{
267
return
Mac48Address::GetBroadcast
();
268
}
269
270
bool
271
WimaxNetDevice::IsMulticast
(
void
)
const
272
{
273
return
false
;
274
}
275
276
Address
277
WimaxNetDevice::GetMulticast
(
void
)
const
278
{
279
return
Mac48Address
(
"01:00:5e:00:00:00"
);
280
}
281
282
Address
283
WimaxNetDevice::MakeMulticastAddress
(
Ipv4Address
multicastGroup)
const
284
{
285
return
GetMulticast
();
286
}
287
288
bool
289
WimaxNetDevice::IsPointToPoint
(
void
)
const
290
{
291
return
false
;
292
}
293
294
bool
295
WimaxNetDevice::Send
(
Ptr<Packet>
packet,
const
Address
& dest, uint16_t protocolNumber)
296
{
297
298
Mac48Address
to =
Mac48Address::ConvertFrom
(dest);
299
LlcSnapHeader
llcHdr;
300
llcHdr.
SetType
(protocolNumber);
301
packet->
AddHeader
(llcHdr);
302
303
m_traceTx
(packet, to);
304
305
return
DoSend
(packet,
Mac48Address::ConvertFrom
(
GetAddress
()), to, protocolNumber);
306
}
307
308
void
309
WimaxNetDevice::SetNode
(
Ptr<Node>
node)
310
{
311
m_node
= node;
312
}
313
314
Ptr<Node>
315
WimaxNetDevice::GetNode
(
void
)
const
316
{
317
return
m_node
;
318
}
319
320
bool
321
WimaxNetDevice::NeedsArp
(
void
)
const
322
{
323
return
false
;
324
/*
325
* Modified by Mohamed Amine ISMAIL.
326
* see "Transmission of IPv4 packets over IEEE 802.16's IP Convergence
327
* Sublayer draft-ietf-16ng-ipv4-over-802-dot-16-ipcs-04.txt" section
328
* 5.2
329
*/
330
}
331
332
void
333
WimaxNetDevice::SetReceiveCallback
(
ReceiveCallback
cb)
334
{
335
m_forwardUp
= cb;
336
}
337
338
void
339
WimaxNetDevice::ForwardUp
(
Ptr<Packet>
packet,
const
Mac48Address
&source,
const
Mac48Address
&dest)
340
{
341
m_traceRx
(packet, source);
342
LlcSnapHeader
llc;
343
packet->
RemoveHeader
(llc);
344
m_forwardUp
(
this
, packet, llc.
GetType
(), source);
345
}
346
347
void
348
WimaxNetDevice::Attach
(
Ptr<WimaxChannel>
channel)
349
{
350
m_phy
->
Attach
(channel);
351
}
352
353
void
354
WimaxNetDevice::SetPhy
(
Ptr<WimaxPhy>
phy)
355
{
356
m_phy
= phy;
357
}
358
359
Ptr<WimaxPhy>
360
WimaxNetDevice::GetPhy
(
void
)
const
361
{
362
return
m_phy
;
363
}
364
365
void
366
WimaxNetDevice::SetChannel
(
Ptr<WimaxChannel>
channel)
367
{
368
if
(
m_phy
!= 0)
369
{
370
m_phy
->
Attach
(channel);
371
}
372
373
}
374
375
uint64_t
376
WimaxNetDevice::GetChannel
(uint8_t index)
const
377
{
378
return
m_dlChannels
.at (index);
379
}
380
381
void
382
WimaxNetDevice::SetNrFrames
(uint32_t nrFrames)
383
{
384
m_nrFrames
= nrFrames;
385
}
386
387
uint32_t
WimaxNetDevice::GetNrFrames
(
void
)
const
388
{
389
390
return
m_nrFrames
;
391
}
392
393
void
394
WimaxNetDevice::SetAddress
(
Address
address)
395
{
396
m_address
=
Mac48Address::ConvertFrom
(address);
397
}
398
399
void
400
WimaxNetDevice::SetMacAddress
(
Mac48Address
address)
401
{
402
m_address
= address;
403
}
404
405
Address
406
WimaxNetDevice::GetAddress
(
void
)
const
407
{
408
return
m_address
;
409
}
410
411
Mac48Address
412
WimaxNetDevice::GetMacAddress
(
void
)
const
413
{
414
return
m_address
;
415
}
416
417
void
418
WimaxNetDevice::SetState
(uint8_t state)
419
{
420
m_state
= state;
421
}
422
423
uint8_t
424
WimaxNetDevice::GetState
(
void
)
const
425
{
426
return
m_state
;
427
}
428
429
Ptr<WimaxConnection>
430
WimaxNetDevice::GetInitialRangingConnection
(
void
)
const
431
{
432
return
m_initialRangingConnection
;
433
}
434
435
Ptr<WimaxConnection>
436
WimaxNetDevice::GetBroadcastConnection
(
void
)
const
437
{
438
return
m_broadcastConnection
;
439
}
440
441
void
442
WimaxNetDevice::SetCurrentDcd
(
Dcd
dcd)
443
{
444
m_currentDcd
= dcd;
445
}
446
447
Dcd
448
WimaxNetDevice::GetCurrentDcd
(
void
)
const
449
{
450
return
m_currentDcd
;
451
}
452
453
void
454
WimaxNetDevice::SetCurrentUcd
(
Ucd
ucd)
455
{
456
m_currentUcd
= ucd;
457
}
458
459
Ucd
460
WimaxNetDevice::GetCurrentUcd
(
void
)
const
461
{
462
return
m_currentUcd
;
463
}
464
465
Ptr<ConnectionManager>
466
WimaxNetDevice::GetConnectionManager
(
void
)
const
467
{
468
return
m_connectionManager
;
469
}
470
471
void
472
WimaxNetDevice::SetConnectionManager
(
Ptr<ConnectionManager>
cm)
473
{
474
m_connectionManager
= cm;
475
}
476
477
Ptr<BurstProfileManager>
478
WimaxNetDevice::GetBurstProfileManager
(
void
)
const
479
{
480
return
m_burstProfileManager
;
481
}
482
483
void
484
WimaxNetDevice::SetBurstProfileManager
(
Ptr<BurstProfileManager>
bpm)
485
{
486
m_burstProfileManager
= bpm;
487
}
488
489
Ptr<BandwidthManager>
490
WimaxNetDevice::GetBandwidthManager
(
void
)
const
491
{
492
return
m_bandwidthManager
;
493
}
494
495
void
496
WimaxNetDevice::SetBandwidthManager
(
Ptr<BandwidthManager>
bwm)
497
{
498
m_bandwidthManager
= bwm;
499
}
500
501
void
502
WimaxNetDevice::CreateDefaultConnections
(
void
)
503
{
504
m_initialRangingConnection
= CreateObject<WimaxConnection> (
Cid::InitialRanging
(),
Cid::INITIAL_RANGING
);
505
m_broadcastConnection
= CreateObject<WimaxConnection> (
Cid::Broadcast
(),
Cid::BROADCAST
);
506
}
507
508
void
509
WimaxNetDevice::Receive
(
Ptr<const PacketBurst>
burst)
510
{
511
512
NS_LOG_DEBUG
(
"WimaxNetDevice::Receive, station = "
<<
GetMacAddress
());
513
514
Ptr<PacketBurst>
b = burst->Copy ();
515
for
(
std::list
<
Ptr<Packet>
>::const_iterator iter = b->
Begin
(); iter != b->
End
(); ++iter)
516
{
517
Ptr<Packet>
packet = *iter;
518
DoReceive
(packet);
519
}
520
}
521
522
Ptr<WimaxChannel>
523
WimaxNetDevice::DoGetChannel
(
void
)
const
524
{
525
return
m_phy
->
GetChannel
();
526
}
527
528
void
529
WimaxNetDevice::SetReceiveCallback
(
void
)
530
{
531
m_phy
->
SetReceiveCallback
(
MakeCallback
(&
WimaxNetDevice::Receive
,
this
));
532
}
533
534
bool
535
WimaxNetDevice::SendFrom
(
Ptr<Packet>
packet,
const
Address
& source,
const
Address
& dest, uint16_t protocolNumber)
536
{
537
538
Mac48Address
from =
Mac48Address::ConvertFrom
(source);
539
Mac48Address
to =
Mac48Address::ConvertFrom
(dest);
540
541
LlcSnapHeader
llcHdr;
542
llcHdr.
SetType
(protocolNumber);
543
packet->
AddHeader
(llcHdr);
544
545
m_traceTx
(packet, to);
546
return
DoSend
(packet, from, to, protocolNumber);
547
}
548
549
void
550
WimaxNetDevice::SetPromiscReceiveCallback
(
PromiscReceiveCallback
cb)
551
{
552
m_promiscRx
= cb;
553
}
554
555
bool
556
WimaxNetDevice::IsPromisc
(
void
)
557
{
558
return
!(
m_promiscRx
.
IsNull
());
559
}
560
561
void
562
WimaxNetDevice::NotifyPromiscTrace
(
Ptr<Packet>
p)
563
{
564
// m_promiscRx(p);
565
}
566
567
bool
568
WimaxNetDevice::SupportsSendFrom
(
void
)
const
569
{
570
return
false
;
571
}
572
573
void
574
WimaxNetDevice::ForwardDown
(
Ptr<PacketBurst>
burst,
WimaxPhy::ModulationType
modulationType)
575
{
576
SendParams
* params =
new
OfdmSendParams
(burst, modulationType,
m_direction
);
577
m_phy
->
Send
(params);
578
delete
params;
579
}
580
581
void
582
WimaxNetDevice::InitializeChannels
(
void
)
583
{
584
585
// initializing vector of channels (or frequencies)
586
// Values according to WirelessMAN-OFDM RF profile for 10 MHz channelization
587
// Section 12.3.3.1 from IEEE 802.16-2004 standard
588
// profR10_3 :
589
// channels: 5000 + n ⋅ 5 MHz, ∀n ∈ { 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167 }
590
// from a range 5GHz to 6GHz, according to Section 8.5.1.
591
uint64_t frequency = 5000;
592
593
for
(uint8_t i = 0; i < 200; i++)
594
{
595
m_dlChannels
.push_back (frequency);
596
frequency += 5;
597
}
598
}
599
600
bool
601
WimaxNetDevice::IsBridge
(
void
)
const
602
{
603
NS_LOG_FUNCTION_NOARGS
();
604
return
false
;
605
}
606
607
Address
608
WimaxNetDevice::GetMulticast
(
Ipv4Address
multicastGroup)
const
609
{
610
NS_LOG_FUNCTION
(multicastGroup);
611
612
Mac48Address
ad =
Mac48Address::GetMulticast
(multicastGroup);
613
614
//
615
// Implicit conversion (operator Address ()) is defined for Mac48Address, so
616
// use it by just returning the EUI-48 address which is automagically converted
617
// to an Address.
618
//
619
NS_LOG_LOGIC
(
"multicast address is "
<< ad);
620
621
return
ad;
622
}
623
624
Address
625
WimaxNetDevice::GetMulticast
(
Ipv6Address
addr)
const
626
{
627
Mac48Address
ad =
Mac48Address::GetMulticast
(addr);
628
629
NS_LOG_LOGIC
(
"MAC IPv6 multicast address is "
<< ad);
630
return
ad;
631
}
632
633
void
634
WimaxNetDevice::AddLinkChangeCallback
(
Callback<void>
callback)
635
{
636
/* TODO: Add a callback invoked whenever the link
637
* status changes to UP. This callback is typically used
638
* by the IP/ARP layer to flush the ARP cache and by IPv6 stack
639
* to flush NDISC cache whenever the link goes up.
640
*/
641
NS_FATAL_ERROR
(
"Not implemented-- please implement and contribute a patch"
);
642
}
643
}
// namespace ns3
src
wimax
model
wimax-net-device.cc
Generated on Tue Oct 9 2012 16:45:50 for ns-3 by
1.8.1.2