A Discrete-Event Network Simulator
API
txop.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 
20 #ifndef TXOP_H
21 #define TXOP_H
22 
23 #include "wifi-mac-header.h"
24 
25 #include "ns3/nstime.h"
26 #include "ns3/object.h"
27 #include "ns3/traced-value.h"
28 
29 #include <memory>
30 #include <vector>
31 
32 namespace ns3
33 {
34 
35 class Packet;
36 class ChannelAccessManager;
37 class MacTxMiddle;
38 class WifiMode;
39 class WifiMacQueue;
40 class WifiMpdu;
41 class UniformRandomVariable;
42 class CtrlBAckResponseHeader;
43 class WifiMac;
44 enum WifiMacDropReason : uint8_t; // opaque enum declaration
45 
70 class Txop : public Object
71 {
72  public:
73  Txop();
74 
80  Txop(Ptr<WifiMacQueue> queue);
81 
82  ~Txop() override;
83 
88  static TypeId GetTypeId();
89 
94 
99  {
102  GRANTED
103  };
104 
110  virtual bool IsQosTxop() const;
111 
117  virtual void SetWifiMac(const Ptr<WifiMac> mac);
123  void SetTxMiddle(const Ptr<MacTxMiddle> txMiddle);
124 
128  virtual void SetDroppedMpduCallback(DroppedMpdu callback);
129 
136 
143  void SetMinCw(uint32_t minCw);
151  void SetMinCws(std::vector<uint32_t> minCws);
158  void SetMinCw(uint32_t minCw, uint8_t linkId);
165  void SetMaxCw(uint32_t maxCw);
173  void SetMaxCws(std::vector<uint32_t> maxCws);
180  void SetMaxCw(uint32_t maxCw, uint8_t linkId);
187  void SetAifsn(uint8_t aifsn);
195  void SetAifsns(std::vector<uint8_t> aifsns);
202  void SetAifsn(uint8_t aifsn, uint8_t linkId);
209  void SetTxopLimit(Time txopLimit);
217  void SetTxopLimits(const std::vector<Time>& txopLimits);
225  void SetTxopLimit(Time txopLimit, uint8_t linkId);
232  uint32_t GetMinCw() const;
238  std::vector<uint32_t> GetMinCws() const;
245  virtual uint32_t GetMinCw(uint8_t linkId) const;
252  uint32_t GetMaxCw() const;
258  std::vector<uint32_t> GetMaxCws() const;
265  virtual uint32_t GetMaxCw(uint8_t linkId) const;
272  uint8_t GetAifsn() const;
278  std::vector<uint8_t> GetAifsns() const;
285  virtual uint8_t GetAifsn(uint8_t linkId) const;
291  Time GetTxopLimit() const;
297  std::vector<Time> GetTxopLimits() const;
304  Time GetTxopLimit(uint8_t linkId) const;
313  void ResetCw(uint8_t linkId);
321  void UpdateFailedCw(uint8_t linkId);
322 
328  virtual void NotifySleep(uint8_t linkId);
332  virtual void NotifyOff();
339  virtual void NotifyWakeUp(uint8_t linkId);
343  virtual void NotifyOn();
344 
345  /* Event handlers */
353  virtual void Queue(Ptr<Packet> packet, const WifiMacHeader& hdr);
360  virtual void Queue(Ptr<WifiMpdu> mpdu);
361 
369  virtual void NotifyChannelAccessed(uint8_t linkId, Time txopDuration = Seconds(0));
376  virtual void NotifyChannelReleased(uint8_t linkId);
377 
387  int64_t AssignStreams(int64_t stream);
388 
393  virtual ChannelAccessStatus GetAccessStatus(uint8_t linkId) const;
394 
402  void StartBackoffNow(uint32_t nSlots, uint8_t linkId);
403 
404  protected:
406  friend class ChannelAccessManager;
407 
408  void DoDispose() override;
409  void DoInitialize() override;
410 
411  /* Txop notifications forwarded here */
417  virtual void NotifyAccessRequested(uint8_t linkId);
418 
424  virtual bool HasFramesToTransmit(uint8_t linkId);
430  virtual void GenerateBackoff(uint8_t linkId);
436  virtual void StartAccessIfNeeded(uint8_t linkId);
442  void RequestAccess(uint8_t linkId);
443 
451  uint32_t GetCw(uint8_t linkId) const;
458  uint32_t GetBackoffSlots(uint8_t linkId) const;
465  Time GetBackoffStart(uint8_t linkId) const;
473  void UpdateBackoffSlotsNow(uint32_t nSlots, Time backoffUpdateBound, uint8_t linkId);
474 
480  struct LinkEntity
481  {
483  virtual ~LinkEntity() = default;
484 
485  uint8_t id{0};
486  uint32_t backoffSlots{0};
491  uint32_t cw{0};
492  uint32_t cwMin{0};
493  uint32_t cwMax{0};
494  uint8_t aifsn{0};
497  };
498 
505  LinkEntity& GetLink(uint8_t linkId) const;
511  uint8_t GetNLinks() const;
512 
518 
520  typedef TracedCallback<uint32_t /* value */, uint8_t /* linkId */> BackoffValueTracedCallback;
522  typedef TracedCallback<uint32_t /* value */, uint8_t /* linkId */> CwValueTracedCallback;
523 
526 
527  private:
533  virtual std::unique_ptr<LinkEntity> CreateLinkEntity() const;
534 
535  std::vector<std::unique_ptr<LinkEntity>> m_links;
536 };
537 
538 } // namespace ns3
539 
540 #endif /* TXOP_H */
Callback template class.
Definition: callback.h:443
Manage a set of ns3::Txop.
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Forward calls to a chain of Callback.
Handle packet fragmentation and retransmissions for data and management frames.
Definition: txop.h:71
virtual void StartAccessIfNeeded(uint8_t linkId)
Request access from Txop on the given link if needed.
Definition: txop.cc:544
Ptr< WifiMac > m_mac
the wifi MAC
Definition: txop.h:516
Time GetTxopLimit() const
Return the TXOP limit.
Definition: txop.cc:473
virtual std::unique_ptr< LinkEntity > CreateLinkEntity() const
Create a LinkEntity object.
Definition: txop.cc:168
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: txop.cc:536
virtual ChannelAccessStatus GetAccessStatus(uint8_t linkId) const
Definition: txop.cc:565
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
Definition: txop.h:514
virtual bool HasFramesToTransmit(uint8_t linkId)
Check if the Txop has frames to transmit over the given link.
Definition: txop.cc:496
virtual void NotifyOff()
When off operation occurs, the queue gets cleaned up.
Definition: txop.cc:622
Ptr< UniformRandomVariable > m_rng
the random stream
Definition: txop.h:517
CwValueTracedCallback m_cwTrace
CW trace value.
Definition: txop.h:525
void DoDispose() override
Destructor implementation.
Definition: txop.cc:157
void SetMaxCw(uint32_t maxCw)
Set the maximum contention window size.
Definition: txop.cc:256
uint32_t GetMinCw() const
Return the minimum contention window size.
Definition: txop.cc:404
ChannelAccessStatus
Enumeration for channel access status.
Definition: txop.h:99
@ GRANTED
Definition: txop.h:102
@ NOT_REQUESTED
Definition: txop.h:100
@ REQUESTED
Definition: txop.h:101
virtual void NotifyOn()
When on operation occurs, channel access will be started.
Definition: txop.cc:636
void UpdateFailedCw(uint8_t linkId)
Update the value of the CW variable for the given link to take into account a transmission failure.
Definition: txop.cc:300
Ptr< WifiMacQueue > GetWifiMacQueue() const
Return the packet queue associated with this Txop.
Definition: txop.cc:220
virtual void SetWifiMac(const Ptr< WifiMac > mac)
Set the wifi MAC this Txop is associated to.
Definition: txop.cc:195
virtual void NotifyWakeUp(uint8_t linkId)
When wake up operation occurs on a link, channel access on that link will be restarted.
Definition: txop.cc:629
virtual void NotifyChannelReleased(uint8_t linkId)
Called by the FrameExchangeManager to notify the completion of the transmissions.
Definition: txop.cc:585
std::vector< uint32_t > GetMaxCws() const
Return the maximum contention window size for each link.
Definition: txop.cc:433
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
Definition: txop.cc:376
TracedCallback< uint32_t, uint8_t > BackoffValueTracedCallback
TracedCallback for backoff trace value typedef.
Definition: txop.h:520
void ResetCw(uint8_t linkId)
Update the value of the CW variable for the given link to take into account a transmission success or...
Definition: txop.cc:291
Txop()
Definition: txop.cc:139
LinkEntity & GetLink(uint8_t linkId) const
Get a reference to the link associated with the given ID.
Definition: txop.cc:174
virtual bool IsQosTxop() const
Check for QoS TXOP.
Definition: txop.cc:646
std::vector< uint32_t > GetMinCws() const
Return the minimum contention window size for each link.
Definition: txop.cc:410
std::vector< uint8_t > GetAifsns() const
Return the number of slots that make up an AIFS for each link.
Definition: txop.cc:456
void UpdateBackoffSlotsNow(uint32_t nSlots, Time backoffUpdateBound, uint8_t linkId)
Update backoff slots for the given link that nSlots has passed.
Definition: txop.cc:324
TracedCallback< uint32_t, uint8_t > CwValueTracedCallback
TracedCallback for CW trace value typedef.
Definition: txop.h:522
Time GetBackoffStart(uint8_t linkId) const
Return the time when the backoff procedure started on the given link.
Definition: txop.cc:318
void SetMaxCws(std::vector< uint32_t > maxCws)
Set the maximum contention window size for each link.
Definition: txop.cc:262
void SetTxopLimits(const std::vector< Time > &txopLimits)
Set the TXOP limit for each link.
Definition: txop.cc:382
DroppedMpdu m_droppedMpduCallback
the dropped MPDU callback
Definition: txop.h:513
void SetTxMiddle(const Ptr< MacTxMiddle > txMiddle)
Set MacTxMiddle this Txop is associated to.
Definition: txop.cc:188
std::vector< std::unique_ptr< LinkEntity > > m_links
vector of LinkEntity objects
Definition: txop.h:535
std::vector< Time > GetTxopLimits() const
Return the TXOP limit for each link.
Definition: txop.cc:479
static TypeId GetTypeId()
Get the type ID.
Definition: txop.cc:51
void SetAifsn(uint8_t aifsn)
Set the number of slots that make up an AIFS.
Definition: txop.cc:353
uint32_t GetCw(uint8_t linkId) const
Get the current value of the CW variable for the given link.
Definition: txop.cc:285
void SetMinCws(std::vector< uint32_t > minCws)
Set the minimum contention window size for each link.
Definition: txop.cc:233
virtual void SetDroppedMpduCallback(DroppedMpdu callback)
Definition: txop.cc:209
virtual void GenerateBackoff(uint8_t linkId)
Generate a new backoff for the given link now.
Definition: txop.cc:607
BackoffValueTracedCallback m_backoffTrace
backoff trace value
Definition: txop.h:524
virtual void NotifyAccessRequested(uint8_t linkId)
Notify that access request has been received for the given link.
Definition: txop.cc:571
void SetAifsns(std::vector< uint8_t > aifsns)
Set the number of slots that make up an AIFS for each link.
Definition: txop.cc:359
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
Definition: txop.h:515
~Txop() override
Definition: txop.cc:151
void StartBackoffNow(uint32_t nSlots, uint8_t linkId)
Definition: txop.cc:335
virtual void NotifyChannelAccessed(uint8_t linkId, Time txopDuration=Seconds(0))
Called by the FrameExchangeManager to notify that channel access has been granted on the given link f...
Definition: txop.cc:578
void RequestAccess(uint8_t linkId)
Request access to the ChannelAccessManager associated with the given link.
Definition: txop.cc:597
void SetMinCw(uint32_t minCw)
Set the minimum contention window size.
Definition: txop.cc:227
uint8_t GetAifsn() const
Return the number of slots that make up an AIFS.
Definition: txop.cc:450
uint32_t GetBackoffSlots(uint8_t linkId) const
Return the current number of backoff slots on the given link.
Definition: txop.cc:312
virtual void Queue(Ptr< Packet > packet, const WifiMacHeader &hdr)
Definition: txop.cc:505
virtual void NotifySleep(uint8_t linkId)
Notify that the given link switched to sleep mode.
Definition: txop.cc:616
uint32_t GetMaxCw() const
Return the maximum contention window size.
Definition: txop.cc:427
Callback< void, WifiMacDropReason, Ptr< const WifiMpdu > > DroppedMpdu
typedef for a callback to invoke when an MPDU is dropped.
Definition: txop.h:93
uint8_t GetNLinks() const
Get the number of links.
Definition: txop.cc:182
void DoInitialize() override
Initialize() implementation.
Definition: txop.cc:554
a unique identifier for an interface.
Definition: type-id.h:60
Implements the IEEE 802.11 MAC header.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
WifiMacDropReason
The reason why an MPDU was dropped.
Definition: wifi-mac.h:75
Every class exported by the ns3 library is enclosed in the ns3 namespace.
mac
Definition: third.py:85