A Discrete-Event Network Simulator
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
21 #ifndef DCF_MANAGER_H
22 #define DCF_MANAGER_H
24 #include "ns3/nstime.h"
25 #include "ns3/event-id.h"
26 #include <vector>
28 namespace ns3 {
30 class WifiPhy;
31 class WifiMac;
32 class MacLow;
33 class PhyListener;
34 class LowDcfListener;
46 class DcfState
47 {
48 public:
49  DcfState ();
50  virtual ~DcfState ();
60  virtual bool IsEdca (void) const = 0;
68  void SetAifsn (uint32_t aifsn);
74  void SetCwMin (uint32_t minCw);
80  void SetCwMax (uint32_t maxCw);
86  void SetTxopLimit (Time txopLimit);
92  uint32_t GetAifsn (void) const;
98  uint32_t GetCwMin (void) const;
104  uint32_t GetCwMax (void) const;
110  Time GetTxopLimit (void) const;
118  void ResetCw (void);
124  void UpdateFailedCw (void);
131  void StartBackoffNow (uint32_t nSlots);
136  uint32_t GetCw (void) const;
141  bool IsAccessRequested (void) const;
144 private:
145  friend class DcfManager;
152  uint32_t GetBackoffSlots (void) const;
158  Time GetBackoffStart (void) const;
165  void UpdateBackoffSlotsNow (uint32_t nSlots, Time backoffUpdateBound);
169  void NotifyAccessRequested (void);
173  void NotifyAccessGranted (void);
177  void NotifyCollision (void);
181  void NotifyInternalCollision (void);
185  void NotifyChannelSwitching (void);
189  void NotifySleep (void);
193  void NotifyWakeUp (void);
200  virtual void DoNotifyAccessGranted (void) = 0;
212  virtual void DoNotifyInternalCollision (void) = 0;
225  virtual void DoNotifyCollision (void) = 0;
232  virtual void DoNotifyChannelSwitching (void) = 0;
239  virtual void DoNotifySleep (void) = 0;
248  virtual void DoNotifyWakeUp (void) = 0;
250  uint32_t m_aifsn;
251  uint32_t m_backoffSlots;
252  //the backoffStart variable is used to keep track of the
253  //time at which a backoff was started or the time at which
254  //the backoff counter was last updated.
256  uint32_t m_cwMin;
257  uint32_t m_cwMax;
258  uint32_t m_cw;
261 };
280 {
281 public:
282  DcfManager ();
283  ~DcfManager ();
296  void RemovePhyListener (Ptr<WifiPhy> phy);
302  void SetupLowListener (Ptr<MacLow> low);
310  void SetSlot (Time slotTime);
317  void SetSifs (Time sifs);
324  void SetEifsNoDifs (Time eifsNoDifs);
329  Time GetEifsNoDifs () const;
341  void Add (DcfState *dcf);
351  void RequestAccess (DcfState *state);
359  void NotifyRxStartNow (Time duration);
364  void NotifyRxEndOkNow (void);
369  void NotifyRxEndErrorNow (void);
377  void NotifyTxStartNow (Time duration);
383  void NotifyMaybeCcaBusyStartNow (Time duration);
391  void NotifySwitchingStartNow (Time duration);
395  void NotifySleepNow (void);
399  void NotifyWakeupNow (void);
405  void NotifyNavResetNow (Time duration);
411  void NotifyNavStartNow (Time duration);
417  void NotifyAckTimeoutStartNow (Time duration);
421  void NotifyAckTimeoutResetNow ();
427  void NotifyCtsTimeoutStartNow (Time duration);
431  void NotifyCtsTimeoutResetNow ();
434 private:
438  void UpdateBackoff (void);
447  Time MostRecent (Time a, Time b) const;
457  Time MostRecent (Time a, Time b, Time c) const;
468  Time MostRecent (Time a, Time b, Time c, Time d) const;
481  Time MostRecent (Time a, Time b, Time c, Time d, Time e, Time f) const;
495  Time MostRecent (Time a, Time b, Time c, Time d, Time e, Time f, Time g) const;
502  Time GetAccessGrantStart (void) const;
520  Time GetBackoffEndFor (DcfState *state);
522  void DoRestartAccessTimeoutIfNeeded (void);
528  void AccessTimeout (void);
532  void DoGrantAccess (void);
540  bool IsBusy (void) const;
548  bool IsWithinAifs (DcfState* state) const;
553  typedef std::vector<DcfState *> States;
555  States m_states;
570  bool m_rxing;
574  uint32_t m_slotTimeUs;
578 };
580 } //namespace ns3
582 #endif /* DCF_MANAGER_H */
uint32_t m_cwMin
Definition: dcf-manager.h:256
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
Definition: dcf-manager.cc:62
void NotifyWakeupNow(void)
Notify the DCF that the device has been resumed from sleep mode.
Definition: dcf-manager.cc:929
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
void NotifySleep(void)
Notify that the device has started to sleep.
Definition: dcf-manager.cc:206
void NotifyInternalCollision(void)
Notify that internal collision has occurred.
Definition: dcf-manager.cc:194
bool m_lastRxReceivedOk
Definition: dcf-manager.h:562
uint32_t GetCwMin(void) const
Return the minimum congestion window size.
Definition: dcf-manager.cc:103
void NotifyAccessGranted(void)
Notify that access has been granted.
Definition: dcf-manager.cc:180
void RequestAccess(DcfState *state)
Definition: dcf-manager.cc:526
Time GetBackoffStart(void) const
Return the time when the backoff procedure started.
Definition: dcf-manager.cc:163
void SetupLowListener(Ptr< MacLow > low)
Set up listener for MacLow events.
Definition: dcf-manager.cc:384
Time m_lastAckTimeoutEnd
Definition: dcf-manager.h:556
void NotifyWakeUp(void)
Notify that the device has started to wake up.
Definition: dcf-manager.cc:212
void UpdateBackoff(void)
Update backoff slots for all DcfStates.
Definition: dcf-manager.cc:697
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.
Time m_lastCtsTimeoutEnd
Definition: dcf-manager.h:557
bool m_accessRequested
Definition: dcf-manager.h:260
void SetAifsn(uint32_t aifsn)
Definition: dcf-manager.cc:56
void ResetCw(void)
Update the value of the CW variable to take into account a transmission success or a transmission abo...
Definition: dcf-manager.cc:115
Time m_lastSwitchingDuration
Definition: dcf-manager.h:569
void Add(DcfState *dcf)
Definition: dcf-manager.cc:424
Time GetTxopLimit(void) const
Return the TXOP limit.
Definition: dcf-manager.cc:97
void DoGrantAccess(void)
Grant access to DCF.
Definition: dcf-manager.cc:574
void NotifyNavResetNow(Time duration)
Definition: dcf-manager.cc:949
Time GetBackoffStartFor(DcfState *state)
Return the time when the backoff procedure started for the given DcfState.
Definition: dcf-manager.cc:677
void NotifyCtsTimeoutStartNow(Time duration)
Notify that CTS timer has started for the given duration.
Definition: dcf-manager.cc:998
void NotifyRxEndOkNow(void)
Notify the DCF that a packet reception was just completed successfully.
Definition: dcf-manager.cc:786
uint32_t m_backoffSlots
Definition: dcf-manager.h:251
tuple phy
Definition: third.py:86
PhyListener * m_phyListener
Definition: dcf-manager.h:576
Time GetAccessGrantStart(void) const
Access will never be granted to the medium before the time returned by this method.
Definition: dcf-manager.cc:638
Time GetBackoffEndFor(DcfState *state)
Return the time when the backoff procedure ended (or will ended) for the given DcfState.
Definition: dcf-manager.cc:687
void NotifyTxStartNow(Time duration)
Definition: dcf-manager.cc:806
void RemovePhyListener(Ptr< WifiPhy > phy)
Remove current registered listener for Phy events.
Definition: dcf-manager.cc:372
void NotifyAckTimeoutStartNow(Time duration)
Notify that ACK timer has started for the given duration.
Definition: dcf-manager.cc:982
void SetupPhyListener(Ptr< WifiPhy > phy)
Set up listener for Phy events.
Definition: dcf-manager.cc:360
Manage a set of ns3::DcfStateHandle a set of independent ns3::DcfState, each of which represents a si...
Definition: dcf-manager.h:279
keep track of the state needed for a single DCF function.
Definition: dcf-manager.h:46
bool IsWithinAifs(DcfState *state) const
Check if the device is between frames (in DIFS or AIFS interval)
Definition: dcf-manager.cc:512
bool IsAccessRequested(void) const
Definition: dcf-manager.cc:169
Listener for PHY events.
Definition: dcf-manager.cc:269
uint32_t GetBackoffSlots(void) const
Return the current number of backoff slots.
Definition: dcf-manager.cc:157
virtual ~DcfState()
Definition: dcf-manager.cc:51
uint32_t GetCwMax(void) const
Return the maximum congestion window size.
Definition: dcf-manager.cc:109
Time m_lastBusyDuration
Definition: dcf-manager.h:567
void SetCwMin(uint32_t minCw)
Set the minimum congestion window size.
Definition: dcf-manager.cc:69
double f(double x, void *params)
Definition: 80211b.c:60
void StartBackoffNow(uint32_t nSlots)
Definition: dcf-manager.cc:136
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.
uint32_t m_cwMax
Definition: dcf-manager.h:257
virtual void DoNotifyAccessGranted(void)=0
Called by DcfManager to notify a DcfState subclass that access to the medium is granted and can start...
std::vector< DcfState * > States
typedef for a vector of DcfStates
Definition: dcf-manager.h:553
void NotifyAccessRequested(void)
Notify that access request has been received.
Definition: dcf-manager.cc:174
void NotifyRxEndErrorNow(void)
Notify the DCF that a packet reception was just completed unsuccessfully.
Definition: dcf-manager.cc:796
uint32_t m_cw
Definition: dcf-manager.h:258
Time m_lastSwitchingStart
Definition: dcf-manager.h:568
void SetEifsNoDifs(Time eifsNoDifs)
Definition: dcf-manager.cc:410
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.
void NotifyMaybeCcaBusyStartNow(Time duration)
Definition: dcf-manager.cc:840
void AccessTimeout(void)
Called when access timeout should occur (e.g.
Definition: dcf-manager.cc:629
Time m_lastNavDuration
Definition: dcf-manager.h:559
void SetSlot(Time slotTime)
Definition: dcf-manager.cc:396
void SetCwMax(uint32_t maxCw)
Set the maximum congestion window size.
Definition: dcf-manager.cc:80
void NotifyAckTimeoutResetNow()
Notify that ACK timer has resetted.
Definition: dcf-manager.cc:990
LowDcfListener * m_lowListener
Definition: dcf-manager.h:577
void NotifyNavStartNow(Time duration)
Definition: dcf-manager.cc:966
An identifier for simulation events.
Definition: event-id.h:53
void NotifyChannelSwitching(void)
Notify that the device is switching channel.
Definition: dcf-manager.cc:200
uint32_t GetCw(void) const
Definition: dcf-manager.cc:151
uint32_t GetAifsn(void) const
Return the number of slots that make up an AIFS.
Definition: dcf-manager.cc:91
uint32_t m_aifsn
Definition: dcf-manager.h:250
virtual void DoNotifyChannelSwitching(void)=0
Called by DcfManager to notify a DcfState subclass that a channel switching occured.
void NotifyRxStartNow(Time duration)
Definition: dcf-manager.cc:775
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.
Definition: dcf-manager.cc:128
Time GetEifsNoDifs() const
Definition: dcf-manager.cc:417
void NotifySleepNow(void)
Notify the DCF that the device has been put in sleep mode.
Definition: dcf-manager.cc:910
void NotifyCtsTimeoutResetNow()
Notify that CTS timer has resetted.
void NotifyCollision(void)
Notify that collision has occurred.
Definition: dcf-manager.cc:188
bool IsBusy(void) const
Check if the device is busy sending or receiving, or NAV or CCA busy.
Definition: dcf-manager.cc:483
Time m_backoffStart
Definition: dcf-manager.h:255
void DoRestartAccessTimeoutIfNeeded(void)
Definition: dcf-manager.cc:734
EventId m_accessTimeout
Definition: dcf-manager.h:573
void UpdateFailedCw(void)
Update the value of the CW variable to take into account a transmission failure.
Definition: dcf-manager.cc:121
Listener for NAV events.
Definition: dcf-manager.cc:221
void NotifySwitchingStartNow(Time duration)
Definition: dcf-manager.cc:850
virtual bool IsEdca(void) const =0
uint32_t m_slotTimeUs
Definition: dcf-manager.h:574
Time MostRecent(Time a, Time b) const
Return the most recent time.
Definition: dcf-manager.cc:431
void SetSifs(Time sifs)
Definition: dcf-manager.cc:403