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 Handles SCTP notification
42 * Function : sctpNtfyInd
45 * Handles SCTP notification
47 * @params[in] sctp notification
50 ******************************************************************/
51 void sctpNtfyInd(CmInetSctpNotification *ntfy)
58 openlog("CU_STUB",LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
60 /*******************************************************************
62 * @brief Main function of CU APP
69 * - Reads CU related configurations
70 * - Initialize SCTP Parameters
71 * - Start SCTP receiver thread
74 * @return ROK - success
77 * ****************************************************************/
86 DU_LOG("\nINFO --> CU_STUB : Starting CU_STUB\n");
88 /* Start thread to receive console input */
89 pthread_attr_init(&attr);
90 pthread_attr_setstacksize(&attr, (size_t)NULLD);
91 pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
92 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
93 retVal = pthread_create(&conThrdId, &attr, cuConsoleHandler, NULLP);
96 DU_LOG("\nERROR --> CU_STUB : Thread creation failed. Cause %d", retVal);
98 pthread_attr_destroy(&attr);
100 /* Read CU configurations */
107 /* Initializing SCTP global parameters */
110 /* Start CU-SCTP to listen on incoming connection */
117 /*******************************************************************
119 * @brief Read CU related configuration
123 * Function : readCuCfg
126 * - RRead CU related configuration
129 * @return ROK - success
132 * ****************************************************************/
137 uint32_t ipv4_du, ipv4_cu;
139 DU_LOG("\nDEBUG --> CU_STUB : Reading CU configurations");
141 cuCb.cuCfgParams.cuId = CU_ID;
142 strcpy(cuCb.cuCfgParams.cuName, CU_NAME);
145 if( getStartupConfigForStub(&g_cfg) != ROK )
147 DU_LOG("\nError --> CU_STUB : Could not fetch startup "\
148 "configurations from Netconf interface\n");
152 cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
153 cuCb.cuCfgParams.sctpParams.sctpAssoc[0].duIpAddr.ipV4Addr = ipv4_du;
154 cuCb.cuCfgParams.sctpParams.sctpAssoc[0].duIpAddr.ipV6Pres = false;
156 cmInetAddr((S8*)g_cfg.CU_IPV4_Addr, &ipv4_cu);
157 cuCb.cuCfgParams.sctpParams.sctpAssoc[0].cuIpAddr.ipV4Addr = ipv4_cu;
158 cuCb.cuCfgParams.sctpParams.sctpAssoc[0].cuIpAddr.ipV6Pres = false;
160 cuCb.cuCfgParams.sctpParams.sctpAssoc[0].duPort = g_cfg.DU_Port;
161 cuCb.cuCfgParams.sctpParams.sctpAssoc[0].cuPort = g_cfg.CU_Port;
162 cuCb.cuCfgParams.sctpParams.numDu = 1;
164 cuCb.cuCfgParams.sctpParams.numDu = 0;
165 cuCb.cuCfgParams.egtpParams.numDu = 0;
167 while(numDu < MAX_DU_SUPPORTED)
169 /* DU IP Address and Port*/
170 memset(&ipv4_du, 0, sizeof(uint32_t));
171 cmInetAddr((S8*)DU_IP_V4_ADDR[numDu], &ipv4_du);
172 cuCb.cuCfgParams.sctpParams.sctpAssoc[numDu].duIpAddr.ipV4Addr = ipv4_du;
173 cuCb.cuCfgParams.sctpParams.sctpAssoc[numDu].duIpAddr.ipV6Pres = false;
174 cuCb.cuCfgParams.sctpParams.sctpAssoc[numDu].duPort = DU_SCTP_PORT[numDu];
176 /* CU IP Address and Port*/
177 memset(&ipv4_du, 0, sizeof(uint32_t));
178 cmInetAddr((S8*)CU_IP_V4_ADDR, &ipv4_cu);
179 cuCb.cuCfgParams.sctpParams.sctpAssoc[numDu].cuIpAddr.ipV4Addr = ipv4_cu;
180 cuCb.cuCfgParams.sctpParams.sctpAssoc[numDu].cuIpAddr.ipV6Pres = false;
181 cuCb.cuCfgParams.sctpParams.sctpAssoc[numDu].cuPort = CU_SCTP_PORT_TO_DU[numDu];
183 /* EGTP Parameters */
184 memset(&ipv4_du, 0, sizeof(uint32_t));
185 cmInetAddr((S8*)DU_IP_V4_ADDR[numDu], &ipv4_du);
186 cuCb.cuCfgParams.egtpParams.egtpAssoc[numDu].localIp.ipV4Pres = TRUE;
187 cuCb.cuCfgParams.egtpParams.egtpAssoc[numDu].localIp.ipV4Addr = ipv4_cu;
188 cuCb.cuCfgParams.egtpParams.egtpAssoc[numDu].localPort = CU_EGTP_PORT[numDu];
189 cuCb.cuCfgParams.egtpParams.egtpAssoc[numDu].destIp.ipV4Pres = TRUE;
190 cuCb.cuCfgParams.egtpParams.egtpAssoc[numDu].destIp.ipV4Addr = ipv4_du;
191 cuCb.cuCfgParams.egtpParams.egtpAssoc[numDu].destPort = DU_EGTP_PORT[numDu];
196 cuCb.cuCfgParams.egtpParams.minTunnelId = MIN_TEID;
197 cuCb.cuCfgParams.egtpParams.currTunnelId = cuCb.cuCfgParams.egtpParams.minTunnelId;
198 cuCb.cuCfgParams.egtpParams.maxTunnelId = MAX_TEID;
199 cuCb.cuCfgParams.egtpParams.numDu = numDu;
200 cuCb.cuCfgParams.sctpParams.numDu = numDu;
204 cuCb.cuCfgParams.plmn.mcc[0] = PLMN_MCC0;
205 cuCb.cuCfgParams.plmn.mcc[1] = PLMN_MCC1;
206 cuCb.cuCfgParams.plmn.mcc[2] = PLMN_MCC2;
207 cuCb.cuCfgParams.plmn.mnc[0] = PLMN_MNC0;
208 cuCb.cuCfgParams.plmn.mnc[1] = PLMN_MNC1;
209 cuCb.cuCfgParams.plmn.mnc[2] = PLMN_MNC2;
212 cuCb.cuCfgParams.rrcVersion.rrcVer = RRC_VER;
213 cuCb.cuCfgParams.rrcVersion.extRrcVer = EXT_RRC_VER;
217 } /* End of readCuCfg */
219 /*******************************************************************
221 * @brief Initiates inter DU handover
225 * Function : initiateInterDuHandover
227 * Functionality: Initiates the first procedure of inter-DU
228 * handover i.eG GNB-DU configuration query to source DU
230 * @params[in] Source DU Id
232 * UE Id to be handed off
233 * @return ROK - success
236 * ****************************************************************/
237 void initiateInterDuHandover(uint32_t sourceDuId, uint32_t targetDuId, uint32_t ueId)
241 CuUeCb *ueCb = NULLP;
243 SEARCH_DU_DB(duIdx, sourceDuId, duDb);
245 ueCb = &duDb->ueCb[ueId-1];
248 ueCb->state = UE_HANDOVER_IN_PROGRESS;
249 ueCb->hoInfo.sourceDuId = sourceDuId;
250 ueCb->hoInfo.targetDuId = targetDuId;
253 DU_LOG("\nINFO --> CU_STUB: Inter-DU Handover Started for ueId [%d] from DU ID [%d] to DU ID [%d]", \
254 ueId, sourceDuId, targetDuId);
255 BuildAndSendUeContextModificationReq(sourceDuId, ueCb, QUERY_CONFIG);
258 /*******************************************************************
260 * @brief Handles Console input
264 * Function : cuConsoleHandler
266 * Functionality: Handles Console input
269 * @return ROK - success
272 * ****************************************************************/
273 void *cuConsoleHandler(void *args)
280 EgtpTeIdCb *teidCb = NULLP;
285 /* Send DL user data to CU when user enters 'd' on console */
289 /* Change #if 0 to #if 1 to take input from user */
291 DU_LOG("\n EGTP --> : Enter TEID id(1..10) where DL Data to be sent\n");
294 if(teId > MAX_TEID || teId < MIN_TEID)
296 DU_LOG("\nERROR --> EGTP : TEID(%x) OUT Of Range",teId);
300 /* Start Pumping data from CU to DU */
301 DU_LOG("\nDEBUG --> EGTP: Sending DL User Data(teId:%d)\n",teId);
304 while(cnt < NUM_DL_PACKETS)
306 ret = cuEgtpDatReq(teId);
309 DU_LOG("\nERROR --> EGTP: Issue with teid=%d\n",teId);
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 = 2;
324 while(totalNumOfTestFlow)
326 for(duId = 1; duId<=MAX_DU_SUPPORTED; duId++)
328 for(teId = 1; teId <= NUM_TUNNEL_TO_PUMP_DATA; teId++)
331 cmHashListFind(&(egtpCb.dstCb[duId-1].teIdLst), (uint8_t *)&(teId), sizeof(uint32_t), 0, (PTR *)&teidCb);
335 DU_LOG("\nDEBUG --> EGTP: Sending DL User Data(duId %d, teId:%d)\n", duId, teId);
336 while(cnt < NUM_DL_PACKETS)
338 ret = cuEgtpDatReq(duId, teId);
341 DU_LOG("\nERROR --> EGTP: Issue with teid=%d\n",teId);
344 /* TODO : sleep(1) will be removed later once we will be able to
345 * support the continuous data pack transfer */
352 DU_LOG("\nDEBUG --> EGTP: TunnelId Not Found for (duId %d, teId:%d)\n", duId, teId);
356 totalNumOfTestFlow--;
362 /* Start Handover procedure towards DU when 'h' is received from console input */
365 uint32_t sourceDuId, targetDuId, ueId;
367 DU_LOG("\nEnter Source DU ID for Inter-DU Handover");
368 scanf("%d", &sourceDuId);
369 DU_LOG("\nEnter Target DU ID for Inter-DU Handover");
370 scanf("%d", &targetDuId);
371 DU_LOG("\nEnter DU UE F1AP ID to be handed over");
374 initiateInterDuHandover(sourceDuId, targetDuId, ueId);
376 /* Start Idle mode paging when 'p' is received from console input */
382 DU_LOG("\nEnter DU ID on which this UE to be pagged");
384 DU_LOG("\nEnter 5g-S-TMSI");
385 scanf("%lu", &sTmsi);
387 if(BuildAndSendPagingMsg(sTmsi, duId) != ROK)
389 DU_LOG("\nERROR --> EGTP: Failed to build and send paging message for 5gsTmsi[%lu]\n", sTmsi);
395 /**********************************************************************
397 **********************************************************************/