|
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 { |
|
43 NS_LOG_FUNCTION_NOARGS (); |
|
44 DeaggregatedMsdus set; |
|
45 |
|
46 AmsduSubframeHeader hdr; |
|
47 uint32_t maxSize = aggregatedPacket->GetSize (); |
|
48 // The worst condition is: two aggregated packets with no padding. |
|
49 // 28 bytes is the size of two Amsdu subframe headers. |
|
50 uint8_t *buffer = new uint8_t[maxSize-28]; |
|
51 uint32_t padding; |
|
52 uint32_t deserialized = 0; |
|
53 |
|
54 while (deserialized < maxSize) |
|
55 { |
|
56 deserialized += aggregatedPacket->RemoveHeader (hdr); |
|
57 deserialized += aggregatedPacket->CopyData (buffer, hdr.GetLength ()); |
|
58 aggregatedPacket->RemoveAtStart (hdr.GetLength ()); |
|
59 |
|
60 padding = (4 - ((hdr.GetLength () + 14) %4 )) % 4; |
|
61 |
|
62 if (padding > 0) |
|
63 { |
|
64 aggregatedPacket->RemoveAtStart (padding); |
|
65 deserialized += padding; |
|
66 } |
|
67 //a new packet is created with the content of extracted msdu |
|
68 Ptr<Packet> p = Create<Packet> (buffer, hdr.GetLength ()); |
|
69 |
|
70 std::pair<Ptr<Packet>, AmsduSubframeHeader> packetHdr (p,hdr); |
|
71 set.push_back (packetHdr); |
|
72 } |
|
73 delete [] buffer; |
|
74 NS_LOG_INFO ("Deaggreated A-MSDU: extracted "<< set.size () << " MSDUs"); |
|
75 return set; |
|
76 } |
|
77 |
|
78 } //namespace ns3 |