4408
|
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 |
#include "ns3/uinteger.h"
|
|
22 |
|
|
23 |
#include "amsdu-subframe-header.h"
|
|
24 |
#include "msdu-standard-aggregator.h"
|
|
25 |
|
|
26 |
NS_LOG_COMPONENT_DEFINE ("MsduStandardAggregator");
|
|
27 |
|
|
28 |
namespace ns3 {
|
|
29 |
|
|
30 |
NS_OBJECT_ENSURE_REGISTERED (MsduStandardAggregator);
|
|
31 |
|
|
32 |
TypeId
|
|
33 |
MsduStandardAggregator::GetTypeId (void)
|
|
34 |
{
|
|
35 |
static TypeId tid = TypeId ("ns3::MsduStandardAggregator")
|
|
36 |
.SetParent<MsduAggregator> ()
|
|
37 |
.AddConstructor<MsduStandardAggregator> ()
|
|
38 |
.AddAttribute ("MaxAmsduSize", "Max length in byte of an A-MSDU",
|
|
39 |
UintegerValue (7935),
|
|
40 |
MakeUintegerAccessor (&MsduStandardAggregator::m_maxAmsduLength),
|
|
41 |
MakeUintegerChecker<uint32_t> ())
|
|
42 |
;
|
|
43 |
return tid;
|
|
44 |
}
|
|
45 |
|
|
46 |
MsduStandardAggregator::MsduStandardAggregator ()
|
|
47 |
{}
|
|
48 |
|
|
49 |
MsduStandardAggregator::~MsduStandardAggregator ()
|
|
50 |
{}
|
|
51 |
|
|
52 |
bool
|
|
53 |
MsduStandardAggregator::Aggregate (Ptr<const Packet> packet, Ptr<Packet> aggregatedPacket,
|
|
54 |
Mac48Address src, Mac48Address dest)
|
|
55 |
{
|
|
56 |
NS_LOG_FUNCTION (this);
|
|
57 |
Ptr<Packet> currentPacket;
|
|
58 |
AmsduSubframeHeader currentHdr;
|
|
59 |
|
|
60 |
uint32_t padding = CalculatePadding (packet);
|
|
61 |
uint32_t actualSize = aggregatedPacket->GetSize ();
|
|
62 |
|
|
63 |
if ((14 + packet->GetSize () + actualSize + padding) <= m_maxAmsduLength)
|
|
64 |
{
|
|
65 |
currentHdr.SetDestinationAddr (dest);
|
|
66 |
currentHdr.SetSourceAddr (src);
|
|
67 |
currentHdr.SetLength (packet->GetSize ());
|
|
68 |
currentPacket = packet->Copy ();
|
|
69 |
if (padding)
|
|
70 |
{
|
|
71 |
currentPacket->AddPaddingAtEnd (padding);
|
|
72 |
}
|
|
73 |
currentPacket->AddHeader (currentHdr);
|
|
74 |
aggregatedPacket->AddAtEnd (currentPacket);
|
|
75 |
return true;
|
|
76 |
}
|
|
77 |
return false;
|
|
78 |
}
|
|
79 |
|
|
80 |
uint32_t
|
|
81 |
MsduStandardAggregator::CalculatePadding (Ptr<const Packet> packet)
|
|
82 |
{
|
|
83 |
return (4 - ((packet->GetSize() + 14) %4 )) % 4;
|
|
84 |
}
|
|
85 |
|
|
86 |
} //namespace ns3
|