A Discrete-Event Network Simulator
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
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  */
21 #ifndef TXOP_H
22 #define TXOP_H
24 #include "ns3/traced-value.h"
26 #include "wifi-mac-header.h"
28 namespace ns3 {
30 class Packet;
31 class ChannelAccessManager;
32 class MacTxMiddle;
33 class MacLow;
34 class WifiMode;
35 class WifiMacQueue;
36 class WifiMacQueueItem;
37 class UniformRandomVariable;
38 class CtrlBAckResponseHeader;
39 class WifiRemoteStationManager;
40 class WifiTxVector;
66 class Txop : public Object
67 {
68 public:
72  Txop ();
73  virtual ~Txop ();
79  static TypeId GetTypeId (void);
102  virtual bool IsQosTxop () const;
109  void SetMacLow (const Ptr<MacLow> low);
121  virtual void SetWifiRemoteStationManager (const Ptr<WifiRemoteStationManager> remoteManager);
127  void SetTxMiddle (const Ptr<MacTxMiddle> txMiddle);
133  void SetTxOkCallback (TxOk callback);
138  void SetTxFailedCallback (TxFailed callback);
143  void SetTxDroppedCallback (TxDropped callback);
150  Ptr<MacLow> GetLow (void) const;
164  void SetMinCw (uint32_t minCw);
170  void SetMaxCw (uint32_t maxCw);
176  void SetAifsn (uint8_t aifsn);
183  void SetTxopLimit (Time txopLimit);
189  uint32_t GetMinCw (void) const;
195  uint32_t GetMaxCw (void) const;
201  uint8_t GetAifsn (void) const;
207  Time GetTxopLimit (void) const;
212  virtual void NotifyChannelSwitching (void);
217  virtual void NotifySleep (void);
221  virtual void NotifyOff (void);
225  virtual void NotifyWakeUp (void);
229  virtual void NotifyOn (void);
231  /* Event handlers */
239  virtual void Queue (Ptr<Packet> packet, const WifiMacHeader &hdr);
247  void SendCfFrame (WifiMacType frameType, Mac48Address addr);
249  /* Event handlers */
253  virtual void MissedCts (void);
257  virtual void GotAck (void);
261  virtual void MissedAck (void);
265  void GotCfEnd (void);
271  void MissedCfPollResponse (bool expectedCfAck);
281  virtual void GotBlockAck (const CtrlBAckResponseHeader *blockAck, Mac48Address recipient,
282  double rxSnr, double dataSnr, WifiTxVector dataTxVector);
287  virtual void MissedBlockAck (uint8_t nMpdus);
293  virtual void StartNextFragment (void);
297  virtual void Cancel (void);
301  virtual void StartNextPacket (void);
306  virtual void EndTxNoAck (void);
313  virtual Time GetTxopRemaining (void) const;
317  virtual void TerminateTxop (void);
325  bool CanStartNextPolling (void) const;
337  int64_t AssignStreams (int64_t stream);
343  virtual bool IsAccessRequested (void) const;
351  void StartBackoffNow (uint32_t nSlots);
353 protected:
355  friend class ChannelAccessManager;
357  virtual void DoDispose (void);
358  virtual void DoInitialize (void);
360  /* Txop notifications forwarded here */
364  virtual void NotifyAccessRequested (void);
368  virtual void NotifyAccessGranted (void);
372  virtual void NotifyInternalCollision (void);
378  virtual bool HasFramesToTransmit (void);
382  virtual void GenerateBackoff (void);
386  virtual void RestartAccessIfNeeded (void);
390  virtual void StartAccessIfNeeded (void);
396  uint32_t GetCw (void) const;
403  void ResetCw (void);
409  void UpdateFailedCw (void);
415  uint32_t GetBackoffSlots (void) const;
421  Time GetBackoffStart (void) const;
428  void UpdateBackoffSlotsNow (uint32_t nSlots, Time backoffUpdateBound);
438  bool NeedRtsRetransmission (Ptr<const Packet> packet, const WifiMacHeader &hdr);
447  bool NeedDataRetransmission (Ptr<const Packet> packet, const WifiMacHeader &hdr);
454  virtual bool NeedFragmentation (void) const;
461  void NextFragment (void);
476  virtual uint32_t GetNextFragmentSize (void) const;
482  virtual uint32_t GetFragmentSize (void) const;
488  virtual uint32_t GetFragmentOffset (void) const;
495  virtual bool IsLastFragment (void) const;
515  uint32_t m_cwMin;
516  uint32_t m_cwMax;
517  uint32_t m_cw;
518  uint32_t m_backoff;
520  uint32_t m_backoffSlots;
528  uint8_t m_aifsn;
537 };
539 } //namespace ns3
541 #endif /* TXOP_H */
TxFailed m_txFailedCallback
the transmit failed callback
Definition: txop.h:507
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
void SendCfFrame(WifiMacType frameType, Mac48Address addr)
Sends CF frame to STA with address addr.
Definition: txop.cc:783
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
uint8_t m_aifsn
Definition: txop.h:528
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
Definition: txop.h:510
TracedCallback< uint32_t > m_backoffTrace
backoff trace value
Definition: txop.h:535
TracedValue< uint32_t > m_cwTrace
CW trace value.
Definition: txop.h:536
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Time m_txopLimit
the TXOP limit time
Definition: txop.h:529
virtual void RestartAccessIfNeeded(void)
Restart access request if needed.
Definition: txop.cc:340
virtual void StartAccessIfNeeded(void)
Request access from Txop if needed.
Definition: txop.cc:353
uint8_t GetAifsn(void) const
Return the number of slots that make up an AIFS.
Definition: txop.cc:297
virtual void StartNextPacket(void)
Start transmission for the next packet if allowed by the TxopLimit.
Definition: txop.cc:867
virtual void EndTxNoAck(void)
Event handler when a transmission that does not require an Ack has completed.
Definition: txop.cc:767
uint32_t m_backoffSlots
the number of backoff slots
Definition: txop.h:520
virtual bool HasFramesToTransmit(void)
Check if the Txop has frames to transmit.
Definition: txop.cc:309
virtual void StartNextFragment(void)
Start transmission for the next fragment.
Definition: txop.cc:738
uint32_t m_backoff
the current backoff
Definition: txop.h:518
void SetChannelAccessManager(const Ptr< ChannelAccessManager > manager)
Set ChannelAccessManager this Txop is associated to.
Definition: txop.cc:120
Ptr< ChannelAccessManager > m_channelAccessManager
the channel access manager
Definition: txop.h:505
virtual void NotifyAccessGranted(void)
Notify the Txop that access has been granted.
Definition: txop.cc:476
virtual void MissedAck(void)
Event handler when an Ack is missed.
Definition: txop.cc:666
void SetTxDroppedCallback(TxDropped callback)
Definition: txop.cc:162
virtual void DoInitialize(void)
Initialize() implementation.
Definition: txop.cc:372
Time GetBackoffStart(void) const
Return the time when the backoff procedure started.
Definition: txop.cc:239
virtual void Cancel(void)
Cancel the transmission.
Definition: txop.cc:760
Manage a set of ns3::TxopHandle a set of independent ns3::Txop, each of which represents a single DCF...
Ptr< UniformRandomVariable > m_rng
the random stream
Definition: txop.h:513
void UpdateBackoffSlotsNow(uint32_t nSlots, Time backoffUpdateBound)
Update backoff slots that nSlots has passed.
Definition: txop.cc:245
bool CanStartNextPolling(void) const
Check if the next PCF transmission can fit in the remaining CFP duration.
Definition: txop.cc:855
virtual void GenerateBackoff(void)
Generate a new backoff now.
Definition: txop.cc:553
Callback< void, Ptr< const Packet > > TxDropped
typedef for a callback to invoke when a packet is dropped.
Definition: txop.h:95
uint32_t GetMinCw(void) const
Return the minimum contention window size.
Definition: txop.cc:285
uint32_t m_cwMax
the maximum contention window
Definition: txop.h:516
control how a packet is transmitted.
virtual void GotBlockAck(const CtrlBAckResponseHeader *blockAck, Mac48Address recipient, double rxSnr, double dataSnr, WifiTxVector dataTxVector)
Event handler when a BlockAck is received.
Definition: txop.cc:873
virtual void NotifyOff(void)
When off operation occurs, the queue gets cleaned up.
Definition: txop.cc:589
void UpdateFailedCw(void)
Update the value of the CW variable to take into account a transmission failure.
Definition: txop.cc:225
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: txop.cc:332
Combination of valid MAC header type/subtype.
void NextFragment(void)
Continue to the next fragment.
Definition: txop.cc:403
static TypeId GetTypeId(void)
Get the type ID.
Definition: txop.cc:44
Headers for BlockAck response.
Definition: ctrl-headers.h:193
virtual bool IsAccessRequested(void) const
Definition: txop.cc:463
virtual bool IsQosTxop() const
Check for QoS TXOP.
Definition: txop.cc:861
virtual uint32_t GetNextFragmentSize(void) const
Calculate the size of the next fragment.
Definition: txop.cc:426
uint32_t m_cwMin
the minimum contention window
Definition: txop.h:515
bool NeedRtsRetransmission(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Check if RTS should be re-transmitted if CTS was missed.
Definition: txop.cc:381
Ptr< MacLow > GetLow(void) const
Return the MacLow associated with this Txop.
Definition: txop.cc:366
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void GotCfEnd(void)
Event handler when a CF-END frame is received.
Definition: txop.cc:698
uint32_t GetCw(void) const
Definition: txop.cc:212
virtual void NotifySleep(void)
When sleep operation occurs, if there is a pending packet transmission, it will be reinserted to the ...
Definition: txop.cc:578
uint32_t GetMaxCw(void) const
Return the maximum contention window size.
Definition: txop.cc:291
virtual void MissedBlockAck(uint8_t nMpdus)
Event handler when a BlockAck timeout has occurred.
Definition: txop.cc:879
virtual void NotifyOn(void)
When on operation occurs, channel access will be started.
Definition: txop.cc:604
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
Definition: txop.h:509
virtual void DoDispose(void)
Destructor implementation.
Definition: txop.cc:108
an EUI-48 address
Definition: mac48-address.h:43
bool NeedDataRetransmission(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Check if Data should be re-transmitted if Ack was missed.
Definition: txop.cc:388
Ptr< const Packet > m_currentPacket
the current packet
Definition: txop.h:531
void SetMacLow(const Ptr< MacLow > low)
Set MacLow associated with this Txop.
Definition: txop.cc:134
virtual bool NeedFragmentation(void) const
Check if the current packet should be fragmented.
Definition: txop.cc:395
virtual Ptr< Packet > GetFragmentPacket(WifiMacHeader *hdr)
Get the next fragment from the packet with appropriate Wifi header for the fragment.
Definition: txop.cc:442
virtual void NotifyChannelSwitching(void)
When a channel switching occurs, enqueued packets are removed.
Definition: txop.cc:570
Callback< void, const WifiMacHeader & > TxOk
typedef for a callback to invoke when a packet transmission was completed successfully.
Definition: txop.h:85
virtual void NotifyInternalCollision(void)
Notify the Txop that internal collision has occurred.
Definition: txop.cc:562
Ptr< MacLow > m_low
the MacLow
Definition: txop.h:511
virtual bool IsLastFragment(void) const
Check if the current fragment is the last fragment.
Definition: txop.cc:418
void TxDroppedPacket(Ptr< const WifiMacQueueItem > item)
Pass the packet included in the wifi MAC queue item to the packet dropped callback.
Definition: txop.cc:170
uint32_t m_cw
the current contention window
Definition: txop.h:517
Definition: txop.cc:86
MacLowTransmissionParameters m_currentParams
current transmission parameters
Definition: txop.h:533
void SetMinCw(uint32_t minCw)
Set the minimum contention window size.
Definition: txop.cc:186
friend class MacLowTransmissionListener
allow MacLowTransmissionListener class access
Definition: txop.h:70
void SetMaxCw(uint32_t maxCw)
Set the maximum contention window size.
Definition: txop.cc:199
bool m_accessRequested
flag whether channel access is already requested
Definition: txop.h:519
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
Definition: txop.cc:277
Time m_backoffStart
the backoffStart variable is used to keep track of the time at which a backoff was started or the tim...
Definition: txop.h:526
virtual void GotAck(void)
Event handler when an Ack is received.
Definition: txop.cc:638
virtual void MissedCts(void)
Event handler when a CTS timeout has occurred.
Definition: txop.cc:611
void SetTxMiddle(const Ptr< MacTxMiddle > txMiddle)
Set MacTxMiddle this Txop is associated to.
Definition: txop.cc:127
uint32_t GetBackoffSlots(void) const
Return the current number of backoff slots.
Definition: txop.cc:233
Callback< void, const WifiMacHeader & > TxFailed
typedef for a callback to invoke when a packet transmission was failed.
Definition: txop.h:90
Ptr< WifiMacQueue > GetWifiMacQueue() const
Return the packet queue associated with this Txop.
Definition: txop.cc:179
virtual Time GetTxopRemaining(void) const
Return the remaining duration in the current TXOP.
Definition: txop.cc:885
void MissedCfPollResponse(bool expectedCfAck)
Event handler when a response to a CF-POLL frame is missed.
Definition: txop.cc:712
TxOk m_txOkCallback
the transmit OK callback
Definition: txop.h:506
virtual void SetWifiRemoteStationManager(const Ptr< WifiRemoteStationManager > remoteManager)
Set WifiRemoteStationsManager this Txop is associated to.
Definition: txop.cc:141
uint8_t m_fragmentNumber
the fragment number
Definition: txop.h:534
void SetAifsn(uint8_t aifsn)
Set the number of slots that make up an AIFS.
Definition: txop.cc:270
A base class which provides memory management and object aggregation.
Definition: object.h:87
virtual void NotifyAccessRequested(void)
Notify that access request has been received.
Definition: txop.cc:469
WifiMacHeader m_currentHdr
the current header
Definition: txop.h:532
virtual void TerminateTxop(void)
Update backoff and restart access if needed.
Definition: txop.cc:892
void SetTxFailedCallback(TxFailed callback)
Definition: txop.cc:155
virtual ~Txop()
Definition: txop.cc:102
Ptr< WifiRemoteStationManager > m_stationManager
the wifi remote station manager
Definition: txop.h:512
virtual uint32_t GetFragmentOffset(void) const
Calculate the offset for the current fragment.
Definition: txop.cc:434
void SetTxOkCallback(TxOk callback)
Definition: txop.cc:148
virtual void Queue(Ptr< Packet > packet, const WifiMacHeader &hdr)
Definition: txop.cc:317
virtual uint32_t GetFragmentSize(void) const
Calculate the size of the current fragment.
Definition: txop.cc:410
void ResetCw(void)
Update the value of the CW variable to take into account a transmission success or a transmission abo...
Definition: txop.cc:218
a unique identifier for an interface.
Definition: type-id.h:58
void StartBackoffNow(uint32_t nSlots)
Definition: txop.cc:254
Implements the IEEE 802.11 MAC header.
virtual void NotifyWakeUp(void)
When wake up operation occurs, channel access will be restarted.
Definition: txop.cc:597
TxDropped m_txDroppedCallback
the packet dropped callback
Definition: txop.h:508
Handle packet fragmentation and retransmissions for data and management frames.
Definition: txop.h:66
Time GetTxopLimit(void) const
Return the TXOP limit.
Definition: txop.cc:303