src/wifi/model/mpdu-standard-aggregator.cc
changeset 11174 780a43e4980c
child 11245 5c781d7e5a25
equal deleted inserted replaced
11173:9b4c47e6c37e 11174:780a43e4980c
       
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
       
     2 /*
       
     3  * Copyright (c) 2013
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License version 2 as
       
     7  * published by the Free Software Foundation;
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    17  *
       
    18  * Author: Ghada Badawy <gbadawy@gmail.com>
       
    19  */
       
    20 #include "ns3/log.h"
       
    21 #include "ns3/uinteger.h"
       
    22 
       
    23 #include "ampdu-subframe-header.h"
       
    24 #include "mpdu-standard-aggregator.h"
       
    25 
       
    26 NS_LOG_COMPONENT_DEFINE ("MpduStandardAggregator");
       
    27 
       
    28 namespace ns3 {
       
    29 
       
    30 NS_OBJECT_ENSURE_REGISTERED (MpduStandardAggregator);
       
    31 
       
    32 TypeId
       
    33 MpduStandardAggregator::GetTypeId (void)
       
    34 {
       
    35   static TypeId tid = TypeId ("ns3::MpduStandardAggregator")
       
    36     .SetParent<MpduAggregator> ()
       
    37     .AddConstructor<MpduStandardAggregator> ()
       
    38     .AddAttribute ("MaxAmpduSize", "Max length in bytes of an A-MPDU",
       
    39                    UintegerValue (65535),
       
    40                    MakeUintegerAccessor (&MpduStandardAggregator::m_maxAmpduLength),
       
    41                    MakeUintegerChecker<uint32_t> ())
       
    42   ;
       
    43   return tid;
       
    44 }
       
    45 
       
    46 MpduStandardAggregator::MpduStandardAggregator ()
       
    47 {
       
    48 }
       
    49 
       
    50 MpduStandardAggregator::~MpduStandardAggregator ()
       
    51 {
       
    52 }
       
    53 
       
    54 bool
       
    55 MpduStandardAggregator::Aggregate (Ptr<const Packet> packet, Ptr<Packet> aggregatedPacket)
       
    56 {
       
    57   NS_LOG_FUNCTION (this);
       
    58   Ptr<Packet> currentPacket;
       
    59   AmpduSubframeHeader currentHdr;
       
    60 
       
    61   uint32_t padding = CalculatePadding (aggregatedPacket);
       
    62   uint32_t actualSize = aggregatedPacket->GetSize ();
       
    63 
       
    64   if ((4 + packet->GetSize () + actualSize + padding) <= m_maxAmpduLength)
       
    65     {
       
    66       if (padding)
       
    67         {
       
    68           Ptr<Packet> pad = Create<Packet> (padding);
       
    69           aggregatedPacket->AddAtEnd (pad);
       
    70         }
       
    71       currentHdr.SetCrc (1);
       
    72       currentHdr.SetSig ();
       
    73       currentHdr.SetLength (packet->GetSize ());
       
    74       currentPacket = packet->Copy ();
       
    75 
       
    76       currentPacket->AddHeader (currentHdr);
       
    77       aggregatedPacket->AddAtEnd (currentPacket);
       
    78       return true;
       
    79     }
       
    80   return false;
       
    81 }
       
    82 
       
    83 void
       
    84 MpduStandardAggregator::AddHeaderAndPad (Ptr<Packet> packet, bool last)
       
    85 {
       
    86   NS_LOG_FUNCTION (this);
       
    87   AmpduSubframeHeader currentHdr;
       
    88   //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
       
    89   //done before when deciding how many packets to add to the queue
       
    90   currentHdr.SetCrc (1);
       
    91   currentHdr.SetSig ();
       
    92   currentHdr.SetLength (packet->GetSize ());
       
    93   packet->AddHeader (currentHdr);
       
    94   uint32_t padding = CalculatePadding (packet);
       
    95 
       
    96   if (padding && !last)
       
    97     {
       
    98       Ptr<Packet> pad = Create<Packet> (padding);
       
    99       packet->AddAtEnd (pad);
       
   100     }
       
   101 }
       
   102 
       
   103 bool
       
   104 MpduStandardAggregator::CanBeAggregated (uint32_t packetSize, Ptr<Packet> aggregatedPacket, uint8_t blockAckSize)
       
   105 {
       
   106   uint32_t padding = CalculatePadding (aggregatedPacket);
       
   107   uint32_t actualSize = aggregatedPacket->GetSize ();
       
   108   if (blockAckSize > 0)
       
   109     {
       
   110       blockAckSize = blockAckSize + 4 + padding;
       
   111     }
       
   112   if ((4 + packetSize + actualSize + padding + blockAckSize) <= m_maxAmpduLength)
       
   113     {
       
   114       return true;
       
   115     }
       
   116   else
       
   117     {
       
   118       return false;
       
   119     }
       
   120 }
       
   121 
       
   122 uint32_t
       
   123 MpduStandardAggregator::CalculatePadding (Ptr<const Packet> packet)
       
   124 {
       
   125   return (4 - (packet->GetSize () % 4 )) % 4;
       
   126 }
       
   127 
       
   128 }  // namespace ns3