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 <memory>
30#include <vector>
31
32namespace ns3
33{
34
35class Packet;
36class ChannelAccessManager;
37class MacTxMiddle;
38class WifiMode;
39class WifiMacQueue;
40class WifiMpdu;
41class UniformRandomVariable;
42class CtrlBAckResponseHeader;
43class WifiMac;
44enum WifiMacDropReason : uint8_t; // opaque enum declaration
45
70class Txop : public Object
71{
72 public:
73 Txop();
74
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
409 virtual bool HasFramesToTransmit(uint8_t linkId);
410
411 protected:
414
415 void DoDispose() override;
416 void DoInitialize() override;
417
418 /* Txop notifications forwarded here */
424 virtual void NotifyAccessRequested(uint8_t linkId);
425
431 virtual void GenerateBackoff(uint8_t linkId);
437 virtual void StartAccessIfNeeded(uint8_t linkId);
443 void RequestAccess(uint8_t linkId);
444
452 uint32_t GetCw(uint8_t linkId) const;
459 uint32_t GetBackoffSlots(uint8_t linkId) const;
466 Time GetBackoffStart(uint8_t linkId) const;
474 void UpdateBackoffSlotsNow(uint32_t nSlots, Time backoffUpdateBound, uint8_t linkId);
475
482 {
484 virtual ~LinkEntity() = default;
485
486 uint8_t id{0};
495 uint8_t aifsn{0};
498 };
499
506 LinkEntity& GetLink(uint8_t linkId) const;
512 uint8_t GetNLinks() const;
513
519
521 typedef TracedCallback<uint32_t /* value */, uint8_t /* linkId */> BackoffValueTracedCallback;
523 typedef TracedCallback<uint32_t /* value */, uint8_t /* linkId */> CwValueTracedCallback;
524
527
528 private:
534 virtual std::unique_ptr<LinkEntity> CreateLinkEntity() const;
535
536 std::vector<std::unique_ptr<LinkEntity>> m_links;
537};
538
539} // namespace ns3
540
541#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:267
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:538
Ptr< WifiMac > m_mac
the wifi MAC
Definition: txop.h:517
Time GetTxopLimit() const
Return the TXOP limit.
Definition: txop.cc:469
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:530
virtual ChannelAccessStatus GetAccessStatus(uint8_t linkId) const
Definition: txop.cc:559
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
Definition: txop.h:515
virtual bool HasFramesToTransmit(uint8_t linkId)
Check if the Txop has frames to transmit over the given link.
Definition: txop.cc:492
virtual void NotifyOff()
When off operation occurs, the queue gets cleaned up.
Definition: txop.cc:616
Ptr< UniformRandomVariable > m_rng
the random stream
Definition: txop.h:518
CwValueTracedCallback m_cwTrace
CW trace value.
Definition: txop.h:526
void DoDispose() override
Destructor implementation.
Definition: txop.cc:153
void SetMaxCw(uint32_t maxCw)
Set the maximum contention window size.
Definition: txop.cc:252
uint32_t GetMinCw() const
Return the minimum contention window size.
Definition: txop.cc:400
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:630
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:296
Ptr< WifiMacQueue > GetWifiMacQueue() const
Return the packet queue associated with this Txop.
Definition: txop.cc:216
virtual void SetWifiMac(const Ptr< WifiMac > mac)
Set the wifi MAC this Txop is associated to.
Definition: txop.cc:191
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:623
virtual void NotifyChannelReleased(uint8_t linkId)
Called by the FrameExchangeManager to notify the completion of the transmissions.
Definition: txop.cc:579
std::vector< uint32_t > GetMaxCws() const
Return the maximum contention window size for each link.
Definition: txop.cc:429
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
Definition: txop.cc:372
TracedCallback< uint32_t, uint8_t > BackoffValueTracedCallback
TracedCallback for backoff trace value typedef.
Definition: txop.h:521
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:287
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:640
std::vector< uint32_t > GetMinCws() const
Return the minimum contention window size for each link.
Definition: txop.cc:406
std::vector< uint8_t > GetAifsns() const
Return the number of slots that make up an AIFS for each link.
Definition: txop.cc:452
void UpdateBackoffSlotsNow(uint32_t nSlots, Time backoffUpdateBound, uint8_t linkId)
Update backoff slots for the given link that nSlots has passed.
Definition: txop.cc:320
TracedCallback< uint32_t, uint8_t > CwValueTracedCallback
TracedCallback for CW trace value typedef.
Definition: txop.h:523
Time GetBackoffStart(uint8_t linkId) const
Return the time when the backoff procedure started on the given link.
Definition: txop.cc:314
void SetMaxCws(std::vector< uint32_t > maxCws)
Set the maximum contention window size for each link.
Definition: txop.cc:258
void SetTxopLimits(const std::vector< Time > &txopLimits)
Set the TXOP limit for each link.
Definition: txop.cc:378
DroppedMpdu m_droppedMpduCallback
the dropped MPDU callback
Definition: txop.h:514
void SetTxMiddle(const Ptr< MacTxMiddle > txMiddle)
Set MacTxMiddle this Txop is associated to.
Definition: txop.cc:184
std::vector< std::unique_ptr< LinkEntity > > m_links
vector of LinkEntity objects
Definition: txop.h:536
std::vector< Time > GetTxopLimits() const
Return the TXOP limit for each link.
Definition: txop.cc:475
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:349
uint32_t GetCw(uint8_t linkId) const
Get the current value of the CW variable for the given link.
Definition: txop.cc:281
void SetMinCws(std::vector< uint32_t > minCws)
Set the minimum contention window size for each link.
Definition: txop.cc:229
virtual void SetDroppedMpduCallback(DroppedMpdu callback)
Definition: txop.cc:205
virtual void GenerateBackoff(uint8_t linkId)
Generate a new backoff for the given link now.
Definition: txop.cc:601
BackoffValueTracedCallback m_backoffTrace
backoff trace value
Definition: txop.h:525
virtual void NotifyAccessRequested(uint8_t linkId)
Notify that access request has been received for the given link.
Definition: txop.cc:565
void SetAifsns(std::vector< uint8_t > aifsns)
Set the number of slots that make up an AIFS for each link.
Definition: txop.cc:355
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
Definition: txop.h:516
~Txop() override
Definition: txop.cc:147
void StartBackoffNow(uint32_t nSlots, uint8_t linkId)
Definition: txop.cc:331
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:572
void RequestAccess(uint8_t linkId)
Request access to the ChannelAccessManager associated with the given link.
Definition: txop.cc:591
void SetMinCw(uint32_t minCw)
Set the minimum contention window size.
Definition: txop.cc:223
uint8_t GetAifsn() const
Return the number of slots that make up an AIFS.
Definition: txop.cc:446
uint32_t GetBackoffSlots(uint8_t linkId) const
Return the current number of backoff slots on the given link.
Definition: txop.cc:308
virtual void NotifySleep(uint8_t linkId)
Notify that the given link switched to sleep mode.
Definition: txop.cc:610
uint32_t GetMaxCw() const
Return the maximum contention window size.
Definition: txop.cc:423
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:178
void DoInitialize() override
Initialize() implementation.
Definition: txop.cc:548
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: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.