A Discrete-Event Network Simulator
API
wifi-mac-queue-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 IITP RAS
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Alexander Krotov <krotov@iitp.ru>
18 */
19
20#include "ns3/fcfs-wifi-queue-scheduler.h"
21#include "ns3/simulator.h"
22#include "ns3/test.h"
23#include "ns3/wifi-mac-queue.h"
24
25using namespace ns3;
26
38{
39 public:
44
45 void DoRun() override;
46};
47
49 : TestCase("Test DROP_OLDEST setting")
50{
51}
52
53void
55{
56 auto wifiMacQueue = CreateObject<WifiMacQueue>(AC_BE);
57 wifiMacQueue->SetMaxSize(QueueSize("5p"));
58 auto wifiMacScheduler = CreateObject<FcfsWifiQueueScheduler>();
59 wifiMacScheduler->SetAttribute("DropPolicy", EnumValue(FcfsWifiQueueScheduler::DROP_OLDEST));
60 wifiMacScheduler->m_perAcInfo[AC_BE].wifiMacQueue = wifiMacQueue;
61 wifiMacQueue->SetScheduler(wifiMacScheduler);
62
63 Mac48Address addr1 = Mac48Address::Allocate();
64
65 // Initialize the queue with 5 packets.
66 std::list<uint64_t> packetUids;
67 for (uint32_t i = 0; i < 5; i++)
68 {
69 WifiMacHeader header;
71 header.SetAddr1(addr1);
72 header.SetQosTid(0);
73 auto packet = Create<Packet>();
74 auto item = Create<WifiMpdu>(packet, header);
75 wifiMacQueue->Enqueue(item);
76
77 packetUids.push_back(packet->GetUid());
78 }
79
80 // Check that all elements are inserted successfully.
81 auto mpdu = wifiMacQueue->PeekByTidAndAddress(0, addr1);
82 NS_TEST_EXPECT_MSG_EQ(wifiMacQueue->GetNPackets(),
83 5,
84 "Queue has unexpected number of elements");
85 for (auto packetUid : packetUids)
86 {
87 NS_TEST_EXPECT_MSG_EQ(mpdu->GetPacket()->GetUid(),
88 packetUid,
89 "Stored packet is not the expected one");
90 mpdu = wifiMacQueue->PeekByTidAndAddress(0, addr1, mpdu);
91 }
92
93 // Push another element into the queue.
94 WifiMacHeader header;
96 header.SetAddr1(addr1);
97 header.SetQosTid(0);
98 auto packet = Create<Packet>();
99 auto item = Create<WifiMpdu>(packet, header);
100 wifiMacQueue->Enqueue(item);
101
102 // Update the list of expected packet UIDs.
103 packetUids.pop_front();
104 packetUids.push_back(packet->GetUid());
105
106 // Check that front packet was replaced correctly.
107 mpdu = wifiMacQueue->PeekByTidAndAddress(0, addr1);
108 NS_TEST_EXPECT_MSG_EQ(wifiMacQueue->GetNPackets(),
109 5,
110 "Queue has unexpected number of elements");
111 for (auto packetUid : packetUids)
112 {
113 NS_TEST_EXPECT_MSG_EQ(mpdu->GetPacket()->GetUid(),
114 packetUid,
115 "Stored packet is not the expected one");
116 mpdu = wifiMacQueue->PeekByTidAndAddress(0, addr1, mpdu);
117 }
118
119 wifiMacScheduler->Dispose();
120 Simulator::Destroy();
121}
122
130{
131 public:
133};
134
136 : TestSuite("wifi-mac-queue", UNIT)
137{
138 AddTestCase(new WifiMacQueueDropOldestTest, TestCase::QUICK);
139}
140
Test DROP_OLDEST setting.
void DoRun() override
Implementation to actually run this TestCase.
Wifi MAC Queue Test Suite.
Hold variables of type enum.
Definition: enum.h:56
an EUI-48 address
Definition: mac48-address.h:46
Class for representing queue sizes.
Definition: queue-size.h:96
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
A suite of tests to run.
Definition: test.h:1256
Implements the IEEE 802.11 MAC header.
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
#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:251
@ AC_BE
Best Effort.
Definition: qos-utils.h:76
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ WIFI_MAC_QOSDATA
static WifiMacQueueTestSuite g_wifiMacQueueTestSuite
the test suite