24 #include "ns3/simulator.h" 25 #include "ns3/random-variable-stream.h" 39 #undef NS_LOG_APPEND_CONTEXT 40 #define NS_LOG_APPEND_CONTEXT if (m_low != 0) { std::clog << "[mac=" << m_low->GetAddress () << "] "; } 53 .SetGroupName (
"Wifi")
55 .AddTraceSource (
"BackoffTrace",
56 "Trace source for backoff values",
58 "ns3::TracedValueCallback::Uint32")
59 .AddTraceSource (
"CwTrace",
60 "Trace source for contention window values",
62 "ns3::TracedValueCallback::Uint32")
63 .AddTraceSource (
"TxopTrace",
64 "Trace source for txop start and duration times",
66 "ns3::TracedValueCallback::Time")
72 : m_msduAggregator (0),
74 m_typeOfStation (
STA),
77 m_isAccessRequestedForRts (false),
78 m_currentIsFragmented (false)
117 m_baManager->CompleteAmpduExchange (recipient, tid);
156 return m_baManager->PeekNextPacketByTidAndAddress (header, tid, timestamp);
162 m_baManager->RemovePacket (tid, recipient, seqnumber);
281 peekedHdr = item->GetHeader ();
283 Ptr<Packet> currentAggregatedPacket = Create<Packet> ();
287 bool aggregated =
false;
288 bool isAmsdu =
false;
291 while (peekedItem != 0)
293 peekedHdr = peekedItem->GetHeader ();
300 m_queue->Remove (peekedItem->GetPacket ());
314 currentAggregatedPacket = 0;
331 bool resetDcf =
false;
340 packet =
m_baManager->GetNextPacket (header,
false);
347 packet = item->GetPacket ();
348 header = item->GetHeader ();
402 NS_LOG_DEBUG (
"Dequeueing and discarding head of queue");
434 bool resetCurrentPacket =
true;
468 resetCurrentPacket =
false;
472 if (resetCurrentPacket ==
true)
565 bool resetCurrentPacket =
true;
598 resetCurrentPacket =
false;
602 if (resetCurrentPacket ==
true)
731 packet = item->GetPacket ();
732 hdr = item->GetHeader ();
767 packet = item->GetPacket ();
768 hdr = item->GetHeader ();
788 uint16_t seqNumber = 0;
819 if (peekedPacket == 0)
825 peekedPacket = peekedItem->GetPacket ();
826 hdr = peekedItem->GetHeader ();
834 else if (peekedPacket == 0)
891 return remainingTxop;
912 hdr = peekedItem->GetHeader ();
936 NS_LOG_DEBUG (
"a transmission that did not require an ACK just finished");
965 bool needTxopFragmentation =
false;
992 if (txopDuration.
IsZero ())
997 uint32_t minSize = 0;
1002 size = (minSize + ((maxSize - minSize) / 2));
1030 NS_LOG_DEBUG (
"GetNTxopFragment returning " << nFragments);
1037 if (fragmentNumber == 0)
1041 uint32_t offset = 0;
1048 if (fragmentNumber < nFragments)
1050 offset = (fragmentNumber * fragmentSize);
1056 NS_LOG_DEBUG (
"GetTxopFragmentOffset returning " << offset);
1066 if (fragmentNumber >= nFragments)
1071 if (fragmentNumber == nFragments - 1)
1075 NS_LOG_DEBUG (
"GetNextTxopFragmentSize returning " << fragmentSize);
1076 return fragmentSize;
1128 bool isLastFragment;
1138 return isLastFragment;
1221 m_queue->PushFront (Create<WifiMacQueueItem> (packet, hdr));
1229 NS_LOG_DEBUG (
"received ADDBA response from " << recipient);
1230 uint8_t tid = respHdr->
GetTid ();
1235 NS_LOG_DEBUG (
"block ack agreement established with " << recipient);
1236 m_baManager->UpdateAgreement (respHdr, recipient);
1241 m_baManager->NotifyAgreementUnsuccessful (recipient, tid);
1251 NS_LOG_DEBUG (
"received DELBA frame from=" << recipient);
1260 m_baManager->NotifyGotBlockAck (blockAck, recipient, rxSnr, txMode, dataSnr);
1289 m_baManager->SwitchToBlockAckIfNeeded (recipient, tid, sequence);
1347 uint32_t packets =
m_queue->GetNPacketsByTidAndAddress (tid, recipient);
1436 uint16_t
timeout,
bool immediateBAck)
1459 reqHdr.SetImmediateBlockAck ();
1463 reqHdr.SetDelayedBlockAck ();
1465 reqHdr.SetTid (tid);
1469 reqHdr.SetBufferSize (0);
1471 reqHdr.SetStartingSequence (startSeq);
bool HasVhtSupported(void) const
Return whether the device has VHT capability support enabled.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
bool GetBaAgreementExists(Mac48Address address, uint8_t tid) const
AcIndex m_ac
the access category
TxFailed m_txFailedCallback
the transmit failed callback
bool IsSuccess(void) const
Return whether the status code is success.
void MissedAck(void)
Event handler when an ACK is missed.
bool IsBroadcast(void) const
Simulation virtual time values and global simulation resolution.
Time GetTxopRemaining(void) const
Return the remaining duration in the current TXOP.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
bool GetAmpduExist(Mac48Address dest) const
Return whether A-MPDU is used to transmit data to a peer station.
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
void VerifyBlockAck(void)
Verifies if dequeued packet has to be transmitted with ack policy Block Ack.
Time CalculateOverallTxTime(Ptr< const Packet > packet, const WifiMacHeader *hdr, const MacLowTransmissionParameters ¶ms, uint32_t fragmentSize=0) const
void RestartAccessIfNeeded(void)
Restart access request if needed.
BlockAckType m_blockAckType
the Block ACK type
Ptr< MpduAggregator > GetMpduAggregator(void) const
Returns the aggregator used to construct A-MPDU subframes.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
void ReportFinalDataFailed(Mac48Address address, const WifiMacHeader *header, uint32_t packetSize)
Should be invoked after calling ReportDataFailed if NeedRetransmission returns false.
Time m_startTxop
the start TXOP time
Mac48Address MapDestAddressForAggregation(const WifiMacHeader &hdr)
This functions are used only to correctly set destination address in A-MSDU subframes.
void EnableBasicBlockAck(void)
Wait BASICBLOCKACKTimeout for a Basic Block Ack Response frame.
bool m_isAccessRequestedForRts
flag whether access is requested to transmit a RTS frame
bool SetupBlockAckIfNeeded()
If number of packets in the queue reaches m_blockAckThreshold value, an ADDBA Request frame is sent t...
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
void MissedBlockAck(uint8_t nMpdus)
Event handler when a Block ACK timeout has occurred.
bool NeedBarRetransmission(void)
Check if Block ACK Request should be re-transmitted.
Ptr< ChannelAccessManager > m_channelAccessManager
the channel access manager
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
uint32_t GetTxopFragmentSize() const
Calculate the size of the current TXOP fragment.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Ptr< MpduAggregator > m_mpduAggregator
A-MPDU aggregator.
void SetBlockAckInactivityTimeout(uint16_t timeout)
Set the Block Ack inactivity timeout.
Mac48Address GetBssid(void) const
Return the Basic Service Set Identification.
virtual WifiTxVector GetDataTxVector(Ptr< const Packet > packet, const WifiMacHeader *hdr) const
Return a TXVECTOR for the DATA frame given the destination.
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...
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
bool IsStrictlyPositive(void) const
bool NeedRts(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, WifiTxVector txVector)
void GotDelBaFrame(const MgtDelBaHeader *delBaHdr, Mac48Address recipient)
Event handler when a DELBA frame is received.
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)
Ptr< UniformRandomVariable > m_rng
the random stream
void PrepareForQueue(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
void SetAccessCategory(AcIndex ac)
Set the access category of this EDCAF.
virtual void StartTransmission(Ptr< const Packet > packet, const WifiMacHeader *hdr, MacLowTransmissionParameters parameters, Ptr< Txop > txop)
uint16_t GetNextSequenceNumberFor(WifiMacHeader *hdr)
Return the next sequence number for the given header.
static TypeId GetTypeId(void)
Get the type ID.
uint8_t GetBlockAckThreshold(void) const
Return the current threshold for block ACK mechanism.
void DoDispose(void)
Destructor implementation.
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
control how a packet is transmitted.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
bool IsLastFragment(void) const
Check if the current fragment is the last fragment.
void SetMsduAggregator(const Ptr< MsduAggregator > aggr)
Set the aggregator used to construct A-MSDU subframes.
bool IsTxopFragmentation() const
Check if the current packet is fragmented because of an exceeded TXOP duration.
Ptr< MsduAggregator > m_msduAggregator
A-MSDU aggregator.
uint32_t GetFragmentOffset(void) const
Calculate the offset for the current fragment.
void UpdateFailedCw(void)
Update the value of the CW variable to take into account a transmission failure.
void DestroyBlockAckAgreement(Mac48Address originator, uint8_t tid)
virtual uint32_t GetInteger(void)=0
Get the next random value as an integer drawn from the distribution.
Mac48Address GetAddress(void) const
Return the MAC address of this MacLow.
uint16_t GetNextSequenceNumberFor(const WifiMacHeader *hdr)
Return the next sequence number for the given header.
void ReportRtsFailed(Mac48Address address, const WifiMacHeader *header)
Should be invoked whenever the RtsTimeout associated to a transmission attempt expires.
uint32_t GetNextFragmentSize(void) const
Calculate the size of the next fragment.
void SetAmpduExist(Mac48Address dest, bool enableAmpdu)
Set indication whether A-MPDU is used to transmit data to a peer station.
void StartAccessIfNeeded(void)
Request access from DCF manager if needed.
void SendBlockAckRequest(const Bar &bar)
After that all packets, for which a block ack agreement was established, have been transmitted...
Ptr< BlockAckManager > m_baManager
the Block ACK manager
void CompleteAmpduTransfer(Mac48Address recipient, uint8_t tid)
static Mac48Address GetBroadcast(void)
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void RegisterEdcaForAc(AcIndex ac, Ptr< QosTxop > edca)
TracedValue< uint32_t > m_backoffTrace
backoff trace value
uint16_t GetMaxAmpduSize(void) const
Returns the maximum A-MPDU size in bytes.
void GotAddBaResponse(const MgtAddBaResponseHeader *respHdr, Mac48Address recipient)
Event handler when an ADDBA response is received.
void SetTypeOfStation(TypeOfStation type)
Set type of station with the given type.
virtual bool IsAccessRequested(void) const
bool GetQosSupported(Mac48Address address) const
Return whether the given station is QoS capable.
std::string GetUniqueName(void) const
bool HasNextPacket(void) const
void MissedCts(void)
Event handler when a CTS timeout has occurred.
uint32_t GetFragmentSize(void) const
Calculate the size of the current fragment.
void PushFront(Ptr< const Packet > packet, const WifiMacHeader &hdr)
uint32_t GetNTxopFragment() const
Calculate the number of TXOP fragments needed for the transmission of the current packet...
Mac48Address recipient
recipient
uint32_t GetFragmentOffset(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, uint32_t fragmentNumber)
bool NeedRtsRetransmission(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Check if RTS should be re-transmitted if CTS was missed.
Ptr< MacLow > GetLow(void) const
Return the MacLow associated with this Txop.
bool IsQosTxop() const
Check for QoS TXOP.
void EnableCompressedBlockAck(void)
Wait COMPRESSEDBLOCKACKTimeout for a Compressed Block Ack Response frame.
void SetMpduAggregator(const Ptr< MpduAggregator > aggr)
Set the aggregator used to construct A-MPDU subframes.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool HasHeSupported(void) const
Return whether the device has HE capability support enabled.
uint32_t GetCw(void) const
void EnableAck(void)
Wait ACKTimeout for an ACK.
void BaTxFailed(const WifiMacHeader &hdr)
The packet we sent was successfully received by the receiver.
Bar m_currentBar
the current BAR
uint32_t GetFragmentSize(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, uint32_t fragmentNumber)
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
virtual void DoDispose(void)
Destructor implementation.
bool NeedDataRetransmission(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Check if DATA should be re-transmitted if ACK was missed.
void BaTxOk(const WifiMacHeader &hdr)
The packet we sent was successfully received by the receiver.
Ptr< const Packet > m_currentPacket
the current packet
uint8_t GetTid(Ptr< const Packet > packet, const WifiMacHeader hdr)
Extraction operator for TypeId.
void EndTxNoAck(void)
Event handler when a transmission that does not require an ACK has completed.
void DisableRts(void)
Do not send rts and wait for cts before sending data.
static Time Now(void)
Return the current simulation virtual time.
uint16_t PeekNextSequenceNumberFor(const WifiMacHeader *hdr)
Return the next sequence number for the Traffic ID and destination, but do not pick it (i...
bool HasHtSupported(void) const
Return whether the device has HT capability support enabled.
void SetBlockAckThreshold(uint8_t threshold)
Set threshold for block ACK mechanism.
TracedValue< uint32_t > m_cwTrace
CW trace value.
Ptr< MacLow > m_low
the MacLow
uint8_t m_blockAckThreshold
the Block ACK threshold
void FlushAggregateQueue(uint8_t tid)
This function is called to flush the aggregate queue, which is used for A-MPDU.
void SetWifiRemoteStationManager(const Ptr< WifiRemoteStationManager > remoteManager)
Set WifiRemoteStationsManager this QosTxop is associated to.
uint32_t GetTxopFragmentOffset(uint32_t fragmentNumber) const
Calculate the offset for the fragment.
void NotifyCollision(void)
Notify the EDCAF that collision has occurred.
void RemoveRetransmitPacket(uint8_t tid, Mac48Address recipient, uint16_t seqnumber)
Remove a packet after you peek in the retransmit queue and get it.
Ptr< const Packet > PeekNextRetransmitPacket(WifiMacHeader &header, uint8_t tid, Time *timestamp)
Peek in retransmit queue and get the next packet without removing it from the queue.
void ReportDataFailed(Mac48Address address, const WifiMacHeader *header, uint32_t packetSize)
Should be invoked whenever the AckTimeout associated to a transmission attempt expires.
MacLowTransmissionParameters m_currentParams
current transmission parameters
void GotBlockAck(const CtrlBAckResponseHeader *blockAck, Mac48Address recipient, double rxSnr, WifiMode txMode, double dataSnr)
Event handler when a Block ACK is received.
void GotAck(void)
Event handler when an ACK is received.
void StartNextPacket(void)
Start transmission for the next packet if allowed by the TxopLimit.
bool m_accessRequested
flag whether channel access is already requested
void Unblock(Mac48Address dest, uint8_t tid)
Un-block the given destination address and TID (e.g.
void CompleteTx(void)
For now is typically invoked to complete transmission of a packets sent with ack policy Block Ack: th...
bool IsStrictlyNegative(void) const
Mac48Address MapSrcAddressForAggregation(const WifiMacHeader &hdr)
This functions are used only to correctly set source address in A-MSDU subframes. ...
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
TypeOfStation GetTypeOfStation(void) const
Return type of station.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< const Packet > bar
block ack request
Ptr< QosBlockedDestinations > m_qosBlockedDestinations
QOS blocked destinations.
void NotifyAccessGranted(void)
Notify the EDCAF that access has been granted.
uint16_t GetNextSeqNumberByTidAndAddress(uint8_t tid, Mac48Address addr) const
Return the next sequence number for the Traffic ID and destination.
bool NeedFragmentation(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
void EnableNextData(uint32_t size)
void Block(Mac48Address dest, uint8_t tid)
Block the given destination address and TID from sending (e.g.
void CompleteMpduTx(Ptr< const Packet > packet, WifiMacHeader hdr, Time tstamp)
Stores an MPDU (part of an A-MPDU) in blockackagreement (i.e.
TxOk m_txOkCallback
the transmit OK callback
void DisableNextData(void)
Do not attempt to send data burst after current transmission.
virtual void SetWifiRemoteStationManager(const Ptr< WifiRemoteStationManager > remoteManager)
Set WifiRemoteStationsManager this Txop is associated to.
void CompleteConfig(void)
Complete block ACK configuration.
bool m_currentIsFragmented
flag whether current packet is fragmented
uint8_t m_fragmentNumber
the fragment number
TracedCallback< Time, Time > m_txopTrace
TXOP trace callback.
void DoInitialize(void)
Initialize() implementation.
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...
bool NeedFragmentation(void) const
Check if the current packet should be fragmented.
TypeOfStation
Enumeration for type of station.
WifiMacHeader m_currentHdr
the current header
Time m_currentPacketTimestamp
the current packet timestamp
Ptr< Packet > GetFragmentPacket(WifiMacHeader *hdr)
Get the next fragment from the packet with appropriate Wifi header for the fragment.
uint16_t m_blockAckInactivityTimeout
the Block ACK inactivity timeout
bool IsNull(void) const
Check for null implementation.
Ptr< WifiRemoteStationManager > m_stationManager
the wifi remote station manager
bool HasTxop(void) const
Check if the station has TXOP granted for the next MPDU.
bool Aggregate(Ptr< const Packet > packet, Ptr< Packet > aggregatedPacket, Mac48Address src, Mac48Address dest) const
Adds packet to aggregatedPacket.
void DisableAck(void)
Do not wait for Ack after data transmission.
void NotifyInternalCollision(void)
Notify the EDCAF that internal collision has occurred.
void ResetCw(void)
Update the value of the CW variable to take into account a transmission success or a transmission abo...
uint32_t GetNextTxopFragmentSize(uint32_t fragmentNumber) const
Calculate the size of the next TXOP fragment.
TypeOfStation m_typeOfStation
the type of station
a unique identifier for an interface.
void ReportFinalRtsFailed(Mac48Address address, const WifiMacHeader *header)
Should be invoked after calling ReportRtsFailed if NeedRetransmission returns false.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
void StartBackoffNow(uint32_t nSlots)
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
void RequestAccess(Ptr< Txop > state, bool isCfPeriod=false)
void AddHeader(const Header &header)
Add header to this packet.
std::map< Mac48Address, bool > m_aMpduEnabled
list containing flags whether A-MPDU is enabled for a given destination address
Implements the IEEE 802.11 MAC trailer.
Ptr< MsduAggregator > GetMsduAggregator(void) const
Returns the aggregator used to construct A-MSDU subframes.
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...
Handle packet fragmentation and retransmissions for data and management frames.
uint16_t PeekNextSequenceNumberFor(WifiMacHeader *hdr)
Return the next sequence number for the Traffic ID and destination, but do not pick it (i...
Time GetTxopLimit(void) const
Return the TXOP limit.