A Discrete-Event Network Simulator
API
fcfs-wifi-queue-scheduler.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Universita' degli Studi di Napoli Federico II
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: Stefano Avallone <stavallo@unina.it>
18 */
19
21
22#include "wifi-mac-queue.h"
23
24#include "ns3/enum.h"
25#include "ns3/log.h"
26
27namespace ns3
28{
29
30NS_LOG_COMPONENT_DEFINE("FcfsWifiQueueScheduler");
31
32NS_OBJECT_ENSURE_REGISTERED(FcfsWifiQueueScheduler);
33
34TypeId
36{
37 static TypeId tid = TypeId("ns3::FcfsWifiQueueScheduler")
39 .SetGroupName("Wifi")
40 .AddConstructor<FcfsWifiQueueScheduler>()
41 .AddAttribute("DropPolicy",
42 "Upon enqueue with full queue, drop oldest (DropOldest) "
43 "or newest (DropNewest) packet",
47 "DropOldest",
49 "DropNewest"));
50 return tid;
51}
52
54 : NS_LOG_TEMPLATE_DEFINE("FcfsWifiQueueScheduler")
55{
56}
57
60{
61 auto queue = GetWifiMacQueue(ac);
62 if (queue->QueueBase::GetNPackets() < queue->GetMaxSize().GetValue())
63 {
64 // the queue is not full, do not drop anything
65 return nullptr;
66 }
67
68 // Management frames should be prioritized
69 if (m_dropPolicy == DROP_OLDEST || mpdu->GetHeader().IsMgt())
70 {
71 auto sortedQueuesIt = GetSortedQueues(ac).begin();
72
73 while (sortedQueuesIt != GetSortedQueues(ac).end() &&
74 std::get<WifiContainerQueueType>(sortedQueuesIt->second.get().first) ==
76 {
77 sortedQueuesIt++;
78 }
79
80 if (sortedQueuesIt != GetSortedQueues(ac).end())
81 {
82 return queue->PeekByQueueId(sortedQueuesIt->second.get().first);
83 }
84 }
85 return mpdu;
86}
87
88void
90{
91 NS_LOG_FUNCTION(this << +ac << *mpdu);
92
93 const auto queueId = WifiMacQueueContainer::GetQueueId(mpdu);
94
95 if (GetWifiMacQueue(ac)->GetNPackets(queueId) > 1)
96 {
97 // Enqueue takes place at the tail, while the priority is determined by the
98 // head of the queue. Therefore, if the queue was not empty before inserting
99 // this MPDU, priority does not change
100 return;
101 }
102
103 auto priority =
104 (mpdu->GetHeader().IsMgt() ? Seconds(0) // Highest priority for management frames
105 : mpdu->GetExpiryTime());
106 SetPriority(ac, queueId, priority);
107}
108
109void
111{
112 NS_LOG_FUNCTION(this << +ac << mpdus.size());
113
114 std::set<WifiContainerQueueId> queueIds;
115
116 for (const auto& mpdu : mpdus)
117 {
118 queueIds.insert(WifiMacQueueContainer::GetQueueId(mpdu));
119 }
120
121 for (const auto& queueId : queueIds)
122 {
123 if (std::get<WifiContainerQueueType>(queueId) == WIFI_MGT_QUEUE)
124 {
125 // the priority of management queues does not change
126 continue;
127 }
128
129 if (auto item = GetWifiMacQueue(ac)->PeekByQueueId(queueId); item != nullptr)
130 {
131 SetPriority(ac, queueId, item->GetExpiryTime());
132 }
133 }
134}
135
136void
138{
139 NS_LOG_FUNCTION(this << +ac << mpdus.size());
140
141 std::set<WifiContainerQueueId> queueIds;
142
143 for (const auto& mpdu : mpdus)
144 {
145 queueIds.insert(WifiMacQueueContainer::GetQueueId(mpdu));
146 }
147
148 for (const auto& queueId : queueIds)
149 {
150 if (std::get<0>(queueId) == WIFI_MGT_QUEUE)
151 {
152 // the priority of management queues does not change
153 continue;
154 }
155
156 if (auto item = GetWifiMacQueue(ac)->PeekByQueueId(queueId); item != nullptr)
157 {
158 SetPriority(ac, queueId, item->GetExpiryTime());
159 }
160 }
161}
162
163} // namespace ns3
Hold variables of type enum.
Definition: enum.h:56
FcfsWifiQueueScheduler is a wifi queue scheduler that serves data frames in a first come first serve ...
Ptr< WifiMpdu > HasToDropBeforeEnqueuePriv(AcIndex ac, Ptr< WifiMpdu > mpdu) override
Check whether an MPDU has to be dropped before enqueuing the given MPDU.
static TypeId GetTypeId()
Get the type ID.
void DoNotifyEnqueue(AcIndex ac, Ptr< WifiMpdu > mpdu) override
Notify the scheduler that the given MPDU has been enqueued by the given Access Category.
void DoNotifyDequeue(AcIndex ac, const std::list< Ptr< WifiMpdu > > &mpdus) override
Notify the scheduler that the given list of MPDUs have been dequeued by the given Access Category.
void DoNotifyRemove(AcIndex ac, const std::list< Ptr< WifiMpdu > > &mpdus) override
Notify the scheduler that the given list of MPDUs have been removed by the given Access Category.
DropPolicy m_dropPolicy
Drop behavior of queue.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
static WifiContainerQueueId GetQueueId(Ptr< const WifiMpdu > mpdu)
Return the QueueId identifying the container queue in which the given MPDU is (or is to be) enqueued.
Ptr< WifiMacQueue > GetWifiMacQueue(AcIndex ac) const
Get the wifi MAC queue associated with the given Access Category.
const SortedQueues & GetSortedQueues(AcIndex ac) const
Get a const reference to the sorted list of container queues for the given Access Category.
void SetPriority(AcIndex ac, const WifiContainerQueueId &queueId, const Time &priority)
Set the priority for the given container queue belonging to the given Access Category.
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Definition: enum.h:205
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_TEMPLATE_DEFINE(name)
Initialize a reference to a Log component.
Definition: log.h:236
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:74
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeEnumChecker(int v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.h:163
#define list