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 
23 #include "msdu-aggregator.h"
24 #include "wifi-mac-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  ;
39  return tid;
40 }
41 
44 {
47 
49  Ptr<Packet> extractedMsdu = Create<Packet> ();
50  uint32_t maxSize = aggregatedPacket->GetSize ();
51  uint16_t extractedLength;
52  uint32_t padding;
53  uint32_t deserialized = 0;
54 
55  while (deserialized < maxSize)
56  {
57  deserialized += aggregatedPacket->RemoveHeader (hdr);
58  extractedLength = hdr.GetLength ();
59  extractedMsdu = aggregatedPacket->CreateFragment (0, static_cast<uint32_t> (extractedLength));
60  aggregatedPacket->RemoveAtStart (extractedLength);
61  deserialized += extractedLength;
62 
63  padding = (4 - ((extractedLength + 14) % 4 )) % 4;
64 
65  if (padding > 0 && deserialized < maxSize)
66  {
67  aggregatedPacket->RemoveAtStart (padding);
68  deserialized += padding;
69  }
70 
71  std::pair<Ptr<Packet>, AmsduSubframeHeader> packetHdr (extractedMsdu, hdr);
72  set.push_back (packetHdr);
73  }
74  NS_LOG_INFO ("Deaggreated A-MSDU: extracted " << set.size () << " MSDUs");
75  return set;
76 }
77 
78 } //namespace ns3
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:268
#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
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:244
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
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:228
void RemoveAtStart(uint32_t size)
Remove size bytes from the start of the current packet.
Definition: packet.cc:340
static TypeId GetTypeId(void)
std::list< std::pair< Ptr< Packet >, AmsduSubframeHeader > > DeaggregatedMsdus
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Introspection did not find any typical Config paths.
A base class which provides memory management and object aggregation.
Definition: object.h:87
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:904
uint16_t GetLength(void) const