A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
msdu-aggregator.cc
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
32 MsduAggregator::GetTypeId (void)
33 {
34  static TypeId tid = TypeId ("ns3::MsduAggregator")
35  .SetParent<Object> ()
36  ;
37  return tid;
38 }
39 
40 MsduAggregator::DeaggregatedMsdus
41 MsduAggregator::Deaggregate (Ptr<Packet> aggregatedPacket)
42 {
44  DeaggregatedMsdus set;
45 
46  AmsduSubframeHeader hdr;
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
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
#define NS_LOG_INFO(msg)
Definition: log.h:264
#define NS_LOG_FUNCTION_NOARGS()
Definition: log.h:275