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",
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  Ptr<Packet> currentPacket;
89  AmpduSubframeHeader currentHdr;
90 
91  uint32_t padding = CalculatePadding (aggregatedPacket);
92  if (padding)
93  {
94  Ptr<Packet> pad = Create<Packet> (padding);
95  aggregatedPacket->AddAtEnd (pad);
96  }
97 
98  currentHdr.SetEof (1);
99  currentHdr.SetCrc (1);
100  currentHdr.SetSig ();
101  currentHdr.SetLength (packet->GetSize ());
102  currentPacket = packet->Copy ();
103 
104  currentPacket->AddHeader (currentHdr);
105  aggregatedPacket->AddAtEnd (currentPacket);
106 }
107 
108 void
109 MpduStandardAggregator::AddHeaderAndPad (Ptr<Packet> packet, bool last, bool vhtSingleMpdu)
110 {
111  NS_LOG_FUNCTION (this);
112  AmpduSubframeHeader currentHdr;
113 
114  //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
115  //done before when deciding how many packets to add to the queue
116  currentHdr.SetCrc (1);
117  currentHdr.SetSig ();
118  currentHdr.SetLength (packet->GetSize ());
119  if (vhtSingleMpdu)
120  {
121  currentHdr.SetEof (1);
122  }
123 
124  packet->AddHeader (currentHdr);
125  uint32_t padding = CalculatePadding (packet);
126 
127  if (padding && !last)
128  {
129  Ptr<Packet> pad = Create<Packet> (padding);
130  packet->AddAtEnd (pad);
131  }
132 }
133 
134 bool
135 MpduStandardAggregator::CanBeAggregated (uint32_t packetSize, Ptr<Packet> aggregatedPacket, uint8_t blockAckSize)
136 {
137  uint32_t padding = CalculatePadding (aggregatedPacket);
138  uint32_t actualSize = aggregatedPacket->GetSize ();
139  if (blockAckSize > 0)
140  {
141  blockAckSize = blockAckSize + 4 + padding;
142  }
143  if ((4 + packetSize + actualSize + padding + blockAckSize) <= m_maxAmpduLength)
144  {
145  return true;
146  }
147  else
148  {
149  return false;
150  }
151 }
152 
153 uint32_t
155 {
156  return (4 - (packet->GetSize () % 4 )) % 4;
157 }
158 
159 } //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:786
virtual void AggregateVhtSingleMpdu(Ptr< const Packet > packet, Ptr< Packet > aggregatedPacket)
This method performs a VHT single MPDU aggregation.
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:311
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:826
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:255