30#include "ns3/attribute-container.h"
32#include "ns3/pointer.h"
33#include "ns3/simulator.h"
34#include "ns3/socket.h"
39#undef NS_LOG_APPEND_CONTEXT
40#define NS_LOG_APPEND_CONTEXT WIFI_TXOP_NS_LOG_APPEND_CONTEXT
56 .AddConstructor<
Txop>()
57 .AddAttribute(
"MinCw",
58 "The minimum value of the contention window (just for the first link, "
59 "in case of 11be multi-link devices).",
64 MakeUintegerChecker<uint32_t>())
67 "The minimum values of the contention window for all the links",
71 MakeAttributeContainerChecker<UintegerValue>(MakeUintegerChecker<uint32_t>()))
72 .AddAttribute(
"MaxCw",
73 "The maximum value of the contention window (just for the first link, "
74 "in case of 11be multi-link devices).",
79 MakeUintegerChecker<uint32_t>())
82 "The maximum values of the contention window for all the links",
86 MakeAttributeContainerChecker<UintegerValue>(MakeUintegerChecker<uint32_t>()))
89 "The AIFSN: the default value conforms to non-QOS (just for the first link, "
90 "in case of 11be multi-link devices).",
95 MakeUintegerChecker<uint8_t>())
98 "The values of AIFSN for all the links",
102 MakeAttributeContainerChecker<UintegerValue>(MakeUintegerChecker<uint8_t>()))
103 .AddAttribute(
"TxopLimit",
104 "The TXOP limit: the default value conforms to non-QoS "
105 "(just for the first link, in case of 11be multi-link devices).",
111 .AddAttribute(
"TxopLimits",
112 "The values of TXOP limit for all the links",
118 .AddAttribute(
"Queue",
119 "The WifiMacQueue object",
122 MakePointerChecker<WifiMacQueue>())
123 .AddTraceSource(
"BackoffTrace",
124 "Trace source for backoff values",
126 "ns3::Txop::BackoffValueTracedCallback")
127 .AddTraceSource(
"CwTrace",
128 "Trace source for contention window values",
130 "ns3::Txop::CwValueTracedCallback");
162std::unique_ptr<Txop::LinkEntity>
165 return std::make_unique<LinkEntity>();
171 auto it =
m_links.find(linkId);
177const std::map<uint8_t, std::unique_ptr<Txop::LinkEntity>>&
190 for (
const auto& [from, to] : links)
192 auto nh = tmp.extract(from);
223 m_queue->TraceConnectWithoutContext(
"DropBeforeEnqueue",
225 m_queue->TraceConnectWithoutContext(
"Expired",
246 for (
const auto& [
id, link] :
m_links)
257 bool changed = (link.cwMin != minCw);
276 for (
const auto& [
id, link] :
m_links)
287 bool changed = (link.cwMax != maxCw);
316 link.cw = std::min(2 * (link.cw + 1) - 1,
GetMaxCw(linkId));
318 link.cw = std::max(link.cw,
GetMinCw(linkId));
340 link.backoffSlots -= nSlots;
341 link.backoffStart = backoffUpdateBound;
342 NS_LOG_DEBUG(
"update slots=" << nSlots <<
" slots, backoff=" << link.backoffSlots);
351 if (link.backoffSlots != 0)
353 NS_LOG_DEBUG(
"reset backoff from " << link.backoffSlots <<
" to " << nSlots <<
" slots");
359 link.backoffSlots = nSlots;
374 for (
const auto& [
id, link] :
m_links)
397 "The size of the given vector (" << txopLimits.size()
398 <<
") does not match the number of links ("
401 for (
const auto& [
id, link] :
m_links)
412 "The TXOP limit must be expressed in multiple of 32 microseconds!");
425 std::vector<uint32_t> ret;
427 for (
const auto& [
id, link] :
m_links)
429 ret.push_back(link->cwMin);
449 std::vector<uint32_t> ret;
451 for (
const auto& [
id, link] :
m_links)
453 ret.push_back(link->cwMax);
473 std::vector<uint8_t> ret;
475 for (
const auto& [
id, link] :
m_links)
477 ret.push_back(link->aifsn);
497 std::vector<Time> ret;
499 for (
const auto& [
id, link] :
m_links)
501 ret.push_back(link->txopLimit);
515 m_queue->WipeAllExpiredMpdus();
516 bool ret =
static_cast<bool>(
m_queue->Peek(linkId));
527 packet->RemovePacketTag(priorityTag);
528 Queue(Create<WifiMpdu>(packet, hdr));
541 {WifiQueueBlockedReason::USING_OTHER_EMLSR_LINK,
542 WifiQueueBlockedReason::WAITING_EMLSR_TRANSITION_DELAY});
545 for (
auto it = linkIds.begin(); it != linkIds.end();)
549 it = linkIds.erase(it);
559 std::map<uint8_t, bool> hasFramesToTransmit;
560 for (
const auto linkId : linkIds)
567 std::vector<uint8_t> shuffledLinkIds(linkIds.cbegin(), linkIds.cend());
572 std::stringstream ss;
573 std::copy(shuffledLinkIds.cbegin(),
574 shuffledLinkIds.cend(),
575 std::ostream_iterator<uint16_t>(ss,
" "));
576 NS_LOG_DEBUG(
"Request channel access on link IDs: " << ss.str());
579 for (
const auto linkId : shuffledLinkIds)
588 hasFramesToTransmit.at(linkId),
604 NS_LOG_FUNCTION(
this << linkId << hadFramesToTransmit << checkMediumBusy);
614 NS_LOG_DEBUG(
"Channel access already requested or granted on link " << +linkId);
620 NS_LOG_DEBUG(
"No frames to transmit on link " << +linkId);
638 for (
const auto& [
id, link] :
m_links)
721 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)
bool IsRunning() 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.
int64_t GetMicroSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
AttributeValue implementation for Time.
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.
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.
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.
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 SetMaxCws(std::vector< uint32_t > maxCws)
Set the maximum contention window size for each 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.
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.
void SetMinCws(std::vector< uint32_t > minCws)
Set the minimum contention window size for each link.
virtual void SetDroppedMpduCallback(DroppedMpdu callback)
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.
void SetAifsns(std::vector< uint8_t > aifsns)
Set the number of slots that make up an AIFS for each 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 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.
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.
This queue implements the timeout procedure described in (Section 9.19.2.6 "Retransmit procedures" pa...
#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)
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
#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 ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#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.
@ WIFI_MAC_DROP_FAILED_ENQUEUE
@ WIFI_MAC_DROP_EXPIRED_LIFETIME
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ LOG_DEBUG
Full voluminous logging to support debugging.
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