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"
24 
25 NS_LOG_COMPONENT_DEFINE ("MpduStandardAggregator");
26 
27 namespace ns3 {
28 
29 NS_OBJECT_ENSURE_REGISTERED (MpduStandardAggregator);
30 
31 TypeId
33 {
34  static TypeId tid = TypeId ("ns3::MpduStandardAggregator")
36  .SetGroupName ("Wifi")
37  .AddConstructor<MpduStandardAggregator> ()
38  .AddAttribute ("MaxAmpduSize", "Max length in bytes of an A-MPDU (Deprecated!)",
39  UintegerValue (65535),
41  MakeUintegerChecker<uint32_t> ())
42  ;
43  return tid;
44 }
45 
47 {
48 }
49 
51 {
52 }
53 
54 void
56 {
57  m_maxAmpduLength = maxSize;
58 }
59 
60 uint32_t
62 {
63  return m_maxAmpduLength;
64 }
65 
66 bool
68 {
69  NS_LOG_FUNCTION (this);
70  Ptr<Packet> currentPacket;
71  AmpduSubframeHeader currentHdr;
72 
73  uint32_t padding = CalculatePadding (aggregatedPacket);
74  uint32_t actualSize = aggregatedPacket->GetSize ();
75 
76  if ((4 + packet->GetSize () + actualSize + padding) <= m_maxAmpduLength)
77  {
78  if (padding)
79  {
80  Ptr<Packet> pad = Create<Packet> (padding);
81  aggregatedPacket->AddAtEnd (pad);
82  }
83  currentHdr.SetCrc (1);
84  currentHdr.SetSig ();
85  currentHdr.SetLength (packet->GetSize ());
86  currentPacket = packet->Copy ();
87 
88  currentPacket->AddHeader (currentHdr);
89  aggregatedPacket->AddAtEnd (currentPacket);
90  return true;
91  }
92  return false;
93 }
94 
95 void
97 {
98  NS_LOG_FUNCTION (this);
99  Ptr<Packet> currentPacket;
100  AmpduSubframeHeader currentHdr;
101 
102  uint32_t padding = CalculatePadding (aggregatedPacket);
103  if (padding)
104  {
105  Ptr<Packet> pad = Create<Packet> (padding);
106  aggregatedPacket->AddAtEnd (pad);
107  }
108 
109  currentHdr.SetEof (1);
110  currentHdr.SetCrc (1);
111  currentHdr.SetSig ();
112  currentHdr.SetLength (packet->GetSize ());
113  currentPacket = packet->Copy ();
114 
115  currentPacket->AddHeader (currentHdr);
116  aggregatedPacket->AddAtEnd (currentPacket);
117 }
118 
119 void
120 MpduStandardAggregator::AddHeaderAndPad (Ptr<Packet> packet, bool last, bool isSingleMpdu) const
121 {
122  NS_LOG_FUNCTION (this);
123  AmpduSubframeHeader currentHdr;
124 
125  //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
126  //done before when deciding how many packets to add to the queue
127  currentHdr.SetCrc (1);
128  currentHdr.SetSig ();
129  currentHdr.SetLength (packet->GetSize ());
130  if (isSingleMpdu)
131  {
132  currentHdr.SetEof (1);
133  }
134 
135  packet->AddHeader (currentHdr);
136  uint32_t padding = CalculatePadding (packet);
137 
138  if (padding && !last)
139  {
140  Ptr<Packet> pad = Create<Packet> (padding);
141  packet->AddAtEnd (pad);
142  }
143 }
144 
145 bool
146 MpduStandardAggregator::CanBeAggregated (uint32_t packetSize, Ptr<Packet> aggregatedPacket, uint8_t blockAckSize) const
147 {
148  uint32_t padding = CalculatePadding (aggregatedPacket);
149  uint32_t actualSize = aggregatedPacket->GetSize ();
150  if (blockAckSize > 0)
151  {
152  blockAckSize = blockAckSize + 4 + padding;
153  }
154  if ((4 + packetSize + actualSize + padding + blockAckSize) <= m_maxAmpduLength)
155  {
156  return true;
157  }
158  else
159  {
160  return false;
161  }
162 }
163 
164 uint32_t
166 {
167  return (4 - (packet->GetSize () % 4 )) % 4;
168 }
169 
170 } //namespace ns3
Abstract class that concrete mpdu aggregators have to implement.
void AggregateSingleMpdu(Ptr< const Packet > packet, Ptr< Packet > aggregatedPacket) const
void SetSig()
Set the SIG field.
void AddHeaderAndPad(Ptr< Packet > packet, bool last, bool isSingleMpdu) const
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void SetMaxAmpduSize(uint32_t maxSize)
Sets the maximum A-MPDU size in bytes.
bool Aggregate(Ptr< const Packet > packet, Ptr< Packet > aggregatedPacket) const
uint32_t m_maxAmpduLength
Maximum length in bytes of A-MPDUs.
uint32_t CalculatePadding(Ptr< const Packet > packet) const
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
static TypeId GetTypeId(void)
Get the type ID.
#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:796
uint32_t GetMaxAmpduSize(void) const
Returns the maximum A-MPDU size in bytes.
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
Definition: packet.cc:312
Hold an unsigned integer type.
Definition: uinteger.h:44
bool CanBeAggregated(uint32_t packetSize, Ptr< Packet > aggregatedPacket, uint8_t blockAckSize) const
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:121
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.
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:914
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256