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;
65 class Txop : public Object
66 {
67 public:
69  friend class DcfListener;
73  Txop ();
74  virtual ~Txop ();
80  static TypeId GetTypeId (void);
103  virtual bool IsQosTxop () const;
110  void SetMacLow (const Ptr<MacLow> low);
122  virtual void SetWifiRemoteStationManager (const Ptr<WifiRemoteStationManager> remoteManager);
128  void SetTxMiddle (const Ptr<MacTxMiddle> txMiddle);
134  void SetTxOkCallback (TxOk callback);
139  void SetTxFailedCallback (TxFailed callback);
144  void SetTxDroppedCallback (TxDropped callback);
151  Ptr<MacLow> GetLow (void) const;
165  void SetMinCw (uint32_t minCw);
171  void SetMaxCw (uint32_t maxCw);
177  void SetAifsn (uint8_t aifsn);
184  void SetTxopLimit (Time txopLimit);
190  uint32_t GetMinCw (void) const;
196  uint32_t GetMaxCw (void) const;
202  uint8_t GetAifsn (void) const;
208  Time GetTxopLimit (void) const;
213  virtual void NotifyChannelSwitching (void);
218  virtual void NotifySleep (void);
222  virtual void NotifyOff (void);
226  virtual void NotifyWakeUp (void);
230  virtual void NotifyOn (void);
232  /* Event handlers */
240  virtual void Queue (Ptr<const Packet> packet, const WifiMacHeader &hdr);
248  void SendCfFrame (WifiMacType frameType, Mac48Address addr);
250  /* Event handlers */
254  virtual void MissedCts (void);
258  virtual void GotAck (void);
262  virtual void MissedAck (void);
266  void GotCfEnd (void);
272  void MissedCfPollResponse (bool expectedCfAck);
282  virtual void GotBlockAck (const CtrlBAckResponseHeader *blockAck, Mac48Address recipient, double rxSnr, WifiMode txMode, double dataSnr);
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  /* dcf notifications forwarded here */
364  virtual void NotifyAccessRequested (void);
368  virtual void NotifyAccessGranted (void);
372  virtual void NotifyInternalCollision (void);
376  virtual void NotifyCollision (void);
381  virtual void RestartAccessIfNeeded (void);
385  virtual void StartAccessIfNeeded (void);
391  uint32_t GetCw (void) const;
398  void ResetCw (void);
404  void UpdateFailedCw (void);
410  uint32_t GetBackoffSlots (void) const;
416  Time GetBackoffStart (void) const;
423  void UpdateBackoffSlotsNow (uint32_t nSlots, Time backoffUpdateBound);
433  bool NeedRtsRetransmission (Ptr<const Packet> packet, const WifiMacHeader &hdr);
442  bool NeedDataRetransmission (Ptr<const Packet> packet, const WifiMacHeader &hdr);
449  virtual bool NeedFragmentation (void) const;
456  void NextFragment (void);
471  virtual uint32_t GetNextFragmentSize (void) const;
477  virtual uint32_t GetFragmentSize (void) const;
483  virtual uint32_t GetFragmentOffset (void) const;
490  virtual bool IsLastFragment (void) const;
510  uint32_t m_cwMin;
511  uint32_t m_cwMax;
512  uint32_t m_cw;
513  uint32_t m_backoff;
515  uint32_t m_backoffSlots;
523  uint8_t m_aifsn;
532 };
534 } //namespace ns3
536 #endif /* TXOP_H */
TxFailed m_txFailedCallback
the transmit failed callback
Definition: txop.h:502
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:786
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
uint8_t m_aifsn
Definition: txop.h:523
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
Definition: txop.h:505
TracedCallback< uint32_t > m_backoffTrace
backoff trace value
Definition: txop.h:530
TracedValue< uint32_t > m_cwTrace
CW trace value.
Definition: txop.h:531
Time m_txopLimit
the txop limit time
Definition: txop.h:524
virtual void RestartAccessIfNeeded(void)
Restart access request if needed.
Definition: txop.cc:329
virtual void StartAccessIfNeeded(void)
Request access from DCF manager if needed.
Definition: txop.cc:342
uint8_t GetAifsn(void) const
Return the number of slots that make up an AIFS.
Definition: txop.cc:296
virtual void StartNextPacket(void)
Start transmission for the next packet if allowed by the TxopLimit.
Definition: txop.cc:870
virtual void EndTxNoAck(void)
Event handler when a transmission that does not require an ACK has completed.
Definition: txop.cc:768
uint32_t m_backoffSlots
the backoff slots
Definition: txop.h:515
virtual void StartNextFragment(void)
Start transmission for the next fragment.
Definition: txop.cc:739
uint32_t m_backoff
the current backoff
Definition: txop.h:513
void SetChannelAccessManager(const Ptr< ChannelAccessManager > manager)
Set ChannelAccessManager this Txop is associated to.
Definition: txop.cc:119
Ptr< ChannelAccessManager > m_channelAccessManager
the channel access manager
Definition: txop.h:500
virtual void NotifyAccessGranted(void)
Notify the DCF that access has been granted.
Definition: txop.cc:467
virtual void MissedAck(void)
Event handler when an ACK is missed.
Definition: txop.cc:665
void SetTxDroppedCallback(TxDropped callback)
Definition: txop.cc:161
virtual void DoInitialize(void)
Initialize() implementation.
Definition: txop.cc:361
Time GetBackoffStart(void) const
Return the time when the backoff procedure started.
Definition: txop.cc:238
virtual void Cancel(void)
Cancel the transmission.
Definition: txop.cc:761
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:508
void UpdateBackoffSlotsNow(uint32_t nSlots, Time backoffUpdateBound)
Update backoff slots that nSlots has passed.
Definition: txop.cc:244
bool CanStartNextPolling(void) const
Check if the next PCF transmission can fit in the remaining CFP duration.
Definition: txop.cc:858
Callback< void, Ptr< const Packet > > TxDropped
typedef for a callback to invoke when a packet is dropped.
Definition: txop.h:96
uint32_t GetMinCw(void) const
Return the minimum contention window size.
Definition: txop.cc:284
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
uint32_t m_cwMax
the CW maximum
Definition: txop.h:511
control how a packet is transmitted.
virtual void NotifyOff(void)
When off operation occurs, the queue gets cleaned up.
Definition: txop.cc:584
void UpdateFailedCw(void)
Update the value of the CW variable to take into account a transmission failure.
Definition: txop.cc:224
friend class DcfListener
allow DcfListener class access
Definition: txop.h:69
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: txop.cc:321
Combination of valid MAC header type/subtype.
void NextFragment(void)
Continue to the next fragment.
Definition: txop.cc:394
static TypeId GetTypeId(void)
Get the type ID.
Definition: txop.cc:43
Headers for Block ack response.
Definition: ctrl-headers.h:193
virtual bool IsAccessRequested(void) const
Definition: txop.cc:454
virtual bool IsQosTxop() const
Check for QoS TXOP.
Definition: txop.cc:864
virtual uint32_t GetNextFragmentSize(void) const
Calculate the size of the next fragment.
Definition: txop.cc:417
uint32_t m_cwMin
the CW minimum
Definition: txop.h:510
bool NeedRtsRetransmission(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Check if RTS should be re-transmitted if CTS was missed.
Definition: txop.cc:372
Ptr< MacLow > GetLow(void) const
Return the MacLow associated with this Txop.
Definition: txop.cc:355
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:699
uint32_t GetCw(void) const
Definition: txop.cc:211
virtual void NotifySleep(void)
When sleep operation occurs, if there is a pending packet transmission, it will be reinserted to the ...
Definition: txop.cc:573
uint32_t GetMaxCw(void) const
Return the maximum contention window size.
Definition: txop.cc:290
virtual void MissedBlockAck(uint8_t nMpdus)
Event handler when a Block ACK timeout has occurred.
Definition: txop.cc:882
virtual void NotifyOn(void)
When on operation occurs, channel access will be started.
Definition: txop.cc:599
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
Definition: txop.h:504
virtual void DoDispose(void)
Destructor implementation.
Definition: txop.cc:107
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:379
Ptr< const Packet > m_currentPacket
the current packet
Definition: txop.h:526
void SetMacLow(const Ptr< MacLow > low)
Set MacLow associated with this Txop.
Definition: txop.cc:133
virtual bool NeedFragmentation(void) const
Check if the current packet should be fragmented.
Definition: txop.cc:386
virtual Ptr< Packet > GetFragmentPacket(WifiMacHeader *hdr)
Get the next fragment from the packet with appropriate Wifi header for the fragment.
Definition: txop.cc:433
virtual void NotifyChannelSwitching(void)
When a channel switching occurs, enqueued packets are removed.
Definition: txop.cc:565
Callback< void, const WifiMacHeader & > TxOk
typedef for a callback to invoke when a packet transmission was completed successfully.
Definition: txop.h:86
virtual void NotifyInternalCollision(void)
Notify the DCF that internal collision has occurred.
Definition: txop.cc:548
Ptr< MacLow > m_low
the MacLow
Definition: txop.h:506
virtual bool IsLastFragment(void) const
Check if the current fragment is the last fragment.
Definition: txop.cc:409
void TxDroppedPacket(Ptr< const WifiMacQueueItem > item)
Pass the packet included in the wifi MAC queue item to the packet dropped callback.
Definition: txop.cc:169
uint32_t m_cw
the current CW
Definition: txop.h:512
Definition: txop.cc:85
MacLowTransmissionParameters m_currentParams
current transmission parameters
Definition: txop.h:528
virtual void Queue(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Definition: txop.cc:308
void SetMinCw(uint32_t minCw)
Set the minimum contention window size.
Definition: txop.cc:185
friend class MacLowTransmissionListener
allow MacLowTransmissionListener class access
Definition: txop.h:71
void SetMaxCw(uint32_t maxCw)
Set the maximum contention window size.
Definition: txop.cc:198
bool m_accessRequested
flag whether channel access is already requested
Definition: txop.h:514
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
Definition: txop.cc:276
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:521
virtual void GotAck(void)
Event handler when an ACK is received.
Definition: txop.cc:635
virtual void MissedCts(void)
Event handler when a CTS timeout has occurred.
Definition: txop.cc:606
void SetTxMiddle(const Ptr< MacTxMiddle > txMiddle)
Set MacTxMiddle this Txop is associated to.
Definition: txop.cc:126
virtual void NotifyCollision(void)
Notify the DCF that collision has occurred.
Definition: txop.cc:555
uint32_t GetBackoffSlots(void) const
Return the current number of backoff slots.
Definition: txop.cc:232
Callback< void, const WifiMacHeader & > TxFailed
typedef for a callback to invoke when a packet transmission was failed.
Definition: txop.h:91
Ptr< WifiMacQueue > GetWifiMacQueue() const
Return the packet queue associated with this Txop.
Definition: txop.cc:178
virtual Time GetTxopRemaining(void) const
Return the remaining duration in the current TXOP.
Definition: txop.cc:888
void MissedCfPollResponse(bool expectedCfAck)
Event handler when a response to a CF-POLL frame is missed.
Definition: txop.cc:713
TxOk m_txOkCallback
the transmit OK callback
Definition: txop.h:501
virtual void SetWifiRemoteStationManager(const Ptr< WifiRemoteStationManager > remoteManager)
Set WifiRemoteStationsManager this Txop is associated to.
Definition: txop.cc:140
uint8_t m_fragmentNumber
the fragment number
Definition: txop.h:529
void SetAifsn(uint8_t aifsn)
Set the number of slots that make up an AIFS.
Definition: txop.cc:269
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:460
WifiMacHeader m_currentHdr
the current header
Definition: txop.h:527
virtual void TerminateTxop(void)
Update backoff and restart access if needed.
Definition: txop.cc:895
void SetTxFailedCallback(TxFailed callback)
Definition: txop.cc:154
virtual ~Txop()
Definition: txop.cc:101
Ptr< WifiRemoteStationManager > m_stationManager
the wifi remote station manager
Definition: txop.h:507
virtual uint32_t GetFragmentOffset(void) const
Calculate the offset for the current fragment.
Definition: txop.cc:425
void SetTxOkCallback(TxOk callback)
Definition: txop.cc:147
virtual void GotBlockAck(const CtrlBAckResponseHeader *blockAck, Mac48Address recipient, double rxSnr, WifiMode txMode, double dataSnr)
Event handler when a Block ACK is received.
Definition: txop.cc:876
virtual uint32_t GetFragmentSize(void) const
Calculate the size of the current fragment.
Definition: txop.cc:401
void ResetCw(void)
Update the value of the CW variable to take into account a transmission success or a transmission abo...
Definition: txop.cc:217
a unique identifier for an interface.
Definition: type-id.h:58
void StartBackoffNow(uint32_t nSlots)
Definition: txop.cc:253
Implements the IEEE 802.11 MAC header.
virtual void NotifyWakeUp(void)
When wake up operation occurs, channel access will be restarted.
Definition: txop.cc:592
TxDropped m_txDroppedCallback
the packet dropped callback
Definition: txop.h:503
Handle packet fragmentation and retransmissions for data and management frames.
Definition: txop.h:65
Time GetTxopLimit(void) const
Return the TXOP limit.
Definition: txop.cc:302