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