A Discrete-Event Network Simulator
API
wifi-aggregation-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2015
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: Sébastien Deronne <sebastien.deronne@gmail.com>
19  */
20 
21 #include "ns3/string.h"
22 #include "ns3/test.h"
23 #include "ns3/object-factory.h"
24 #include "ns3/simulator.h"
25 #include "ns3/wifi-mac-queue.h"
26 #include "ns3/mac-low.h"
27 #include "ns3/edca-txop-n.h"
28 #include "ns3/yans-wifi-phy.h"
29 
30 using namespace ns3;
31 
33 {
34 public:
36 
37 private:
38  virtual void DoRun (void);
46 };
47 
49  : TestCase ("Check the correctness of two-level aggregation operations")
50 {
51 }
52 
53 void
55 {
56  /*
57  * Create and configure phy layer.
58  */
59  m_phy = CreateObject<YansWifiPhy> ();
61 
62  /*
63  * Create and configure manager.
64  */
66  m_factory.SetTypeId ("ns3::ConstantRateWifiManager");
67  m_factory.Set ("DataMode", StringValue ("HtMcs7"));
70 
71  /*
72  * Create and configure maclayer.
73  */
74  m_low = CreateObject<MacLow> ();
75  m_low->SetPhy (m_phy);
77 
78  m_edca = CreateObject<EdcaTxopN> ();
79  m_edca->SetLow (m_low);
83 
84  /*
85  * Configure aggregation.
86  */
88  m_factory.SetTypeId ("ns3::MsduStandardAggregator");
89  m_factory.Set ("MaxAmsduSize", UintegerValue (4095));
92 
94  m_factory.SetTypeId ("ns3::MpduStandardAggregator");
95  m_factory.Set ("MaxAmpduSize", UintegerValue (65535));
98 
99  /*
100  * Create dummy packets of 1500 bytes and fill mac header fields that will be used for the tests.
101  */
102  Ptr<const Packet> pkt = Create<Packet> (1500);
103  Ptr<Packet> currentAggregatedPacket = Create<Packet> ();
104  WifiMacHeader hdr, peekedHdr;
105  hdr.SetAddr1 (Mac48Address ("00:00:00:00:00:01"));
106  hdr.SetAddr2 (Mac48Address ("00:00:00:00:00:02"));
107  hdr.SetType (WIFI_MAC_QOSDATA);
108  hdr.SetQosTid (0);
109  Time tstamp;
110 
111  //-----------------------------------------------------------------------------------------------------
112 
113  /*
114  * Test MSDU aggregation of two packets using MacLow::PerformMsduAggregation.
115  * It checks whether aggregation succeeded:
116  * - returned packet should be different from 0;
117  * - A-MSDU frame size should be 3030 bytes (= 2 packets + headers + padding);
118  * - one packet should be removed from the queue (the other packet is removed later in MacLow::AggregateToAmpdu) .
119  */
120  m_edca->GetEdcaQueue ()->Enqueue (pkt, hdr);
121  m_edca->GetEdcaQueue ()->Enqueue (pkt, hdr);
122 
123  Ptr<const Packet> peekedPacket = m_edca->GetEdcaQueue ()->PeekByTidAndAddress (&peekedHdr, 0,
124  WifiMacHeader::ADDR1,
125  hdr.GetAddr1 (),
126  &tstamp);
127  m_low->m_currentPacket = peekedPacket->Copy ();
128  m_low->m_currentHdr = peekedHdr;
129 
130  Ptr<Packet> packet = m_low->PerformMsduAggregation (peekedPacket, &peekedHdr, &tstamp, currentAggregatedPacket, 0);
131 
132  bool result = (packet != 0);
133  NS_TEST_EXPECT_MSG_EQ (result, true, "aggregation failed");
134  NS_TEST_EXPECT_MSG_EQ (packet->GetSize (), 3030, "wrong packet size");
135  NS_TEST_EXPECT_MSG_EQ (m_edca->GetEdcaQueue ()->GetSize (), 0, "aggregated packets not removed from the queue");
136 
137  //-----------------------------------------------------------------------------------------------------
138 
139  /*
140  * Aggregation is refused when the maximum size is reached.
141  * It checks whether MSDU aggregation has been rejected because the maximum MPDU size is set to 0 (returned packet should be equal to 0).
142  * This test is needed to ensure that no packets are removed from the queue in MacLow::PerformMsduAggregation, since aggregation will no occur in MacLow::AggregateToAmpdu.
143  */
145  m_factory.SetTypeId ("ns3::MpduStandardAggregator");
146  m_factory.Set ("MaxAmpduSize", UintegerValue (0));
147  m_mpduAggregator = m_factory.Create<MpduAggregator> ();
149 
150  m_edca->GetEdcaQueue ()->Enqueue (pkt, hdr);
151  packet = m_low->PerformMsduAggregation (peekedPacket, &peekedHdr, &tstamp, currentAggregatedPacket, 0);
152 
153  result = (packet != 0);
154  NS_TEST_EXPECT_MSG_EQ (result, false, "maximum aggregated frame size check failed");
155 
156  //-----------------------------------------------------------------------------------------------------
157 
158  /*
159  * Aggregation does not occur zhen there is no more packets in the queue.
160  * It checks whether MSDU aggregation has been rejected because there is no packets ready in the queue (returned packet should be equal to 0).
161  * This test is needed to ensure that there is no issue when the queue is empty.
162  */
163  m_factory = ObjectFactory ();
164  m_factory.SetTypeId ("ns3::MpduStandardAggregator");
165  m_factory.Set ("MaxAmpduSize", UintegerValue (4095));
166  m_mpduAggregator = m_factory.Create<MpduAggregator> ();
168 
169  m_edca->GetEdcaQueue ()->Remove (pkt);
170  m_edca->GetEdcaQueue ()->Remove (pkt);
171  packet = m_low->PerformMsduAggregation (peekedPacket, &peekedHdr, &tstamp, currentAggregatedPacket, 0);
172 
173  result = (packet != 0);
174  NS_TEST_EXPECT_MSG_EQ (result, false, "aggregation failed to stop as queue is empty");
175  Simulator::Destroy ();
176 }
177 
178 
179 //-----------------------------------------------------------------------------
181 {
182 public:
184 };
185 
187  : TestSuite ("aggregation-wifi", UNIT)
188 {
189  AddTestCase (new TwoLevelAggregationTest, TestCase::QUICK);
190 }
191 
Abstract class that concrete mpdu aggregators have to implement.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
virtual void DoRun(void)
Implementation to actually run this TestCase.
HT OFDM PHY for the 5 GHz band (clause 20)
Ptr< WifiRemoteStationManager > m_manager
Hold variables of type string.
Definition: string.h:41
A suite of tests to run.
Definition: test.h:1333
void SetWifiRemoteStationManager(Ptr< WifiRemoteStationManager > remoteManager)
Set WifiRemoteStationsManager this EdcaTxopN is associated to.
Definition: edca-txop-n.cc:352
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition: test.h:278
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:786
encapsulates test code
Definition: test.h:1147
virtual void SetupPhy(Ptr< WifiPhy > phy)
Set up PHY associated with this device since it is the object that knows the full set of transmit rat...
Best Effort.
Definition: qos-utils.h:39
Ptr< MsduAggregator > m_msduAggregator
Ptr< Packet > PerformMsduAggregation(Ptr< const Packet > packet, WifiMacHeader *hdr, Time *tstamp, Ptr< Packet > currentAmpduPacket, uint16_t blockAckSize)
Perform MSDU aggregation for a given MPDU in an A-MPDU.
Definition: mac-low.cc:3153
void SetLow(Ptr< MacLow > low)
Set MacLow associated with this EdcaTxopN.
Definition: edca-txop-n.cc:437
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:297
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
Hold an unsigned integer type.
Definition: uinteger.h:44
hold a list of per-remote-station state.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:122
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetAccessCategory(enum AcIndex ac)
Set the access category of this EDCAF.
static WifiAggregationTestSuite g_wifiAggregationTestSuite
an EUI-48 address
Definition: mac48-address.h:43
void Set(std::string name, const AttributeValue &value)
Set an attribute to be set during construction.
void SetPhy(Ptr< WifiPhy > phy)
Set up WifiPhy associated with this MacLow.
Definition: mac-low.cc:517
void SetMsduAggregator(Ptr< MsduAggregator > aggr)
Instantiate subclasses of ns3::Object.
void CompleteConfig(void)
Complete block ACK configuration.
Ptr< Packet > m_currentPacket
Current packet transmitted/to be transmitted.
Definition: mac-low.h:1327
virtual void ConfigureStandard(enum WifiPhyStandard standard)
Configure the PHY-level parameters for different Wi-Fi standard.
Abstract class that concrete msdu aggregators have to implement.
WifiMacHeader m_currentHdr
Header of the current packet.
Definition: mac-low.h:1328
Implements the IEEE 802.11 MAC header.
void SetWifiRemoteStationManager(Ptr< WifiRemoteStationManager > manager)
Set up WifiRemoteStationManager associated with this MacLow.
Definition: mac-low.cc:541
void SetMpduAggregator(Ptr< MpduAggregator > aggregator)
Set up MpduAggregator associated with this MacLow.
Definition: mac-low.cc:2705
Ptr< MpduAggregator > m_mpduAggregator
Ptr< WifiMacQueue > GetEdcaQueue() const
Return the packet queue associated with this EdcaTxopN.
Definition: edca-txop-n.cc:374