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  *         Nicola Baldo  <nbaldo@cttc.es>
20  * Modified by:
21  *          Danilo Abrignani <danilo.abrignani@unibo.it> (Carrier Aggregation - GSoC 2015)
22  *          Biljana Bojovic <biljana.bojovic@cttc.es> (Carrier Aggregation)
23  */
24 
25 #ifndef LTE_ENB_MAC_H
26 #define LTE_ENB_MAC_H
27 
28 
29 #include <map>
30 #include <vector>
31 #include <ns3/lte-common.h>
32 #include <ns3/lte-mac-sap.h>
33 #include <ns3/lte-enb-cmac-sap.h>
34 #include <ns3/ff-mac-csched-sap.h>
35 #include <ns3/ff-mac-sched-sap.h>
36 #include <ns3/lte-enb-phy-sap.h>
37 #include "ns3/traced-value.h"
38 #include "ns3/trace-source-accessor.h"
39 #include <ns3/packet.h>
40 #include <ns3/packet-burst.h>
41 #include <ns3/lte-ccm-mac-sap.h>
42 
43 namespace ns3 {
44 
45 class DlCqiLteControlMessage;
46 class UlCqiLteControlMessage;
47 class PdcchMapLteControlMessage;
48 
49 /// DlHarqProcessesBuffer_t typedef
50 typedef std::vector <std::vector < Ptr<PacketBurst> > > DlHarqProcessesBuffer_t;
51 
52 /**
53  * This class implements the MAC layer of the eNodeB device
54  */
55 class LteEnbMac :   public Object
56 {
57   /// allow EnbMacMemberLteEnbCmacSapProvider class friend access
58   friend class EnbMacMemberLteEnbCmacSapProvider;
59   /// allow EnbMacMemberLteMacSapProvider<LteEnbMac> class friend access
60   friend class EnbMacMemberLteMacSapProvider<LteEnbMac>;
61   /// allow EnbMacMemberFfMacSchedSapUser class friend access
62   friend class EnbMacMemberFfMacSchedSapUser;
63   /// allow EnbMacMemberFfMacCschedSapUser class friend access
64   friend class EnbMacMemberFfMacCschedSapUser;
65   /// allow EnbMacMemberLteEnbPhySapUser class friend access
66   friend class EnbMacMemberLteEnbPhySapUser;
67   /// allow MemberLteCcmMacSapProvider<LteEnbMac> class friend access
68   friend class MemberLteCcmMacSapProvider<LteEnbMac>;
69 
70 public:
71   /**
72    * \brief Get the type ID.
73    * \return the object TypeId
74    */
75   static TypeId GetTypeId (void);
76 
77   LteEnbMac (void);
78   virtual ~LteEnbMac (void);
79   virtual void DoDispose (void);
80 
81   /**
82    * \brief Set the component carrier ID
83    * \param index the component carrier ID
84    */
85   void SetComponentCarrierId (uint8_t index);
86   /**
87    * \brief Set the scheduler SAP provider
88    * \param s a pointer SAP provider of the FF packet scheduler
89    */
90   void SetFfMacSchedSapProvider (FfMacSchedSapProvider* s);
91   /**
92    * \brief Get the scheduler SAP user
93    * \return a pointer to the SAP user of the scheduler
94    */
95   FfMacSchedSapUser* GetFfMacSchedSapUser (void);
96   /**
97    * \brief Set the control scheduler SAP provider
98    * \param s a pointer to the control scheduler SAP provider
99    */
100   void SetFfMacCschedSapProvider (FfMacCschedSapProvider* s);
101   /**
102    * \brief Get the control scheduler SAP user
103    * \return a pointer to the control scheduler SAP user
104    */
105   FfMacCschedSapUser* GetFfMacCschedSapUser (void);
106 
107 
108 
109   /**
110    * \brief Set the MAC SAP user
111    * \param s a pointer to the MAC SAP user
112    */
113   void SetLteMacSapUser (LteMacSapUser* s);
114   /**
115    * \brief Get the MAC SAP provider
116    * \return a pointer to the SAP provider of the MAC
117    */
118   LteMacSapProvider* GetLteMacSapProvider (void);
119   /**
120    * \brief Set the control MAC SAP user
121    * \param s a pointer to the control MAC SAP user
122    */
123   void SetLteEnbCmacSapUser (LteEnbCmacSapUser* s);
124   /**
125    * \brief Get the control MAC SAP provider
126    * \return a pointer to the control MAC SAP provider
127    */
128   LteEnbCmacSapProvider* GetLteEnbCmacSapProvider (void);
129 
130 
131   /**
132   * \brief Get the eNB-PHY SAP User
133   * \return a pointer to the SAP User of the PHY
134   */
135   LteEnbPhySapUser* GetLteEnbPhySapUser ();
136 
137   /**
138   * \brief Set the PHY SAP Provider
139   * \param s a pointer to the PHY SAP provider
140   */
141   void SetLteEnbPhySapProvider (LteEnbPhySapProvider* s);
142 
143   /**
144   * \brief Get the eNB-ComponentCarrierManager SAP User
145   * \return a pointer to the SAP User of the ComponentCarrierManager
146   */
147   LteCcmMacSapProvider* GetLteCcmMacSapProvider ();
148 
149   /**
150   * \brief Set the ComponentCarrierManager SAP user
151   * \param s a pointer to the ComponentCarrierManager provider
152   */
153   void SetLteCcmMacSapUser (LteCcmMacSapUser* s);
154 
155 
156   /**
157    * TracedCallback signature for DL scheduling events.
158    *
159    * \param [in] frame Frame number.
160    * \param [in] subframe Subframe number.
161    * \param [in] rnti The C-RNTI identifying the UE.
162    * \param [in] mcs0 The MCS for transport block..
163    * \param [in] tbs0Size
164    * \param [in] mcs1 The MCS for transport block.
165    * \param [in] tbs1Size
166    * \param [in] component carrier id
167    */
168   typedef void (* DlSchedulingTracedCallback)
169     (const uint32_t frame, const uint32_t subframe, const uint16_t rnti,
170      const uint8_t mcs0, const uint16_t tbs0Size,
171      const uint8_t mcs1, const uint16_t tbs1Size, const uint8_t ccId);
172 
173   /**
174    *  TracedCallback signature for UL scheduling events.
175    *
176    * \param [in] frame Frame number.
177    * \param [in] subframe Subframe number.
178    * \param [in] rnti The C-RNTI identifying the UE.
179    * \param [in] mcs  The MCS for transport block
180    * \param [in] tbsSize
181    */
182   typedef void (* UlSchedulingTracedCallback)
183     (const uint32_t frame, const uint32_t subframe, const uint16_t rnti,
184      const uint8_t mcs, const uint16_t tbsSize);
185 
186 private:
187 
188   /**
189   * \brief Receive a DL CQI ideal control message
190   * \param msg the DL CQI message
191   */
192   void ReceiveDlCqiLteControlMessage  (Ptr<DlCqiLteControlMessage> msg);
193 
194   /**
195   * \brief Receive a DL CQI ideal control message
196   * \param msg the DL CQI message
197   */
198   void DoReceiveLteControlMessage (Ptr<LteControlMessage> msg);
199 
200   /**
201   * \brief Receive a CE element containing the buffer status report
202   * \param bsr the BSR message
203   */
204   void ReceiveBsrMessage  (MacCeListElement_s bsr);
205 
206   /**
207   * \brief UL CQI report
208   * \param ulcqi FfMacSchedSapProvider::SchedUlCqiInfoReqParameters
209   */
210   void DoUlCqiReport (FfMacSchedSapProvider::SchedUlCqiInfoReqParameters ulcqi);
211 
212 
213 
214   // forwarded from LteEnbCmacSapProvider
215   /**
216   * \brief Configure MAC function
217   * \param ulBandwidth the UL bandwidth
218   * \param dlBandwidth the DL bandwidth
219   */
220   void DoConfigureMac (uint16_t ulBandwidth, uint16_t dlBandwidth);
221   /**
222   * \brief Add UE function
223   * \param rnti the RNTI
224   */
225   void DoAddUe (uint16_t rnti);
226   /**
227   * \brief Remove UE function
228   * \param rnti the RNTI
229   */
230   void DoRemoveUe (uint16_t rnti);
231   /**
232   * \brief Add LC function
233   * \param lcinfo the LC info
234   * \param msu the LTE MAC SAP user
235   */
236   void DoAddLc (LteEnbCmacSapProvider::LcInfo lcinfo, LteMacSapUser* msu);
237   /**
238   * \brief Reconfigure LC function
239   * \param lcinfo the LC info
240   */
241   void DoReconfigureLc (LteEnbCmacSapProvider::LcInfo lcinfo);
242   /**
243   * \brief Release LC function
244   * \param rnti the RNTI
245   * \param lcid the LCID
246   */
247   void DoReleaseLc (uint16_t  rnti, uint8_t lcid);
248   /**
249   * \brief UE Update configuration request function
250   * \param params LteEnbCmacSapProvider::UeConfig
251   */
252   void DoUeUpdateConfigurationReq (LteEnbCmacSapProvider::UeConfig params);
253   /**
254   * \brief Get RACH configuration function
255   * \returns LteEnbCmacSapProvider::RachConfig
256   */
257   LteEnbCmacSapProvider::RachConfig DoGetRachConfig ();
258   /**
259   * \brief Allocate NC RA preamble function
260   * \param rnti the RNTI
261   * \returns LteEnbCmacSapProvider::AllocateNcRaPreambleReturnValue
262   */
263   LteEnbCmacSapProvider::AllocateNcRaPreambleReturnValue DoAllocateNcRaPreamble (uint16_t rnti);
264 
265   // forwarded from LteMacSapProvider
266   /**
267   * \brief Transmit PDU function
268   * \param params LteMacSapProvider::TransmitPduParameters
269   */
270   void DoTransmitPdu (LteMacSapProvider::TransmitPduParameters params);
271   /**
272   * \brief Report Buffer Status function
273   * \param params LteMacSapProvider::ReportBufferStatusParameters
274   */
275   void DoReportBufferStatus (LteMacSapProvider::ReportBufferStatusParameters params);
276 
277 
278   // forwarded from FfMacCchedSapUser
279   /**
280   * \brief CSched Cell Config configure function
281   * \param params FfMacCschedSapUser::CschedCellConfigCnfParameters
282   */
283   void DoCschedCellConfigCnf (FfMacCschedSapUser::CschedCellConfigCnfParameters params);
284   /**
285   * \brief CSched UE Config configure function
286   * \param params FfMacCschedSapUser::CschedUeConfigCnfParameters
287   */
288   void DoCschedUeConfigCnf (FfMacCschedSapUser::CschedUeConfigCnfParameters params);
289   /**
290   * \brief CSched LC Config configure function
291   * \param params FfMacCschedSapUser::CschedLcConfigCnfParameters
292   */
293   void DoCschedLcConfigCnf (FfMacCschedSapUser::CschedLcConfigCnfParameters params);
294   /**
295   * \brief CSched LC Release configure function
296   * \param params FfMacCschedSapUser::CschedLcReleaseCnfParameters
297   */
298   void DoCschedLcReleaseCnf (FfMacCschedSapUser::CschedLcReleaseCnfParameters params);
299   /**
300   * \brief CSched UE Release configure function
301   * \param params FfMacCschedSapUser::CschedUeReleaseCnfParameters
302   */
303   void DoCschedUeReleaseCnf (FfMacCschedSapUser::CschedUeReleaseCnfParameters params);
304   /**
305   * \brief CSched UE Config Update Indication function
306   * \param params FfMacCschedSapUser::CschedUeConfigUpdateIndParameters
307   */
308   void DoCschedUeConfigUpdateInd (FfMacCschedSapUser::CschedUeConfigUpdateIndParameters params);
309   /**
310   * \brief CSched Cell Config Update Indication function
311   * \param params FfMacCschedSapUser::CschedCellConfigUpdateIndParameters
312   */
313   void DoCschedCellConfigUpdateInd (FfMacCschedSapUser::CschedCellConfigUpdateIndParameters params);
314 
315   // forwarded from FfMacSchedSapUser
316   /**
317   * \brief Sched DL Config Indication function
318   * \param ind FfMacSchedSapUser::SchedDlConfigIndParameters
319   */
320   void DoSchedDlConfigInd (FfMacSchedSapUser::SchedDlConfigIndParameters ind);
321   /**
322   * \brief Sched UL Config Indication function
323   * \param params FfMacSchedSapUser::SchedUlConfigIndParameters
324   */
325   void DoSchedUlConfigInd (FfMacSchedSapUser::SchedUlConfigIndParameters params);
326 
327   // forwarded from LteEnbPhySapUser
328   /**
329   * \brief Subrame Indication function
330   * \param frameNo frame number
331   * \param subframeNo subframe number
332   */
333   void DoSubframeIndication (uint32_t frameNo, uint32_t subframeNo);
334   /**
335   * \brief Receive RACH Preamble function
336   * \param prachId PRACH ID number
337   */
338   void DoReceiveRachPreamble (uint8_t prachId);
339 
340   // forwarded by LteCcmMacSapProvider
341   /**
342    * Report MAC CE to scheduler
343    * \param bsr the BSR
344    */
345   void DoReportMacCeToScheduler (MacCeListElement_s bsr);
346 
347   /**
348    * \brief Report SR to scheduler
349    * \param rnti RNTI of the UE that requested the SR
350    *
351    * Since SR is not implemented in LTE, this method does nothing.
352    */
DoReportSrToScheduler(uint16_t rnti)353   void DoReportSrToScheduler (uint16_t rnti)
354   {
355     NS_UNUSED (rnti);
356   }
357 
358 public:
359   /**
360    * legacy public for use the Phy callback
361    * \param p packet
362    */
363   void DoReceivePhyPdu (Ptr<Packet> p);
364 
365 private:
366   /**
367   * \brief UL Info List ELements HARQ Feedback function
368   * \param params UlInfoListElement_s
369   */
370   void DoUlInfoListElementHarqFeeback (UlInfoListElement_s params);
371   /**
372   * \brief DL Info List ELements HARQ Feedback function
373   * \param params DlInfoListElement_s
374   */
375   void DoDlInfoListElementHarqFeeback (DlInfoListElement_s params);
376 
377   /// RNTI, LC ID, SAP of the RLC instance
378   std::map <uint16_t, std::map<uint8_t, LteMacSapUser*> > m_rlcAttached;
379 
380   std::vector <CqiListElement_s> m_dlCqiReceived; ///< DL-CQI received
381   std::vector <FfMacSchedSapProvider::SchedUlCqiInfoReqParameters> m_ulCqiReceived; ///< UL-CQI received
382   std::vector <MacCeListElement_s> m_ulCeReceived; ///< CE received (BSR up to now)
383 
384   std::vector <DlInfoListElement_s> m_dlInfoListReceived; ///< DL HARQ feedback received
385 
386   std::vector <UlInfoListElement_s> m_ulInfoListReceived; ///< UL HARQ feedback received
387 
388 
389   /*
390   * Map of UE's info element (see 4.3.12 of FF MAC Scheduler API)
391   */
392   //std::map <uint16_t,UlInfoListElement_s> m_ulInfoListElements;
393 
394 
395 
396   LteMacSapProvider* m_macSapProvider; ///< the MAC SAP provider
397   LteEnbCmacSapProvider* m_cmacSapProvider; ///< the CMAC SAP provider
398   LteMacSapUser* m_macSapUser; ///< the MAC SAP user
399   LteEnbCmacSapUser* m_cmacSapUser; ///< the CMAC SAP user
400 
401 
402   FfMacSchedSapProvider* m_schedSapProvider; ///< the Sched SAP provider
403   FfMacCschedSapProvider* m_cschedSapProvider; ///< the Csched SAP provider
404   FfMacSchedSapUser* m_schedSapUser; ///< the Sched SAP user
405   FfMacCschedSapUser* m_cschedSapUser; ///< the CSched SAP user
406 
407   // PHY-SAP
408   LteEnbPhySapProvider* m_enbPhySapProvider; ///< the ENB Phy SAP provider
409   LteEnbPhySapUser* m_enbPhySapUser; ///< the ENB Phy SAP user
410 
411   // Sap For ComponentCarrierManager 'Uplink case'
412   LteCcmMacSapProvider* m_ccmMacSapProvider; ///< CCM MAC SAP provider
413   LteCcmMacSapUser* m_ccmMacSapUser; ///< CCM MAC SAP user
414   /**
415    * frame number of current subframe indication
416    */
417   uint32_t m_frameNo;
418   /**
419    * subframe number of current subframe indication
420    */
421   uint32_t m_subframeNo;
422   /**
423    * Trace information regarding DL scheduling
424    * Frame number, Subframe number, RNTI, MCS of TB1, size of TB1,
425    * MCS of TB2 (0 if not present), size of TB2 (0 if not present)
426    */
427   TracedCallback<DlSchedulingCallbackInfo> m_dlScheduling;
428 
429   /**
430    * Trace information regarding UL scheduling
431    * Frame number, Subframe number, RNTI, MCS of TB, size of TB, component carrier id
432    */
433   TracedCallback<uint32_t, uint32_t, uint16_t,
434                  uint8_t, uint16_t, uint8_t> m_ulScheduling;
435 
436   uint8_t m_macChTtiDelay; ///< delay of MAC, PHY and channel in terms of TTIs
437 
438 
439   std::map <uint16_t, DlHarqProcessesBuffer_t> m_miDlHarqProcessesPackets; ///< Packet under transmission of the DL HARQ process
440 
441   uint8_t m_numberOfRaPreambles; ///< number of RA preambles
442   uint8_t m_preambleTransMax; ///< preamble transmit maximum
443   uint8_t m_raResponseWindowSize; ///< RA response window size
444   uint8_t m_connEstFailCount; ///< the counter value for T300 timer expiration
445 
446   /**
447    * info associated with a preamble allocated for non-contention based RA
448    *
449    */
450   struct NcRaPreambleInfo
451   {
452     uint16_t rnti; ///< rnti previously allocated for this non-contention based RA procedure
453     Time expiryTime; ///< value the expiration time of this allocation (so that stale preambles can be reused)
454   };
455 
456   /**
457    * map storing as key the random access preamble IDs allocated for
458    * non-contention based access, and as value the associated info
459    *
460    */
461   std::map<uint8_t, NcRaPreambleInfo> m_allocatedNcRaPreambleMap;
462 
463   std::map<uint8_t, uint32_t> m_receivedRachPreambleCount; ///< received RACH preamble count
464 
465   std::map<uint16_t, uint32_t> m_rapIdRntiMap; ///< RAPID RNTI map
466 
467   /// component carrier Id used to address sap
468   uint8_t m_componentCarrierId;
469 
470 };
471 
472 } // end namespace ns3
473 
474 #endif /* LTE_ENB_MAC_ENTITY_H */
475