30#include "ns3/attribute-container.h"
32#include "ns3/pointer.h"
33#include "ns3/shuffle.h"
34#include "ns3/simulator.h"
35#include "ns3/socket.h"
40#undef NS_LOG_APPEND_CONTEXT
41#define NS_LOG_APPEND_CONTEXT WIFI_TXOP_NS_LOG_APPEND_CONTEXT
57 .AddConstructor<
Txop>()
58 .AddAttribute(
"AcIndex",
59 "The AC index of the packets contained in the wifi MAC queue of this "
79 .AddAttribute(
"MinCw",
80 "The minimum value of the contention window (just for the first link, "
81 "in case of 11be multi-link devices).",
86 MakeUintegerChecker<uint32_t>(),
88 "Use MinCws attribute instead of MinCw")
91 "The minimum values of the contention window for all the links (sorted in "
92 "increasing order of link ID). An empty vector is ignored and the default value "
93 "as per Table 9-155 of the IEEE 802.11-2020 standard will be used. Note that, if "
94 "this is a non-AP STA, these values could be overridden by values advertised by "
95 "the AP through EDCA Parameter Set elements.",
98 MakeAttributeContainerChecker<UintegerValue>(MakeUintegerChecker<uint32_t>()))
99 .AddAttribute(
"MaxCw",
100 "The maximum value of the contention window (just for the first link, "
101 "in case of 11be multi-link devices).",
106 MakeUintegerChecker<uint32_t>(),
108 "Use MaxCws attribute instead of MaxCw")
111 "The maximum values of the contention window for all the links (sorted in "
112 "increasing order of link ID). An empty vector is ignored and the default value "
113 "as per Table 9-155 of the IEEE 802.11-2020 standard will be used. Note that, if "
114 "this is a non-AP STA, these values could be overridden by values advertised by "
115 "the AP through EDCA Parameter Set elements.",
118 MakeAttributeContainerChecker<UintegerValue>(MakeUintegerChecker<uint32_t>()))
121 "The AIFSN: the default value conforms to non-QOS (just for the first link, "
122 "in case of 11be multi-link devices).",
127 MakeUintegerChecker<uint8_t>(),
129 "Use Aifsns attribute instead of Aifsn")
132 "The values of AIFSN for all the links (sorted in increasing order "
133 "of link ID). An empty vector is ignored and the default value as per "
134 "Table 9-155 of the IEEE 802.11-2020 standard will be used. Note that, if "
135 "this is a non-AP STA, these values could be overridden by values advertised by "
136 "the AP through EDCA Parameter Set elements.",
139 MakeAttributeContainerChecker<UintegerValue>(MakeUintegerChecker<uint8_t>()))
140 .AddAttribute(
"TxopLimit",
141 "The TXOP limit: the default value conforms to non-QoS "
142 "(just for the first link, in case of 11be multi-link devices).",
149 "Use TxopLimits attribute instead of TxopLimit")
152 "The values of TXOP limit for all the links (sorted in increasing order "
153 "of link ID). An empty vector is ignored and the default value as per "
154 "Table 9-155 of the IEEE 802.11-2020 standard will be used. Note that, if "
155 "this is a non-AP STA, these values could be overridden by values advertised by "
156 "the AP through EDCA Parameter Set elements.",
161 .AddAttribute(
"Queue",
162 "The WifiMacQueue object",
165 MakePointerChecker<WifiMacQueue>())
166 .AddTraceSource(
"BackoffTrace",
167 "Trace source for backoff values",
169 "ns3::Txop::BackoffValueTracedCallback")
170 .AddTraceSource(
"CwTrace",
171 "Trace source for contention window values",
173 "ns3::Txop::CwValueTracedCallback");
204 m_queue = CreateObject<WifiMacQueue>(aci);
207std::unique_ptr<Txop::LinkEntity>
210 return std::make_unique<LinkEntity>();
216 auto it =
m_links.find(linkId);
222const std::map<uint8_t, std::unique_ptr<Txop::LinkEntity>>&
235 for (
const auto& [from, to] : links)
237 auto nh = tmp.extract(from);
268 m_queue->TraceConnectWithoutContext(
"DropBeforeEnqueue",
270 m_queue->TraceConnectWithoutContext(
"Expired",
296 "The size of the given vector (" << minCws.size()
297 <<
") does not match the number of links ("
302 for (
const auto& [
id, link] :
m_links)
313 "This function can only be called after that links have been created");
315 bool changed = (link.cwMin != minCw);
339 "The size of the given vector (" << maxCws.size()
340 <<
") does not match the number of links ("
345 for (
const auto& [
id, link] :
m_links)
356 "This function can only be called after that links have been created");
358 bool changed = (link.cwMax != maxCw);
387 link.cw = std::min(2 * (link.cw + 1) - 1,
GetMaxCw(linkId));
389 link.cw = std::max(link.cw,
GetMinCw(linkId));
411 link.backoffSlots -= nSlots;
412 link.backoffStart = backoffUpdateBound;
413 NS_LOG_DEBUG(
"update slots=" << nSlots <<
" slots, backoff=" << link.backoffSlots);
422 if (link.backoffSlots != 0)
424 NS_LOG_DEBUG(
"reset backoff from " << link.backoffSlots <<
" to " << nSlots <<
" slots");
430 link.backoffSlots = nSlots;
450 "The size of the given vector (" << aifsns.size()
451 <<
") does not match the number of links ("
456 for (
const auto& [
id, link] :
m_links)
467 "This function can only be called after that links have been created");
480 if (txopLimits.empty())
487 "The size of the given vector (" << txopLimits.size()
488 <<
") does not match the number of links ("
493 for (
const auto& [
id, link] :
m_links)
505 "The TXOP limit must be expressed in multiple of 32 microseconds!");
507 "This function can only be called after that links have been created");
526 std::vector<uint32_t> ret;
528 for (
const auto& [
id, link] :
m_links)
530 ret.push_back(link->cwMin);
550 std::vector<uint32_t> ret;
552 for (
const auto& [
id, link] :
m_links)
554 ret.push_back(link->cwMax);
574 std::vector<uint8_t> ret;
576 for (
const auto& [
id, link] :
m_links)
578 ret.push_back(link->aifsn);
598 std::vector<Time> ret;
600 for (
const auto& [
id, link] :
m_links)
602 ret.push_back(link->txopLimit);
616 m_queue->WipeAllExpiredMpdus();
617 bool ret =
static_cast<bool>(
m_queue->Peek(linkId));
628 packet->RemovePacketTag(priorityTag);
629 Queue(Create<WifiMpdu>(packet, hdr));
642 {WifiQueueBlockedReason::USING_OTHER_EMLSR_LINK,
643 WifiQueueBlockedReason::WAITING_EMLSR_TRANSITION_DELAY});
646 for (
auto it = linkIds.begin(); it != linkIds.end();)
650 it = linkIds.erase(it);
660 std::map<uint8_t, bool> hasFramesToTransmit;
661 for (
const auto linkId : linkIds)
668 std::vector<uint8_t> shuffledLinkIds(linkIds.cbegin(), linkIds.cend());
673 std::stringstream ss;
674 std::copy(shuffledLinkIds.cbegin(),
675 shuffledLinkIds.cend(),
676 std::ostream_iterator<uint16_t>(ss,
" "));
677 NS_LOG_DEBUG(
"Request channel access on link IDs: " << ss.str());
680 for (
const auto linkId : shuffledLinkIds)
689 hasFramesToTransmit.at(linkId),
705 NS_LOG_FUNCTION(
this << linkId << hadFramesToTransmit << checkMediumBusy);
715 NS_LOG_DEBUG(
"Channel access already requested or granted on link " << +linkId);
721 NS_LOG_DEBUG(
"No frames to transmit on link " << +linkId);
739 for (
const auto& [
id, link] :
m_links)
822 for (
const auto& [
id, link] :
m_links)
A container for one type of attribute.
auto Bind(BoundArgs &&... bargs)
Bind a variable number of arguments.
bool NeedBackoffUponAccess(Ptr< Txop > txop, bool hadFramesToTransmit, bool checkMediumBusy)
Determine if a new backoff needs to be generated as per letter a) of Section 10.23....
void RequestAccess(Ptr< Txop > txop)
Hold variables of type enum.
bool IsPending() const
This method is syntactic sugar for !IsExpired().
A base class which provides memory management and object aggregation.
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
Template class for packet Queues.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
static Time Now()
Return the current simulation virtual time.
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
indicates whether the socket has a priority set.
Simulation virtual time values and global simulation resolution.
bool IsPositive() const
Exactly equivalent to t >= 0.
int64_t GetMicroSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Handle packet fragmentation and retransmissions for data and management frames.
Ptr< WifiMac > m_mac
the wifi MAC
Time GetTxopLimit() const
Return the TXOP limit.
virtual std::unique_ptr< LinkEntity > CreateLinkEntity() const
Create a LinkEntity object.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
virtual ChannelAccessStatus GetAccessStatus(uint8_t linkId) const
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
void StartAccessAfterEvent(uint8_t linkId, bool hadFramesToTransmit, bool checkMediumBusy)
Request channel access on the given link after the occurrence of an event that possibly requires to g...
virtual bool HasFramesToTransmit(uint8_t linkId)
Check if the Txop has frames to transmit over the given link.
virtual void NotifyOff()
When off operation occurs, the queue gets cleaned up.
UniformRandomBitGenerator m_shuffleLinkIdsGen
random number generator to shuffle link IDs
Ptr< UniformRandomVariable > m_rng
the random stream
CwValueTracedCallback m_cwTrace
CW trace value.
void DoDispose() override
Destructor implementation.
void SetMaxCw(uint32_t maxCw)
Set the maximum contention window size.
void SetMaxCws(const std::vector< uint32_t > &maxCws)
Set the maximum contention window size for each link.
uint32_t GetMinCw() const
Return the minimum contention window size.
ChannelAccessStatus
Enumeration for channel access status.
virtual void NotifyOn()
When on operation occurs, channel access will be started.
void UpdateFailedCw(uint8_t linkId)
Update the value of the CW variable for the given link to take into account a transmission failure.
void SetAifsns(const std::vector< uint8_t > &aifsns)
Set the number of slots that make up an AIFS for each link.
static constexpr bool DIDNT_HAVE_FRAMES_TO_TRANSMIT
no packet available for transmission was in the queue
Ptr< WifiMacQueue > GetWifiMacQueue() const
Return the packet queue associated with this Txop.
virtual void SetWifiMac(const Ptr< WifiMac > mac)
Set the wifi MAC this Txop is associated to.
virtual void NotifyWakeUp(uint8_t linkId)
When wake up operation occurs on a link, channel access on that link will be restarted.
virtual void NotifyChannelReleased(uint8_t linkId)
Called by the FrameExchangeManager to notify the completion of the transmissions.
std::vector< uint32_t > GetMaxCws() const
Return the maximum contention window size for each link.
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
virtual void CreateQueue(AcIndex aci)
Create a wifi MAC queue containing packets of the given AC.
void ResetCw(uint8_t linkId)
Update the value of the CW variable for the given link to take into account a transmission success or...
LinkEntity & GetLink(uint8_t linkId) const
Get a reference to the link associated with the given ID.
virtual bool IsQosTxop() const
Check for QoS TXOP.
std::vector< uint32_t > GetMinCws() const
Return the minimum contention window size for each link.
std::vector< uint8_t > GetAifsns() const
Return the number of slots that make up an AIFS for each link.
void UpdateBackoffSlotsNow(uint32_t nSlots, Time backoffUpdateBound, uint8_t linkId)
Update backoff slots for the given link that nSlots has passed.
Time GetBackoffStart(uint8_t linkId) const
Return the time when the backoff procedure started on the given link.
void SetTxopLimits(const std::vector< Time > &txopLimits)
Set the TXOP limit for each link.
DroppedMpdu m_droppedMpduCallback
the dropped MPDU callback
void SwapLinks(std::map< uint8_t, uint8_t > links)
Swap the links based on the information included in the given map.
const UserDefinedAccessParams & GetUserAccessParams() const
void SetTxMiddle(const Ptr< MacTxMiddle > txMiddle)
Set MacTxMiddle this Txop is associated to.
std::vector< Time > GetTxopLimits() const
Return the TXOP limit for each link.
const std::map< uint8_t, std::unique_ptr< LinkEntity > > & GetLinks() const
static TypeId GetTypeId()
Get the type ID.
void SetAifsn(uint8_t aifsn)
Set the number of slots that make up an AIFS.
uint32_t GetCw(uint8_t linkId) const
Get the current value of the CW variable for the given link.
virtual void SetDroppedMpduCallback(DroppedMpdu callback)
UserDefinedAccessParams m_userAccessParams
user-defined DCF/EDCA access parameters
virtual void GenerateBackoff(uint8_t linkId)
Generate a new backoff for the given link now.
BackoffValueTracedCallback m_backoffTrace
backoff trace value
virtual void NotifyAccessRequested(uint8_t linkId)
Notify that access request has been received for the given link.
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
static constexpr bool CHECK_MEDIUM_BUSY
generation of backoff (also) depends on the busy/idle state of the medium
void StartBackoffNow(uint32_t nSlots, uint8_t linkId)
virtual void NotifyChannelAccessed(uint8_t linkId, Time txopDuration=Seconds(0))
Called by the FrameExchangeManager to notify that channel access has been granted on the given link f...
std::map< uint8_t, std::unique_ptr< LinkEntity > > m_links
ID-indexed map of LinkEntity objects.
void SetMinCws(const std::vector< uint32_t > &minCws)
Set the minimum contention window size for each link.
void RequestAccess(uint8_t linkId)
Request access to the ChannelAccessManager associated with the given link.
void SetMinCw(uint32_t minCw)
Set the minimum contention window size.
uint8_t GetAifsn() const
Return the number of slots that make up an AIFS.
uint32_t GetBackoffSlots(uint8_t linkId) const
Return the current number of backoff slots on the given link.
virtual void Queue(Ptr< Packet > packet, const WifiMacHeader &hdr)
virtual void NotifySleep(uint8_t linkId)
Notify that the given link switched to sleep mode.
static constexpr bool DONT_CHECK_MEDIUM_BUSY
generation of backoff is independent of the busy/idle state of the medium
uint32_t GetMaxCw() const
Return the maximum contention window size.
void DoInitialize() override
Initialize() implementation.
a unique identifier for an interface.
@ ATTR_GET
The attribute can be read.
@ ATTR_SET
The attribute can be written.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
@ OBSOLETE
Attribute or trace source is not used anymore; simulation fails.
Hold an unsigned integer type.
Ptr< WifiMacQueueScheduler > GetMacQueueScheduler() const
Get the wifi MAC queue scheduler.
Ptr< WifiPhy > GetWifiPhy(uint8_t linkId=SINGLE_LINK_OP_ID) const
const std::set< uint8_t > & GetLinkIds() const
Ptr< ChannelAccessManager > GetChannelAccessManager(uint8_t linkId=SINGLE_LINK_OP_ID) const
Get the Channel Access Manager associated with the given link.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
@ WIFI_MAC_DROP_FAILED_ENQUEUE
@ WIFI_MAC_DROP_EXPIRED_LIFETIME
@ AC_UNDEF
Total number of ACs.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Ptr< const AttributeChecker > MakeEnumChecker(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
void Shuffle(RND_ACCESS_ITER first, RND_ACCESS_ITER last, Ptr< UniformRandomVariable > rv)
Shuffle the elements in the range first to last.
@ LOG_DEBUG
Full voluminous logging to support debugging.
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Structure holding information specific to a single link.
class ns3::Txop::LinkEntity::@72 accessRequest
access request event, to be used by Txop::Queue() only
ChannelAccessStatus access
channel access status
uint32_t cw
the current contention window
uint32_t cwMax
the maximum contention window
Time txopLimit
the TXOP limit time
Time backoffStart
the backoffStart variable is used to keep track of the time at which a backoff was started or the tim...
uint32_t cwMin
the minimum contention window
uint32_t backoffSlots
the number of backoff slots
DCF/EDCA access parameters for all the links provided by users via this class' attributes or the corr...
std::vector< uint32_t > cwMins
the minimum contention window values for all the links
std::vector< uint8_t > aifsns
the AIFSN values for all the links
std::vector< uint32_t > cwMaxs
the maximum contention window values for all the links
std::vector< Time > txopLimits
TXOP limit values for all the links.