A Discrete-Event Network Simulator
API
txop.h
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2005 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 TXOP_H
22#define TXOP_H
23
24#include "ns3/traced-value.h"
25#include "wifi-mac-header.h"
26#include <memory>
27#include <vector>
28
29namespace ns3 {
30
31class Packet;
32class ChannelAccessManager;
33class MacTxMiddle;
34class WifiMode;
35class WifiMacQueue;
36class WifiMpdu;
37class UniformRandomVariable;
38class CtrlBAckResponseHeader;
39class WifiMac;
40enum WifiMacDropReason : uint8_t; // opaque enum declaration
41
66class Txop : public Object
67{
68public:
69 Txop ();
70
76 Txop (Ptr<WifiMacQueue> queue);
77
78 virtual ~Txop ();
79
84 static TypeId GetTypeId (void);
85
90
95 {
99 };
100
106 virtual bool IsQosTxop () const;
107
113 virtual void SetWifiMac (const Ptr<WifiMac> mac);
119 void SetTxMiddle (const Ptr<MacTxMiddle> txMiddle);
120
124 virtual void SetDroppedMpduCallback (DroppedMpdu callback);
125
132
139 void SetMinCw (uint32_t minCw);
147 void SetMinCws (std::vector<uint32_t> minCws);
154 void SetMinCw (uint32_t minCw, uint8_t linkId);
161 void SetMaxCw (uint32_t maxCw);
169 void SetMaxCws (std::vector<uint32_t> maxCws);
176 void SetMaxCw (uint32_t maxCw, uint8_t linkId);
183 void SetAifsn (uint8_t aifsn);
191 void SetAifsns (std::vector<uint8_t> aifsns);
198 void SetAifsn (uint8_t aifsn, uint8_t linkId);
205 void SetTxopLimit (Time txopLimit);
213 void SetTxopLimits (const std::vector<Time>& txopLimits);
221 void SetTxopLimit (Time txopLimit, uint8_t linkId);
228 uint32_t GetMinCw (void) const;
234 std::vector<uint32_t> GetMinCws (void) const;
241 virtual uint32_t GetMinCw (uint8_t linkId) const;
248 uint32_t GetMaxCw (void) const;
254 std::vector<uint32_t> GetMaxCws (void) const;
261 virtual uint32_t GetMaxCw (uint8_t linkId) const;
268 uint8_t GetAifsn (void) const;
274 std::vector<uint8_t> GetAifsns (void) const;
281 virtual uint8_t GetAifsn (uint8_t linkId) const;
287 Time GetTxopLimit (void) const;
293 std::vector<Time> GetTxopLimits (void) const;
300 Time GetTxopLimit (uint8_t linkId) const;
309 void ResetCw (uint8_t linkId);
317 void UpdateFailedCw (uint8_t linkId);
318
324 virtual void NotifySleep (uint8_t linkId);
328 virtual void NotifyOff (void);
335 virtual void NotifyWakeUp (uint8_t linkId);
339 virtual void NotifyOn (void);
340
341 /* Event handlers */
349 virtual void Queue (Ptr<Packet> packet, const WifiMacHeader &hdr);
356 virtual void Queue (Ptr<WifiMpdu> mpdu);
357
365 virtual void NotifyChannelAccessed (uint8_t linkId, Time txopDuration = Seconds (0));
372 virtual void NotifyChannelReleased (uint8_t linkId);
373
383 int64_t AssignStreams (int64_t stream);
384
389 virtual ChannelAccessStatus GetAccessStatus (uint8_t linkId) const;
390
398 void StartBackoffNow (uint32_t nSlots, uint8_t linkId);
399
400protected:
403
404 void DoDispose (void) override;
405 void DoInitialize (void) override;
406
407 /* Txop notifications forwarded here */
413 virtual void NotifyAccessRequested (uint8_t linkId);
414
420 virtual bool HasFramesToTransmit (uint8_t linkId);
426 virtual void GenerateBackoff (uint8_t linkId);
432 virtual void StartAccessIfNeeded (uint8_t linkId);
438 void RequestAccess (uint8_t linkId);
439
447 uint32_t GetCw (uint8_t linkId) const;
454 uint32_t GetBackoffSlots (uint8_t linkId) const;
461 Time GetBackoffStart (uint8_t linkId) const;
469 void UpdateBackoffSlotsNow (uint32_t nSlots, Time backoffUpdateBound, uint8_t linkId);
470
477 {
479 virtual ~LinkEntity () = default;
480
481 uint8_t id {0};
490 uint8_t aifsn {0};
493 };
494
501 LinkEntity& GetLink (uint8_t linkId) const;
507 uint8_t GetNLinks (void) const;
508
514
516 typedef TracedCallback<uint32_t /* value */, uint8_t /* linkId */> BackoffValueTracedCallback;
518 typedef TracedCallback<uint32_t /* value */, uint8_t /* linkId */> CwValueTracedCallback;
519
522
523private:
529 virtual std::unique_ptr<LinkEntity> CreateLinkEntity (void) const;
530
531 std::vector<std::unique_ptr<LinkEntity>> m_links;
532};
533
534} //namespace ns3
535
536#endif /* TXOP_H */
Callback template class.
Definition: callback.h:422
Manage a set of ns3::Txop.
A base class which provides memory management and object aggregation.
Definition: object.h:88
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
Forward calls to a chain of Callback.
Handle packet fragmentation and retransmissions for data and management frames.
Definition: txop.h:67
virtual void StartAccessIfNeeded(uint8_t linkId)
Request access from Txop on the given link if needed.
Definition: txop.cc:525
Ptr< WifiMac > m_mac
the wifi MAC
Definition: txop.h:512
void DoInitialize(void) override
Initialize() implementation.
Definition: txop.cc:535
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: txop.cc:517
virtual ChannelAccessStatus GetAccessStatus(uint8_t linkId) const
Definition: txop.cc:546
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
Definition: txop.h:510
virtual bool HasFramesToTransmit(uint8_t linkId)
Check if the Txop has frames to transmit over the given link.
Definition: txop.cc:478
Ptr< UniformRandomVariable > m_rng
the random stream
Definition: txop.h:513
CwValueTracedCallback m_cwTrace
CW trace value.
Definition: txop.h:521
virtual std::unique_ptr< LinkEntity > CreateLinkEntity(void) const
Create a LinkEntity object.
Definition: txop.cc:153
uint8_t GetNLinks(void) const
Get the number of links.
Definition: txop.cc:167
void SetMaxCw(uint32_t maxCw)
Set the maximum contention window size.
Definition: txop.cc:240
ChannelAccessStatus
Enumeration for channel access status.
Definition: txop.h:95
@ GRANTED
Definition: txop.h:98
@ NOT_REQUESTED
Definition: txop.h:96
@ REQUESTED
Definition: txop.h:97
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:284
Ptr< WifiMacQueue > GetWifiMacQueue() const
Return the packet queue associated with this Txop.
Definition: txop.cc:204
Time GetTxopLimit(void) const
Return the TXOP limit.
Definition: txop.cc:455
virtual void SetWifiMac(const Ptr< WifiMac > mac)
Set the wifi MAC this Txop is associated to.
Definition: txop.cc:179
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:610
virtual void NotifyChannelReleased(uint8_t linkId)
Called by the FrameExchangeManager to notify the completion of the transmissions.
Definition: txop.cc:566
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
Definition: txop.cc:360
TracedCallback< uint32_t, uint8_t > BackoffValueTracedCallback
TracedCallback for backoff trace value typedef.
Definition: txop.h:516
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:275
virtual void NotifyOn(void)
When on operation occurs, channel access will be started.
Definition: txop.cc:617
static TypeId GetTypeId(void)
Get the type ID.
Definition: txop.cc:45
Txop()
Definition: txop.cc:124
LinkEntity & GetLink(uint8_t linkId) const
Get a reference to the link associated with the given ID.
Definition: txop.cc:159
virtual bool IsQosTxop() const
Check for QoS TXOP.
Definition: txop.cc:627
void UpdateBackoffSlotsNow(uint32_t nSlots, Time backoffUpdateBound, uint8_t linkId)
Update backoff slots for the given link that nSlots has passed.
Definition: txop.cc:308
TracedCallback< uint32_t, uint8_t > CwValueTracedCallback
TracedCallback for CW trace value typedef.
Definition: txop.h:518
Time GetBackoffStart(uint8_t linkId) const
Return the time when the backoff procedure started on the given link.
Definition: txop.cc:302
void SetMaxCws(std::vector< uint32_t > maxCws)
Set the maximum contention window size for each link.
Definition: txop.cc:246
void SetTxopLimits(const std::vector< Time > &txopLimits)
Set the TXOP limit for each link.
Definition: txop.cc:366
DroppedMpdu m_droppedMpduCallback
the dropped MPDU callback
Definition: txop.h:509
void SetTxMiddle(const Ptr< MacTxMiddle > txMiddle)
Set MacTxMiddle this Txop is associated to.
Definition: txop.cc:172
std::vector< std::unique_ptr< LinkEntity > > m_links
vector of LinkEntity objects
Definition: txop.h:531
std::vector< uint32_t > GetMinCws(void) const
Return the minimum contention window size for each link.
Definition: txop.cc:392
void SetAifsn(uint8_t aifsn)
Set the number of slots that make up an AIFS.
Definition: txop.cc:337
uint32_t GetCw(uint8_t linkId) const
Get the current value of the CW variable for the given link.
Definition: txop.cc:269
void SetMinCws(std::vector< uint32_t > minCws)
Set the minimum contention window size for each link.
Definition: txop.cc:217
virtual void SetDroppedMpduCallback(DroppedMpdu callback)
Definition: txop.cc:193
virtual void GenerateBackoff(uint8_t linkId)
Generate a new backoff for the given link now.
Definition: txop.cc:588
BackoffValueTracedCallback m_backoffTrace
backoff trace value
Definition: txop.h:520
virtual void NotifyAccessRequested(uint8_t linkId)
Notify that access request has been received for the given link.
Definition: txop.cc:552
std::vector< uint32_t > GetMaxCws(void) const
Return the maximum contention window size for each link.
Definition: txop.cc:415
void SetAifsns(std::vector< uint8_t > aifsns)
Set the number of slots that make up an AIFS for each link.
Definition: txop.cc:343
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
Definition: txop.h:511
std::vector< uint8_t > GetAifsns(void) const
Return the number of slots that make up an AIFS for each link.
Definition: txop.cc:438
virtual ~Txop()
Definition: txop.cc:136
void StartBackoffNow(uint32_t nSlots, uint8_t linkId)
Definition: txop.cc:319
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:559
uint32_t GetMaxCw(void) const
Return the maximum contention window size.
Definition: txop.cc:409
virtual void NotifyOff(void)
When off operation occurs, the queue gets cleaned up.
Definition: txop.cc:603
void RequestAccess(uint8_t linkId)
Request access to the ChannelAccessManager associated with the given link.
Definition: txop.cc:578
void SetMinCw(uint32_t minCw)
Set the minimum contention window size.
Definition: txop.cc:211
uint32_t GetBackoffSlots(uint8_t linkId) const
Return the current number of backoff slots on the given link.
Definition: txop.cc:296
virtual void Queue(Ptr< Packet > packet, const WifiMacHeader &hdr)
Definition: txop.cc:487
virtual void NotifySleep(uint8_t linkId)
Notify that the given link switched to sleep mode.
Definition: txop.cc:597
uint32_t GetMinCw(void) const
Return the minimum contention window size.
Definition: txop.cc:386
std::vector< Time > GetTxopLimits(void) const
Return the TXOP limit for each link.
Definition: txop.cc:461
uint8_t GetAifsn(void) const
Return the number of slots that make up an AIFS.
Definition: txop.cc:432
Callback< void, WifiMacDropReason, Ptr< const WifiMpdu > > DroppedMpdu
typedef for a callback to invoke when an MPDU is dropped.
Definition: txop.h:89
void DoDispose(void) override
Destructor implementation.
Definition: txop.cc:142
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:1245
WifiMacDropReason
The reason why an MPDU was dropped.
Definition: wifi-mac.h:72
Every class exported by the ns3 library is enclosed in the ns3 namespace.
mac
Definition: third.py:87