1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011, 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4  * Copyright (c) 2018 Fraunhofer ESK : RLF extensions
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  * Authors: Nicola Baldo <nbaldo@cttc.es>
20  *          Marco Miozzo <mmiozzo@cttc.es>
21  *          Manuel Requena <manuel.requena@cttc.es>
22  * Modified by:
23  *          Danilo Abrignani <danilo.abrignani@unibo.it> (Carrier Aggregation - GSoC 2015)
24  *          Biljana Bojovic <biljana.bojovic@cttc.es> (Carrier Aggregation)
25  *          Vignesh Babu <ns3-dev@esk.fraunhofer.de> (RLF extensions)
26  */
27 
28 #ifndef LTE_ENB_RRC_H
29 #define LTE_ENB_RRC_H
30 
31 #include <ns3/nstime.h>
32 #include <ns3/object.h>
33 #include <ns3/traced-callback.h>
34 #include <ns3/event-id.h>
35 
36 #include <ns3/lte-enb-cmac-sap.h>
37 #include <ns3/lte-mac-sap.h>
38 #include <ns3/ff-mac-sched-sap.h>
39 #include <ns3/ff-mac-csched-sap.h>
40 #include <ns3/lte-pdcp-sap.h>
41 #include <ns3/epc-x2-sap.h>
42 #include <ns3/epc-enb-s1-sap.h>
43 #include <ns3/lte-handover-management-sap.h>
44 #include <ns3/lte-ccm-rrc-sap.h>
45 #include <ns3/lte-enb-cphy-sap.h>
46 #include <ns3/lte-rrc-sap.h>
47 #include <ns3/lte-anr-sap.h>
48 #include <ns3/lte-ffr-rrc-sap.h>
49 #include <ns3/lte-rlc.h>
50 
51 #include <map>
52 #include <set>
53 #include <ns3/component-carrier-enb.h>
54 #include <vector>
55 
56 #define MIN_NO_CC 1
57 #define MAX_NO_CC 5 // this is the maximum number of carrier components allowed by 3GPP up to R13
58 
59 namespace ns3 {
60 
61 class LteRadioBearerInfo;
62 class LteSignalingRadioBearerInfo;
63 class LteDataRadioBearerInfo;
64 class LteEnbRrc;
65 class Packet;
66 
67 
68 
69 /**
70  * \ingroup lte
71  * Manages all the radio bearer information possessed by the ENB RRC for a
72  * single UE.
73  */
74 class UeManager : public Object
75 {
76   /// allow LtePdcpSpecificLtePdcpSapUser<UeManager> class friend access
77   friend class LtePdcpSpecificLtePdcpSapUser<UeManager>;
78 
79 public:
80 
81 
82   /**
83    * The state of the UeManager at the eNB RRC
84    *
85    */
86   enum State
87   {
88     INITIAL_RANDOM_ACCESS = 0,
89     CONNECTION_SETUP,
90     CONNECTION_REJECTED,
91     ATTACH_REQUEST,
92     CONNECTED_NORMALLY,
93     CONNECTION_RECONFIGURATION,
94     CONNECTION_REESTABLISHMENT,
95     HANDOVER_PREPARATION,
96     HANDOVER_JOINING,
97     HANDOVER_PATH_SWITCH,
98     HANDOVER_LEAVING,
99     NUM_STATES
100   };
101 
102   UeManager ();
103 
104   /**
105    * UeManager constructor
106    *
107    * \param rrc pointer to the LteEnbRrc holding this UeManager
108    * \param rnti RNTI of the UE
109    * \param s initial state of the UeManager
110    * \param componentCarrierId primary component carrier ID
111    *
112    * \return
113    */
114   UeManager (Ptr<LteEnbRrc> rrc, uint16_t rnti, State s, uint8_t componentCarrierId);
115 
116   virtual ~UeManager (void);
117 
118   // inherited from Object
119 protected:
120   virtual void DoInitialize ();
121   virtual void DoDispose ();
122 public:
123   /**
124    * \brief Get the type ID.
125    * \return the object TypeId
126    */
127   static TypeId GetTypeId (void);
128 
129   /**
130    * Set the identifiers of the source eNB for the case where a UE
131    * joins the current eNB as part of a handover procedure
132    *
133    * \param sourceCellId
134    * \param sourceX2apId
135    */
136   void SetSource (uint16_t sourceCellId, uint16_t sourceX2apId);
137 
138   /**
139    * Set the IMSI
140    *
141    * \param imsi the IMSI
142    */
143   void SetImsi (uint64_t imsi);
144 
145   /**
146    * Process Initial context setup request message from the MME.
147    * It triggers RRC connection reconfiguration.
148    */
149   void InitialContextSetupRequest ();
150 
151   /**
152    * Setup a new data radio bearer, including both the configuration
153    * within the eNB and the necessary RRC signaling with the UE
154    *
155    * \param bearer the QoS characteristics of the bearer
156    * \param bearerId the EPS bearer identifier
157    * \param gtpTeid S1-bearer GTP tunnel endpoint identifier, see 36.423 9.2.1
158    * \param transportLayerAddress  IP Address of the SGW, see 36.423 9.2.1
159    *
160    */
161   void SetupDataRadioBearer (EpsBearer bearer, uint8_t bearerId, uint32_t gtpTeid, Ipv4Address transportLayerAddress);
162 
163   /**
164    * Start all configured data radio bearers. It is safe to call this
165    * method if any bearer had been already started previously.
166    *
167    */
168   void RecordDataRadioBearersToBeStarted ();
169 
170   /**
171    * Start the data radio bearers that have been previously recorded
172    * to be started using RecordDataRadioBearersToBeStarted()
173    *
174    */
175   void StartDataRadioBearers ();
176 
177   /**
178    *
179    * Release a given radio bearer
180    *
181    * \param drbid the data radio bearer id of the bearer to be released
182    */
183   void ReleaseDataRadioBearer (uint8_t drbid);
184 
185   /**
186    * schedule an RRC Connection Reconfiguration procedure with the UE
187    *
188    */
189   void ScheduleRrcConnectionReconfiguration ();
190 
191   /**
192    * Start the handover preparation and send the handover request
193    *
194    * \param cellId id of the target cell
195    */
196   void PrepareHandover (uint16_t cellId);
197 
198   /**
199    * take the necessary actions in response to the reception of an X2 HANDOVER REQUEST ACK message
200    *
201    * \param params
202    */
203   void RecvHandoverRequestAck (EpcX2SapUser::HandoverRequestAckParams params);
204 
205   /**
206    *
207    * \return the HandoverPreparationInfo sent by the source eNB to the
208    * target eNB in the X2-based handover procedure
209    */
210   LteRrcSap::RadioResourceConfigDedicated GetRadioResourceConfigForHandoverPreparationInfo ();
211 
212   /**
213    *
214    * \return retrieve the data that the target eNB needs to send to the source
215    * eNB as the Handover Command in the X2-based handover
216    * procedure.
217    *
218    * \note mobility control info is not expected to be filled in
219    * (shall be filled in by the caller).
220    */
221   LteRrcSap::RrcConnectionReconfiguration GetRrcConnectionReconfigurationForHandover ();
222 
223   /**
224    * Send a data packet over the appropriate Data Radio Bearer.
225    * If state is HANDOVER_JOINING (i.e. target eNB has received the
226    * Handover Request), the packet is buffered.
227    * If state is HANDOVER_LEAVING (i.e. source eNB has received the
228    * RRC Connection Reconfiguration, the packet is sent through the
229    * X2 interface.
230    *
231    * \param bid the corresponding EPS Bearer ID
232    * \param p the packet
233    */
234   void SendData (uint8_t bid, Ptr<Packet> p);
235 
236   /**
237    *
238    * \return a list of ERAB-to-be-setup items to be put in a X2 HO REQ message
239    */
240   std::vector<EpcX2Sap::ErabToBeSetupItem> GetErabList ();
241 
242   /**
243    * send the UE CONTEXT RELEASE X2 message to the source eNB, thus
244    * successfully terminating an X2 handover procedure
245    *
246    */
247   void SendUeContextRelease ();
248 
249   /**
250    * Take the necessary actions in response to the reception of an X2 HO preparation failure message
251    *
252    * \param cellId id of the target cell
253    */
254   void RecvHandoverPreparationFailure (uint16_t cellId);
255 
256   /**
257    * Take the necessary actions in response to the reception of an X2 SN STATUS TRANSFER message
258    *
259    * \param params the SN STATUS
260    */
261   void RecvSnStatusTransfer (EpcX2SapUser::SnStatusTransferParams params);
262 
263   /**
264    * Take the necessary actions in response to the reception of an X2 UE CONTEXT RELEASE message
265    *
266    * \param params the SN STATUS
267    */
268   void RecvUeContextRelease (EpcX2SapUser::UeContextReleaseParams params);
269 
270 
271   // METHODS FORWARDED FROM ENB RRC SAP ///////////////////////////////////////
272 
273   /**
274    * Implement the LteEnbRrcSapProvider::CompleteSetupUe interface.
275    * \param params CompleteSetupUeParameters
276    */
277   void CompleteSetupUe (LteEnbRrcSapProvider::CompleteSetupUeParameters params);
278   /**
279    * Implement the LteEnbRrcSapProvider::RecvRrcConnectionRequest interface.
280    * \param msg the RRC connection request message
281    */
282   void RecvRrcConnectionRequest (LteRrcSap::RrcConnectionRequest msg);
283   /**
284    * Implement the LteEnbRrcSapProvider::RecvRrcConnectionSetupCompleted interface.
285    * \param msg RRC connection setup completed message
286    */
287   void RecvRrcConnectionSetupCompleted (LteRrcSap::RrcConnectionSetupCompleted msg);
288   /**
289    * Implement the LteEnbRrcSapProvider::RecvRrcConnectionReconfigurationCompleted interface.
290    * \param msg RRC connection reconfiguration completed message
291    */
292   void RecvRrcConnectionReconfigurationCompleted (LteRrcSap::RrcConnectionReconfigurationCompleted msg);
293   /**
294    * Implement the LteEnbRrcSapProvider::RecvRrcConnectionReestablishmentRequest interface.
295    * \param msg the RRC connection reestablishment request message
296    */
297   void RecvRrcConnectionReestablishmentRequest (LteRrcSap::RrcConnectionReestablishmentRequest msg);
298   /**
299    * Implement the LteEnbRrcSapProvider::RecvRrcConnectionReestablishmentComplete interface.
300    * \param msg the RRC connection reestablsihment complete message
301    */
302   void RecvRrcConnectionReestablishmentComplete (LteRrcSap::RrcConnectionReestablishmentComplete msg);
303   /**
304    * Implement the LteEnbRrcSapProvider::RecvMeasurementReport interface.
305    * \param msg the measrurement report
306    */
307   void RecvMeasurementReport (LteRrcSap::MeasurementReport msg);
308   /**
309    * Implement the LteEnbRrcSapProvider::RecvIdealUeContextRemoveRequest interface.
310    *
311    * \param rnti the C-RNTI identifying the user
312    */
313   void RecvIdealUeContextRemoveRequest (uint16_t rnti);
314 
315 
316   // METHODS FORWARDED FROM ENB CMAC SAP //////////////////////////////////////
317 
318   /**
319    * CMAC UE config update indication function
320    * \param cmacParams the UE config parameters
321    */
322   void CmacUeConfigUpdateInd (LteEnbCmacSapUser::UeConfig cmacParams);
323 
324   // METHODS FORWARDED FROM ENB PDCP SAP //////////////////////////////////////
325 
326   /**
327    * Receive PDCP SDU function
328    * \param params the receive PDCP SDU parameters
329    */
330   void DoReceivePdcpSdu (LtePdcpSapUser::ReceivePdcpSduParameters params);
331 
332   /**
333    *
334    * \return the RNTI, i.e., an UE identifier that is unique within
335    * the cell
336    */
337   uint16_t GetRnti (void) const;
338 
339   /**
340    *
341    * \return the IMSI, i.e., a globally unique UE identifier
342    */
343   uint64_t GetImsi (void) const;
344 
345   /**
346    *
347    * \return the primary component carrier ID
348    */
349   uint8_t GetComponentCarrierId () const;
350 
351   /**
352    *
353    * \return the SRS Configuration Index
354    */
355   uint16_t GetSrsConfigurationIndex (void) const;
356 
357   /**
358    * Set the SRS configuration index and do the necessary reconfiguration
359    *
360    * \param srsConfIndex
361    */
362   void SetSrsConfigurationIndex (uint16_t srsConfIndex);
363 
364   /**
365    *
366    * \return the current state
367    */
368   State GetState () const;
369 
370   /**
371    * Configure PdschConfigDedicated (i.e. P_A value) for UE and start RrcConnectionReconfiguration
372    * to inform UE about new PdschConfigDedicated
373    *
374    * \param pdschConfigDedicated new pdschConfigDedicated (i.e. P_A value) to be set
375    */
376   void SetPdschConfigDedicated (LteRrcSap::PdschConfigDedicated pdschConfigDedicated);
377 
378   /**
379    * Cancel all timers which are running for the UE
380    *
381    */
382   void CancelPendingEvents ();
383 
384   /**
385    * TracedCallback signature for state transition events.
386    *
387    * \param [in] imsi
388    * \param [in] cellId
389    * \param [in] rnti
390    * \param [in] oldState
391    * \param [in] newState
392    */
393   typedef void (*StateTracedCallback)
394     (const uint64_t imsi, const uint16_t cellId, const uint16_t rnti,
395     const State oldState, const State newState);
396 
397 private:
398 
399   /**
400    * Add a new LteDataRadioBearerInfo structure to the UeManager
401    *
402    * \param radioBearerInfo
403    *
404    * \return the id of the newly added data radio bearer structure
405    */
406   uint8_t AddDataRadioBearerInfo (Ptr<LteDataRadioBearerInfo> radioBearerInfo);
407 
408   /**
409    * \param drbid the Data Radio Bearer id
410    *
411    * \return the corresponding LteDataRadioBearerInfo
412    */
413   Ptr<LteDataRadioBearerInfo> GetDataRadioBearerInfo (uint8_t drbid);
414 
415   /**
416    * remove the LteDataRadioBearerInfo corresponding to a bearer being released
417    *
418    * \param drbid the Data Radio Bearer id
419    */
420   void RemoveDataRadioBearerInfo (uint8_t drbid);
421 
422   /**
423    *
424    * \return an RrcConnectionReconfiguration struct built based on the
425    * current configuration
426    */
427   LteRrcSap::RrcConnectionReconfiguration BuildRrcConnectionReconfiguration ();
428 
429   /**
430    *
431    * \return an NonCriticalExtensionConfiguration struct built based on the
432    * current configuration
433    */
434   LteRrcSap::NonCriticalExtensionConfiguration BuildNonCriticalExtentionConfigurationCa ();
435 
436   /**
437    *
438    * \return a RadioResourceConfigDedicated struct built based on the
439    * current configuration
440    */
441   LteRrcSap::RadioResourceConfigDedicated BuildRadioResourceConfigDedicated ();
442 
443   /**
444    *
445    * \return a newly allocated identifier for a new RRC transaction
446    */
447   uint8_t GetNewRrcTransactionIdentifier ();
448 
449   /**
450    * \param lcid a Logical Channel Identifier
451    *
452    * \return the corresponding Data Radio Bearer Id
453    */
454   uint8_t Lcid2Drbid (uint8_t lcid);
455 
456   /**
457    * \param drbid a Data Radio Bearer Id
458    *
459    * \return the corresponding  Logical Channel Identifier
460    */
461   uint8_t Drbid2Lcid (uint8_t drbid);
462 
463   /**
464    * \param lcid a  Logical Channel Identifier
465    *
466    * \return the corresponding EPS Bearer Identifier
467    */
468   uint8_t Lcid2Bid (uint8_t lcid);
469 
470   /**
471    * \param bid  an EPS Bearer Identifier
472    *
473    * \return the corresponding Logical Channel Identifier
474    */
475   uint8_t Bid2Lcid (uint8_t bid);
476 
477   /**
478    * \param drbid Data Radio Bearer Id
479    *
480    * \return the corresponding EPS Bearer Identifier
481    */
482   uint8_t Drbid2Bid (uint8_t drbid);
483 
484   /**
485    * \param bid an EPS Bearer Identifier
486    *
487    * \return the corresponding Data Radio Bearer Id
488    */
489   uint8_t Bid2Drbid (uint8_t bid);
490 
491   /**
492    * Send a data packet over the appropriate Data Radio Bearer.
493    * It is called by SendData if the UE is in a connected state
494    * or when the RRC Connection Reconfiguration Complete message
495    * is received and the packets are debuffered.
496    *
497    * \param bid the corresponding EPS Bearer ID
498    * \param p the packet
499    */
500   void SendPacket (uint8_t bid, Ptr<Packet> p);
501 
502   /**
503    * Switch the UeManager to the given state
504    *
505    * \param s the given state
506    */
507   void SwitchToState (State s);
508 
509   uint8_t m_lastAllocatedDrbid; ///< last allocated Data Radio Bearer ID
510 
511   /**
512    * The `DataRadioBearerMap` attribute. List of UE DataRadioBearerInfo by
513    * DRBID.
514    */
515   std::map <uint8_t, Ptr<LteDataRadioBearerInfo> > m_drbMap;
516 
517   /**
518    * The `Srb0` attribute. SignalingRadioBearerInfo for SRB0.
519    */
520   Ptr<LteSignalingRadioBearerInfo> m_srb0;
521   /**
522    * The `Srb1` attribute. SignalingRadioBearerInfo for SRB1.
523    */
524   Ptr<LteSignalingRadioBearerInfo> m_srb1;
525 
526   /**
527    * The `C-RNTI` attribute. Cell Radio Network Temporary Identifier.
528    */
529   uint16_t m_rnti;
530   /**
531    * International Mobile Subscriber Identity assigned to this UE. A globally
532    * unique UE identifier.
533    */
534   uint64_t m_imsi;
535   /**
536    * ID of the primary CC for this UE
537    */
538   uint8_t m_componentCarrierId;
539 
540   uint8_t m_lastRrcTransactionIdentifier; ///< last RRC transaction identifier
541 
542   LteRrcSap::PhysicalConfigDedicated m_physicalConfigDedicated; ///< physical config dedicated
543   /// Pointer to the parent eNodeB RRC.
544   Ptr<LteEnbRrc> m_rrc;
545   /// The current UeManager state.
546   State m_state;
547 
548   LtePdcpSapUser* m_drbPdcpSapUser; ///< DRB PDCP SAP user
549 
550   bool m_pendingRrcConnectionReconfiguration; ///< pending RRC connection reconfiguration
551 
552   /**
553    * The `StateTransition` trace source. Fired upon every UE state transition
554    * seen by the UeManager at the eNB RRC. Exporting IMSI, cell ID, RNTI, old
555    * state, and new state.
556    */
557   TracedCallback<uint64_t, uint16_t, uint16_t, State, State> m_stateTransitionTrace;
558 
559   /**
560    * The `DrbCreated` trace source. Fired when DRB is created, i.e.
561    * the RLC and PDCP entities are created for one logical channel.
562    * Exporting IMSI, cell ID, RNTI, LCID.
563    */
564   TracedCallback<uint64_t, uint16_t, uint16_t, uint8_t> m_drbCreatedTrace;
565 
566   uint16_t m_sourceX2apId; ///< source X2 ap ID
567   uint16_t m_targetX2apId; ///< target X2 ap ID
568   uint16_t m_sourceCellId; ///< source cell ID
569   uint16_t m_targetCellId; ///< target cell ID
570   std::list<uint8_t> m_drbsToBeStarted; ///< DRBS to be started
571   bool m_needPhyMacConfiguration; ///< need Phy MAC configuration
572 
573   /**
574    * Time limit before a _connection request timeout_ occurs. Set after a new
575    * UE context is added after a successful Random Access. Calling
576    * LteEnbRrc::ConnectionRequestTimeout() when it expires. Cancelled when RRC
577    * CONNECTION REQUEST is received.
578    */
579   EventId m_connectionRequestTimeout;
580   /**
581    * Time limit before a _connection setup timeout_ occurs. Set after an RRC
582    * CONNECTION SETUP is sent. Calling LteEnbRrc::ConnectionSetupTimeout() when
583    * it expires. Cancelled when RRC CONNECTION SETUP COMPLETE is received.
584    */
585   EventId m_connectionSetupTimeout;
586   /**
587    * The delay before a _connection rejected timeout_ occurs. Set after an RRC
588    * CONNECTION REJECT is sent. Calling LteEnbRrc::ConnectionRejectedTimeout()
589    * when it expires.
590    */
591   EventId m_connectionRejectedTimeout;
592   /**
593    * Time limit before a _handover joining timeout_ occurs. Set after a new UE
594    * context is added after receiving a handover request. Calling
595    * LteEnbRrc::HandoverJoiningTimeout() when it expires. Cancelled when
596    * RRC CONNECTION RECONFIGURATION COMPLETE is received.
597    */
598   EventId m_handoverJoiningTimeout;
599   /**
600    * Time limit before a _handover leaving timeout_ occurs. Set after a
601    * handover command is sent. Calling LteEnbRrc::HandoverLeavingTimeout()
602    * when it expires. Cancelled when RRC CONNECTION RE-ESTABLISHMENT or X2
603    * UE CONTEXT RELEASE is received.
604    */
605   EventId m_handoverLeavingTimeout;
606 
607   /// Define if the Carrier Aggregation was already configure for the current UE on not
608   bool m_caSupportConfigured;
609 
610   /// Pending start data radio bearers
611   bool m_pendingStartDataRadioBearers;
612 
613 
614   /**
615    * Packet buffer for when UE is doing the handover.
616    * The packets are stored with the bid (bearer ID).
617    *
618    * Source eNB starts forwarding data to target eNB through the X2 interface
619    * when it sends RRC Connection Reconfiguration to the UE.
620    * Target eNB buffers data until it receives RRC Connection Reconfiguration
621    * Complete from the UE.
622    */
623   std::list<std::pair<uint8_t, Ptr<Packet> > > m_packetBuffer;
624 
625 }; // end of `class UeManager`
626 
627 
628 
629 /**
630  * \ingroup lte
631  *
632  * The LTE Radio Resource Control entity at the eNB
633  */
634 class LteEnbRrc : public Object
635 {
636 
637   /// allow EnbRrcMemberLteEnbCmacSapUser class friend access
638   friend class EnbRrcMemberLteEnbCmacSapUser;
639   /// allow MemberLteHandoverManagementSapUser<LteEnbRrc> class friend access
640   friend class MemberLteHandoverManagementSapUser<LteEnbRrc>;
641   /// allow MemberLteAnrSapUser<LteEnbRrc> class friend access
642   friend class MemberLteAnrSapUser<LteEnbRrc>;
643   /// allow MemberLteFfrRrcSapUser<LteEnbRrc> class friend access
644   friend class MemberLteFfrRrcSapUser<LteEnbRrc>;
645   /// allow MemberLteEnbRrcSapProvider<LteEnbRrc> class friend access
646   friend class MemberLteEnbRrcSapProvider<LteEnbRrc>;
647   /// allow MemberLteEnbRrcSapProvider<LteEnbRrc> class friend access
648   friend class MemberEpcEnbS1SapUser<LteEnbRrc>;
649   /// allow MemberEpcEnbS1SapUser<LteEnbRrc> class friend access
650   friend class EpcX2SpecificEpcX2SapUser<LteEnbRrc>;
651   /// allow UeManager class friend access
652   friend class UeManager;
653   /// allow  MemberLteCcmRrcSapUser<LteEnbRrc> class friend access
654   friend class MemberLteCcmRrcSapUser<LteEnbRrc>;
655 
656 public:
657   /**
658    * create an RRC instance for use within an eNB
659    *
660    */
661   LteEnbRrc ();
662 
663   /**
664    * Destructor
665    */
666   virtual ~LteEnbRrc ();
667 
668 
669   // inherited from Object
670 protected:
671   virtual void DoDispose (void);
672 public:
673   /**
674    * \brief Get the type ID.
675    * \return the object TypeId
676    */
677   static TypeId GetTypeId (void);
678 
679   /**
680    * Set the X2 SAP this RRC should interact with
681    * \param s the X2 SAP Provider to be used by this RRC entity
682    */
683   void SetEpcX2SapProvider (EpcX2SapProvider* s);
684 
685   /**
686    * Get the X2 SAP offered by this RRC
687    * \return s the X2 SAP User interface offered to the X2 entity by this RRC entity
688    */
689   EpcX2SapUser* GetEpcX2SapUser ();
690 
691 
692   /**
693    * set the CMAC SAP this RRC should interact with
694    *
695    * \param s the CMAC SAP Provider to be used by this RRC
696    */
697   void SetLteEnbCmacSapProvider (LteEnbCmacSapProvider * s);
698 
699   /**
700    * set the CMAC SAP this RRC should interact with
701    *
702    * \param s the CMAC SAP Provider to be used by this RRC
703    * \param pos the position
704    */
705   void SetLteEnbCmacSapProvider (LteEnbCmacSapProvider * s, uint8_t pos);
706 
707   /**
708    * Get the CMAC SAP offered by this RRC
709    * \returns the CMAC SAP User interface offered to the MAC by this RRC
710    */
711   LteEnbCmacSapUser* GetLteEnbCmacSapUser ();
712 
713   /**
714    * Get the CMAC SAP offered by this RRC
715    * \param pos the position
716    * \returns the CMAC SAP User interface offered to the MAC by this RRC
717    */
718   LteEnbCmacSapUser* GetLteEnbCmacSapUser (uint8_t pos);
719 
720   /**
721    * set the Handover Management SAP this RRC should interact with
722    *
723    * \param s the Handover Management SAP Provider to be used by this RRC
724    */
725   void SetLteHandoverManagementSapProvider (LteHandoverManagementSapProvider * s);
726 
727   /**
728    * Get the Handover Management SAP offered by this RRC
729    * \returns the Handover Management SAP User interface offered to the
730    *           handover algorithm by this RRC
731    */
732   LteHandoverManagementSapUser* GetLteHandoverManagementSapUser ();
733 
734 
735   /**
736    * set the Component Carrier Management SAP this RRC should interact with
737    *
738    * \param s the Component Carrier Management SAP Provider to be used by this RRC
739    */
740   void SetLteCcmRrcSapProvider (LteCcmRrcSapProvider * s);
741 
742   /**
743    * Get the Component Carrier Management SAP offered by this RRC
744    * \return s the Component Carrier Management SAP User interface offered to the
745    *           carrier component selection algorithm by this RRC
746    */
747   LteCcmRrcSapUser* GetLteCcmRrcSapUser ();
748 
749 
750   /**
751    * set the ANR SAP this RRC should interact with
752    *
753    * \param s the ANR SAP Provider to be used by this RRC
754    */
755   void SetLteAnrSapProvider (LteAnrSapProvider * s);
756 
757   /**
758    * Get the ANR SAP offered by this RRC
759    * \return s the ANR SAP User interface offered to the ANR instance by this
760    *           RRC
761    */
762   LteAnrSapUser* GetLteAnrSapUser ();
763 
764 
765 
766   /**
767    * set the FFR SAP this RRC should interact with
768    *
769    * \param s the FFR SAP Provider to be used by this RRC
770    */
771   void SetLteFfrRrcSapProvider (LteFfrRrcSapProvider * s);
772   /**
773    * set the FFR SAP this RRC should interact with
774    *
775    * \param s the FFR SAP Provider to be used by this RRC
776    * \param index the index
777    */
778   void SetLteFfrRrcSapProvider (LteFfrRrcSapProvider * s, uint8_t index);
779 
780   /**
781    * Get the FFR SAP offered by this RRC
782    * \return s the FFR SAP User interface offered to the ANR instance by this
783    *           RRC
784    */
785   LteFfrRrcSapUser* GetLteFfrRrcSapUser ();
786   /**
787    * Get the FFR SAP offered by this RRC
788    * \param index the index
789    * \return s the FFR SAP User interface offered to the ANR instance by this
790    *           RRC
791    */
792   LteFfrRrcSapUser* GetLteFfrRrcSapUser (uint8_t index);
793 
794   /**
795    * set the RRC SAP this RRC should interact with
796    *
797    * \param s the RRC SAP User to be used by this RRC
798    */
799   void SetLteEnbRrcSapUser (LteEnbRrcSapUser * s);
800 
801   /**
802    *
803    *
804    * \return s the RRC SAP Provider interface offered to the MAC by this RRC
805    */
806   LteEnbRrcSapProvider* GetLteEnbRrcSapProvider ();
807 
808   /**
809    * set the MAC SAP provider. The eNB RRC does not use this
810    * directly, but it needs to provide it to newly created RLC instances.
811    *
812    * \param s the MAC SAP provider that will be used by all
813    * newly created RLC instances
814    */
815   void SetLteMacSapProvider (LteMacSapProvider* s);
816 
817 
818   /**
819    * Set the S1 SAP Provider
820    *
821    * \param s the S1 SAP Provider
822    */
823   void SetS1SapProvider (EpcEnbS1SapProvider * s);
824 
825   /**
826    *
827    * \return the S1 SAP user
828    */
829   EpcEnbS1SapUser* GetS1SapUser ();
830 
831 
832   /**
833    * set the CPHY SAP this RRC should use to interact with the PHY
834    *
835    * \param s the CPHY SAP Provider
836    */
837   void SetLteEnbCphySapProvider (LteEnbCphySapProvider * s);
838 
839   /**
840    * set the CPHY SAP this RRC should use to interact with the PHY
841    *
842    * \param s the CPHY SAP Provider
843    * \param pos the position
844    */
845   void SetLteEnbCphySapProvider (LteEnbCphySapProvider * s, uint8_t pos);
846 
847   /**
848    *
849    *
850    * \return s the CPHY SAP User interface offered to the PHY by this RRC
851    */
852   LteEnbCphySapUser* GetLteEnbCphySapUser ();
853 
854   /**
855    * Get the ENB CPhy SAP user
856    *
857    * \param pos the position
858    * \return s the CPHY SAP User interface offered to the PHY by this RRC
859    */
860   LteEnbCphySapUser* GetLteEnbCphySapUser (uint8_t pos);
861 
862   /**
863    *
864    *
865    * \param rnti the identifier of an UE
866    *
867    * \return true if the corresponding UeManager instance exists
868    */
869   bool HasUeManager (uint16_t rnti) const;
870 
871   /**
872    *
873    *
874    * \param rnti the identifier of an UE
875    *
876    * \return the corresponding UeManager instance
877    */
878   Ptr<UeManager> GetUeManager (uint16_t rnti);
879 
880   /**
881    * \brief Add a new UE measurement reporting configuration
882    * \param config the new reporting configuration
883    * \return the measurement ID (measId) referring to the newly added
884    *         reporting configuration
885    *
886    * Assuming intra-frequency environment, the new measurement reporting
887    * configuration will be automatically associated to the only measurement
888    * object (i.e., a new measurement identity will be automatically created).
889    *
890    * Can only be called before the start of simulation.
891    */
892   uint8_t AddUeMeasReportConfig (LteRrcSap::ReportConfigEutra config);
893 
894   /**
895    * \brief Configure cell-specific parameters.
896    *
897    * Configure cell-specific parameters and propagate them to lower layers.
898    * The parameters include bandwidth, EARFCN (E-UTRA Absolute Radio Frequency
899    * Channel Number), and cell ID.
900    *
901    * In addition to parameter configuration, this function also performs several
902    * other tasks:
903    *  - Initializing UE measurement (i.e. measurement object and quantity
904    *    configuration), which is expected to be further configured through
905    *    `LteEnbRrc::AddUeMeasReportConfig`;
906    *  - Enabling MIB (Master Information Block) broadcast transmission
907    *  - Enabling SIB (System Information Block) broadcast transmission
908    *
909    * Typically runs when the eNodeB NetDevice is installed, for instance by
910    * `LteHelper::InstallEnbDevice` (i.e. before the simulation starts).
911    *
912    * \warning Raises an error when executed more than once.
913    *
914    * \param ccPhyConf the component carrier configuration
915    */
916   void ConfigureCell (std::map<uint8_t, Ptr<ComponentCarrierBaseStation> > ccPhyConf);
917 
918   /**
919    * \brief Configure carriers.
920    * \param ccPhyConf the component carrier configuration
921    */
922   void ConfigureCarriers (std::map<uint8_t, Ptr<ComponentCarrierBaseStation>> ccPhyConf);
923 
924   /**
925    * set the cell id of this eNB
926    *
927    * \param m_cellId
928    */
929   void SetCellId (uint16_t m_cellId);
930 
931   /**
932    * set the cell id of this eNB
933    *
934    * \param m_cellId
935    * \param ccIndex
936    */
937   void SetCellId (uint16_t m_cellId, uint8_t ccIndex);
938 
939   /**
940    * convert the cell id to component carrier id
941    *
942    * \param cellId Cell ID
943    *
944    * \return corresponding component carrier id
945    */
946   uint8_t CellToComponentCarrierId (uint16_t cellId);
947 
948   /**
949    * convert the component carrier id to cell id
950    *
951    * \param componentCarrierId component carrier ID
952    *
953    * \return corresponding cell ID
954    */
955   uint16_t ComponentCarrierToCellId (uint8_t componentCarrierId);
956 
957   /**
958    * Enqueue an IP data packet on the proper bearer for downlink
959    * transmission. Normally expected to be called by the NetDevice
960    * forwarding a packet coming from the EpcEnbApplication
961    *
962    * \param p the packet
963    *
964    * \return true if successful, false if an error occurred
965    */
966   bool SendData (Ptr<Packet> p);
967 
968   /**
969    * set the callback used to forward data packets up the stack
970    *
971    * \param cb
972    */
973   void SetForwardUpCallback (Callback <void, Ptr<Packet> > cb);
974 
975   /**
976    * Method triggered when a UE is expected to request for connection but does
977    * not do so in a reasonable time. The method will remove the UE context.
978    *
979    * \param rnti the T-C-RNTI whose timeout expired
980    */
981   void ConnectionRequestTimeout (uint16_t rnti);
982 
983   /**
984    * Method triggered when a UE is expected to complete a connection setup
985    * procedure but does not do so in a reasonable time. The method will remove
986    * the UE context.
987    *
988    * \param rnti the T-C-RNTI whose timeout expired
989    */
990   void ConnectionSetupTimeout (uint16_t rnti);
991 
992   /**
993    * Method triggered a while after sending RRC Connection Rejected. The method
994    * will remove the UE context.
995    *
996    * \param rnti the T-C-RNTI whose timeout expired
997    */
998   void ConnectionRejectedTimeout (uint16_t rnti);
999 
1000   /**
1001    * Method triggered when a UE is expected to join the cell for a handover
1002    * but does not do so in a reasonable time. The method will remove the UE
1003    * context.
1004    *
1005    * \param rnti the C-RNTI whose timeout expired
1006    */
1007   void HandoverJoiningTimeout (uint16_t rnti);
1008 
1009   /**
1010    * Method triggered when a UE is expected to leave a cell for a handover
1011    * but no feedback is received in a reasonable time. The method will remove
1012    * the UE context.
1013    *
1014    * \param rnti the C-RNTI whose timeout expired
1015    */
1016   void HandoverLeavingTimeout (uint16_t rnti);
1017 
1018   /**
1019    * Send a HandoverRequest through the X2 SAP interface. This method will
1020    * trigger a handover which is started by the RRC by sending a handover
1021    * request to the target eNB over the X2 interface
1022    *
1023    * \param rnti the ID of the UE to be handed over
1024    * \param cellId the ID of the target eNB
1025    */
1026   void SendHandoverRequest (uint16_t rnti, uint16_t cellId);
1027 
1028   /**
1029    *  \brief This function acts as an interface to trigger Release indication messages towards eNB and EPC
1030    *  \param imsi the IMSI
1031    *  \param rnti the RNTI
1032    *  \param bearerId Bearer Identity which is to be de-activated
1033    */
1034   void DoSendReleaseDataRadioBearer (uint64_t imsi, uint16_t rnti, uint8_t bearerId);
1035 
1036   /**
1037    * Identifies how EPS Bearer parameters are mapped to different RLC types
1038    *
1039    */
1040   enum LteEpsBearerToRlcMapping_t {RLC_SM_ALWAYS = 1,
1041                                    RLC_UM_ALWAYS = 2,
1042                                    RLC_AM_ALWAYS = 3,
1043                                    PER_BASED = 4};
1044 
1045   /**
1046    * TracedCallback signature for new Ue Context events.
1047    *
1048    * \param [in] cellId
1049    * \param [in] rnti
1050    */
1051   typedef void (*NewUeContextTracedCallback)
1052     (const uint16_t cellId, const uint16_t rnti);
1053 
1054   /**
1055    * TracedCallback signature for connection and handover end events.
1056    *
1057    * \param [in] imsi
1058    * \param [in] cellId
1059    * \param [in] rnti
1060    */
1061   typedef void (*ConnectionHandoverTracedCallback)
1062     (const uint64_t imsi, const uint16_t cellId, const uint16_t rnti);
1063 
1064   /**
1065    * TracedCallback signature for handover start events.
1066    *
1067    * \param [in] imsi
1068    * \param [in] cellId
1069    * \param [in] rnti
1070    * \param [in] targetCid
1071    */
1072   typedef void (*HandoverStartTracedCallback)
1073     (const uint64_t imsi, const uint16_t cellId, const uint16_t rnti,
1074      const uint16_t targetCid);
1075 
1076   /**
1077    * TracedCallback signature for receive measurement report events.
1078    *
1079    * \param [in] imsi
1080    * \param [in] cellId
1081    * \param [in] rnti
1082    * \param [in] report
1083    * \todo The \c LteRrcSap::MeasurementReport argument should be
1084    * changed to a const reference since the argument is large.
1085    */
1086   typedef void (*ReceiveReportTracedCallback)
1087     (const uint64_t imsi, const uint16_t cellId, const uint16_t rnti,
1088      const LteRrcSap::MeasurementReport report);
1089 
1090   /**
1091    * TracedCallback signature for timer expiry events
1092    *
1093    * \param [in] imsi
1094    * \param [in] rnti
1095    * \param [in] cellId
1096    * \param [in] cause
1097    */
1098   typedef void (*TimerExpiryTracedCallback)
1099       (const uint64_t imsi, const uint16_t rnti, const uint16_t cellId,
1100        const std::string cause);
1101 
1102 
1103 private:
1104 
1105 
1106   // RRC SAP methods
1107 
1108   /**
1109    * Part of the RRC protocol. Forwarding LteEnbRrcSapProvider::CompleteSetupUe interface to UeManager::CompleteSetupUe
1110    * \param rnti the RNTI
1111    * \param params the LteEnbRrcSapProvider::CompleteSetupUeParameters
1112    */
1113   void DoCompleteSetupUe (uint16_t rnti, LteEnbRrcSapProvider::CompleteSetupUeParameters params);
1114   /**
1115    * Part of the RRC protocol. Forwarding LteEnbRrcSapProvider::RecvRrcConnectionRequest interface to UeManager::RecvRrcConnectionRequest
1116    *
1117    * \param rnti the RNTI
1118    * \param msg the LteRrcSap::RrcConnectionRequest
1119    */
1120   void DoRecvRrcConnectionRequest (uint16_t rnti, LteRrcSap::RrcConnectionRequest msg);
1121   /**
1122    * Part of the RRC protocol. Forwarding LteEnbRrcSapProvider::RecvRrcConnectionSetupCompleted interface to UeManager::RecvRrcConnectionSetupCompleted
1123    *
1124    * \param rnti the RNTI
1125    * \param msg the LteRrcSap::RrcConnectionSetupCompleted
1126    */
1127   void DoRecvRrcConnectionSetupCompleted (uint16_t rnti, LteRrcSap::RrcConnectionSetupCompleted msg);
1128   /**
1129    * Part of the RRC protocol. Forwarding LteEnbRrcSapProvider::RecvRrcConnectionReconfigurationCompleted interface to UeManager::RecvRrcConnectionReconfigurationCompleted
1130    *
1131    * \param rnti the RNTI
1132    * \param msg the LteRrcSap::RrcConnectionReconfigurationCompleted
1133    */
1134   void DoRecvRrcConnectionReconfigurationCompleted (uint16_t rnti, LteRrcSap::RrcConnectionReconfigurationCompleted msg);
1135   /**
1136    * Part of the RRC protocol. Forwarding LteEnbRrcSapProvider::RecvRrcConnectionReestablishmentRequest interface to UeManager::RecvRrcConnectionReestablishmentRequest
1137    *
1138    * \param rnti the RNTI
1139    * \param msg the LteRrcSap::RrcConnectionReestablishmentRequest
1140    */
1141   void DoRecvRrcConnectionReestablishmentRequest (uint16_t rnti, LteRrcSap::RrcConnectionReestablishmentRequest msg);
1142   /**
1143    * Part of the RRC protocol. Forwarding LteEnbRrcSapProvider::RecvRrcConnectionReestablishmentComplete interface to UeManager::RecvRrcConnectionReestablishmentComplete
1144    *
1145    * \param rnti the RNTI
1146    * \param msg the LteRrcSap::RrcConnectionReestablishmentComplete
1147    */
1148   void DoRecvRrcConnectionReestablishmentComplete (uint16_t rnti, LteRrcSap::RrcConnectionReestablishmentComplete msg);
1149   /**
1150    * Part of the RRC protocol. Forwarding LteEnbRrcSapProvider::RecvMeasurementReport interface to UeManager::RecvMeasurementReport
1151    *
1152    * \param rnti the RNTI
1153    * \param msg the LteRrcSap::MeasurementReport
1154    */
1155   void DoRecvMeasurementReport (uint16_t rnti, LteRrcSap::MeasurementReport msg);
1156   /**
1157    * \brief Part of the RRC protocol. Forwarding LteEnbRrcSapProvider::RecvIdealUeContextRemoveRequest interface to UeManager::RecvIdealUeContextRemoveRequest.
1158    *
1159    * Remove the UE context at eNodeB and also remove the bearers established
1160    * at SGW/PGW node. Bearer info at MME is not deleted since they are added at
1161    * MME only at the beginning of simulation and if they are removed,
1162    * the bearers cannot be activated again.
1163    *
1164    * \param rnti the C-RNTI identifying the user
1165    */
1166   void DoRecvIdealUeContextRemoveRequest (uint16_t rnti);
1167 
1168   // S1 SAP methods
1169 
1170   /**
1171    * Initial context setup request function
1172    *
1173    * \param params EpcEnbS1SapUser::InitialContextSetupRequestParameters
1174    */
1175   void DoInitialContextSetupRequest (EpcEnbS1SapUser::InitialContextSetupRequestParameters params);
1176   /**
1177    * Data radio beaerer setup request function
1178    *
1179    * \param params EpcEnbS1SapUser::DataRadioBearerSetupRequestParameters
1180    */
1181   void DoDataRadioBearerSetupRequest (EpcEnbS1SapUser::DataRadioBearerSetupRequestParameters params);
1182   /**
1183    * Path switch request acknowledge function
1184    *
1185    * \param params EpcEnbS1SapUser::PathSwitchRequestAcknowledgeParameters
1186    */
1187   void DoPathSwitchRequestAcknowledge (EpcEnbS1SapUser::PathSwitchRequestAcknowledgeParameters params);
1188 
1189   // X2 SAP methods
1190 
1191   /**
1192    * Receive handover request function
1193    *
1194    * \param params EpcX2SapUser::HandoverRequestParams
1195    */
1196   void DoRecvHandoverRequest (EpcX2SapUser::HandoverRequestParams params);
1197   /**
1198    * Receive handover request acknowledge function
1199    *
1200    * \param params EpcX2SapUser::HandoverRequestAckParams
1201    */
1202   void DoRecvHandoverRequestAck (EpcX2SapUser::HandoverRequestAckParams params);
1203   /**
1204    * Receive handover preparation failure function
1205    *
1206    * \param params EpcX2SapUser::HandoverPreparationFailureParams
1207    */
1208   void DoRecvHandoverPreparationFailure (EpcX2SapUser::HandoverPreparationFailureParams params);
1209   /**
1210    * Receive SN status transfer function
1211    *
1212    * \param params EpcX2SapUser::SnStatusTransferParams
1213    */
1214   void DoRecvSnStatusTransfer (EpcX2SapUser::SnStatusTransferParams params);
1215   /**
1216    * Receive UE context release function
1217    *
1218    * \param params EpcX2SapUser::UeContextReleaseParams
1219    */
1220   void DoRecvUeContextRelease (EpcX2SapUser::UeContextReleaseParams params);
1221   /**
1222    * Receive load information function
1223    *
1224    * \param params EpcX2SapUser::LoadInformationParams
1225    */
1226   void DoRecvLoadInformation (EpcX2SapUser::LoadInformationParams params);
1227   /**
1228    * Receive resource status update function
1229    *
1230    * \param params EpcX2SapUser::ResourceStatusUpdateParams
1231    */
1232   void DoRecvResourceStatusUpdate (EpcX2SapUser::ResourceStatusUpdateParams params);
1233   /**
1234    * Receive UE data function
1235    *
1236    * \param params EpcX2SapUser::UeDataParams
1237    */
1238   void DoRecvUeData (EpcX2SapUser::UeDataParams params);
1239 
1240   // CMAC SAP methods
1241 
1242   /**
1243    * Allocate temporary cell RNTI function
1244    *
1245    * \param componentCarrierId ID of the primary component carrier
1246    * \return temporary RNTI
1247    */
1248   uint16_t DoAllocateTemporaryCellRnti (uint8_t componentCarrierId);
1249   /**
1250    * Notify LC config result function
1251    *
1252    * \param rnti RNTI
1253    * \param lcid LCID
1254    * \param success the success indicator
1255    */
1256   void DoNotifyLcConfigResult (uint16_t rnti, uint8_t lcid, bool success);
1257   /**
1258    * RRC configuration update indication function
1259    *
1260    * \param params LteEnbCmacSapUser::UeConfig
1261    */
1262   void DoRrcConfigurationUpdateInd (LteEnbCmacSapUser::UeConfig params);
1263 
1264   // Handover Management SAP methods
1265 
1266   /**
1267    * Add UE measure report config for handover function
1268    *
1269    * \param reportConfig LteRrcSap::ReportConfigEutra
1270    * \returns measure ID
1271    */
1272   uint8_t DoAddUeMeasReportConfigForHandover (LteRrcSap::ReportConfigEutra reportConfig);
1273   /**
1274    * Add UE measure report config for component carrier function
1275    *
1276    * \param reportConfig LteRrcSap::ReportConfigEutra
1277    * \returns measure ID
1278    */
1279   uint8_t DoAddUeMeasReportConfigForComponentCarrier (LteRrcSap::ReportConfigEutra reportConfig);
1280   /**
1281    * \brief Set number of component carriers
1282    * \param numberOfComponentCarriers the number of component carriers
1283    */
1284   void DoSetNumberOfComponentCarriers (uint16_t numberOfComponentCarriers);
1285 
1286 
1287   /**
1288    * Trigger handover function
1289    *
1290    * \param rnti RNTI
1291    * \param targetCellId target cell ID
1292    */
1293   void DoTriggerHandover (uint16_t rnti, uint16_t targetCellId);
1294 
1295   // ANR SAP methods
1296 
1297   /**
1298    * Add UE measure report config for ANR function
1299    *
1300    * \param reportConfig LteRrcSap::ReportConfigEutra
1301    * \returns measure ID
1302    */
1303   uint8_t DoAddUeMeasReportConfigForAnr (LteRrcSap::ReportConfigEutra reportConfig);
1304 
1305   // FFR RRC SAP methods
1306   /**
1307    * Add UE measure report config for FFR function
1308    *
1309    * \param reportConfig LteRrcSap::ReportConfigEutra
1310    * \returns measure ID
1311    */
1312   uint8_t DoAddUeMeasReportConfigForFfr (LteRrcSap::ReportConfigEutra reportConfig);
1313   /**
1314    * Set PDSCH config dedicated function
1315    *
1316    * \param rnti the RNTI
1317    * \param pa LteRrcSap::PdschConfigDedicated
1318    */
1319   void DoSetPdschConfigDedicated (uint16_t rnti, LteRrcSap::PdschConfigDedicated pa);
1320   /**
1321    * Send load information function
1322    *
1323    * \param params EpcX2Sap::LoadInformationParams
1324    */
1325   void DoSendLoadInformation (EpcX2Sap::LoadInformationParams params);
1326 
1327   // Internal methods
1328 
1329   /**
1330    * Allocate a new RNTI for a new UE. This is done in the following cases:
1331    *   * T-C-RNTI allocation upon contention-based MAC Random Access procedure
1332    *   * target cell RNTI allocation upon handover
1333    *
1334    * \param state the initial state of the UeManager
1335    * \param componentCarrierId primary component carrier ID of the UeManager
1336    *
1337    * \return the newly allocated RNTI
1338    */
1339   uint16_t AddUe (UeManager::State state, uint8_t componentCarrierId);
1340 
1341   /**
1342    * remove a UE from the cell
1343    *
1344    * \param rnti the C-RNTI identiftying the user
1345    */
1346   void RemoveUe (uint16_t rnti);
1347 
1348 
1349   /**
1350    *
1351    * \param bearer the specification of an EPS bearer
1352    *
1353    * \return the type of RLC that is to be created for the given EPS bearer
1354    */
1355   TypeId GetRlcType (EpsBearer bearer);
1356 
1357   /**
1358    * \brief Is random access completed function
1359    *
1360    * This method is executed to decide if the non contention based
1361    * preamble has to reused or not upon preamble expiry. If the random access
1362    * in connected mode is completed, then the preamble can be reused by other UEs.
1363    * If not, the same UE retains the preamble and other available preambles is
1364    * assigned to the required UEs.
1365    *
1366    * \param rnti the C-RNTI identifying the user
1367    * \return true if the random access in connected mode is completed
1368    */
1369   bool IsRandomAccessCompleted (uint16_t rnti);
1370 
1371 
1372 
1373 public:
1374 
1375   /**
1376    * Add a neighbour with an X2 interface
1377    *
1378    * \param cellId neighbouring cell id
1379    */
1380   void AddX2Neighbour (uint16_t cellId);
1381 
1382   /**
1383    *
1384    * \param p the SRS periodicity in num TTIs
1385    */
1386   void SetSrsPeriodicity (uint32_t p);
1387 
1388   /**
1389    *
1390    * \return the current SRS periodicity
1391    */
1392   uint32_t GetSrsPeriodicity () const;
1393 
1394   /**
1395    * \brief Associate this RRC entity with a particular CSG information.
1396    * \param csgId the intended Closed Subscriber Group identity
1397    * \param csgIndication if TRUE, only CSG members are allowed to access the
1398    *                      cell
1399    *
1400    * CSG identity is a number identifying a Closed Subscriber Group which the
1401    * cell belongs to. eNodeB is associated with a single CSG identity.
1402    *
1403    * The same CSG identity can also be associated to several UEs, which is
1404    * equivalent as enlisting these UEs as the members of this particular CSG.
1405    * When the CSG indication field is set to TRUE, only UEs which are members of
1406    * the CSG (i.e. same CSG ID) can gain access to the eNodeB, therefore
1407    * enforcing closed access mode. Otherwise, the eNodeB operates as a non-CSG
1408    * cell and implements open access mode.
1409    *
1410    * This restriction only applies to initial cell selection and EPC-enabled
1411    * simulation.
1412    */
1413   void SetCsgId (uint32_t csgId, bool csgIndication);
1414 
1415 private:
1416 
1417   /**
1418    * Allocate a new SRS configuration index for a new UE.
1419    *
1420    * \note this method can have the side effect of updating the SRS
1421    * configuration index of all UEs
1422    *
1423    * \return the newly allocated SRS configuration index
1424    */
1425   uint16_t GetNewSrsConfigurationIndex (void);
1426 
1427   /**
1428    * remove a previously allocated SRS configuration index
1429    *
1430    * \note this method can have the side effect of updating the SRS
1431    * configuration index of all UEs
1432    *
1433    * \param srcCi the indext to be removed
1434    */
1435   void RemoveSrsConfigurationIndex (uint16_t srcCi);
1436 
1437 
1438 
1439   /**
1440    *
1441    * \param bearer the characteristics of the bearer
1442    *
1443    * \return the Logical Channel Group in a bearer with these
1444    * characteristics is put. Used for MAC Buffer Status Reporting purposes.
1445    */
1446   uint8_t GetLogicalChannelGroup (EpsBearer bearer);
1447 
1448   /**
1449    *
1450    * \param bearer the characteristics of the bearer
1451    *
1452    * \return the priority level of a bearer with these
1453    * characteristics is put. Used for the part of UL MAC Scheduling
1454    * carried out by the UE
1455    */
1456   uint8_t GetLogicalChannelPriority (EpsBearer bearer);
1457 
1458 
1459   /**
1460    * method used to periodically send System Information
1461    *
1462    */
1463   void SendSystemInformation ();
1464 
1465   Callback <void, Ptr<Packet> > m_forwardUpCallback;  ///< forward up callback function
1466 
1467   /// Interface to receive messages from neighbour eNodeB over the X2 interface.
1468   EpcX2SapUser* m_x2SapUser;
1469   /// Interface to send messages to neighbour eNodeB over the X2 interface.
1470   EpcX2SapProvider* m_x2SapProvider;
1471 
1472   /// Receive API calls from the eNodeB MAC instance.
1473   std::vector<LteEnbCmacSapUser*> m_cmacSapUser;
1474   /// Interface to the eNodeB MAC instance.
1475   std::vector<LteEnbCmacSapProvider*> m_cmacSapProvider;
1476 
1477   /// Receive API calls from the handover algorithm instance.
1478   LteHandoverManagementSapUser* m_handoverManagementSapUser;
1479   /// Interface to the handover algorithm instance.
1480   LteHandoverManagementSapProvider* m_handoverManagementSapProvider;
1481 
1482   /// Receive API calls from the LteEnbComponentCarrierManager instance.
1483   LteCcmRrcSapUser* m_ccmRrcSapUser;
1484   /// Interface to the LteEnbComponentCarrierManager instance.
1485   LteCcmRrcSapProvider* m_ccmRrcSapProvider;
1486 
1487   /// Receive API calls from the ANR instance.
1488   LteAnrSapUser* m_anrSapUser;
1489   /// Interface to the ANR instance.
1490   LteAnrSapProvider* m_anrSapProvider;
1491 
1492   /// Receive API calls from the FFR algorithm instance.
1493   std::vector<LteFfrRrcSapUser*> m_ffrRrcSapUser;
1494   /// Interface to the FFR algorithm instance.
1495   std::vector<LteFfrRrcSapProvider*> m_ffrRrcSapProvider;
1496 
1497   /// Interface to send messages to UE over the RRC protocol.
1498   LteEnbRrcSapUser* m_rrcSapUser;
1499   /// Interface to receive messages from UE over the RRC protocol.
1500   LteEnbRrcSapProvider* m_rrcSapProvider;
1501 
1502   /// Interface to the eNodeB MAC instance, to be used by RLC instances.
1503   LteMacSapProvider* m_macSapProvider;
1504 
1505   /// Interface to send messages to core network over the S1 protocol.
1506   EpcEnbS1SapProvider* m_s1SapProvider;
1507   /// Interface to receive messages from core network over the S1 protocol.
1508   EpcEnbS1SapUser* m_s1SapUser;
1509 
1510   /// Receive API calls from the eNodeB PHY instances.
1511   std::vector<LteEnbCphySapUser*> m_cphySapUser;
1512   /// Interface to the eNodeB PHY instances.
1513   std::vector<LteEnbCphySapProvider*> m_cphySapProvider;
1514 
1515   /// True if ConfigureCell() has been completed.
1516   bool m_configured;
1517   /// Downlink E-UTRA Absolute Radio Frequency Channel Number.
1518   uint32_t m_dlEarfcn;
1519   /// Uplink E-UTRA Absolute Radio Frequency Channel Number.
1520   uint32_t m_ulEarfcn;
1521   /// Downlink transmission bandwidth configuration in number of Resource Blocks.
1522   uint16_t m_dlBandwidth;
1523   /// Uplink transmission bandwidth configuration in number of Resource Blocks.
1524   uint16_t m_ulBandwidth;
1525   /// Last allocated RNTI
1526   uint16_t m_lastAllocatedRnti;
1527 
1528   /// The System Information Block Type 1 that is currently broadcasted over BCH.
1529   std::vector<LteRrcSap::SystemInformationBlockType1> m_sib1;
1530 
1531   /**
1532    * The `UeMap` attribute. List of UeManager by C-RNTI.
1533    */
1534   std::map<uint16_t, Ptr<UeManager> > m_ueMap;
1535 
1536   /**
1537    * List of measurement configuration which are active in every UE attached to
1538    * this eNodeB instance.
1539    */
1540   LteRrcSap::MeasConfig m_ueMeasConfig;
1541 
1542   /// List of measurement identities which are intended for handover purpose.
1543   std::set<uint8_t> m_handoverMeasIds;
1544   /// List of measurement identities which are intended for ANR purpose.
1545   std::set<uint8_t> m_anrMeasIds;
1546   /// List of measurement identities which are intended for FFR purpose.
1547   std::set<uint8_t> m_ffrMeasIds;
1548   /// List of measurement identities which are intended for component carrier management purposes.
1549   std::set<uint8_t> m_componentCarrierMeasIds;
1550 
1551   /// X2uTeidInfo structure
1552   struct X2uTeidInfo
1553   {
1554     uint16_t rnti; ///< RNTI
1555     uint8_t drbid; ///< DRBID
1556   };
1557 
1558   /// TEID, RNTI, DRBID
1559   std::map<uint32_t, X2uTeidInfo> m_x2uTeidInfoMap;
1560 
1561   /**
1562    * The `DefaultTransmissionMode` attribute. The default UEs' transmission
1563    * mode (0: SISO).
1564    */
1565   uint8_t m_defaultTransmissionMode;
1566   /**
1567    * The `EpsBearerToRlcMapping` attribute. Specify which type of RLC will be
1568    * used for each type of EPS bearer.
1569    */
1570   enum LteEpsBearerToRlcMapping_t m_epsBearerToRlcMapping;
1571   /**
1572    * The `SystemInformationPeriodicity` attribute. The interval for sending
1573    * system information.
1574    */
1575   Time m_systemInformationPeriodicity;
1576   /**
1577    * The `SrsPeriodicity` attribute. The SRS periodicity in milliseconds.
1578    */
1579   uint16_t m_srsCurrentPeriodicityId; ///< SRS current periodicity ID
1580   std::set<uint16_t> m_ueSrsConfigurationIndexSet; ///< UE SRS configuration index set
1581   uint16_t m_lastAllocatedConfigurationIndex; ///< last allocated configuration index
1582   bool m_reconfigureUes; ///< reconfigure UEs?
1583 
1584   /**
1585    * The `QRxLevMin` attribute. One of information transmitted within the SIB1
1586    * message, indicating the required minimum RSRP level that any UE must
1587    * receive from this cell before it is allowed to camp to this cell.
1588    */
1589   int8_t m_qRxLevMin;
1590   /**
1591    * The `AdmitHandoverRequest` attribute. Whether to admit an X2 handover
1592    * request from another eNB.
1593    */
1594   bool m_admitHandoverRequest;
1595   /**
1596    * The `AdmitRrcConnectionRequest` attribute. Whether to admit a connection
1597    * request from a UE.
1598    */
1599   bool m_admitRrcConnectionRequest;
1600   /**
1601    * The `RsrpFilterCoefficient` attribute. Determines the strength of
1602    * smoothing effect induced by layer 3 filtering of RSRP in all attached UE.
1603    * If equals to 0, no layer 3 filtering is applicable.
1604    */
1605   uint8_t m_rsrpFilterCoefficient;
1606   /**
1607    * The `RsrqFilterCoefficient` attribute. Determines the strength of
1608    * smoothing effect induced by layer 3 filtering of RSRQ in all attached UE.
1609    * If equals to 0, no layer 3 filtering is applicable.
1610    */
1611   uint8_t m_rsrqFilterCoefficient;
1612   /**
1613    * The `ConnectionRequestTimeoutDuration` attribute. After a RA attempt, if
1614    * no RRC CONNECTION REQUEST is received before this time, the UE context is
1615    * destroyed. Must account for reception of RAR and transmission of RRC
1616    * CONNECTION REQUEST over UL GRANT.
1617    */
1618   Time m_connectionRequestTimeoutDuration;
1619   /**
1620    * The `ConnectionSetupTimeoutDuration` attribute. After accepting connection
1621    * request, if no RRC CONNECTION SETUP COMPLETE is received before this time,
1622    * the UE context is destroyed. Must account for the UE's reception of RRC
1623    * CONNECTION SETUP and transmission of RRC CONNECTION SETUP COMPLETE.
1624    */
1625   Time m_connectionSetupTimeoutDuration;
1626   /**
1627    * The `ConnectionRejectedTimeoutDuration` attribute. Time to wait between
1628    * sending a RRC CONNECTION REJECT and destroying the UE context.
1629    */
1630   Time m_connectionRejectedTimeoutDuration;
1631   /**
1632    * The `HandoverJoiningTimeoutDuration` attribute. After accepting a handover
1633    * request, if no RRC CONNECTION RECONFIGURATION COMPLETE is received before
1634    * this time, the UE context is destroyed. Must account for reception of X2
1635    * HO REQ ACK by source eNB, transmission of the Handover Command,
1636    * non-contention-based random access and reception of the RRC CONNECTION
1637    * RECONFIGURATION COMPLETE message.
1638    */
1639   Time m_handoverJoiningTimeoutDuration;
1640   /**
1641    * The `HandoverLeavingTimeoutDuration` attribute. After issuing a Handover
1642    * Command, if neither RRC CONNECTION RE-ESTABLISHMENT nor X2 UE Context
1643    * Release has been previously received, the UE context is destroyed.
1644    */
1645   Time m_handoverLeavingTimeoutDuration;
1646 
1647   /**
1648    * The `NewUeContext` trace source. Fired upon creation of a new UE context.
1649    * Exporting cell ID and RNTI.
1650    */
1651   TracedCallback<uint16_t, uint16_t> m_newUeContextTrace;
1652   /**
1653    * The `ConnectionEstablished` trace source. Fired upon successful RRC
1654    * connection establishment. Exporting IMSI, cell ID, and RNTI.
1655    */
1656   TracedCallback<uint64_t, uint16_t, uint16_t> m_connectionEstablishedTrace;
1657   /**
1658    * The `ConnectionReconfiguration` trace source. Fired upon RRC connection
1659    * reconfiguration. Exporting IMSI, cell ID, and RNTI.
1660    */
1661   TracedCallback<uint64_t, uint16_t, uint16_t> m_connectionReconfigurationTrace;
1662   /**
1663    * The `HandoverStart` trace source. Fired upon start of a handover
1664    * procedure. Exporting IMSI, cell ID, RNTI, and target cell ID.
1665    */
1666   TracedCallback<uint64_t, uint16_t, uint16_t, uint16_t> m_handoverStartTrace;
1667   /**
1668    * The `HandoverEndOk` trace source. Fired upon successful termination of a
1669    * handover procedure. Exporting IMSI, cell ID, and RNTI.
1670    */
1671   TracedCallback<uint64_t, uint16_t, uint16_t> m_handoverEndOkTrace;
1672   /**
1673    * The `RecvMeasurementReport` trace source. Fired when measurement report is
1674    * received. Exporting IMSI, cell ID, and RNTI.
1675    */
1676   TracedCallback<uint64_t, uint16_t, uint16_t, LteRrcSap::MeasurementReport> m_recvMeasurementReportTrace;
1677   /**
1678    * The `NotifyConnectionRelease` trace source. Fired when an UE leaves the eNB.
1679    * Exporting IMSI, cell ID, RNTI.
1680    *
1681    */
1682   TracedCallback<uint64_t, uint16_t, uint16_t> m_connectionReleaseTrace;
1683   /**
1684    * The 'TimerExpiry' Trace source. Fired when any of the RRC timers maintained
1685    * at eNB expires. Exporting IMSI, cell ID, and RNTI and name of timer
1686    * which expired.
1687    */
1688   TracedCallback<uint64_t, uint16_t, uint16_t, std::string> m_rrcTimeoutTrace;
1689 
1690   uint16_t m_numberOfComponentCarriers; ///< number of component carriers
1691 
1692   bool m_carriersConfigured; ///< are carriers configured
1693 
1694   std::map<uint8_t, Ptr<ComponentCarrierBaseStation>> m_componentCarrierPhyConf; ///< component carrier phy configuration
1695 
1696 }; // end of `class LteEnbRrc`
1697 
1698 
1699 } // namespace ns3
1700 
1701 #endif // LTE_ENB_RRC_H
1702