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
#include "
wifi-tx-vector.h
"
45
46
namespace
ns3 {
47
48
class
WifiPhy;
49
class
WifiMac;
50
class
EdcaTxopN;
51
56
class
MacLowTransmissionListener
57
{
58
public
:
59
MacLowTransmissionListener
();
60
virtual
~MacLowTransmissionListener
();
61
69
virtual
void
GotCts
(
double
snr,
WifiMode
txMode) = 0;
74
virtual
void
MissedCts
(
void
) = 0;
84
virtual
void
GotAck
(
double
snr,
WifiMode
txMode) = 0;
89
virtual
void
MissedAck
(
void
) = 0;
102
virtual
void
GotBlockAck
(
const
CtrlBAckResponseHeader
*blockAck,
Mac48Address
source);
112
virtual
void
MissedBlockAck
(
void
);
119
virtual
void
StartNext
(
void
) = 0;
120
127
virtual
void
Cancel
(
void
) = 0;
128
134
virtual
void
EndTxNoAck
(
void
) = 0;
135
136
};
137
138
147
class
MacLowDcfListener
148
{
149
public
:
150
MacLowDcfListener
();
151
virtual
~MacLowDcfListener
();
155
virtual
void
NavStart
(
Time
duration) = 0;
159
virtual
void
NavReset
(
Time
duration) = 0;
160
virtual
void
AckTimeoutStart
(
Time
duration) = 0;
161
virtual
void
AckTimeoutReset
() = 0;
162
virtual
void
CtsTimeoutStart
(
Time
duration) = 0;
163
virtual
void
CtsTimeoutReset
() = 0;
164
};
165
170
class
MacLowBlockAckEventListener
171
{
172
public
:
173
MacLowBlockAckEventListener
();
174
virtual
~MacLowBlockAckEventListener
();
184
virtual
void
BlockAckInactivityTimeout
(
Mac48Address
originator, uint8_t tid) = 0;
185
};
186
195
class
MacLowTransmissionParameters
196
{
197
public
:
198
MacLowTransmissionParameters
();
199
205
void
EnableAck
(
void
);
219
void
EnableFastAck
(
void
);
226
void
EnableSuperFastAck
(
void
);
230
void
EnableBasicBlockAck
(
void
);
234
void
EnableCompressedBlockAck
(
void
);
238
void
EnableMultiTidBlockAck
(
void
);
245
void
EnableRts
(
void
);
255
void
EnableNextData
(uint32_t size);
256
264
void
EnableOverrideDurationId
(
Time
durationId);
265
270
void
DisableAck
(
void
);
274
void
DisableRts
(
void
);
278
void
DisableNextData
(
void
);
284
void
DisableOverrideDurationId
(
void
);
285
293
bool
MustWaitAck
(
void
)
const
;
300
bool
MustWaitNormalAck
(
void
)
const
;
307
bool
MustWaitFastAck
(
void
)
const
;
314
bool
MustWaitSuperFastAck
(
void
)
const
;
320
bool
MustWaitBasicBlockAck
(
void
)
const
;
326
bool
MustWaitCompressedBlockAck
(
void
)
const
;
332
bool
MustWaitMultiTidBlockAck
(
void
)
const
;
337
bool
MustSendRts
(
void
)
const
;
342
bool
HasDurationId
(
void
)
const
;
346
Time
GetDurationId
(
void
)
const
;
350
bool
HasNextPacket
(
void
)
const
;
354
uint32_t
GetNextPacketSize
(
void
)
const
;
355
356
private
:
357
friend
std::ostream &
operator <<
(std::ostream &os,
const
MacLowTransmissionParameters
¶ms);
358
uint32_t
m_nextSize
;
359
enum
360
{
361
ACK_NONE
,
362
ACK_NORMAL
,
363
ACK_FAST
,
364
ACK_SUPER_FAST
,
365
BLOCK_ACK_BASIC
,
366
BLOCK_ACK_COMPRESSED
,
367
BLOCK_ACK_MULTI_TID
368
}
m_waitAck
;
369
bool
m_sendRts
;
370
Time
m_overrideDurationId
;
371
};
372
373
std::ostream &
operator <<
(std::ostream &os,
const
MacLowTransmissionParameters
¶ms);
374
375
380
class
MacLow
:
public
Object
381
{
382
public
:
383
typedef
Callback<void, Ptr<Packet>
,
const
WifiMacHeader
*>
MacLowRxCallback
;
384
385
MacLow
();
386
virtual
~MacLow
();
387
388
void
SetPhy
(
Ptr<WifiPhy>
phy);
389
void
SetWifiRemoteStationManager
(
Ptr<WifiRemoteStationManager>
manager);
390
391
void
SetAddress
(
Mac48Address
ad);
392
void
SetAckTimeout
(
Time
ackTimeout);
393
void
SetBasicBlockAckTimeout
(
Time
blockAckTimeout);
394
void
SetCompressedBlockAckTimeout
(
Time
blockAckTimeout);
395
void
SetCtsToSelfSupported
(
bool
enable);
396
void
SetCtsTimeout
(
Time
ctsTimeout);
397
void
SetSifs
(
Time
sifs);
398
void
SetRifs
(
Time
rifs);
399
void
SetSlotTime
(
Time
slotTime);
400
void
SetPifs
(
Time
pifs);
401
void
SetBssid
(
Mac48Address
ad);
402
void
SetPromisc
(
void
);
403
bool
GetCtsToSelfSupported
()
const
;
404
Mac48Address
GetAddress
(
void
)
const
;
405
Time
GetAckTimeout
(
void
)
const
;
406
Time
GetBasicBlockAckTimeout
()
const
;
407
Time
GetCompressedBlockAckTimeout
()
const
;
408
Time
GetCtsTimeout
(
void
)
const
;
409
Time
GetSifs
(
void
)
const
;
410
Time
GetSlotTime
(
void
)
const
;
411
Time
GetPifs
(
void
)
const
;
412
Time
GetRifs
(
void
)
const
;
413
Mac48Address
GetBssid
(
void
)
const
;
414
421
void
SetRxCallback
(
Callback
<
void
,
Ptr<Packet>
,
const
WifiMacHeader
*> callback);
426
void
RegisterDcfListener
(
MacLowDcfListener
*listener);
427
436
Time
CalculateTransmissionTime
(
Ptr<const Packet>
packet,
437
const
WifiMacHeader
* hdr,
438
const
MacLowTransmissionParameters
& parameters)
const
;
439
449
void
StartTransmission
(
Ptr<const Packet>
packet,
450
const
WifiMacHeader
* hdr,
451
MacLowTransmissionParameters
parameters,
452
MacLowTransmissionListener
*listener);
453
463
void
ReceiveOk
(
Ptr<Packet>
packet,
double
rxSnr,
WifiMode
txMode,
WifiPreamble
preamble);
471
void
ReceiveError
(
Ptr<const Packet>
packet,
double
rxSnr);
479
void
NotifySwitchingStartNow
(
Time
duration);
495
void
CreateBlockAckAgreement
(
const
MgtAddBaResponseHeader
*respHdr,
496
Mac48Address
originator,
497
uint16_t startingSeq);
506
void
DestroyBlockAckAgreement
(
Mac48Address
originator, uint8_t tid);
514
void
RegisterBlockAckListenerForAc
(
enum
AcIndex
ac,
MacLowBlockAckEventListener
*listener);
515
private
:
516
void
CancelAllEvents
(
void
);
517
uint32_t
GetAckSize
(
void
)
const
;
518
uint32_t
GetBlockAckSize
(
enum
BlockAckType
type)
const
;
519
uint32_t
GetRtsSize
(
void
)
const
;
520
uint32_t
GetCtsSize
(
void
)
const
;
521
uint32_t
GetSize
(
Ptr<const Packet>
packet,
const
WifiMacHeader
*hdr)
const
;
522
Time
NowUs
(
void
)
const
;
523
void
ForwardDown
(
Ptr<const Packet>
packet,
const
WifiMacHeader
*hdr,
524
WifiTxVector
txVector,
WifiPreamble
preamble);
525
WifiTxVector
GetRtsTxVector
(
Ptr<const Packet>
packet,
const
WifiMacHeader
*hdr)
const
;
526
WifiTxVector
GetDataTxVector
(
Ptr<const Packet>
packet,
const
WifiMacHeader
*hdr)
const
;
527
WifiTxVector
GetCtsTxVector
(
Mac48Address
to,
WifiMode
rtsTxMode)
const
;
528
WifiTxVector
GetAckTxVector
(
Mac48Address
to,
WifiMode
dataTxMode)
const
;
529
WifiTxVector
GetBlockAckTxVector
(
Mac48Address
to,
WifiMode
dataTxMode)
const
;
530
531
WifiTxVector
GetCtsToSelfTxVector
(
Ptr<const Packet>
packet,
const
WifiMacHeader
*hdr)
const
;
532
533
WifiTxVector
GetCtsTxVectorForRts
(
Mac48Address
to,
WifiMode
rtsTxMode)
const
;
534
WifiTxVector
GetAckTxVectorForData
(
Mac48Address
to,
WifiMode
dataTxMode)
const
;
535
536
Time
GetCtsDuration
(
WifiTxVector
ctsTxVector)
const
;
537
Time
GetCtsDuration
(
Mac48Address
to,
WifiTxVector
rtsTxVector)
const
;
538
Time
GetAckDuration
(
WifiTxVector
ackTxVector)
const
;
539
Time
GetAckDuration
(
Mac48Address
to,
WifiTxVector
dataTxVector)
const
;
540
Time
GetBlockAckDuration
(
Mac48Address
to,
WifiTxVector
blockAckReqTxVector,
enum
BlockAckType
type)
const
;
541
542
bool
NeedCtsToSelf
(
void
);
543
544
Time
CalculateOverallTxTime
(
Ptr<const Packet>
packet,
545
const
WifiMacHeader
* hdr,
546
const
MacLowTransmissionParameters
¶ms)
const
;
547
void
NotifyNav
(
Ptr<const Packet>
packet,
const
WifiMacHeader
&hdr,
WifiMode
txMode,
WifiPreamble
preamble);
548
void
DoNavResetNow
(
Time
duration);
549
bool
DoNavStartNow
(
Time
duration);
550
bool
IsNavZero
(
void
)
const
;
551
void
NotifyAckTimeoutStartNow
(
Time
duration);
552
void
NotifyAckTimeoutResetNow
();
553
void
NotifyCtsTimeoutStartNow
(
Time
duration);
554
void
NotifyCtsTimeoutResetNow
();
555
void
MaybeCancelPrevious
(
void
);
556
557
void
NavCounterResetCtsMissed
(
Time
rtsEndRxTime);
558
void
NormalAckTimeout
(
void
);
559
void
FastAckTimeout
(
void
);
560
void
SuperFastAckTimeout
(
void
);
561
void
FastAckFailedTimeout
(
void
);
562
void
BlockAckTimeout
(
void
);
563
void
CtsTimeout
(
void
);
564
void
SendCtsToSelf
(
void
);
565
void
SendCtsAfterRts
(
Mac48Address
source,
Time
duration,
WifiMode
txMode,
double
rtsSnr);
566
void
SendAckAfterData
(
Mac48Address
source,
Time
duration,
WifiMode
txMode,
double
rtsSnr);
567
void
SendDataAfterCts
(
Mac48Address
source,
Time
duration,
WifiMode
txMode);
568
void
WaitSifsAfterEndTx
(
void
);
569
void
EndTxNoAck
(
void
);
570
571
void
SendRtsForPacket
(
void
);
572
void
SendDataPacket
(
void
);
573
void
SendCurrentTxPacket
(
void
);
574
void
StartDataTxTimers
(
WifiTxVector
dataTxVector);
575
virtual
void
DoDispose
(
void
);
584
void
RxCompleteBufferedPacketsWithSmallerSequence
(uint16_t seq,
Mac48Address
originator, uint8_t tid);
597
void
RxCompleteBufferedPacketsUntilFirstLost
(
Mac48Address
originator, uint8_t tid);
598
/*
599
* This method checks if exists a valid established block ack agreement.
600
* If there is, store the packet without pass it up to WifiMac. The packet is buffered
601
* in order of increasing sequence control field. All comparison are performed
602
* circularly modulo 2^12.
603
*/
604
bool
StoreMpduIfNeeded
(
Ptr<Packet>
packet,
WifiMacHeader
hdr);
605
/*
606
* Invoked after that a block ack request has been received. Looks for corresponding
607
* block ack agreement and creates block ack bitmap on a received packets basis.
608
*/
609
void
SendBlockAckAfterBlockAckRequest
(
const
CtrlBAckRequestHeader
reqHdr,
Mac48Address
originator,
610
Time
duration,
WifiMode
blockAckReqTxMode);
611
/*
612
* This method creates block ack frame with header equals to <i>blockAck</i> and start its transmission.
613
*/
614
void
SendBlockAckResponse
(
const
CtrlBAckResponseHeader
* blockAck,
Mac48Address
originator,
bool
immediate,
615
Time
duration,
WifiMode
blockAckReqTxMode);
616
/*
617
* Every time that a block ack request or a packet with ack policy equals to <i>block ack</i>
618
* are received, if a relative block ack agreement exists and the value of inactivity timeout
619
* is not 0, the timer is reset.
620
* see section 11.5.3 in IEEE802.11e for more details.
621
*/
622
void
ResetBlockAckInactivityTimerIfNeeded
(
BlockAckAgreement
&agreement);
623
624
void
SetupPhyMacLowListener
(
Ptr<WifiPhy>
phy);
625
626
Ptr<WifiPhy>
m_phy
;
627
Ptr<WifiRemoteStationManager>
m_stationManager
;
628
MacLowRxCallback
m_rxCallback
;
629
typedef
std::vector<MacLowDcfListener *>::const_iterator
DcfListenersCI
;
630
typedef
std::vector<MacLowDcfListener *>
DcfListeners
;
631
DcfListeners
m_dcfListeners
;
632
633
EventId
m_normalAckTimeoutEvent
;
634
EventId
m_fastAckTimeoutEvent
;
635
EventId
m_superFastAckTimeoutEvent
;
636
EventId
m_fastAckFailedTimeoutEvent
;
637
EventId
m_blockAckTimeoutEvent
;
638
EventId
m_ctsTimeoutEvent
;
639
EventId
m_sendCtsEvent
;
640
EventId
m_sendAckEvent
;
641
EventId
m_sendDataEvent
;
642
EventId
m_waitSifsEvent
;
643
EventId
m_endTxNoAckEvent
;
644
EventId
m_navCounterResetCtsMissed
;
645
EventId
m_waitRifsEvent
;
646
647
Ptr<Packet>
m_currentPacket
;
648
WifiMacHeader
m_currentHdr
;
649
MacLowTransmissionParameters
m_txParams
;
650
MacLowTransmissionListener
*
m_listener
;
651
Mac48Address
m_self
;
652
Mac48Address
m_bssid
;
653
Time
m_ackTimeout
;
654
Time
m_basicBlockAckTimeout
;
655
Time
m_compressedBlockAckTimeout
;
656
Time
m_ctsTimeout
;
657
Time
m_sifs
;
658
Time
m_slotTime
;
659
Time
m_pifs
;
660
Time
m_rifs
;
661
662
Time
m_lastNavStart
;
663
Time
m_lastNavDuration
;
664
665
bool
m_promisc
;
666
667
// Listerner needed to monitor when a channel switching occurs.
668
class
PhyMacLowListener
*
m_phyMacLowListener
;
669
670
/*
671
* BlockAck data structures.
672
*/
673
typedef
std::pair<Ptr<Packet>,
WifiMacHeader
>
BufferedPacket
;
674
typedef
std::list<BufferedPacket>::iterator
BufferedPacketI
;
675
676
typedef
std::pair<Mac48Address, uint8_t>
AgreementKey
;
677
typedef
std::pair<BlockAckAgreement, std::list<BufferedPacket> >
AgreementValue
;
678
679
typedef
std::map<AgreementKey, AgreementValue>
Agreements
;
680
typedef
std::map<AgreementKey, AgreementValue>::iterator
AgreementsI
;
681
682
typedef
std::map<AgreementKey, BlockAckCache>
BlockAckCaches
;
683
typedef
std::map<AgreementKey, BlockAckCache>::iterator
BlockAckCachesI
;
684
685
Agreements
m_bAckAgreements
;
686
BlockAckCaches
m_bAckCaches
;
687
688
typedef
std::map<AcIndex, MacLowBlockAckEventListener*>
QueueListeners
;
689
QueueListeners
m_edcaListeners
;
690
bool
m_ctsToSelfSupported
;
691
};
692
693
}
// namespace ns3
694
695
#endif
/* MAC_LOW_H */
src
wifi
model
mac-low.h
Generated on Fri Aug 30 2013 01:43:05 for ns-3 by
1.8.1.2