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  .AddConstructor<MpduStandardAggregator> ()
38  .AddAttribute ("MaxAmpduSize", "Max length in bytes of an A-MPDU",
39  UintegerValue (65535),
41  MakeUintegerChecker<uint32_t> ())
42  ;
43  return tid;
44 }
45 
47 {
48 }
49 
51 {
52 }
53 
54 bool
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
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
124 {
125  return (4 - (packet->GetSize () % 4 )) % 4;
126 }
127 
128 } // 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.
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:51
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:253