A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
51  virtual ~DcfState ();
52 
59  void SetAifsn (uint32_t aifsn);
60  void SetCwMin (uint32_t minCw);
61  void SetCwMax (uint32_t maxCw);
62  uint32_t GetAifsn (void) const;
63  uint32_t GetCwMin (void) const;
64  uint32_t GetCwMax (void) const;
71  void ResetCw (void);
77  void UpdateFailedCw (void);
84  void StartBackoffNow (uint32_t nSlots);
89  uint32_t GetCw (void) const;
94  bool IsAccessRequested (void) const;
95 
96 private:
97  friend class DcfManager;
98 
99  uint32_t GetBackoffSlots (void) const;
100  Time GetBackoffStart (void) const;
101  void UpdateBackoffSlotsNow (uint32_t nSlots, Time backoffUpdateBound);
102  void NotifyAccessRequested (void);
103  void NotifyAccessGranted (void);
104  void NotifyCollision (void);
105  void NotifyInternalCollision (void);
106  void NotifyChannelSwitching (void);
107 
108 
114  virtual void DoNotifyAccessGranted (void) = 0;
126  virtual void DoNotifyInternalCollision (void) = 0;
136  virtual void DoNotifyCollision (void) = 0;
144  virtual void DoNotifyChannelSwitching () = 0;
145 
146  uint32_t m_aifsn;
147  uint32_t m_backoffSlots;
148  // the backoffStart variable is used to keep track of the
149  // time at which a backoff was started or the time at which
150  // the backoff counter was last updated.
152  uint32_t m_cwMin;
153  uint32_t m_cwMax;
154  uint32_t m_cw;
156 };
157 
174 {
175 public:
176  DcfManager ();
177  ~DcfManager ();
178 
179  void SetupPhyListener (Ptr<WifiPhy> phy);
180  void SetupLowListener (Ptr<MacLow> low);
181 
188  void SetSlot (Time slotTime);
195  void SetSifs (Time sifs);
196 
203  void SetEifsNoDifs (Time eifsNoDifs);
204 
208  Time GetEifsNoDifs () const;
209 
220  void Add (DcfState *dcf);
221 
230  void RequestAccess (DcfState *state);
231 
238  void NotifyRxStartNow (Time duration);
243  void NotifyRxEndOkNow (void);
248  void NotifyRxEndErrorNow (void);
256  void NotifyTxStartNow (Time duration);
262  void NotifyMaybeCcaBusyStartNow (Time duration);
270  void NotifySwitchingStartNow (Time duration);
276  void NotifyNavResetNow (Time duration);
282  void NotifyNavStartNow (Time duration);
283  void NotifyAckTimeoutStartNow (Time duration);
284  void NotifyAckTimeoutResetNow ();
285  void NotifyCtsTimeoutStartNow (Time duration);
286  void NotifyCtsTimeoutResetNow ();
287 private:
288  void UpdateBackoff (void);
289  Time MostRecent (Time a, Time b) const;
290  Time MostRecent (Time a, Time b, Time c) const;
291  Time MostRecent (Time a, Time b, Time c, Time d) const;
292  Time MostRecent (Time a, Time b, Time c, Time d, Time e, Time f) const;
293  Time MostRecent (Time a, Time b, Time c, Time d, Time e, Time f, Time g) const;
301  Time GetAccessGrantStart (void) const;
303  Time GetBackoffEndFor (DcfState *state);
304  void DoRestartAccessTimeoutIfNeeded (void);
305  void AccessTimeout (void);
306  void DoGrantAccess (void);
307  bool IsBusy (void) const;
308 
309  typedef std::vector<DcfState *> States;
310 
326  bool m_rxing;
330  uint32_t m_slotTimeUs;
334 };
335 
336 } // namespace ns3
337 
338 #endif /* DCF_MANAGER_H */