From 96774d6d67e4fb69a63535f6901e7de77079bf4a Mon Sep 17 00:00:00 2001 From: Rediet Date: Mon, 1 Apr 2019 11:10:25 +0200 Subject: [PATCH] wifi: Add a method to check whether packet is an A-MPDU --- src/wifi/model/wifi-utils.cc | 38 ++++++++++++++++++++++++++++++++++++ src/wifi/model/wifi-utils.h | 7 +++++++ 2 files changed, 45 insertions(+) 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