A Discrete-Event Network Simulator
API
msdu-aggregator.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 MIRKO BANCHI
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: Mirko Banchi <mk.banchi@gmail.com>
19  */
20 
21 #include "ns3/log.h"
22 #include "ns3/packet.h"
23 #include "msdu-aggregator.h"
24 #include "amsdu-subframe-header.h"
25 
26 namespace ns3 {
27 
28 NS_LOG_COMPONENT_DEFINE ("MsduAggregator");
29 
30 NS_OBJECT_ENSURE_REGISTERED (MsduAggregator);
31 
32 TypeId
34 {
35  static TypeId tid = TypeId ("ns3::MsduAggregator")
36  .SetParent<Object> ()
37  .SetGroupName ("Wifi")
38  .AddConstructor<MsduAggregator> ()
39  ;
40  return tid;
41 }
42 
44 {
45 }
46 
48 {
49 }
50 
51 void
53 {
54  m_maxAmsduLength = maxSize;
55 }
56 
57 uint16_t
59 {
60  return m_maxAmsduLength;
61 }
62 
63 bool
65  Mac48Address src, Mac48Address dest) const
66 {
67  NS_LOG_FUNCTION (this);
68  Ptr<Packet> currentPacket;
69  AmsduSubframeHeader currentHdr;
70 
71  uint8_t padding = CalculatePadding (aggregatedPacket);
72  uint32_t actualSize = aggregatedPacket->GetSize ();
73 
74  if ((14 + packet->GetSize () + actualSize + padding) <= GetMaxAmsduSize ())
75  {
76  if (padding)
77  {
78  Ptr<Packet> pad = Create<Packet> (padding);
79  aggregatedPacket->AddAtEnd (pad);
80  }
81  currentHdr.SetDestinationAddr (dest);
82  currentHdr.SetSourceAddr (src);
83  currentHdr.SetLength (static_cast<uint16_t> (packet->GetSize ()));
84  currentPacket = packet->Copy ();
85 
86  currentPacket->AddHeader (currentHdr);
87  aggregatedPacket->AddAtEnd (currentPacket);
88  return true;
89  }
90  return false;
91 }
92 
93 uint8_t
95 {
96  return (4 - (packet->GetSize () % 4 )) % 4;
97 }
98 
101 {
103  DeaggregatedMsdus set;
104 
106  Ptr<Packet> extractedMsdu = Create<Packet> ();
107  uint32_t maxSize = aggregatedPacket->GetSize ();
108  uint16_t extractedLength;
109  uint8_t padding;
110  uint32_t deserialized = 0;
111 
112  while (deserialized < maxSize)
113  {
114  deserialized += aggregatedPacket->RemoveHeader (hdr);
115  extractedLength = hdr.GetLength ();
116  extractedMsdu = aggregatedPacket->CreateFragment (0, static_cast<uint32_t> (extractedLength));
117  aggregatedPacket->RemoveAtStart (extractedLength);
118  deserialized += extractedLength;
119 
120  padding = (4 - ((extractedLength + 14) % 4 )) % 4;
121 
122  if (padding > 0 && deserialized < maxSize)
123  {
124  aggregatedPacket->RemoveAtStart (padding);
125  deserialized += padding;
126  }
127 
128  std::pair<Ptr<Packet>, AmsduSubframeHeader> packetHdr (extractedMsdu, hdr);
129  set.push_back (packetHdr);
130  }
131  NS_LOG_INFO ("Deaggreated A-MSDU: extracted " << set.size () << " MSDUs");
132  return set;
133 }
134 
135 } //namespace ns3
uint16_t GetMaxAmsduSize(void) const
Returns the maximum A-MSDU size in bytes.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:831
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
Definition: packet.cc:227
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
static DeaggregatedMsdus Deaggregate(Ptr< Packet > aggregatedPacket)
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:278
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
void SetSourceAddr(Mac48Address to)
Set source address function.
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
Definition: packet.cc:335
void RemoveAtStart(uint32_t size)
Remove size bytes from the start of the current packet.
Definition: packet.cc:362
static TypeId GetTypeId(void)
Get the type ID.
void SetLength(uint16_t length)
Set length function.
std::list< std::pair< Ptr< Packet >, AmsduSubframeHeader > > DeaggregatedMsdus
DeaggregatedMsdus typedef.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
an EUI-48 address
Definition: mac48-address.h:43
Introspection did not find any typical Config paths.
void SetDestinationAddr(Mac48Address to)
Set destination address function.
uint16_t GetLength(void) const
Get length function.
uint8_t CalculatePadding(Ptr< const Packet > packet) const
Calculates how much padding must be added to the end of aggregated packet, after that a new packet is...
Aggregator used to construct A-MSDUs.
A base class which provides memory management and object aggregation.
Definition: object.h:87
bool Aggregate(Ptr< const Packet > packet, Ptr< Packet > aggregatedPacket, Mac48Address src, Mac48Address dest) const
Adds packet to aggregatedPacket.
a unique identifier for an interface.
Definition: type-id.h:58
uint16_t m_maxAmsduLength
maximum AMSDU length
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
void SetMaxAmsduSize(uint16_t maxSize)
Sets the maximum A-MSDU size in bytes.