22 #include "ns3/pointer.h" 23 #include "ns3/simulator.h" 24 #include "ns3/random-variable-stream.h" 25 #include "ns3/socket.h" 34 #undef NS_LOG_APPEND_CONTEXT 35 #define NS_LOG_APPEND_CONTEXT if (m_low != 0) { std::clog << "[mac=" << m_low->GetAddress () << "] "; } 48 .SetGroupName (
"Wifi")
49 .AddConstructor<
Txop> ()
50 .AddAttribute (
"MinCw",
"The minimum value of the contention window.",
54 MakeUintegerChecker<uint32_t> ())
55 .AddAttribute (
"MaxCw",
"The maximum value of the contention window.",
59 MakeUintegerChecker<uint32_t> ())
60 .AddAttribute (
"Aifsn",
"The AIFSN: the default value conforms to non-QOS.",
64 MakeUintegerChecker<uint8_t> ())
65 .AddAttribute (
"TxopLimit",
"The TXOP limit: the default value conforms to non-QoS.",
70 .AddAttribute (
"Queue",
"The WifiMacQueue object",
73 MakePointerChecker<WifiMacQueue> ())
74 .AddTraceSource (
"BackoffTrace",
75 "Trace source for backoff values",
77 "ns3::TracedCallback::Uint32Callback")
78 .AddTraceSource (
"CwTrace",
79 "Trace source for contention window values",
81 "ns3::TracedValueCallback::Uint32")
87 : m_channelAccessManager (0),
92 m_accessRequested (false),
98 m_queue = CreateObject<WifiMacQueue> ();
99 m_rng = CreateObject<UniformRandomVariable> ();
189 bool changed = (
m_cwMin != minCw);
202 bool changed = (
m_cwMax != maxCw);
327 m_queue->Enqueue (Create<WifiMacQueueItem> (packet, hdr));
346 && !
m_low->IsCfPeriod ())
359 && !
m_low->IsCfPeriod ())
531 GetLow ()->StartTransmission (Create<WifiMacQueueItem> (fragment, hdr),
770 NS_LOG_DEBUG (
"a transmission that did not require an ACK just finished");
869 NS_LOG_WARN (
"StartNext should not be called for non QoS!");
875 NS_LOG_WARN (
"GotBlockAck should not be called for non QoS!");
881 NS_LOG_WARN (
"MissedBlockAck should not be called for non QoS!");
887 NS_LOG_WARN (
"GetTxopRemaining should not be called for non QoS!");
894 NS_LOG_WARN (
"TerminateTxop should not be called for non QoS!");
TxFailed m_txFailedCallback
the transmit failed callback
Simulation virtual time values and global simulation resolution.
void SendCfFrame(WifiMacType frameType, Mac48Address addr)
Sends CF frame to STA with address addr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
TracedCallback< uint32_t > m_backoffTrace
backoff trace value
TracedValue< uint32_t > m_cwTrace
CW trace value.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Time m_txopLimit
the TXOP limit time
virtual void RestartAccessIfNeeded(void)
Restart access request if needed.
virtual void StartAccessIfNeeded(void)
Request access from Txop if needed.
uint8_t GetAifsn(void) const
Return the number of slots that make up an AIFS.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
void ReportFinalDataFailed(Mac48Address address, const WifiMacHeader *header, uint32_t packetSize)
Should be invoked after calling ReportDataFailed if NeedRetransmission returns false.
virtual void StartNextPacket(void)
Start transmission for the next packet if allowed by the TxopLimit.
virtual void EndTxNoAck(void)
Event handler when a transmission that does not require an Ack has completed.
uint32_t m_backoffSlots
the number of backoff slots
virtual bool HasFramesToTransmit(void)
Check if the Txop has frames to transmit.
virtual void StartNextFragment(void)
Start transmission for the next fragment.
uint32_t m_backoff
the current backoff
void SetChannelAccessManager(const Ptr< ChannelAccessManager > manager)
Set ChannelAccessManager this Txop is associated to.
Ptr< ChannelAccessManager > m_channelAccessManager
the channel access manager
virtual void NotifyAccessGranted(void)
Notify the Txop that access has been granted.
virtual void MissedAck(void)
Event handler when an Ack is missed.
void SetTxDroppedCallback(TxDropped callback)
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
virtual void DoInitialize(void)
Initialize() implementation.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
static const uint16_t WIFI_MAC_FCS_LENGTH
The length in octects of the IEEE 802.11 MAC FCS field.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time GetBackoffStart(void) const
Return the time when the backoff procedure started.
bool IsBusy(void) const
Check if the device is busy sending or receiving, or NAV or CCA busy.
void RequestAccess(Ptr< Txop > txop, bool isCfPeriod=false)
virtual void Cancel(void)
Cancel the transmission.
void UpdateFragmentationThreshold(void)
Typically called to update the fragmentation threshold at the start of a new transmission.
bool IsLastFragment(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, uint32_t fragmentNumber)
Ptr< UniformRandomVariable > m_rng
the random stream
void UpdateBackoffSlotsNow(uint32_t nSlots, Time backoffUpdateBound)
Update backoff slots that nSlots has passed.
bool CanStartNextPolling(void) const
Check if the next PCF transmission can fit in the remaining CFP duration.
virtual void GenerateBackoff(void)
Generate a new backoff now.
bool NeedBackoffUponAccess(Ptr< Txop > txop)
Determine if a new backoff needs to be generated when a packet is queued for transmission.
uint32_t GetMinCw(void) const
Return the minimum contention window size.
uint32_t m_cwMax
the maximum contention window
virtual void GotBlockAck(const CtrlBAckResponseHeader *blockAck, Mac48Address recipient, double rxSnr, double dataSnr, WifiTxVector dataTxVector)
Event handler when a BlockAck is received.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
virtual void NotifyOff(void)
When off operation occurs, the queue gets cleaned up.
void Add(Ptr< Txop > txop)
void UpdateFailedCw(void)
Update the value of the CW variable to take into account a transmission failure.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
AttributeValue implementation for Time.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
WifiMacType
Combination of valid MAC header type/subtype.
Hold an unsigned integer type.
void NextFragment(void)
Continue to the next fragment.
indicates whether the socket has a priority set.
static TypeId GetTypeId(void)
Get the type ID.
bool NeedRetransmission(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
virtual bool IsAccessRequested(void) const
virtual bool IsQosTxop() const
Check for QoS TXOP.
bool NeedRts(const WifiMacHeader &header, uint32_t size)
virtual uint32_t GetNextFragmentSize(void) const
Calculate the size of the next fragment.
uint32_t m_cwMin
the minimum contention window
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
uint32_t GetFragmentOffset(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, uint32_t fragmentNumber)
bool NeedRtsRetransmission(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Check if RTS should be re-transmitted if CTS was missed.
Ptr< MacLow > GetLow(void) const
Return the MacLow associated with this Txop.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void GotCfEnd(void)
Event handler when a CF-END frame is received.
uint32_t GetCw(void) const
Hold objects of type Ptr<T>.
virtual void NotifySleep(void)
When sleep operation occurs, if there is a pending packet transmission, it will be reinserted to the ...
void EnableAck(void)
Wait ACKTimeout for an Ack.
uint32_t GetMaxCw(void) const
Return the maximum contention window size.
virtual void MissedBlockAck(uint8_t nMpdus)
Event handler when a BlockAck timeout has occurred.
uint32_t GetFragmentSize(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, uint32_t fragmentNumber)
virtual void NotifyOn(void)
When on operation occurs, channel access will be started.
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
virtual void DoDispose(void)
Destructor implementation.
bool NeedDataRetransmission(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Check if Data should be re-transmitted if Ack was missed.
Ptr< const Packet > m_currentPacket
the current packet
void SetMacLow(const Ptr< MacLow > low)
Set MacLow associated with this Txop.
virtual bool NeedFragmentation(void) const
Check if the current packet should be fragmented.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
virtual Ptr< Packet > GetFragmentPacket(WifiMacHeader *hdr)
Get the next fragment from the packet with appropriate Wifi header for the fragment.
virtual void NotifyChannelSwitching(void)
When a channel switching occurs, enqueued packets are removed.
void DisableRts(void)
Do not send RTS and wait for CTS before sending data.
static Time Now(void)
Return the current simulation virtual time.
virtual void NotifyInternalCollision(void)
Notify the Txop that internal collision has occurred.
Ptr< MacLow > m_low
the MacLow
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
virtual bool IsLastFragment(void) const
Check if the current fragment is the last fragment.
void TxDroppedPacket(Ptr< const WifiMacQueueItem > item)
Pass the packet included in the wifi MAC queue item to the packet dropped callback.
uint32_t m_cw
the current contention window
void ReportDataFailed(Mac48Address address, const WifiMacHeader *header, uint32_t packetSize)
Should be invoked whenever the AckTimeout associated to a transmission attempt expires.
MacLowTransmissionParameters m_currentParams
current transmission parameters
void SetMinCw(uint32_t minCw)
Set the minimum contention window size.
void EnableRts(void)
Send a RTS, and wait CTSTimeout for a CTS.
void SetMaxCw(uint32_t maxCw)
Set the maximum contention window size.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
bool m_accessRequested
flag whether channel access is already requested
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
Time m_backoffStart
the backoffStart variable is used to keep track of the time at which a backoff was started or the tim...
virtual void GotAck(void)
Event handler when an Ack is received.
virtual void MissedCts(void)
Event handler when a CTS timeout has occurred.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
void SetTxMiddle(const Ptr< MacTxMiddle > txMiddle)
Set MacTxMiddle this Txop is associated to.
Time Seconds(double value)
Construct a Time in the indicated unit.
uint32_t GetBackoffSlots(void) const
Return the current number of backoff slots.
Ptr< WifiMacQueue > GetWifiMacQueue() const
Return the packet queue associated with this Txop.
virtual Time GetTxopRemaining(void) const
Return the remaining duration in the current TXOP.
void MissedCfPollResponse(bool expectedCfAck)
Event handler when a response to a CF-POLL frame is missed.
bool NeedFragmentation(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
void EnableNextData(uint32_t size)
TxOk m_txOkCallback
the transmit OK callback
void DisableNextData(void)
Do not attempt to send data burst after current transmission.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
virtual void SetWifiRemoteStationManager(const Ptr< WifiRemoteStationManager > remoteManager)
Set WifiRemoteStationsManager this Txop is associated to.
uint8_t m_fragmentNumber
the fragment number
void SetAifsn(uint8_t aifsn)
Set the number of slots that make up an AIFS.
A base class which provides memory management and object aggregation.
virtual void NotifyAccessRequested(void)
Notify that access request has been received.
WifiMacHeader m_currentHdr
the current header
virtual void TerminateTxop(void)
Update backoff and restart access if needed.
void SetTxFailedCallback(TxFailed callback)
bool IsNull(void) const
Check for null implementation.
Ptr< WifiRemoteStationManager > m_stationManager
the wifi remote station manager
virtual uint32_t GetFragmentOffset(void) const
Calculate the offset for the current fragment.
void SetTxOkCallback(TxOk callback)
void DisableAck(void)
Do not wait for Ack after data transmission.
virtual void Queue(Ptr< Packet > packet, const WifiMacHeader &hdr)
virtual uint32_t GetFragmentSize(void) const
Calculate the size of the current fragment.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
void ResetCw(void)
Update the value of the CW variable to take into account a transmission success or a transmission abo...
a unique identifier for an interface.
void ReportFinalRtsFailed(Mac48Address address, const WifiMacHeader *header)
Should be invoked after calling ReportRtsFailed if NeedRetransmission returns false.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
void StartBackoffNow(uint32_t nSlots)
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
virtual void NotifyWakeUp(void)
When wake up operation occurs, channel access will be restarted.
TxDropped m_txDroppedCallback
the packet dropped callback
Handle packet fragmentation and retransmissions for data and management frames.
Time GetTxopLimit(void) const
Return the TXOP limit.