A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
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
37
class
WifiMacQueueDropOldestTest
:
public
TestCase
38
{
39
public
:
43
WifiMacQueueDropOldestTest
();
44
45
void
DoRun ()
override
;
46
};
47
48
WifiMacQueueDropOldestTest::WifiMacQueueDropOldestTest
()
49
:
TestCase
(
"Test DROP_OLDEST setting"
)
50
{
51
}
52
53
void
54
WifiMacQueueDropOldestTest::DoRun
()
55
{
56
auto
wifiMacQueue = CreateObject<WifiMacQueue> (
AC_BE
);
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
116
class
WifiMacQueueTestSuite
:
public
TestSuite
117
{
118
public
:
119
WifiMacQueueTestSuite
();
120
};
121
122
WifiMacQueueTestSuite::WifiMacQueueTestSuite
()
123
:
TestSuite
(
"wifi-mac-queue"
, UNIT)
124
{
125
AddTestCase
(
new
WifiMacQueueDropOldestTest
, TestCase::QUICK);
126
}
127
128
static
WifiMacQueueTestSuite
g_wifiMacQueueTestSuite
;
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:299
WifiMacQueueDropOldestTest::WifiMacQueueDropOldestTest
WifiMacQueueDropOldestTest()
Constructor.
Definition:
wifi-mac-queue-test.cc:48
g_wifiMacQueueTestSuite
static WifiMacQueueTestSuite g_wifiMacQueueTestSuite
the test suite
Definition:
wifi-mac-queue-test.cc:128
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WifiMacQueueDropOldestTest
Test DROP_OLDEST setting.
Definition:
wifi-mac-queue-test.cc:38
ns3::EnumValue
Hold variables of type enum.
Definition:
enum.h:55
ns3::TestCase
encapsulates test code
Definition:
test.h:1154
ns3::WifiMacHeader
Implements the IEEE 802.11 MAC header.
Definition:
wifi-mac-header.h:85
WifiMacQueueTestSuite::WifiMacQueueTestSuite
WifiMacQueueTestSuite()
Definition:
wifi-mac-queue-test.cc:122
ns3::AC_BE
@ AC_BE
Best Effort.
Definition:
qos-utils.h:73
NS_TEST_EXPECT_MSG_EQ
#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
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1344
ns3::WIFI_MAC_QOSDATA
@ WIFI_MAC_QOSDATA
Definition:
wifi-mac-header.h:70
ns3::WifiMacHeader::SetType
void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
Definition:
wifi-mac-header.cc:132
WifiMacQueueDropOldestTest::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition:
wifi-mac-queue-test.cc:54
WifiMacQueueTestSuite
Wifi MAC Queue Test Suite.
Definition:
wifi-mac-queue-test.cc:117
ns3::WifiMacHeader::SetQosTid
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
Definition:
wifi-mac-header.cc:352
ns3::QueueSize
Class for representing queue sizes.
Definition:
queue-size.h:95
src
wifi
test
wifi-mac-queue-test.cc
Generated on Fri Oct 1 2021 17:03:51 for ns-3 by
1.8.20