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
mac-low.h
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2005, 2006 INRIA
4
* Copyright (c) 2009 MIRKO BANCHI
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 2 as
8
* published by the Free Software Foundation;
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
*
19
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20
* Author: Mirko Banchi <mk.banchi@gmail.com>
21
*/
22
#ifndef MAC_LOW_H
23
#define MAC_LOW_H
24
25
#include <vector>
26
#include <stdint.h>
27
#include <ostream>
28
#include <map>
29
30
#include "
wifi-mac-header.h
"
31
#include "
wifi-mode.h
"
32
#include "
wifi-preamble.h
"
33
#include "
wifi-remote-station-manager.h
"
34
#include "
ctrl-headers.h
"
35
#include "
mgt-headers.h
"
36
#include "
block-ack-agreement.h
"
37
#include "ns3/mac48-address.h"
38
#include "ns3/callback.h"
39
#include "ns3/event-id.h"
40
#include "ns3/packet.h"
41
#include "ns3/nstime.h"
42
#include "
qos-utils.h
"
43
#include "
block-ack-cache.h
"
44
45
namespace
ns3 {
46
47
class
WifiPhy;
48
class
WifiMac;
49
class
EdcaTxopN;
50
55
class
MacLowTransmissionListener
56
{
57
public
:
58
MacLowTransmissionListener
();
59
virtual
~MacLowTransmissionListener
();
60
68
virtual
void
GotCts
(
double
snr,
WifiMode
txMode) = 0;
73
virtual
void
MissedCts
(
void
) = 0;
83
virtual
void
GotAck
(
double
snr,
WifiMode
txMode) = 0;
88
virtual
void
MissedAck
(
void
) = 0;
101
virtual
void
GotBlockAck
(
const
CtrlBAckResponseHeader
*blockAck,
Mac48Address
source);
111
virtual
void
MissedBlockAck
(
void
);
118
virtual
void
StartNext
(
void
) = 0;
119
126
virtual
void
Cancel
(
void
) = 0;
127
133
virtual
void
EndTxNoAck
(
void
) = 0;
134
135
};
136
137
146
class
MacLowDcfListener
147
{
148
public
:
149
MacLowDcfListener
();
150
virtual
~MacLowDcfListener
();
154
virtual
void
NavStart
(
Time
duration) = 0;
158
virtual
void
NavReset
(
Time
duration) = 0;
159
virtual
void
AckTimeoutStart
(
Time
duration) = 0;
160
virtual
void
AckTimeoutReset
() = 0;
161
virtual
void
CtsTimeoutStart
(
Time
duration) = 0;
162
virtual
void
CtsTimeoutReset
() = 0;
163
};
164
169
class
MacLowBlockAckEventListener
170
{
171
public
:
172
MacLowBlockAckEventListener
();
173
virtual
~MacLowBlockAckEventListener
();
183
virtual
void
BlockAckInactivityTimeout
(
Mac48Address
originator, uint8_t tid) = 0;
184
};
185
194
class
MacLowTransmissionParameters
195
{
196
public
:
197
MacLowTransmissionParameters
();
198
204
void
EnableAck
(
void
);
218
void
EnableFastAck
(
void
);
225
void
EnableSuperFastAck
(
void
);
229
void
EnableBasicBlockAck
(
void
);
233
void
EnableCompressedBlockAck
(
void
);
237
void
EnableMultiTidBlockAck
(
void
);
244
void
EnableRts
(
void
);
254
void
EnableNextData
(uint32_t size);
255
263
void
EnableOverrideDurationId
(
Time
durationId);
264
269
void
DisableAck
(
void
);
273
void
DisableRts
(
void
);
277
void
DisableNextData
(
void
);
283
void
DisableOverrideDurationId
(
void
);
284
292
bool
MustWaitAck
(
void
)
const
;
299
bool
MustWaitNormalAck
(
void
)
const
;
306
bool
MustWaitFastAck
(
void
)
const
;
313
bool
MustWaitSuperFastAck
(
void
)
const
;
319
bool
MustWaitBasicBlockAck
(
void
)
const
;
325
bool
MustWaitCompressedBlockAck
(
void
)
const
;
331
bool
MustWaitMultiTidBlockAck
(
void
)
const
;
336
bool
MustSendRts
(
void
)
const
;
341
bool
HasDurationId
(
void
)
const
;
345
Time
GetDurationId
(
void
)
const
;
349
bool
HasNextPacket
(
void
)
const
;
353
uint32_t
GetNextPacketSize
(
void
)
const
;
354
355
private
:
356
friend
std::ostream &
operator <<
(std::ostream &os,
const
MacLowTransmissionParameters
¶ms);
357
uint32_t
m_nextSize
;
358
enum
359
{
360
ACK_NONE
,
361
ACK_NORMAL
,
362
ACK_FAST
,
363
ACK_SUPER_FAST
,
364
BLOCK_ACK_BASIC
,
365
BLOCK_ACK_COMPRESSED
,
366
BLOCK_ACK_MULTI_TID
367
}
m_waitAck
;
368
bool
m_sendRts
;
369
Time
m_overrideDurationId
;
370
};
371
372
std::ostream &
operator <<
(std::ostream &os,
const
MacLowTransmissionParameters
¶ms);
373
374
379
class
MacLow
:
public
Object
380
{
381
public
:
382
typedef
Callback<void, Ptr<Packet>
,
const
WifiMacHeader
*>
MacLowRxCallback
;
383
384
MacLow
();
385
virtual
~MacLow
();
386
387
void
SetPhy
(
Ptr<WifiPhy>
phy);
388
void
SetWifiRemoteStationManager
(
Ptr<WifiRemoteStationManager>
manager);
389
390
void
SetAddress
(
Mac48Address
ad);
391
void
SetAckTimeout
(
Time
ackTimeout);
392
void
SetBasicBlockAckTimeout
(
Time
blockAckTimeout);
393
void
SetCompressedBlockAckTimeout
(
Time
blockAckTimeout);
394
void
SetCtsTimeout
(
Time
ctsTimeout);
395
void
SetSifs
(
Time
sifs);
396
void
SetSlotTime
(
Time
slotTime);
397
void
SetPifs
(
Time
pifs);
398
void
SetBssid
(
Mac48Address
ad);
399
void
SetPromisc
(
void
);
400
Mac48Address
GetAddress
(
void
)
const
;
401
Time
GetAckTimeout
(
void
)
const
;
402
Time
GetBasicBlockAckTimeout
()
const
;
403
Time
GetCompressedBlockAckTimeout
()
const
;
404
Time
GetCtsTimeout
(
void
)
const
;
405
Time
GetSifs
(
void
)
const
;
406
Time
GetSlotTime
(
void
)
const
;
407
Time
GetPifs
(
void
)
const
;
408
Mac48Address
GetBssid
(
void
)
const
;
409
416
void
SetRxCallback
(
Callback
<
void
,
Ptr<Packet>
,
const
WifiMacHeader
*> callback);
421
void
RegisterDcfListener
(
MacLowDcfListener
*listener);
422
431
Time
CalculateTransmissionTime
(
Ptr<const Packet>
packet,
432
const
WifiMacHeader
* hdr,
433
const
MacLowTransmissionParameters
& parameters)
const
;
434
444
void
StartTransmission
(
Ptr<const Packet>
packet,
445
const
WifiMacHeader
* hdr,
446
MacLowTransmissionParameters
parameters,
447
MacLowTransmissionListener
*listener);
448
458
void
ReceiveOk
(
Ptr<Packet>
packet,
double
rxSnr,
WifiMode
txMode,
WifiPreamble
preamble);
466
void
ReceiveError
(
Ptr<const Packet>
packet,
double
rxSnr);
474
void
NotifySwitchingStartNow
(
Time
duration);
490
void
CreateBlockAckAgreement
(
const
MgtAddBaResponseHeader
*respHdr,
491
Mac48Address
originator,
492
uint16_t startingSeq);
501
void
DestroyBlockAckAgreement
(
Mac48Address
originator, uint8_t tid);
509
void
RegisterBlockAckListenerForAc
(
enum
AcIndex
ac,
MacLowBlockAckEventListener
*listener);
510
private
:
511
void
CancelAllEvents
(
void
);
512
uint32_t
GetAckSize
(
void
)
const
;
513
uint32_t
GetBlockAckSize
(
enum
BlockAckType
type)
const
;
514
uint32_t
GetRtsSize
(
void
)
const
;
515
uint32_t
GetCtsSize
(
void
)
const
;
516
uint32_t
GetSize
(
Ptr<const Packet>
packet,
const
WifiMacHeader
*hdr)
const
;
517
Time
NowUs
(
void
)
const
;
518
void
ForwardDown
(
Ptr<const Packet>
packet,
const
WifiMacHeader
*hdr,
519
WifiMode
txMode);
520
Time
CalculateOverallTxTime
(
Ptr<const Packet>
packet,
521
const
WifiMacHeader
* hdr,
522
const
MacLowTransmissionParameters
¶ms)
const
;
523
WifiMode
GetRtsTxMode
(
Ptr<const Packet>
packet,
const
WifiMacHeader
*hdr)
const
;
524
WifiMode
GetDataTxMode
(
Ptr<const Packet>
packet,
const
WifiMacHeader
*hdr)
const
;
525
WifiMode
GetCtsTxModeForRts
(
Mac48Address
to,
WifiMode
rtsTxMode)
const
;
526
WifiMode
GetAckTxModeForData
(
Mac48Address
to,
WifiMode
dataTxMode)
const
;
527
528
Time
GetCtsDuration
(
Mac48Address
to,
WifiMode
rtsTxMode)
const
;
529
Time
GetAckDuration
(
Mac48Address
to,
WifiMode
dataTxMode)
const
;
530
Time
GetBlockAckDuration
(
Mac48Address
to,
WifiMode
blockAckReqTxMode,
enum
BlockAckType
type)
const
;
531
void
NotifyNav
(
const
WifiMacHeader
&hdr,
WifiMode
txMode,
WifiPreamble
preamble);
532
void
DoNavResetNow
(
Time
duration);
533
bool
DoNavStartNow
(
Time
duration);
534
bool
IsNavZero
(
void
)
const
;
535
void
NotifyAckTimeoutStartNow
(
Time
duration);
536
void
NotifyAckTimeoutResetNow
();
537
void
NotifyCtsTimeoutStartNow
(
Time
duration);
538
void
NotifyCtsTimeoutResetNow
();
539
void
MaybeCancelPrevious
(
void
);
540
541
void
NavCounterResetCtsMissed
(
Time
rtsEndRxTime);
542
void
NormalAckTimeout
(
void
);
543
void
FastAckTimeout
(
void
);
544
void
SuperFastAckTimeout
(
void
);
545
void
FastAckFailedTimeout
(
void
);
546
void
BlockAckTimeout
(
void
);
547
void
CtsTimeout
(
void
);
548
void
SendCtsAfterRts
(
Mac48Address
source,
Time
duration,
WifiMode
txMode,
double
rtsSnr);
549
void
SendAckAfterData
(
Mac48Address
source,
Time
duration,
WifiMode
txMode,
double
rtsSnr);
550
void
SendDataAfterCts
(
Mac48Address
source,
Time
duration,
WifiMode
txMode);
551
void
WaitSifsAfterEndTx
(
void
);
552
void
EndTxNoAck
(
void
);
553
554
void
SendRtsForPacket
(
void
);
555
void
SendDataPacket
(
void
);
556
void
SendCurrentTxPacket
(
void
);
557
void
StartDataTxTimers
(
void
);
558
virtual
void
DoDispose
(
void
);
567
void
RxCompleteBufferedPacketsWithSmallerSequence
(uint16_t seq,
Mac48Address
originator, uint8_t tid);
580
void
RxCompleteBufferedPacketsUntilFirstLost
(
Mac48Address
originator, uint8_t tid);
581
/*
582
* This method checks if exists a valid established block ack agreement.
583
* If there is, store the packet without pass it up to WifiMac. The packet is buffered
584
* in order of increasing sequence control field. All comparison are performed
585
* circularly modulo 2^12.
586
*/
587
bool
StoreMpduIfNeeded
(
Ptr<Packet>
packet,
WifiMacHeader
hdr);
588
/*
589
* Invoked after that a block ack request has been received. Looks for corresponding
590
* block ack agreement and creates block ack bitmap on a received packets basis.
591
*/
592
void
SendBlockAckAfterBlockAckRequest
(
const
CtrlBAckRequestHeader
reqHdr,
Mac48Address
originator,
593
Time
duration,
WifiMode
blockAckReqTxMode);
594
/*
595
* This method creates block ack frame with header equals to <i>blockAck</i> and start its transmission.
596
*/
597
void
SendBlockAckResponse
(
const
CtrlBAckResponseHeader
* blockAck,
Mac48Address
originator,
bool
immediate,
598
Time
duration,
WifiMode
blockAckReqTxMode);
599
/*
600
* Every time that a block ack request or a packet with ack policy equals to <i>block ack</i>
601
* are received, if a relative block ack agreement exists and the value of inactivity timeout
602
* is not 0, the timer is reset.
603
* see section 11.5.3 in IEEE802.11e for more details.
604
*/
605
void
ResetBlockAckInactivityTimerIfNeeded
(
BlockAckAgreement
&agreement);
606
607
void
SetupPhyMacLowListener
(
Ptr<WifiPhy>
phy);
608
609
Ptr<WifiPhy>
m_phy
;
610
Ptr<WifiRemoteStationManager>
m_stationManager
;
611
MacLowRxCallback
m_rxCallback
;
612
typedef
std::vector<MacLowDcfListener *>::const_iterator
DcfListenersCI
;
613
typedef
std::vector<MacLowDcfListener *>
DcfListeners
;
614
DcfListeners
m_dcfListeners
;
615
616
EventId
m_normalAckTimeoutEvent
;
617
EventId
m_fastAckTimeoutEvent
;
618
EventId
m_superFastAckTimeoutEvent
;
619
EventId
m_fastAckFailedTimeoutEvent
;
620
EventId
m_blockAckTimeoutEvent
;
621
EventId
m_ctsTimeoutEvent
;
622
EventId
m_sendCtsEvent
;
623
EventId
m_sendAckEvent
;
624
EventId
m_sendDataEvent
;
625
EventId
m_waitSifsEvent
;
626
EventId
m_endTxNoAckEvent
;
627
EventId
m_navCounterResetCtsMissed
;
628
629
Ptr<Packet>
m_currentPacket
;
630
WifiMacHeader
m_currentHdr
;
631
MacLowTransmissionParameters
m_txParams
;
632
MacLowTransmissionListener
*
m_listener
;
633
Mac48Address
m_self
;
634
Mac48Address
m_bssid
;
635
Time
m_ackTimeout
;
636
Time
m_basicBlockAckTimeout
;
637
Time
m_compressedBlockAckTimeout
;
638
Time
m_ctsTimeout
;
639
Time
m_sifs
;
640
Time
m_slotTime
;
641
Time
m_pifs
;
642
643
Time
m_lastNavStart
;
644
Time
m_lastNavDuration
;
645
646
bool
m_promisc
;
647
648
// Listerner needed to monitor when a channel switching occurs.
649
class
PhyMacLowListener
*
m_phyMacLowListener
;
650
651
/*
652
* BlockAck data structures.
653
*/
654
typedef
std::pair<Ptr<Packet>,
WifiMacHeader
>
BufferedPacket
;
655
typedef
std::list<BufferedPacket>::iterator
BufferedPacketI
;
656
657
typedef
std::pair<Mac48Address, uint8_t>
AgreementKey
;
658
typedef
std::pair<BlockAckAgreement, std::list<BufferedPacket> >
AgreementValue
;
659
660
typedef
std::map<AgreementKey, AgreementValue>
Agreements
;
661
typedef
std::map<AgreementKey, AgreementValue>::iterator
AgreementsI
;
662
663
typedef
std::map<AgreementKey, BlockAckCache>
BlockAckCaches
;
664
typedef
std::map<AgreementKey, BlockAckCache>::iterator
BlockAckCachesI
;
665
666
Agreements
m_bAckAgreements
;
667
BlockAckCaches
m_bAckCaches
;
668
669
typedef
std::map<AcIndex, MacLowBlockAckEventListener*>
QueueListeners
;
670
QueueListeners
m_edcaListeners
;
671
};
672
673
}
// namespace ns3
674
675
#endif
/* MAC_LOW_H */
src
wifi
model
mac-low.h
Generated on Fri Dec 21 2012 19:00:48 for ns-3 by
1.8.1.2