diff -r 9b4c47e6c37e -r 780a43e4980c src/wifi/model/mpdu-standard-aggregator.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/wifi/model/mpdu-standard-aggregator.cc Wed Jan 28 10:11:32 2015 -0800 @@ -0,0 +1,128 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2013 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Ghada Badawy + */ +#include "ns3/log.h" +#include "ns3/uinteger.h" + +#include "ampdu-subframe-header.h" +#include "mpdu-standard-aggregator.h" + +NS_LOG_COMPONENT_DEFINE ("MpduStandardAggregator"); + +namespace ns3 { + +NS_OBJECT_ENSURE_REGISTERED (MpduStandardAggregator); + +TypeId +MpduStandardAggregator::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::MpduStandardAggregator") + .SetParent () + .AddConstructor () + .AddAttribute ("MaxAmpduSize", "Max length in bytes of an A-MPDU", + UintegerValue (65535), + MakeUintegerAccessor (&MpduStandardAggregator::m_maxAmpduLength), + MakeUintegerChecker ()) + ; + return tid; +} + +MpduStandardAggregator::MpduStandardAggregator () +{ +} + +MpduStandardAggregator::~MpduStandardAggregator () +{ +} + +bool +MpduStandardAggregator::Aggregate (Ptr packet, Ptr aggregatedPacket) +{ + NS_LOG_FUNCTION (this); + Ptr currentPacket; + AmpduSubframeHeader currentHdr; + + uint32_t padding = CalculatePadding (aggregatedPacket); + uint32_t actualSize = aggregatedPacket->GetSize (); + + if ((4 + packet->GetSize () + actualSize + padding) <= m_maxAmpduLength) + { + if (padding) + { + Ptr pad = Create (padding); + aggregatedPacket->AddAtEnd (pad); + } + currentHdr.SetCrc (1); + currentHdr.SetSig (); + currentHdr.SetLength (packet->GetSize ()); + currentPacket = packet->Copy (); + + currentPacket->AddHeader (currentHdr); + aggregatedPacket->AddAtEnd (currentPacket); + return true; + } + return false; +} + +void +MpduStandardAggregator::AddHeaderAndPad (Ptr packet, bool last) +{ + NS_LOG_FUNCTION (this); + AmpduSubframeHeader currentHdr; + //This is called to prepare packets from the aggregte queue to be sent so no need to check total size since it has already been + //done before when deciding how many packets to add to the queue + currentHdr.SetCrc (1); + currentHdr.SetSig (); + currentHdr.SetLength (packet->GetSize ()); + packet->AddHeader (currentHdr); + uint32_t padding = CalculatePadding (packet); + + if (padding && !last) + { + Ptr pad = Create (padding); + packet->AddAtEnd (pad); + } +} + +bool +MpduStandardAggregator::CanBeAggregated (uint32_t packetSize, Ptr aggregatedPacket, uint8_t blockAckSize) +{ + uint32_t padding = CalculatePadding (aggregatedPacket); + uint32_t actualSize = aggregatedPacket->GetSize (); + if (blockAckSize > 0) + { + blockAckSize = blockAckSize + 4 + padding; + } + if ((4 + packetSize + actualSize + padding + blockAckSize) <= m_maxAmpduLength) + { + return true; + } + else + { + return false; + } +} + +uint32_t +MpduStandardAggregator::CalculatePadding (Ptr packet) +{ + return (4 - (packet->GetSize () % 4 )) % 4; +} + +} // namespace ns3