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"
26 #include "wifi-mac-header.h"
27 
28 namespace ns3 {
29 
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;
41 
66 class Txop : public Object
67 {
68 public:
71 
72  Txop ();
73  virtual ~Txop ();
74 
79  static TypeId GetTypeId (void);
80 
96 
101  {
105  };
106 
112  virtual bool IsQosTxop () const;
113 
119  void SetMacLow (const Ptr<MacLow> low);
131  virtual void SetWifiRemoteStationManager (const Ptr<WifiRemoteStationManager> remoteManager);
137  void SetTxMiddle (const Ptr<MacTxMiddle> txMiddle);
138 
143  void SetTxOkCallback (TxOk callback);
148  void SetTxFailedCallback (TxFailed callback);
153  void SetTxDroppedCallback (TxDropped callback);
154 
160  Ptr<MacLow> GetLow (void) const;
161 
168 
174  void SetMinCw (uint32_t minCw);
180  void SetMaxCw (uint32_t maxCw);
186  void SetAifsn (uint8_t aifsn);
193  void SetTxopLimit (Time txopLimit);
199  uint32_t GetMinCw (void) const;
205  uint32_t GetMaxCw (void) const;
211  uint8_t GetAifsn (void) const;
217  Time GetTxopLimit (void) const;
224  void ResetCw (void);
230  void UpdateFailedCw (void);
231 
235  virtual void NotifyChannelSwitching (void);
240  virtual void NotifySleep (void);
244  virtual void NotifyOff (void);
248  virtual void NotifyWakeUp (void);
252  virtual void NotifyOn (void);
253 
254  /* Event handlers */
262  virtual void Queue (Ptr<Packet> packet, const WifiMacHeader &hdr);
263 
270  void SendCfFrame (WifiMacType frameType, Mac48Address addr);
271 
272  /* Event handlers */
276  virtual void MissedCts (void);
280  virtual void GotAck (void);
284  virtual void MissedAck (void);
288  void GotCfEnd (void);
294  void MissedCfPollResponse (bool expectedCfAck);
304  virtual void GotBlockAck (const CtrlBAckResponseHeader *blockAck, Mac48Address recipient,
305  double rxSnr, double dataSnr, WifiTxVector dataTxVector);
310  virtual void MissedBlockAck (uint8_t nMpdus);
311 
316  virtual void StartNextFragment (void);
320  virtual void Cancel (void);
324  virtual void StartNextPacket (void);
329  virtual void EndTxNoAck (void);
330 
336  virtual Time GetTxopRemaining (void) const;
340  virtual void TerminateTxop (void);
341 
346  virtual void NotifyChannelAccessed (void);
351  virtual void NotifyChannelReleased (void);
352 
359  bool CanStartNextPolling (void) const;
360 
361 
371  int64_t AssignStreams (int64_t stream);
372 
376  virtual ChannelAccessStatus GetAccessStatus (void) const;
377 
384  void StartBackoffNow (uint32_t nSlots);
385 
386 protected:
388  friend class ChannelAccessManager;
389 
390  virtual void DoDispose (void);
391  virtual void DoInitialize (void);
392 
393  /* Txop notifications forwarded here */
397  virtual void NotifyAccessRequested (void);
401  virtual void NotifyAccessGranted (void);
405  virtual void NotifyInternalCollision (void);
406 
411  virtual bool HasFramesToTransmit (void);
415  virtual void GenerateBackoff (void);
419  virtual void RestartAccessIfNeeded (void);
423  virtual void StartAccessIfNeeded (void);
427  void RequestAccess (void);
428 
433  uint32_t GetCw (void) const;
439  uint32_t GetBackoffSlots (void) const;
445  Time GetBackoffStart (void) const;
452  void UpdateBackoffSlotsNow (uint32_t nSlots, Time backoffUpdateBound);
453 
462  bool NeedRtsRetransmission (Ptr<const Packet> packet, const WifiMacHeader &hdr);
471  bool NeedDataRetransmission (Ptr<const Packet> packet, const WifiMacHeader &hdr);
478  virtual bool NeedFragmentation (void) const;
479 
485  void NextFragment (void);
500  virtual uint32_t GetNextFragmentSize (void) const;
506  virtual uint32_t GetFragmentSize (void) const;
512  virtual uint32_t GetFragmentOffset (void) const;
519  virtual bool IsLastFragment (void) const;
528 
538 
539  uint32_t m_cwMin;
540  uint32_t m_cwMax;
541  uint32_t m_cw;
542  uint32_t m_backoff;
544  uint32_t m_backoffSlots;
545 
551 
552  uint8_t m_aifsn;
554 
561 };
562 
563 } //namespace ns3
564 
565 #endif /* TXOP_H */
TxFailed m_txFailedCallback
the transmit failed callback
Definition: txop.h:531
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
void SendCfFrame(WifiMacType frameType, Mac48Address addr)
Sends CF frame to STA with address addr.
Definition: txop.cc:803
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
uint8_t m_aifsn
the AIFSN
Definition: txop.h:552
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
Definition: txop.h:534
TracedCallback< uint32_t > m_backoffTrace
backoff trace value
Definition: txop.h:559
TracedValue< uint32_t > m_cwTrace
CW trace value.
Definition: txop.h:560
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:553
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:887
virtual void EndTxNoAck(void)
Event handler when a transmission that does not require an Ack has completed.
Definition: txop.cc:788
uint32_t m_backoffSlots
the number of backoff slots
Definition: txop.h:544
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:759
uint32_t m_backoff
the current backoff
Definition: txop.h:542
void RequestAccess(void)
Request access to the ChannelAccessManager.
Definition: txop.cc:493
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:529
virtual void NotifyAccessGranted(void)
Notify the Txop that access has been granted.
Definition: txop.cc:502
virtual void MissedAck(void)
Event handler when an Ack is missed.
Definition: txop.cc:689
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:781
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:537
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:875
virtual void GenerateBackoff(void)
Generate a new backoff now.
Definition: txop.cc:579
Callback< void, Ptr< const Packet > > TxDropped
typedef for a callback to invoke when a packet is dropped.
Definition: txop.h:95
virtual ChannelAccessStatus GetAccessStatus(void) const
Definition: txop.cc:461
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:540
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:893
virtual void NotifyOff(void)
When off operation occurs, the queue gets cleaned up.
Definition: txop.cc:615
ChannelAccessStatus
Enumeration for channel access status.
Definition: txop.h:100
void UpdateFailedCw(void)
Update the value of the CW variable to take into account a transmission failure.
Definition: txop.cc:224
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
WifiMacType
Combination of valid MAC header type/subtype.
void NextFragment(void)
Continue to the next fragment.
Definition: txop.cc:401
virtual void NotifyChannelReleased(void)
Called by the FrameExchangeManager to notify the completion of the transmissions. ...
Definition: txop.cc:481
static TypeId GetTypeId(void)
Get the type ID.
Definition: txop.cc:44
Headers for BlockAck response.
Definition: ctrl-headers.h:193
ChannelAccessStatus m_access
channel access status
Definition: txop.h:543
virtual bool IsQosTxop() const
Check for QoS TXOP.
Definition: txop.cc:881
virtual uint32_t GetNextFragmentSize(void) const
Calculate the size of the next fragment.
Definition: txop.cc:424
uint32_t m_cwMin
the minimum contention window
Definition: txop.h:539
bool NeedRtsRetransmission(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Check if RTS should be re-transmitted if CTS was missed.
Definition: txop.cc:380
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:719
uint32_t GetCw(void) const
Definition: txop.cc:210
virtual void NotifySleep(void)
When sleep operation occurs, if there is a pending packet transmission, it will be reinserted to the ...
Definition: txop.cc:604
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:899
virtual void NotifyOn(void)
When on operation occurs, channel access will be started.
Definition: txop.cc:630
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
Definition: txop.h:533
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:387
Ptr< const Packet > m_currentPacket
the current packet
Definition: txop.h:555
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:394
virtual Ptr< Packet > GetFragmentPacket(WifiMacHeader *hdr)
Get the next fragment from the packet with appropriate Wifi header for the fragment.
Definition: txop.cc:440
virtual void NotifyChannelSwitching(void)
When a channel switching occurs, enqueued packets are removed.
Definition: txop.cc:596
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:588
Ptr< MacLow > m_low
the MacLow
Definition: txop.h:535
virtual bool IsLastFragment(void) const
Check if the current fragment is the last fragment.
Definition: txop.cc:416
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:541
Txop()
Definition: txop.cc:86
MacLowTransmissionParameters m_currentParams
current transmission parameters
Definition: txop.h:557
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:198
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:550
virtual void GotAck(void)
Event handler when an Ack is received.
Definition: txop.cc:662
virtual void MissedCts(void)
Event handler when a CTS timeout has occurred.
Definition: txop.cc:637
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:905
void MissedCfPollResponse(bool expectedCfAck)
Event handler when a response to a CF-POLL frame is missed.
Definition: txop.cc:733
TxOk m_txOkCallback
the transmit OK callback
Definition: txop.h:530
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:558
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:467
WifiMacHeader m_currentHdr
the current header
Definition: txop.h:556
virtual void TerminateTxop(void)
Update backoff and restart access if needed.
Definition: txop.cc:912
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:536
virtual uint32_t GetFragmentOffset(void) const
Calculate the offset for the current fragment.
Definition: txop.cc:432
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:408
void ResetCw(void)
Update the value of the CW variable to take into account a transmission success or a transmission abo...
Definition: txop.cc:216
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:623
TxDropped m_txDroppedCallback
the packet dropped callback
Definition: txop.h:532
virtual void NotifyChannelAccessed(void)
Called by the FrameExchangeManager to notify that channel access has been granted.
Definition: txop.cc:474
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