1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 /* 3 * Copyright (c) 2010 TELEMATICS LAB, DEE - Politecnico di Bari 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: Giuseppe Piro <g.piro@poliba.it> 19 * Author: Marco Miozzo <marco.miozzo@cttc.es> 20 */ 21 22 #ifndef ENB_LTE_PHY_H 23 #define ENB_LTE_PHY_H 24 25 26 #include <ns3/lte-control-messages.h> 27 #include <ns3/lte-enb-phy-sap.h> 28 #include <ns3/lte-enb-cphy-sap.h> 29 #include <ns3/lte-phy.h> 30 #include <ns3/lte-harq-phy.h> 31 32 #include <map> 33 #include <set> 34 35 36 37 namespace ns3 { 38 39 class PacketBurst; 40 class LteNetDevice; 41 class LteUePhy; 42 43 /** 44 * \ingroup lte 45 * LteEnbPhy models the physical layer for the eNodeB 46 */ 47 class LteEnbPhy : public LtePhy 48 { 49 /// allow EnbMemberLteEnbPhySapProvider class friend access 50 friend class EnbMemberLteEnbPhySapProvider; 51 /// allow MemberLteEnbCphySapProvider<LteEnbPhy> class friend access 52 friend class MemberLteEnbCphySapProvider<LteEnbPhy>; 53 54 public: 55 /** 56 * @warning the default constructor should not be used 57 */ 58 LteEnbPhy (); 59 60 /** 61 * 62 * \param dlPhy the downlink LteSpectrumPhy instance 63 * \param ulPhy the uplink LteSpectrumPhy instance 64 */ 65 LteEnbPhy (Ptr<LteSpectrumPhy> dlPhy, Ptr<LteSpectrumPhy> ulPhy); 66 67 virtual ~LteEnbPhy (); 68 69 /** 70 * \brief Get the type ID. 71 * \return the object TypeId 72 */ 73 static TypeId GetTypeId (void); 74 // inherited from Object 75 virtual void DoInitialize (void); 76 virtual void DoDispose (void); 77 78 79 /** 80 * \brief Get the PHY SAP provider 81 * \return a pointer to the SAP Provider of the PHY 82 */ 83 LteEnbPhySapProvider* GetLteEnbPhySapProvider (); 84 85 /** 86 * \brief Set the PHY SAP User 87 * \param s a pointer to the PHY SAP user 88 */ 89 void SetLteEnbPhySapUser (LteEnbPhySapUser* s); 90 91 /** 92 * \brief Get the CPHY SAP provider 93 * \return a pointer to the SAP Provider 94 */ 95 LteEnbCphySapProvider* GetLteEnbCphySapProvider (); 96 97 /** 98 * \brief Set the CPHY SAP User 99 * \param s a pointer to the SAP user 100 */ 101 void SetLteEnbCphySapUser (LteEnbCphySapUser* s); 102 103 /** 104 * \param pow the transmission power in dBm 105 */ 106 void SetTxPower (double pow); 107 108 /** 109 * \return the transmission power in dBm 110 */ 111 double GetTxPower () const; 112 113 /** 114 * \return the transmission power in dBm 115 */ 116 int8_t DoGetReferenceSignalPower () const; 117 118 /** 119 * \param pow the noise figure in dB 120 */ 121 void SetNoiseFigure (double pow); 122 123 /** 124 * \return the noise figure in dB 125 */ 126 double GetNoiseFigure () const; 127 128 /** 129 * \param delay the TTI delay between MAC and channel 130 */ 131 void SetMacChDelay (uint8_t delay); 132 133 /** 134 * \returns the TTI delay between MAC and channel 135 */ 136 uint8_t GetMacChDelay (void) const; 137 138 /** 139 * \return a pointer to the LteSpectrumPhy instance relative to the downlink 140 */ 141 Ptr<LteSpectrumPhy> GetDlSpectrumPhy () const; 142 143 /** 144 * \return a pointer to the LteSpectrumPhy instance relative to the uplink 145 */ 146 Ptr<LteSpectrumPhy> GetUlSpectrumPhy () const; 147 148 149 /** 150 * \brief set the resource blocks (a.k.a. sub channels) to be used in the downlink for transmission 151 * 152 * \param mask a vector of integers, if the i-th value is j it means 153 * that the j-th resource block is used for transmission in the 154 * downlink. If there is no i such that the value of the i-th 155 * element is j, it means that RB j is not used. 156 */ 157 void SetDownlinkSubChannels (std::vector<int> mask ); 158 159 /** 160 * \brief set the resource blocks (a.k.a. sub channels) and its power 161 * to be used in the downlink for transmission 162 * 163 * \param mask a vector of integers, if the i-th value is j it means 164 * that the j-th resource block is used for transmission in the 165 * downlink. If there is no i such that the value of the i-th 166 * element is j, it means that RB j is not used. 167 */ 168 void SetDownlinkSubChannelsWithPowerAllocation (std::vector<int> mask); 169 /** 170 * 171 * \return a vector of integers, if the i-th value is j it means 172 * that the j-th resource block is used for transmission in the 173 * downlink. If there is no i such that the value of the i-th 174 * element is j, it means that RB j is not used. 175 */ 176 std::vector<int> GetDownlinkSubChannels (void); 177 178 179 /** 180 * \brief Generate power allocation map (i.e. tx power level for each RB) 181 * 182 * \param rnti indicates which UE will occupy this RB 183 * \param rbId indicates which RB UE is using, 184 * power level for this RB is power level of UE 185 */ 186 void GeneratePowerAllocationMap (uint16_t rnti, int rbId); 187 188 /** 189 * \brief Create the PSD for TX 190 * \returns the PSD 191 */ 192 virtual Ptr<SpectrumValue> CreateTxPowerSpectralDensity (); 193 194 /** 195 * \brief Create the PSD for TX with power allocation for each RB 196 * \return the PSD 197 */ 198 virtual Ptr<SpectrumValue> CreateTxPowerSpectralDensityWithPowerAllocation (); 199 200 /** 201 * \brief Calculate the channel quality for a given UE 202 * \param sinr a list of computed SINR 203 * \param ue the UE 204 */ 205 void CalcChannelQualityForUe (std::vector <double> sinr, Ptr<LteSpectrumPhy> ue); 206 207 /** 208 * \brief Receive the control message 209 * \param msg the received message 210 */ 211 virtual void ReceiveLteControlMessage (Ptr<LteControlMessage> msg); 212 213 /** 214 * \brief Create the UL CQI feedback from SINR values perceived at 215 * the physical layer with the PUSCH signal received from eNB 216 * \param sinr SINR values vector 217 * \return UL CQI feedback in the format usable by an FF MAC scheduler 218 */ 219 FfMacSchedSapProvider::SchedUlCqiInfoReqParameters CreatePuschCqiReport (const SpectrumValue& sinr); 220 221 /** 222 * \brief Create the UL CQI feedback from SINR values perceived at 223 * the physical layer with the SRS signal received from eNB 224 * \param sinr SINR values vector 225 * \return UL CQI feedback in the format usable by an FF MAC scheduler 226 */ 227 FfMacSchedSapProvider::SchedUlCqiInfoReqParameters CreateSrsCqiReport (const SpectrumValue& sinr); 228 229 /** 230 * \brief Send the PDCCH and PCFICH in the first 3 symbols 231 * \param ctrlMsgList the list of control messages of PDCCH 232 */ 233 void SendControlChannels (std::list<Ptr<LteControlMessage> > ctrlMsgList); 234 235 /** 236 * \brief Send the PDSCH 237 * \param pb the PacketBurst to be sent 238 */ 239 void SendDataChannels (Ptr<PacketBurst> pb); 240 241 /** 242 * \param m the UL-CQI to be queued 243 */ 244 void QueueUlDci (UlDciLteControlMessage m); 245 246 /** 247 * \returns the list of UL-CQI to be processed 248 */ 249 std::list<UlDciLteControlMessage> DequeueUlDci (void); 250 251 252 /** 253 * \brief Start a LTE frame 254 */ 255 void StartFrame (void); 256 /** 257 * \brief Start a LTE sub frame 258 */ 259 void StartSubFrame (void); 260 /** 261 * \brief End a LTE sub frame 262 */ 263 void EndSubFrame (void); 264 /** 265 * \brief End a LTE frame 266 */ 267 void EndFrame (void); 268 269 /** 270 * \brief PhySpectrum received a new PHY-PDU 271 * \param p the packet received 272 */ 273 void PhyPduReceived (Ptr<Packet> p); 274 275 /** 276 * \brief PhySpectrum received a new list of LteControlMessage 277 */ 278 virtual void ReceiveLteControlMessageList (std::list<Ptr<LteControlMessage> >); 279 280 // inherited from LtePhy 281 virtual void GenerateCtrlCqiReport (const SpectrumValue& sinr); 282 virtual void GenerateDataCqiReport (const SpectrumValue& sinr); 283 virtual void ReportInterference (const SpectrumValue& interf); 284 virtual void ReportRsReceivedPower (const SpectrumValue& power); 285 286 287 288 /** 289 * \brief Report the uplink HARQ feedback generated by LteSpectrumPhy to MAC 290 * 291 * \param mes UlInfoListElement_s 292 */ 293 virtual void ReportUlHarqFeedback (UlInfoListElement_s mes); 294 295 /** 296 * \brief Set the HARQ Phy module 297 * 298 * \param harq the HARQ Phy 299 */ 300 void SetHarqPhyModule (Ptr<LteHarqPhy> harq); 301 302 /** 303 * TracedCallback signature for the linear average of SRS SINRs. 304 * 305 * \param [in] cellId 306 * \param [in] rnti 307 * \param [in] sinrLinear 308 */ 309 typedef void (* ReportUeSinrTracedCallback) 310 (uint16_t cellId, uint16_t rnti, double sinrLinear, uint8_t componentCarrierId); 311 312 /** 313 * TracedCallback signature for the linear average of SRS SINRs. 314 * 315 * \param [in] cellId 316 * \param [in] spectrumValue 317 * \deprecated The non-const \c Ptr<SpectrumValue> argument is deprecated 318 * and will be changed to \c Ptr<const SpectrumValue> in a future release. 319 */ 320 typedef void (* ReportInterferenceTracedCallback) 321 (uint16_t cellId, Ptr<SpectrumValue> spectrumValue); 322 323 private: 324 325 // LteEnbCphySapProvider forwarded methods 326 /** 327 * Set bandwidth function 328 * 329 * \param ulBandwidth UL bandwidth 330 * \param dlBandwidth DL bandwidth 331 */ 332 void DoSetBandwidth (uint16_t ulBandwidth, uint16_t dlBandwidth); 333 /** 334 * Set EARFCN 335 * 336 * \param dlEarfcn DL EARFCN 337 * \param ulEarfcn UL EARFCN 338 */ 339 void DoSetEarfcn (uint32_t dlEarfcn, uint32_t ulEarfcn); 340 /** 341 * Add UE 342 * 343 * \param rnti RNTI 344 */ 345 void DoAddUe (uint16_t rnti); 346 /** 347 * Remove UE 348 * 349 * \param rnti RNTI 350 */ 351 void DoRemoveUe (uint16_t rnti); 352 /** 353 * Set PA 354 * 355 * \param rnti RNTI 356 * \param pa PA 357 */ 358 void DoSetPa (uint16_t rnti, double pa); 359 /** 360 * Set transmission mode 361 * 362 * \param rnti RNTI 363 * \param txMode transmit mode 364 */ 365 void DoSetTransmissionMode (uint16_t rnti, uint8_t txMode); 366 /** 367 * Set source configuration index 368 * 369 * \param rnti RNTI 370 * \param srcCi source configuration index 371 */ 372 void DoSetSrsConfigurationIndex (uint16_t rnti, uint16_t srcCi); 373 /** 374 * Set master information block 375 * 376 * \param mib LteRrcSap::MasterInformationBlock 377 */ 378 void DoSetMasterInformationBlock (LteRrcSap::MasterInformationBlock mib); 379 /** 380 * Set system information block 381 * 382 * \param sib1 LteRrcSap::SystemInformationBlockType1 383 */ 384 void DoSetSystemInformationBlockType1 (LteRrcSap::SystemInformationBlockType1 sib1); 385 386 // LteEnbPhySapProvider forwarded methods 387 void DoSendMacPdu (Ptr<Packet> p); 388 /** 389 * Send LTE Control Message function 390 * 391 * \param msg LTE control message 392 */ 393 void DoSendLteControlMessage (Ptr<LteControlMessage> msg); 394 /** 395 * Get MAC ch TTI delay function 396 * 397 * \returns delay value 398 */ 399 uint8_t DoGetMacChTtiDelay (); 400 401 /** 402 * Add the given RNTI to the list of attached UE #m_ueAttached. 403 * \param rnti RNTI of a UE 404 * \return true if the RNTI has _not_ existed before, or false otherwise. 405 */ 406 bool AddUePhy (uint16_t rnti); 407 /** 408 * Remove the given RNTI from the list of attached UE #m_ueAttached. 409 * \param rnti RNTI of a UE 410 * \return true if the RNTI has existed before, or false otherwise. 411 */ 412 bool DeleteUePhy (uint16_t rnti); 413 414 /** 415 * Create SRS report function 416 * 417 * \param rnti the RNTI 418 * \param srs the SRS 419 */ 420 void CreateSrsReport (uint16_t rnti, double srs); 421 422 /** 423 * List of RNTI of attached UEs. Used for quickly determining whether a UE is 424 * attached to this eNodeB or not. 425 */ 426 std::set <uint16_t> m_ueAttached; 427 428 429 /// P_A per UE RNTI. 430 std::map <uint16_t,double> m_paMap; 431 432 /// DL power allocation map. 433 std::map <int, double> m_dlPowerAllocationMap; 434 435 /** 436 * A vector of integers, if the i-th value is j it means that the j-th 437 * resource block is used for transmission in the downlink. If there is 438 * no i such that the value of the i-th element is j, it means that RB j 439 * is not used. 440 */ 441 std::vector <int> m_listOfDownlinkSubchannel; 442 443 std::vector <int> m_dlDataRbMap; ///< DL data RB map 444 445 /// For storing info on future receptions. 446 std::vector< std::list<UlDciLteControlMessage> > m_ulDciQueue; 447 448 LteEnbPhySapProvider* m_enbPhySapProvider; ///< ENB Phy SAP provider 449 LteEnbPhySapUser* m_enbPhySapUser; ///< ENB Phy SAP user 450 451 LteEnbCphySapProvider* m_enbCphySapProvider; ///< ENB CPhy SAP provider 452 LteEnbCphySapUser* m_enbCphySapUser; ///< ENB CPhy SAP user 453 454 /** 455 * The frame number currently served. In ns-3, frame number starts from 1. 456 * In contrast, the 3GPP standard's frame number starts from 0. 457 */ 458 uint32_t m_nrFrames; 459 /** 460 * The subframe number currently served. In ns-3, subframe number starts 461 * from 1. In contrast, the 3GPP standard's subframe number starts from 0. 462 * The number resets to the beginning again after 10 subframes. 463 */ 464 uint32_t m_nrSubFrames; 465 466 uint16_t m_srsPeriodicity; ///< SRS periodicity 467 Time m_srsStartTime; ///< SRS start time 468 std::map <uint16_t,uint16_t> m_srsCounter; ///< SRS counter 469 std::vector <uint16_t> m_srsUeOffset; ///< SRS UE offset 470 uint16_t m_currentSrsOffset; ///< current SRS offset 471 472 /** 473 * The Master Information Block message to be broadcasted every frame. 474 * The message content is specified by the upper layer through the RRC SAP. 475 */ 476 LteRrcSap::MasterInformationBlock m_mib; 477 /** 478 * The System Information Block Type 1 message to be broadcasted. SIB1 is 479 * broadcasted every 6th subframe of every odd-numbered radio frame. 480 * The message content is specified by the upper layer through the RRC SAP. 481 */ 482 LteRrcSap::SystemInformationBlockType1 m_sib1; 483 484 Ptr<LteHarqPhy> m_harqPhyModule; ///< HARQ Phy module 485 486 /** 487 * The `ReportUeSinr` trace source. Reporting the linear average of SRS SINR. 488 * Exporting cell ID, RNTI, SINR in linear unit and ComponentCarrierId 489 */ 490 TracedCallback<uint16_t, uint16_t, double, uint8_t> m_reportUeSinr; 491 /** 492 * The `UeSinrSamplePeriod` trace source. The sampling period for reporting 493 * UEs' SINR stats. 494 */ 495 uint16_t m_srsSamplePeriod; 496 std::map <uint16_t,uint16_t> m_srsSampleCounterMap; ///< SRS sample counter map 497 498 /** 499 * The `ReportInterference` trace source. Reporting the interference per PHY 500 * RB (TS 36.214 section 5.2.2, measured on DATA). Exporting cell ID and 501 * interference linear power per RB basis. 502 * \deprecated The non-const \c Ptr<SpectrumValue> argument is deprecated 503 * and will be changed to \c Ptr<const SpectrumValue> in a future release. 504 */ 505 TracedCallback<uint16_t, Ptr<SpectrumValue> > m_reportInterferenceTrace; 506 /** 507 * The `InterferenceSamplePeriod` attribute. The sampling period for 508 * reporting interference stats. 509 * \todo In what unit is this? 510 */ 511 uint16_t m_interferenceSamplePeriod; 512 uint16_t m_interferenceSampleCounter; ///< interference sample counter 513 514 /** 515 * The `DlPhyTransmission` trace source. Contains trace information regarding 516 * PHY stats from DL Tx perspective. Exporting a structure with type 517 * PhyTransmissionStatParameters. 518 */ 519 TracedCallback<PhyTransmissionStatParameters> m_dlPhyTransmission; 520 521 }; // end of `class LteEnbPhy` 522 523 524 } 525 526 #endif /* LTE_ENB_PHY_H */ 527