From de2f4d08c9449df1abaaef48a6972dee6c68f997 Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Sun, 1 Sep 2019 01:29:03 +0200 Subject: [PATCH] wifi: Receive WifiMacQueueItems instead of separate header and payload which means that original MSDUs (i.e., packets) are preserved in case of A-MSDU aggregation. --- src/mesh/model/mesh-wifi-interface-mac.cc | 4 +- src/mesh/model/mesh-wifi-interface-mac.h | 5 +- src/wave/model/ocb-wifi-mac.cc | 12 +++-- src/wave/model/ocb-wifi-mac.h | 2 +- src/wifi/model/adhoc-wifi-mac.cc | 11 +++-- src/wifi/model/adhoc-wifi-mac.h | 2 +- src/wifi/model/ap-wifi-mac.cc | 32 ++++++------ src/wifi/model/ap-wifi-mac.h | 8 ++- src/wifi/model/mac-low.cc | 60 ++++++++++++----------- src/wifi/model/mac-low.h | 19 +++---- src/wifi/model/mac-rx-middle.cc | 21 ++++++-- src/wifi/model/mac-rx-middle.h | 8 +-- src/wifi/model/regular-wifi-mac.cc | 18 +++---- src/wifi/model/regular-wifi-mac.h | 11 ++--- src/wifi/model/sta-wifi-mac.cc | 12 +++-- src/wifi/model/sta-wifi-mac.h | 5 +- 16 files changed, 125 insertions(+), 105 deletions(-) diff --git a/src/mesh/model/mesh-wifi-interface-mac.cc b/src/mesh/model/mesh-wifi-interface-mac.cc index 0b18e724a..6186cdf03 100644 --- a/src/mesh/model/mesh-wifi-interface-mac.cc +++ b/src/mesh/model/mesh-wifi-interface-mac.cc @@ -417,8 +417,10 @@ MeshWifiInterfaceMac::SendBeacon () ScheduleNextBeacon (); } void -MeshWifiInterfaceMac::Receive (Ptr packet, WifiMacHeader const *hdr) +MeshWifiInterfaceMac::Receive (Ptr mpdu) { + const WifiMacHeader* hdr = &mpdu->GetHeader (); + Ptr packet = mpdu->GetPacket ()->Copy (); // Process beacon if ((hdr->GetAddr1 () != GetAddress ()) && (hdr->GetAddr1 () != Mac48Address::GetBroadcast ())) { diff --git a/src/mesh/model/mesh-wifi-interface-mac.h b/src/mesh/model/mesh-wifi-interface-mac.h index cacab3545..79c75de49 100644 --- a/src/mesh/model/mesh-wifi-interface-mac.h +++ b/src/mesh/model/mesh-wifi-interface-mac.h @@ -180,10 +180,9 @@ private: /** * Frame receive handler * - * \param packet the received packet - * \param hdr the wifi MAC header + * \param mpdu the received MPDU */ - void Receive (Ptr packet, WifiMacHeader const *hdr); + void Receive (Ptr mpdu); /** * Send frame. Frame is supposed to be tagged by routing information. * diff --git a/src/wave/model/ocb-wifi-mac.cc b/src/wave/model/ocb-wifi-mac.cc index 76c5d67e2..005590928 100644 --- a/src/wave/model/ocb-wifi-mac.cc +++ b/src/wave/model/ocb-wifi-mac.cc @@ -238,9 +238,13 @@ OcbWifiMac::Enqueue (Ptr packet, Mac48Address to) * here we only care about data packet and vsa management frame */ void -OcbWifiMac::Receive (Ptr packet, const WifiMacHeader *hdr) +OcbWifiMac::Receive (Ptr mpdu) { - NS_LOG_FUNCTION (this << packet << hdr); + NS_LOG_FUNCTION (this << *mpdu); + const WifiMacHeader* hdr = &mpdu->GetHeader (); + // Create a copy of the MPDU payload because non-const operations like RemovePacketTag + // and RemoveHeader may need to be performed. + Ptr packet = mpdu->GetPacket ()->Copy (); NS_ASSERT (!hdr->IsCtl ()); NS_ASSERT (hdr->GetAddr3 () == WILDCARD_BSSID); @@ -269,7 +273,7 @@ OcbWifiMac::Receive (Ptr packet, const WifiMacHeader *hdr) if (hdr->IsQosData () && hdr->IsQosAmsdu ()) { NS_LOG_DEBUG ("Received A-MSDU from" << from); - DeaggregateAmsduAndForward (packet, hdr); + DeaggregateAmsduAndForward (mpdu); } else { @@ -320,7 +324,7 @@ OcbWifiMac::Receive (Ptr packet, const WifiMacHeader *hdr) // Invoke the receive handler of our parent class to deal with any // other frames. Specifically, this will handle Block Ack-related // Management Action frames. - RegularWifiMac::Receive (packet, hdr); + RegularWifiMac::Receive (Create (packet, *hdr)); } void diff --git a/src/wave/model/ocb-wifi-mac.h b/src/wave/model/ocb-wifi-mac.h index 852d79386..990fd55ce 100644 --- a/src/wave/model/ocb-wifi-mac.h +++ b/src/wave/model/ocb-wifi-mac.h @@ -176,7 +176,7 @@ public: protected: virtual void FinishConfigureStandard (enum WifiPhyStandard standard); private: - virtual void Receive (Ptr packet, const WifiMacHeader *hdr); + virtual void Receive (Ptr mpdu); VendorSpecificContentManager m_vscManager; ///< VSC manager }; diff --git a/src/wifi/model/adhoc-wifi-mac.cc b/src/wifi/model/adhoc-wifi-mac.cc index 9534428f8..8cb5a4aa3 100644 --- a/src/wifi/model/adhoc-wifi-mac.cc +++ b/src/wifi/model/adhoc-wifi-mac.cc @@ -168,9 +168,10 @@ AdhocWifiMac::SetLinkUpCallback (Callback linkUp) } void -AdhocWifiMac::Receive (Ptr packet, const WifiMacHeader *hdr) +AdhocWifiMac::Receive (Ptr mpdu) { - NS_LOG_FUNCTION (this << packet << hdr); + NS_LOG_FUNCTION (this << *mpdu); + const WifiMacHeader* hdr = &mpdu->GetHeader (); NS_ASSERT (!hdr->IsCtl ()); Mac48Address from = hdr->GetAddr2 (); Mac48Address to = hdr->GetAddr1 (); @@ -198,11 +199,11 @@ AdhocWifiMac::Receive (Ptr packet, const WifiMacHeader *hdr) if (hdr->IsQosData () && hdr->IsQosAmsdu ()) { NS_LOG_DEBUG ("Received A-MSDU from" << from); - DeaggregateAmsduAndForward (packet, hdr); + DeaggregateAmsduAndForward (mpdu); } else { - ForwardUp (packet, from, to); + ForwardUp (mpdu->GetPacket ()->Copy (), from, to); } return; } @@ -210,7 +211,7 @@ AdhocWifiMac::Receive (Ptr packet, const WifiMacHeader *hdr) //Invoke the receive handler of our parent class to deal with any //other frames. Specifically, this will handle Block Ack-related //Management Action frames. - RegularWifiMac::Receive (packet, hdr); + RegularWifiMac::Receive (mpdu); } } //namespace ns3 diff --git a/src/wifi/model/adhoc-wifi-mac.h b/src/wifi/model/adhoc-wifi-mac.h index 648fb6505..fbe494e42 100644 --- a/src/wifi/model/adhoc-wifi-mac.h +++ b/src/wifi/model/adhoc-wifi-mac.h @@ -66,7 +66,7 @@ public: private: - void Receive (Ptr packet, const WifiMacHeader *hdr); + void Receive (Ptr mpdu); }; } //namespace ns3 diff --git a/src/wifi/model/ap-wifi-mac.cc b/src/wifi/model/ap-wifi-mac.cc index 7921a1cf7..869918019 100644 --- a/src/wifi/model/ap-wifi-mac.cc +++ b/src/wifi/model/ap-wifi-mac.cc @@ -1018,9 +1018,13 @@ ApWifiMac::TxFailed (const WifiMacHeader &hdr) } void -ApWifiMac::Receive (Ptr packet, const WifiMacHeader *hdr) +ApWifiMac::Receive (Ptr mpdu) { - NS_LOG_FUNCTION (this << packet << hdr); + NS_LOG_FUNCTION (this << *mpdu); + const WifiMacHeader* hdr = &mpdu->GetHeader (); + // Create a copy of the MPDU payload because non-const operations like RemovePacketTag + // and RemoveHeader may need to be performed. + Ptr packet = mpdu->GetPacket ()->Copy (); Mac48Address from = hdr->GetAddr2 (); if (hdr->IsData ()) { @@ -1039,7 +1043,7 @@ ApWifiMac::Receive (Ptr packet, const WifiMacHeader *hdr) if (hdr->IsQosAmsdu ()) { NS_LOG_DEBUG ("Received A-MSDU from=" << from << ", size=" << packet->GetSize ()); - DeaggregateAmsduAndForward (packet, hdr); + DeaggregateAmsduAndForward (mpdu); packet = 0; } else @@ -1536,28 +1540,26 @@ ApWifiMac::Receive (Ptr packet, const WifiMacHeader *hdr) //Invoke the receive handler of our parent class to deal with any //other frames. Specifically, this will handle Block Ack-related //Management Action frames. - RegularWifiMac::Receive (packet, hdr); + RegularWifiMac::Receive (Create (packet, *hdr)); } void -ApWifiMac::DeaggregateAmsduAndForward (Ptr aggregatedPacket, const WifiMacHeader *hdr) +ApWifiMac::DeaggregateAmsduAndForward (Ptr mpdu) { - NS_LOG_FUNCTION (this << aggregatedPacket << hdr); - MsduAggregator::DeaggregatedMsdus packets = MsduAggregator::Deaggregate (aggregatedPacket); - for (MsduAggregator::DeaggregatedMsdusCI i = packets.begin (); - i != packets.end (); ++i) + NS_LOG_FUNCTION (this << *mpdu); + for (auto& i : *PeekPointer (mpdu)) { - if ((*i).second.GetDestinationAddr () == GetAddress ()) + if (i.second.GetDestinationAddr () == GetAddress ()) { - ForwardUp ((*i).first, (*i).second.GetSourceAddr (), - (*i).second.GetDestinationAddr ()); + ForwardUp (i.first, i.second.GetSourceAddr (), + i.second.GetDestinationAddr ()); } else { - Mac48Address from = (*i).second.GetSourceAddr (); - Mac48Address to = (*i).second.GetDestinationAddr (); + Mac48Address from = i.second.GetSourceAddr (); + Mac48Address to = i.second.GetDestinationAddr (); NS_LOG_DEBUG ("forwarding QoS frame from=" << from << ", to=" << to); - ForwardDown ((*i).first, from, to, hdr->GetQosTid ()); + ForwardDown (i.first, from, to, mpdu->GetHeader ().GetQosTid ()); } } } diff --git a/src/wifi/model/ap-wifi-mac.h b/src/wifi/model/ap-wifi-mac.h index 141a0fad2..8fd1b1b7e 100644 --- a/src/wifi/model/ap-wifi-mac.h +++ b/src/wifi/model/ap-wifi-mac.h @@ -154,7 +154,7 @@ public: private: - void Receive (Ptr packet, const WifiMacHeader *hdr); + void Receive (Ptr mpdu); /** * The packet we sent was successfully received by the receiver * (i.e. we received an ACK from the receiver). If the packet @@ -180,11 +180,9 @@ private: * here because, as an AP, we also need to think about redistributing * to other associated STAs. * - * \param aggregatedPacket the Packet containing the A-MSDU. - * \param hdr a pointer to the MAC header for \c aggregatedPacket. + * \param mpdu the MPDU containing the A-MSDU. */ - void DeaggregateAmsduAndForward (Ptr aggregatedPacket, - const WifiMacHeader *hdr); + void DeaggregateAmsduAndForward (Ptr mpdu); /** * Forward the packet down to DCF/EDCAF (enqueue the packet). This method * is a wrapper for ForwardDown with traffic id. diff --git a/src/wifi/model/mac-low.cc b/src/wifi/model/mac-low.cc index bd94c679b..ab3e1d3e3 100644 --- a/src/wifi/model/mac-low.cc +++ b/src/wifi/model/mac-low.cc @@ -475,7 +475,7 @@ MacLow::IsPromisc (void) const } void -MacLow::SetRxCallback (Callback, const WifiMacHeader *> callback) +MacLow::SetRxCallback (Callback> callback) { m_rxCallback = callback; } @@ -783,7 +783,7 @@ MacLow::ReceiveOk (Ptr mpdu, double rxSnr, WifiTxVector txVect * we handle any packet present in the * packet queue. */ - WifiMacHeader hdr = mpdu->GetHeader (); + const WifiMacHeader& hdr = mpdu->GetHeader (); Ptr packet = mpdu->GetPacket ()->Copy (); bool isPrevNavZero = IsNavZero (); @@ -1026,7 +1026,7 @@ MacLow::ReceiveOk (Ptr mpdu, double rxSnr, WifiTxVector txVect } m_stationManager->ReportRxOk (hdr.GetAddr2 (), &hdr, rxSnr, txVector.GetMode ()); - if (hdr.IsQosData () && ReceiveMpdu (packet, hdr)) + if (hdr.IsQosData () && ReceiveMpdu (mpdu)) { /* From section 9.10.4 in IEEE 802.11: Upon the receipt of a QoS data frame from the originator for which @@ -1090,6 +1090,7 @@ MacLow::ReceiveOk (Ptr mpdu, double rxSnr, WifiTxVector txVect SnrTag tag; tag.Set (rxSnr); packet->AddPacketTag (tag); + mpdu = Create (packet, hdr); } if (hdr.IsMgt () && ampduSubframe) { @@ -1137,6 +1138,7 @@ MacLow::ReceiveOk (Ptr mpdu, double rxSnr, WifiTxVector txVect SnrTag tag; tag.Set (rxSnr); packet->AddPacketTag (tag); + mpdu = Create (packet, hdr); } goto rxPacket; } @@ -1168,7 +1170,7 @@ rxPacket: NS_ASSERT (m_currentTxop != 0); m_currentTxop->GotAck (); } - m_rxCallback (packet, &hdr); + m_rxCallback (mpdu); return; } @@ -2148,8 +2150,10 @@ MacLow::SendAckAfterData (Mac48Address source, Time duration, WifiMode dataTxMod } bool -MacLow::ReceiveMpdu (Ptr packet, WifiMacHeader hdr) +MacLow::ReceiveMpdu (Ptr mpdu) { + const WifiMacHeader& hdr = mpdu->GetHeader (); + if (m_stationManager->GetHtSupported () || m_stationManager->GetVhtSupported () || m_stationManager->GetHeSupported ()) @@ -2167,7 +2171,7 @@ MacLow::ReceiveMpdu (Ptr packet, WifiMacHeader hdr) //Implement HT immediate Block Ack support for HT Delayed Block Ack is not added yet if (!QosUtilsIsOldPacket ((*it).second.first.GetStartingSequence (), seqNumber)) { - StoreMpduIfNeeded (packet, hdr); + StoreMpduIfNeeded (mpdu); if (!IsInWindow (hdr.GetSequenceNumber (), (*it).second.first.GetStartingSequence (), (*it).second.first.GetBufferSize ())) { uint16_t delta = (seqNumber - (*it).second.first.GetWinEnd () + 4096) % 4096; @@ -2183,26 +2187,26 @@ MacLow::ReceiveMpdu (Ptr packet, WifiMacHeader hdr) } return false; } - return StoreMpduIfNeeded (packet, hdr); + return StoreMpduIfNeeded (mpdu); } bool -MacLow::StoreMpduIfNeeded (Ptr packet, WifiMacHeader hdr) +MacLow::StoreMpduIfNeeded (Ptr mpdu) { + const WifiMacHeader& hdr = mpdu->GetHeader (); + AgreementsI it = m_bAckAgreements.find (std::make_pair (hdr.GetAddr2 (), hdr.GetQosTid ())); if (it != m_bAckAgreements.end ()) { - BufferedPacket bufferedPacket (packet, hdr); - uint16_t endSequence = ((*it).second.first.GetStartingSequence () + 2047) % 4096; uint32_t mappedSeqControl = QosUtilsMapSeqControlToUniqueInteger (hdr.GetSequenceControl (), endSequence); BufferedPacketI i = (*it).second.second.begin (); for (; i != (*it).second.second.end () - && QosUtilsMapSeqControlToUniqueInteger ((*i).second.GetSequenceControl (), endSequence) < mappedSeqControl; i++) + && QosUtilsMapSeqControlToUniqueInteger ((*i)->GetHeader ().GetSequenceControl (), endSequence) < mappedSeqControl; i++) { } - (*it).second.second.insert (i, bufferedPacket); + (*it).second.second.insert (i, mpdu); //Update block ack cache BlockAckCachesI j = m_bAckCaches.find (std::make_pair (hdr.GetAddr2 (), hdr.GetQosTid ())); @@ -2233,7 +2237,7 @@ MacLow::CreateBlockAckAgreement (const MgtAddBaResponseHeader *respHdr, Mac48Add agreement.SetTimeout (respHdr->GetTimeout ()); agreement.SetStartingSequence (startingSeq); - std::list buffer (0); + std::list> buffer (0); AgreementKey key (originator, respHdr->GetTid ()); AgreementValue value (agreement, buffer); m_bAckAgreements.insert (std::make_pair (key, value)); @@ -2283,31 +2287,31 @@ MacLow::RxCompleteBufferedPacketsWithSmallerSequence (uint16_t seq, Mac48Address uint16_t guard = 0; if (last != (*it).second.second.end ()) { - guard = (*it).second.second.begin ()->second.GetSequenceControl (); + guard = (*(*it).second.second.begin ())->GetHeader ().GetSequenceControl (); } BufferedPacketI i = (*it).second.second.begin (); for (; i != (*it).second.second.end () - && QosUtilsMapSeqControlToUniqueInteger ((*i).second.GetSequenceControl (), endSequence) < mappedStart; ) + && QosUtilsMapSeqControlToUniqueInteger ((*i)->GetHeader ().GetSequenceControl (), endSequence) < mappedStart; ) { - if (guard == (*i).second.GetSequenceControl ()) + if (guard == (*i)->GetHeader ().GetSequenceControl ()) { - if (!(*i).second.IsMoreFragments ()) + if (!(*i)->GetHeader ().IsMoreFragments ()) { while (last != i) { - m_rxCallback ((*last).first, &(*last).second); + m_rxCallback (*last); last++; } - m_rxCallback ((*last).first, &(*last).second); + m_rxCallback (*last); last++; /* go to next packet */ - while (i != (*it).second.second.end () && guard == (*i).second.GetSequenceControl ()) + while (i != (*it).second.second.end () && guard == (*i)->GetHeader ().GetSequenceControl ()) { i++; } if (i != (*it).second.second.end ()) { - guard = (*i).second.GetSequenceControl (); + guard = (*i)->GetHeader ().GetSequenceControl (); last = i; } } @@ -2319,13 +2323,13 @@ MacLow::RxCompleteBufferedPacketsWithSmallerSequence (uint16_t seq, Mac48Address else { /* go to next packet */ - while (i != (*it).second.second.end () && guard == (*i).second.GetSequenceControl ()) + while (i != (*it).second.second.end () && guard == (*i)->GetHeader ().GetSequenceControl ()) { i++; } if (i != (*it).second.second.end ()) { - guard = (*i).second.GetSequenceControl (); + guard = (*i)->GetHeader ().GetSequenceControl (); last = i; } } @@ -2343,19 +2347,19 @@ MacLow::RxCompleteBufferedPacketsUntilFirstLost (Mac48Address originator, uint8_ uint16_t guard = (*it).second.first.GetStartingSequenceControl (); BufferedPacketI lastComplete = (*it).second.second.begin (); BufferedPacketI i = (*it).second.second.begin (); - for (; i != (*it).second.second.end () && guard == (*i).second.GetSequenceControl (); i++) + for (; i != (*it).second.second.end () && guard == (*i)->GetHeader ().GetSequenceControl (); i++) { - if (!(*i).second.IsMoreFragments ()) + if (!(*i)->GetHeader ().IsMoreFragments ()) { while (lastComplete != i) { - m_rxCallback ((*lastComplete).first, &(*lastComplete).second); + m_rxCallback (*lastComplete); lastComplete++; } - m_rxCallback ((*lastComplete).first, &(*lastComplete).second); + m_rxCallback (*lastComplete); lastComplete++; } - guard = (*i).second.IsMoreFragments () ? (guard + 1) : ((guard + 16) & 0xfff0); + guard = (*i)->GetHeader ().IsMoreFragments () ? (guard + 1) : ((guard + 16) & 0xfff0); } (*it).second.first.SetStartingSequenceControl (guard); /* All packets already forwarded to WifiMac must be removed from buffer: diff --git a/src/wifi/model/mac-low.h b/src/wifi/model/mac-low.h index e96f16749..2431cdec4 100644 --- a/src/wifi/model/mac-low.h +++ b/src/wifi/model/mac-low.h @@ -63,7 +63,7 @@ public: /** * typedef for a callback for MacLowRx */ - typedef Callback, const WifiMacHeader*> MacLowRxCallback; + typedef Callback> MacLowRxCallback; MacLow (); virtual ~MacLow (); @@ -270,7 +270,7 @@ public: * This callback typically forwards incoming packets to * an instance of ns3::MacRxMiddle. */ - void SetRxCallback (Callback,const WifiMacHeader *> callback); + void SetRxCallback (Callback> callback); /** * \param dcf listen to NAV events for every incoming and outgoing packet. */ @@ -813,18 +813,16 @@ private: */ void RxCompleteBufferedPacketsUntilFirstLost (Mac48Address originator, uint8_t tid); /** - * \param packet the packet - * \param hdr the header + * \param mpdu the MPDU * \returns true if MPDU received * * This method updates the reorder buffer and the scoreboard when an MPDU is received in an HT station * and stores the MPDU if needed when an MPDU is received in an non-HT Station (implements HT * immediate block Ack) */ - bool ReceiveMpdu (Ptr packet, WifiMacHeader hdr); + bool ReceiveMpdu (Ptr mpdu); /** - * \param packet the packet - * \param hdr the header + * \param mpdu the MPDU * \returns true if the MPDU stored * * This method checks if exists a valid established block ack agreement. @@ -832,7 +830,7 @@ private: * in order of increasing sequence control field. All comparison are performed * circularly modulo 2^12. */ - bool StoreMpduIfNeeded (Ptr packet, WifiMacHeader hdr); + bool StoreMpduIfNeeded (Ptr mpdu); /** * Invoked after that a block ack request has been received. Looks for corresponding * block ack agreement and creates block ack bitmap on a received packets basis. @@ -961,11 +959,10 @@ private: /* * BlockAck data structures. */ - typedef std::pair, WifiMacHeader> BufferedPacket; //!< buffered packet typedef - typedef std::list::iterator BufferedPacketI; //!< buffered packet iterator typedef + typedef std::list>::iterator BufferedPacketI; //!< buffered packet iterator typedef typedef std::pair AgreementKey; //!< agreement key typedef - typedef std::pair > AgreementValue; //!< agreement value typedef + typedef std::pair> > AgreementValue; //!< agreement value typedef typedef std::map Agreements; //!< agreements typedef std::map::iterator AgreementsI; //!< agreements iterator diff --git a/src/wifi/model/mac-rx-middle.cc b/src/wifi/model/mac-rx-middle.cc index 110d23e30..d370eb2d0 100644 --- a/src/wifi/model/mac-rx-middle.cc +++ b/src/wifi/model/mac-rx-middle.cc @@ -22,7 +22,7 @@ #include "ns3/sequence-number.h" #include "ns3/packet.h" #include "mac-rx-middle.h" -#include "wifi-mac-header.h" +#include "wifi-mac-queue-item.h" namespace ns3 { @@ -296,9 +296,11 @@ MacRxMiddle::HandleFragments (Ptr packet, const WifiMacHeader *hdr, } void -MacRxMiddle::Receive (Ptr packet, const WifiMacHeader *hdr) +MacRxMiddle::Receive (Ptr mpdu) { - NS_LOG_FUNCTION (packet << hdr); + NS_LOG_FUNCTION (*mpdu); + const WifiMacHeader* hdr = &mpdu->GetHeader (); + Ptr packet = mpdu->GetPacket ()->Copy (); NS_ASSERT (hdr->IsData () || hdr->IsMgt ()); if (!m_pcfCallback.IsNull ()) { @@ -339,7 +341,18 @@ MacRxMiddle::Receive (Ptr packet, const WifiMacHeader *hdr) { originator->SetSequenceControl (hdr->GetSequenceControl ()); } - m_callback (aggregate, hdr); + if (aggregate == packet) + { + m_callback (mpdu); + } + else + { + // We could do this in all cases, but passing the received mpdu in case of + // A-MSDUs saves us the time to deaggregate the A-MSDU in MSDUs (which are + // kept separate in the received mpdu) and allows us to pass the originally + // transmitted packets (i.e., with the same UID) to the receiver. + m_callback (Create (aggregate, *hdr)); + } } void diff --git a/src/wifi/model/mac-rx-middle.h b/src/wifi/model/mac-rx-middle.h index 3fb708ffd..f61ab11cf 100644 --- a/src/wifi/model/mac-rx-middle.h +++ b/src/wifi/model/mac-rx-middle.h @@ -31,6 +31,7 @@ class WifiMacHeader; class OriginatorRxStatus; class Packet; class Mac48Address; +class WifiMacQueueItem; /** * \ingroup wifi @@ -43,7 +44,7 @@ public: /** * typedef for callback */ - typedef Callback, const WifiMacHeader*> ForwardUpCallback; + typedef Callback> ForwardUpCallback; MacRxMiddle (); ~MacRxMiddle (); @@ -65,10 +66,9 @@ public: /** * Receive a packet. * - * \param packet the packet - * \param hdr MAC header + * \param mpdu the MPDU */ - void Receive (Ptr packet, const WifiMacHeader *hdr); + void Receive (Ptr mpdu); private: diff --git a/src/wifi/model/regular-wifi-mac.cc b/src/wifi/model/regular-wifi-mac.cc index 23044faa6..3748dd757 100644 --- a/src/wifi/model/regular-wifi-mac.cc +++ b/src/wifi/model/regular-wifi-mac.cc @@ -857,10 +857,12 @@ RegularWifiMac::ForwardUp (Ptr packet, Mac48Address from, Mac48Address t } void -RegularWifiMac::Receive (Ptr packet, const WifiMacHeader *hdr) +RegularWifiMac::Receive (Ptr mpdu) { - NS_LOG_FUNCTION (this << packet << hdr); + NS_LOG_FUNCTION (this << *mpdu); + const WifiMacHeader* hdr = &mpdu->GetHeader (); + Ptr packet = mpdu->GetPacket ()->Copy (); Mac48Address to = hdr->GetAddr1 (); Mac48Address from = hdr->GetAddr2 (); @@ -955,15 +957,13 @@ RegularWifiMac::Receive (Ptr packet, const WifiMacHeader *hdr) } void -RegularWifiMac::DeaggregateAmsduAndForward (Ptr aggregatedPacket, const WifiMacHeader *hdr) +RegularWifiMac::DeaggregateAmsduAndForward (Ptr mpdu) { - NS_LOG_FUNCTION (this << aggregatedPacket << hdr); - MsduAggregator::DeaggregatedMsdus packets = MsduAggregator::Deaggregate (aggregatedPacket); - for (MsduAggregator::DeaggregatedMsdusCI i = packets.begin (); - i != packets.end (); ++i) + NS_LOG_FUNCTION (this << *mpdu); + for (auto& msduPair : *PeekPointer (mpdu)) { - ForwardUp ((*i).first, (*i).second.GetSourceAddr (), - (*i).second.GetDestinationAddr ()); + ForwardUp (msduPair.first, msduPair.second.GetSourceAddr (), + msduPair.second.GetDestinationAddr ()); } } diff --git a/src/wifi/model/regular-wifi-mac.h b/src/wifi/model/regular-wifi-mac.h index ffb223695..33bc9b979 100644 --- a/src/wifi/model/regular-wifi-mac.h +++ b/src/wifi/model/regular-wifi-mac.h @@ -389,10 +389,9 @@ protected: * classes so that they can perform their data handling before * invoking the base version. * - * \param packet the packet that has been received. - * \param hdr a pointer to the MAC header of the received frame. + * \param mpdu the MPDU that has been received. */ - virtual void Receive (Ptr packet, const WifiMacHeader *hdr); + virtual void Receive (Ptr mpdu); /** * The packet we sent was successfully received by the receiver * (i.e. we received an ACK from the receiver). @@ -421,11 +420,9 @@ protected: * This method can be called to de-aggregate an A-MSDU and forward * the constituent packets up the stack. * - * \param aggregatedPacket the Packet containing the A-MSDU. - * \param hdr a pointer to the MAC header for \c aggregatedPacket. + * \param mpdu the MPDU containing the A-MSDU. */ - virtual void DeaggregateAmsduAndForward (Ptr aggregatedPacket, - const WifiMacHeader *hdr); + virtual void DeaggregateAmsduAndForward (Ptr mpdu); /** * This method can be called to accept a received ADDBA Request. An diff --git a/src/wifi/model/sta-wifi-mac.cc b/src/wifi/model/sta-wifi-mac.cc index 843af034a..b50ce7914 100644 --- a/src/wifi/model/sta-wifi-mac.cc +++ b/src/wifi/model/sta-wifi-mac.cc @@ -502,9 +502,13 @@ StaWifiMac::Enqueue (Ptr packet, Mac48Address to) } void -StaWifiMac::Receive (Ptr packet, const WifiMacHeader *hdr) +StaWifiMac::Receive (Ptr mpdu) { - NS_LOG_FUNCTION (this << packet << hdr); + NS_LOG_FUNCTION (this << *mpdu); + const WifiMacHeader* hdr = &mpdu->GetHeader (); + // Create a copy of the MPDU payload because non-const operations like RemovePacketTag + // and RemoveHeader may need to be performed. + Ptr packet = mpdu->GetPacket ()->Copy (); NS_ASSERT (!hdr->IsCtl ()); if (hdr->GetAddr3 () == GetAddress ()) { @@ -547,7 +551,7 @@ StaWifiMac::Receive (Ptr packet, const WifiMacHeader *hdr) if (hdr->IsQosAmsdu ()) { NS_ASSERT (hdr->GetAddr3 () == GetBssid ()); - DeaggregateAmsduAndForward (packet, hdr); + DeaggregateAmsduAndForward (mpdu); packet = 0; } else @@ -712,7 +716,7 @@ StaWifiMac::Receive (Ptr packet, const WifiMacHeader *hdr) //Invoke the receive handler of our parent class to deal with any //other frames. Specifically, this will handle Block Ack-related //Management Action frames. - RegularWifiMac::Receive (packet, hdr); + RegularWifiMac::Receive (Create (packet, *hdr)); } void diff --git a/src/wifi/model/sta-wifi-mac.h b/src/wifi/model/sta-wifi-mac.h index 71e21a5f6..48ee42229 100644 --- a/src/wifi/model/sta-wifi-mac.h +++ b/src/wifi/model/sta-wifi-mac.h @@ -187,10 +187,9 @@ private: /** * Handle a received packet. * - * \param packet the received packet - * \param hdr the MAC header of the received packet + * \param mpdu the received MPDU */ - void Receive (Ptr packet, const WifiMacHeader *hdr); + void Receive (Ptr mpdu); /** * Update associated AP's information from beacon. If STA is not associated, * this information will used for the association process.