A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #include "ns3/log.h"
21 
22 #include "msdu-aggregator.h"
23 #include "wifi-mac-header.h"
24 
25 NS_LOG_COMPONENT_DEFINE ("MsduAggregator");
26 
27 namespace ns3 {
28 
29 NS_OBJECT_ENSURE_REGISTERED (MsduAggregator);
30 
31 TypeId
33 {
34  static TypeId tid = TypeId ("ns3::MsduAggregator")
35  .SetParent<Object> ()
36  ;
37  return tid;
38 }
39 
42 {
45 
47  Ptr<Packet> extractedMsdu = Create<Packet> ();
48  uint32_t maxSize = aggregatedPacket->GetSize ();
49  uint16_t extractedLength;
50  uint32_t padding;
51  uint32_t deserialized = 0;
52 
53  while (deserialized < maxSize)
54  {
55  deserialized += aggregatedPacket->RemoveHeader (hdr);
56  extractedLength = hdr.GetLength ();
57  extractedMsdu = aggregatedPacket->CreateFragment (0, static_cast<uint32_t> (extractedLength));
58  aggregatedPacket->RemoveAtStart (extractedLength);
59  deserialized += extractedLength;
60 
61  padding = (4 - ((extractedLength + 14) % 4 )) % 4;
62 
63  if (padding > 0 && deserialized < maxSize)
64  {
65  aggregatedPacket->RemoveAtStart (padding);
66  deserialized += padding;
67  }
68 
69  std::pair<Ptr<Packet>, AmsduSubframeHeader> packetHdr (extractedMsdu, hdr);
70  set.push_back (packetHdr);
71  }
72  NS_LOG_INFO ("Deaggreated A-MSDU: extracted " << set.size () << " MSDUs");
73  return set;
74 }
75 
76 } // 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 the class in the ns-3 factory.
Definition: object-base.h:38
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:744
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:223
#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:353
static TypeId GetTypeId(void)
std::list< std::pair< Ptr< Packet >, AmsduSubframeHeader > > DeaggregatedMsdus
Doxygen introspection did not find any typical Config paths.
a base class which provides memory management and object aggregation
Definition: object.h:64
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
uint16_t GetLength(void) const