A Discrete-Event Network Simulator
API
mpdu-standard-aggregator.cc
Go to the documentation of this file.
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"
25 
26 NS_LOG_COMPONENT_DEFINE ("MpduStandardAggregator");
27 
28 namespace ns3 {
29 
30 NS_OBJECT_ENSURE_REGISTERED (MpduStandardAggregator);
31 
32 TypeId
34 {
35  static TypeId tid = TypeId ("ns3::MpduStandardAggregator")
37  .SetGroupName ("Wifi")
38  .AddConstructor<MpduStandardAggregator> ()
39  .AddAttribute ("MaxAmpduSize", "Max length in bytes of an A-MPDU",
40  UintegerValue (65535),
42  MakeUintegerChecker<uint32_t> ())
43  ;
44  return tid;
45 }
46 
48 {
49 }
50 
52 {
53 }
54 
55 bool
57 {
58  NS_LOG_FUNCTION (this);
59  Ptr<Packet> currentPacket;
60  AmpduSubframeHeader currentHdr;
61 
62  uint32_t padding = CalculatePadding (aggregatedPacket);
63  uint32_t actualSize = aggregatedPacket->GetSize ();
64 
65  if ((4 + packet->GetSize () + actualSize + padding) <= m_maxAmpduLength)
66  {
67  if (padding)
68  {
69  Ptr<Packet> pad = Create<Packet> (padding);
70  aggregatedPacket->AddAtEnd (pad);
71  }
72  currentHdr.SetCrc (1);
73  currentHdr.SetSig ();
74  currentHdr.SetLength (packet->GetSize ());
75  currentPacket = packet->Copy ();
76 
77  currentPacket->AddHeader (currentHdr);
78  aggregatedPacket->AddAtEnd (currentPacket);
79  return true;
80  }
81  return false;
82 }
83 
84 void
86 {
87  NS_LOG_FUNCTION (this);
88  AmpduSubframeHeader currentHdr;
89  //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
90  //done before when deciding how many packets to add to the queue
91  currentHdr.SetCrc (1);
92  currentHdr.SetSig ();
93  currentHdr.SetLength (packet->GetSize ());
94  packet->AddHeader (currentHdr);
95  uint32_t padding = CalculatePadding (packet);
96 
97  if (padding && !last)
98  {
99  Ptr<Packet> pad = Create<Packet> (padding);
100  packet->AddAtEnd (pad);
101  }
102 }
103 
104 bool
105 MpduStandardAggregator::CanBeAggregated (uint32_t packetSize, Ptr<Packet> aggregatedPacket, uint8_t blockAckSize)
106 {
107  uint32_t padding = CalculatePadding (aggregatedPacket);
108  uint32_t actualSize = aggregatedPacket->GetSize ();
109  if (blockAckSize > 0)
110  {
111  blockAckSize = blockAckSize + 4 + padding;
112  }
113  if ((4 + packetSize + actualSize + padding + blockAckSize) <= m_maxAmpduLength)
114  {
115  return true;
116  }
117  else
118  {
119  return false;
120  }
121 }
122 
123 uint32_t
125 {
126  return (4 - (packet->GetSize () % 4 )) % 4;
127 }
128 
129 } // namespace ns3
Abstract class that concrete mpdu aggregators have to implement.
void SetSig()
Set the SIG field.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
virtual bool Aggregate(Ptr< const Packet > packet, Ptr< Packet > aggregatedPacket)
uint32_t m_maxAmpduLength
Maximum length in bytes of A-MPDUs.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:766
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
Definition: packet.cc:317
Hold an unsigned integer type.
Definition: uinteger.h:44
void SetCrc(uint8_t crc)
Set the CRC field.
Introspection did not find any typical Config paths.
virtual void AddHeaderAndPad(Ptr< Packet > packet, bool last)
Adds A-MPDU subframe header and padding to each MPDU that is part of an A-MPDU before it is sent...
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:122
void SetLength(uint16_t length)
Set the length field.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Standard MPDU aggregator.
virtual uint32_t CalculatePadding(Ptr< const Packet > packet)
virtual bool CanBeAggregated(uint32_t packetSize, Ptr< Packet > aggregatedPacket, uint8_t blockAckSize)
static const uint32_t packetSize
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
a unique identifier for an interface.
Definition: type-id.h:57
TypeId SetParent(TypeId tid)
Definition: type-id.cc:638
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:253