diff --git a/src/wifi/model/wifi-utils.cc b/src/wifi/model/wifi-utils.cc index 321e771f5..02d8a60f2 100644 --- a/src/wifi/model/wifi-utils.cc +++ b/src/wifi/model/wifi-utils.cc @@ -27,6 +27,7 @@ #include "ht-configuration.h" #include "he-configuration.h" #include "wifi-mode.h" +#include "ampdu-subframe-header.h" namespace ns3 { @@ -264,4 +265,41 @@ GetPpduMaxTime (WifiPreamble preamble) return duration; } +bool +IsAmpdu (Ptr packet) +{ + AmpduSubframeHeader hdr; + //Rely on metadata if present + bool metadataEnabled = false; + PacketMetadata::ItemIterator metadataIterator = packet->BeginItem (); + while (metadataIterator.HasNext ()) + { + metadataEnabled = true; + PacketMetadata::Item item = metadataIterator.Next (); + if (item.tid == hdr.GetTypeId ()) + { + return true; + } + } + if (metadataEnabled) + { + //Didn't find header in metadata + return false; + } + + //No metadata so peek manually into buffer and check consistency of extracted data + uint32_t totalSize = packet->GetSize (); + uint32_t deserialized = packet->PeekHeader (hdr); + if (deserialized == hdr.GetSerializedSize () + && hdr.IsSignatureValid () + && hdr.GetLength () <= (totalSize - deserialized)) + { + return true; + } + else + { + return false; + } +} + } //namespace ns3 diff --git a/src/wifi/model/wifi-utils.h b/src/wifi/model/wifi-utils.h index 168fffd4d..a9ff9d911 100644 --- a/src/wifi/model/wifi-utils.h +++ b/src/wifi/model/wifi-utils.h @@ -175,6 +175,13 @@ void AddWifiMacTrailer (Ptr packet); * \return the total packet size */ uint32_t GetSize (Ptr packet, const WifiMacHeader *hdr, bool isAmpdu); +/** + * \param packet the packet to check + * \returns true if packet is an A-MPDU + * + * This method checks if the packet is an A-MPDU by looking for A-MPDU subframe headers. + */ +bool IsAmpdu (Ptr packet); /** * Get the maximum PPDU duration (see Section 10.14 of 802.11-2016) for