<JIRA ID: ODUHIGH-358 : UE CONTEXT SETUP REQ multiple bearer creation>
[o-du/l2.git] / src / cu_stub / cu_stub.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
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                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
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 *******************************************************************************/
18
19 /* This functions contains main() for cu_app */
20 #include "common_def.h"
21 #include "cu_stub.h"
22 #include "cu_stub_sctp.h"
23 #include "cu_stub_egtp.h"
24 #include "du_log.h"
25
26 #ifdef O1_ENABLE
27 #include "ConfigInterface.h"
28 #endif
29
30 #define CU_ID 1
31 #define CU_NAME "ORAN_OAM_CU"
32
33 #define DU_IP_V6_ADDR "0000:0000:0000:0000:0000:0000:0000:0001"
34 #define CU_IP_V6_ADDR "0000:0000:0000:0000:0000:0000:0000:0011"
35
36 #ifndef O1_ENABLE
37
38 #define DU_IP_V4_ADDR "192.168.130.81"
39 #define CU_IP_V4_ADDR "192.168.130.82"
40 #define DU_PORT 38472
41 #define CU_PORT 38472 
42
43 #endif
44
45 #define DU_EGTP_PORT 39001
46 #define CU_EGTP_PORT 39002
47 #define RRC_VER 0
48 #define EXT_RRC_VER 5
49 #define PLMN_MCC0 3
50 #define PLMN_MCC1 1
51 #define PLMN_MCC2 1
52 #define PLMN_MNC0 4
53 #define PLMN_MNC1 8
54 #define PLMN_MNC2 0
55
56 #ifdef O1_ENABLE
57
58 extern StartupConfig g_cfg;
59
60 #endif
61
62
63 /*******************************************************************
64  *
65  * @brief Handles SCTP notification 
66  *
67  * @details
68  *
69  *    Function : sctpNtfyInd
70  *
71  *    Functionality:
72  *         Handles SCTP notification
73  *
74  * @params[in] sctp notification
75  * @return void
76  *
77  ******************************************************************/
78 void sctpNtfyInd(CmInetSctpNotification *ntfy)
79 {
80 //TODO
81 }
82
83 void init_log()
84 {
85     openlog("CU_STUB",LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
86 }
87 /*******************************************************************
88  *
89  * @brief Main function of CU APP
90  *
91  * @details
92  *
93  *    Function : main
94  *
95  *    Functionality:
96  *         - Reads CU related configurations
97  *         - Initialize SCTP Parameters
98  *         - Start SCTP receiver thread
99  *
100  * @params[in] 
101  * @return ROK     - success
102  *         RFAILED - failure
103  *
104  * ****************************************************************/
105
106 uint8_t tst()
107 {
108    int retVal=0;
109    pthread_t conThrdId;
110    pthread_attr_t attr;
111
112    init_log();   
113    DU_LOG("\nINFO   -->  CU_STUB : Starting CU_STUB\n");
114
115    /* Start thread to receive console input */
116    pthread_attr_init(&attr);
117    pthread_attr_setstacksize(&attr, (size_t)NULLD);
118    pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
119    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
120    retVal = pthread_create(&conThrdId, &attr, cuConsoleHandler, NULLP);
121    if(retVal != 0)
122    {
123       DU_LOG("\nERROR  -->  CU_STUB :  Thread creation failed. Cause %d", retVal);
124    }
125    pthread_attr_destroy(&attr);
126
127    /* Read CU configurations */
128    readCuCfg();
129
130    /* Start CU-EGTP */
131    egtpActvInit();
132    egtpInitReq();
133
134    /* Initializing SCTP global parameters */
135    sctpActvInit();
136  
137    /* Start CU-SCTP to listen on incoming connection */
138    sctpCfgReq();
139    sctpStartReq();
140
141    return ROK;
142 }
143
144 /*******************************************************************
145  *
146  * @brief Read CU related configuration
147  *
148  * @details
149  *
150  *    Function : readCuCfg
151  *
152  *    Functionality:
153  *            - RRead CU related configuration
154  *
155  * @params[in] 
156  * @return ROK     - success
157  *         RFAILED - failure
158  *
159  * ****************************************************************/
160
161 void readCuCfg()
162 {
163    uint32_t ipv4_du, ipv4_cu;
164
165    DU_LOG("\nDEBUG  -->  CU_STUB : Reading CU configurations");
166
167 #ifdef O1_ENABLE
168    if( getStartupConfigForStub(&g_cfg) != ROK )
169    {
170       DU_LOG("\nError  -->  CU_STUB : Could not fetch startup "\
171              "configurations from Netconf interface\n");
172       exit(1);
173    }
174    
175    cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
176    cmInetAddr((S8*)g_cfg.CU_IPV4_Addr, &ipv4_cu);
177
178    cuCfgParams.sctpParams.duPort = g_cfg.DU_Port;
179    cuCfgParams.sctpParams.cuPort = g_cfg.CU_Port;
180 #else
181    cmInetAddr((S8*)DU_IP_V4_ADDR, &ipv4_du);
182    cmInetAddr((S8*)CU_IP_V4_ADDR, &ipv4_cu);
183    cuCfgParams.sctpParams.duPort = DU_PORT;
184    cuCfgParams.sctpParams.cuPort = CU_PORT;
185 #endif
186     
187    cuCfgParams.cuId = CU_ID;
188    strcpy(cuCfgParams.cuName, CU_NAME);
189  
190    /* DU IP Address and Port*/
191    cuCfgParams.sctpParams.duIpAddr.ipV4Addr = ipv4_du;
192    cuCfgParams.sctpParams.duIpAddr.ipV6Pres = false;
193
194    /* CU IP Address and Port*/
195    cuCfgParams.sctpParams.cuIpAddr.ipV4Addr = ipv4_cu;
196    cuCfgParams.sctpParams.cuIpAddr.ipV6Pres = false;
197
198    /*PLMN*/
199    cuCfgParams.plmn.mcc[0] = PLMN_MCC0;
200    cuCfgParams.plmn.mcc[1] = PLMN_MCC1;
201    cuCfgParams.plmn.mcc[2] = PLMN_MCC2;
202    cuCfgParams.plmn.mnc[0] = PLMN_MNC0;
203    cuCfgParams.plmn.mnc[1] = PLMN_MNC1;
204    cuCfgParams.plmn.mnc[2] = PLMN_MNC2;
205
206    /*RRC Version*/
207    cuCfgParams.rrcVersion.rrcVer = RRC_VER;
208    cuCfgParams.rrcVersion.extRrcVer = EXT_RRC_VER;
209
210
211    /* EGTP Parameters */
212    cuCfgParams.egtpParams.localIp.ipV4Pres = TRUE;
213    cuCfgParams.egtpParams.localIp.ipV4Addr = ipv4_cu;
214    cuCfgParams.egtpParams.localPort = CU_EGTP_PORT;
215    cuCfgParams.egtpParams.destIp.ipV4Pres = TRUE;
216    cuCfgParams.egtpParams.destIp.ipV4Addr = ipv4_du;
217    cuCfgParams.egtpParams.destPort = DU_EGTP_PORT;
218    cuCfgParams.egtpParams.minTunnelId = MIN_TEID;
219    cuCfgParams.egtpParams.currTunnelId = cuCfgParams.egtpParams.minTunnelId;
220    cuCfgParams.egtpParams.maxTunnelId = MAX_TEID;
221
222 } /* End of readCuCfg */
223
224 /*******************************************************************
225  *
226  * @brief Handles Console input
227  *
228  * @details
229  *
230  *    Function : cuConsoleHandler
231  *
232  *    Functionality: Handles Console input
233  *
234  * @params[in] 
235  * @return ROK     - success
236  *         RFAILED - failure
237  *
238  * ****************************************************************/
239 void *cuConsoleHandler(void *args)
240 {
241    char ch;
242    uint8_t teId = 0;
243    uint8_t ret = ROK;
244
245    while(true) 
246    {
247       /* Send DL user data to CU when user enters 'd' on console */
248       if((ch = getchar()) == 'd')
249       {
250
251          uint8_t cnt =0;
252          DU_LOG("\n EGTP --> : Enter TEID id(1..10) where DL Data to be sent\n");
253          scanf("%d",&teId);
254          
255          if(teId > MAX_TEID || teId < MIN_TEID)
256          {
257             DU_LOG("\nERROR  -->  EGTP : TEID(%x) OUT Of Range",teId);
258             printf("\n");
259             continue;
260          }
261          /* Start Pumping data from CU to DU */
262          DU_LOG("\nDEBUG  -->  EGTP: Sending DL User Data(teId:%d)\n",teId);
263          
264          while(cnt < NUM_DL_PACKETS)
265          {
266            ret =  cuEgtpDatReq(teId);      
267            if(ret != ROK)
268            {
269              DU_LOG("\nERROR --> EGTP: Issue with teid=%d\n",teId);
270              break;
271            }
272            cnt++;
273          }
274          continue;
275       } 
276    }
277 }
278 /**********************************************************************
279          End of file
280 **********************************************************************/