24 #include "ns3/pointer.h"
32 #include "ns3/simulator.h"
34 #undef NS_LOG_APPEND_CONTEXT
35 #define NS_LOG_APPEND_CONTEXT if (m_low != 0) { std::clog << "[mac=" << m_low->GetAddress () << "] "; }
48 .SetGroupName (
"Wifi")
50 .AddTraceSource (
"BackoffTrace",
51 "Trace source for backoff values",
53 "ns3::TracedValue::Uint32Callback")
54 .AddTraceSource (
"CwTrace",
55 "Trace source for contention window values",
57 "ns3::TracedValue::Uint32Callback")
58 .AddTraceSource (
"TxopTrace",
59 "Trace source for txop start and duration times",
61 "ns3::TracedValueCallback::Time")
67 : m_msduAggregator (0),
69 m_typeOfStation (
STA),
72 m_isAccessRequestedForRts (false),
73 m_currentIsFragmented (false)
78 m_baManager->SetQueue (
m_queue);
82 m_baManager->SetMaxPacketDelay (
m_queue->GetMaxDelay ());
106 return m_baManager->ExistsAgreement (address, tid);
112 return m_baManager->GetNBufferedPackets (address, tid);
118 return m_baManager->GetNRetryNeededPackets (recipient, tid);
124 m_baManager->CompleteAmpduExchange (recipient, tid);
169 return m_baManager->PeekNextPacketByTidAndAddress (header,recipient,tid, timestamp);
175 m_baManager->RemovePacket (tid, recipient, seqnumber);
293 peekedHdr = item->GetHeader ();
295 Ptr<Packet> currentAggregatedPacket = Create<Packet> ();
299 bool aggregated =
false;
300 bool isAmsdu =
false;
304 while (peekedItem != 0)
306 peekedHdr = peekedItem->GetHeader ();
313 m_queue->Remove (peekedItem->GetPacket ());
327 currentAggregatedPacket = 0;
344 bool resetDcf =
false;
360 packet = item->GetPacket ();
361 header = item->GetHeader ();
415 NS_LOG_DEBUG (
"Dequeueing and discarding head of queue");
447 bool resetCurrentPacket =
true;
481 resetCurrentPacket =
false;
485 if (resetCurrentPacket ==
true)
577 bool resetCurrentPacket =
true;
610 resetCurrentPacket =
false;
614 if (resetCurrentPacket ==
true)
743 packet = item->GetPacket ();
744 hdr = item->GetHeader ();
784 packet = item->GetPacket ();
785 hdr = item->GetHeader ();
805 uint16_t seqNumber = 0;
836 if (peekedPacket == 0)
843 peekedPacket = peekedItem->GetPacket ();
844 hdr = peekedItem->GetHeader ();
852 else if (peekedPacket == 0)
911 return remainingTxop;
933 hdr = peekedItem->GetHeader ();
957 NS_LOG_DEBUG (
"a transmission that did not require an ACK just finished");
986 bool needTxopFragmentation =
false;
1013 if (txopDuration.
IsZero ())
1018 uint32_t minSize = 0;
1023 size = (minSize + ((maxSize - minSize) / 2));
1051 NS_LOG_DEBUG (
"GetNTxopFragment returning " << nFragments);
1058 if (fragmentNumber == 0)
1062 uint32_t offset = 0;
1069 if (fragmentNumber < nFragments)
1071 offset = (fragmentNumber * fragmentSize);
1077 NS_LOG_DEBUG (
"GetTxopFragmentOffset returning " << offset);
1087 if (fragmentNumber >= nFragments)
1092 if (fragmentNumber == nFragments - 1)
1096 NS_LOG_DEBUG (
"GetNextTxopFragmentSize returning " << fragmentSize);
1097 return fragmentSize;
1149 bool isLastFragment;
1159 return isLastFragment;
1242 m_queue->PushFront (Create<WifiMacQueueItem> (packet, hdr));
1250 NS_LOG_DEBUG (
"received ADDBA response from " << recipient);
1251 uint8_t tid = respHdr->
GetTid ();
1256 NS_LOG_DEBUG (
"block ack agreement established with " << recipient);
1257 m_baManager->UpdateAgreement (respHdr, recipient);
1262 m_baManager->NotifyAgreementUnsuccessful (recipient, tid);
1272 NS_LOG_DEBUG (
"received DELBA frame from=" << recipient);
1281 m_baManager->NotifyGotBlockAck (blockAck, recipient, rxSnr, txMode, dataSnr);
1310 m_baManager->SwitchToBlockAckIfNeeded (recipient, tid, sequence);
1464 uint16_t
timeout,
bool immediateBAck)
1466 NS_LOG_FUNCTION (
this << dest << (uint16_t)tid << startSeq << timeout << immediateBAck);
1487 reqHdr.SetImmediateBlockAck ();
1491 reqHdr.SetDelayedBlockAck ();
1493 reqHdr.SetTid (tid);
1497 reqHdr.SetBufferSize (0);
1498 reqHdr.SetTimeout (timeout);
1499 reqHdr.SetStartingSequence (startSeq);
MacLowTransmissionParameters m_currentParams
current transmission parameters
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
void DoDispose(void)
Destructor implementation.
bool NeedRtsRetransmission(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Check if RTS should be re-transmitted if CTS was missed.
Simulation virtual time values and global simulation resolution.
Ptr< DcfState > m_dcf
the DCF state
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint8_t m_fragmentNumber
the fragment number
void SetBlockAckInactivityTimeout(uint16_t timeout)
Set the Block Ack inactivity timeout.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
virtual void StartTransmission(Ptr< const Packet > packet, const WifiMacHeader *hdr, MacLowTransmissionParameters parameters, Ptr< DcaTxop > dca)
uint16_t m_blockAckInactivityTimeout
the Block ACK inactivity timeout
uint32_t GetFragmentOffset(void) const
Calculate the offset for the current fragment.
uint32_t GetTxopFragmentOffset(uint32_t fragmentNumber) const
Calculate the offset for the fragment.
void VerifyBlockAck(void)
Verifies if dequeued packet has to be transmitted with ack policy Block Ack.
void StartNextPacket(void)
Start transmission for the next packet if allowed by the TxopLimit.
void NotifyCollision(void)
Notify the EDCAF that collision has occurred.
void ReportDataFailed(Mac48Address address, const WifiMacHeader *header)
Should be invoked whenever the AckTimeout associated to a transmission attempt expires.
void EnableBasicBlockAck(void)
Wait BASICBLOCKACKTimeout for a Basic Block Ack Response frame.
void CompleteMpduTx(Ptr< const Packet > packet, WifiMacHeader hdr, Time tstamp)
Stores an MPDU (part of an A-MPDU) in blockackagreement (i.e.
bool HasTxop(void) const
Check if the station has TXOP granted for the next MPDU.
void SendBlockAckRequest(const Bar &bar)
After that all packets, for which a block ack agreement was established, have been transmitted...
bool GetQosSupported(Mac48Address address) const
Return whether the given station is QoS capable.
Ptr< MacLow > m_low
the MacLow
Mac48Address GetBssid(void) const
Return the Basic Service Set Identification.
void SetAccessCategory(AcIndex ac)
Set the access category of this EDCAF.
bool IsNull(void) const
Check for null implementation.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
bool NeedBarRetransmission(void)
Check if Block ACK Request should be re-transmitted.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
uint8_t m_blockAckThreshold
the Block ACK threshold
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
bool IsBroadcast(void) const
TxOk m_txOkCallback
the transmit OK callback
bool NeedDataRetransmission(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Check if DATA should be re-transmitted if ACK was missed.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
bool NeedRts(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, WifiTxVector txVector)
uint32_t GetNextFragmentSize(void) const
Calculate the size of the next fragment.
void UpdateFragmentationThreshold(void)
Typically called to update the fragmentation threshold at the start of a new transmission.
bool IsLastFragment(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, uint32_t fragmentNumber)
void ResetCw(void)
Update the value of the CW variable to take into account a transmission success or a transmission abo...
Time GetTxopRemaining(void) const
Return the remaining duration in the current TXOP.
void PrepareForQueue(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
Ptr< MsduAggregator > m_msduAggregator
A-MSDU aggregator.
void SetWifiRemoteStationManager(const Ptr< WifiRemoteStationManager > remoteManager)
Set WifiRemoteStationsManager this EdcaTxopN is associated to.
uint32_t GetFragmentSize(void) const
Calculate the size of the current fragment.
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
uint32_t GetTxopFragmentSize() const
Calculate the size of the current TXOP fragment.
control how a packet is transmitted.
void MissedBlockAck(uint8_t nMpdus)
Event handler when a Block ACK timeout has occurred.
bool m_isAccessRequestedForRts
flag whether access is requested to transmit a RTS frame
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Ptr< MpduAggregator > m_mpduAggregator
A-MPDU aggregator.
AcIndex m_ac
the access category
void MissedAck(void)
Event handler when an ACK is missed.
TracedCallback< Time, Time > m_txopTrace
TXOP trace callback.
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
Time GetTxopLimit(void) const
Return the TXOP limit.
void DestroyBlockAckAgreement(Mac48Address originator, uint8_t tid)
This queue contains packets for a particular access class.
void GotDelBaFrame(const MgtDelBaHeader *delBaHdr, Mac48Address recipient)
Event handler when a DELBA frame is received.
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
void NotifyAccessGranted(void)
Notify the EDCAF that access has been granted.
void RemoveRetransmitPacket(uint8_t tid, Mac48Address recipient, uint16_t seqnumber)
Remove a packet after you peek in the retransmit queue and get it.
virtual uint32_t GetInteger(void)=0
Get the next random value as an integer drawn from the distribution.
void ReportFinalDataFailed(Mac48Address address, const WifiMacHeader *header)
Should be invoked after calling ReportDataFailed if NeedDataRetransmission returns false...
void NotifyInternalCollision(void)
Notify the EDCAF that internal collision has occurred.
std::map< Mac48Address, bool > m_aMpduEnabled
list containing flags whether A-MPDU is enabled for a given destination address
TracedValue< uint32_t > m_cwTrace
CW trace value.
uint16_t GetNextSequenceNumberFor(const WifiMacHeader *hdr)
Return the next sequence number for the given header.
TracedValue< uint32_t > m_backoffTrace
backoff trace value
void ReportRtsFailed(Mac48Address address, const WifiMacHeader *header)
Should be invoked whenever the RtsTimeout associated to a transmission attempt expires.
uint32_t GetNTxopFragment() const
Calculate the number of TXOP fragments needed for the transmission of the current packet...
void SendAddBaRequest(Mac48Address recipient, uint8_t tid, uint16_t startSeq, uint16_t timeout, bool immediateBAck)
Sends an ADDBA Request to establish a block ack agreement with sta addressed by recipient for tid tid...
void SendDelbaFrame(Mac48Address addr, uint8_t tid, bool byOriginator)
Sends DELBA frame to cancel a block ack agreement with sta addressed by addr for tid tid...
Ptr< const Packet > PeekNextRetransmitPacket(WifiMacHeader &header, Mac48Address recipient, uint8_t tid, Time *timestamp)
Peek in retransmit queue and get the next packet without removing it from the queue.
bool IsStrictlyPositive(void) const
void SetBlockAckThreshold(uint8_t threshold)
Set threshold for block ACK mechanism.
void SetMsduAggregator(const Ptr< MsduAggregator > aggr)
Set the aggregator used to construct A-MSDU subframes.
void MissedCts(void)
Event handler when a CTS timeout has occurred.
void SetTypeOfStation(TypeOfStation type)
Set type of station with the given type.
bool IsTxopFragmentation() const
Check if the current packet is fragmented because of an exceeded TXOP duration.
std::string GetUniqueName(void) const
static Mac48Address GetBroadcast(void)
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Mac48Address GetAddress(void) const
Return the MAC address of this MacLow.
bool HasNextPacket(void) const
bool IsAccessRequested(void) const
Ptr< Packet > GetFragmentPacket(WifiMacHeader *hdr)
Get the next fragment from the packet with appropriate Wifi header for the fragment.
Ptr< WifiRemoteStationManager > m_stationManager
the wifi remote station manager
uint32_t GetNRetryNeededPackets(Mac48Address recipient, uint8_t tid) const
Time CalculateOverallTxFragmentTime(Ptr< const Packet > packet, const WifiMacHeader *hdr, const MacLowTransmissionParameters ¶ms, uint32_t fragmentSize) const
Time m_currentPacketTimestamp
the current packet timestamp
Mac48Address recipient
recipient
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
uint32_t GetFragmentOffset(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, uint32_t fragmentNumber)
void EndTxNoAck(void)
Event handler when a transmission that does not require an ACK has completed.
void StartBackoffNow(uint32_t nSlots)
bool NeedFragmentation(void) const
Check if the current packet should be fragmented.
void GotAck(void)
Event handler when an ACK is received.
Ptr< UniformRandomVariable > m_rng
the random stream
Ptr< MpduAggregator > GetMpduAggregator(void) const
Returns the aggregator used to construct A-MPDU subframes.
void EnableCompressedBlockAck(void)
Wait COMPRESSEDBLOCKACKTimeout for a Compressed Block Ack Response frame.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< MsduAggregator > GetMsduAggregator(void) const
Returns the aggregator used to construct A-MSDU subframes.
Bar m_currentBar
the current BAR
WifiMacHeader m_currentHdr
the current header
bool IsEdca()
Check for EDCA.
void EnableAck(void)
Wait ACKTimeout for an ACK.
TypeOfStation GetTypeOfStation(void) const
Return type of station.
uint32_t GetFragmentSize(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, uint32_t fragmentNumber)
Mac48Address MapDestAddressForAggregation(const WifiMacHeader &hdr)
This functions are used only to correctly set destination address in A-MSDU subframes.
bool SetupBlockAckIfNeeded()
If number of packets in the queue reaches m_blockAckThreshold value, an ADDBA Request frame is sent t...
bool GetBaAgreementExists(Mac48Address address, uint8_t tid) const
bool HasVhtSupported(void) const
Return whether the device has VHT capability support enabled.
uint8_t GetTid(Ptr< const Packet > packet, const WifiMacHeader hdr)
Extraction operator for TypeId.
void SetAmpduExist(Mac48Address dest, bool enableAmpdu)
Set indication whether A-MPDU is used to transmit data to a peer station.
void BaTxOk(const WifiMacHeader &hdr)
The packet we sent was successfully received by the receiver.
void DisableRts(void)
Do not send rts and wait for cts before sending data.
static Time Now(void)
Return the current simulation virtual time.
Time m_startTxop
the start TXOP time
uint16_t PeekNextSequenceNumberFor(const WifiMacHeader *hdr)
Return the next sequence number for the Traffic ID and destination, but do not pick it (i...
uint32_t GetNextTxopFragmentSize(uint32_t fragmentNumber) const
Calculate the size of the next TXOP fragment.
bool GetAmpduExist(Mac48Address dest) const
Return whether A-MPDU is used to transmit data to a peer station.
Ptr< const Packet > m_currentPacket
the current packet
void GotBlockAck(const CtrlBAckResponseHeader *blockAck, Mac48Address recipient, double rxSnr, WifiMode txMode, double dataSnr)
Event handler when a Block ACK is received.
void FlushAggregateQueue(uint8_t tid)
This function is called to flush the aggregate queue, which is used for A-MPDU.
void DoInitialize(void)
Initialize() implementation.
bool HasHtSupported(void) const
Return whether the device has HT capability support enabled.
Ptr< MacLow > GetLow(void) const
Return the MacLow associated with this DcaTxop.
void PushFront(Ptr< const Packet > packet, const WifiMacHeader &hdr)
virtual WifiTxVector GetDataTxVector(Ptr< const Packet > packet, const WifiMacHeader *hdr) const
Return a TXVECTOR for the DATA frame given the destination.
bool HasHeSupported(void) const
Return whether the device has HE capability support enabled.
static TypeId GetTypeId(void)
Get the type ID.
void BaTxFailed(const WifiMacHeader &hdr)
The packet we sent was successfully received by the receiver.
Time CalculateOverallTxTime(Ptr< const Packet > packet, const WifiMacHeader *hdr, const MacLowTransmissionParameters ¶ms) const
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
Ptr< QosBlockedDestinations > m_qosBlockedDestinations
QOS blocked destinations.
void CompleteConfig(void)
Complete block ACK configuration.
uint32_t GetCw(void) const
void Unblock(Mac48Address dest, uint8_t tid)
Un-block the given destination address and TID (e.g.
BlockAckType m_blockAckType
the Block ACK type
void RestartAccessIfNeeded(void)
Restart access request if needed.
void CompleteAmpduTransfer(Mac48Address recipient, uint8_t tid)
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< const Packet > bar
block ack request
uint8_t GetBlockAckThreshold(void) const
Return the current threshold for block ACK mechanism.
void CompleteTx(void)
For now is typically invoked to complete transmission of a packets sent with ack policy Block Ack: th...
bool IsSuccess(void) const
Return whether the status code is success.
bool NeedFragmentation(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
virtual void DoDispose(void)
Destructor implementation.
void RequestAccess(Ptr< DcfState > state)
bool IsStrictlyNegative(void) const
void EnableNextData(uint32_t size)
void DisableOverrideDurationId(void)
Do not force the duration/id field of the packet: its value is automatically calculated by the MacLow...
bool IsLastFragment(void) const
Check if the current fragment is the last fragment.
void Block(Mac48Address dest, uint8_t tid)
Block the given destination address and TID from sending (e.g.
void DisableNextData(void)
Do not attempt to send data burst after current transmission.
uint16_t PeekNextSequenceNumberFor(WifiMacHeader *hdr)
Return the next sequence number for the Traffic ID and destination, but do not pick it (i...
virtual uint32_t GetMaxAmpduSize(void) const =0
Returns the maximum A-MPDU size in bytes.
void StartAccessIfNeeded(void)
Request access from DCF manager if needed.
bool m_currentIsFragmented
flag whether current packet is fragmented
void ReportAmpduTxStatus(Mac48Address address, uint8_t tid, uint8_t nSuccessfulMpdus, uint8_t nFailedMpdus, double rxSnr, double dataSnr)
Typically called per A-MPDU, either when a Block ACK was successfully received or when a BlockAckTime...
TypeOfStation
Enumeration for type of station.
Ptr< BlockAckManager > m_baManager
the Block ACK manager
void UpdateFailedCw(void)
Update the value of the CW variable to take into account a transmission failure.
virtual bool Aggregate(Ptr< const Packet > packet, Ptr< Packet > aggregatedPacket, Mac48Address src, Mac48Address dest) const =0
Adds packet to aggregatedPacket.
handle packet fragmentation and retransmissions.
uint32_t GetNOutstandingPacketsInBa(Mac48Address address, uint8_t tid) const
void DisableAck(void)
Do not wait for Ack after data transmission.
uint16_t GetNextSeqNumberByTidAndAddress(uint8_t tid, Mac48Address addr) const
Return the next sequence number for the Traffic ID and destination.
a unique identifier for an interface.
void ReportFinalRtsFailed(Mac48Address address, const WifiMacHeader *header)
Should be invoked after calling ReportRtsFailed if NeedRtsRetransmission returns false.
bool NeedsAccess(void) const
Check if the EDCAF requires access.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
void SetMpduAggregator(const Ptr< MpduAggregator > aggr)
Set the aggregator used to construct A-MPDU subframes.
void AddHeader(const Header &header)
Add header to this packet.
void GotAddBaResponse(const MgtAddBaResponseHeader *respHdr, Mac48Address recipient)
Event handler when an ADDBA response is received.
Implements the IEEE 802.11 MAC trailer.
virtual void SetWifiRemoteStationManager(const Ptr< WifiRemoteStationManager > remoteManager)
Set WifiRemoteStationsManager this DcaTxop is associated to.
TypeOfStation m_typeOfStation
the type of station
Mac48Address MapSrcAddressForAggregation(const WifiMacHeader &hdr)
This functions are used only to correctly set source address in A-MSDU subframes. ...
void RegisterEdcaForAc(AcIndex ac, Ptr< EdcaTxopN > edca)
TxFailed m_txFailedCallback
the transmit failed callback
Ptr< DcfManager > m_manager
the DCF manager
uint16_t GetNextSequenceNumberFor(WifiMacHeader *hdr)
Return the next sequence number for the given header.