1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 /* This functions contains main() for cu_app */
20 #include "common_def.h"
21 #include "cu_stub_sctp.h"
22 #include "cu_stub_egtp.h"
23 #include "OCTET_STRING.h"
24 #include "cu_f1ap_msg_hdl.h"
28 #include "CmInterface.h"
33 extern StartupConfig g_cfg;
36 /*******************************************************************
38 * @brief Fetches pointer to DU Database
45 * Searches and returns pointer to DU structure based on DU Id
48 * @return Pointer to DU Db
50 ******************************************************************/
51 DuDb* getDuDb(uint32_t duId)
54 for(duIdx=0; duIdx < cuCb.numDu; duIdx++)
56 if(cuCb.duInfo[duIdx].duId == duId)
57 return (&cuCb.duInfo[duIdx]);
62 /*******************************************************************
64 * @brief Fetches pointer to Cell Cb
68 * Function : getCellCb
71 * Searches for a cell within a DU based on NR cell Id
72 * Returns pointer to this cell Cb structure
74 * @params[in] Pointer to DU Db
76 * @return Pointer to cell Cb
78 ******************************************************************/
79 CuCellCb* getCellCb(DuDb *duDb, uint32_t cellId)
82 for(cellIdx=0; cellIdx < duDb->numCells; cellIdx++)
84 if(duDb->cellCb[cellIdx].nrCellId == cellId)
85 return &(duDb->cellCb[cellIdx]);
90 /*******************************************************************
92 * @brief Handles SCTP notification
96 * Function : sctpNtfyInd
99 * Handles SCTP notification
101 * @params[in] sctp notification
104 ******************************************************************/
105 void sctpNtfyInd(CmInetSctpNotification *ntfy)
112 openlog("CU_STUB",LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
114 /*******************************************************************
116 * @brief Main function of CU APP
123 * - Reads CU related configurations
124 * - Initialize SCTP Parameters
125 * - Start SCTP receiver thread
128 * @return ROK - success
131 * ****************************************************************/
140 DU_LOG("\nINFO --> CU_STUB : Starting CU_STUB\n");
142 /* Start thread to receive console input */
143 pthread_attr_init(&attr);
144 pthread_attr_setstacksize(&attr, (size_t)NULLD);
145 pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
146 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
147 retVal = pthread_create(&conThrdId, &attr, cuConsoleHandler, NULLP);
150 DU_LOG("\nERROR --> CU_STUB : Thread creation failed. Cause %d", retVal);
152 pthread_attr_destroy(&attr);
154 /* Read CU configurations */
161 /* Initializing SCTP global parameters */
164 /* Start CU-SCTP to listen on incoming connection */
171 /*******************************************************************
173 * @brief Read CU related configuration
177 * Function : readCuCfg
180 * - RRead CU related configuration
183 * @return ROK - success
186 * ****************************************************************/
191 uint32_t ipv4_du, ipv4_cu;
193 DU_LOG("\nDEBUG --> CU_STUB : Reading CU configurations");
195 cuCb.cuCfgParams.cuId = CU_ID;
196 strcpy(cuCb.cuCfgParams.cuName, CU_NAME);
199 if( getStartupConfigForStub(&g_cfg) != ROK )
201 DU_LOG("\nError --> CU_STUB : Could not fetch startup "\
202 "configurations from Netconf interface\n");
206 cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
207 cmInetAddr((S8*)g_cfg.CU_IPV4_Addr, &ipv4_cu);
209 cuCb.cuCfgParams.sctpParams.duPort = g_cfg.DU_Port;
210 cuCb.cuCfgParams.sctpParams.cuPort = g_cfg.CU_Port;
212 cuCb.cuCfgParams.sctpParams.numDu = 0;
213 numDu = &cuCb.cuCfgParams.sctpParams.numDu;
214 while(*numDu < MAX_DU_SUPPORTED)
216 /* DU IP Address and Port*/
217 memset(&ipv4_du, 0, sizeof(uint32_t));
218 cmInetAddr((S8*)DU_IP_V4_ADDR[*numDu], &ipv4_du);
219 cuCb.cuCfgParams.sctpParams.sctpAssoc[*numDu].duIpAddr.ipV4Addr = ipv4_du;
220 cuCb.cuCfgParams.sctpParams.sctpAssoc[*numDu].duIpAddr.ipV6Pres = false;
221 cuCb.cuCfgParams.sctpParams.sctpAssoc[*numDu].duPort = DU_SCTP_PORT[*numDu];
223 /* CU IP Address and Port*/
224 memset(&ipv4_du, 0, sizeof(uint32_t));
225 cmInetAddr((S8*)CU_IP_V4_ADDR, &ipv4_cu);
226 cuCb.cuCfgParams.sctpParams.sctpAssoc[*numDu].cuIpAddr.ipV4Addr = ipv4_cu;
227 cuCb.cuCfgParams.sctpParams.sctpAssoc[*numDu].cuIpAddr.ipV6Pres = false;
228 cuCb.cuCfgParams.sctpParams.sctpAssoc[*numDu].cuPort = CU_SCTP_PORT_TO_DU[*numDu];
235 cuCb.cuCfgParams.plmn.mcc[0] = PLMN_MCC0;
236 cuCb.cuCfgParams.plmn.mcc[1] = PLMN_MCC1;
237 cuCb.cuCfgParams.plmn.mcc[2] = PLMN_MCC2;
238 cuCb.cuCfgParams.plmn.mnc[0] = PLMN_MNC0;
239 cuCb.cuCfgParams.plmn.mnc[1] = PLMN_MNC1;
240 cuCb.cuCfgParams.plmn.mnc[2] = PLMN_MNC2;
243 cuCb.cuCfgParams.rrcVersion.rrcVer = RRC_VER;
244 cuCb.cuCfgParams.rrcVersion.extRrcVer = EXT_RRC_VER;
247 /* EGTP Parameters */
248 cuCb.cuCfgParams.egtpParams.localIp.ipV4Pres = TRUE;
249 cuCb.cuCfgParams.egtpParams.localIp.ipV4Addr = ipv4_cu;
250 cuCb.cuCfgParams.egtpParams.localPort = CU_EGTP_PORT;
251 cuCb.cuCfgParams.egtpParams.destIp.ipV4Pres = TRUE;
252 cuCb.cuCfgParams.egtpParams.destIp.ipV4Addr = ipv4_du;
253 cuCb.cuCfgParams.egtpParams.destPort = DU_EGTP_PORT;
254 cuCb.cuCfgParams.egtpParams.minTunnelId = MIN_TEID;
255 cuCb.cuCfgParams.egtpParams.currTunnelId = cuCb.cuCfgParams.egtpParams.minTunnelId;
256 cuCb.cuCfgParams.egtpParams.maxTunnelId = MAX_TEID;
258 } /* End of readCuCfg */
260 /*******************************************************************
262 * @brief Initiates inter DU handover
266 * Function : initiateInterDuHandover
268 * Functionality: Initiates the first procedure of inter-DU
269 * handover i.eG GNB-DU configuration query to source DU
271 * @params[in] Source DU Id
273 * UE Id to be handed off
274 * @return ROK - success
277 * ****************************************************************/
278 void initiateInterDuHandover(uint32_t sourceDuId, uint32_t targetDuId, uint32_t ueId)
281 CuUeCb *ueCb = NULLP;
283 duDb = getDuDb(sourceDuId);
285 ueCb = &duDb->ueCb[ueId-1];
287 ueCb->state = HANDOVER_IN_PROGRESS;
289 DU_LOG("\nINFO --> CU_STUB: Inter-DU Handover Started for ueId [%d] from DU ID [%d] to DU ID [%d]", \
290 ueId, sourceDuId, targetDuId);
291 BuildAndSendUeContextModificationReq(sourceDuId, ueCb, QUERY_CONFIG);
294 /*******************************************************************
296 * @brief Handles Console input
300 * Function : cuConsoleHandler
302 * Functionality: Handles Console input
305 * @return ROK - success
308 * ****************************************************************/
309 void *cuConsoleHandler(void *args)
316 /* This variable is taken for sending specific number of downlink data packet.
317 * Presently the code is supporting total 4500 data packets trasfer for 3 UEs only with sleep(1).
318 * If you wants to pump data for 3 UE change the following macro values
319 * NUM_TUNNEL_TO_PUMP_DATA = 9, NUM_DL_PACKETS = 1.
320 * totalDataPacket = totalNumOfTestFlow * NUM_TUNNEL_TO_PUMP_DATA * NUM_DL_PACKETS
321 * totalDataPacket = [500*9*1] */
322 int32_t totalNumOfTestFlow = 500;
327 /* Send DL user data to CU when user enters 'd' on console */
331 /* Change #if 0 to #if 1 to take input from user */
333 DU_LOG("\n EGTP --> : Enter TEID id(1..10) where DL Data to be sent\n");
336 if(teId > MAX_TEID || teId < MIN_TEID)
338 DU_LOG("\nERROR --> EGTP : TEID(%x) OUT Of Range",teId);
342 /* Start Pumping data from CU to DU */
343 DU_LOG("\nDEBUG --> EGTP: Sending DL User Data(teId:%d)\n",teId);
346 while(cnt < NUM_DL_PACKETS)
348 ret = cuEgtpDatReq(teId);
351 DU_LOG("\nERROR --> EGTP: Issue with teid=%d\n",teId);
357 while(totalNumOfTestFlow)
359 for(teId = 1; teId <= NUM_TUNNEL_TO_PUMP_DATA; teId++)
361 DU_LOG("\nDEBUG --> EGTP: Sending DL User Data(teId:%d)\n",teId);
363 while(cnt < NUM_DL_PACKETS)
365 ret = cuEgtpDatReq(teId);
368 DU_LOG("\nERROR --> EGTP: Issue with teid=%d\n",teId);
371 /* TODO : sleep(1) will be removed later once we will be able to
372 * support the continuous data pack transfer */
377 totalNumOfTestFlow--;
383 /* Start Handover procedure towards DU when 'h' is received from console input */
386 uint32_t sourceDuId, targetDuId, ueId;
388 DU_LOG("\nEnter Source DU ID for Inter-DU Handover");
389 scanf("%d", &sourceDuId);
390 DU_LOG("\nEnter Target DU ID for Inter-DU Handover");
391 scanf("%d", &targetDuId);
392 DU_LOG("\nEnter DU UE F1AP ID to be handed over");
395 initiateInterDuHandover(sourceDuId, targetDuId, ueId);
399 /**********************************************************************
401 **********************************************************************/