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"
26 #include "CmInterface.h"
32 extern StartupConfig g_cfg;
37 /*******************************************************************
39 * @brief Handles SCTP notification
43 * Function : sctpNtfyInd
46 * Handles SCTP notification
48 * @params[in] sctp notification
51 ******************************************************************/
52 void sctpNtfyInd(CmInetSctpNotification *ntfy)
59 openlog("CU_STUB",LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
61 /*******************************************************************
63 * @brief Main function of CU APP
70 * - Reads CU related configurations
71 * - Initialize SCTP Parameters
72 * - Start SCTP receiver thread
75 * @return ROK - success
78 * ****************************************************************/
87 DU_LOG("\nINFO --> CU_STUB : Starting CU_STUB\n");
89 /* Start thread to receive console input */
90 pthread_attr_init(&attr);
91 pthread_attr_setstacksize(&attr, (size_t)NULLD);
92 pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
93 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
94 retVal = pthread_create(&conThrdId, &attr, cuConsoleHandler, NULLP);
97 DU_LOG("\nERROR --> CU_STUB : Thread creation failed. Cause %d", retVal);
99 pthread_attr_destroy(&attr);
101 /* Read CU configurations */
108 /* Initializing SCTP global parameters */
111 /* Start CU-SCTP to listen on incoming connection */
118 /*******************************************************************
120 * @brief Read CU related configuration
124 * Function : readCuCfg
127 * - RRead CU related configuration
130 * @return ROK - success
133 * ****************************************************************/
138 uint32_t ipv4_du, ipv4_cu;
140 DU_LOG("\nDEBUG --> CU_STUB : Reading CU configurations");
142 cuCb.cuCfgParams.cuId = CU_ID;
143 strcpy(cuCb.cuCfgParams.cuName, CU_NAME);
146 if( getStartupConfigForStub(&g_cfg) != ROK )
148 DU_LOG("\nError --> CU_STUB : Could not fetch startup "\
149 "configurations from Netconf interface\n");
153 cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
154 cmInetAddr((S8*)g_cfg.CU_IPV4_Addr, &ipv4_cu);
156 cuCb.cuCfgParams.sctpParams.duPort = g_cfg.DU_Port;
157 cuCb.cuCfgParams.sctpParams.cuPort = g_cfg.CU_Port;
159 cuCb.cuCfgParams.sctpParams.numDu = 0;
160 numDu = &cuCb.cuCfgParams.sctpParams.numDu;
161 while(*numDu < MAX_DU_SUPPORTED)
163 /* DU IP Address and Port*/
164 memset(&ipv4_du, 0, sizeof(uint32_t));
165 cmInetAddr((S8*)DU_IP_V4_ADDR[*numDu], &ipv4_du);
166 cuCb.cuCfgParams.sctpParams.sctpAssoc[*numDu].duIpAddr.ipV4Addr = ipv4_du;
167 cuCb.cuCfgParams.sctpParams.sctpAssoc[*numDu].duIpAddr.ipV6Pres = false;
168 cuCb.cuCfgParams.sctpParams.sctpAssoc[*numDu].duPort = DU_SCTP_PORT[*numDu];
170 /* CU IP Address and Port*/
171 memset(&ipv4_du, 0, sizeof(uint32_t));
172 cmInetAddr((S8*)CU_IP_V4_ADDR, &ipv4_cu);
173 cuCb.cuCfgParams.sctpParams.sctpAssoc[*numDu].cuIpAddr.ipV4Addr = ipv4_cu;
174 cuCb.cuCfgParams.sctpParams.sctpAssoc[*numDu].cuIpAddr.ipV6Pres = false;
175 cuCb.cuCfgParams.sctpParams.sctpAssoc[*numDu].cuPort = CU_SCTP_PORT_TO_DU[*numDu];
182 cuCb.cuCfgParams.plmn.mcc[0] = PLMN_MCC0;
183 cuCb.cuCfgParams.plmn.mcc[1] = PLMN_MCC1;
184 cuCb.cuCfgParams.plmn.mcc[2] = PLMN_MCC2;
185 cuCb.cuCfgParams.plmn.mnc[0] = PLMN_MNC0;
186 cuCb.cuCfgParams.plmn.mnc[1] = PLMN_MNC1;
187 cuCb.cuCfgParams.plmn.mnc[2] = PLMN_MNC2;
190 cuCb.cuCfgParams.rrcVersion.rrcVer = RRC_VER;
191 cuCb.cuCfgParams.rrcVersion.extRrcVer = EXT_RRC_VER;
194 /* EGTP Parameters */
195 cuCb.cuCfgParams.egtpParams.localIp.ipV4Pres = TRUE;
196 cuCb.cuCfgParams.egtpParams.localIp.ipV4Addr = ipv4_cu;
197 cuCb.cuCfgParams.egtpParams.localPort = CU_EGTP_PORT;
198 cuCb.cuCfgParams.egtpParams.destIp.ipV4Pres = TRUE;
199 cuCb.cuCfgParams.egtpParams.destIp.ipV4Addr = ipv4_du;
200 cuCb.cuCfgParams.egtpParams.destPort = DU_EGTP_PORT;
201 cuCb.cuCfgParams.egtpParams.minTunnelId = MIN_TEID;
202 cuCb.cuCfgParams.egtpParams.currTunnelId = cuCb.cuCfgParams.egtpParams.minTunnelId;
203 cuCb.cuCfgParams.egtpParams.maxTunnelId = MAX_TEID;
205 } /* End of readCuCfg */
207 /*******************************************************************
209 * @brief Handles Console input
213 * Function : cuConsoleHandler
215 * Functionality: Handles Console input
218 * @return ROK - success
221 * ****************************************************************/
222 void *cuConsoleHandler(void *args)
229 /* This variable is taken for sending specific number of downlink data packet.
230 * Presently the code is supporting total 4500 data packets trasfer for 3 UEs only with sleep(1).
231 * If you wants to pump data for 3 UE change the following macro values
232 * NUM_TUNNEL_TO_PUMP_DATA = 9, NUM_DL_PACKETS = 1.
233 * totalDataPacket = totalNumOfTestFlow * NUM_TUNNEL_TO_PUMP_DATA * NUM_DL_PACKETS
234 * totalDataPacket = [500*9*1] */
235 int32_t totalNumOfTestFlow = 500;
239 /* Send DL user data to CU when user enters 'd' on console */
240 if((ch = getchar()) == 'd')
243 /* Change #if 0 to #if 1 to take input from user */
245 DU_LOG("\n EGTP --> : Enter TEID id(1..10) where DL Data to be sent\n");
248 if(teId > MAX_TEID || teId < MIN_TEID)
250 DU_LOG("\nERROR --> EGTP : TEID(%x) OUT Of Range",teId);
254 /* Start Pumping data from CU to DU */
255 DU_LOG("\nDEBUG --> EGTP: Sending DL User Data(teId:%d)\n",teId);
258 while(cnt < NUM_DL_PACKETS)
260 ret = cuEgtpDatReq(teId);
263 DU_LOG("\nERROR --> EGTP: Issue with teid=%d\n",teId);
269 while(totalNumOfTestFlow)
271 for(teId = 1; teId <= NUM_TUNNEL_TO_PUMP_DATA; teId++)
273 DU_LOG("\nDEBUG --> EGTP: Sending DL User Data(teId:%d)\n",teId);
275 while(cnt < NUM_DL_PACKETS)
277 ret = cuEgtpDatReq(teId);
280 DU_LOG("\nERROR --> EGTP: Issue with teid=%d\n",teId);
283 /* TODO : sleep(1) will be removed later once we will be able to
284 * support the continuous data pack transfer */
289 totalNumOfTestFlow--;
296 /**********************************************************************
298 **********************************************************************/