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 
25 #include "wifi-mac-header.h"
26 
27 namespace ns3 {
28 
29 class Packet;
30 class ChannelAccessManager;
31 class MacTxMiddle;
32 class MacLow;
33 class WifiMode;
34 class WifiMacQueue;
35 class WifiMacQueueItem;
36 class UniformRandomVariable;
37 class CtrlBAckResponseHeader;
38 class WifiRemoteStationManager;
39 
64 class Txop : public Object
65 {
66 public:
68  friend class DcfListener;
71 
72  Txop ();
73  virtual ~Txop ();
74 
79  static TypeId GetTypeId (void);
80 
96 
102  virtual bool IsQosTxop () const;
103 
109  void SetMacLow (const Ptr<MacLow> low);
121  virtual void SetWifiRemoteStationManager (const Ptr<WifiRemoteStationManager> remoteManager);
127  void SetTxMiddle (const Ptr<MacTxMiddle> txMiddle);
128 
133  void SetTxOkCallback (TxOk callback);
138  void SetTxFailedCallback (TxFailed callback);
143  void SetTxDroppedCallback (TxDropped callback);
144 
150  Ptr<MacLow> GetLow (void) const;
151 
158 
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;
208 
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);
230 
231  /* Event handlers */
239  virtual void Queue (Ptr<const Packet> packet, const WifiMacHeader &hdr);
240 
247  void SendCfFrame (WifiMacType frameType, Mac48Address addr);
248 
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, double rxSnr, WifiMode txMode, double dataSnr);
286  virtual void MissedBlockAck (uint8_t nMpdus);
287 
292  virtual void StartNextFragment (void);
296  virtual void Cancel (void);
300  virtual void StartNextPacket (void);
305  virtual void EndTxNoAck (void);
306 
313  virtual bool HasTxop (void) const;
314 
321  bool CanStartNextPolling (void) const;
322 
323 
333  int64_t AssignStreams (int64_t stream);
334 
339  virtual bool IsAccessRequested (void) const;
340 
347  void StartBackoffNow (uint32_t nSlots);
348 
349 protected:
351  friend class ChannelAccessManager;
352 
353  virtual void DoDispose (void);
354  virtual void DoInitialize (void);
355 
356  /* dcf notifications forwarded here */
360  virtual void NotifyAccessRequested (void);
364  virtual void NotifyAccessGranted (void);
368  virtual void NotifyInternalCollision (void);
372  virtual void NotifyCollision (void);
373 
377  virtual void RestartAccessIfNeeded (void);
381  virtual void StartAccessIfNeeded (void);
382 
387  uint32_t GetCw (void) const;
394  void ResetCw (void);
400  void UpdateFailedCw (void);
406  uint32_t GetBackoffSlots (void) const;
412  Time GetBackoffStart (void) const;
419  void UpdateBackoffSlotsNow (uint32_t nSlots, Time backoffUpdateBound);
420 
429  bool NeedRtsRetransmission (Ptr<const Packet> packet, const WifiMacHeader &hdr);
438  bool NeedDataRetransmission (Ptr<const Packet> packet, const WifiMacHeader &hdr);
445  virtual bool NeedFragmentation (void) const;
446 
452  void NextFragment (void);
467  virtual uint32_t GetNextFragmentSize (void) const;
473  virtual uint32_t GetFragmentSize (void) const;
479  virtual uint32_t GetFragmentOffset (void) const;
486  virtual bool IsLastFragment (void) const;
495 
505 
506  uint32_t m_cwMin;
507  uint32_t m_cwMax;
508  uint32_t m_cw;
510  uint32_t m_backoffSlots;
511 
517 
518  uint8_t m_aifsn;
520 
525 };
526 
527 } //namespace ns3
528 
529 #endif /* TXOP_H */
TxFailed m_txFailedCallback
the transmit failed callback
Definition: txop.h:498
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:732
uint8_t m_aifsn
the AIFSN
Definition: txop.h:518
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
Definition: txop.h:501
Time m_txopLimit
the txop limit time
Definition: txop.h:519
virtual void RestartAccessIfNeeded(void)
Restart access request if needed.
Definition: txop.cc:313
virtual void StartAccessIfNeeded(void)
Request access from DCF manager if needed.
Definition: txop.cc:326
uint8_t GetAifsn(void) const
Return the number of slots that make up an AIFS.
Definition: txop.cc:284
virtual void StartNextPacket(void)
Start transmission for the next packet if allowed by the TxopLimit.
Definition: txop.cc:816
virtual void EndTxNoAck(void)
Event handler when a transmission that does not require an ACK has completed.
Definition: txop.cc:717
uint32_t m_backoffSlots
the backoff slots
Definition: txop.h:510
virtual void StartNextFragment(void)
Start transmission for the next fragment.
Definition: txop.cc:688
void SetChannelAccessManager(const Ptr< ChannelAccessManager > manager)
Set ChannelAccessManager this Txop is associated to.
Definition: txop.cc:109
Ptr< ChannelAccessManager > m_channelAccessManager
the channel access manager
Definition: txop.h:496
virtual void NotifyAccessGranted(void)
Notify the DCF that access has been granted.
Definition: txop.cc:448
virtual void MissedAck(void)
Event handler when an ACK is missed.
Definition: txop.cc:620
void SetTxDroppedCallback(TxDropped callback)
Definition: txop.cc:151
virtual void DoInitialize(void)
Initialize() implementation.
Definition: txop.cc:345
Time GetBackoffStart(void) const
Return the time when the backoff procedure started.
Definition: txop.cc:226
virtual void Cancel(void)
Cancel the transmission.
Definition: txop.cc:710
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:504
void UpdateBackoffSlotsNow(uint32_t nSlots, Time backoffUpdateBound)
Update backoff slots that nSlots has passed.
Definition: txop.cc:232
bool CanStartNextPolling(void) const
Check if the next PCF transmission can fit in the remaining CFP duration.
Definition: txop.cc:804
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:272
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:507
control how a packet is transmitted.
virtual void NotifyOff(void)
When off operation occurs, the queue gets cleaned up.
Definition: txop.cc:546
void UpdateFailedCw(void)
Update the value of the CW variable to take into account a transmission failure.
Definition: txop.cc:212
friend class DcfListener
allow DcfListener class access
Definition: txop.h:68
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: txop.cc:305
WifiMacType
Combination of valid MAC header type/subtype.
void NextFragment(void)
Continue to the next fragment.
Definition: txop.cc:375
static TypeId GetTypeId(void)
Get the type ID.
Definition: txop.cc:42
Headers for Block ack response.
Definition: ctrl-headers.h:181
virtual bool IsAccessRequested(void) const
Definition: txop.cc:435
virtual bool IsQosTxop() const
Check for QoS TXOP.
Definition: txop.cc:810
virtual uint32_t GetNextFragmentSize(void) const
Calculate the size of the next fragment.
Definition: txop.cc:398
uint32_t m_cwMin
the CW minimum
Definition: txop.h:506
bool NeedRtsRetransmission(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Check if RTS should be re-transmitted if CTS was missed.
Definition: txop.cc:353
Ptr< MacLow > GetLow(void) const
Return the MacLow associated with this Txop.
Definition: txop.cc:339
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:648
uint32_t GetCw(void) const
Definition: txop.cc:199
virtual void NotifySleep(void)
When sleep operation occurs, if there is a pending packet transmission, it will be reinserted to the ...
Definition: txop.cc:535
uint32_t GetMaxCw(void) const
Return the maximum contention window size.
Definition: txop.cc:278
virtual void MissedBlockAck(uint8_t nMpdus)
Event handler when a Block ACK timeout has occurred.
Definition: txop.cc:828
virtual void NotifyOn(void)
When on operation occurs, channel access will be started.
Definition: txop.cc:561
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
Definition: txop.h:500
virtual void DoDispose(void)
Destructor implementation.
Definition: txop.cc:97
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:360
Ptr< const Packet > m_currentPacket
the current packet
Definition: txop.h:521
void SetMacLow(const Ptr< MacLow > low)
Set MacLow associated with this Txop.
Definition: txop.cc:123
virtual bool NeedFragmentation(void) const
Check if the current packet should be fragmented.
Definition: txop.cc:367
virtual Ptr< Packet > GetFragmentPacket(WifiMacHeader *hdr)
Get the next fragment from the packet with appropriate Wifi header for the fragment.
Definition: txop.cc:414
virtual void NotifyChannelSwitching(void)
When a channel switching occurs, enqueued packets are removed.
Definition: txop.cc:527
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 DCF that internal collision has occurred.
Definition: txop.cc:512
Ptr< MacLow > m_low
the MacLow
Definition: txop.h:502
virtual bool IsLastFragment(void) const
Check if the current fragment is the last fragment.
Definition: txop.cc:390
void TxDroppedPacket(Ptr< const WifiMacQueueItem > item)
Pass the packet included in the wifi MAC queue item to the packet dropped callback.
Definition: txop.cc:159
uint32_t m_cw
the current CW
Definition: txop.h:508
Txop()
Definition: txop.cc:76
MacLowTransmissionParameters m_currentParams
current transmission parameters
Definition: txop.h:523
virtual void Queue(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Definition: txop.cc:296
void SetMinCw(uint32_t minCw)
Set the minimum contention window size.
Definition: txop.cc:175
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:187
bool m_accessRequested
flag whether channel access is already requested
Definition: txop.h:509
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
Definition: txop.cc:264
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:516
virtual void GotAck(void)
Event handler when an ACK is received.
Definition: txop.cc:593
virtual void MissedCts(void)
Event handler when a CTS timeout has occurred.
Definition: txop.cc:568
void SetTxMiddle(const Ptr< MacTxMiddle > txMiddle)
Set MacTxMiddle this Txop is associated to.
Definition: txop.cc:116
virtual void NotifyCollision(void)
Notify the DCF that collision has occurred.
Definition: txop.cc:519
uint32_t GetBackoffSlots(void) const
Return the current number of backoff slots.
Definition: txop.cc:220
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:168
void MissedCfPollResponse(bool expectedCfAck)
Event handler when a response to a CF-POLL frame is missed.
Definition: txop.cc:662
TxOk m_txOkCallback
the transmit OK callback
Definition: txop.h:497
virtual void SetWifiRemoteStationManager(const Ptr< WifiRemoteStationManager > remoteManager)
Set WifiRemoteStationsManager this Txop is associated to.
Definition: txop.cc:130
uint8_t m_fragmentNumber
the fragment number
Definition: txop.h:524
void SetAifsn(uint8_t aifsn)
Set the number of slots that make up an AIFS.
Definition: txop.cc:257
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:441
WifiMacHeader m_currentHdr
the current header
Definition: txop.h:522
void SetTxFailedCallback(TxFailed callback)
Definition: txop.cc:144
virtual ~Txop()
Definition: txop.cc:91
Ptr< WifiRemoteStationManager > m_stationManager
the wifi remote station manager
Definition: txop.h:503
virtual uint32_t GetFragmentOffset(void) const
Calculate the offset for the current fragment.
Definition: txop.cc:406
void SetTxOkCallback(TxOk callback)
Definition: txop.cc:137
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:822
virtual uint32_t GetFragmentSize(void) const
Calculate the size of the current fragment.
Definition: txop.cc:382
void ResetCw(void)
Update the value of the CW variable to take into account a transmission success or a transmission abo...
Definition: txop.cc:205
a unique identifier for an interface.
Definition: type-id.h:58
void StartBackoffNow(uint32_t nSlots)
Definition: txop.cc:241
virtual bool HasTxop(void) const
Check if the station has TXOP granted for the next MPDU.
Definition: txop.cc:834
Implements the IEEE 802.11 MAC header.
virtual void NotifyWakeUp(void)
When wake up operation occurs, channel access will be restarted.
Definition: txop.cc:554
TxDropped m_txDroppedCallback
the packet dropped callback
Definition: txop.h:499
Handle packet fragmentation and retransmissions for data and management frames.
Definition: txop.h:64
Time GetTxopLimit(void) const
Return the TXOP limit.
Definition: txop.cc:290