22 #include "ns3/pointer.h"
23 #include "ns3/simulator.h"
24 #include "ns3/random-variable-stream.h"
25 #include "ns3/socket.h"
33 #undef NS_LOG_APPEND_CONTEXT
34 #define NS_LOG_APPEND_CONTEXT if (m_mac != 0) { std::clog << "[mac=" << m_mac->GetAddress () << "] "; }
47 .SetGroupName (
"Wifi")
48 .AddConstructor<
Txop> ()
49 .AddAttribute (
"MinCw",
"The minimum value of the contention window.",
53 MakeUintegerChecker<uint32_t> ())
54 .AddAttribute (
"MaxCw",
"The maximum value of the contention window.",
58 MakeUintegerChecker<uint32_t> ())
59 .AddAttribute (
"Aifsn",
"The AIFSN: the default value conforms to non-QOS.",
63 MakeUintegerChecker<uint8_t> ())
64 .AddAttribute (
"TxopLimit",
"The TXOP limit: the default value conforms to non-QoS.",
69 .AddAttribute (
"Queue",
"The WifiMacQueue object",
72 MakePointerChecker<WifiMacQueue> ())
73 .AddTraceSource (
"BackoffTrace",
74 "Trace source for backoff values",
76 "ns3::TracedCallback::Uint32Callback")
77 .AddTraceSource (
"CwTrace",
78 "Trace source for contention window values",
80 "ns3::TracedValueCallback::Uint32")
91 : m_channelAccessManager (0),
97 m_access (NOT_REQUESTED),
102 m_rng = CreateObject<UniformRandomVariable> ();
147 m_queue->TraceConnectWithoutContext (
"DropBeforeEnqueue",
149 m_queue->TraceConnectWithoutContext (
"Expired",
164 bool changed = (
m_cwMin != minCw);
176 bool changed = (
m_cwMax != maxCw);
288 bool ret = (!
m_queue->IsEmpty ());
304 m_queue->Enqueue (Create<WifiMacQueueItem> (packet, hdr));
Callback< R, T2, T3, T4, T5, T6, T7, T8, T9 > Bind(T a)
Bind the first arguments.
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 EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
static Time Now(void)
Return the current simulation virtual time.
indicates whether the socket has a priority set.
Simulation virtual time values and global simulation resolution.
int64_t GetMicroSeconds(void) 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
void DoInitialize(void) override
Initialize() implementation.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
virtual ChannelAccessStatus GetAccessStatus(void) const
void UpdateFailedCw(void)
Update the value of the CW variable to take into account a transmission failure.
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
virtual void NotifyChannelReleased(void)
Called by the FrameExchangeManager to notify the completion of the transmissions.
Ptr< UniformRandomVariable > m_rng
the random stream
uint32_t m_backoff
the current backoff
uint32_t GetCw(void) const
void SetMaxCw(uint32_t maxCw)
Set the maximum contention window size.
virtual void NotifySleep(void)
When sleep operation occurs, if there is a pending packet transmission, it will be reinserted to the ...
uint32_t m_cw
the current contention window
ChannelAccessStatus m_access
channel access status
TracedValue< uint32_t > m_cwTrace
CW trace value.
ChannelAccessStatus
Enumeration for channel access status.
Ptr< WifiMacQueue > GetWifiMacQueue() const
Return the packet queue associated with this Txop.
Time GetTxopLimit(void) const
Return the TXOP limit.
virtual void SetWifiMac(const Ptr< WifiMac > mac)
Set the wifi MAC this Txop is associated to.
TracedCallback< uint32_t > m_backoffTrace
backoff trace value
virtual void NotifyAccessRequested(void)
Notify that access request has been received.
uint32_t m_cwMin
the minimum contention window
Time m_backoffStart
the backoffStart variable is used to keep track of the time at which a backoff was started or the tim...
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
virtual void NotifyOn(void)
When on operation occurs, channel access will be started.
static TypeId GetTypeId(void)
Get the type ID.
virtual bool IsQosTxop() const
Check for QoS TXOP.
virtual void NotifyChannelAccessed(Time txopDuration=Seconds(0))
Called by the FrameExchangeManager to notify that channel access has been granted for the given amoun...
Time m_txopLimit
the TXOP limit time
DroppedMpdu m_droppedMpduCallback
the dropped MPDU callback
void SetTxMiddle(const Ptr< MacTxMiddle > txMiddle)
Set MacTxMiddle this Txop is associated to.
void SetAifsn(uint8_t aifsn)
Set the number of slots that make up an AIFS.
Ptr< ChannelAccessManager > m_channelAccessManager
the channel access manager
virtual void SetDroppedMpduCallback(DroppedMpdu callback)
void UpdateBackoffSlotsNow(uint32_t nSlots, Time backoffUpdateBound)
Update backoff slots that nSlots has passed.
void ResetCw(void)
Update the value of the CW variable to take into account a transmission success or a transmission abo...
uint32_t m_backoffSlots
the number of backoff slots
void RequestAccess(void)
Request access to the ChannelAccessManager.
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
Time GetBackoffStart(void) const
Return the time when the backoff procedure started.
virtual uint32_t GetMaxCw(void) const
Return the maximum contention window size.
uint32_t m_cwMax
the maximum contention window
virtual void NotifyWakeUp(void)
When wake up operation occurs, channel access will be restarted.
void StartBackoffNow(uint32_t nSlots)
virtual void NotifyOff(void)
When off operation occurs, the queue gets cleaned up.
void SetMinCw(uint32_t minCw)
Set the minimum contention window size.
uint32_t GetBackoffSlots(void) const
Return the current number of backoff slots.
void SetChannelAccessManager(const Ptr< ChannelAccessManager > manager)
Set ChannelAccessManager this Txop is associated to.
virtual void Queue(Ptr< Packet > packet, const WifiMacHeader &hdr)
virtual void GenerateBackoff(void)
Generate a new backoff now.
virtual bool HasFramesToTransmit(void)
Check if the Txop has frames to transmit.
virtual uint32_t GetMinCw(void) const
Return the minimum contention window size.
virtual uint8_t GetAifsn(void) const
Return the number of slots that make up an AIFS.
void DoDispose(void) override
Destructor implementation.
virtual void StartAccessIfNeeded(void)
Request access from Txop if needed.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
This queue implements the timeout procedure described in (Section 9.19.2.6 "Retransmit procedures" pa...
#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)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#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 Seconds(double value)
Construct a Time in the indicated unit.
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
@ WIFI_MAC_DROP_FAILED_ENQUEUE
@ WIFI_MAC_DROP_EXPIRED_LIFETIME