A Discrete-Event Network Simulator
API
wifi-mac-queue-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2021 IITP RAS
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: Alexander Krotov <krotov@iitp.ru>
19  */
20 
21 #include "ns3/test.h"
22 #include "ns3/wifi-mac-queue.h"
23 #include "ns3/simulator.h"
24 
25 using namespace ns3;
26 
38 {
39 public:
44 
45  void DoRun () override;
46 };
47 
49  : TestCase ("Test DROP_OLDEST setting")
50 {
51 }
52 
53 void
55 {
56  auto wifiMacQueue = CreateObject<WifiMacQueue> ();
57  wifiMacQueue->SetMaxSize (QueueSize ("5p"));
58  wifiMacQueue->SetAttribute ("DropPolicy", EnumValue (WifiMacQueue::DROP_OLDEST));
59 
60  // Initialize the queue with 5 packets.
61  std::vector<uint64_t> packetUids;
62  for (uint32_t i = 0; i < 5; i++)
63  {
64  WifiMacHeader header;
65  header.SetType (WIFI_MAC_QOSDATA);
66  header.SetQosTid (0);
67  auto packet = Create<Packet> ();
68  auto item = Create<WifiMacQueueItem> (packet, header);
69  wifiMacQueue->PushFront (item);
70 
71  packetUids.push_back (packet->GetUid ());
72  }
73 
74  // Check that all elements are inserted successfully.
75  auto it = wifiMacQueue->begin ();
76  NS_TEST_EXPECT_MSG_EQ (wifiMacQueue->GetNPackets (), 5, "Queue has unexpected number of elements");
77  for (uint32_t i = 5; i > 0; i--)
78  {
79  NS_TEST_EXPECT_MSG_EQ ((*it)->GetPacket ()->GetUid (),
80  packetUids.at (i - 1),
81  "Stored packet is not the expected one");
82  it++;
83  }
84 
85  // Push another element in front of the queue.
86  WifiMacHeader header;
87  header.SetType (WIFI_MAC_QOSDATA);
88  header.SetQosTid (0);
89  auto packet = Create<Packet> ();
90  auto item = Create<WifiMacQueueItem> (packet, header);
91  wifiMacQueue->PushFront (item);
92 
93  // Update the vector of expected packet UIDs.
94  packetUids.at (4) = packet->GetUid ();
95 
96  // Check that front packet was replaced correctly.
97  it = wifiMacQueue->begin ();
98  NS_TEST_EXPECT_MSG_EQ (wifiMacQueue->GetNPackets (), 5, "Queue has unexpected number of elements");
99  for (uint32_t i = 5; i > 0; i--)
100  {
101  NS_TEST_EXPECT_MSG_EQ ((*it)->GetPacket ()->GetUid (),
102  packetUids.at (i - 1),
103  "Stored packet is not the expected one");
104  it++;
105  }
106 
107  Simulator::Destroy ();
108 }
109 
117 {
118  public:
120 };
121 
123  : TestSuite ("wifi-mac-queue", UNIT)
124 {
125  AddTestCase (new WifiMacQueueDropOldestTest, TestCase::QUICK);
126 }
127 
Class for representing queue sizes.
Definition: queue-size.h:94
A suite of tests to run.
Definition: test.h:1343
#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:283
encapsulates test code
Definition: test.h:1153
Hold variables of type enum.
Definition: enum.h:54
Wifi MAC Queue Test Suite.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
void DoRun() override
Implementation to actually run this TestCase.
WifiMacQueueDropOldestTest()
Constructor.
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
Test DROP_OLDEST setting.
static WifiMacQueueTestSuite g_wifiMacQueueTestSuite
the test suite
Implements the IEEE 802.11 MAC header.