A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
frame-exchange-manager.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Universita' degli Studi di Napoli Federico II
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Stefano Avallone <stavallo@unina.it>
18 */
19
21
22#include "snr-tag.h"
23#include "sta-wifi-mac.h"
24#include "wifi-mac-queue.h"
25#include "wifi-mac-trailer.h"
26#include "wifi-utils.h"
27
28#include "ns3/abort.h"
29#include "ns3/log.h"
30
31#undef NS_LOG_APPEND_CONTEXT
32#define NS_LOG_APPEND_CONTEXT WIFI_FEM_NS_LOG_APPEND_CONTEXT
33
34// Time (in nanoseconds) to be added to the PSDU duration to yield the duration
35// of the timer that is started when the PHY indicates the start of the reception
36// of a frame and we are waiting for a response.
37#define PSDU_DURATION_SAFEGUARD 400
38
39namespace ns3
40{
41
42NS_LOG_COMPONENT_DEFINE("FrameExchangeManager");
43
44NS_OBJECT_ENSURE_REGISTERED(FrameExchangeManager);
45
46TypeId
48{
49 static TypeId tid = TypeId("ns3::FrameExchangeManager")
51 .AddConstructor<FrameExchangeManager>()
52 .SetGroupName("Wifi");
53 return tid;
54}
55
57 : m_navEnd(Seconds(0)),
58 m_linkId(0),
59 m_allowedWidth(0),
60 m_promisc(false),
61 m_moreFragments(false)
62{
63 NS_LOG_FUNCTION(this);
64}
65
67{
69}
70
71void
73{
74 NS_LOG_FUNCTION(this);
77 {
79 }
81 m_mpdu = nullptr;
83 m_dcf = nullptr;
84}
85
86void
88{
89 NS_LOG_FUNCTION(this);
90 Reset();
91 m_fragmentedPacket = nullptr;
92 m_mac = nullptr;
93 m_txMiddle = nullptr;
94 m_rxMiddle = nullptr;
95 m_channelAccessManager = nullptr;
96 m_protectionManager = nullptr;
97 m_ackManager = nullptr;
98 ResetPhy();
100}
101
102void
104{
105 NS_LOG_FUNCTION(this << protectionManager);
106 m_protectionManager = protectionManager;
107}
108
111{
112 return m_protectionManager;
113}
114
115void
117{
118 NS_LOG_FUNCTION(this << ackManager);
119 m_ackManager = ackManager;
120}
121
124{
125 return m_ackManager;
126}
127
128void
130{
131 NS_LOG_FUNCTION(this << +linkId);
132 m_linkId = linkId;
133}
134
135void
137{
138 NS_LOG_FUNCTION(this << mac);
139 m_mac = mac;
140}
141
142void
144{
145 NS_LOG_FUNCTION(this << txMiddle);
146 m_txMiddle = txMiddle;
147}
148
149void
151{
152 NS_LOG_FUNCTION(this << rxMiddle);
153 m_rxMiddle = rxMiddle;
154}
155
156void
158{
159 NS_LOG_FUNCTION(this << channelAccessManager);
160 m_channelAccessManager = channelAccessManager;
161}
162
165{
167}
168
169void
171{
172 NS_LOG_FUNCTION(this << phy);
173 m_phy = phy;
174 m_phy->TraceConnectWithoutContext("PhyRxPayloadBegin",
177}
178
179void
181{
182 NS_LOG_FUNCTION(this);
183 if (m_phy)
184 {
186 "PhyRxPayloadBegin",
188 if (m_phy->GetState())
189 {
194 std::vector<bool>>());
195 }
196 m_phy = nullptr;
197 }
198}
199
200void
202{
203 NS_LOG_FUNCTION(this << address);
204 // For APs, the BSSID is the MAC address. For STAs, the BSSID will be overwritten
205 // when receiving Beacon frames or Probe Response frames
206 SetBssid(address);
207 m_self = address;
208}
209
212{
213 return m_self;
214}
215
216void
218{
219 NS_LOG_FUNCTION(this << bssid);
220 m_bssid = bssid;
221}
222
225{
226 return m_bssid;
227}
228
229void
231{
232 NS_LOG_FUNCTION(this << &callback);
233 m_droppedMpduCallback = callback;
234}
235
236void
238{
239 NS_LOG_FUNCTION(this << &callback);
240 m_ackedMpduCallback = callback;
241}
242
243void
245{
246 m_promisc = true;
247}
248
249bool
251{
252 return m_promisc;
253}
254
255const WifiTxTimer&
257{
258 return m_txTimer;
259}
260
261void
263{
265 {
267 }
268}
269
270void
272{
273 NS_LOG_FUNCTION(this << "PSDU reception started for " << psduDuration.As(Time::US)
274 << " (txVector: " << txVector << ")");
275
277 "The TX timer and the NAV reset event cannot be both running");
278
279 // No need to reschedule timeouts if PSDU duration is null. In this case,
280 // PHY-RXEND immediately follows PHY-RXSTART (e.g. when PPDU has been filtered)
281 // and CCA will take over
282 if (m_txTimer.IsRunning() && psduDuration.IsStrictlyPositive())
283 {
284 // we are waiting for a response and something arrived
285 NS_LOG_DEBUG("Rescheduling timeout event");
287 // PHY has switched to RX, so we can reset the ack timeout
289 }
290
292 {
294 }
295}
296
297bool
299{
300 NS_LOG_FUNCTION(this << dcf << allowedWidth);
301
303 if (m_txTimer.IsRunning())
304 {
306 }
307 m_dcf = dcf;
308 m_allowedWidth = allowedWidth;
309
310 Ptr<WifiMacQueue> queue = dcf->GetWifiMacQueue();
311
312 // Even though channel access is requested when the queue is not empty, at
313 // the time channel access is granted the lifetime of the packet might be
314 // expired and the queue might be empty.
315 queue->WipeAllExpiredMpdus();
316
317 Ptr<WifiMpdu> mpdu = queue->Peek(m_linkId);
318
319 if (!mpdu)
320 {
321 NS_LOG_DEBUG("Queue empty");
323 m_dcf = nullptr;
324 return false;
325 }
326
328
329 NS_ASSERT(mpdu->GetHeader().IsData() || mpdu->GetHeader().IsMgt());
330
331 // assign a sequence number if this is not a fragment nor a retransmission
332 if (!mpdu->IsFragment() && !mpdu->GetHeader().IsRetry())
333 {
334 uint16_t sequence = m_txMiddle->GetNextSequenceNumberFor(&mpdu->GetHeader());
335 mpdu->AssignSeqNo(sequence);
336 }
337
338 NS_LOG_DEBUG("MPDU payload size=" << mpdu->GetPacketSize()
339 << ", to=" << mpdu->GetHeader().GetAddr1()
340 << ", seq=" << mpdu->GetHeader().GetSequenceControl());
341
342 // check if the MSDU needs to be fragmented
343 mpdu = GetFirstFragmentIfNeeded(mpdu);
344
347 WifiTxParameters txParams;
348 txParams.m_txVector =
349 GetWifiRemoteStationManager()->GetDataTxVector(mpdu->GetHeader(), m_allowedWidth);
350 txParams.AddMpdu(mpdu);
351 UpdateTxDuration(mpdu->GetHeader().GetAddr1(), txParams);
352 txParams.m_protection = m_protectionManager->TryAddMpdu(mpdu, txParams);
353 txParams.m_acknowledgment = m_ackManager->TryAddMpdu(mpdu, txParams);
354
355 SendMpduWithProtection(mpdu, txParams);
356
357 return true;
358}
359
362{
363 NS_LOG_FUNCTION(this << *mpdu);
364
365 if (mpdu->IsFragment())
366 {
367 // a fragment cannot be further fragmented
369 }
370 else if (GetWifiRemoteStationManager()->NeedFragmentation(mpdu))
371 {
372 NS_LOG_DEBUG("Fragmenting the MSDU");
373 m_fragmentedPacket = mpdu->GetPacket()->Copy();
374 // create the first fragment
376 0,
377 GetWifiRemoteStationManager()->GetFragmentSize(mpdu, 0));
378 // enqueue the first fragment
379 Ptr<WifiMpdu> item = Create<WifiMpdu>(fragment, mpdu->GetHeader());
380 item->GetHeader().SetMoreFragments();
381 m_mac->GetTxopQueue(mpdu->GetQueueAc())->Replace(mpdu, item);
382 return item;
383 }
384 return mpdu;
385}
386
387void
389{
390 NS_LOG_FUNCTION(this << *mpdu << &txParams);
391
392 m_mpdu = mpdu;
393 m_txParams = std::move(txParams);
394
395 // If protection is required, the MPDU must be stored in some queue because
396 // it is not put back in a queue if the RTS/CTS exchange fails
398 m_mpdu->GetHeader().IsCtl() || m_mpdu->IsQueued());
399
400 // Make sure that the acknowledgment time has been computed, so that SendRts()
401 // and SendCtsToSelf() can reuse this value.
403
404 if (!m_txParams.m_acknowledgment->acknowledgmentTime.has_value())
405 {
407 }
408
409 // Set QoS Ack policy if this is a QoS data frame
411
412 if (m_mpdu->IsQueued())
413 {
414 m_mpdu->SetInFlight(m_linkId);
415 }
416
418}
419
420void
422{
423 NS_LOG_FUNCTION(this << &txParams);
424
425 switch (txParams.m_protection->method)
426 {
428 SendRts(txParams);
429 break;
431 SendCtsToSelf(txParams);
432 break;
435 break;
436 default:
437 NS_ABORT_MSG("Unknown protection type: " << txParams.m_protection.get());
438 }
439}
440
441void
443{
444 NS_LOG_FUNCTION(this);
446 m_sentRtsTo.clear();
448 SendMpdu();
449}
450
451const std::set<Mac48Address>&
453{
454 return m_protectedStas;
455}
456
457void
459{
460 NS_LOG_FUNCTION(this);
461
464 m_phy->GetPhyBand());
465
467
469 {
470 if (!m_mpdu->GetHeader().IsQosData() ||
471 m_mpdu->GetHeader().GetQosAckPolicy() == WifiMacHeader::NO_ACK)
472 {
473 // No acknowledgment, hence dequeue the MPDU if it is stored in a queue
475 }
476
477 Simulator::Schedule(txDuration, [=, this]() {
479 m_mpdu = nullptr;
480 });
481 }
483 {
484 m_mpdu->GetHeader().SetDuration(
485 GetFrameDurationId(m_mpdu->GetHeader(),
489
490 // the timeout duration is "aSIFSTime + aSlotTime + aRxPHYStartDelay, starting
491 // at the PHY-TXEND.confirm primitive" (section 10.3.2.9 or 10.22.2.2 of 802.11-2016).
492 // aRxPHYStartDelay equals the time to transmit the PHY header.
493 auto normalAcknowledgment = static_cast<WifiNormalAck*>(m_txParams.m_acknowledgment.get());
494
495 Time timeout =
496 txDuration + m_phy->GetSifs() + m_phy->GetSlot() +
497 m_phy->CalculatePhyPreambleAndHeaderDuration(normalAcknowledgment->ackTxVector);
500 timeout,
501 {m_mpdu->GetHeader().GetAddr1()},
503 this,
504 m_mpdu,
507 }
508 else
509 {
510 NS_ABORT_MSG("Unable to handle the selected acknowledgment method ("
511 << m_txParams.m_acknowledgment.get() << ")");
512 }
513
514 // transmit the MPDU
516}
517
518void
520{
521 NS_LOG_FUNCTION(this << *mpdu << txVector);
522
523 auto psdu = Create<WifiPsdu>(mpdu, false);
524 FinalizeMacHeader(psdu);
525 m_allowedWidth = std::min(m_allowedWidth, txVector.GetChannelWidth());
526 m_phy->Send(psdu, txVector);
527}
528
529void
531{
532 NS_LOG_FUNCTION(this << psdu);
533
534 if (m_mac->GetTypeOfStation() != STA)
535 {
536 return;
537 }
538
539 auto pmMode = StaticCast<StaWifiMac>(m_mac)->GetPmMode(m_linkId);
540
541 for (const auto& mpdu : *PeekPointer(psdu))
542 {
543 switch (pmMode)
544 {
545 case WIFI_PM_ACTIVE:
547 mpdu->GetHeader().SetNoPowerManagement();
548 break;
551 mpdu->GetHeader().SetPowerManagement();
552 break;
553 default:
554 NS_ABORT_MSG("Unknown PM mode: " << +pmMode);
555 }
556 }
557}
558
559void
561{
562 NS_LOG_DEBUG(this << *mpdu);
563
564 if (mpdu->IsQueued())
565 {
566 m_mac->GetTxopQueue(mpdu->GetQueueAc())->DequeueIfQueued({mpdu});
567 }
568}
569
572{
573 return mpdu->GetSize();
574}
575
576void
578{
579 NS_LOG_FUNCTION(this << protection);
580 NS_ASSERT(protection);
581
582 if (protection->method == WifiProtection::NONE)
583 {
584 protection->protectionTime = Seconds(0);
585 }
586 else if (protection->method == WifiProtection::RTS_CTS)
587 {
588 auto rtsCtsProtection = static_cast<WifiRtsCtsProtection*>(protection);
589 rtsCtsProtection->protectionTime = m_phy->CalculateTxDuration(GetRtsSize(),
590 rtsCtsProtection->rtsTxVector,
591 m_phy->GetPhyBand()) +
593 rtsCtsProtection->ctsTxVector,
594 m_phy->GetPhyBand()) +
595 2 * m_phy->GetSifs();
596 }
597 else if (protection->method == WifiProtection::CTS_TO_SELF)
598 {
599 auto ctsToSelfProtection = static_cast<WifiCtsToSelfProtection*>(protection);
600 ctsToSelfProtection->protectionTime =
602 ctsToSelfProtection->ctsTxVector,
603 m_phy->GetPhyBand()) +
604 m_phy->GetSifs();
605 }
606}
607
608void
610{
611 NS_LOG_FUNCTION(this << acknowledgment);
612 NS_ASSERT(acknowledgment);
613
614 if (acknowledgment->method == WifiAcknowledgment::NONE)
615 {
616 acknowledgment->acknowledgmentTime = Seconds(0);
617 }
618 else if (acknowledgment->method == WifiAcknowledgment::NORMAL_ACK)
619 {
620 auto normalAcknowledgment = static_cast<WifiNormalAck*>(acknowledgment);
621 normalAcknowledgment->acknowledgmentTime =
623 normalAcknowledgment->ackTxVector,
624 m_phy->GetPhyBand());
625 }
626}
627
628Time
630 Mac48Address receiver,
631 const WifiTxParameters& txParams) const
632{
633 return m_phy->CalculateTxDuration(ppduPayloadSize, txParams.m_txVector, m_phy->GetPhyBand());
634}
635
636void
638{
639 txParams.m_txDuration = GetTxDuration(txParams.GetSize(receiver), receiver, txParams);
640}
641
642Time
644 uint32_t size,
645 const WifiTxParameters& txParams,
646 Ptr<Packet> fragmentedPacket) const
647{
648 NS_LOG_FUNCTION(this << header << size << &txParams << fragmentedPacket);
649
650 NS_ASSERT(txParams.m_acknowledgment &&
651 txParams.m_acknowledgment->acknowledgmentTime.has_value());
652 auto durationId = *txParams.m_acknowledgment->acknowledgmentTime;
653
654 // if the current frame is a fragment followed by another fragment, we have to
655 // update the Duration/ID to cover the next fragment and the corresponding Ack
656 if (header.IsMoreFragments())
657 {
658 uint32_t payloadSize = size - header.GetSize() - WIFI_MAC_FCS_LENGTH;
659 uint32_t nextFragmentOffset = (header.GetFragmentNumber() + 1) * payloadSize;
660 uint32_t nextFragmentSize =
661 std::min(fragmentedPacket->GetSize() - nextFragmentOffset, payloadSize);
662 WifiTxVector ackTxVector =
663 GetWifiRemoteStationManager()->GetAckTxVector(header.GetAddr1(), txParams.m_txVector);
664
665 durationId +=
666 2 * m_phy->GetSifs() +
668 m_phy->CalculateTxDuration(nextFragmentSize, txParams.m_txVector, m_phy->GetPhyBand());
669 }
670 return durationId;
671}
672
673Time
675 Time txDuration,
676 Time response) const
677{
678 NS_LOG_FUNCTION(this << rtsTxVector << txDuration << response);
679
680 WifiTxVector ctsTxVector;
681 ctsTxVector = GetWifiRemoteStationManager()->GetCtsTxVector(m_self, rtsTxVector.GetMode());
682
683 return m_phy->GetSifs() +
684 m_phy->CalculateTxDuration(GetCtsSize(), ctsTxVector, m_phy->GetPhyBand()) /* CTS */
685 + m_phy->GetSifs() + txDuration + response;
686}
687
688void
690{
691 NS_LOG_FUNCTION(this << &txParams);
692
693 NS_ASSERT(txParams.GetPsduInfoMap().size() == 1);
694 Mac48Address receiver = txParams.GetPsduInfoMap().begin()->first;
695
696 WifiMacHeader rts;
698 rts.SetDsNotFrom();
699 rts.SetDsNotTo();
700 rts.SetNoRetry();
701 rts.SetNoMoreFragments();
702 rts.SetAddr1(receiver);
703 rts.SetAddr2(m_self);
704
705 NS_ASSERT(txParams.m_protection && txParams.m_protection->method == WifiProtection::RTS_CTS);
706 auto rtsCtsProtection = static_cast<WifiRtsCtsProtection*>(txParams.m_protection.get());
707
708 NS_ASSERT(txParams.m_txDuration.has_value());
709 NS_ASSERT(txParams.m_acknowledgment->acknowledgmentTime.has_value());
710 rts.SetDuration(GetRtsDurationId(rtsCtsProtection->rtsTxVector,
711 *txParams.m_txDuration,
712 *txParams.m_acknowledgment->acknowledgmentTime));
713 Ptr<WifiMpdu> mpdu = Create<WifiMpdu>(Create<Packet>(), rts);
714
715 // After transmitting an RTS frame, the STA shall wait for a CTSTimeout interval with
716 // a value of aSIFSTime + aSlotTime + aRxPHYStartDelay (IEEE 802.11-2016 sec. 10.3.2.7).
717 // aRxPHYStartDelay equals the time to transmit the PHY header.
719 rtsCtsProtection->rtsTxVector,
720 m_phy->GetPhyBand()) +
721 m_phy->GetSifs() + m_phy->GetSlot() +
722 m_phy->CalculatePhyPreambleAndHeaderDuration(rtsCtsProtection->ctsTxVector);
725 timeout,
726 {receiver},
728 this,
729 mpdu,
730 rtsCtsProtection->rtsTxVector);
732 NS_ASSERT(m_sentRtsTo.empty());
733 m_sentRtsTo = {receiver};
734
735 ForwardMpduDown(mpdu, rtsCtsProtection->rtsTxVector);
736}
737
738void
740 WifiTxVector& ctsTxVector,
741 double rtsSnr)
742{
743 NS_LOG_FUNCTION(this << rtsHdr << ctsTxVector << rtsSnr);
744
745 WifiMacHeader cts;
747 cts.SetDsNotFrom();
748 cts.SetDsNotTo();
749 cts.SetNoMoreFragments();
750 cts.SetNoRetry();
751 cts.SetAddr1(rtsHdr.GetAddr2());
752 Time duration = rtsHdr.GetDuration() - m_phy->GetSifs() -
754 // The TXOP holder may exceed the TXOP limit in some situations (Sec. 10.22.2.8 of 802.11-2016)
755 if (duration.IsStrictlyNegative())
756 {
757 duration = Seconds(0);
758 }
759 cts.SetDuration(duration);
760
761 Ptr<Packet> packet = Create<Packet>();
762
763 SnrTag tag;
764 tag.Set(rtsSnr);
765 packet->AddPacketTag(tag);
766
767 // CTS should always use non-HT PPDU (HT PPDU cases not supported yet)
768 ForwardMpduDown(Create<WifiMpdu>(packet, cts), ctsTxVector);
769}
770
771void
773 WifiMode rtsTxMode,
774 double rtsSnr)
775{
776 NS_LOG_FUNCTION(this << rtsHdr << rtsTxMode << rtsSnr);
777
778 WifiTxVector ctsTxVector =
779 GetWifiRemoteStationManager()->GetCtsTxVector(rtsHdr.GetAddr2(), rtsTxMode);
780 DoSendCtsAfterRts(rtsHdr, ctsTxVector, rtsSnr);
781}
782
783Time
785 Time txDuration,
786 Time response) const
787{
788 NS_LOG_FUNCTION(this << ctsTxVector << txDuration << response);
789
790 return m_phy->GetSifs() + txDuration + response;
791}
792
793void
795{
796 NS_LOG_FUNCTION(this << &txParams);
797
798 WifiMacHeader cts;
800 cts.SetDsNotFrom();
801 cts.SetDsNotTo();
802 cts.SetNoMoreFragments();
803 cts.SetNoRetry();
804 cts.SetAddr1(m_self);
805
806 NS_ASSERT(txParams.m_protection &&
807 txParams.m_protection->method == WifiProtection::CTS_TO_SELF);
808 auto ctsToSelfProtection = static_cast<WifiCtsToSelfProtection*>(txParams.m_protection.get());
809
810 NS_ASSERT(txParams.m_txDuration.has_value());
811 NS_ASSERT(txParams.m_acknowledgment->acknowledgmentTime.has_value());
812 cts.SetDuration(GetCtsToSelfDurationId(ctsToSelfProtection->ctsTxVector,
813 *txParams.m_txDuration,
814 *txParams.m_acknowledgment->acknowledgmentTime));
815
816 ForwardMpduDown(Create<WifiMpdu>(Create<Packet>(), cts), ctsToSelfProtection->ctsTxVector);
817
818 Time ctsDuration = m_phy->CalculateTxDuration(GetCtsSize(),
819 ctsToSelfProtection->ctsTxVector,
820 m_phy->GetPhyBand());
821 Simulator::Schedule(ctsDuration + m_phy->GetSifs(),
823 this);
824}
825
826void
828 const WifiTxVector& dataTxVector,
829 double dataSnr)
830{
831 NS_LOG_FUNCTION(this << hdr << dataTxVector << dataSnr);
832
833 WifiTxVector ackTxVector =
834 GetWifiRemoteStationManager()->GetAckTxVector(hdr.GetAddr2(), dataTxVector);
835 WifiMacHeader ack;
837 ack.SetDsNotFrom();
838 ack.SetDsNotTo();
839 ack.SetNoRetry();
840 ack.SetNoMoreFragments();
841 ack.SetAddr1(hdr.GetAddr2());
842 // 802.11-2016, Section 9.2.5.7: Duration/ID is received duration value
843 // minus the time to transmit the Ack frame and its SIFS interval
844 Time duration = hdr.GetDuration() - m_phy->GetSifs() -
846 // The TXOP holder may exceed the TXOP limit in some situations (Sec. 10.22.2.8 of 802.11-2016)
847 if (duration.IsStrictlyNegative())
848 {
849 duration = Seconds(0);
850 }
851 ack.SetDuration(duration);
852
853 Ptr<Packet> packet = Create<Packet>();
854
855 SnrTag tag;
856 tag.Set(dataSnr);
857 packet->AddPacketTag(tag);
858
859 ForwardMpduDown(Create<WifiMpdu>(packet, ack), ackTxVector);
860}
861
864{
865 NS_LOG_FUNCTION(this);
866 NS_ASSERT(m_mpdu->GetHeader().IsMoreFragments());
867
868 WifiMacHeader& hdr = m_mpdu->GetHeader();
870
871 uint32_t startOffset = hdr.GetFragmentNumber() * m_mpdu->GetPacketSize();
872 uint32_t size = m_fragmentedPacket->GetSize() - startOffset;
873
874 if (size > m_mpdu->GetPacketSize())
875 {
876 // this is not the last fragment
877 size = m_mpdu->GetPacketSize();
878 hdr.SetMoreFragments();
879 }
880 else
881 {
882 hdr.SetNoMoreFragments();
883 }
884
885 return Create<WifiMpdu>(m_fragmentedPacket->CreateFragment(startOffset, size), hdr);
886}
887
888void
890{
891 NS_LOG_FUNCTION(this);
892
893 // Upon a transmission success, a non-QoS station transmits the next fragment,
894 // if any, or releases the channel, otherwise
895 if (m_moreFragments)
896 {
897 NS_LOG_DEBUG("Schedule transmission of next fragment in a SIFS");
900 this,
901 m_dcf,
903 m_moreFragments = false;
904 }
905 else
906 {
908 m_dcf = nullptr;
909 }
910}
911
912void
914{
915 NS_LOG_FUNCTION(this);
916 // A non-QoS station always releases the channel upon a transmission failure
918 m_dcf = nullptr;
919}
920
921void
923{
924 NS_LOG_FUNCTION(this << txop);
925 txop->NotifyChannelReleased(m_linkId);
926 m_protectedStas.clear();
927}
928
929void
931{
932 NS_LOG_FUNCTION(this << *mpdu << txVector);
933
934 GetWifiRemoteStationManager()->ReportDataFailed(mpdu);
935
936 if (!GetWifiRemoteStationManager()->NeedRetransmission(mpdu))
937 {
938 NS_LOG_DEBUG("Missed Ack, discard MPDU");
940 // Dequeue the MPDU if it is stored in a queue
941 DequeueMpdu(mpdu);
942 GetWifiRemoteStationManager()->ReportFinalDataFailed(mpdu);
944 }
945 else
946 {
947 NS_LOG_DEBUG("Missed Ack, retransmit MPDU");
948 if (mpdu->IsQueued()) // the MPDU may have been removed due to lifetime expiration
949 {
950 mpdu = m_mac->GetTxopQueue(mpdu->GetQueueAc())->GetOriginal(mpdu);
951 mpdu->ResetInFlight(m_linkId);
952 }
953 mpdu->GetHeader().SetRetry();
956 }
957
958 m_mpdu = nullptr;
960}
961
962void
964{
965 NS_LOG_FUNCTION(this << *mpdu);
966}
967
968void
970{
971 NS_LOG_FUNCTION(this << *rts << txVector);
972
973 DoCtsTimeout(Create<WifiPsdu>(m_mpdu, true));
974 m_mpdu = nullptr;
975}
976
977void
979{
980 NS_LOG_FUNCTION(this << *psdu);
981
982 m_sentRtsTo.clear();
983 for (const auto& mpdu : *PeekPointer(psdu))
984 {
985 if (mpdu->IsQueued())
986 {
987 mpdu->ResetInFlight(m_linkId);
988 }
989 }
990
991 GetWifiRemoteStationManager()->ReportRtsFailed(psdu->GetHeader(0));
992
993 if (!GetWifiRemoteStationManager()->NeedRetransmission(*psdu->begin()))
994 {
995 NS_LOG_DEBUG("Missed CTS, discard MPDU(s)");
996 GetWifiRemoteStationManager()->ReportFinalRtsFailed(psdu->GetHeader(0));
997 for (const auto& mpdu : *PeekPointer(psdu))
998 {
999 // Dequeue the MPDU if it is stored in a queue
1000 DequeueMpdu(mpdu);
1002 }
1004 }
1005 else
1006 {
1007 NS_LOG_DEBUG("Missed CTS, retransmit MPDU(s)");
1009 }
1010 // Make the sequence numbers of the MPDUs available again if the MPDUs have never
1011 // been transmitted, both in case the MPDUs have been discarded and in case the
1012 // MPDUs have to be transmitted (because a new sequence number is assigned to
1013 // MPDUs that have never been transmitted and are selected for transmission)
1015
1017}
1018
1019void
1021{
1022 NS_LOG_FUNCTION(this << *psdu);
1023
1024 NS_ASSERT_MSG(psdu->GetNMpdus() == 1, "A-MPDUs should be handled by the HT FEM override");
1025 auto mpdu = *psdu->begin();
1026
1027 // the MPDU should be still in the DCF queue, unless it expired.
1028 // If the MPDU has never been transmitted and is not in-flight, it will be assigned
1029 // a sequence number again the next time we try to transmit it. Therefore, we need to
1030 // make its sequence number available again
1031 if (!mpdu->GetHeader().IsRetry() && !mpdu->IsInFlight())
1032 {
1033 mpdu->UnassignSeqNo();
1034 m_txMiddle->SetSequenceNumberFor(&mpdu->GetOriginal()->GetHeader());
1035 }
1036}
1037
1038void
1040{
1041 NS_LOG_FUNCTION(this);
1042
1043 // For internal collisions occurring with the EDCA access method, the appropriate
1044 // retry counters (short retry counter for MSDU, A-MSDU, or MMPDU and QSRC[AC] or
1045 // long retry counter for MSDU, A-MSDU, or MMPDU and QLRC[AC]) are incremented
1046 // (Sec. 10.22.2.11.1 of 802.11-2016).
1047 // We do not prepare the PSDU that the AC losing the internal collision would have
1048 // sent. As an approximation, we consider the frame peeked from the queues of the AC.
1049 Ptr<QosTxop> qosTxop = (txop->IsQosTxop() ? StaticCast<QosTxop>(txop) : nullptr);
1050
1051 auto mpdu =
1052 (qosTxop ? qosTxop->PeekNextMpdu(m_linkId) : txop->GetWifiMacQueue()->Peek(m_linkId));
1053
1054 if (mpdu)
1055 {
1056 if (mpdu->GetHeader().HasData() && !mpdu->GetHeader().GetAddr1().IsGroup())
1057 {
1058 GetWifiRemoteStationManager()->ReportDataFailed(mpdu);
1059 }
1060
1061 if (!mpdu->GetHeader().GetAddr1().IsGroup() &&
1062 !GetWifiRemoteStationManager()->NeedRetransmission(mpdu))
1063 {
1064 NS_LOG_DEBUG("reset DCF");
1065 GetWifiRemoteStationManager()->ReportFinalDataFailed(mpdu);
1066 DequeueMpdu(mpdu);
1068 txop->ResetCw(m_linkId);
1069 }
1070 else
1071 {
1072 NS_LOG_DEBUG("Update CW");
1073 txop->UpdateFailedCw(m_linkId);
1074 }
1075 }
1076
1077 txop->Txop::NotifyChannelReleased(m_linkId);
1078}
1079
1080void
1082{
1083 NS_LOG_DEBUG("Switching channel. Cancelling MAC pending events");
1085 if (m_txTimer.IsRunning())
1086 {
1087 // we were transmitting something before channel switching. Since we will
1088 // not be able to receive the response, have the timer expire now, so that
1089 // we perform the actions required in case of missing response
1091 }
1093}
1094
1095void
1097{
1098 NS_LOG_DEBUG("Device in sleep mode. Cancelling MAC pending events");
1099 Reset();
1100}
1101
1102void
1104{
1105 NS_LOG_DEBUG("Device is switched off. Cancelling MAC pending events");
1106 Reset();
1107}
1108
1109void
1111 RxSignalInfo rxSignalInfo,
1112 WifiTxVector txVector,
1113 std::vector<bool> perMpduStatus)
1114{
1116 this << psdu << rxSignalInfo << txVector << perMpduStatus.size()
1117 << std::all_of(perMpduStatus.begin(), perMpduStatus.end(), [](bool v) { return v; }));
1118
1119 if (!perMpduStatus.empty())
1120 {
1121 // for A-MPDUs, we get here only once
1122 PreProcessFrame(psdu, txVector);
1123 }
1124
1125 Mac48Address addr1 = psdu->GetAddr1();
1126
1127 if (addr1.IsGroup() || addr1 == m_self)
1128 {
1129 // receive broadcast frames or frames addressed to us only
1130 if (psdu->GetNMpdus() == 1)
1131 {
1132 // if perMpduStatus is not empty (i.e., this MPDU is not included in an A-MPDU)
1133 // then it must contain a single value which must be true (i.e., the MPDU
1134 // has been correctly received)
1135 NS_ASSERT(perMpduStatus.empty() || (perMpduStatus.size() == 1 && perMpduStatus[0]));
1136 // Ack and CTS do not carry Addr2
1137 if (!psdu->GetHeader(0).IsAck() && !psdu->GetHeader(0).IsCts())
1138 {
1139 GetWifiRemoteStationManager()->ReportRxOk(psdu->GetHeader(0).GetAddr2(),
1140 rxSignalInfo,
1141 txVector);
1142 }
1143 ReceiveMpdu(*(psdu->begin()), rxSignalInfo, txVector, perMpduStatus.empty());
1144 }
1145 else
1146 {
1147 EndReceiveAmpdu(psdu, rxSignalInfo, txVector, perMpduStatus);
1148 }
1149 }
1150 else if (m_promisc)
1151 {
1152 for (const auto& mpdu : *PeekPointer(psdu))
1153 {
1154 if (!mpdu->GetHeader().IsCtl())
1155 {
1156 m_rxMiddle->Receive(mpdu, m_linkId);
1157 }
1158 }
1159 }
1160
1161 if (!perMpduStatus.empty())
1162 {
1163 // for A-MPDUs, we get here only once
1164 PostProcessFrame(psdu, txVector);
1165 }
1166}
1167
1168void
1170{
1171 NS_LOG_FUNCTION(this << psdu << txVector);
1172}
1173
1174void
1176{
1177 NS_LOG_FUNCTION(this << psdu << txVector);
1178
1179 UpdateNav(psdu, txVector);
1180}
1181
1182void
1184{
1185 NS_LOG_FUNCTION(this << psdu << txVector);
1186
1187 if (!psdu->HasNav())
1188 {
1189 return;
1190 }
1191
1192 Time duration = psdu->GetDuration();
1193 NS_LOG_DEBUG("Duration/ID=" << duration);
1194
1195 if (psdu->GetAddr1() == m_self)
1196 {
1197 // When the received frame’s RA is equal to the STA’s own MAC address, the STA
1198 // shall not update its NAV (IEEE 802.11-2016, sec. 10.3.2.4)
1199 return;
1200 }
1201
1202 // For all other received frames the STA shall update its NAV when the received
1203 // Duration is greater than the STA’s current NAV value (IEEE 802.11-2016 sec. 10.3.2.4)
1204 Time navEnd = Simulator::Now() + duration;
1205 if (navEnd > m_navEnd)
1206 {
1207 m_navEnd = navEnd;
1208 NS_LOG_DEBUG("Updated NAV=" << m_navEnd);
1209
1210 // A STA that used information from an RTS frame as the most recent basis to update
1211 // its NAV setting is permitted to reset its NAV if no PHY-RXSTART.indication
1212 // primitive is received from the PHY during a NAVTimeout period starting when the
1213 // MAC receives a PHY-RXEND.indication primitive corresponding to the detection of
1214 // the RTS frame. NAVTimeout period is equal to:
1215 // (2 x aSIFSTime) + (CTS_Time) + aRxPHYStartDelay + (2 x aSlotTime)
1216 // The “CTS_Time” shall be calculated using the length of the CTS frame and the data
1217 // rate at which the RTS frame used for the most recent NAV update was received
1218 // (IEEE 802.11-2016 sec. 10.3.2.4)
1219 if (psdu->GetHeader(0).IsRts())
1220 {
1221 WifiTxVector ctsTxVector =
1222 GetWifiRemoteStationManager()->GetCtsTxVector(psdu->GetAddr2(), txVector.GetMode());
1223 Time navResetDelay =
1224 2 * m_phy->GetSifs() +
1229 }
1230 }
1231 NS_LOG_DEBUG("Current NAV=" << m_navEnd);
1232
1234}
1235
1236void
1238{
1239 NS_LOG_FUNCTION(this);
1242}
1243
1244bool
1246{
1247 return m_navEnd <= Simulator::Now();
1248}
1249
1250void
1252 RxSignalInfo rxSignalInfo,
1253 const WifiTxVector& txVector,
1254 bool inAmpdu)
1255{
1256 NS_LOG_FUNCTION(this << *mpdu << rxSignalInfo << txVector << inAmpdu);
1257 // The received MPDU is either broadcast or addressed to this station
1258 NS_ASSERT(mpdu->GetHeader().GetAddr1().IsGroup() || mpdu->GetHeader().GetAddr1() == m_self);
1259
1260 double rxSnr = rxSignalInfo.snr;
1261 const WifiMacHeader& hdr = mpdu->GetHeader();
1262
1263 if (hdr.IsCtl())
1264 {
1265 if (hdr.IsRts())
1266 {
1267 NS_ABORT_MSG_IF(inAmpdu, "Received RTS as part of an A-MPDU");
1268
1269 // A non-VHT STA that is addressed by an RTS frame behaves as follows:
1270 // - If the NAV indicates idle, the STA shall respond with a CTS frame after a SIFS
1271 // - Otherwise, the STA shall not respond with a CTS frame
1272 // (IEEE 802.11-2016 sec. 10.3.2.7)
1273 if (VirtualCsMediumIdle())
1274 {
1275 NS_LOG_DEBUG("Received RTS from=" << hdr.GetAddr2() << ", schedule CTS");
1278 this,
1279 hdr,
1280 txVector.GetMode(),
1281 rxSnr);
1282 }
1283 else
1284 {
1285 NS_LOG_DEBUG("Received RTS from=" << hdr.GetAddr2() << ", cannot schedule CTS");
1286 }
1287 }
1288 else if (hdr.IsCts() && m_txTimer.IsRunning() &&
1290 {
1291 NS_ABORT_MSG_IF(inAmpdu, "Received CTS as part of an A-MPDU");
1292 NS_ASSERT(hdr.GetAddr1() == m_self);
1293
1294 Mac48Address sender = m_mpdu->GetHeader().GetAddr1();
1295 NS_LOG_DEBUG("Received CTS from=" << sender);
1296
1297 SnrTag tag;
1298 mpdu->GetPacket()->PeekPacketTag(tag);
1299 GetWifiRemoteStationManager()->ReportRxOk(sender, rxSignalInfo, txVector);
1300 GetWifiRemoteStationManager()->ReportRtsOk(m_mpdu->GetHeader(),
1301 rxSnr,
1302 txVector.GetMode(),
1303 tag.Get());
1304
1305 m_txTimer.Cancel();
1308 }
1309 else if (hdr.IsAck() && m_mpdu && m_txTimer.IsRunning() &&
1311 {
1312 NS_ASSERT(hdr.GetAddr1() == m_self);
1313 SnrTag tag;
1314 mpdu->GetPacket()->PeekPacketTag(tag);
1315 ReceivedNormalAck(m_mpdu, m_txParams.m_txVector, txVector, rxSignalInfo, tag.Get());
1316 m_mpdu = nullptr;
1317 }
1318 }
1319 else if (hdr.IsMgt())
1320 {
1321 NS_ABORT_MSG_IF(inAmpdu, "Received management frame as part of an A-MPDU");
1322
1323 if (hdr.IsBeacon() || hdr.IsProbeResp())
1324 {
1325 // Apply SNR tag for beacon quality measurements
1326 SnrTag tag;
1327 tag.Set(rxSnr);
1328 Ptr<Packet> packet = mpdu->GetPacket()->Copy();
1329 packet->AddPacketTag(tag);
1330 mpdu = Create<WifiMpdu>(packet, hdr);
1331 }
1332
1333 if (hdr.GetAddr1() == m_self)
1334 {
1335 NS_LOG_DEBUG("Received " << hdr.GetTypeString() << " from=" << hdr.GetAddr2()
1336 << ", schedule ACK");
1339 this,
1340 hdr,
1341 txVector,
1342 rxSnr);
1343 }
1344
1345 m_rxMiddle->Receive(mpdu, m_linkId);
1346 }
1347 else if (hdr.IsData() && !hdr.IsQosData())
1348 {
1349 if (hdr.GetAddr1() == m_self)
1350 {
1351 NS_LOG_DEBUG("Received " << hdr.GetTypeString() << " from=" << hdr.GetAddr2()
1352 << ", schedule ACK");
1355 this,
1356 hdr,
1357 txVector,
1358 rxSnr);
1359 }
1360
1361 m_rxMiddle->Receive(mpdu, m_linkId);
1362 }
1363}
1364
1365void
1367 const WifiTxVector& txVector,
1368 const WifiTxVector& ackTxVector,
1369 const RxSignalInfo& rxInfo,
1370 double snr)
1371{
1372 Mac48Address sender = mpdu->GetHeader().GetAddr1();
1373 NS_LOG_DEBUG("Received ACK from=" << sender);
1374
1376
1377 // When fragmentation is used, only update manager when the last fragment is acknowledged
1378 if (!mpdu->GetHeader().IsMoreFragments())
1379 {
1380 GetWifiRemoteStationManager()->ReportRxOk(sender, rxInfo, ackTxVector);
1381 GetWifiRemoteStationManager()->ReportDataOk(mpdu,
1382 rxInfo.snr,
1383 ackTxVector.GetMode(),
1384 snr,
1385 txVector);
1386 }
1387 // cancel the timer
1388 m_txTimer.Cancel();
1390
1391 // The CW shall be reset to aCWmin after every successful attempt to transmit
1392 // a frame containing all or part of an MSDU or MMPDU (sec. 10.3.3 of 802.11-2016)
1394
1395 if (mpdu->GetHeader().IsMoreFragments())
1396 {
1397 // replace the current fragment with the next one
1398 m_dcf->GetWifiMacQueue()->Replace(mpdu, GetNextFragment());
1399 m_moreFragments = true;
1400 }
1401 else
1402 {
1403 // the MPDU has been acknowledged, we can now dequeue it if it is stored in a queue
1404 DequeueMpdu(mpdu);
1405 }
1406
1408}
1409
1410void
1412{
1413 NS_LOG_FUNCTION(this << *mpdu);
1414
1415 // inform the MAC that the transmission was successful
1417 {
1418 m_ackedMpduCallback(mpdu);
1419 }
1420}
1421
1422void
1424 const RxSignalInfo& rxSignalInfo,
1425 const WifiTxVector& txVector,
1426 const std::vector<bool>& perMpduStatus)
1427{
1428 NS_ASSERT_MSG(false, "A non-QoS station should not receive an A-MPDU");
1429}
1430
1431} // namespace ns3
bool IsNull() const
Check for null implementation.
Definition: callback.h:571
void NotifyAckTimeoutResetNow()
Notify that ack timer has reset.
void NotifyAckTimeoutStartNow(Time duration)
Notify that ack timer has started for the given duration.
void NotifyCtsTimeoutStartNow(Time duration)
Notify that CTS timer has started for the given duration.
void NotifyCtsTimeoutResetNow()
Notify that CTS timer has reset.
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:55
bool IsPending() const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:76
std::set< Mac48Address > m_sentRtsTo
the STA(s) which we sent an RTS to (waiting for CTS)
void DoCtsTimeout(Ptr< WifiPsdu > psdu)
Take required actions when the CTS timer fired after sending an RTS to protect the given PSDU expires...
Ptr< WifiMpdu > m_mpdu
the MPDU being transmitted
virtual void SetAckManager(Ptr< WifiAckManager > ackManager)
Set the Acknowledgment Manager to use.
void NotifyOffNow()
This method is typically invoked by the PhyListener to notify the MAC layer that the device has been ...
virtual void NotifyInternalCollision(Ptr< Txop > txop)
Notify that an internal collision has occurred for the given Txop.
static TypeId GetTypeId()
Get the type ID.
uint8_t m_linkId
the ID of the link this object is associated with
Ptr< WifiMac > m_mac
the MAC layer on this station
DroppedMpdu m_droppedMpduCallback
the dropped MPDU callback
virtual void SetWifiMac(const Ptr< WifiMac > mac)
Set the MAC layer to use.
virtual void ResetPhy()
Remove WifiPhy associated with this FrameExchangeManager.
virtual void UpdateNav(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector)
Update the NAV, if needed, based on the Duration/ID of the given psdu.
void SendMpduWithProtection(Ptr< WifiMpdu > mpdu, WifiTxParameters &txParams)
Send an MPDU with the given TX parameters (with the specified protection).
Ptr< WifiAckManager > m_ackManager
Acknowledgment manager.
Ptr< WifiRemoteStationManager > GetWifiRemoteStationManager() const
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...
virtual void CalculateAcknowledgmentTime(WifiAcknowledgment *acknowledgment) const
Calculate the time required to acknowledge a frame according to the given acknowledgment method.
Ptr< MacTxMiddle > m_txMiddle
the MAC TX Middle on this station
void SendNormalAck(const WifiMacHeader &hdr, const WifiTxVector &dataTxVector, double dataSnr)
Send Normal Ack.
Ptr< Packet > m_fragmentedPacket
the MSDU being fragmented
virtual void SetDroppedMpduCallback(DroppedMpdu callback)
Set the callback to invoke when an MPDU is dropped.
virtual void Reset()
Reset this frame exchange manager.
Mac48Address m_self
the MAC address of this device
virtual void StartProtection(const WifiTxParameters &txParams)
Start the protection mechanism indicated by the given TX parameters.
virtual void TransmissionFailed()
Take necessary actions upon a transmission failure.
uint16_t m_allowedWidth
the allowed width in MHz for the current transmission
virtual void NotifyPacketDiscarded(Ptr< const WifiMpdu > mpdu)
Pass the given MPDU, discarded because of the max retry limit was reached, to the MPDU dropped callba...
WifiTxTimer m_txTimer
the timer set upon frame transmission
virtual void SendCtsAfterRts(const WifiMacHeader &rtsHdr, WifiMode rtsTxMode, double rtsSnr)
Send CTS after receiving RTS.
std::set< Mac48Address > m_protectedStas
STAs that have replied to an RTS in this TXOP.
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 ...
virtual void RetransmitMpduAfterMissedAck(Ptr< WifiMpdu > mpdu) const
Retransmit an MPDU that was not acknowledged.
Mac48Address GetAddress() const
Get the MAC address.
Ptr< WifiProtectionManager > m_protectionManager
Protection manager.
virtual void ProtectionCompleted()
Transmit prepared frame upon successful protection mechanism.
virtual void ForwardMpduDown(Ptr< WifiMpdu > mpdu, WifiTxVector &txVector)
Forward an MPDU down to the PHY layer.
virtual void SetLinkId(uint8_t linkId)
Set the ID of the link this Frame Exchange Manager is associated with.
virtual bool VirtualCsMediumIdle() const
void SendRts(const WifiTxParameters &txParams)
Send RTS to begin RTS-CTS-Data-Ack transaction.
virtual void NotifyReceivedNormalAck(Ptr< WifiMpdu > mpdu)
Notify other components that an MPDU was acknowledged.
virtual void NotifyChannelReleased(Ptr< Txop > txop)
Notify the given Txop that channel has been released.
virtual void NormalAckTimeout(Ptr< WifiMpdu > mpdu, const WifiTxVector &txVector)
Called when the Ack timeout expires.
virtual void NotifySwitchingStartNow(Time duration)
virtual void SetBssid(Mac48Address bssid)
Set the Basic Service Set Identification.
void SendCtsToSelf(const WifiTxParameters &txParams)
Send CTS for a CTS-to-self mechanism.
virtual void CtsTimeout(Ptr< WifiMpdu > rts, const WifiTxVector &txVector)
Called when the CTS timeout expires.
virtual void CalculateProtectionTime(WifiProtection *protection) const
Calculate the time required to protect a frame according to the given protection method.
virtual void SetAddress(Mac48Address address)
Set the MAC address.
Ptr< WifiAckManager > GetAckManager() const
Get the Acknowledgment Manager used by this node.
virtual void DequeueMpdu(Ptr< const WifiMpdu > mpdu)
Dequeue the given MPDU from the queue in which it is stored.
virtual void NavResetTimeout()
Reset the NAV upon expiration of the NAV reset timer.
const std::set< Mac48Address > & GetProtectedStas() const
Ptr< WifiProtectionManager > GetProtectionManager() const
Get the Protection Manager used by this node.
bool IsPromisc() const
Check if the device is operating in promiscuous mode.
void SendMpdu()
Send the current MPDU, which can be acknowledged by a Normal Ack.
virtual void EndReceiveAmpdu(Ptr< const WifiPsdu > psdu, const RxSignalInfo &rxSignalInfo, const WifiTxVector &txVector, const std::vector< bool > &perMpduStatus)
This method is called when the reception of an A-MPDU including multiple MPDUs is completed.
Ptr< MacRxMiddle > m_rxMiddle
the MAC RX Middle on this station
virtual void TransmissionSucceeded()
Take necessary actions upon a transmission success.
Ptr< Txop > m_dcf
the DCF/EDCAF that gained channel access
Ptr< WifiPhy > m_phy
the PHY layer on this station
Ptr< WifiMpdu > GetFirstFragmentIfNeeded(Ptr< WifiMpdu > mpdu)
Fragment the given MPDU if needed.
Ptr< WifiMpdu > GetNextFragment()
Get the next fragment of the current MSDU.
virtual void ReleaseSequenceNumbers(Ptr< const WifiPsdu > psdu) const
Make the sequence numbers of MPDUs included in the given PSDU available again if the MPDUs have never...
void SetAckedMpduCallback(AckedMpdu callback)
Set the callback to invoke when an MPDU is successfully acked.
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...
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.
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 DoSendCtsAfterRts(const WifiMacHeader &rtsHdr, WifiTxVector &ctsTxVector, double rtsSnr)
Send CTS after receiving RTS.
void Receive(Ptr< const WifiPsdu > psdu, RxSignalInfo rxSignalInfo, WifiTxVector txVector, std::vector< bool > perMpduStatus)
This method is intended to be called by the PHY layer every time an MPDU is received and also when th...
Mac48Address m_bssid
BSSID address (Mac48Address)
virtual void SetWifiPhy(const Ptr< WifiPhy > phy)
Set the PHY layer to use.
AckedMpdu m_ackedMpduCallback
the acknowledged MPDU callback
virtual void FinalizeMacHeader(Ptr< const WifiPsdu > psdu)
Finalize the MAC header of the MPDUs in the given PSDU before transmission.
virtual void PostProcessFrame(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector)
Perform actions that are possibly needed after receiving any frame, independently of whether the fram...
virtual uint32_t GetPsduSize(Ptr< const WifiMpdu > mpdu, const WifiTxVector &txVector) const
Get the size in bytes of the given MPDU, which is to be transmitted with the given TXVECTOR.
Ptr< ChannelAccessManager > m_channelAccessManager
the channel access manager
virtual void ReceivedNormalAck(Ptr< WifiMpdu > mpdu, const WifiTxVector &txVector, const WifiTxVector &ackTxVector, const RxSignalInfo &rxInfo, double snr)
Perform the actions needed when a Normal Ack is received.
bool m_promisc
Flag if the device is operating in promiscuous mode.
void NotifySleepNow()
This method is typically invoked by the PhyListener to notify the MAC layer that the device has been ...
virtual void ReceiveMpdu(Ptr< const WifiMpdu > mpdu, RxSignalInfo rxSignalInfo, const WifiTxVector &txVector, bool inAmpdu)
This method handles the reception of an MPDU (possibly included in an A-MPDU)
virtual void SetChannelAccessManager(const Ptr< ChannelAccessManager > channelAccessManager)
Set the channel access manager to use.
bool m_moreFragments
true if a fragment has to be sent after a SIFS
void SetPromisc()
Enable promiscuous mode.
Time m_navEnd
NAV expiration time.
virtual void SetMacTxMiddle(const Ptr< MacTxMiddle > txMiddle)
Set the MAC TX Middle to use.
virtual void SetMacRxMiddle(const Ptr< MacRxMiddle > rxMiddle)
Set the MAC RX Middle to use.
virtual void SetProtectionManager(Ptr< WifiProtectionManager > protectionManager)
Set the Protection Manager to use.
Mac48Address GetBssid() const
Get the Basic Service Set Identification.
void DoDispose() override
Destructor implementation.
WifiTxParameters m_txParams
the TX parameters for the current frame
virtual bool StartTransmission(Ptr< Txop > dcf, uint16_t allowedWidth)
Request the FrameExchangeManager to start a frame exchange sequence.
virtual void RxStartIndication(WifiTxVector txVector, Time psduDuration)
EventId m_navResetEvent
the event to reset the NAV after an RTS
const WifiTxTimer & GetWifiTxTimer() const
Get a const reference to the WifiTxTimer object.
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...
an EUI-48 address
Definition: mac48-address.h:46
bool IsGroup() const
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:322
bool TraceDisconnectWithoutContext(std::string name, const CallbackBase &cb)
Disconnect from a TraceSource a Callback previously connected without a context.
Definition: object-base.cc:352
A base class which provides memory management and object aggregation.
Definition: object.h:89
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:444
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:861
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
Definition: packet.cc:238
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition: simulator.h:605
void Set(double snr)
Set the SNR to the given value.
Definition: snr-tag.cc:84
double Get() const
Return the SNR value.
Definition: snr-tag.cc:90
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:415
bool IsStrictlyPositive() const
Exactly equivalent to t > 0.
Definition: nstime.h:351
@ US
microsecond
Definition: nstime.h:118
bool IsStrictlyNegative() const
Exactly equivalent to t < 0.
Definition: nstime.h:342
void UpdateFailedCw(uint8_t linkId)
Update the value of the CW variable for the given link to take into account a transmission failure.
Definition: txop.cc:382
Ptr< WifiMacQueue > GetWifiMacQueue() const
Return the packet queue associated with this Txop.
Definition: txop.cc:275
void ResetCw(uint8_t linkId)
Update the value of the CW variable for the given link to take into account a transmission success or...
Definition: txop.cc:373
virtual void NotifyChannelAccessed(uint8_t linkId, Time txopDuration=Seconds(0))
Called by the FrameExchangeManager to notify that channel access has been granted on the given link f...
Definition: txop.cc:760
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
static void SetQosAckPolicy(Ptr< WifiMpdu > item, const WifiAcknowledgment *acknowledgment)
Set the QoS Ack policy for the given MPDU, which must be a QoS data frame.
Implements the IEEE 802.11 MAC header.
bool IsAck() const
Return true if the header is an Ack header.
bool IsCts() const
Return true if the header is a CTS header.
bool IsBeacon() const
Return true if the header is a Beacon header.
Mac48Address GetAddr1() const
Return the address in the Address 1 field.
bool IsMoreFragments() const
Return if the More Fragment bit is set.
void SetNoMoreFragments()
Un-set the More Fragment bit in the Frame Control Field.
bool IsMgt() const
Return true if the Type is Management.
bool IsCtl() const
Return true if the Type is Control.
Time GetDuration() const
Return the duration from the Duration/ID field (Time object).
virtual uint32_t GetSize() const
Return the size of the WifiMacHeader in octets.
void SetDsNotFrom()
Un-set the From DS bit in the Frame Control field.
bool IsProbeResp() const
Return true if the header is a Probe Response header.
void SetMoreFragments()
Set the More Fragment bit in the Frame Control field.
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
virtual void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
Mac48Address GetAddr2() const
Return the address in the Address 2 field.
virtual const char * GetTypeString() const
Return a string corresponds to the header type.
void SetDuration(Time duration)
Set the Duration/ID field with the given duration (Time object).
bool IsData() const
Return true if the Type is DATA.
bool IsRts() const
Return true if the header is a RTS header.
void SetAddr2(Mac48Address address)
Fill the Address 2 field with the given address.
uint8_t GetFragmentNumber() const
Return the fragment number of the header.
bool IsQosData() const
Return true if the Type is DATA and Subtype is one of the possible values for QoS Data.
void SetDsNotTo()
Un-set the To DS bit in the Frame Control field.
void SetFragmentNumber(uint8_t frag)
Set the fragment number of the header.
void SetNoRetry()
Un-set the Retry bit in the Frame Control field.
virtual void NotifyChannelSwitching(uint8_t linkId)
Notify that channel on the given link has been switched.
Definition: wifi-mac.cc:676
TypeOfStation GetTypeOfStation() const
Return the type of station.
Definition: wifi-mac.cc:466
virtual Ptr< WifiMacQueue > GetTxopQueue(AcIndex ac) const
Get the wifi MAC queue of the (Qos)Txop associated with the given AC, if such (Qos)Txop is installed,...
Definition: wifi-mac.cc:639
Ptr< WifiRemoteStationManager > GetWifiRemoteStationManager(uint8_t linkId=0) const
Definition: wifi-mac.cc:1045
represent a single transmission mode
Definition: wifi-mode.h:51
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:1759
Time GetSlot() const
Return the slot duration for this PHY.
Definition: wifi-phy.cc:825
Time GetSifs() const
Return the Short Interframe Space (SIFS) for this PHY.
Definition: wifi-phy.cc:813
static Time CalculateTxDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, uint16_t staId=SU_STA_ID)
Definition: wifi-phy.cc:1539
Ptr< WifiPhyStateHelper > GetState() const
Return the WifiPhyStateHelper of this PHY.
Definition: wifi-phy.cc:461
WifiPhyBand GetPhyBand() const
Get the configured Wi-Fi band.
Definition: wifi-phy.cc:1053
void SetReceiveOkCallback(RxOkCallback callback)
Definition: wifi-phy.cc:467
static Time CalculatePhyPreambleAndHeaderDuration(const WifiTxVector &txVector)
Definition: wifi-phy.cc:1532
This class stores the TX parameters (TX vector, protection mechanism, acknowledgment mechanism,...
std::optional< Time > m_txDuration
TX duration of the frame.
const PsduInfoMap & GetPsduInfoMap() const
Get a const reference to the map containing information about PSDUs.
std::unique_ptr< WifiProtection > m_protection
protection method
uint32_t GetSize(Mac48Address receiver) const
Get the size in bytes of the (A-)MPDU addressed to the given receiver.
std::unique_ptr< WifiAcknowledgment > m_acknowledgment
acknowledgment method
WifiTxVector m_txVector
TXVECTOR of the frame being prepared.
void AddMpdu(Ptr< const WifiMpdu > mpdu)
Record that an MPDU is being added to the current frame.
void Clear()
Reset the TX parameters.
This class is used to handle the timer that a station starts when transmitting a frame that solicits ...
Definition: wifi-tx-timer.h:49
bool IsRunning() const
Return true if the timer is running.
void Cancel()
Cancel the timer.
void Set(Reason reason, const Time &delay, const std::set< Mac48Address > &from, MEM mem_ptr, OBJ obj, Args... args)
This method is called when a frame soliciting a response is transmitted.
Reason GetReason() const
Get the reason why the timer was started.
void Reschedule(const Time &delay)
Reschedule the timer to time out the given amount of time from the moment this function is called.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
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.
uint16_t GetChannelWidth() const
#define PSDU_DURATION_SAFEGUARD
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#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:86
Callback< R, Args... > MakeNullCallback()
Definition: callback.h:743
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:49
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1355
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
@ STA
Definition: wifi-mac.h:68
@ WIFI_MAC_DROP_REACHED_RETRY_LIMIT
Definition: wifi-mac.h:83
@ WIFI_PM_SWITCHING_TO_ACTIVE
Definition: sta-wifi-mac.h:96
@ WIFI_PM_POWERSAVE
Definition: sta-wifi-mac.h:95
@ WIFI_PM_SWITCHING_TO_PS
Definition: sta-wifi-mac.h:94
@ WIFI_PM_ACTIVE
Definition: sta-wifi-mac.h:93
Every class exported by the ns3 library is enclosed in the ns3 namespace.
U * PeekPointer(const Ptr< U > &p)
Definition: ptr.h:454
static const uint16_t WIFI_MAC_FCS_LENGTH
The length in octets of the IEEE 802.11 MAC FCS field.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:700
uint32_t GetRtsSize()
Return the total RTS size (including FCS trailer).
Definition: wifi-utils.cc:105
@ WIFI_MAC_CTL_RTS
@ WIFI_MAC_CTL_CTS
@ WIFI_MAC_CTL_ACK
uint32_t GetAckSize()
Return the total Ack size (including FCS trailer).
Definition: wifi-utils.cc:60
uint32_t GetCtsSize()
Return the total CTS size (including FCS trailer).
Definition: wifi-utils.cc:113
ns3::Time timeout
RxSignalInfo structure containing info on the received signal.
Definition: phy-entity.h:69
double snr
SNR in linear scale.
Definition: phy-entity.h:70
WifiAcknowledgment is an abstract base struct.
const Method method
acknowledgment method
std::optional< Time > acknowledgmentTime
time required by the acknowledgment method
WifiCtsToSelfProtection specifies that CTS-to-self protection method is used.
WifiNormalAck specifies that acknowledgment via Normal Ack is required.
WifiProtection is an abstract base struct.
std::optional< Time > protectionTime
time required by the protection method
const Method method
protection method
WifiRtsCtsProtection specifies that RTS/CTS protection method is used.