29 #include "ns3/attribute-container.h"
31 #include "ns3/pointer.h"
32 #include "ns3/random-variable-stream.h"
33 #include "ns3/simulator.h"
34 #include "ns3/socket.h"
36 #undef NS_LOG_APPEND_CONTEXT
37 #define NS_LOG_APPEND_CONTEXT \
40 std::clog << "[mac=" << m_mac->GetAddress() << "] "; \
57 .AddConstructor<
Txop>()
58 .AddAttribute(
"MinCw",
59 "The minimum value of the contention window (just for the first link, "
60 "in case of 11be multi-link devices).",
65 MakeUintegerChecker<uint32_t>())
68 "The minimum values of the contention window for all the links",
72 MakeAttributeContainerChecker<UintegerValue>(MakeUintegerChecker<uint32_t>()))
73 .AddAttribute(
"MaxCw",
74 "The maximum value of the contention window (just for the first link, "
75 "in case of 11be multi-link devices).",
80 MakeUintegerChecker<uint32_t>())
83 "The maximum values of the contention window for all the links",
87 MakeAttributeContainerChecker<UintegerValue>(MakeUintegerChecker<uint32_t>()))
90 "The AIFSN: the default value conforms to non-QOS (just for the first link, "
91 "in case of 11be multi-link devices).",
96 MakeUintegerChecker<uint8_t>())
99 "The values of AIFSN for all the links",
103 MakeAttributeContainerChecker<UintegerValue>(MakeUintegerChecker<uint8_t>()))
104 .AddAttribute(
"TxopLimit",
105 "The TXOP limit: the default value conforms to non-QoS "
106 "(just for the first link, in case of 11be multi-link devices).",
112 .AddAttribute(
"TxopLimits",
113 "The values of TXOP limit for all the links",
119 .AddAttribute(
"Queue",
120 "The WifiMacQueue object",
123 MakePointerChecker<WifiMacQueue>())
124 .AddTraceSource(
"BackoffTrace",
125 "Trace source for backoff values",
127 "ns3::Txop::BackoffValueTracedCallback")
128 .AddTraceSource(
"CwTrace",
129 "Trace source for contention window values",
131 "ns3::Txop::CwValueTracedCallback");
144 m_rng = CreateObject<UniformRandomVariable>();
163 std::unique_ptr<Txop::LinkEntity>
166 return std::make_unique<LinkEntity>();
172 auto it =
m_links.find(linkId);
178 const std::map<uint8_t, std::unique_ptr<Txop::LinkEntity>>&
191 for (
const auto& [from, to] : links)
193 auto nh = tmp.extract(from);
224 m_queue->TraceConnectWithoutContext(
"DropBeforeEnqueue",
226 m_queue->TraceConnectWithoutContext(
"Expired",
258 bool changed = (
link.cwMin != minCw);
288 bool changed = (
link.cwMax != maxCw);
341 link.backoffSlots -= nSlots;
342 link.backoffStart = backoffUpdateBound;
343 NS_LOG_DEBUG(
"update slots=" << nSlots <<
" slots, backoff=" <<
link.backoffSlots);
352 if (
link.backoffSlots != 0)
354 NS_LOG_DEBUG(
"reset backoff from " <<
link.backoffSlots <<
" to " << nSlots <<
" slots");
360 link.backoffSlots = nSlots;
398 "The size of the given vector (" << txopLimits.size()
399 <<
") does not match the number of links ("
413 "The TXOP limit must be expressed in multiple of 32 microseconds!");
423 std::vector<uint32_t>
426 std::vector<uint32_t> ret;
430 ret.push_back(
link->cwMin);
447 std::vector<uint32_t>
450 std::vector<uint32_t> ret;
454 ret.push_back(
link->cwMax);
474 std::vector<uint8_t> ret;
478 ret.push_back(
link->aifsn);
498 std::vector<Time> ret;
502 ret.push_back(
link->txopLimit);
516 m_queue->WipeAllExpiredMpdus();
517 bool ret =
static_cast<bool>(
m_queue->Peek(linkId));
529 Queue(Create<WifiMpdu>(packet, hdr));
537 std::map<uint8_t, bool> hasFramesToTransmit;
541 for (
const auto linkId : linkIds)
546 for (
const auto linkId : linkIds)
557 hasFramesToTransmit.at(linkId),
574 NS_LOG_FUNCTION(
this << +linkId << hadFramesToTransmit << checkMediumBusy);
578 NS_LOG_DEBUG(
"No need to request channel access on link " << +linkId);
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.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Hold objects of type Ptr<T>.
Smart pointer class similar to boost::intrusive_ptr.
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.
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.
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.
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...
#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
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Structure holding information specific to a single link.
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