A Discrete-Event Network Simulator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 ();
51  virtual ~DcfState ();
59  void SetAifsn (uint32_t aifsn);
65  void SetCwMin (uint32_t minCw);
71  void SetCwMax (uint32_t maxCw);
77  uint32_t GetAifsn (void) const;
83  uint32_t GetCwMin (void) const;
89  uint32_t GetCwMax (void) const;
96  void ResetCw (void);
102  void UpdateFailedCw (void);
109  void StartBackoffNow (uint32_t nSlots);
114  uint32_t GetCw (void) const;
119  bool IsAccessRequested (void) const;
121 private:
122  friend class DcfManager;
129  uint32_t GetBackoffSlots (void) const;
135  Time GetBackoffStart (void) const;
142  void UpdateBackoffSlotsNow (uint32_t nSlots, Time backoffUpdateBound);
146  void NotifyAccessRequested (void);
150  void NotifyAccessGranted (void);
154  void NotifyCollision (void);
158  void NotifyInternalCollision (void);
162  void NotifyChannelSwitching (void);
170  virtual void DoNotifyAccessGranted (void) = 0;
182  virtual void DoNotifyInternalCollision (void) = 0;
192  virtual void DoNotifyCollision (void) = 0;
200  virtual void DoNotifyChannelSwitching () = 0;
202  uint32_t m_aifsn;
203  uint32_t m_backoffSlots;
204  // the backoffStart variable is used to keep track of the
205  // time at which a backoff was started or the time at which
206  // the backoff counter was last updated.
208  uint32_t m_cwMin;
209  uint32_t m_cwMax;
210  uint32_t m_cw;
212 };
230 {
231 public:
232  DcfManager ();
233  ~DcfManager ();
240  void SetupPhyListener (Ptr<WifiPhy> phy);
246  void SetupLowListener (Ptr<MacLow> low);
254  void SetSlot (Time slotTime);
261  void SetSifs (Time sifs);
269  void SetEifsNoDifs (Time eifsNoDifs);
274  Time GetEifsNoDifs () const;
286  void Add (DcfState *dcf);
296  void RequestAccess (DcfState *state);
304  void NotifyRxStartNow (Time duration);
309  void NotifyRxEndOkNow (void);
314  void NotifyRxEndErrorNow (void);
322  void NotifyTxStartNow (Time duration);
328  void NotifyMaybeCcaBusyStartNow (Time duration);
336  void NotifySwitchingStartNow (Time duration);
342  void NotifyNavResetNow (Time duration);
348  void NotifyNavStartNow (Time duration);
354  void NotifyAckTimeoutStartNow (Time duration);
358  void NotifyAckTimeoutResetNow ();
364  void NotifyCtsTimeoutStartNow (Time duration);
368  void NotifyCtsTimeoutResetNow ();
369 private:
373  void UpdateBackoff (void);
381  Time MostRecent (Time a, Time b) const;
390  Time MostRecent (Time a, Time b, Time c) const;
400  Time MostRecent (Time a, Time b, Time c, Time d) const;
412  Time MostRecent (Time a, Time b, Time c, Time d, Time e, Time f) const;
425  Time MostRecent (Time a, Time b, Time c, Time d, Time e, Time f, Time g) const;
433  Time GetAccessGrantStart (void) const;
449  Time GetBackoffEndFor (DcfState *state);
450  void DoRestartAccessTimeoutIfNeeded (void);
455  void AccessTimeout (void);
459  void DoGrantAccess (void);
467  bool IsBusy (void) const;
472  typedef std::vector<DcfState *> States;
489  bool m_rxing;
492  uint32_t m_slotTimeUs;
496 };
498 } // namespace ns3
500 #endif /* DCF_MANAGER_H */
uint32_t m_cwMin
Definition: dcf-manager.h:208
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
void NotifyInternalCollision(void)
Notify that internal collision has occurred.
Definition: dcf-manager.cc:155
bool m_lastRxReceivedOk
Definition: dcf-manager.h:481
uint32_t GetCwMin(void) const
Return the minimum congestion window size.
Definition: dcf-manager.cc:79
void NotifyAccessGranted(void)
Notify that access has been granted.
Definition: dcf-manager.cc:143
void RequestAccess(DcfState *state)
Definition: dcf-manager.cc:423
Time GetBackoffStart(void) const
Return the time when the backoff procedure started.
Definition: dcf-manager.cc:128
void SetupLowListener(Ptr< MacLow > low)
Set up listener for MacLow events.
Definition: dcf-manager.cc:306
Time m_lastAckTimeoutEnd
Definition: dcf-manager.h:475
void UpdateBackoff(void)
Update backoff slots for all DcfStates.
Definition: dcf-manager.cc:566
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:476
bool m_accessRequested
Definition: dcf-manager.h:211
void SetAifsn(uint32_t aifsn)
Definition: dcf-manager.cc:57
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:90
Time m_lastSwitchingDuration
Definition: dcf-manager.h:488
void Add(DcfState *dcf)
Definition: dcf-manager.cc:343
void DoGrantAccess(void)
Grant access to DCF.
Definition: dcf-manager.cc:447
void NotifyNavResetNow(Time duration)
Definition: dcf-manager.cc:747
Time GetBackoffStartFor(DcfState *state)
Return the time when the backoff procedure started for the given DcfState.
Definition: dcf-manager.cc:550
void NotifyCtsTimeoutStartNow(Time duration)
Notify that CTS timer has started for the given duration.
Definition: dcf-manager.cc:793
void NotifyRxEndOkNow(void)
Notify the DCF that a packet reception was just completed successfully.
Definition: dcf-manager.cc:638
uint32_t m_backoffSlots
Definition: dcf-manager.h:203
PhyListener * m_phyListener
Definition: dcf-manager.h:494
Time GetAccessGrantStart(void) const
Access will never be granted to the medium before the time returned by this method.
Definition: dcf-manager.cc:511
Time GetBackoffEndFor(DcfState *state)
Return the time when the backoff procedure ended (or will ended) for the given DcfState.
Definition: dcf-manager.cc:560
void NotifyTxStartNow(Time duration)
Definition: dcf-manager.cc:656
void NotifyAckTimeoutStartNow(Time duration)
Notify that ACK timer has started for the given duration.
Definition: dcf-manager.cc:779
void SetupPhyListener(Ptr< WifiPhy > phy)
Set up listener for Phy events.
Definition: dcf-manager.cc:295
Manage a set of ns3::DcfStateHandle a set of independent ns3::DcfState, each of which represents a si...
Definition: dcf-manager.h:229
keep track of the state needed for a single DCF function.
Definition: dcf-manager.h:46
bool IsAccessRequested(void) const
Definition: dcf-manager.cc:133
Listener for PHY events.
Definition: dcf-manager.cc:215
uint32_t GetBackoffSlots(void) const
Return the current number of backoff slots.
Definition: dcf-manager.cc:123
virtual ~DcfState()
Definition: dcf-manager.cc:52
uint32_t GetCwMax(void) const
Return the maximum congestion window size.
Definition: dcf-manager.cc:84
Time m_lastBusyDuration
Definition: dcf-manager.h:486
void SetCwMin(uint32_t minCw)
Set the minimum congestion window size.
Definition: dcf-manager.cc:62
void StartBackoffNow(uint32_t nSlots)
Definition: dcf-manager.cc:109
uint32_t m_cwMax
Definition: dcf-manager.h:209
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:472
void NotifyAccessRequested(void)
Notify that access request has been received.
Definition: dcf-manager.cc:138
void NotifyRxEndErrorNow(void)
Notify the DCF that a packet reception was just completed unsuccessfully.
Definition: dcf-manager.cc:647
uint32_t m_cw
Definition: dcf-manager.h:210
Time m_lastSwitchingStart
Definition: dcf-manager.h:487
void SetEifsNoDifs(Time eifsNoDifs)
Definition: dcf-manager.cc:330
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:676
void AccessTimeout(void)
Called when access timeout should occur (e.g.
Definition: dcf-manager.cc:502
virtual void DoNotifyChannelSwitching()=0
Called by DcfManager to notify a DcfState subclass that a channel switching occured.
Time m_lastNavDuration
Definition: dcf-manager.h:478
void SetSlot(Time slotTime)
Definition: dcf-manager.cc:318
void SetCwMax(uint32_t maxCw)
Set the maximum congestion window size.
Definition: dcf-manager.cc:68
void NotifyAckTimeoutResetNow()
Notify that ACK timer has resetted.
Definition: dcf-manager.cc:786
LowDcfListener * m_lowListener
Definition: dcf-manager.h:495
void NotifyNavStartNow(Time duration)
Definition: dcf-manager.cc:764
an identifier for simulation events.
Definition: event-id.h:46
void NotifyChannelSwitching(void)
Notify that the device is switching channel.
Definition: dcf-manager.cc:160
uint32_t GetCw(void) const
Definition: dcf-manager.cc:118
uint32_t GetAifsn(void) const
Return the number of slots that make up an AIFS.
Definition: dcf-manager.cc:74
uint32_t m_aifsn
Definition: dcf-manager.h:202
void NotifyRxStartNow(Time duration)
Definition: dcf-manager.cc:628
void UpdateBackoffSlotsNow(uint32_t nSlots, Time backoffUpdateBound)
Update backoff slots that nSlots has passed.
Definition: dcf-manager.cc:101
Time GetEifsNoDifs() const
Definition: dcf-manager.cc:336
void NotifyCtsTimeoutResetNow()
Notify that CTS timer has resetted.
Definition: dcf-manager.cc:799
void NotifyCollision(void)
Notify that collision has occurred.
Definition: dcf-manager.cc:150
bool IsBusy(void) const
Check if the device is busy sending or receiving, or NAV busy.
Definition: dcf-manager.cc:399
Time m_backoffStart
Definition: dcf-manager.h:207
void DoRestartAccessTimeoutIfNeeded(void)
Definition: dcf-manager.cc:588
EventId m_accessTimeout
Definition: dcf-manager.h:491
void UpdateFailedCw(void)
Update the value of the CW variable to take into account a transmission failure.
Definition: dcf-manager.cc:95
Listener for NAV events.
Definition: dcf-manager.cc:169
void NotifySwitchingStartNow(Time duration)
Definition: dcf-manager.cc:687
uint32_t m_slotTimeUs
Definition: dcf-manager.h:492
Time MostRecent(Time a, Time b) const
Return the most recent time.
Definition: dcf-manager.cc:350
void SetSifs(Time sifs)
Definition: dcf-manager.cc:324