28#include "ns3/simulator.h"
30#undef NS_LOG_APPEND_CONTEXT
31#define NS_LOG_APPEND_CONTEXT std::clog << "[link=" << +m_linkId << "] "
80 const std::vector<Time>& per20MhzDurations)
override
123 m_lastRxReceivedOk(
true),
128 m_phyListener(
nullptr),
132 InitLastBusyStructs();
315 txop->GetBackoffSlots(
m_linkId) == 0)
355 if (txop->IsQosTxop() && txop->GetBackoffStart(
m_linkId) > accessGrantStart)
360 Time diff = txop->GetBackoffStart(
m_linkId) - accessGrantStart;
362 txop->UpdateBackoffSlotsNow(0, accessGrantStart + (nIntSlots *
GetSlot()),
m_linkId);
367 txop->NotifyAccessRequested(
m_linkId);
378 for (Txops::iterator i =
m_txops.begin(); i !=
m_txops.end(); k++)
382 (!txop->IsQosTxop() || !StaticCast<QosTxop>(txop)->EdcaDisabled(
m_linkId)) &&
389 NS_LOG_DEBUG(
"dcf " << k <<
" needs access. backoff expired. access granted. slots="
390 << txop->GetBackoffSlots(
m_linkId));
393 std::vector<Ptr<Txop>> internalCollisionTxops;
394 for (Txops::iterator j = i; j !=
m_txops.end(); j++, k++)
401 "dcf " << k <<
" needs access. backoff expired. internal collision. slots="
402 << otherTxop->GetBackoffSlots(
m_linkId));
408 internalCollisionTxops.push_back(otherTxop);
433 for (
auto& collidingTxop : internalCollisionTxops)
435 m_feManager->NotifyInternalCollision(collidingTxop);
444 k = std::distance(
m_txops.begin(), i);
478 Time accessGrantedStart;
481 accessGrantedStart = std::max({rxAccessStart,
484 ackTimeoutAccessStart,
485 ctsTimeoutAccessStart,
486 switchingAccessStart});
490 accessGrantedStart = std::max({rxAccessStart,
494 ackTimeoutAccessStart,
495 ctsTimeoutAccessStart,
496 switchingAccessStart});
498 NS_LOG_INFO(
"access grant start=" << accessGrantedStart <<
", rx access start=" << rxAccessStart
499 <<
", busy access start=" << busyAccessStart
500 <<
", tx access start=" << txAccessStart
501 <<
", nav access start=" << navAccessStart);
502 return accessGrantedStart;
509 Time mostRecentEvent =
510 std::max({txop->GetBackoffStart(
m_linkId),
514 return mostRecentEvent;
549 if (txop->IsQosTxop())
554 NS_LOG_DEBUG(
"dcf " << k <<
" dec backoff slots=" << n);
555 Time backoffUpdateBound = backoffStart + (n *
GetSlot());
556 txop->UpdateBackoffSlotsNow(n, backoffUpdateBound,
m_linkId);
570 bool accessTimeoutNeeded =
false;
579 accessTimeoutNeeded =
true;
580 expectedBackoffEnd = std::min(expectedBackoffEnd, tmp);
584 NS_LOG_DEBUG(
"Access timeout needed: " << accessTimeoutNeeded);
585 if (accessTimeoutNeeded)
587 NS_LOG_DEBUG(
"expected backoff end=" << expectedBackoffEnd);
624 if (lastIdle.second.start <= end - interval && lastIdle.second.end >= end)
627 width = (width == 0) ? 20 : (2 * width);
645 "Index 0 only can be specified if the channel width is less than 40 MHz");
649 for (
const auto index : indices)
654 NS_LOG_DEBUG(
"20 MHz channel with index " << +index <<
" is busy");
668 NS_LOG_DEBUG(
"Backoff will resume at time " << resume <<
" with "
669 << qosTxop->GetBackoffSlots(
m_linkId)
670 <<
" remaining slot(s)");
671 qosTxop->UpdateBackoffSlotsNow(0, resume,
m_linkId);
731 const std::vector<Time>& per20MhzDurations)
739 lastBusyEndIt->second = now + duration;
741 "Size of received vector (" << per20MhzDurations.size()
742 <<
") differs from the expected size ("
744 for (std::size_t chIdx = 0; chIdx < per20MhzDurations.size(); ++chIdx)
746 if (per20MhzDurations[chIdx].IsStrictlyPositive())
784 if (remainingSlots > 0)
786 txop->UpdateBackoffSlotsNow(remainingSlots, now,
m_linkId);
841 if (remainingSlots > 0)
860 if (remainingSlots > 0)
934 if (idleStart >= now)
942 if (busyEnd.second < now)
944 auto lastIdleIt =
m_lastIdle.find(busyEnd.first);
946 lastIdleIt->second = {std::max(idleStart, busyEnd.second), now};
948 << lastIdleIt->second.end.As(
Time::S)
949 <<
") on channel " << lastIdleIt->first);
Manage a set of ns3::Txop.
uint16_t GetLargestIdlePrimaryChannel(Time interval, Time end)
Return the width of the largest primary channel that has been idle for the given time interval before...
std::vector< Time > m_lastPer20MHzBusyEnd
the last busy end time per 20 MHz channel (HE stations and channel width > 20 MHz only)
bool IsBusy() const
Check if the device is busy sending or receiving, or NAV or CCA busy.
void DoRestartAccessTimeoutIfNeeded()
void NotifyRxEndErrorNow()
Notify the Txop that a packet reception was just completed unsuccessfuly.
bool m_off
flag whether it is in off state
void NotifyRxStartNow(Time duration)
Time GetBackoffEndFor(Ptr< Txop > txop)
Return the time when the backoff procedure ended (or will ended) for the given Txop.
void NotifyWakeupNow()
Notify the Txop that the device has been resumed from sleep mode.
bool m_lastRxReceivedOk
the last receive OK
std::map< WifiChannelListType, Timespan > m_lastIdle
the last idle start and end time for each channel type
Ptr< WifiPhy > m_phy
pointer to the PHY
void NotifyAckTimeoutResetNow()
Notify that ack timer has reset.
void NotifyTxStartNow(Time duration)
void NotifyRxEndOkNow()
Notify the Txop that a packet reception was just completed successfully.
virtual Time GetEifsNoDifs() const
Return the EIFS duration minus a DIFS.
uint8_t m_linkId
the ID of the link this object is associated with
void NotifyCcaBusyStartNow(Time duration, WifiChannelListType channelType, const std::vector< Time > &per20MhzDurations)
Time m_lastAckTimeoutEnd
the last Ack timeout end time
virtual Time GetSlot() const
Return the slot duration for this PHY.
void NotifyAckTimeoutStartNow(Time duration)
Notify that ack timer has started for the given duration.
void AccessTimeout()
Called when access timeout should occur (e.g.
void UpdateBackoff()
Update backoff slots for all Txops.
bool m_sleeping
flag whether it is in sleeping state
void SetLinkId(uint8_t linkId)
Set the ID of the link this Channel Access Manager is associated with.
void SetupFrameExchangeManager(Ptr< FrameExchangeManager > feManager)
Set up the Frame Exchange Manager.
void NotifyCtsTimeoutStartNow(Time duration)
Notify that CTS timer has started for the given duration.
void RequestAccess(Ptr< Txop > txop)
Time m_lastSwitchingEnd
the last switching end time
Timespan m_lastRx
the last receive start and end time
std::map< WifiChannelListType, Time > m_lastBusyEnd
the last busy end time for each channel type
void RemovePhyListener(Ptr< WifiPhy > phy)
Remove current registered listener for PHY events.
Time m_lastTxEnd
the last transmit end time
void SetupPhyListener(Ptr< WifiPhy > phy)
Set up listener for PHY events.
Time m_lastCtsTimeoutEnd
the last CTS timeout end time
void DoDispose() override
Destructor implementation.
void NotifySleepNow()
Notify the Txop that the device has been put in sleep mode.
Ptr< FrameExchangeManager > m_feManager
pointer to the Frame Exchange Manager
PhyListener * m_phyListener
the PHY listener
void UpdateLastIdlePeriod()
This method determines whether the medium has been idle during a period (of non-null duration) immedi...
void NotifySwitchingStartNow(Time duration)
void DisableEdcaFor(Ptr< Txop > qosTxop, Time duration)
void DoInitialize() override
Initialize() implementation.
Txops m_txops
the vector of managed Txops
bool GetPer20MHzBusy(const std::set< uint8_t > &indices) const
void DoGrantDcfAccess()
Grant access to Txop using DCF/EDCF contention rules.
Time m_lastNavEnd
the last NAV end time
~ChannelAccessManager() override
void NotifyCtsTimeoutResetNow()
Notify that CTS timer has reset.
void NotifyOffNow()
Notify the Txop that the device has been put in off mode.
void NotifyNavResetNow(Time duration)
Time GetAccessGrantStart(bool ignoreNav=false) const
Access will never be granted to the medium before the time returned by this method.
bool NeedBackoffUponAccess(Ptr< Txop > txop)
Determine if a new backoff needs to be generated when a packet is queued for transmission.
void Add(Ptr< Txop > txop)
void NotifyOnNow()
Notify the Txop that the device has been resumed from off mode.
Time GetBackoffStartFor(Ptr< Txop > txop)
Return the time when the backoff procedure started for the given Txop.
virtual Time GetSifs() const
Return the Short Interframe Space (SIFS) for this PHY.
void NotifyNavStartNow(Time duration)
EventId m_accessTimeout
the access timeout ID
void InitLastBusyStructs()
Initialize the structures holding busy end times per channel type (primary, secondary,...
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
bool IsExpired() const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
bool IsRunning() const
This method is syntactic sugar for !IsExpired().
PhyListener(ns3::ChannelAccessManager *cam)
Create a PhyListener for the given ChannelAccessManager.
void NotifyOff() override
Notify listeners that we went to switch off.
void NotifySleep() override
Notify listeners that we went to sleep.
ns3::ChannelAccessManager * m_cam
ChannelAccessManager to forward events to.
void NotifyTxStart(Time duration, double txPowerDbm) override
void NotifyRxStart(Time duration) override
void NotifyRxEndError() override
We have received the last bit of a packet for which NotifyRxStart was invoked first and,...
void NotifyOn() override
Notify listeners that we went to switch on.
void NotifySwitchingStart(Time duration) override
void NotifyRxEndOk() override
We have received the last bit of a packet for which NotifyRxStart was invoked first and,...
void NotifyWakeup() override
Notify listeners that we woke up.
void NotifyCcaBusyStart(Time duration, WifiChannelListType channelType, const std::vector< Time > &per20MhzDurations) override
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now()
Return the current simulation virtual time.
static Time GetMaximumSimulationTime()
Get the maximum representable simulation time.
static Time GetDelayLeft(const EventId &id)
Get the remaining time until this event will execute.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Time GetSlot() const
Return the slot duration for this PHY.
uint16_t GetChannelWidth() const
Time GetSifs() const
Return the Short Interframe Space (SIFS) for this PHY.
WifiPhyBand GetPhyBand() const
Get the configured Wi-Fi band.
Time GetPifs() const
Return the PCF Interframe Space (PIFS) for this PHY.
WifiStandard GetStandard() const
Get the configured Wi-Fi standard.
void NotifyChannelAccessRequested()
Notify the PHY that an access to the channel was requested.
Time GetAckTxTime() const
Return the estimated Ack TX time for this PHY.
const WifiPhyOperatingChannel & GetOperatingChannel() const
Get a const reference to the operating channel.
receive notifications about PHY events.
bool IsOfdm() const
Return whether the operating channel is an OFDM channel.
#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_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 ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Seconds(double value)
Construct a Time in the indicated unit.
WifiChannelListType
Enumeration of the possible channel-list parameter elements defined in Table 8-5 of IEEE 802....
@ WIFI_PHY_BAND_2_4GHZ
The 2.4 GHz band.
@ WIFI_CHANLIST_SECONDARY40
@ WIFI_CHANLIST_SECONDARY
@ WIFI_CHANLIST_SECONDARY80
Every class exported by the ns3 library is enclosed in the ns3 namespace.