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 
65 class Txop : public Object
66 {
67 public:
69  friend class DcfListener;
72 
73  Txop ();
74  virtual ~Txop ();
75 
80  static TypeId GetTypeId (void);
81 
97 
103  virtual bool IsQosTxop () const;
104 
110  void SetMacLow (const Ptr<MacLow> low);
122  virtual void SetWifiRemoteStationManager (const Ptr<WifiRemoteStationManager> remoteManager);
128  void SetTxMiddle (const Ptr<MacTxMiddle> txMiddle);
129 
134  void SetTxOkCallback (TxOk callback);
139  void SetTxFailedCallback (TxFailed callback);
144  void SetTxDroppedCallback (TxDropped callback);
145 
151  Ptr<MacLow> GetLow (void) const;
152 
159 
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;
209 
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);
231 
232  /* Event handlers */
240  virtual void Queue (Ptr<Packet> packet, const WifiMacHeader &hdr);
241 
248  void SendCfFrame (WifiMacType frameType, Mac48Address addr);
249 
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);
288 
293  virtual void StartNextFragment (void);
297  virtual void Cancel (void);
301  virtual void StartNextPacket (void);
306  virtual void EndTxNoAck (void);
307 
313  virtual Time GetTxopRemaining (void) const;
317  virtual void TerminateTxop (void);
318 
325  bool CanStartNextPolling (void) const;
326 
327 
337  int64_t AssignStreams (int64_t stream);
338 
343  virtual bool IsAccessRequested (void) const;
344 
351  void StartBackoffNow (uint32_t nSlots);
352 
353 protected:
355  friend class ChannelAccessManager;
356 
357  virtual void DoDispose (void);
358  virtual void DoInitialize (void);
359 
360  /* dcf notifications forwarded here */
364  virtual void NotifyAccessRequested (void);
368  virtual void NotifyAccessGranted (void);
372  virtual void NotifyInternalCollision (void);
373 
378  virtual bool HasFramesToTransmit (void);
382  virtual void GenerateBackoff (void);
386  virtual void RestartAccessIfNeeded (void);
390  virtual void StartAccessIfNeeded (void);
391 
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);
429 
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;
455 
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;
504 
514 
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;
521 
527 
528  uint8_t m_aifsn;
530 
537 };
538 
539 } //namespace ns3
540 
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:787
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
uint8_t m_aifsn
the 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
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 DCF manager if needed.
Definition: txop.cc:353
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:871
virtual void EndTxNoAck(void)
Event handler when a transmission that does not require an ACK has completed.
Definition: txop.cc:771
uint32_t m_backoffSlots
the backoff slots
Definition: txop.h:520
virtual bool HasFramesToTransmit(void)
Check if the DCF has frames to transmit.
Definition: txop.cc:308
virtual void StartNextFragment(void)
Start transmission for the next fragment.
Definition: txop.cc:742
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:119
Ptr< ChannelAccessManager > m_channelAccessManager
the channel access manager
Definition: txop.h:505
virtual void NotifyAccessGranted(void)
Notify the DCF that access has been granted.
Definition: txop.cc:476
virtual void MissedAck(void)
Event handler when an ACK is missed.
Definition: txop.cc:670
void SetTxDroppedCallback(TxDropped callback)
Definition: txop.cc:161
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:238
virtual void Cancel(void)
Cancel the transmission.
Definition: txop.cc:764
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:244
bool CanStartNextPolling(void) const
Check if the next PCF transmission can fit in the remaining CFP duration.
Definition: txop.cc:859
virtual void GenerateBackoff(void)
Generate a new backoff now.
Definition: txop.cc:557
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:516
control how a packet is transmitted.
virtual void NotifyOff(void)
When off operation occurs, the queue gets cleaned up.
Definition: txop.cc:593
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:332
WifiMacType
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:43
Headers for Block ack 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:865
virtual uint32_t GetNextFragmentSize(void) const
Calculate the size of the next fragment.
Definition: txop.cc:426
uint32_t m_cwMin
the CW minimum
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:702
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:582
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:883
virtual void NotifyOn(void)
When on operation occurs, channel access will be started.
Definition: txop.cc:608
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
Definition: txop.h:509
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: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:133
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:574
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:566
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:169
uint32_t m_cw
the current CW
Definition: txop.h:517
Txop()
Definition: txop.cc:85
MacLowTransmissionParameters m_currentParams
current transmission parameters
Definition: txop.h:533
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:519
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:526
virtual void GotAck(void)
Event handler when an ACK is received.
Definition: txop.cc:642
virtual void MissedCts(void)
Event handler when a CTS timeout has occurred.
Definition: txop.cc:615
void SetTxMiddle(const Ptr< MacTxMiddle > txMiddle)
Set MacTxMiddle this Txop is associated to.
Definition: txop.cc:126
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:889
void MissedCfPollResponse(bool expectedCfAck)
Event handler when a response to a CF-POLL frame is missed.
Definition: txop.cc:716
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:140
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: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: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:896
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: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: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:877
virtual void Queue(Ptr< Packet > packet, const WifiMacHeader &hdr)
Definition: txop.cc:316
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: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:601
TxDropped m_txDroppedCallback
the packet dropped callback
Definition: txop.h:508
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