A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
27 namespace ns3
28 {
29 
30 NS_LOG_COMPONENT_DEFINE("FcfsWifiQueueScheduler");
31 
32 bool
33 operator==(const FcfsPrio& lhs, const FcfsPrio& rhs)
34 {
35  return lhs.priority == rhs.priority && lhs.type == rhs.type;
36 }
37 
38 bool
39 operator<(const FcfsPrio& lhs, const FcfsPrio& rhs)
40 {
41  // Control queues have the highest priority
42  if (lhs.type == WIFI_CTL_QUEUE && rhs.type != WIFI_CTL_QUEUE)
43  {
44  return true;
45  }
46  if (lhs.type != WIFI_CTL_QUEUE && rhs.type == WIFI_CTL_QUEUE)
47  {
48  return false;
49  }
50  // Management queues have the second highest priority
51  if (lhs.type == WIFI_MGT_QUEUE && rhs.type != WIFI_MGT_QUEUE)
52  {
53  return true;
54  }
55  if (lhs.type != WIFI_MGT_QUEUE && rhs.type == WIFI_MGT_QUEUE)
56  {
57  return false;
58  }
59  // we get here if both priority values refer to container queues of the same type,
60  // hence we can compare the time values.
61  return lhs.priority < rhs.priority;
62 }
63 
64 NS_OBJECT_ENSURE_REGISTERED(FcfsWifiQueueScheduler);
65 
66 TypeId
68 {
69  static TypeId tid =
70  TypeId("ns3::FcfsWifiQueueScheduler")
72  .SetGroupName("Wifi")
73  .AddConstructor<FcfsWifiQueueScheduler>()
74  .AddAttribute("DropPolicy",
75  "Upon enqueue with full queue, drop oldest (DropOldest) "
76  "or newest (DropNewest) packet",
78  MakeEnumAccessor<DropPolicy>(&FcfsWifiQueueScheduler::m_dropPolicy),
80  "DropOldest",
82  "DropNewest"));
83  return tid;
84 }
85 
87  : NS_LOG_TEMPLATE_DEFINE("FcfsWifiQueueScheduler")
88 {
89 }
90 
93 {
94  auto queue = GetWifiMacQueue(ac);
95  if (queue->QueueBase::GetNPackets() < queue->GetMaxSize().GetValue())
96  {
97  // the queue is not full, do not drop anything
98  return nullptr;
99  }
100 
101  // Control and management frames should be prioritized
102  if (m_dropPolicy == DROP_OLDEST || mpdu->GetHeader().IsCtl() || mpdu->GetHeader().IsMgt())
103  {
104  for (const auto& [priority, queueInfo] : GetSortedQueues(ac))
105  {
106  if (std::get<WifiContainerQueueType>(queueInfo.get().first) == WIFI_MGT_QUEUE ||
107  std::get<WifiContainerQueueType>(queueInfo.get().first) == WIFI_CTL_QUEUE)
108  {
109  // do not drop control or management frames
110  continue;
111  }
112 
113  // do not drop frames that are inflight or to be retransmitted
114  Ptr<WifiMpdu> item;
115  while ((item = queue->PeekByQueueId(queueInfo.get().first, item)))
116  {
117  if (!item->IsInFlight() && !item->GetHeader().IsRetry())
118  {
119  NS_LOG_DEBUG("Dropping " << *item);
120  return item;
121  }
122  }
123  }
124  }
125  NS_LOG_DEBUG("Dropping received MPDU: " << *mpdu);
126  return mpdu;
127 }
128 
129 void
131 {
132  NS_LOG_FUNCTION(this << +ac << *mpdu);
133 
134  const auto queueId = WifiMacQueueContainer::GetQueueId(mpdu);
135 
136  // priority is determined by the head of the queue
137  auto item = GetWifiMacQueue(ac)->PeekByQueueId(queueId);
138  NS_ASSERT(item);
139 
140  SetPriority(ac, queueId, {item->GetTimestamp(), std::get<WifiContainerQueueType>(queueId)});
141 }
142 
143 void
145 {
146  NS_LOG_FUNCTION(this << +ac << mpdus.size());
147 
148  std::set<WifiContainerQueueId> queueIds;
149 
150  for (const auto& mpdu : mpdus)
151  {
152  queueIds.insert(WifiMacQueueContainer::GetQueueId(mpdu));
153  }
154 
155  for (const auto& queueId : queueIds)
156  {
157  if (auto item = GetWifiMacQueue(ac)->PeekByQueueId(queueId))
158  {
159  SetPriority(ac,
160  queueId,
161  {item->GetTimestamp(), std::get<WifiContainerQueueType>(queueId)});
162  }
163  }
164 }
165 
166 void
168 {
169  NS_LOG_FUNCTION(this << +ac << mpdus.size());
170 
171  std::set<WifiContainerQueueId> queueIds;
172 
173  for (const auto& mpdu : mpdus)
174  {
175  queueIds.insert(WifiMacQueueContainer::GetQueueId(mpdu));
176  }
177 
178  for (const auto& queueId : queueIds)
179  {
180  if (auto item = GetWifiMacQueue(ac)->PeekByQueueId(queueId))
181  {
182  SetPriority(ac,
183  queueId,
184  {item->GetTimestamp(), std::get<WifiContainerQueueType>(queueId)});
185  }
186  }
187 }
188 
189 } // namespace ns3
Hold variables of type enum.
Definition: enum.h:62
FcfsWifiQueueScheduler is a wifi queue scheduler that serves data frames in a first come first serve ...
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.
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 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:77
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
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
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 FcfsPrio &priority)
Set the priority for the given container queue belonging to the given Access Category.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#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_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#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:46
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:73
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:157
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:194
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:170
#define list
Definition of priority for container queues.
WifiContainerQueueType type
type of container queue
Time priority
time priority