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>();
163std::unique_ptr<Txop::LinkEntity>
166 return std::make_unique<LinkEntity>();
209 m_queue->TraceConnectWithoutContext(
"DropBeforeEnqueue",
211 m_queue->TraceConnectWithoutContext(
"Expired",
232 for (std::size_t linkId = 0; linkId < minCws.size(); linkId++)
243 bool changed = (link.cwMin != minCw);
261 for (std::size_t linkId = 0; linkId < maxCws.size(); linkId++)
272 bool changed = (link.cwMax != maxCw);
301 link.cw = std::min(2 * (link.cw + 1) - 1,
GetMaxCw(linkId));
303 link.cw = std::max(link.cw,
GetMinCw(linkId));
325 link.backoffSlots -= nSlots;
326 link.backoffStart = backoffUpdateBound;
327 NS_LOG_DEBUG(
"update slots=" << nSlots <<
" slots, backoff=" << link.backoffSlots);
336 if (link.backoffSlots != 0)
338 NS_LOG_DEBUG(
"reset backoff from " << link.backoffSlots <<
" to " << nSlots <<
" slots");
344 link.backoffSlots = nSlots;
358 for (std::size_t linkId = 0; linkId < aifsns.size(); linkId++)
381 "The size of the given vector (" << txopLimits.size()
382 <<
") does not match the number of links ("
384 for (std::size_t linkId = 0; linkId < txopLimits.size(); linkId++)
395 "The TXOP limit must be expressed in multiple of 32 microseconds!");
408 std::vector<uint32_t> ret;
409 for (std::size_t linkId = 0; linkId <
m_links.size(); linkId++)
431 std::vector<uint32_t> ret;
432 for (std::size_t linkId = 0; linkId <
m_links.size(); linkId++)
454 std::vector<uint8_t> ret;
455 for (std::size_t linkId = 0; linkId <
m_links.size(); linkId++)
477 std::vector<Time> ret;
478 for (std::size_t linkId = 0; linkId <
m_links.size(); linkId++)
494 m_queue->WipeAllExpiredMpdus();
495 bool ret =
static_cast<bool>(
m_queue->Peek(linkId));
506 packet->RemovePacketTag(priorityTag);
507 Queue(Create<WifiMpdu>(packet, hdr));
515 for (
const auto linkId : linkIds)
523 for (
const auto linkId : linkIds)
551 for (std::size_t linkId = 0; linkId <
m_links.size(); linkId++)
633 for (std::size_t linkId = 0; linkId <
m_links.size(); linkId++)
A container for one type of attribute.
auto Bind(BoundArgs &&... bargs)
Bind a variable number of arguments.
void RequestAccess(Ptr< Txop > txop)
bool NeedBackoffUponAccess(Ptr< Txop > txop)
Determine if a new backoff needs to be generated when a packet is queued for transmission.
A base class which provides memory management and object aggregation.
Hold objects of type Ptr<T>.
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.
virtual void StartAccessIfNeeded(uint8_t linkId)
Request access from Txop on the given link if needed.
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
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.
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 SetTxMiddle(const Ptr< MacTxMiddle > txMiddle)
Set MacTxMiddle this Txop is associated to.
std::vector< std::unique_ptr< LinkEntity > > m_links
vector of LinkEntity objects
std::vector< Time > GetTxopLimits() const
Return the TXOP limit for each link.
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
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...
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.
uint32_t GetMaxCw() const
Return the maximum contention window size.
uint8_t GetNLinks() const
Get the number of links.
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.
uint8_t GetNLinks() const
Get the number of links (can be greater than 1 for 11be devices only).
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.
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