1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
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: Marco Miozzo <marco.miozzo@cttc.es>
19  * Modification: Dizhi Zhou <dizhi.zhou@gmail.com>    // modify codes related to downlink scheduler
20  */
21 
22 #ifndef TDBET_FF_MAC_SCHEDULER_H
23 #define TDBET_FF_MAC_SCHEDULER_H
24 
25 #include <ns3/lte-common.h>
26 #include <ns3/ff-mac-csched-sap.h>
27 #include <ns3/ff-mac-sched-sap.h>
28 #include <ns3/ff-mac-scheduler.h>
29 #include <vector>
30 #include <map>
31 #include <ns3/nstime.h>
32 #include <ns3/lte-amc.h>
33 #include <ns3/lte-ffr-sap.h>
34 
35 // value for SINR outside the range defined by FF-API, used to indicate that there
36 // is no CQI for this element
37 #define NO_SINR -5000
38 
39 
40 #define HARQ_PROC_NUM 8
41 #define HARQ_DL_TIMEOUT 11
42 
43 namespace ns3 {
44 
45 
46 typedef std::vector < uint8_t > DlHarqProcessesStatus_t;
47 typedef std::vector < uint8_t > DlHarqProcessesTimer_t;
48 typedef std::vector < DlDciListElement_s > DlHarqProcessesDciBuffer_t;
49 typedef std::vector < std::vector <struct RlcPduListElement_s> > RlcPduList_t; // vector of the LCs and layers per UE
50 typedef std::vector < RlcPduList_t > DlHarqRlcPduListBuffer_t; // vector of the 8 HARQ processes per UE
51 
52 typedef std::vector < UlDciListElement_s > UlHarqProcessesDciBuffer_t;
53 typedef std::vector < uint8_t > UlHarqProcessesStatus_t;
54 
55 
56 /// tdbetsFlowPerf_t structure
57 struct tdbetsFlowPerf_t
58 {
59   Time flowStart; ///< flow start time
60   unsigned long totalBytesTransmitted; ///< total bytes transmitted
61   unsigned int lastTtiBytesTrasmitted; ///< last total bytes transmitted
62   double lastAveragedThroughput; ///< last average throughput
63 };
64 
65 
66 /**
67  * \ingroup ff-api
68  * \brief Implements the SCHED SAP and CSCHED SAP for a Time Domain Blind Equal Throughput scheduler
69  *
70  * This class implements the interface defined by the FfMacScheduler abstract class
71  */
72 
73 class TdBetFfMacScheduler : public FfMacScheduler
74 {
75 public:
76   /**
77    * \brief Constructor
78    *
79    * Creates the MAC Scheduler interface implementation
80    */
81   TdBetFfMacScheduler ();
82 
83   /**
84    * Destructor
85    */
86   virtual ~TdBetFfMacScheduler ();
87 
88   // inherited from Object
89   virtual void DoDispose (void);
90   /**
91    * \brief Get the type ID.
92    * \return the object TypeId
93    */
94   static TypeId GetTypeId (void);
95 
96   // inherited from FfMacScheduler
97   virtual void SetFfMacCschedSapUser (FfMacCschedSapUser* s);
98   virtual void SetFfMacSchedSapUser (FfMacSchedSapUser* s);
99   virtual FfMacCschedSapProvider* GetFfMacCschedSapProvider ();
100   virtual FfMacSchedSapProvider* GetFfMacSchedSapProvider ();
101 
102   // FFR SAPs
103   virtual void SetLteFfrSapProvider (LteFfrSapProvider* s);
104   virtual LteFfrSapUser* GetLteFfrSapUser ();
105 
106   /// allow MemberCschedSapProvider<TdBetFfMacScheduler> class friend access
107   friend class MemberCschedSapProvider<TdBetFfMacScheduler>;
108   /// allow MemberSchedSapProvider<TdBetFfMacScheduler> class friend access
109   friend class MemberSchedSapProvider<TdBetFfMacScheduler>;
110 
111   /**
112    * \brief Transmission mode configuration update function
113    * \param rnti the RNTI
114    * \param txMode the transmission mode
115    */
116   void TransmissionModeConfigurationUpdate (uint16_t rnti, uint8_t txMode);
117 
118 private:
119   //
120   // Implementation of the CSCHED API primitives
121   // (See 4.1 for description of the primitives)
122   //
123 
124   /**
125    * \brief CSched cell config request
126    * \param params FfMacCschedSapProvider::CschedCellConfigReqParameters
127    */
128   void DoCschedCellConfigReq (const struct FfMacCschedSapProvider::CschedCellConfigReqParameters& params);
129 
130   /**
131    * \brief CSched UE config request
132    * \param params FfMacCschedSapProvider::CschedUeConfigReqParameters
133    */
134   void DoCschedUeConfigReq (const struct FfMacCschedSapProvider::CschedUeConfigReqParameters& params);
135 
136   /**
137    * \brief CSched LC config request
138    * \param params FfMacCschedSapProvider::CschedLcConfigReqParameters
139    */
140   void DoCschedLcConfigReq (const struct FfMacCschedSapProvider::CschedLcConfigReqParameters& params);
141 
142   /**
143    * \brief CSched LC release request
144    * \param params FfMacCschedSapProvider::CschedLcReleaseReqParameters
145    */
146   void DoCschedLcReleaseReq (const struct FfMacCschedSapProvider::CschedLcReleaseReqParameters& params);
147 
148   /**
149    * \brief CSched UE release request
150    * \param params FfMacCschedSapProvider::CschedUeReleaseReqParameters
151    */
152   void DoCschedUeReleaseReq (const struct FfMacCschedSapProvider::CschedUeReleaseReqParameters& params);
153 
154   //
155   // Implementation of the SCHED API primitives
156   // (See 4.2 for description of the primitives)
157   //
158 
159   /**
160    * \brief Sched DL RLC buffer request
161    * \param params FfMacSchedSapProvider::SchedDlRlcBufferReqParameters
162    */
163   void DoSchedDlRlcBufferReq (const struct FfMacSchedSapProvider::SchedDlRlcBufferReqParameters& params);
164 
165   /**
166    * \brief Sched DL paging buffer request
167    * \param params FfMacSchedSapProvider::SchedDlPagingBufferReqParameters
168    */
169   void DoSchedDlPagingBufferReq (const struct FfMacSchedSapProvider::SchedDlPagingBufferReqParameters& params);
170 
171   /**
172    * \brief Sched DL MAC buffer request
173    * \param params FfMacSchedSapProvider::SchedDlMacBufferReqParameters
174    */
175   void DoSchedDlMacBufferReq (const struct FfMacSchedSapProvider::SchedDlMacBufferReqParameters& params);
176 
177   /**
178    * \brief Sched DL trigger request
179    * \param params FfMacSchedSapProvider::SchedDlTriggerReqParameters
180    */
181   void DoSchedDlTriggerReq (const struct FfMacSchedSapProvider::SchedDlTriggerReqParameters& params);
182 
183   /**
184    * \brief Sched DL RACH info request
185    * \param params FfMacSchedSapProvider::SchedDlRachInfoReqParameters
186    */
187   void DoSchedDlRachInfoReq (const struct FfMacSchedSapProvider::SchedDlRachInfoReqParameters& params);
188 
189   /**
190    * \brief Sched DL CQI info request
191    * \param params FfMacSchedSapProvider::SchedDlCqiInfoReqParameters
192    */
193   void DoSchedDlCqiInfoReq (const struct FfMacSchedSapProvider::SchedDlCqiInfoReqParameters& params);
194 
195   /**
196    * \brief Sched UL trigger request
197    * \param params FfMacSchedSapProvider::SchedUlTriggerReqParameters
198    */
199   void DoSchedUlTriggerReq (const struct FfMacSchedSapProvider::SchedUlTriggerReqParameters& params);
200 
201   /**
202    * \brief Sched UL noise interference request
203    * \param params FfMacSchedSapProvider::SchedUlNoiseInterferenceReqParameters
204    */
205   void DoSchedUlNoiseInterferenceReq (const struct FfMacSchedSapProvider::SchedUlNoiseInterferenceReqParameters& params);
206 
207   /**
208    * \brief Sched UL SR info request
209    * \param params FfMacSchedSapProvider::SchedUlSrInfoReqParameters
210    */
211   void DoSchedUlSrInfoReq (const struct FfMacSchedSapProvider::SchedUlSrInfoReqParameters& params);
212 
213   /**
214    * \brief Sched UL MAC control info request
215    * \param params FfMacSchedSapProvider::SchedUlMacCtrlInfoReqParameters
216    */
217   void DoSchedUlMacCtrlInfoReq (const struct FfMacSchedSapProvider::SchedUlMacCtrlInfoReqParameters& params);
218 
219   /**
220    * \brief Sched UL CQI info request
221    * \param params FfMacSchedSapProvider::SchedUlCqiInfoReqParameters
222    */
223   void DoSchedUlCqiInfoReq (const struct FfMacSchedSapProvider::SchedUlCqiInfoReqParameters& params);
224 
225   /**
226    * \brief Get RBG size function
227    * \param dlbandwidth DL bandwidth
228    * \returns RBG size
229    */
230   int GetRbgSize (int dlbandwidth);
231 
232   /**
233    * \brief LC active flow function
234    * \param rnti the RNTI
235    * \returns LC active flow
236    */
237   unsigned int LcActivePerFlow (uint16_t rnti);
238 
239   /**
240    * \brief Estimate UL SINR function
241    * \param rnti the RNTI
242    * \param rb the RB
243    * \returns SINR
244    */
245   double EstimateUlSinr (uint16_t rnti, uint16_t rb);
246 
247   /// Refresh DL CQI maps function
248   void RefreshDlCqiMaps (void);
249   /// Refresh UL CQI maps function
250   void RefreshUlCqiMaps (void);
251 
252   /**
253    * \brief Update DL RLC buffer info function
254    * \param rnti the RNTI
255    * \param lcid the LCID
256    * \param size the size
257    */
258   void UpdateDlRlcBufferInfo (uint16_t rnti, uint8_t lcid, uint16_t size);
259   /**
260    * \brief Update UL RLC buffer info function
261    * \param rnti the RNTI
262    * \param size the size
263    */
264   void UpdateUlRlcBufferInfo (uint16_t rnti, uint16_t size);
265 
266   /**
267   * \brief Update and return a new process Id for the RNTI specified
268   *
269   * \param rnti the RNTI of the UE to be updated
270   * \return the process id  value
271   */
272   uint8_t UpdateHarqProcessId (uint16_t rnti);
273 
274   /**
275   * \brief Return the availability of free process for the RNTI specified
276   *
277   * \param rnti the RNTI of the UE to be updated
278   * \return the process id  value
279   */
280   uint8_t HarqProcessAvailability (uint16_t rnti);
281 
282   /**
283   * \brief Refresh HARQ processes according to the timers
284   *
285   */
286   void RefreshHarqProcesses ();
287 
288   Ptr<LteAmc> m_amc; ///< AMC
289 
290   /**
291    * Vectors of UE's LC info
292   */
293   std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters> m_rlcBufferReq;
294 
295 
296   /**
297   * Map of UE statistics (per RNTI basis) in downlink
298   */
299   std::map <uint16_t, tdbetsFlowPerf_t> m_flowStatsDl;
300 
301   /**
302   * Map of UE statistics (per RNTI basis)
303   */
304   std::map <uint16_t, tdbetsFlowPerf_t> m_flowStatsUl;
305 
306 
307   /**
308   * Map of UE's DL CQI P01 received
309   */
310   std::map <uint16_t,uint8_t> m_p10CqiRxed;
311   /**
312   * Map of UE's timers on DL CQI P01 received
313   */
314   std::map <uint16_t,uint32_t> m_p10CqiTimers;
315 
316   /**
317   * Map of UE's DL CQI A30 received
318   */
319   std::map <uint16_t,SbMeasResult_s> m_a30CqiRxed;
320   /**
321   * Map of UE's timers on DL CQI A30 received
322   */
323   std::map <uint16_t,uint32_t> m_a30CqiTimers;
324 
325   /**
326   * Map of previous allocated UE per RBG
327   * (used to retrieve info from UL-CQI)
328   */
329   std::map <uint16_t, std::vector <uint16_t> > m_allocationMaps;
330 
331   /**
332   * Map of UEs' UL-CQI per RBG
333   */
334   std::map <uint16_t, std::vector <double> > m_ueCqi;
335   /**
336   * Map of UEs' timers on UL-CQI per RBG
337   */
338   std::map <uint16_t, uint32_t> m_ueCqiTimers;
339 
340   /**
341   * Map of UE's buffer status reports received
342   */
343   std::map <uint16_t,uint32_t> m_ceBsrRxed;
344 
345   // MAC SAPs
346   FfMacCschedSapUser* m_cschedSapUser; ///< CSched SAP user
347   FfMacSchedSapUser* m_schedSapUser; ///< Sched SAP user
348   FfMacCschedSapProvider* m_cschedSapProvider; ///< CSched SAP provider
349   FfMacSchedSapProvider* m_schedSapProvider; ///< Sched SAP provider
350 
351   // FFR SAPs
352   LteFfrSapUser* m_ffrSapUser; ///< FFR SAP user
353   LteFfrSapProvider* m_ffrSapProvider; ///< FFR SAP provider
354 
355   // Internal parameters
356   FfMacCschedSapProvider::CschedCellConfigReqParameters m_cschedCellConfig; ///< CSched cell config
357 
358 
359   double m_timeWindow; ///< time window
360 
361   uint16_t m_nextRntiUl; ///< RNTI of the next user to be served next scheduling in UL
362 
363   uint32_t m_cqiTimersThreshold; ///< # of TTIs for which a CQI can be considered valid
364 
365   std::map <uint16_t,uint8_t> m_uesTxMode; ///< txMode of the UEs
366 
367   // HARQ attributes
368   /**
369   * m_harqOn when false inhibit the HARQ mechanisms (by default active)
370   */
371   bool m_harqOn;
372   std::map <uint16_t, uint8_t> m_dlHarqCurrentProcessId; ///< DL HARQ process ID
373   //HARQ status
374   // 0: process Id available
375   // x>0: process Id equal to `x` transmission count
376   std::map <uint16_t, DlHarqProcessesStatus_t> m_dlHarqProcessesStatus; ///< DL HARQ process status
377   std::map <uint16_t, DlHarqProcessesTimer_t> m_dlHarqProcessesTimer; ///< DL HARQ process timer
378   std::map <uint16_t, DlHarqProcessesDciBuffer_t> m_dlHarqProcessesDciBuffer; ///< DL HARQ process DCI buffer
379   std::map <uint16_t, DlHarqRlcPduListBuffer_t> m_dlHarqProcessesRlcPduListBuffer; ///< DL HARQ process RLC PDU list buffer
380   std::vector <DlInfoListElement_s> m_dlInfoListBuffered; ///< HARQ retx buffered
381 
382   std::map <uint16_t, uint8_t> m_ulHarqCurrentProcessId; ///< UL HARQ current process ID
383   //HARQ status
384   // 0: process Id available
385   // x>0: process Id equal to `x` transmission count
386   std::map <uint16_t, UlHarqProcessesStatus_t> m_ulHarqProcessesStatus; ///< UL HARQ process status
387   std::map <uint16_t, UlHarqProcessesDciBuffer_t> m_ulHarqProcessesDciBuffer; ///< UL HARQ process DCI buffer
388 
389 
390   // RACH attributes
391   std::vector <struct RachListElement_s> m_rachList; ///< RACH list
392   std::vector <uint16_t> m_rachAllocationMap; ///< RACH allocation map
393   uint8_t m_ulGrantMcs; ///< MCS for UL grant (default 0)
394 
395 };
396 
397 } // namespace ns3
398 
399 #endif /* TDBET_FF_MAC_SCHEDULER_H */
400