A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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
33namespace ns3
34{
35
36class Packet;
37class ChannelAccessManager;
38class MacTxMiddle;
39class WifiMode;
40class WifiMacQueue;
41class WifiMpdu;
42class UniformRandomVariable;
43class CtrlBAckResponseHeader;
44class WifiMac;
45enum WifiMacDropReason : uint8_t; // opaque enum declaration
46
71class Txop : public Object
72{
73 public:
74 Txop();
75
82
83 ~Txop() override;
84
89 static TypeId GetTypeId();
90
95
100 {
103 GRANTED
104 };
105
111 virtual bool IsQosTxop() const;
112
118 virtual void SetWifiMac(const Ptr<WifiMac> mac);
124 void SetTxMiddle(const Ptr<MacTxMiddle> txMiddle);
125
129 virtual void SetDroppedMpduCallback(DroppedMpdu callback);
130
137
144 void SetMinCw(uint32_t minCw);
152 void SetMinCws(std::vector<uint32_t> minCws);
159 void SetMinCw(uint32_t minCw, uint8_t linkId);
166 void SetMaxCw(uint32_t maxCw);
174 void SetMaxCws(std::vector<uint32_t> maxCws);
181 void SetMaxCw(uint32_t maxCw, uint8_t linkId);
188 void SetAifsn(uint8_t aifsn);
196 void SetAifsns(std::vector<uint8_t> aifsns);
203 void SetAifsn(uint8_t aifsn, uint8_t linkId);
210 void SetTxopLimit(Time txopLimit);
218 void SetTxopLimits(const std::vector<Time>& txopLimits);
226 void SetTxopLimit(Time txopLimit, uint8_t linkId);
233 uint32_t GetMinCw() const;
239 std::vector<uint32_t> GetMinCws() const;
246 virtual uint32_t GetMinCw(uint8_t linkId) const;
253 uint32_t GetMaxCw() const;
259 std::vector<uint32_t> GetMaxCws() const;
266 virtual uint32_t GetMaxCw(uint8_t linkId) const;
273 uint8_t GetAifsn() const;
279 std::vector<uint8_t> GetAifsns() const;
286 virtual uint8_t GetAifsn(uint8_t linkId) const;
292 Time GetTxopLimit() const;
298 std::vector<Time> GetTxopLimits() const;
305 Time GetTxopLimit(uint8_t linkId) const;
314 void ResetCw(uint8_t linkId);
322 void UpdateFailedCw(uint8_t linkId);
323
329 virtual void NotifySleep(uint8_t linkId);
333 virtual void NotifyOff();
340 virtual void NotifyWakeUp(uint8_t linkId);
344 virtual void NotifyOn();
345
346 /* Event handlers */
354 virtual void Queue(Ptr<Packet> packet, const WifiMacHeader& hdr);
361 virtual void Queue(Ptr<WifiMpdu> mpdu);
362
370 virtual void NotifyChannelAccessed(uint8_t linkId, Time txopDuration = Seconds(0));
377 virtual void NotifyChannelReleased(uint8_t linkId);
378
388 int64_t AssignStreams(int64_t stream);
389
394 virtual ChannelAccessStatus GetAccessStatus(uint8_t linkId) const;
395
403 void StartBackoffNow(uint32_t nSlots, uint8_t linkId);
404
410 virtual bool HasFramesToTransmit(uint8_t linkId);
411
420 void SwapLinks(std::map<uint8_t, uint8_t> links);
421
422 protected:
425
426 void DoDispose() override;
427 void DoInitialize() override;
428
429 /* Txop notifications forwarded here */
435 virtual void NotifyAccessRequested(uint8_t linkId);
436
442 virtual void GenerateBackoff(uint8_t linkId);
448 virtual void StartAccessIfNeeded(uint8_t linkId);
454 void RequestAccess(uint8_t linkId);
455
463 uint32_t GetCw(uint8_t linkId) const;
470 uint32_t GetBackoffSlots(uint8_t linkId) const;
477 Time GetBackoffStart(uint8_t linkId) const;
485 void UpdateBackoffSlotsNow(uint32_t nSlots, Time backoffUpdateBound, uint8_t linkId);
486
493 {
495 virtual ~LinkEntity() = default;
496
505 uint8_t aifsn{0};
508 };
509
516 LinkEntity& GetLink(uint8_t linkId) const;
517
521 const std::map<uint8_t, std::unique_ptr<LinkEntity>>& GetLinks() const;
522
528
530 typedef TracedCallback<uint32_t /* value */, uint8_t /* linkId */> BackoffValueTracedCallback;
532 typedef TracedCallback<uint32_t /* value */, uint8_t /* linkId */> CwValueTracedCallback;
533
536
537 private:
543 virtual std::unique_ptr<LinkEntity> CreateLinkEntity() const;
544
545 std::map<uint8_t, std::unique_ptr<LinkEntity>>
547};
548
549} // namespace ns3
550
551#endif /* TXOP_H */
Callback template class.
Definition: callback.h:438
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
Template class for packet Queues.
Definition: queue.h:268
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:72
virtual void StartAccessIfNeeded(uint8_t linkId)
Request access from Txop on the given link if needed.
Definition: txop.cc:561
Ptr< WifiMac > m_mac
the wifi MAC
Definition: txop.h:526
Time GetTxopLimit() const
Return the TXOP limit.
Definition: txop.cc:491
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:553
virtual ChannelAccessStatus GetAccessStatus(uint8_t linkId) const
Definition: txop.cc:582
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
Definition: txop.h:524
virtual bool HasFramesToTransmit(uint8_t linkId)
Check if the Txop has frames to transmit over the given link.
Definition: txop.cc:515
virtual void NotifyOff()
When off operation occurs, the queue gets cleaned up.
Definition: txop.cc:639
Ptr< UniformRandomVariable > m_rng
the random stream
Definition: txop.h:527
CwValueTracedCallback m_cwTrace
CW trace value.
Definition: txop.h:535
void DoDispose() override
Destructor implementation.
Definition: txop.cc:153
void SetMaxCw(uint32_t maxCw)
Set the maximum contention window size.
Definition: txop.cc:268
uint32_t GetMinCw() const
Return the minimum contention window size.
Definition: txop.cc:419
ChannelAccessStatus
Enumeration for channel access status.
Definition: txop.h:100
@ GRANTED
Definition: txop.h:103
@ NOT_REQUESTED
Definition: txop.h:101
@ REQUESTED
Definition: txop.h:102
virtual void NotifyOn()
When on operation occurs, channel access will be started.
Definition: txop.cc:653
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:313
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:646
virtual void NotifyChannelReleased(uint8_t linkId)
Called by the FrameExchangeManager to notify the completion of the transmissions.
Definition: txop.cc:602
std::vector< uint32_t > GetMaxCws() const
Return the maximum contention window size for each link.
Definition: txop.cc:449
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
Definition: txop.cc:390
TracedCallback< uint32_t, uint8_t > BackoffValueTracedCallback
TracedCallback for backoff trace value typedef.
Definition: txop.h:530
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:304
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:663
std::vector< uint32_t > GetMinCws() const
Return the minimum contention window size for each link.
Definition: txop.cc:425
std::vector< uint8_t > GetAifsns() const
Return the number of slots that make up an AIFS for each link.
Definition: txop.cc:473
void UpdateBackoffSlotsNow(uint32_t nSlots, Time backoffUpdateBound, uint8_t linkId)
Update backoff slots for the given link that nSlots has passed.
Definition: txop.cc:337
TracedCallback< uint32_t, uint8_t > CwValueTracedCallback
TracedCallback for CW trace value typedef.
Definition: txop.h:532
Time GetBackoffStart(uint8_t linkId) const
Return the time when the backoff procedure started on the given link.
Definition: txop.cc:331
void SetMaxCws(std::vector< uint32_t > maxCws)
Set the maximum contention window size for each link.
Definition: txop.cc:274
void SetTxopLimits(const std::vector< Time > &txopLimits)
Set the TXOP limit for each link.
Definition: txop.cc:396
DroppedMpdu m_droppedMpduCallback
the dropped MPDU callback
Definition: txop.h:523
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:497
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:366
uint32_t GetCw(uint8_t linkId) const
Get the current value of the CW variable for the given link.
Definition: txop.cc:298
void SetMinCws(std::vector< uint32_t > minCws)
Set the minimum contention window size for each link.
Definition: txop.cc:244
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:624
BackoffValueTracedCallback m_backoffTrace
backoff trace value
Definition: txop.h:534
virtual void NotifyAccessRequested(uint8_t linkId)
Notify that access request has been received for the given link.
Definition: txop.cc:588
void SetAifsns(std::vector< uint8_t > aifsns)
Set the number of slots that make up an AIFS for each link.
Definition: txop.cc:372
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
Definition: txop.h:525
~Txop() override
Definition: txop.cc:147
void StartBackoffNow(uint32_t nSlots, uint8_t linkId)
Definition: txop.cc:348
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:595
std::map< uint8_t, std::unique_ptr< LinkEntity > > m_links
ID-indexed map of LinkEntity objects.
Definition: txop.h:546
void RequestAccess(uint8_t linkId)
Request access to the ChannelAccessManager associated with the given link.
Definition: txop.cc:614
void SetMinCw(uint32_t minCw)
Set the minimum contention window size.
Definition: txop.cc:238
uint8_t GetAifsn() const
Return the number of slots that make up an AIFS.
Definition: txop.cc:467
uint32_t GetBackoffSlots(uint8_t linkId) const
Return the current number of backoff slots on the given link.
Definition: txop.cc:325
virtual void NotifySleep(uint8_t linkId)
Notify that the given link switched to sleep mode.
Definition: txop.cc:633
uint32_t GetMaxCw() const
Return the maximum contention window size.
Definition: txop.cc:443
Callback< void, WifiMacDropReason, Ptr< const WifiMpdu > > DroppedMpdu
typedef for a callback to invoke when an MPDU is dropped.
Definition: txop.h:94
void DoInitialize() override
Initialize() implementation.
Definition: txop.cc:571
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:1325
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.