1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2020 Universita' degli Studi di Napoli Federico II
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: Stefano Avallone <stavallo@unina.it>
19  */
20 
21 #ifndef MULTI_USER_SCHEDULER_H
22 #define MULTI_USER_SCHEDULER_H
23 
24 #include "ns3/object.h"
25 #include "he-ru.h"
26 #include "ns3/ctrl-headers.h"
27 #include "ns3/ap-wifi-mac.h"
28 #include "ns3/wifi-mac-queue.h"
29 #include "ns3/wifi-tx-parameters.h"
30 #include "ns3/wifi-remote-station-manager.h"
31 #include <unordered_map>
32 
33 namespace ns3 {
34 
35 class HeFrameExchangeManager;
36 
37 typedef std::unordered_map <uint16_t /* staId */, Ptr<WifiPsdu> /* PSDU */> WifiPsduMap;
38 
39 /**
40  * \ingroup wifi
41  *
42  * MultiUserScheduler is an abstract base class defining the API that APs
43  * supporting at least VHT can use to determine the format of their next transmission.
44  * VHT APs can only transmit DL MU PPDUs by using MU-MIMO, while HE APs can
45  * transmit both DL MU PPDUs and UL MU PPDUs by using OFDMA in addition to MU-MIMO.
46  *
47  * However, given that DL MU-MIMO is not yet supported, a MultiUserScheduler can
48  * only be aggregated to HE APs.
49  */
50 class MultiUserScheduler : public Object
51 {
52 public:
53   /**
54    * \brief Get the type ID.
55    * \return the object TypeId
56    */
57   static TypeId GetTypeId (void);
58   MultiUserScheduler ();
59   virtual ~MultiUserScheduler ();
60 
61   /// Enumeration of the possible transmission formats
62   enum TxFormat
63   {
64     NO_TX = 0,
65     SU_TX,
66     DL_MU_TX,
67     UL_MU_TX
68   };
69 
70   /// Information to be provided in case of DL MU transmission
71   struct DlMuInfo
72   {
73     WifiPsduMap psduMap;            //!< the DL MU PPDU to transmit
74     WifiTxParameters txParams;      //!< the transmission parameters
75   };
76 
77   /// Information to be provided in case of UL MU transmission
78   struct UlMuInfo
79   {
80     Ptr<WifiMacQueueItem> trigger;  //!< the Trigger frame used to solicit TB PPDUs
81     Time tbPpduDuration;            //!< the duration of the solicited TB PPDU
82     WifiTxParameters txParams;      //!< the transmission parameters for the Trigger Frame
83   };
84 
85   /**
86    * Notify the Multi-user Scheduler that the given AC of the AP gained channel
87    * access. The Multi-user Scheduler determines the format of the next transmission.
88    *
89    * \param edca the EDCAF which has been granted the opportunity to transmit
90    * \param availableTime the amount of time allowed for the frame exchange. Pass
91    *                      Time::Min() in case the TXOP limit is null
92    * \param initialFrame true if the frame being transmitted is the initial frame
93    *                     of the TXOP. This is used to determine whether the TXOP
94    *                     limit can be exceeded
95    * \return the format of the next transmission
96    */
97   TxFormat NotifyAccessGranted (Ptr<QosTxop> edca, Time availableTime, bool initialFrame);
98 
99   /**
100    * Get the information required to perform a DL MU transmission. Note
101    * that this method can only be called if GetTxFormat returns DL_MU_TX.
102    *
103    * \return the information required to perform a DL MU transmission
104    */
105   DlMuInfo& GetDlMuInfo (void);
106 
107   /**
108    * Get the information required to solicit an UL MU transmission. Note
109    * that this method can only be called if GetTxFormat returns UL_MU_TX.
110    *
111    * \return the information required to solicit an UL MU transmission
112    */
113   UlMuInfo& GetUlMuInfo (void);
114 
115 protected:
116   /**
117    * Get the station manager attached to the AP.
118    *
119    * \return the station manager attached to the AP
120    */
121   Ptr<WifiRemoteStationManager> GetWifiRemoteStationManager (void) const;
122 
123   /**
124    * Get the format of the last transmission, as determined by the last call
125    * to NotifyAccessGranted that did not return NO_TX.
126    *
127    * \return the format of the last transmission
128    */
129   TxFormat GetLastTxFormat (void) const;
130 
131   void DoDispose (void) override;
132   void NotifyNewAggregate (void) override;
133   void DoInitialize (void) override;
134 
135   Ptr<ApWifiMac> m_apMac;                //!< the AP wifi MAC
136   Ptr<HeFrameExchangeManager> m_heFem;   //!< HE Frame Exchange Manager
137   Ptr<QosTxop> m_edca;                   //!< the AC that gained channel access
138   Time m_availableTime;                  //!< the time available for frame exchange
139   bool m_initialFrame;                   //!< true if a TXOP is being started
140   uint32_t m_sizeOf8QosNull;             //!< size in bytes of 8 QoS Null frames
141 
142 private:
143   /**
144    * Set the wifi MAC. Note that it must be the MAC of an HE AP.
145    *
146    * \param mac the AP wifi MAC
147    */
148   void SetWifiMac (Ptr<ApWifiMac> mac);
149 
150   /**
151    * Select the format of the next transmission.
152    *
153    * \return the format of the next transmission
154    */
155   virtual TxFormat SelectTxFormat (void) = 0;
156 
157   /**
158    * Compute the information required to perform a DL MU transmission.
159    *
160    * \return the information required to perform a DL MU transmission
161    */
162   virtual DlMuInfo ComputeDlMuInfo (void) = 0;
163 
164   /**
165    * Prepare the information required to solicit an UL MU transmission.
166    *
167    * \return the information required to solicit an UL MU transmission
168    */
169   virtual UlMuInfo ComputeUlMuInfo (void) = 0;
170 
171   TxFormat m_lastTxFormat {NO_TX};       //!< the format of last transmission
172   DlMuInfo m_dlInfo;                     //!< information required to perform a DL MU transmission
173   UlMuInfo m_ulInfo;                     //!< information required to solicit an UL MU transmission
174 };
175 
176 } //namespace ns3
177 
178 #endif /* MULTI_USER_SCHEDULER_H */
179