A Discrete-Event Network Simulator
API
edca-txop-n.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2006, 2009 INRIA
4  * Copyright (c) 2009 MIRKO BANCHI
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  * Mirko Banchi <mk.banchi@gmail.com>
21  */
22 #ifndef EDCA_TXOP_N_H
23 #define EDCA_TXOP_N_H
24 
25 #include "ns3/object.h"
26 #include "ns3/mac48-address.h"
27 #include "ns3/packet.h"
28 #include "ns3/traced-value.h"
29 #include "wifi-mode.h"
30 #include "wifi-mac-header.h"
32 #include "qos-utils.h"
33 #include "dcf.h"
34 #include "ctrl-headers.h"
35 #include "block-ack-manager.h"
36 #include <map>
37 #include <list>
38 
40 
41 namespace ns3 {
42 
43 class DcfState;
44 class DcfManager;
45 class MacLow;
46 class MacTxMiddle;
47 class WifiMac;
48 class WifiMacParameters;
49 class WifiMacQueue;
50 class RandomStream;
51 class QosBlockedDestinations;
52 class MsduAggregator;
53 class MpduAggregator;
54 class MgtAddBaResponseHeader;
55 class BlockAckManager;
56 class MgtDelBaHeader;
57 
62 {
63  STA,
64  AP,
71 };
72 
73 
86 class EdcaTxopN : public Dcf
87 {
88 public:
89  // Allow test cases to access private members
90  friend class ::AmpduAggregationTest;
91 
102 
103  std::map<Mac48Address, bool> m_aMpduEnabled;
104 
105  static TypeId GetTypeId (void);
106  EdcaTxopN ();
107  virtual ~EdcaTxopN ();
108  void DoDispose ();
109 
115  void SetLow (Ptr<MacLow> low);
116  void SetTxMiddle (MacTxMiddle *txMiddle);
122  void SetManager (DcfManager *manager);
127  void SetTxOkCallback (TxOk callback);
132  void SetTxFailedCallback (TxFailed callback);
144  void SetTypeOfStation (enum TypeOfStation type);
150  enum TypeOfStation GetTypeOfStation (void) const;
157 
158  virtual void SetMinCw (uint32_t minCw);
159  virtual void SetMaxCw (uint32_t maxCw);
160  virtual void SetAifsn (uint32_t aifsn);
161  virtual void SetTxopLimit (Time txopLimit);
162  virtual uint32_t GetMinCw (void) const;
163  virtual uint32_t GetMaxCw (void) const;
164  virtual uint32_t GetAifsn (void) const;
165  virtual Time GetTxopLimit (void) const;
166 
172  Ptr<MacLow> Low (void);
173 
176 
185  bool GetBaAgreementExists (Mac48Address address, uint8_t tid) const;
193  uint32_t GetNOutstandingPacketsInBa (Mac48Address address, uint8_t tid);
201  uint32_t GetNRetryNeededPackets (Mac48Address recipient, uint8_t tid) const;
209  void CompleteAmpduTransfer (Mac48Address recipient, uint8_t tid);
210 
211  /* dcf notifications forwarded here */
218  bool NeedsAccess (void) const;
222  void NotifyAccessGranted (void);
226  void NotifyInternalCollision (void);
230  void NotifyCollision (void);
234  void NotifyChannelSwitching (void);
238  void NotifySleep (void);
242  void NotifyWakeUp (void);
243 
244  /* Event handlers */
251  void GotCts (double snr, WifiMode txMode);
255  void MissedCts (void);
262  void GotAck (double snr, WifiMode txMode);
272  void GotBlockAck (const CtrlBAckResponseHeader *blockAck, Mac48Address recipient, double rxSnr, WifiMode txMode, double dataSnr);
276  void MissedBlockAck (uint32_t nMpdus);
277  void GotAddBaResponse (const MgtAddBaResponseHeader *respHdr, Mac48Address recipient);
278  void GotDelBaFrame (const MgtDelBaHeader *delBaHdr, Mac48Address recipient);
282  void MissedAck (void);
287  void StartNextFragment (void);
291  void StartNext (void);
295  void Cancel (void);
300  void EndTxNoAck (void);
304  void RestartAccessIfNeeded (void);
308  void StartAccessIfNeeded (void);
317  bool NeedRtsRetransmission (Ptr<const Packet> packet, const WifiMacHeader &hdr);
326  bool NeedDataRetransmission (Ptr<const Packet> packet, const WifiMacHeader &hdr);
333  bool NeedBarRetransmission (void);
340  bool NeedFragmentation (void) const;
346  uint32_t GetNextFragmentSize (void);
352  uint32_t GetFragmentSize (void);
358  uint32_t GetFragmentOffset (void);
365  bool IsLastFragment (void) const;
371  void NextFragment (void);
380 
386  void SetAccessCategory (enum AcIndex ac);
387 
395  void Queue (Ptr<const Packet> packet, const WifiMacHeader &hdr);
396 
399 
407  void PushFront (Ptr<const Packet> packet, const WifiMacHeader &hdr);
408 
412  void CompleteConfig (void);
413 
420  void SetBlockAckThreshold (uint8_t threshold);
426  uint8_t GetBlockAckThreshold (void) const;
427 
428  void SetBlockAckInactivityTimeout (uint16_t timeout);
429  void SendDelbaFrame (Mac48Address addr, uint8_t tid, bool byOriginator);
430  void CompleteMpduTx (Ptr<const Packet> packet, WifiMacHeader hdr, Time tstamp);
431  bool GetAmpduExist (Mac48Address dest) const;
432  void SetAmpduExist (Mac48Address dest, bool enableAmpdu);
433 
441  uint16_t GetNextSequenceNumberfor (WifiMacHeader *hdr);
453  void RemoveRetransmitPacket (uint8_t tid, Mac48Address recipient, uint16_t seqnumber);
454  /*
455  * Peek in retransmit queue and get the next packet without removing it from the queue
456  */
457  Ptr<const Packet> PeekNextRetransmitPacket (WifiMacHeader &header, Mac48Address recipient, uint8_t tid, Time *timestamp);
463  void BaTxOk (const WifiMacHeader &hdr);
469  void BaTxFailed (const WifiMacHeader &hdr);
470 
479  int64_t AssignStreams (int64_t stream);
480 
481 
482 private:
483  void DoInitialize ();
498  EdcaTxopN &operator = (const EdcaTxopN &);
499  EdcaTxopN (const EdcaTxopN &);
500 
507  bool SetupBlockAckIfNeeded ();
518  void SendAddBaRequest (Mac48Address recipient, uint8_t tid, uint16_t startSeq,
519  uint16_t timeout, bool immediateBAck);
526  void SendBlockAckRequest (const struct Bar &bar);
531  void CompleteTx (void);
536  void VerifyBlockAck (void);
540  uint8_t GetCurrentTid () const;
541  /*
542  * Return the remaining duration in the current TXOP.
543  *
544  * \return the remaining duration in the current TXOP
545  */
546  Time GetTxopRemaining (void);
547  /*
548  * Check if the station has TXOP granted for the next MPDU.
549  *
550  * \return true if the station has TXOP granted for the next MPDU,
551  * false otherwise
552  */
553  bool HasTxop (void);
554 
556  class Dcf;
557  class TransmissionListener;
559  friend class Dcf;
560  friend class TransmissionListener;
573 
574  /* current packet could be a simple MSDU or, if an aggregator for this queue is
575  present, could be an A-MSDU.
576  */
578 
585  /*
586  * Represents the minimum number of packets for use of block ack.
587  */
597 };
598 
599 } //namespace ns3
600 
601 #endif /* EDCA_TXOP_N_H */
Keep track of destination address - TID pairs that are waiting for a block ACK response.
virtual void SetMaxCw(uint32_t maxCw)
Set the maximum contention window size.
Definition: edca-txop-n.cc:399
TransmissionListener * m_transmissionListener
Definition: edca-txop-n.h:568
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Ptr< const Packet > m_currentPacket
Definition: edca-txop-n.h:577
void DoInitialize()
Initialize() implementation.
TxFailed m_txFailedCallback
Definition: edca-txop-n.h:565
void NotifyWakeUp(void)
When wake up operation occurs, restart channel access.
Definition: edca-txop-n.cc:894
void SetBlockAckInactivityTimeout(uint16_t timeout)
uint32_t GetFragmentSize(void)
Calculate the size of the current fragment.
uint16_t m_blockAckInactivityTimeout
Definition: edca-txop-n.h:591
void VerifyBlockAck(void)
Verifies if dequeued packet has to be transmitted with ack policy Block Ack.
void NotifyCollision(void)
Notify the EDCAF that collision has occurred.
Definition: edca-txop-n.cc:731
void SetTypeOfStation(enum TypeOfStation type)
Set type of station with the given type.
Definition: edca-txop-n.cc:371
void CompleteMpduTx(Ptr< const Packet > packet, WifiMacHeader hdr, Time tstamp)
void SetTxFailedCallback(TxFailed callback)
Definition: edca-txop-n.cc:356
void GotAck(double snr, WifiMode txMode)
Event handler when an ACK is received.
Definition: edca-txop-n.cc:910
bool NeedBarRetransmission(void)
Check if Block ACK Request should be re-transmitted.
uint8_t m_blockAckThreshold
Definition: edca-txop-n.h:588
void SetWifiRemoteStationManager(Ptr< WifiRemoteStationManager > remoteManager)
Set WifiRemoteStationsManager this EdcaTxopN is associated to.
Definition: edca-txop-n.cc:363
WifiMacHeader m_currentHdr
Definition: edca-txop-n.h:579
void NotifySleep(void)
When sleep operation occurs, re-insert pending packet into front of the queue.
Definition: edca-txop-n.cc:883
Ptr< MsduAggregator > m_msduAggregator
Definition: edca-txop-n.h:580
ns3::Time timeout
BlockAckType
Enumeration for different block ACK policies.
Definition: ctrl-headers.h:31
virtual Time GetTxopLimit(void) const
Return the TXOP limit.
Definition: edca-txop-n.cc:441
Block Ack Request.
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:99
void NextFragment(void)
Continue to the next fragment.
uint8_t GetCurrentTid() const
Get Traffic ID of the current packet.
Definition: edca-txop-n.cc:747
void SetTxOkCallback(TxOk callback)
Definition: edca-txop-n.cc:349
BlockAckManager * m_baManager
Definition: edca-txop-n.h:584
struct Bar m_currentBar
Definition: edca-txop-n.h:592
bool m_isAccessRequestedForRts
Definition: edca-txop-n.h:594
virtual uint32_t GetAifsn(void) const
Return the number of slots that make up an AIFS.
Definition: edca-txop-n.cc:434
void MissedBlockAck(uint32_t nMpdus)
Event handler when a Block ACK timeout has occurred.
Handles sequence numbering of IEEE 802.11 data frames.
Definition: mac-tx-middle.h:39
Ptr< MpduAggregator > m_mpduAggregator
Definition: edca-txop-n.h:581
DcfManager * m_manager
Definition: edca-txop-n.h:562
void MissedAck(void)
Event handler when an ACK is missed.
Definition: edca-txop-n.cc:960
enum TypeOfStation GetTypeOfStation(void) const
Return type of station.
Definition: edca-txop-n.cc:378
void SetLow(Ptr< MacLow > low)
Set MacLow associated with this EdcaTxopN.
Definition: edca-txop-n.cc:461
Ptr< MacLow > Low(void)
Return the MacLow associated with this EdcaTxopN.
Definition: edca-txop-n.cc:455
Ptr< WifiRemoteStationManager > m_stationManager
Definition: edca-txop-n.h:571
This queue contains packets for a particular access class.
Definition: edca-txop-n.h:86
void GotDelBaFrame(const MgtDelBaHeader *delBaHdr, Mac48Address recipient)
void NotifyAccessGranted(void)
Notify the EDCAF that access has been granted.
Definition: edca-txop-n.cc:497
RandomStream * m_rng
Definition: edca-txop-n.h:570
void RemoveRetransmitPacket(uint8_t tid, Mac48Address recipient, uint16_t seqnumber)
Remove a packet after you peek in the retransmit queue and get it.
Definition: edca-txop-n.cc:491
void NotifyInternalCollision(void)
Notify the EDCAF that internal collision has occurred.
Definition: edca-txop-n.cc:655
std::map< Mac48Address, bool > m_aMpduEnabled
Definition: edca-txop-n.h:103
TracedValue< uint32_t > m_cwTrace
Definition: edca-txop-n.h:596
TracedValue< uint32_t > m_backoffTrace
Definition: edca-txop-n.h:595
virtual void SetMinCw(uint32_t minCw)
Set the minimum contention window size.
Definition: edca-txop-n.cc:392
void SendAddBaRequest(Mac48Address recipient, uint8_t tid, uint16_t startSeq, uint16_t timeout, bool immediateBAck)
Sends an ADDBA Request to establish a block ack agreement with sta addressed by recipient for tid tid...
Ptr< const Packet > PeekNextRetransmitPacket(WifiMacHeader &header, Mac48Address recipient, uint8_t tid, Time *timestamp)
Definition: edca-txop-n.cc:485
void SendDelbaFrame(Mac48Address addr, uint8_t tid, bool byOriginator)
void SetBlockAckThreshold(uint8_t threshold)
Set threshold for block ACK mechanism.
MacTxMiddle * m_txMiddle
Definition: edca-txop-n.h:567
Callback< void, const WifiMacHeader & > TxOk
typedef for a callback to invoke when a packet transmission was completed successfully.
Definition: edca-txop-n.h:96
void MissedCts(void)
Event handler when a CTS timeout has occurred.
Definition: edca-txop-n.cc:812
Manage a set of ns3::DcfStateHandle a set of independent ns3::DcfState, each of which represents a si...
Definition: dcf-manager.h:279
A simple wrapper around RngStream to make testing of the code easier.
Definition: random-stream.h:34
uint16_t PeekNextSequenceNumberfor(WifiMacHeader *hdr)
Return the next sequence number for the Traffic ID and destination, but do not pick it (i...
Definition: edca-txop-n.cc:479
Headers for Block ack response.
Definition: ctrl-headers.h:186
void NotifyChannelSwitching(void)
When a channel switching occurs, enqueued packets are removed.
Definition: edca-txop-n.cc:875
void StartNextFragment(void)
Start transmission for the next fragment.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Ptr< Packet > GetFragmentPacket(WifiMacHeader *hdr)
Get the next fragment from the packet with appropriate Wifi header for the fragment.
virtual ~EdcaTxopN()
Definition: edca-txop-n.cc:287
bool HasTxop(void)
uint32_t GetNRetryNeededPackets(Mac48Address recipient, uint8_t tid) const
Definition: edca-txop-n.cc:329
uint8_t m_fragmentNumber
Definition: edca-txop-n.h:572
Time m_currentPacketTimestamp
Definition: edca-txop-n.h:590
virtual uint32_t GetMinCw(void) const
Return the minimum contention window size.
Definition: edca-txop-n.cc:420
void EndTxNoAck(void)
Event handler when a transmission that does not require an ACK has completed.
bool NeedFragmentation(void) const
Check if the current packet should be fragmented.
Ptr< MpduAggregator > GetMpduAggregator(void) const
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< MsduAggregator > GetMsduAggregator(void) const
void SetAccessCategory(enum AcIndex ac)
Set the access category of this EDCAF.
Callback< void, const WifiMacHeader & > TxFailed
typedef for a callback to invoke when a packet transmission was failed.
Definition: edca-txop-n.h:101
Mac48Address MapDestAddressForAggregation(const WifiMacHeader &hdr)
void SetMpduAggregator(Ptr< MpduAggregator > aggr)
bool SetupBlockAckIfNeeded()
If number of packets in the queue reaches m_blockAckThreshold value, an ADDBA Request frame is sent t...
bool GetBaAgreementExists(Mac48Address address, uint8_t tid) const
Definition: edca-txop-n.cc:317
void StartNext(void)
Start transmission for the next packet if allowed by the TxopLimit.
an EUI-48 address
Definition: mac48-address.h:43
void SetAmpduExist(Mac48Address dest, bool enableAmpdu)
void Cancel(void)
Cancel the transmission.
void BaTxOk(const WifiMacHeader &hdr)
The packet we sent was successfully received by the receiver.
void SetManager(DcfManager *manager)
Set DcfManager this EdcaTxopN is associated to.
Definition: edca-txop-n.cc:341
void Queue(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Definition: edca-txop-n.cc:901
uint16_t GetNextSequenceNumberfor(WifiMacHeader *hdr)
Return the next sequence number for the given header.
Definition: edca-txop-n.cc:474
void SetMsduAggregator(Ptr< MsduAggregator > aggr)
bool GetAmpduExist(Mac48Address dest) const
void GotBlockAck(const CtrlBAckResponseHeader *blockAck, Mac48Address recipient, double rxSnr, WifiMode txMode, double dataSnr)
Event handler when a Block ACK is received.
EdcaTxopN & operator=(const EdcaTxopN &)
void PushFront(Ptr< const Packet > packet, const WifiMacHeader &hdr)
enum BlockAckType m_blockAckType
Definition: edca-txop-n.h:589
static TypeId GetTypeId(void)
Definition: edca-txop-n.cc:237
void BaTxFailed(const WifiMacHeader &hdr)
The packet we sent was successfully received by the receiver.
uint32_t GetNextFragmentSize(void)
Calculate the size of the next fragment.
bool NeedRtsRetransmission(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Check if RTS should be re-transmitted if CTS was missed.
void CompleteConfig(void)
Complete block ACK configuration.
void RestartAccessIfNeeded(void)
Restart access request if needed.
Implement the header for management frames of type add block ack response.
Definition: mgt-headers.h:799
QosBlockedDestinations * m_qosBlockedDestinations
Definition: edca-txop-n.h:583
Implement the header for management frames of type del block ack.
Definition: mgt-headers.h:920
void CompleteAmpduTransfer(Mac48Address recipient, uint8_t tid)
Definition: edca-txop-n.cc:335
Ptr< MacLow > m_low
Definition: edca-txop-n.h:566
uint8_t GetBlockAckThreshold(void) const
Return the current threshold for block ACK mechanism.
void CompleteTx(void)
For now is typically invoked to complete transmission of a packets sent with ack policy Block Ack: th...
void SetTxMiddle(MacTxMiddle *txMiddle)
Definition: edca-txop-n.cc:448
void GotCts(double snr, WifiMode txMode)
Event handler when a CTS is received.
Definition: edca-txop-n.cc:740
Time GetTxopRemaining(void)
void DoDispose()
Destructor implementation.
Definition: edca-txop-n.cc:293
bool NeedDataRetransmission(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Check if DATA should be re-transmitted if ACK was missed.
bool IsLastFragment(void) const
Check if the current fragment is the last fragment.
virtual uint32_t GetMaxCw(void) const
Return the maximum contention window size.
Definition: edca-txop-n.cc:427
Ptr< WifiMacQueue > m_queue
Definition: edca-txop-n.h:563
void StartAccessIfNeeded(void)
Request access from DCF manager if needed.
tuple address
Definition: first.py:37
void SendBlockAckRequest(const struct Bar &bar)
After that all packets, for which a block ack agreement was established, have been transmitted...
TypeOfStation
Enumeration for type of station.
Definition: edca-txop-n.h:61
virtual void SetTxopLimit(Time txopLimit)
Definition: edca-txop-n.cc:413
Manages all block ack agreements for an originator station.
uint32_t GetNOutstandingPacketsInBa(Mac48Address address, uint8_t tid)
Definition: edca-txop-n.cc:323
a unique identifier for an interface.
Definition: type-id.h:58
bool NeedsAccess(void) const
Check if the EDCAF requires access.
Definition: edca-txop-n.cc:468
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:36
uint32_t GetFragmentOffset(void)
Calculate the offset for the current fragment.
AggregationCapableTransmissionListener * m_blockAckListener
Definition: edca-txop-n.h:569
Implements the IEEE 802.11 MAC header.
void GotAddBaResponse(const MgtAddBaResponseHeader *respHdr, Mac48Address recipient)
virtual void SetAifsn(uint32_t aifsn)
Definition: edca-txop-n.cc:406
TypeOfStation m_typeOfStation
Definition: edca-txop-n.h:582
Mac48Address MapSrcAddressForAggregation(const WifiMacHeader &hdr)
This functions are used only to correctly set addresses in a-msdu subframe.
Ptr< WifiMacQueue > GetEdcaQueue() const
Return the packet queue associated with this EdcaTxopN.
Definition: edca-txop-n.cc:385