A Discrete-Event Network Simulator
API
qos-frame-exchange-manager.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2020 Universita' degli Studi di Napoli Federico II
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: Stefano Avallone <stavallo@unina.it>
19  */
20 
21 #include "ns3/log.h"
22 #include "ns3/abort.h"
24 #include "wifi-mac-queue.h"
25 #include "wifi-mac-trailer.h"
26 #include "ap-wifi-mac.h"
27 
28 #undef NS_LOG_APPEND_CONTEXT
29 #define NS_LOG_APPEND_CONTEXT std::clog << "[mac=" << m_self << "] "
30 
31 namespace ns3 {
32 
33 NS_LOG_COMPONENT_DEFINE ("QosFrameExchangeManager");
34 
35 NS_OBJECT_ENSURE_REGISTERED (QosFrameExchangeManager);
36 
37 TypeId
39 {
40  static TypeId tid = TypeId ("ns3::QosFrameExchangeManager")
42  .AddConstructor<QosFrameExchangeManager> ()
43  .SetGroupName ("Wifi")
44  .AddAttribute ("PifsRecovery",
45  "Perform a PIFS recovery as a response to transmission failure "
46  "within a TXOP",
47  BooleanValue (true),
50  ;
51  return tid;
52 }
53 
55  : m_initialFrame (false)
56 {
57  NS_LOG_FUNCTION (this);
58 }
59 
61 {
63 }
64 
65 void
67 {
68  NS_LOG_FUNCTION (this);
69  m_edca = 0;
70  m_edcaBackingOff = 0;
73 }
74 
75 bool
77 {
78  NS_LOG_FUNCTION (this);
79  NS_ASSERT (m_edca != 0);
81 
82  WifiMacHeader cfEnd;
83  cfEnd.SetType (WIFI_MAC_CTL_END);
84  cfEnd.SetDsNotFrom ();
85  cfEnd.SetDsNotTo ();
86  cfEnd.SetNoRetry ();
87  cfEnd.SetNoMoreFragments ();
88  cfEnd.SetDuration (Seconds (0));
89  cfEnd.SetAddr1 (Mac48Address::GetBroadcast ());
90  cfEnd.SetAddr2 (m_self);
91 
92  WifiTxVector cfEndTxVector = m_mac->GetWifiRemoteStationManager ()->GetRtsTxVector (cfEnd.GetAddr1 ());
93 
94  Time txDuration = m_phy->CalculateTxDuration (cfEnd.GetSize () + WIFI_MAC_FCS_LENGTH,
95  cfEndTxVector, m_phy->GetPhyBand ());
96 
97  // Send the CF-End frame if the remaining duration is long enough to transmit this frame
98  if (m_edca->GetRemainingTxop () > txDuration)
99  {
100  NS_LOG_DEBUG ("Send CF-End frame");
101  m_phy->Send (Create<WifiPsdu> (Create<Packet> (), cfEnd), cfEndTxVector);
103  return true;
104  }
105 
107  m_edca = 0;
108  return false;
109 }
110 
111 void
113 {
114  NS_LOG_FUNCTION (this);
115  NS_ASSERT (m_edca != 0);
117 
118  // Release the channel if it has not been idle for the last PIFS interval
119  if (m_channelAccessManager->GetAccessGrantStart () - m_phy->GetSifs ()
120  > Simulator::Now () - m_phy->GetPifs ())
121  {
123  m_edca = 0;
124  }
125  else
126  {
127  // the txopDuration parameter is unused because we are not starting a new TXOP
129  }
130 }
131 
132 void
134 {
135  NS_LOG_FUNCTION (this);
137  NS_ASSERT (m_edca != 0);
138 
139  NS_LOG_DEBUG ("Cancel PIFS recovery being attempted by EDCAF " << m_edca);
142 }
143 
144 bool
146 {
147  NS_LOG_FUNCTION (this << edca);
148 
150  {
151  // Another AC (having AIFS=1 or lower, if the user changed the default settings)
152  // gained channel access while performing PIFS recovery. Abort PIFS recovery
154  }
155 
156  // TODO This will become an assert once no Txop is installed on a QoS station
157  if (!edca->IsQosTxop ())
158  {
159  m_edca = 0;
161  }
162 
163  Ptr<QosTxop> qosTxop = StaticCast<QosTxop> (edca);
164  return StartTransmission (qosTxop, qosTxop->GetTxopLimit ());
165 }
166 
167 bool
169 {
170  NS_LOG_FUNCTION (this << edca << txopDuration);
171 
173  {
174  // Another AC (having AIFS=1 or lower, if the user changed the default settings)
175  // gained channel access while performing PIFS recovery. Abort PIFS recovery
177  }
178 
179  if (m_txTimer.IsRunning ())
180  {
181  m_txTimer.Cancel ();
182  }
183  m_dcf = edca;
184  m_edca = edca;
185 
186  // We check if this EDCAF invoked the backoff procedure (without terminating
187  // the TXOP) because the transmission of a non-initial frame of a TXOP failed
188  bool backingOff = (m_edcaBackingOff == m_edca);
189 
190  if (backingOff)
191  {
196 
197  // clear the member variable
198  m_edcaBackingOff = 0;
199  }
200 
202  {
203  // TXOP limit is not null. We have to check if this EDCAF is starting a
204  // new TXOP. This includes the case when the transmission of a non-initial
205  // frame of a TXOP failed and backoff was invoked without terminating the
206  // TXOP. In such a case, we assume that a new TXOP is being started if it
207  // elapsed more than TXOPlimit since the start of the paused TXOP. Note
208  // that GetRemainingTxop returns 0 iff Now - TXOPstart >= TXOPlimit
209  if (!m_edca->IsTxopStarted ()
210  || (backingOff && m_edca->GetRemainingTxop ().IsZero ()))
211  {
212  // starting a new TXOP
213  m_edca->NotifyChannelAccessed (txopDuration);
214 
215  if (StartFrameExchange (m_edca, txopDuration, true))
216  {
217  m_initialFrame = true;
218  return true;
219  }
220 
221  // TXOP not even started, return false
222  NS_LOG_DEBUG ("No frame transmitted");
224  m_edca = 0;
225  return false;
226  }
227 
228  // We are continuing a TXOP, check if we can transmit another frame
230 
232  {
233  NS_LOG_DEBUG ("Not enough remaining TXOP time");
234  return SendCfEndIfNeeded ();
235  }
236 
237  return true;
238  }
239 
240  // we get here if TXOP limit is null
241  m_initialFrame = true;
242 
243  if (StartFrameExchange (m_edca, Time::Min (), true))
244  {
246  return true;
247  }
248 
249  NS_LOG_DEBUG ("No frame transmitted");
251  m_edca = 0;
252  return false;
253 }
254 
255 bool
256 QosFrameExchangeManager::StartFrameExchange (Ptr<QosTxop> edca, Time availableTime, bool initialFrame)
257 {
258  NS_LOG_FUNCTION (this << edca << availableTime << initialFrame);
259 
261 
262  // Even though channel access is requested when the queue is not empty, at
263  // the time channel access is granted the lifetime of the packet might be
264  // expired and the queue might be empty.
265  if (mpdu == 0)
266  {
267  NS_LOG_DEBUG ("Queue empty");
268  return false;
269  }
270 
271  WifiTxParameters txParams;
272  txParams.m_txVector = m_mac->GetWifiRemoteStationManager ()->GetDataTxVector (mpdu->GetHeader ());
273 
275  Ptr<WifiMacQueueItem> item = edca->GetNextMpdu (mpdu, txParams, availableTime, initialFrame, queueIt);
276 
277  if (item == nullptr)
278  {
279  NS_LOG_DEBUG ("Not enough time to transmit a frame");
280  return false;
281  }
282 
283  NS_ASSERT_MSG (!item->GetHeader ().IsQosData () || !item->GetHeader ().IsQosAmsdu (),
284  "We should not get an A-MSDU here");
285 
286  // check if the MSDU needs to be fragmented
287  item = GetFirstFragmentIfNeeded (item);
288 
289  // update the protection method if the frame was fragmented
290  if (item->IsFragment () && item->GetSize () != mpdu->GetSize ())
291  {
292  WifiTxParameters fragmentTxParams;
293  fragmentTxParams.m_txVector = txParams.m_txVector;
294  txParams.m_protection = GetProtectionManager ()->TryAddMpdu (item, fragmentTxParams);
295  NS_ASSERT (txParams.m_protection != nullptr);
296  }
297 
298  SendMpduWithProtection (item, txParams);
299 
300  return true;
301 }
302 
303 bool
305  Time availableTime) const
306 {
307  NS_ASSERT (mpdu != 0);
308  NS_LOG_FUNCTION (this << *mpdu << &txParams << availableTime);
309 
310  // check if adding the given MPDU requires a different protection method
311  Time protectionTime = Time::Min (); // uninitialized
312  if (txParams.m_protection)
313  {
314  protectionTime = txParams.m_protection->protectionTime;
315  }
316 
317  std::unique_ptr<WifiProtection> protection;
318  protection = GetProtectionManager ()->TryAddMpdu (mpdu, txParams);
319  bool protectionSwapped = false;
320 
321  if (protection)
322  {
323  // the protection method has changed, calculate the new protection time
324  CalculateProtectionTime (protection.get ());
325  protectionTime = protection->protectionTime;
326  // swap unique pointers, so that the txParams that is passed to the next
327  // call to IsWithinLimitsIfAddMpdu is the most updated one
328  txParams.m_protection.swap (protection);
329  protectionSwapped = true;
330  }
331  NS_ASSERT (protectionTime != Time::Min ());
332  NS_LOG_DEBUG ("protection time=" << protectionTime);
333 
334  // check if adding the given MPDU requires a different acknowledgment method
335  Time acknowledgmentTime = Time::Min (); // uninitialized
336  if (txParams.m_acknowledgment)
337  {
338  acknowledgmentTime = txParams.m_acknowledgment->acknowledgmentTime;
339  }
340 
341  std::unique_ptr<WifiAcknowledgment> acknowledgment;
342  acknowledgment = GetAckManager ()->TryAddMpdu (mpdu, txParams);
343  bool acknowledgmentSwapped = false;
344 
345  if (acknowledgment)
346  {
347  // the acknowledgment method has changed, calculate the new acknowledgment time
348  CalculateAcknowledgmentTime (acknowledgment.get ());
349  acknowledgmentTime = acknowledgment->acknowledgmentTime;
350  // swap unique pointers, so that the txParams that is passed to the next
351  // call to IsWithinLimitsIfAddMpdu is the most updated one
352  txParams.m_acknowledgment.swap (acknowledgment);
353  acknowledgmentSwapped = true;
354  }
355  NS_ASSERT (acknowledgmentTime != Time::Min ());
356  NS_LOG_DEBUG ("acknowledgment time=" << acknowledgmentTime);
357 
358  Time ppduDurationLimit = Time::Min ();
359  if (availableTime != Time::Min ())
360  {
361  ppduDurationLimit = availableTime - protectionTime - acknowledgmentTime;
362  }
363 
364  if (!IsWithinLimitsIfAddMpdu (mpdu, txParams, ppduDurationLimit))
365  {
366  // adding MPDU failed, restore protection and acknowledgment methods
367  // if they were swapped
368  if (protectionSwapped)
369  {
370  txParams.m_protection.swap (protection);
371  }
372  if (acknowledgmentSwapped)
373  {
374  txParams.m_acknowledgment.swap (acknowledgment);
375  }
376  return false;
377  }
378 
379  // the given MPDU can be added, hence update the txParams
380  txParams.AddMpdu (mpdu);
381  UpdateTxDuration (mpdu->GetHeader ().GetAddr1 (), txParams);
382 
383  return true;
384 }
385 
386 bool
388  const WifiTxParameters& txParams,
389  Time ppduDurationLimit) const
390 {
391  NS_ASSERT (mpdu != 0);
392  NS_LOG_FUNCTION (this << *mpdu << &txParams << ppduDurationLimit);
393 
394  // A QoS station only has to check that the MPDU transmission time does not
395  // exceed the given limit
396  return IsWithinSizeAndTimeLimits (mpdu->GetSize (), mpdu->GetHeader ().GetAddr1 (),
397  txParams, ppduDurationLimit);
398 }
399 
400 bool
402  const WifiTxParameters& txParams,
403  Time ppduDurationLimit) const
404 {
405  NS_LOG_FUNCTION (this << ppduPayloadSize << receiver << &txParams << ppduDurationLimit);
406 
407  if (ppduDurationLimit != Time::Min () && ppduDurationLimit.IsNegative ())
408  {
409  NS_LOG_DEBUG ("ppduDurationLimit is null or negative, time limit is trivially exceeded");
410  return false;
411  }
412 
413  if (ppduPayloadSize > WifiPhy::GetMaxPsduSize (txParams.m_txVector.GetModulationClass ()))
414  {
415  NS_LOG_DEBUG ("the frame exceeds the max PSDU size");
416  return false;
417  }
418 
419  // Get the maximum PPDU Duration based on the preamble type
420  Time maxPpduDuration = GetPpduMaxTime (txParams.m_txVector.GetPreambleType ());
421 
422  Time txTime = GetTxDuration (ppduPayloadSize, receiver, txParams);
423  NS_LOG_DEBUG ("PPDU duration: " << txTime.As (Time::MS));
424 
425  if ((ppduDurationLimit.IsStrictlyPositive () && txTime > ppduDurationLimit)
426  || (maxPpduDuration.IsStrictlyPositive () && txTime > maxPpduDuration))
427  {
428  NS_LOG_DEBUG ("the frame does not meet the constraint on max PPDU duration or PPDU duration limit");
429  return false;
430  }
431 
432  return true;
433 }
434 
435 Time
437  const WifiTxParameters& txParams,
438  Ptr<Packet> fragmentedPacket) const
439 {
440  NS_LOG_FUNCTION (this << header << size << &txParams << fragmentedPacket);
441 
442  // TODO This will be removed once no Txop is installed on a QoS station
443  if (m_edca == 0)
444  {
445  return FrameExchangeManager::GetFrameDurationId (header, size, txParams, fragmentedPacket);
446  }
447 
448  if (m_edca->GetTxopLimit ().IsZero ())
449  {
450  return FrameExchangeManager::GetFrameDurationId (header, size, txParams, fragmentedPacket);
451  }
452 
453  // under multiple protection settings, if the TXOP limit is not null, Duration/ID
454  // is set to cover the remaining TXOP time (Sec. 9.2.5.2 of 802.11-2016).
455  // The TXOP holder may exceed the TXOP limit in some situations (Sec. 10.22.2.8
456  // of 802.11-2016)
457  return std::max (m_edca->GetRemainingTxop ()
458  - m_phy->CalculateTxDuration (size, txParams.m_txVector, m_phy->GetPhyBand ()),
459  Seconds (0));
460 }
461 
462 Time
463 QosFrameExchangeManager::GetRtsDurationId (const WifiTxVector& rtsTxVector, Time txDuration, Time response) const
464 {
465  NS_LOG_FUNCTION (this << rtsTxVector << txDuration << response);
466 
467  // TODO This will be removed once no Txop is installed on a QoS station
468  if (m_edca == 0)
469  {
470  return FrameExchangeManager::GetRtsDurationId (rtsTxVector, txDuration, response);
471  }
472 
473  if (m_edca->GetTxopLimit ().IsZero ())
474  {
475  return FrameExchangeManager::GetRtsDurationId (rtsTxVector, txDuration, response);
476  }
477 
478  // under multiple protection settings, if the TXOP limit is not null, Duration/ID
479  // is set to cover the remaining TXOP time (Sec. 9.2.5.2 of 802.11-2016).
480  // The TXOP holder may exceed the TXOP limit in some situations (Sec. 10.22.2.8
481  // of 802.11-2016)
482  return std::max (m_edca->GetRemainingTxop ()
483  - m_phy->CalculateTxDuration (GetRtsSize (), rtsTxVector, m_phy->GetPhyBand ()),
484  Seconds (0));
485 }
486 
487 Time
489  Time txDuration, Time response) const
490 {
491  NS_LOG_FUNCTION (this << ctsTxVector << txDuration << response);
492 
493  // TODO This will be removed once no Txop is installed on a QoS station
494  if (m_edca == 0)
495  {
496  return FrameExchangeManager::GetCtsToSelfDurationId (ctsTxVector, txDuration, response);
497  }
498 
499  if (m_edca->GetTxopLimit ().IsZero ())
500  {
501  return FrameExchangeManager::GetCtsToSelfDurationId (ctsTxVector, txDuration, response);
502  }
503 
504  // under multiple protection settings, if the TXOP limit is not null, Duration/ID
505  // is set to cover the remaining TXOP time (Sec. 9.2.5.2 of 802.11-2016).
506  // The TXOP holder may exceed the TXOP limit in some situations (Sec. 10.22.2.8
507  // of 802.11-2016)
508  return std::max (m_edca->GetRemainingTxop ()
509  - m_phy->CalculateTxDuration (GetCtsSize (), ctsTxVector, m_phy->GetPhyBand ()),
510  Seconds (0));
511 }
512 
513 void
515 {
516  NS_LOG_DEBUG (this);
517 
518  // TODO This will be removed once no Txop is installed on a QoS station
519  if (m_edca == 0)
520  {
522  return;
523  }
524 
526  && m_edca->GetRemainingTxop () > m_phy->GetSifs ())
527  {
528  NS_LOG_DEBUG ("Schedule another transmission in a SIFS");
530 
531  // we are continuing a TXOP, hence the txopDuration parameter is unused
532  Simulator::Schedule (m_phy->GetSifs (), fp, this, m_edca, Seconds (0));
533  }
534  else
535  {
537  m_edca = 0;
538  }
539  m_initialFrame = false;
540 }
541 
542 void
544 {
545  NS_LOG_FUNCTION (this);
546 
547  // TODO This will be removed once no Txop is installed on a QoS station
548  if (m_edca == 0)
549  {
551  return;
552  }
553 
554  if (m_initialFrame)
555  {
556  // The backoff procedure shall be invoked by an EDCAF when the transmission
557  // of an MPDU in the initial PPDU of a TXOP fails (Sec. 10.22.2.2 of 802.11-2016)
558  NS_LOG_DEBUG ("TX of the initial frame of a TXOP failed: terminate TXOP");
560  m_edca = 0;
561  }
562  else
563  {
565  "Cannot transmit more than one frame if TXOP Limit is zero");
566 
567  // A STA can perform a PIFS recovery or perform a backoff as a response to
568  // transmission failure within a TXOP. How it chooses between these two is
569  // implementation dependent. (Sec. 10.22.2.2 of 802.11-2016)
570  if (m_pifsRecovery)
571  {
572  // we can continue the TXOP if the carrier sense mechanism indicates that
573  // the medium is idle in a PIFS
574  NS_LOG_DEBUG ("TX of a non-initial frame of a TXOP failed: perform PIFS recovery");
577  }
578  else
579  {
580  // In order not to terminate (yet) the TXOP, we call the NotifyChannelReleased
581  // method of the Txop class, which only generates a new backoff value and
582  // requests channel access if needed,
583  NS_LOG_DEBUG ("TX of a non-initial frame of a TXOP failed: invoke backoff");
584  m_edca->Txop::NotifyChannelReleased ();
586  m_edca = 0;
587  }
588  }
589  m_initialFrame = false;
590 }
591 
592 void
594 {
595  NS_LOG_FUNCTION (this << psdu << txVector);
596 
597  SetTxopHolder (psdu, txVector);
598 
599  // APs store buffer size report of associated stations
600  if (m_mac->GetTypeOfStation () == AP && psdu->GetAddr1 () == m_self)
601  {
602  for (const auto& mpdu : *PeekPointer (psdu))
603  {
604  const WifiMacHeader& hdr = mpdu->GetHeader ();
605 
606  if (hdr.IsQosData () && hdr.IsQosEosp ())
607  {
608  NS_LOG_DEBUG ("Station " << hdr.GetAddr2 () << " reported a buffer status of "
609  << +hdr.GetQosQueueSize () << " for tid=" << +hdr.GetQosTid ());
610  StaticCast<ApWifiMac> (m_mac)->SetBufferStatus (hdr.GetQosTid (), hdr.GetAddr2 (), hdr.GetQosQueueSize ());
611  }
612  }
613  }
614 
615  FrameExchangeManager::PreProcessFrame (psdu, txVector);
616 }
617 
618 void
620 {
621  NS_LOG_FUNCTION (this << psdu << txVector);
622 
623  const WifiMacHeader& hdr = psdu->GetHeader (0);
624 
625  if (hdr.IsQosData () || hdr.IsMgt () || hdr.IsRts ())
626  {
627  m_txopHolder = psdu->GetAddr2 ();
628  }
629  else if (hdr.IsCts () || hdr.IsAck ())
630  {
631  m_txopHolder = psdu->GetAddr1 ();
632  }
633 }
634 
635 void
637  const WifiTxVector& txVector, bool inAmpdu)
638 {
639  // The received MPDU is either broadcast or addressed to this station
640  NS_ASSERT (mpdu->GetHeader ().GetAddr1 ().IsGroup ()
641  || mpdu->GetHeader ().GetAddr1 () == m_self);
642 
643  double rxSnr = rxSignalInfo.snr;
644  const WifiMacHeader& hdr = mpdu->GetHeader ();
645 
646  if (hdr.IsCfEnd ())
647  {
648  // reset NAV
649  NavResetTimeout ();
650  return;
651  }
652 
653  if (hdr.IsRts ())
654  {
655  NS_ABORT_MSG_IF (inAmpdu, "Received RTS as part of an A-MPDU");
656 
657  // If a non-VHT STA receives an RTS frame with the RA address matching the
658  // MAC address of the STA and the MAC address in the TA field in the RTS
659  // frame matches the saved TXOP holder address, then the STA shall send the
660  // CTS frame after SIFS, without regard for, and without resetting, its NAV.
661  // (sec. 10.22.2.4 of 802.11-2016)
662  if (hdr.GetAddr2 () == m_txopHolder || m_navEnd <= Simulator::Now ())
663  {
664  NS_LOG_DEBUG ("Received RTS from=" << hdr.GetAddr2 () << ", schedule CTS");
666  this, hdr, txVector.GetMode (), rxSnr);
667  }
668  else
669  {
670  NS_LOG_DEBUG ("Received RTS from=" << hdr.GetAddr2 () << ", cannot schedule CTS");
671  }
672  return;
673  }
674 
675  if (hdr.IsQosData ())
676  {
677  if (hdr.GetAddr1 () == m_self && hdr.GetQosAckPolicy () == WifiMacHeader::NORMAL_ACK)
678  {
679  NS_LOG_DEBUG ("Received " << hdr.GetTypeString () << " from=" << hdr.GetAddr2 () << ", schedule ACK");
681  this, hdr, txVector, rxSnr);
682  }
683 
684  // Forward up the frame if it is not a QoS Null frame
685  if (hdr.HasData ())
686  {
687  m_rxMiddle->Receive (mpdu);
688  }
689 
690  // the received data frame has been processed
691  return;
692  }
693 
694  return FrameExchangeManager::ReceiveMpdu (mpdu, rxSignalInfo, txVector, inAmpdu);
695 }
696 
697 } //namespace ns3
EventId m_pifsRecoveryEvent
event associated with an attempt of PIFS recovery
bool IsCfEnd(void) const
Return true if the header is a CF-End header.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:557
Ptr< const WifiMacQueueItem > PeekNextMpdu(uint8_t tid=8, Mac48Address recipient=Mac48Address::GetBroadcast())
Peek the next frame to transmit to the given receiver and of the given TID from the block ack manager...
Definition: qos-txop.cc:277
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
WifiTxTimer m_txTimer
the timer set upon frame transmission
AttributeValue implementation for Boolean.
Definition: boolean.h:36
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SendMpduWithProtection(Ptr< WifiMacQueueItem > mpdu, WifiTxParameters &txParams)
Send an MPDU with the given TX parameters (with the specified protection).
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Ptr< WifiProtectionManager > GetProtectionManager(void) const
Get the Protection Manager used by this node.
Ptr< WifiPhy > m_phy
the PHY layer on this station
static Time Min()
Minimum representable Time Not to be confused with Min(Time,Time).
Definition: nstime.h:274
WifiPhyBand GetPhyBand(void) const
Get the configured Wi-Fi band.
Definition: wifi-phy.cc:1124
std::unique_ptr< WifiProtection > m_protection
protection method
uint32_t GetRtsSize(void)
Return the total RTS size (including FCS trailer).
Definition: wifi-utils.cc:209
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: boolean.h:85
Time GetRtsDurationId(const WifiTxVector &rtsTxVector, Time txDuration, Time response) const override
Compute how to set the Duration/ID field of an RTS frame to send to protect a frame transmitted with ...
WifiModulationClass GetModulationClass(void) const
Get the modulation class specified by this TXVECTOR.
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
virtual void PreProcessFrame(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector)
Perform actions that are possibly needed when receiving any frame, independently of whether the frame...
U * PeekPointer(const Ptr< U > &p)
Definition: ptr.h:411
bool IsQosEosp(void) const
Return if the end of service period (EOSP) is set.
Information needed to remove an MSDU from the queue.
static const uint16_t WIFI_MAC_FCS_LENGTH
The length in octects of the IEEE 802.11 MAC FCS field.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
virtual void CalculateProtectionTime(WifiProtection *protection) const
Calculate the time required to protect a frame according to the given protection method.
bool IsStrictlyPositive(void) const
Exactly equivalent to t > 0.
Definition: nstime.h:333
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:813
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
virtual Time GetRemainingTxop(void) const
Return the remaining duration in the current TXOP.
Definition: qos-txop.cc:598
void PifsRecovery(void)
Perform a PIFS recovery as a response to transmission failure within a TXOP.
const char * GetTypeString(void) const
Return a string corresponds to the header type.
Ptr< ChannelAccessManager > m_channelAccessManager
the channel access manager
virtual void TransmissionFailed(void)
Take necessary actions upon a transmission failure.
virtual void CalculateAcknowledgmentTime(WifiAcknowledgment *acknowledgment) const
Calculate the time required to acknowledge a frame according to the given acknowledgment method...
Ptr< WifiAckManager > GetAckManager(void) const
Get the Acknowledgment Manager used by this node.
Ptr< RegularWifiMac > m_mac
the MAC layer on this station
bool StartTransmission(Ptr< Txop > edca) override
Request the FrameExchangeManager to start a frame exchange sequence.
WifiMode GetMode(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the selected payload transmission mode...
Ptr< WifiMacQueueItem > GetFirstFragmentIfNeeded(Ptr< WifiMacQueueItem > mpdu)
Fragment the given MPDU if needed.
void DoDispose() override
Destructor implementation.
WifiPreamble GetPreambleType(void) const
static Time CalculateTxDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, uint16_t staId=SU_STA_ID)
Definition: wifi-phy.cc:1610
void TransmissionSucceeded(void) override
Take necessary actions upon a transmission success.
RxSignalInfo structure containing info on the received signal.
Definition: phy-entity.h:66
const WifiMacHeader & GetHeader(void) const
Get the header stored in this item.
virtual Time GetFrameDurationId(const WifiMacHeader &header, uint32_t size, const WifiTxParameters &txParams, Ptr< Packet > fragmentedPacket) const
Compute how to set the Duration/ID field of a frame being transmitted with the given TX parameters...
#define max(a, b)
Definition: 80211b.c:43
void PreProcessFrame(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector) override
Perform actions that are possibly needed when receiving any frame, independently of whether the frame...
bool IsZero(void) const
Exactly equivalent to t == 0.
Definition: nstime.h:301
QosFrameExchangeManager handles the frame exchange sequences for QoS stations.
uint8_t GetQosQueueSize(void) const
Get the Queue Size subfield in the QoS control field.
bool IsQosAmsdu(void) const
Check if the A-MSDU present bit is set in the QoS control field.
virtual bool IsWithinSizeAndTimeLimits(uint32_t ppduPayloadSize, Mac48Address receiver, const WifiTxParameters &txParams, Time ppduDurationLimit) const
Check whether the transmission time of the frame being built (as described by the given TX parameters...
static TypeId GetTypeId(void)
Get the type ID.
uint8_t GetQosTid(void) const
Return the Traffic ID of a QoS header.
virtual void NotifyChannelReleased(void)
Called by the FrameExchangeManager to notify the completion of the transmissions. ...
Definition: txop.cc:349
bool IsCts(void) const
Return true if the header is a CTS header.
virtual bool StartTransmission(Ptr< Txop > dcf)
Request the FrameExchangeManager to start a frame exchange sequence.
Ptr< Txop > m_edcaBackingOff
channel access function that invoked backoff during TXOP
static Mac48Address GetBroadcast(void)
virtual Time GetRtsDurationId(const WifiTxVector &rtsTxVector, Time txDuration, Time response) const
Compute how to set the Duration/ID field of an RTS frame to send to protect a frame transmitted with ...
Mac48Address GetAddr2(void) const
Get the Transmitter Address (TA), which is common to all the MPDUs.
Definition: wifi-psdu.cc:126
virtual void SetTxopHolder(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector)
Set the TXOP holder, if needed, based on the received frame.
virtual bool IsQosTxop() const
Check for QoS TXOP.
Definition: txop.cc:421
virtual bool SendCfEndIfNeeded(void)
Send a CF-End frame to indicate the completion of the TXOP, provided that the remaining duration is l...
bool m_initialFrame
true if transmitting the initial frame of a TXOP
const WifiMacHeader & GetHeader(std::size_t i) const
Get the header of the i-th MPDU.
Definition: wifi-psdu.cc:266
Mac48Address m_self
the MAC address of this device
Mac48Address GetAddr2(void) const
Return the address in the Address 2 field.
void CancelPifsRecovery(void)
Cancel the PIFS recovery event and have the EDCAF attempting PIFS recovery release the channel...
WifiTxVector m_txVector
TXVECTOR of the frame being prepared.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static uint32_t GetMaxPsduSize(WifiModulationClass modulation)
Get the maximum PSDU size in bytes for the given modulation class.
Definition: wifi-phy.cc:1631
bool m_pifsRecovery
true if performing a PIFS recovery after failure
void DoDispose() override
Destructor implementation.
void NotifyChannelAccessed(Time txopDuration) override
Called by the FrameExchangeManager to notify that channel access has been granted for the given amoun...
Definition: qos-txop.cc:566
void Cancel(void)
Cancel the timer.
an EUI-48 address
Definition: mac48-address.h:43
bool IsRunning(void) const
Return true if the timer is running.
Mac48Address m_txopHolder
MAC address of the TXOP holder.
Time GetPifs(void) const
Return the PCF Interframe Space (PIFS) for this PHY.
Definition: wifi-phy.cc:934
Ptr< QosTxop > m_edca
the EDCAF that gained channel access
void SendCtsAfterRts(const WifiMacHeader &rtsHdr, WifiMode rtsTxMode, double rtsSnr)
Send CTS after receiving RTS.
bool IsGroup(void) const
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
Time GetFrameDurationId(const WifiMacHeader &header, uint32_t size, const WifiTxParameters &txParams, Ptr< Packet > fragmentedPacket) const override
Compute how to set the Duration/ID field of a frame being transmitted with the given TX parameters...
void SendNormalAck(const WifiMacHeader &hdr, const WifiTxVector &dataTxVector, double dataSnr)
Send Normal Ack.
FrameExchangeManager is a base class handling the basic frame exchange sequences for non-QoS stations...
virtual Time GetTxDuration(uint32_t ppduPayloadSize, Mac48Address receiver, const WifiTxParameters &txParams) const
Get the updated TX duration of the frame associated with the given TX parameters if the size of the P...
void AddMpdu(Ptr< const WifiMacQueueItem > mpdu)
Record that an MPDU is being added to the current frame.
uint32_t GetCtsSize(void)
Return the total CTS size (including FCS trailer).
Definition: wifi-utils.cc:217
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:88
void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
bool IsMgt(void) const
Return true if the Type is Management.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
Time GetPpduMaxTime(WifiPreamble preamble)
Get the maximum PPDU duration (see Section 10.14 of 802.11-2016) for the PHY layers defining the aPPD...
Definition: wifi-utils.cc:254
Time GetSifs(void) const
Return the Short Interframe Space (SIFS) for this PHY.
Definition: wifi-phy.cc:910
void NotifyChannelReleased(void) override
Called by the FrameExchangeManager to notify the completion of the transmissions. ...
Definition: qos-txop.cc:584
double snr
SNR in linear scale.
Definition: phy-entity.h:68
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
This class stores the TX parameters (TX vector, protection mechanism, acknowledgment mechanism...
Ptr< Txop > m_dcf
the DCF/EDCAF that gained channel access
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:71
void Send(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector)
This function is a wrapper for the Send variant that accepts a WifiConstPsduMap as first argument...
Definition: wifi-phy.cc:1768
virtual Time GetCtsToSelfDurationId(const WifiTxVector &ctsTxVector, Time txDuration, Time response) const
Compute how to set the Duration/ID field of a CTS-to-self frame to send to protect a frame transmitte...
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
bool IsRts(void) const
Return true if the header is a RTS header.
Time m_navEnd
NAV expiration time.
virtual void ReceiveMpdu(Ptr< WifiMacQueueItem > mpdu, RxSignalInfo rxSignalInfo, const WifiTxVector &txVector, bool inAmpdu)
This method handles the reception of an MPDU (possibly included in an A-MPDU)
void ReceiveMpdu(Ptr< WifiMacQueueItem > mpdu, RxSignalInfo rxSignalInfo, const WifiTxVector &txVector, bool inAmpdu) override
This method handles the reception of an MPDU (possibly included in an A-MPDU)
bool IsQosData(void) const
Return true if the Type is DATA and Subtype is one of the possible values for QoS Data...
void TransmissionFailed(void) override
Take necessary actions upon a transmission failure.
virtual void TransmissionSucceeded(void)
Take necessary actions upon a transmission success.
bool IsAck(void) const
Return true if the header is an Ack header.
std::unique_ptr< WifiAcknowledgment > m_acknowledgment
acknowledgment method
void UpdateTxDuration(Mac48Address receiver, WifiTxParameters &txParams) const
Update the TX duration field of the given TX parameters after that the PSDU addressed to the given re...
Mac48Address GetAddr1(void) const
Get the Receiver Address (RA), which is common to all the MPDUs.
Definition: wifi-psdu.cc:111
Ptr< WifiMacQueueItem > GetNextMpdu(Ptr< const WifiMacQueueItem > peekedItem, WifiTxParameters &txParams, Time availableTime, bool initialFrame, WifiMacQueueItem::QueueIteratorPair &queueIt)
Prepare the frame to transmit starting from the MPDU that has been previously peeked by calling PeekN...
Definition: qos-txop.cc:359
bool TryAddMpdu(Ptr< const WifiMacQueueItem > mpdu, WifiTxParameters &txParams, Time availableTime) const
Recompute the protection and acknowledgment methods to use if the given MPDU is added to the frame be...
Ptr< MacRxMiddle > m_rxMiddle
the MAC RX Middle on this station
millisecond
Definition: nstime.h:116
virtual bool StartFrameExchange(Ptr< QosTxop > edca, Time availableTime, bool initialFrame)
Start a frame exchange (including protection frames and acknowledgment frames as needed) that fits wi...
a unique identifier for an interface.
Definition: type-id.h:58
Time GetCtsToSelfDurationId(const WifiTxVector &ctsTxVector, Time txDuration, Time response) const override
Compute how to set the Duration/ID field of a CTS-to-self frame to send to protect a frame transmitte...
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
virtual bool IsWithinLimitsIfAddMpdu(Ptr< const WifiMacQueueItem > mpdu, const WifiTxParameters &txParams, Time ppduDurationLimit) const
Check whether the given MPDU can be added to the frame being built (as described by the given TX para...
Implements the IEEE 802.11 MAC header.
bool IsNegative(void) const
Exactly equivalent to t <= 0.
Definition: nstime.h:309
virtual bool IsTxopStarted(void) const
Return true if a TXOP has started.
Definition: qos-txop.cc:577
bool HasData(void) const
Return true if the header type is DATA and is not DATA_NULL.
virtual void NavResetTimeout(void)
Reset the NAV upon expiration of the NAV reset timer.
QosAckPolicy GetQosAckPolicy(void) const
Return the QoS Ack policy in the QoS control field.
Time GetTxopLimit(void) const
Return the TXOP limit.
Definition: txop.cc:274