A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Stefano Avallone <stavallo@unina.it>
7 */
8
10
11#include "wifi-mac-queue.h"
12
13#include "ns3/enum.h"
14#include "ns3/log.h"
15
16namespace ns3
17{
18
19NS_LOG_COMPONENT_DEFINE("FcfsWifiQueueScheduler");
20
21bool
22operator==(const FcfsPrio& lhs, const FcfsPrio& rhs)
23{
24 return lhs.priority == rhs.priority && lhs.type == rhs.type;
25}
26
27bool
28operator<(const FcfsPrio& lhs, const FcfsPrio& rhs)
29{
30 // Control queues have the highest priority
31 if (lhs.type == WIFI_CTL_QUEUE && rhs.type != WIFI_CTL_QUEUE)
32 {
33 return true;
34 }
35 if (lhs.type != WIFI_CTL_QUEUE && rhs.type == WIFI_CTL_QUEUE)
36 {
37 return false;
38 }
39 // Management queues have the second highest priority
40 if (lhs.type == WIFI_MGT_QUEUE && rhs.type != WIFI_MGT_QUEUE)
41 {
42 return true;
43 }
44 if (lhs.type != WIFI_MGT_QUEUE && rhs.type == WIFI_MGT_QUEUE)
45 {
46 return false;
47 }
48 // we get here if both priority values refer to container queues of the same type,
49 // hence we can compare the time values.
50 return lhs.priority < rhs.priority;
51}
52
53NS_OBJECT_ENSURE_REGISTERED(FcfsWifiQueueScheduler);
54
55TypeId
57{
58 static TypeId tid =
59 TypeId("ns3::FcfsWifiQueueScheduler")
61 .SetGroupName("Wifi")
62 .AddConstructor<FcfsWifiQueueScheduler>()
63 .AddAttribute("DropPolicy",
64 "Upon enqueue with full queue, drop oldest (DropOldest) "
65 "or newest (DropNewest) packet",
69 "DropOldest",
71 "DropNewest"));
72 return tid;
73}
74
79
82{
83 auto queue = GetWifiMacQueue(ac);
84 if (queue->QueueBase::GetNPackets() < queue->GetMaxSize().GetValue())
85 {
86 // the queue is not full, do not drop anything
87 return nullptr;
88 }
89
90 // Control and management frames should be prioritized
91 if (m_dropPolicy == DROP_OLDEST || mpdu->GetHeader().IsCtl() || mpdu->GetHeader().IsMgt())
92 {
93 for (const auto& [priority, queueInfo] : GetSortedQueues(ac))
94 {
95 if (std::get<WifiContainerQueueType>(queueInfo.get().first) == WIFI_MGT_QUEUE ||
96 std::get<WifiContainerQueueType>(queueInfo.get().first) == WIFI_CTL_QUEUE)
97 {
98 // do not drop control or management frames
99 continue;
100 }
101
102 // do not drop frames that are inflight or to be retransmitted
103 Ptr<WifiMpdu> item;
104 while ((item = queue->PeekByQueueId(queueInfo.get().first, item)))
105 {
106 if (!item->IsInFlight() && !item->GetHeader().IsRetry())
107 {
108 NS_LOG_DEBUG("Dropping " << *item);
109 return item;
110 }
111 }
112 }
113 }
114 NS_LOG_DEBUG("Dropping received MPDU: " << *mpdu);
115 return mpdu;
116}
117
118void
120{
121 NS_LOG_FUNCTION(this << +ac << *mpdu);
122
123 const auto queueId = WifiMacQueueContainer::GetQueueId(mpdu);
124
125 // priority is determined by the head of the queue
126 auto item = GetWifiMacQueue(ac)->PeekByQueueId(queueId);
127 NS_ASSERT(item);
128
129 SetPriority(ac, queueId, {item->GetTimestamp(), std::get<WifiContainerQueueType>(queueId)});
130}
131
132void
134{
135 NS_LOG_FUNCTION(this << +ac << mpdus.size());
136
137 std::set<WifiContainerQueueId> queueIds;
138
139 for (const auto& mpdu : mpdus)
140 {
141 queueIds.insert(WifiMacQueueContainer::GetQueueId(mpdu));
142 }
143
144 for (const auto& queueId : queueIds)
145 {
146 if (auto item = GetWifiMacQueue(ac)->PeekByQueueId(queueId))
147 {
148 SetPriority(ac,
149 queueId,
150 {item->GetTimestamp(), std::get<WifiContainerQueueType>(queueId)});
151 }
152 }
153}
154
155void
157{
158 NS_LOG_FUNCTION(this << +ac << mpdus.size());
159
160 std::set<WifiContainerQueueId> queueIds;
161
162 for (const auto& mpdu : mpdus)
163 {
164 queueIds.insert(WifiMacQueueContainer::GetQueueId(mpdu));
165 }
166
167 for (const auto& queueId : queueIds)
168 {
169 if (auto item = GetWifiMacQueue(ac)->PeekByQueueId(queueId))
170 {
171 SetPriority(ac,
172 queueId,
173 {item->GetTimestamp(), std::get<WifiContainerQueueType>(queueId)});
174 }
175 }
176}
177
178} // namespace ns3
Hold variables of type enum.
Definition enum.h:52
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.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
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.
WifiMacQueueSchedulerImpl is a template class enabling the definition of different types of priority ...
Ptr< WifiMacQueue > GetWifiMacQueue(AcIndex ac) const
const SortedQueues & GetSortedQueues(AcIndex ac) const
void SetPriority(AcIndex ac, const WifiContainerQueueId &queueId, const FcfsPrio &priority)
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_TEMPLATE_DEFINE(name)
Initialize a reference to a Log component.
Definition log.h:225
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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:35
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition qos-utils.h:62
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator==(const EventId &a, const EventId &b)
Definition event-id.h:155
Ptr< const AttributeChecker > MakeEnumChecker(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition enum.h:179
bool operator<(const EventId &a, const EventId &b)
Definition event-id.h:168
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Definition enum.h:221
Definition of priority for container queues.
WifiContainerQueueType type
type of container queue
Time priority
time priority