1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2018 Fraunhofer ESK
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: Vignesh Babu <ns3-dev@esk.fraunhofer.de>
19  */
20 
21 #ifndef LTE_TEST_RADIO_LINK_FAILURE_H
22 #define LTE_TEST_RADIO_LINK_FAILURE_H
23 
24 
25 #include <ns3/test.h>
26 #include <ns3/nstime.h>
27 #include <ns3/node-container.h>
28 #include <ns3/net-device-container.h>
29 #include <ns3/vector.h>
30 #include <ns3/lte-ue-rrc.h>
31 #include <vector>
32 
33 
34 namespace ns3 {
35 
36 class LteUeNetDevice;
37 
38 }
39 
40 using namespace ns3;
41 
42 
43 /**
44  * \brief Test suite for
45  *
46  * \sa ns3::LteRadioLinkFailureTestCase
47  */
48 class LteRadioLinkFailureTestSuite : public TestSuite
49 {
50 public:
51   LteRadioLinkFailureTestSuite ();
52 };
53 
54 /**
55  * \ingroup lte
56  *
57  * \brief Testing the cell reselection procedure by UE at IDLE state
58  */
59 class LteRadioLinkFailureTestCase : public TestCase
60 {
61 public:
62   /**
63    * \brief Creates an instance of the radio link failure test case.
64    *
65    * \param numEnbs number of eNodeBs
66    * \param numUes number of UEs
67    * \param simTime the simulation time
68    * \param isIdealRrc if true, simulation uses Ideal RRC protocol, otherwise
69    *                   simulation uses Real RRC protocol
70    * \param uePositionList Position of the UEs
71    * \param enbPositionList Position of the eNodeBs
72    * \param ueJumpAwayPosition Vector holding the UE jump away coordinates
73    * \param checkConnectedList the time at which UEs should have an active RRC connection
74    */
75   LteRadioLinkFailureTestCase (uint32_t numEnbs, uint32_t numUes, Time simTime, bool isIdealRrc,
76                                std::vector<Vector> uePositionList, std::vector<Vector> enbPositionList,
77                                Vector ueJumpAwayPosition, std::vector<Time> checkConnectedList);
78 
79   virtual ~LteRadioLinkFailureTestCase ();
80 
81 private:
82   /**
83    * Builds the test name string based on provided parameter values
84    * \param numEnbs the number of eNB nodes
85    * \param numUes the number of UE nodes
86    * \param isIdealRrc True if the Ideal RRC protocol is used
87    * \returns the name string
88    */
89   std::string BuildNameString (uint32_t numEnbs, uint32_t numUes, bool isIdealRrc);
90   /**
91    * \brief Setup the simulation according to the configuration set by the
92    *        class constructor, run it, and verify the result.
93    */
94   virtual void DoRun ();
95 
96   /**
97    * Check connected function
98    * \param ueDevice the UE device
99    * \param enbDevices the ENB devices
100    */
101   void CheckConnected (Ptr<NetDevice> ueDevice, NetDeviceContainer enbDevices);
102 
103   /**
104    * Check if the UE is in idle state
105    * \param ueDevice the UE device
106    * \param enbDevices the ENB devices
107    */
108   void CheckIdle (Ptr<NetDevice> ueDevice, NetDeviceContainer enbDevices);
109 
110   /**
111    * \brief Check if the UE exist at the eNB
112    * \param rnti the RNTI of the UE
113    * \param enbDevice the eNB device
114    * \return true if the UE exist at the eNB, otherwise false
115    */
116   bool CheckUeExistAtEnb (uint16_t rnti, Ptr<NetDevice> enbDevice);
117 
118   /**
119    * \brief State transition callback function
120    * \param context the context string
121    * \param imsi the IMSI
122    * \param cellId the cell ID
123    * \param rnti the RNTI
124    * \param oldState the old state
125    * \param newState the new state
126    */
127   void UeStateTransitionCallback (std::string context, uint64_t imsi,
128                                   uint16_t cellId, uint16_t rnti,
129                                   LteUeRrc::State oldState, LteUeRrc::State newState);
130 
131   /**
132    * \brief Connection established at UE callback function
133    * \param context the context string
134    * \param imsi the IMSI
135    * \param cellId the cell ID
136    * \param rnti the RNTI
137    */
138   void ConnectionEstablishedUeCallback (std::string context, uint64_t imsi,
139                                         uint16_t cellId, uint16_t rnti);
140 
141   /**
142    * \brief Connection established at eNodeB callback function
143    * \param context the context string
144    * \param imsi the IMSI
145    * \param cellId the cell ID
146    * \param rnti the RNTI
147    */
148   void ConnectionEstablishedEnbCallback (std::string context, uint64_t imsi,
149                                          uint16_t cellId, uint16_t rnti);
150 
151   /**
152    * \brief This callback function is executed when UE context is removed at eNodeB
153    * \param context the context string
154    * \param imsi the IMSI
155    * \param cellId the cell ID
156    * \param rnti the RNTI
157    */
158   void ConnectionReleaseAtEnbCallback (std::string context, uint64_t imsi,
159                                        uint16_t cellId, uint16_t rnti);
160 
161   /**
162    * \brief This callback function is executed when UE RRC receives an in-sync or out-of-sync indication
163    * \param context the context string
164    * \param imsi the IMSI
165    * \param rnti the RNTI
166    * \param cellId the cell ID
167    * \param type in-sync or out-of-sync indication
168    * \param count the number of in-sync or out-of-sync indications
169    */
170   void PhySyncDetectionCallback (std::string context, uint64_t imsi, uint16_t rnti,
171                                  uint16_t cellId, std::string type, uint8_t count);
172 
173   /**
174    * \brief This callback function is executed when radio link failure is detected
175    * \param context the context string
176    * \param imsi the IMSI
177    * \param rnti the RNTI
178    * \param cellId the cell ID
179    */
180   void RadioLinkFailureCallback (std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti);
181 
182   /**
183    * \brief Jump away function
184    *
185    * \param UeJumpAwayPositionList A list of positions where UE would jump
186    */
187   void JumpAway (Vector UeJumpAwayPositionList);
188 
189   uint32_t m_numEnbs; ///<number of eNodeBs
190   uint32_t m_numUes; ///<number of UEs
191   Time m_simTime; ///< simulation time
192   bool m_isIdealRrc; ///< whether the LTE is configured to use ideal RRC
193   std::vector<Vector> m_uePositionList; ///< Position of the UEs
194   std::vector<Vector> m_enbPositionList; ///< Position of the eNodeBs
195   std::vector<Time> m_checkConnectedList; ///<the time at which UEs should have an active RRC connection
196   Vector m_ueJumpAwayPosition; ///< Position where the UE(s) would jump
197 
198   /// The current UE RRC state.
199   LteUeRrc::State m_lastState;
200 
201   bool m_radioLinkFailureDetected;  ///< true if radio link fails
202   uint32_t m_numOfInSyncIndications; ///< number of in-sync indications detected
203   uint32_t m_numOfOutOfSyncIndications; ///< number of out-of-sync indications detected
204   Ptr<MobilityModel> m_ueMobility; ///< UE mobility model
205 
206 }; // end of class LteRadioLinkFailureTestCase
207 
208 #endif /* LTE_TEST_RADIO_LINK_FAILURE_H */
209