21 #include "ns3/assert.h"
23 #include "ns3/simulator.h"
32 NS_LOG_DEBUG (Simulator::Now () << " " << this << " " << x)
48 m_accessRequested (false)
112 MY_DEBUG (
"start backoff=" << nSlots <<
" slots");
287 m_lastRxReceivedOk (true),
393 retval =
Max (retval, c);
471 MY_DEBUG (
"medium is busy: collision");
486 for (States::const_iterator i =
m_states.begin (); i !=
m_states.end (); k++)
496 MY_DEBUG (
"dcf " << k <<
" needs access. backoff expired. access granted. slots=" << state->
GetBackoffSlots ());
499 std::vector<DcfState *> internalCollisionStates;
500 for (States::const_iterator j = i; j !=
m_states.end (); j++, k++)
506 MY_DEBUG (
"dcf " << k <<
" needs access. backoff expired. internal collision. slots=" <<
513 internalCollisionStates.push_back (otherState);
525 for (std::vector<DcfState *>::const_iterator k = internalCollisionStates.begin ();
526 k != internalCollisionStates.end (); k++)
528 (*k)->NotifyInternalCollision ();
572 ackTimeoutAccessStart,
573 ctsTimeoutAccessStart,
576 NS_LOG_INFO (
"access grant start=" << accessGrantedStart <<
577 ", rx access start=" << rxAccessStart <<
578 ", busy access start=" << busyAccessStart <<
579 ", tx access start=" << txAccessStart <<
580 ", nav access start=" << navAccessStart);
581 return accessGrantedStart;
591 return mostRecentEvent;
605 for (States::const_iterator i =
m_states.begin (); i !=
m_states.end (); i++, k++)
612 uint32_t nus = (
Simulator::Now () - backoffStart).GetMicroSeconds ();
615 MY_DEBUG (
"dcf " << k <<
" dec backoff slots=" << n);
630 bool accessTimeoutNeeded =
false;
632 for (States::const_iterator i =
m_states.begin (); i !=
m_states.end (); i++)
640 accessTimeoutNeeded =
true;
641 expectedBackoffEnd = std::min (expectedBackoffEnd, tmp);
645 if (accessTimeoutNeeded)
647 MY_DEBUG (
"expected backoff end=" << expectedBackoffEnd);
666 MY_DEBUG (
"rx start for=" << duration);
705 MY_DEBUG (
"tx start for " << duration);
714 MY_DEBUG (
"busy start for " << duration);
765 if (remainingSlots > 0)
775 MY_DEBUG (
"switching start for " << duration);
809 if (remainingSlots > 0)
824 MY_DEBUG (
"nav reset for=" << duration);
842 MY_DEBUG (
"nav start for=" << duration);
846 if (newNavEnd > lastNavEnd)
849 m_lastNavDuration = duration;
ns3::DcfManager * m_dcf
DcfManager to forward events to.
static Time GetDelayLeft(const EventId &id)
Get the remaining time until this event will execute.
void NotifyWakeupNow(void)
Notify the DCF that the device has been resumed from sleep mode.
Simulation virtual time values and global simulation resolution.
void NotifySleep(void)
Notify that the device has started to sleep.
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.
void NotifyWakeUp(void)
Notify that the device has started to wake up.
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 !IsExpired().
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 RemovePhyListener(Ptr< WifiPhy > phy)
Remove current registered listener for Phy events.
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
void RegisterDcfListener(MacLowDcfListener *listener)
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 DoNotifyWakeUp(void)=0
Called by DcfManager to notify a DcfState subclass that the device has begun to wake up...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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...
virtual void UnregisterListener(WifiPhyListener *listener)=0
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 virtual time.
void NotifyMaybeCcaBusyStartNow(Time duration)
void AccessTimeout(void)
Called when access timeout should occur (e.g.
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.
virtual void DoNotifyChannelSwitching(void)=0
Called by DcfManager to notify a DcfState subclass that a channel switching occured.
void NotifyRxStartNow(Time duration)
virtual void DoNotifySleep(void)=0
Called by DcfManager to notify a DcfState subclass that the device has begun to sleep.
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)
Get the maximum representable simulation time.
Time MostRecent(Time a, Time b) const
Return the most recent time.
virtual void AckTimeoutReset()
Notify that ACK timeout has resetted.