A Discrete-Event Network Simulator
API
dcf-manager.h
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
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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  */
20 
21 #ifndef DCF_MANAGER_H
22 #define DCF_MANAGER_H
23 
24 #include "ns3/nstime.h"
25 #include "ns3/event-id.h"
26 #include <vector>
27 
28 namespace ns3 {
29 
30 class WifiPhy;
31 class WifiMac;
32 class MacLow;
33 class PhyListener;
34 class LowDcfListener;
35 
46 class DcfState
47 {
48 public:
49  DcfState ();
50  virtual ~DcfState ();
51 
60  virtual bool IsEdca (void) const = 0;
61 
68  void SetAifsn (uint32_t aifsn);
74  void SetCwMin (uint32_t minCw);
80  void SetCwMax (uint32_t maxCw);
86  uint32_t GetAifsn (void) const;
92  uint32_t GetCwMin (void) const;
98  uint32_t GetCwMax (void) const;
105  void ResetCw (void);
111  void UpdateFailedCw (void);
118  void StartBackoffNow (uint32_t nSlots);
123  uint32_t GetCw (void) const;
128  bool IsAccessRequested (void) const;
129 
130 
131 private:
132  friend class DcfManager;
133 
139  uint32_t GetBackoffSlots (void) const;
145  Time GetBackoffStart (void) const;
152  void UpdateBackoffSlotsNow (uint32_t nSlots, Time backoffUpdateBound);
156  void NotifyAccessRequested (void);
160  void NotifyAccessGranted (void);
164  void NotifyCollision (void);
168  void NotifyInternalCollision (void);
172  void NotifyChannelSwitching (void);
176  void NotifySleep (void);
180  void NotifyWakeUp (void);
181 
187  virtual void DoNotifyAccessGranted (void) = 0;
199  virtual void DoNotifyInternalCollision (void) = 0;
209  virtual void DoNotifyCollision (void) = 0;
216  virtual void DoNotifyChannelSwitching (void) = 0;
223  virtual void DoNotifySleep (void) = 0;
232  virtual void DoNotifyWakeUp (void) = 0;
233 
234  uint32_t m_aifsn;
235  uint32_t m_backoffSlots;
236  //the backoffStart variable is used to keep track of the
237  //time at which a backoff was started or the time at which
238  //the backoff counter was last updated.
240  uint32_t m_cwMin;
241  uint32_t m_cwMax;
242  uint32_t m_cw;
244 };
245 
246 
263 {
264 public:
265  DcfManager ();
266  ~DcfManager ();
267 
279  void RemovePhyListener (Ptr<WifiPhy> phy);
285  void SetupLowListener (Ptr<MacLow> low);
286 
293  void SetSlot (Time slotTime);
300  void SetSifs (Time sifs);
307  void SetEifsNoDifs (Time eifsNoDifs);
308 
312  Time GetEifsNoDifs () const;
313 
324  void Add (DcfState *dcf);
325 
334  void RequestAccess (DcfState *state);
335 
342  void NotifyRxStartNow (Time duration);
347  void NotifyRxEndOkNow (void);
352  void NotifyRxEndErrorNow (void);
360  void NotifyTxStartNow (Time duration);
366  void NotifyMaybeCcaBusyStartNow (Time duration);
374  void NotifySwitchingStartNow (Time duration);
378  void NotifySleepNow (void);
382  void NotifyWakeupNow (void);
388  void NotifyNavResetNow (Time duration);
394  void NotifyNavStartNow (Time duration);
400  void NotifyAckTimeoutStartNow (Time duration);
404  void NotifyAckTimeoutResetNow ();
410  void NotifyCtsTimeoutStartNow (Time duration);
414  void NotifyCtsTimeoutResetNow ();
415 
416 
417 private:
421  void UpdateBackoff (void);
430  Time MostRecent (Time a, Time b) const;
440  Time MostRecent (Time a, Time b, Time c) const;
451  Time MostRecent (Time a, Time b, Time c, Time d) const;
464  Time MostRecent (Time a, Time b, Time c, Time d, Time e, Time f) const;
478  Time MostRecent (Time a, Time b, Time c, Time d, Time e, Time f, Time g) const;
485  Time GetAccessGrantStart (void) const;
503  Time GetBackoffEndFor (DcfState *state);
504 
505  void DoRestartAccessTimeoutIfNeeded (void);
506 
511  void AccessTimeout (void);
515  void DoGrantAccess (void);
523  bool IsBusy (void) const;
524 
528  typedef std::vector<DcfState *> States;
529 
530  States m_states;
545  bool m_rxing;
549  uint32_t m_slotTimeUs;
553 };
554 
555 } //namespace ns3
556 
557 #endif /* DCF_MANAGER_H */
uint32_t m_cwMin
Definition: dcf-manager.h:240
void NotifyWakeupNow(void)
Notify the DCF that the device has been resumed from sleep mode.
Definition: dcf-manager.cc:852
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:187
void NotifyInternalCollision(void)
Notify that internal collision has occurred.
Definition: dcf-manager.cc:175
bool m_lastRxReceivedOk
Definition: dcf-manager.h:537
uint32_t GetCwMin(void) const
Return the minimum congestion window size.
Definition: dcf-manager.cc:90
void NotifyAccessGranted(void)
Notify that access has been granted.
Definition: dcf-manager.cc:161
void RequestAccess(DcfState *state)
Definition: dcf-manager.cc:487
Time GetBackoffStart(void) const
Return the time when the backoff procedure started.
Definition: dcf-manager.cc:144
void SetupLowListener(Ptr< MacLow > low)
Set up listener for MacLow events.
Definition: dcf-manager.cc:365
Time m_lastAckTimeoutEnd
Definition: dcf-manager.h:531
void NotifyWakeUp(void)
Notify that the device has started to wake up.
Definition: dcf-manager.cc:193
void UpdateBackoff(void)
Update backoff slots for all DcfStates.
Definition: dcf-manager.cc:635
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:532
bool m_accessRequested
Definition: dcf-manager.h:243
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:102
Time m_lastSwitchingDuration
Definition: dcf-manager.h:544
void Add(DcfState *dcf)
Definition: dcf-manager.cc:405
void DoGrantAccess(void)
Grant access to DCF.
Definition: dcf-manager.cc:516
void NotifyNavResetNow(Time duration)
Definition: dcf-manager.cc:872
Time GetBackoffStartFor(DcfState *state)
Return the time when the backoff procedure started for the given DcfState.
Definition: dcf-manager.cc:619
void NotifyCtsTimeoutStartNow(Time duration)
Notify that CTS timer has started for the given duration.
Definition: dcf-manager.cc:922
void NotifyRxEndOkNow(void)
Notify the DCF that a packet reception was just completed successfully.
Definition: dcf-manager.cc:723
uint32_t m_backoffSlots
Definition: dcf-manager.h:235
tuple phy
Definition: third.py:86
PhyListener * m_phyListener
Definition: dcf-manager.h:551
Time GetAccessGrantStart(void) const
Access will never be granted to the medium before the time returned by this method.
Definition: dcf-manager.cc:580
Time GetBackoffEndFor(DcfState *state)
Return the time when the backoff procedure ended (or will ended) for the given DcfState.
Definition: dcf-manager.cc:629
void NotifyTxStartNow(Time duration)
Definition: dcf-manager.cc:743
void RemovePhyListener(Ptr< WifiPhy > phy)
Remove current registered listener for Phy events.
Definition: dcf-manager.cc:353
void NotifyAckTimeoutStartNow(Time duration)
Notify that ACK timer has started for the given duration.
Definition: dcf-manager.cc:906
void SetupPhyListener(Ptr< WifiPhy > phy)
Set up listener for Phy events.
Definition: dcf-manager.cc:341
Manage a set of ns3::DcfStateHandle a set of independent ns3::DcfState, each of which represents a si...
Definition: dcf-manager.h:262
keep track of the state needed for a single DCF function.
Definition: dcf-manager.h:46
bool IsAccessRequested(void) const
Definition: dcf-manager.cc:150
Listener for PHY events.
Definition: dcf-manager.cc:250
uint32_t GetBackoffSlots(void) const
Return the current number of backoff slots.
Definition: dcf-manager.cc:138
virtual ~DcfState()
Definition: dcf-manager.cc:51
uint32_t GetCwMax(void) const
Return the maximum congestion window size.
Definition: dcf-manager.cc:96
Time m_lastBusyDuration
Definition: dcf-manager.h:542
void SetCwMin(uint32_t minCw)
Set the minimum congestion window size.
Definition: dcf-manager.cc:62
double f(double x, void *params)
Definition: 80211b.c:60
void StartBackoffNow(uint32_t nSlots)
Definition: dcf-manager.cc:123
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:241
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:528
void NotifyAccessRequested(void)
Notify that access request has been received.
Definition: dcf-manager.cc:155
void NotifyRxEndErrorNow(void)
Notify the DCF that a packet reception was just completed unsuccessfully.
Definition: dcf-manager.cc:733
uint32_t m_cw
Definition: dcf-manager.h:242
Time m_lastSwitchingStart
Definition: dcf-manager.h:543
void SetEifsNoDifs(Time eifsNoDifs)
Definition: dcf-manager.cc:391
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:763
void AccessTimeout(void)
Called when access timeout should occur (e.g.
Definition: dcf-manager.cc:571
Time m_lastNavDuration
Definition: dcf-manager.h:534
void SetSlot(Time slotTime)
Definition: dcf-manager.cc:377
void SetCwMax(uint32_t maxCw)
Set the maximum congestion window size.
Definition: dcf-manager.cc:73
void NotifyAckTimeoutResetNow()
Notify that ACK timer has resetted.
Definition: dcf-manager.cc:914
LowDcfListener * m_lowListener
Definition: dcf-manager.h:552
void NotifyNavStartNow(Time duration)
Definition: dcf-manager.cc:890
An identifier for simulation events.
Definition: event-id.h:53
void NotifyChannelSwitching(void)
Notify that the device is switching channel.
Definition: dcf-manager.cc:181
uint32_t GetCw(void) const
Definition: dcf-manager.cc:132
uint32_t GetAifsn(void) const
Return the number of slots that make up an AIFS.
Definition: dcf-manager.cc:84
uint32_t m_aifsn
Definition: dcf-manager.h:234
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:712
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:115
Time GetEifsNoDifs() const
Definition: dcf-manager.cc:398
void NotifySleepNow(void)
Notify the DCF that the device has been put in sleep mode.
Definition: dcf-manager.cc:833
void NotifyCtsTimeoutResetNow()
Notify that CTS timer has resetted.
Definition: dcf-manager.cc:929
void NotifyCollision(void)
Notify that collision has occurred.
Definition: dcf-manager.cc:169
bool IsBusy(void) const
Check if the device is busy sending or receiving, or NAV busy.
Definition: dcf-manager.cc:464
Time m_backoffStart
Definition: dcf-manager.h:239
void DoRestartAccessTimeoutIfNeeded(void)
Definition: dcf-manager.cc:672
EventId m_accessTimeout
Definition: dcf-manager.h:548
void UpdateFailedCw(void)
Update the value of the CW variable to take into account a transmission failure.
Definition: dcf-manager.cc:108
Listener for NAV events.
Definition: dcf-manager.cc:202
void NotifySwitchingStartNow(Time duration)
Definition: dcf-manager.cc:773
virtual bool IsEdca(void) const =0
uint32_t m_slotTimeUs
Definition: dcf-manager.h:549
Time MostRecent(Time a, Time b) const
Return the most recent time.
Definition: dcf-manager.cc:412
void SetSifs(Time sifs)
Definition: dcf-manager.cc:384