A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dcf-manager.h
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 (Time duration, uint16_t toChannel);
107  void NotifyChannelSensing (void);
108 
109 
115  virtual void DoNotifyAccessGranted (void) = 0;
127  virtual void DoNotifyInternalCollision (void) = 0;
137  virtual void DoNotifyCollision (void) = 0;
145  virtual void DoNotifyChannelSwitching (Time duration, uint16_t toChannel) = 0;
146  virtual void DoNotifyChannelSensing () = 0;
147 
148  uint32_t m_aifsn;
149  uint32_t m_backoffSlots;
150  // the backoffStart variable is used to keep track of the
151  // time at which a backoff was started or the time at which
152  // the backoff counter was last updated.
153  Time m_backoffStart;
154  uint32_t m_cwMin;
155  uint32_t m_cwMax;
156  uint32_t m_cw;
157  bool m_accessRequested;
158 };
159 
176 {
177 public:
178  DcfManager ();
179  ~DcfManager ();
180 
181  void SetupPhyListener (Ptr<WifiPhy> phy);
182  void SetupLowListener (Ptr<MacLow> low);
183 
190  void SetSlot (Time slotTime);
197  void SetSifs (Time sifs);
198 
205  void SetEifsNoDifs (Time eifsNoDifs);
206 
210  Time GetEifsNoDifs () const;
211 
222  void Add (DcfState *dcf);
223 
232  void RequestAccess (DcfState *state);
233 
240  void NotifyRxStartNow (Time duration);
245  void NotifyRxEndOkNow (void);
250  void NotifyRxEndErrorNow (void);
258  void NotifyTxStartNow (Time duration);
264  void NotifyMaybeCcaBusyStartNow (Time duration);
272  void NotifySwitchingStartNow (Time duration, uint16_t toChannel);
273  void NotifySensingStartNow (Time duration);
279  void NotifyNavResetNow (Time duration);
285  void NotifyNavStartNow (Time duration);
286  void NotifyAckTimeoutStartNow (Time duration);
287  void NotifyAckTimeoutResetNow ();
288  void NotifyCtsTimeoutStartNow (Time duration);
289  void NotifyCtsTimeoutResetNow ();
290 private:
291  void UpdateBackoff (void);
292  Time MostRecent (Time a, Time b) const;
293  Time MostRecent (Time a, Time b, Time c) const;
294  Time MostRecent (Time a, Time b, Time c, Time d) const;
295  Time MostRecent (Time a, Time b, Time c, Time d, Time e, Time f) const;
296  Time MostRecent (Time a, Time b, Time c, Time d, Time e, Time f, Time g, Time h) const;
304  Time GetAccessGrantStart (void) const;
305  Time GetBackoffStartFor (DcfState *state);
306  Time GetBackoffEndFor (DcfState *state);
307  void DoRestartAccessTimeoutIfNeeded (void);
308  void AccessTimeout (void);
309  void DoGrantAccess (void);
310  bool IsBusy (void) const;
311 
312  typedef std::vector<DcfState *> States;
313 
314  States m_states;
315  Time m_lastAckTimeoutEnd;
316  Time m_lastCtsTimeoutEnd;
317  Time m_lastNavStart;
318  Time m_lastNavDuration;
319  Time m_lastRxStart;
320  Time m_lastRxDuration;
321  bool m_lastRxReceivedOk;
322  Time m_lastRxEnd;
323  Time m_lastTxStart;
324  Time m_lastTxDuration;
325  Time m_lastBusyStart;
326  Time m_lastBusyDuration;
327  Time m_lastSwitchingStart;
328  Time m_lastSensingStart;
329  Time m_lastSwitchingDuration;
330  Time m_lastSensingDuration;
331  bool m_rxing;
332  bool m_sleeping;
333  Time m_eifsNoDifs;
334  EventId m_accessTimeout;
335  uint32_t m_slotTimeUs;
336  Time m_sifs;
337  PhyListener* m_phyListener;
338  LowDcfListener* m_lowListener;
339 };
340 
341 } // namespace ns3
342 
343 #endif /* DCF_MANAGER_H */
keep track of time unit.
Definition: nstime.h:149
void RequestAccess(DcfState *state)
Definition: dcf-manager.cc:419
virtual void DoNotifyCollision(void)=0
void SetAifsn(uint32_t aifsn)
Definition: dcf-manager.cc:57
void ResetCw(void)
Definition: dcf-manager.cc:90
void Add(DcfState *dcf)
Definition: dcf-manager.cc:338
void DoGrantAccess(void)
Definition: dcf-manager.cc:443
void NotifyNavResetNow(Time duration)
Definition: dcf-manager.cc:805
void NotifyRxEndOkNow(void)
Definition: dcf-manager.cc:636
Time GetAccessGrantStart(void) const
Definition: dcf-manager.cc:507
void NotifyTxStartNow(Time duration)
Definition: dcf-manager.cc:654
Manage a set of ns3::DcfStateHandle a set of independent ns3::DcfState, each of which represents a si...
Definition: dcf-manager.h:175
keep track of the state needed for a single DCF function.Multiple instances of a DcfState can be regi...
Definition: dcf-manager.h:46
bool IsAccessRequested(void) const
Definition: dcf-manager.cc:133
void StartBackoffNow(uint32_t nSlots)
Definition: dcf-manager.cc:109
virtual void DoNotifyAccessGranted(void)=0
void NotifyRxEndErrorNow(void)
Definition: dcf-manager.cc:645
virtual void DoNotifyChannelSwitching(Time duration, uint16_t toChannel)=0
void SetEifsNoDifs(Time eifsNoDifs)
Definition: dcf-manager.cc:325
virtual void DoNotifyInternalCollision(void)=0
void NotifyMaybeCcaBusyStartNow(Time duration)
Definition: dcf-manager.cc:674
void SetSlot(Time slotTime)
Definition: dcf-manager.cc:313
void NotifyNavStartNow(Time duration)
Definition: dcf-manager.cc:822
an identifier for simulation events.
Definition: event-id.h:46
uint32_t GetCw(void) const
Definition: dcf-manager.cc:118
void NotifyRxStartNow(Time duration)
Definition: dcf-manager.cc:626
Time GetEifsNoDifs() const
Definition: dcf-manager.cc:331
void DoRestartAccessTimeoutIfNeeded(void)
Definition: dcf-manager.cc:586
void UpdateFailedCw(void)
Definition: dcf-manager.cc:95
void NotifySwitchingStartNow(Time duration, uint16_t toChannel)
Definition: dcf-manager.cc:685
void SetSifs(Time sifs)
Definition: dcf-manager.cc:319