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 
21 #include "ns3/log.h"
22 #include "ns3/uinteger.h"
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 (Deprecated!)",
40  UintegerValue (65535),
42  MakeUintegerChecker<uint32_t> ())
43  ;
44  return tid;
45 }
46 
48 {
49 }
50 
52 {
53 }
54 
55 void
57 {
58  m_maxAmpduLength = maxSize;
59 }
60 
61 uint32_t
63 {
64  return m_maxAmpduLength;
65 }
66 
67 bool
69 {
70  NS_LOG_FUNCTION (this);
71  Ptr<Packet> currentPacket;
72  AmpduSubframeHeader currentHdr;
73 
74  uint32_t padding = CalculatePadding (aggregatedPacket);
75  uint32_t actualSize = aggregatedPacket->GetSize ();
76 
77  if ((4 + packet->GetSize () + actualSize + padding) <= m_maxAmpduLength)
78  {
79  if (padding)
80  {
81  Ptr<Packet> pad = Create<Packet> (padding);
82  aggregatedPacket->AddAtEnd (pad);
83  }
84  currentHdr.SetCrc (1);
85  currentHdr.SetSig ();
86  currentHdr.SetLength (packet->GetSize ());
87  currentPacket = packet->Copy ();
88 
89  currentPacket->AddHeader (currentHdr);
90  aggregatedPacket->AddAtEnd (currentPacket);
91  return true;
92  }
93  return false;
94 }
95 
96 void
98 {
99  NS_LOG_FUNCTION (this);
100  Ptr<Packet> currentPacket;
101  AmpduSubframeHeader currentHdr;
102 
103  uint32_t padding = CalculatePadding (aggregatedPacket);
104  if (padding)
105  {
106  Ptr<Packet> pad = Create<Packet> (padding);
107  aggregatedPacket->AddAtEnd (pad);
108  }
109 
110  currentHdr.SetEof (1);
111  currentHdr.SetCrc (1);
112  currentHdr.SetSig ();
113  currentHdr.SetLength (packet->GetSize ());
114  currentPacket = packet->Copy ();
115 
116  currentPacket->AddHeader (currentHdr);
117  aggregatedPacket->AddAtEnd (currentPacket);
118 }
119 
120 void
121 MpduStandardAggregator::AddHeaderAndPad (Ptr<Packet> packet, bool last, bool vhtSingleMpdu)
122 {
123  NS_LOG_FUNCTION (this);
124  AmpduSubframeHeader currentHdr;
125 
126  //This is called to prepare packets from the aggregate queue to be sent so no need to check total size since it has already been
127  //done before when deciding how many packets to add to the queue
128  currentHdr.SetCrc (1);
129  currentHdr.SetSig ();
130  currentHdr.SetLength (packet->GetSize ());
131  if (vhtSingleMpdu)
132  {
133  currentHdr.SetEof (1);
134  }
135 
136  packet->AddHeader (currentHdr);
137  uint32_t padding = CalculatePadding (packet);
138 
139  if (padding && !last)
140  {
141  Ptr<Packet> pad = Create<Packet> (padding);
142  packet->AddAtEnd (pad);
143  }
144 }
145 
146 bool
147 MpduStandardAggregator::CanBeAggregated (uint32_t packetSize, Ptr<Packet> aggregatedPacket, uint8_t blockAckSize)
148 {
149  uint32_t padding = CalculatePadding (aggregatedPacket);
150  uint32_t actualSize = aggregatedPacket->GetSize ();
151  if (blockAckSize > 0)
152  {
153  blockAckSize = blockAckSize + 4 + padding;
154  }
155  if ((4 + packetSize + actualSize + padding + blockAckSize) <= m_maxAmpduLength)
156  {
157  return true;
158  }
159  else
160  {
161  return false;
162  }
163 }
164 
165 uint32_t
167 {
168  return (4 - (packet->GetSize () % 4 )) % 4;
169 }
170 
171 } //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 void SetMaxAmpduSize(uint32_t maxSize)
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:792
virtual void AggregateVhtSingleMpdu(Ptr< const Packet > packet, Ptr< Packet > aggregatedPacket)
This method performs a VHT single MPDU aggregation.
virtual uint32_t GetMaxAmpduSize(void) const
virtual void AddHeaderAndPad(Ptr< Packet > packet, bool last, bool vhtSingleMpdu)
Adds A-MPDU subframe header and padding to each MPDU that is part of an A-MPDU before it is sent...
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
Definition: packet.cc:313
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.
void SetEof(bool eof)
Set the EOF field.
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:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:904
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:257