21 #include "ns3/assert.h"
23 #include "ns3/simulator.h"
34 NS_LOG_DEBUG (Simulator::Now () << " " << this << " " << x)
48 m_accessRequested (false)
112 MY_DEBUG (
"start backoff=" << nSlots <<
" slots");
277 m_lastRxReceivedOk (true),
370 retval =
Max (retval, c);
448 MY_DEBUG (
"medium is busy: collision");
463 for (States::const_iterator i =
m_states.begin (); i !=
m_states.end (); k++)
473 MY_DEBUG (
"dcf " << k <<
" needs access. backoff expired. access granted. slots=" << state->
GetBackoffSlots ());
476 std::vector<DcfState *> internalCollisionStates;
477 for (States::const_iterator j = i; j !=
m_states.end (); j++, k++)
483 MY_DEBUG (
"dcf " << k <<
" needs access. backoff expired. internal collision. slots=" <<
490 internalCollisionStates.push_back (otherState);
502 for (std::vector<DcfState *>::const_iterator k = internalCollisionStates.begin ();
503 k != internalCollisionStates.end (); k++)
505 (*k)->NotifyInternalCollision ();
549 ackTimeoutAccessStart,
550 ctsTimeoutAccessStart,
553 NS_LOG_INFO (
"access grant start=" << accessGrantedStart <<
554 ", rx access start=" << rxAccessStart <<
555 ", busy access start=" << busyAccessStart <<
556 ", tx access start=" << txAccessStart <<
557 ", nav access start=" << navAccessStart);
558 return accessGrantedStart;
568 return mostRecentEvent;
582 for (States::const_iterator i =
m_states.begin (); i !=
m_states.end (); i++, k++)
589 uint32_t nus = (
Simulator::Now () - backoffStart).GetMicroSeconds ();
592 MY_DEBUG (
"dcf " << k <<
" dec backoff slots=" << n);
607 bool accessTimeoutNeeded =
false;
609 for (States::const_iterator i =
m_states.begin (); i !=
m_states.end (); i++)
617 accessTimeoutNeeded =
true;
618 expectedBackoffEnd = std::min (expectedBackoffEnd, tmp);
622 if (accessTimeoutNeeded)
624 MY_DEBUG (
"expected backoff end=" << expectedBackoffEnd);
643 MY_DEBUG (
"rx start for=" << duration);
682 MY_DEBUG (
"tx start for " << duration);
691 MY_DEBUG (
"busy start for " << duration);
742 if (remainingSlots > 0)
752 MY_DEBUG (
"switching start for " << duration);
780 if (remainingSlots > 0)
794 MY_DEBUG (
"nav reset for=" << duration);
812 MY_DEBUG (
"nav start for=" << duration);
816 if (newNavEnd > lastNavEnd)
819 m_lastNavDuration = duration;
ns3::DcfManager * m_dcf
DcfManager to forward events to.
static Time GetDelayLeft(const EventId &id)
void NotifyWakeupNow(void)
Notify the DCF that the device has been resumed from sleep mode.
Simulation virtual time values and global simulation resolution.
ns3::DcfManager * m_dcf
DcfManager to forward events to.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
virtual void NavReset(Time duration)
Notify that NAV has resetted.
void NotifyInternalCollision(void)
Notify that internal collision has occurred.
uint32_t GetCwMin(void) const
Return the minimum congestion window size.
virtual void NotifyRxStart(Time duration)
void NotifyAccessGranted(void)
Notify that access has been granted.
void RequestAccess(DcfState *state)
Time GetBackoffStart(void) const
Return the time when the backoff procedure started.
void SetupLowListener(Ptr< MacLow > low)
Set up listener for MacLow 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.
virtual void NotifySwitchingStart(Time duration)
LowDcfListener(ns3::DcfManager *dcf)
Create a LowDcfListener for the given DcfManager.
void UpdateBackoff(void)
Update backoff slots for all DcfStates.
virtual void DoNotifyCollision(void)=0
Called by DcfManager to notify a DcfState subclass that a normal collision occured, that is, that the medium was busy when access was requested.
virtual void NotifyWakeup(void)
Notify listeners that we woke up.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
void SetAifsn(uint32_t aifsn)
bool IsRunning(void) const
This method is syntactic sugar for the ns3::Simulator::isExpired method.
void ResetCw(void)
Update the value of the CW variable to take into account a transmission success or a transmission abo...
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Time m_lastSwitchingDuration
PhyListener(ns3::DcfManager *dcf)
Create a PhyListener for the given DcfManager.
virtual void NotifyRxEndOk(void)
We have received the last bit of a packet for which NotifyRxStart was invoked first and...
virtual void RegisterListener(WifiPhyListener *listener)=0
void DoGrantAccess(void)
Grant access to DCF.
void NotifyNavResetNow(Time duration)
Time GetBackoffStartFor(DcfState *state)
Return the time when the backoff procedure started for the given DcfState.
void NotifyCtsTimeoutStartNow(Time duration)
Notify that CTS timer has started for the given duration.
void NotifyRxEndOkNow(void)
Notify the DCF that a packet reception was just completed successfully.
PhyListener * m_phyListener
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Time GetAccessGrantStart(void) const
Access will never be granted to the medium before the time returned by this method.
receive notifications about phy events.
Time GetBackoffEndFor(DcfState *state)
Return the time when the backoff procedure ended (or will ended) for the given DcfState.
void NotifyTxStartNow(Time duration)
void NotifyAckTimeoutStartNow(Time duration)
Notify that ACK timer has started for the given duration.
virtual void NavStart(Time duration)
Norify that NAV has started for the given duration.
void SetupPhyListener(Ptr< WifiPhy > phy)
Set up listener for Phy events.
Manage a set of ns3::DcfStateHandle a set of independent ns3::DcfState, each of which represents a si...
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
keep track of the state needed for a single DCF function.
virtual void AckTimeoutStart(Time duration)
Notify that ACK timeout has started for a given duration.
virtual void CtsTimeoutReset()
Notify that CTS timeout has resetted.
bool IsAccessRequested(void) const
uint32_t GetBackoffSlots(void) const
Return the current number of backoff slots.
uint32_t GetCwMax(void) const
Return the maximum congestion window size.
void SetCwMin(uint32_t minCw)
Set the minimum congestion window size.
virtual void NotifySleep(void)
Notify listeners that we went to sleep.
void StartBackoffNow(uint32_t nSlots)
virtual void NotifyMaybeCcaBusyStart(Time duration)
virtual void DoNotifyAccessGranted(void)=0
Called by DcfManager to notify a DcfState subclass that access to the medium is granted and can start...
void NotifyAccessRequested(void)
Notify that access request has been received.
void NotifyRxEndErrorNow(void)
Notify the DCF that a packet reception was just completed unsuccessfully.
virtual void CtsTimeoutStart(Time duration)
Notify that CTS timeout has started for a given duration.
Time m_lastSwitchingStart
void SetEifsNoDifs(Time eifsNoDifs)
virtual void DoNotifyInternalCollision(void)=0
Called by DcfManager to notify a DcfState subclass that an 'internal' collision occured, that is, that the backoff timer of a higher priority DcfState expired at the same time and that access was granted to this higher priority DcfState.
listen to NAV eventsThis class is typically connected to an instance of ns3::Dcf and calls to its met...
static Time Now(void)
Return the "current simulation time".
void NotifyMaybeCcaBusyStartNow(Time duration)
void AccessTimeout(void)
Called when access timeout should occur (e.g.
virtual void DoNotifyChannelSwitching()=0
Called by DcfManager to notify a DcfState subclass that a channel switching occured.
void SetSlot(Time slotTime)
void SetCwMax(uint32_t maxCw)
Set the maximum congestion window size.
void NotifyAckTimeoutResetNow()
Notify that ACK timer has resetted.
LowDcfListener * m_lowListener
void NotifyNavStartNow(Time duration)
void NotifyChannelSwitching(void)
Notify that the device is switching channel.
uint32_t GetCw(void) const
uint32_t GetAifsn(void) const
Return the number of slots that make up an AIFS.
void NotifyRxStartNow(Time duration)
void UpdateBackoffSlotsNow(uint32_t nSlots, Time backoffUpdateBound)
Update backoff slots that nSlots has passed.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time GetEifsNoDifs() const
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::cancel method.
virtual void NotifyRxEndError(void)
We have received the last bit of a packet for which NotifyRxStart was invoked first and...
void NotifySleepNow(void)
Notify the DCF that the device has been put in sleep mode.
void NotifyCtsTimeoutResetNow()
Notify that CTS timer has resetted.
void NotifyCollision(void)
Notify that collision has occurred.
virtual void NotifyTxStart(Time duration, double txPowerDbm)
bool IsBusy(void) const
Check if the device is busy sending or receiving, or NAV busy.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
void DoRestartAccessTimeoutIfNeeded(void)
virtual ~LowDcfListener()
void UpdateFailedCw(void)
Update the value of the CW variable to take into account a transmission failure.
void NotifySwitchingStartNow(Time duration)
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::isExpired method.
static Time GetMaximumSimulationTime(void)
Time MostRecent(Time a, Time b) const
Return the most recent time.
virtual void AckTimeoutReset()
Notify that ACK timeout has resetted.