22 #include "ns3/simulator.h" 108 m_lastRxReceivedOk (true),
170 low->RegisterChannelAccessManager (
this);
212 return *std::max_element (
list.begin (),
list.end ());
326 uint32_t nIntSlots = (diff /
m_slot).GetHigh () + 1;
348 for (Txops::iterator i =
m_txops.begin (); i !=
m_txops.end (); k++)
361 std::vector<Ptr<Txop> > internalCollisionTxops;
362 for (Txops::iterator j = i; j !=
m_txops.end (); j++, k++)
368 NS_LOG_DEBUG (
"dcf " << k <<
" needs access. backoff expired. internal collision. slots=" <<
375 internalCollisionTxops.push_back (otherTxop);
387 for (
auto collidingTxop : internalCollisionTxops)
389 collidingTxop->NotifyInternalCollision ();
422 Time accessGrantedStart;
425 accessGrantedStart =
MostRecent ({rxAccessStart,
428 ackTimeoutAccessStart,
429 ctsTimeoutAccessStart,
430 switchingAccessStart}
435 accessGrantedStart =
MostRecent ({rxAccessStart,
439 ackTimeoutAccessStart,
440 ctsTimeoutAccessStart,
441 switchingAccessStart}
444 NS_LOG_INFO (
"access grant start=" << accessGrantedStart <<
445 ", rx access start=" << rxAccessStart <<
446 ", busy access start=" << busyAccessStart <<
447 ", tx access start=" << txAccessStart <<
448 ", nav access start=" << navAccessStart);
449 return accessGrantedStart;
460 return mostRecentEvent;
495 if (txop->IsQosTxop ())
499 uint32_t
n =
std::min (nIntSlots, txop->GetBackoffSlots ());
501 Time backoffUpdateBound = backoffStart + (
n *
m_slot);
502 txop->UpdateBackoffSlotsNow (
n, backoffUpdateBound);
516 bool accessTimeoutNeeded =
false;
520 if (txop->IsAccessRequested ())
525 accessTimeoutNeeded =
true;
526 expectedBackoffEnd =
std::min (expectedBackoffEnd, tmp);
530 NS_LOG_DEBUG (
"Access timeout needed: " << accessTimeoutNeeded);
531 if (accessTimeoutNeeded)
533 NS_LOG_DEBUG (
"expected backoff end=" << expectedBackoffEnd);
655 uint32_t remainingSlots = txop->GetBackoffSlots ();
656 if (remainingSlots > 0)
658 txop->UpdateBackoffSlotsNow (remainingSlots, now);
659 NS_ASSERT (txop->GetBackoffSlots () == 0);
662 txop->m_accessRequested =
false;
663 txop->NotifyChannelSwitching ();
685 txop->NotifySleep ();
714 uint32_t remainingSlots = txop->GetBackoffSlots ();
715 if (remainingSlots > 0)
718 NS_ASSERT (txop->GetBackoffSlots () == 0);
721 txop->m_accessRequested =
false;
722 txop->NotifyWakeUp ();
733 uint32_t remainingSlots = txop->GetBackoffSlots ();
734 if (remainingSlots > 0)
737 NS_ASSERT (txop->GetBackoffSlots () == 0);
740 txop->m_accessRequested =
false;
771 if (newNavEnd > lastNavEnd)
static Time GetDelayLeft(const EventId &id)
Get the remaining time until this event will execute.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Simulation virtual time values and global simulation resolution.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Time m_eifsNoDifs
EIFS no DIFS time.
void UpdateBackoff(void)
Update backoff slots for all Txops.
bool m_off
flag whether it is in off state
uint8_t GetAifsn(void) const
Return the number of slots that make up an AIFS.
void NotifyMaybeCcaBusyStart(Time duration)
Time m_lastRxDuration
the last receive duration time
Time m_lastCtsTimeoutEnd
the last CTS timeout end time
void NotifySwitchingStart(Time duration)
virtual bool HasFramesToTransmit(void)
Check if the Txop has frames to transmit.
void NotifyOnNow(void)
Notify the Txop that the device has been resumed from off mode.
PhyListener(ns3::ChannelAccessManager *cam)
Create a PhyListener for the given ChannelAccessManager.
virtual void NotifyAccessGranted(void)
Notify the Txop that access has been granted.
virtual ~ChannelAccessManager()
void SetupPhyListener(Ptr< WifiPhy > phy)
Set up listener for PHY events.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void NotifyOff(void)
Notify listeners that we went to switch off.
Time GetBackoffStart(void) const
Return the time when the backoff procedure started.
void NotifyMaybeCcaBusyStartNow(Time duration)
Time m_lastBusyStart
the last busy start time
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)
EventId m_accessTimeout
the access timeout ID
Time MostRecent(std::initializer_list< Time > list) const
Return the most recent time.
void RemovePhyListener(Ptr< WifiPhy > phy)
Remove current registered listener for PHY events.
Time GetBackoffStartFor(Ptr< Txop > txop)
Return the time when the backoff procedure started for the given Txop.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Manage a set of ns3::TxopHandle a set of independent ns3::Txop, each of which represents a single DCF...
bool m_sleeping
flag whether it is in sleeping state
Time m_lastTxDuration
the last transmit duration time
void UpdateBackoffSlotsNow(uint32_t nSlots, Time backoffUpdateBound)
Update backoff slots that nSlots has passed.
TimeWithUnit As(const enum Unit unit) const
Attach a unit to a Time, to facilitate output in a specific unit.
bool NeedBackoffUponAccess(Ptr< Txop > txop)
Determine if a new backoff needs to be generated when a packet is queued for transmission.
void NotifyRxStartNow(Time duration)
void NotifyRxEndError(void)
We have received the last bit of a packet for which NotifyRxStart was invoked first and...
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
ns3::ChannelAccessManager * m_cam
ChannelAccessManager to forward events to.
Time m_lastRxStart
the last receive start time
Time m_lastBusyDuration
the last busy duration time
void NotifyRxEndErrorNow(void)
Notify the Txop that a packet reception was just completed unsuccessfully.
Time m_lastNavDuration
the last NAV duration time
void Add(Ptr< Txop > txop)
void NotifyCtsTimeoutStartNow(Time duration)
Notify that CTS timer has started for the given duration.
Ptr< WifiPhy > m_phy
pointer to the PHY
Time GetEifsNoDifs(void) const
void SetEifsNoDifs(Time eifsNoDifs)
receive notifications about PHY events.
void NotifyOffNow(void)
Notify the Txop that the device has been put in off mode.
void NotifyChannelAccessRequested(void)
Notify the PHY that an access to the channel was requested.
Time m_lastSwitchingStart
the last switching start time
void NotifyWakeup(void)
Notify listeners that we woke up.
void NotifySleepNow(void)
Notify the Txop that the device has been put in sleep mode.
void NotifyTxStart(Time duration, double txPowerDbm)
virtual bool IsAccessRequested(void) const
virtual bool IsQosTxop() const
Check for QoS TXOP.
Time m_lastTxStart
the last transmit start time
void NotifyNavResetNow(Time duration)
void NotifyAckTimeoutStartNow(Time duration)
Notify that ack timer has started for the given duration.
void NotifySleep(void)
Notify listeners that we went to sleep.
Txops m_txops
the vector of managed Txops
void DoGrantPcfAccess(Ptr< Txop > txop)
Grant access to Txop using PCF preemption.
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 NotifyOn(void)
Notify listeners that we went to switch on.
void NotifyRxEndOkNow(void)
Notify the Txop that a packet reception was just completed successfully.
Time GetAccessGrantStart(bool ignoreNav=false) const
Access will never be granted to the medium before the time returned by this method.
bool m_lastRxReceivedOk
the last receive OK
PhyListener * m_phyListener
the PHY listener
void NotifyCtsTimeoutResetNow(void)
Notify that CTS timer has reset.
static Time Now(void)
Return the current simulation virtual time.
void NotifyRxStart(Time duration)
void DoGrantDcfAccess(void)
Grant access to Txop using DCF/EDCF contention rules.
Time m_lastNavStart
the last NAV start time
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Time Seconds(double value)
Construct a Time in the indicated unit.
uint32_t GetBackoffSlots(void) const
Return the current number of backoff slots.
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
void NotifySwitchingStartNow(Time duration)
void NotifyNavStartNow(Time duration)
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Time m_lastSwitchingDuration
the last switching duration time
Time GetBackoffEndFor(Ptr< Txop > txop)
Return the time when the backoff procedure ended (or will ended) for the given Txop.
void SetSlot(Time slotTime)
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
void AccessTimeout(void)
Called when access timeout should occur (e.g.
void NotifyTxStartNow(Time duration)
virtual void NotifyAccessRequested(void)
Notify that access request has been received.
void SetupLow(Ptr< MacLow > low)
Set up listener for MacLow events.
void NotifyRxEndOk(void)
We have received the last bit of a packet for which NotifyRxStart was invoked first and...
void DoRestartAccessTimeoutIfNeeded(void)
static Time GetMaximumSimulationTime(void)
Get the maximum representable simulation time.
void NotifyWakeupNow(void)
Notify the Txop that the device has been resumed from sleep mode.
Time m_lastAckTimeoutEnd
the last Ack timeout end time
void DoDispose(void)
Destructor implementation.
void NotifyAckTimeoutResetNow(void)
Notify that ack timer has reset.