# HG changeset patch # User Tom Henderson # Date 1496154716 25200 # Tue May 30 07:31:56 2017 -0700 # Node ID 32173758feb37e63087c07809e7398fd7e996b42 # Parent 1dd3e78828daf63596b6c0276907dc2316c01c17 enable deserialization of MeshInformationElementVector diff -r 1dd3e78828da -r 32173758feb3 src/mesh/model/dot11s/hwmp-protocol-mac.cc --- a/src/mesh/model/dot11s/hwmp-protocol-mac.cc Tue May 30 07:25:24 2017 -0700 +++ b/src/mesh/model/dot11s/hwmp-protocol-mac.cc Tue May 30 07:31:56 2017 -0700 @@ -108,7 +108,9 @@ return true; } MeshInformationElementVector elements; - packet->RemoveHeader (elements); + // To determine header size here, we can rely on the knowledge that + // this is the last header to remove. + packet->RemoveHeader (elements, packet->GetSize ()); std::vector failedDestinations; for (MeshInformationElementVector::Iterator i = elements.Begin (); i != elements.End (); i++) { diff -r 1dd3e78828da -r 32173758feb3 src/mesh/model/dot11s/peer-management-protocol-mac.cc --- a/src/mesh/model/dot11s/peer-management-protocol-mac.cc Tue May 30 07:25:24 2017 -0700 +++ b/src/mesh/model/dot11s/peer-management-protocol-mac.cc Tue May 30 07:31:56 2017 -0700 @@ -76,7 +76,9 @@ MgtBeaconHeader beacon_hdr; packet->RemoveHeader (beacon_hdr); MeshInformationElementVector elements; - packet->RemoveHeader (elements); + // To determine header size here, we can rely on the knowledge that + // this is the last header to remove. + packet->RemoveHeader (elements, packet->GetSize ()); Ptr beaconTiming = DynamicCast (elements.FindFirst (IE_BEACON_TIMING)); Ptr meshId = DynamicCast (elements.FindFirst (IE_MESH_ID)); @@ -174,9 +176,10 @@ NS_FATAL_ERROR ("Unknown Self-protected Action type: " << actionValue.selfProtectedAction); } Ptr peerElement; - //Peer Management element is the last element in this frame - so, we can use MeshInformationElementVector MeshInformationElementVector elements; - packet->RemoveHeader (elements); + // To determine header size here, we can rely on the knowledge that + // this is the last header to remove. + packet->RemoveHeader (elements, packet->GetSize ()); peerElement = DynamicCast(elements.FindFirst (IE_MESH_PEERING_MANAGEMENT)); NS_ASSERT (peerElement != 0); diff -r 1dd3e78828da -r 32173758feb3 src/mesh/test/mesh-information-element-vector-test-suite.cc --- a/src/mesh/test/mesh-information-element-vector-test-suite.cc Tue May 30 07:25:24 2017 -0700 +++ b/src/mesh/test/mesh-information-element-vector-test-suite.cc Tue May 30 07:31:56 2017 -0700 @@ -145,8 +145,9 @@ } Ptr packet = Create (); packet->AddHeader (vector); + uint32_t size = vector.GetSerializedSize (); MeshInformationElementVector resultVector; - packet->RemoveHeader (resultVector); + packet->RemoveHeader (resultVector, size); NS_TEST_ASSERT_MSG_EQ (vector, resultVector, "Roundtrip serialization of all known information elements works"); } diff -r 1dd3e78828da -r 32173758feb3 src/wifi/model/wifi-information-element-vector.cc --- a/src/wifi/model/wifi-information-element-vector.cc Tue May 30 07:25:24 2017 -0700 +++ b/src/wifi/model/wifi-information-element-vector.cc Tue May 30 07:31:56 2017 -0700 @@ -72,15 +72,22 @@ uint32_t WifiInformationElementVector::Deserialize (Buffer::Iterator start) { - Buffer::Iterator i = start; - uint32_t size = start.GetSize (); + NS_FATAL_ERROR ("This variant should not be called on a variable-sized header"); + return 0; +} + +uint32_t +WifiInformationElementVector::Deserialize (Buffer::Iterator start, Buffer::Iterator end) +{ + uint32_t size = start.GetDistanceFrom (end); while (size > 0) { - uint32_t deserialized = DeserializeSingleIe (i); - i.Next (deserialized); + uint32_t deserialized = DeserializeSingleIe (start); + start.Next (deserialized); + NS_ASSERT (deserialized <= size); size -= deserialized; } - return i.GetDistanceFrom (start); + return size; } uint32_t diff -r 1dd3e78828da -r 32173758feb3 src/wifi/model/wifi-information-element-vector.h --- a/src/wifi/model/wifi-information-element-vector.h Tue May 30 07:25:24 2017 -0700 +++ b/src/wifi/model/wifi-information-element-vector.h Tue May 30 07:31:56 2017 -0700 @@ -51,13 +51,23 @@ virtual uint32_t GetSerializedSize () const; virtual void Serialize (Buffer::Iterator start) const; /** - * \attention When you use RemoveHeader, WifiInformationElementVector supposes, that - * all buffer consists of information elements + * \attention This variant should not be used but is implemented due to + * backward compatibility reasons * - * \param start the iterator - * \returns distance + * \param start buffer location to start deserializing from + * \return number of bytes deserialized */ virtual uint32_t Deserialize (Buffer::Iterator start); + /** + * Deserialize a number of WifiInformationElements + * + * The size of this Header should equal start.GetDistanceFrom (end). + * + * \param start starting buffer location + * \param end ending buffer location + * \return number of bytes deserialized + */ + virtual uint32_t Deserialize (Buffer::Iterator start, Buffer::Iterator end); virtual void Print (std::ostream &os) const; /**