A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
rr-wifi-queue-scheduler.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026 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 "qos-txop.h"
12#include "wifi-mac-queue.h"
13#include "wifi-mac.h"
14#include "wifi-net-device.h"
15#include "wifi-phy.h"
16
17#include "ns3/log.h"
18
19namespace ns3
20{
21
22NS_LOG_COMPONENT_DEFINE("RrWifiQueueScheduler");
23
25
28{
29 static TypeId tid = TypeId("ns3::RrWifiQueueScheduler")
31 .SetGroupName("Wifi")
32 .AddConstructor<RrWifiQueueScheduler>();
33 return tid;
34}
35
40
41void
43{
45
46 const auto dev = mac->GetDevice();
47 for (uint8_t phyId = 0; phyId < dev->GetNPhys(); ++phyId)
48 {
49 dev->GetPhy(phyId)->TraceConnectWithoutContext(
50 "PhyTxPsduBegin",
52 }
53}
54
55void
57 WifiConstPsduMap psduMap,
58 WifiTxVector txVector,
59 Watt_u txPower)
60{
61 NS_LOG_FUNCTION(this << phyId << txVector << txPower);
62
63 const auto now = Simulator::Now();
64 const auto linkId = GetMac()->GetLinkForPhy(phyId);
65
66 NS_ASSERT_MSG(linkId,
67 "PHY " << +phyId << " transmitted a PSDU but it is not operating on any link");
68
69 for (const auto& [staId, psdu] : psduMap)
70 {
71 if (const auto mpdu = *psdu->begin(); mpdu->IsQueued())
72 {
73 const auto ac = mpdu->GetQueueAc();
74
75 if (auto txop = GetMac()->GetTxopFor(ac);
76 txop->IsQosTxop() && StaticCast<QosTxop>(txop)->GetTxopStartTime(*linkId))
77 {
78 const auto queueId = WifiMacQueueContainer::GetQueueId(mpdu);
79 m_perAcQueueIdLastTxTime[ac][queueId] = now;
80 SetPriority(ac, queueId, {now, queueId.type});
81 }
82 }
83 }
84}
85
86void
88{
89 NS_LOG_FUNCTION(this << ac << *mpdu);
90
91 // if the container queue was empty before the insertion of this MPDU, we need to assign a
92 // priority to the container queue; let's use the last priority value we assigned to the
93 // container queue (which equals the current priority if the container queue was not empty),
94 // if any, or Time{0}, otherwise
95 const auto queueId = WifiMacQueueContainer::GetQueueId(mpdu);
96 const auto [it, inserted] = m_perAcQueueIdLastTxTime[ac].insert({queueId, Time{0}});
97 SetPriority(ac, queueId, {it->second, queueId.type});
98}
99
100void
102{
103 NS_LOG_FUNCTION(this << ac << mpdus.size());
104 // do nothing, priority is set when a PSDU is transmitted in a TXOP
105}
106
107void
109{
110 NS_LOG_FUNCTION(this << ac << mpdus.size());
111 // do nothing, priority is set when a PSDU is transmitted in a TXOP
112}
113
114} // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
RrWifiQueueScheduler is a wifi queue scheduler that serves container queues in a round robin fashion.
std::vector< QueueIdLastTimeMap > m_perAcQueueIdLastTxTime
per-AC map of last time a frame in each container queue was transmitted
void PsduTransmitted(uint8_t phyId, WifiConstPsduMap psduMap, WifiTxVector txVector, Watt_u txPower)
Callback connected to the PHY trace that is fired every time a PSDU (map) is transmitted.
void DoNotifyEnqueue(AcIndex ac, Ptr< WifiMpdu > mpdu) override
Notify the scheduler that the given MPDU has been enqueued by the given Access Category.
void SetWifiMac(Ptr< WifiMac > mac) override
Set the wifi MAC.
static TypeId GetTypeId()
Get the type ID.
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.
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:999
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< WifiMac > GetMac() const
Get the wifi MAC.
void SetPriority(AcIndex ac, const WifiContainerQueueId &queueId, const WifiSchedPrecedence< Time > &priority)
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition callback.h:690
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#define NS_LOG_TEMPLATE_DEFINE(name)
Initialize a reference to a Log component.
Definition log.h:228
#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:64
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > StaticCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:650
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
Definition wifi-ppdu.h:38
double Watt_u
Watt weak type.
Definition wifi-units.h:25