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 <map>
30 #include <memory>
31 #include <vector>
32 
33 class EmlsrUlTxopTest;
34 
35 namespace ns3
36 {
37 
38 class Packet;
39 class ChannelAccessManager;
40 class MacTxMiddle;
41 class WifiMode;
42 class WifiMacQueue;
43 class WifiMpdu;
44 class UniformRandomVariable;
45 class CtrlBAckResponseHeader;
46 class WifiMac;
47 enum WifiMacDropReason : uint8_t; // opaque enum declaration
48 
73 class Txop : public Object
74 {
75  public:
76  Txop();
77 
83  Txop(Ptr<WifiMacQueue> queue);
84 
85  ~Txop() override;
86 
91  static TypeId GetTypeId();
92 
97 
102  {
105  GRANTED
106  };
107 
113  virtual bool IsQosTxop() const;
114 
120  virtual void SetWifiMac(const Ptr<WifiMac> mac);
126  void SetTxMiddle(const Ptr<MacTxMiddle> txMiddle);
127 
131  virtual void SetDroppedMpduCallback(DroppedMpdu callback);
132 
139 
146  void SetMinCw(uint32_t minCw);
154  void SetMinCws(std::vector<uint32_t> minCws);
161  void SetMinCw(uint32_t minCw, uint8_t linkId);
168  void SetMaxCw(uint32_t maxCw);
176  void SetMaxCws(std::vector<uint32_t> maxCws);
183  void SetMaxCw(uint32_t maxCw, uint8_t linkId);
190  void SetAifsn(uint8_t aifsn);
198  void SetAifsns(std::vector<uint8_t> aifsns);
205  void SetAifsn(uint8_t aifsn, uint8_t linkId);
212  void SetTxopLimit(Time txopLimit);
220  void SetTxopLimits(const std::vector<Time>& txopLimits);
228  void SetTxopLimit(Time txopLimit, uint8_t linkId);
235  uint32_t GetMinCw() const;
241  std::vector<uint32_t> GetMinCws() const;
248  virtual uint32_t GetMinCw(uint8_t linkId) const;
255  uint32_t GetMaxCw() const;
261  std::vector<uint32_t> GetMaxCws() const;
268  virtual uint32_t GetMaxCw(uint8_t linkId) const;
275  uint8_t GetAifsn() const;
281  std::vector<uint8_t> GetAifsns() const;
288  virtual uint8_t GetAifsn(uint8_t linkId) const;
294  Time GetTxopLimit() const;
300  std::vector<Time> GetTxopLimits() const;
307  Time GetTxopLimit(uint8_t linkId) const;
316  void ResetCw(uint8_t linkId);
324  void UpdateFailedCw(uint8_t linkId);
325 
331  virtual void NotifySleep(uint8_t linkId);
335  virtual void NotifyOff();
342  virtual void NotifyWakeUp(uint8_t linkId);
346  virtual void NotifyOn();
347 
348  /* Event handlers */
356  virtual void Queue(Ptr<Packet> packet, const WifiMacHeader& hdr);
363  virtual void Queue(Ptr<WifiMpdu> mpdu);
364 
372  virtual void NotifyChannelAccessed(uint8_t linkId, Time txopDuration = Seconds(0));
379  virtual void NotifyChannelReleased(uint8_t linkId);
380 
390  int64_t AssignStreams(int64_t stream);
391 
396  virtual ChannelAccessStatus GetAccessStatus(uint8_t linkId) const;
397 
413  void StartAccessAfterEvent(uint8_t linkId, bool hadFramesToTransmit, bool checkMediumBusy);
414 
415  static constexpr bool HAD_FRAMES_TO_TRANSMIT =
416  true;
417  static constexpr bool DIDNT_HAVE_FRAMES_TO_TRANSMIT =
418  false;
419  static constexpr bool CHECK_MEDIUM_BUSY =
420  true;
421  static constexpr bool DONT_CHECK_MEDIUM_BUSY =
422  false;
423 
431  void StartBackoffNow(uint32_t nSlots, uint8_t linkId);
432 
438  virtual bool HasFramesToTransmit(uint8_t linkId);
439 
448  void SwapLinks(std::map<uint8_t, uint8_t> links);
449 
450  protected:
452  friend class ChannelAccessManager;
453  friend class ::EmlsrUlTxopTest;
454 
455  void DoDispose() override;
456  void DoInitialize() override;
457 
458  /* Txop notifications forwarded here */
464  virtual void NotifyAccessRequested(uint8_t linkId);
465 
471  virtual void GenerateBackoff(uint8_t linkId);
477  void RequestAccess(uint8_t linkId);
478 
486  uint32_t GetCw(uint8_t linkId) const;
493  uint32_t GetBackoffSlots(uint8_t linkId) const;
500  Time GetBackoffStart(uint8_t linkId) const;
508  void UpdateBackoffSlotsNow(uint32_t nSlots, Time backoffUpdateBound, uint8_t linkId);
509 
515  struct LinkEntity
516  {
518  virtual ~LinkEntity() = default;
519 
520  uint32_t backoffSlots{0};
525  uint32_t cw{0};
526  uint32_t cwMin{0};
527  uint32_t cwMax{0};
528  uint8_t aifsn{0};
531 
532  mutable class
533  {
534  friend void Txop::Queue(Ptr<WifiMpdu>);
537  };
538 
545  LinkEntity& GetLink(uint8_t linkId) const;
546 
550  const std::map<uint8_t, std::unique_ptr<LinkEntity>>& GetLinks() const;
551 
557 
559  typedef TracedCallback<uint32_t /* value */, uint8_t /* linkId */> BackoffValueTracedCallback;
561  typedef TracedCallback<uint32_t /* value */, uint8_t /* linkId */> CwValueTracedCallback;
562 
565 
566  private:
572  virtual std::unique_ptr<LinkEntity> CreateLinkEntity() const;
573 
574  std::map<uint8_t, std::unique_ptr<LinkEntity>>
576 };
577 
578 } // namespace ns3
579 
580 #endif /* TXOP_H */
Test the transmission of UL frames from EMLSR clients.
Callback template class.
Definition: callback.h:438
Manage a set of ns3::Txop.
An identifier for simulation events.
Definition: event-id.h:55
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:77
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:74
Ptr< WifiMac > m_mac
the wifi MAC
Definition: txop.h:555
Time GetTxopLimit() const
Return the TXOP limit.
Definition: txop.cc:490
virtual std::unique_ptr< LinkEntity > CreateLinkEntity() const
Create a LinkEntity object.
Definition: txop.cc:164
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: txop.cc:564
virtual ChannelAccessStatus GetAccessStatus(uint8_t linkId) const
Definition: txop.cc:604
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
Definition: txop.h:553
void StartAccessAfterEvent(uint8_t linkId, bool hadFramesToTransmit, bool checkMediumBusy)
Request channel access on the given link after the occurrence of an event that possibly requires to g...
Definition: txop.cc:572
virtual bool HasFramesToTransmit(uint8_t linkId)
Check if the Txop has frames to transmit over the given link.
Definition: txop.cc:514
virtual void NotifyOff()
When off operation occurs, the queue gets cleaned up.
Definition: txop.cc:661
Ptr< UniformRandomVariable > m_rng
the random stream
Definition: txop.h:556
CwValueTracedCallback m_cwTrace
CW trace value.
Definition: txop.h:564
void DoDispose() override
Destructor implementation.
Definition: txop.cc:153
void SetMaxCw(uint32_t maxCw)
Set the maximum contention window size.
Definition: txop.cc:267
uint32_t GetMinCw() const
Return the minimum contention window size.
Definition: txop.cc:418
ChannelAccessStatus
Enumeration for channel access status.
Definition: txop.h:102
@ GRANTED
Definition: txop.h:105
@ NOT_REQUESTED
Definition: txop.h:103
@ REQUESTED
Definition: txop.h:104
virtual void NotifyOn()
When on operation occurs, channel access will be started.
Definition: txop.cc:676
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:312
static constexpr bool DIDNT_HAVE_FRAMES_TO_TRANSMIT
no packet available for transmission was in the queue
Definition: txop.h:417
Ptr< WifiMacQueue > GetWifiMacQueue() const
Return the packet queue associated with this Txop.
Definition: txop.cc:231
virtual void SetWifiMac(const Ptr< WifiMac > mac)
Set the wifi MAC this Txop is associated to.
Definition: txop.cc:209
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:668
virtual void NotifyChannelReleased(uint8_t linkId)
Called by the FrameExchangeManager to notify the completion of the transmissions.
Definition: txop.cc:624
std::vector< uint32_t > GetMaxCws() const
Return the maximum contention window size for each link.
Definition: txop.cc:448
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
Definition: txop.cc:389
TracedCallback< uint32_t, uint8_t > BackoffValueTracedCallback
TracedCallback for backoff trace value typedef.
Definition: txop.h:559
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:303
Txop()
Definition: txop.cc:135
LinkEntity & GetLink(uint8_t linkId) const
Get a reference to the link associated with the given ID.
Definition: txop.cc:170
virtual bool IsQosTxop() const
Check for QoS TXOP.
Definition: txop.cc:687
std::vector< uint32_t > GetMinCws() const
Return the minimum contention window size for each link.
Definition: txop.cc:424
std::vector< uint8_t > GetAifsns() const
Return the number of slots that make up an AIFS for each link.
Definition: txop.cc:472
void UpdateBackoffSlotsNow(uint32_t nSlots, Time backoffUpdateBound, uint8_t linkId)
Update backoff slots for the given link that nSlots has passed.
Definition: txop.cc:336
TracedCallback< uint32_t, uint8_t > CwValueTracedCallback
TracedCallback for CW trace value typedef.
Definition: txop.h:561
Time GetBackoffStart(uint8_t linkId) const
Return the time when the backoff procedure started on the given link.
Definition: txop.cc:330
void SetMaxCws(std::vector< uint32_t > maxCws)
Set the maximum contention window size for each link.
Definition: txop.cc:273
void SetTxopLimits(const std::vector< Time > &txopLimits)
Set the TXOP limit for each link.
Definition: txop.cc:395
DroppedMpdu m_droppedMpduCallback
the dropped MPDU callback
Definition: txop.h:552
void SwapLinks(std::map< uint8_t, uint8_t > links)
Swap the links based on the information included in the given map.
Definition: txop.cc:185
void SetTxMiddle(const Ptr< MacTxMiddle > txMiddle)
Set MacTxMiddle this Txop is associated to.
Definition: txop.cc:202
std::vector< Time > GetTxopLimits() const
Return the TXOP limit for each link.
Definition: txop.cc:496
const std::map< uint8_t, std::unique_ptr< LinkEntity > > & GetLinks() const
Definition: txop.cc:179
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:365
uint32_t GetCw(uint8_t linkId) const
Get the current value of the CW variable for the given link.
Definition: txop.cc:297
void SetMinCws(std::vector< uint32_t > minCws)
Set the minimum contention window size for each link.
Definition: txop.cc:243
virtual void SetDroppedMpduCallback(DroppedMpdu callback)
Definition: txop.cc:220
virtual void GenerateBackoff(uint8_t linkId)
Generate a new backoff for the given link now.
Definition: txop.cc:646
BackoffValueTracedCallback m_backoffTrace
backoff trace value
Definition: txop.h:563
virtual void NotifyAccessRequested(uint8_t linkId)
Notify that access request has been received for the given link.
Definition: txop.cc:610
void SetAifsns(std::vector< uint8_t > aifsns)
Set the number of slots that make up an AIFS for each link.
Definition: txop.cc:371
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
Definition: txop.h:554
static constexpr bool CHECK_MEDIUM_BUSY
generation of backoff (also) depends on the busy/idle state of the medium
Definition: txop.h:419
~Txop() override
Definition: txop.cc:147
void StartBackoffNow(uint32_t nSlots, uint8_t linkId)
Definition: txop.cc:347
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:617
std::map< uint8_t, std::unique_ptr< LinkEntity > > m_links
ID-indexed map of LinkEntity objects.
Definition: txop.h:575
void RequestAccess(uint8_t linkId)
Request access to the ChannelAccessManager associated with the given link.
Definition: txop.cc:636
void SetMinCw(uint32_t minCw)
Set the minimum contention window size.
Definition: txop.cc:237
uint8_t GetAifsn() const
Return the number of slots that make up an AIFS.
Definition: txop.cc:466
uint32_t GetBackoffSlots(uint8_t linkId) const
Return the current number of backoff slots on the given link.
Definition: txop.cc:324
virtual void Queue(Ptr< Packet > packet, const WifiMacHeader &hdr)
Definition: txop.cc:523
virtual void NotifySleep(uint8_t linkId)
Notify that the given link switched to sleep mode.
Definition: txop.cc:655
static constexpr bool DONT_CHECK_MEDIUM_BUSY
generation of backoff is independent of the busy/idle state of the medium
Definition: txop.h:421
uint32_t GetMaxCw() const
Return the maximum contention window size.
Definition: txop.cc:442
static constexpr bool HAD_FRAMES_TO_TRANSMIT
packets available for transmission were in the queue
Definition: txop.h:415
Callback< void, WifiMacDropReason, Ptr< const WifiMpdu > > DroppedMpdu
typedef for a callback to invoke when an MPDU is dropped.
Definition: txop.h:96
void DoInitialize() override
Initialize() implementation.
Definition: txop.cc:593
a unique identifier for an interface.
Definition: type-id.h:59
Implements the IEEE 802.11 MAC header.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
WifiMacDropReason
The reason why an MPDU was dropped.
Definition: wifi-mac.h:77
Every class exported by the ns3 library is enclosed in the ns3 namespace.
mac
Definition: third.py:92