<[Epic-ID: ODUHIGH-406][Task-ID: ODUHIGH-421]Paging Message: CU_STUB Trigger and...
[o-du/l2.git] / src / ric_stub / ric_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 ric_app */
20 #include "common_def.h"
21 #include "ric_stub_sctp.h"
22 #include "ric_stub.h"
23
24 #ifdef O1_ENABLE
25 #include "CmInterface.h"
26 #endif
27
28 #ifdef O1_ENABLE
29 extern StartupConfig g_cfg;
30 #endif
31
32 /*******************************************************************
33  *
34  * @brief Handles SCTP notification 
35  *
36  * @details
37  *
38  *    Function : sctpNtfyInd
39  *
40  *    Functionality:
41  *         Handles SCTP notification
42  *
43  * @params[in] sctp notification
44  * @return void
45  *
46  ******************************************************************/
47 void sctpNtfyInd(CmInetSctpNotification *ntfy)
48 {
49 //TODO
50 }
51
52 void init_log()
53 {
54         openlog("RIC_STUB",LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
55 }
56 /*******************************************************************
57  *
58  * @brief Main function of E2 APP
59  *
60  * @details
61  *
62  *    Function : main
63  *
64  *    Functionality:
65  *         - Reads RIC related configurations
66  *         - Initialize SCTP Parameters
67  *         - Start SCTP receiver thread
68  *
69  * @params[in] 
70  * @return ROK     - success
71  *         RFAILED - failure
72  *
73  * ****************************************************************/
74
75 uint8_t tst()
76 {
77    init_log();   
78  
79    DU_LOG("\nINFO  --> RIC : Starting RIC_STUB");
80    /* Read RIC configurations */
81    readRicCfg();
82
83    /* Start RIC-SCTP to listen on incoming connection */
84    sctpCfgReq();
85    /*Sleep is introduced for GDB to increase the waiting time for RIC Configuration from DUAPP*/
86    sleep(1);
87    sctpStartReq();
88
89    return ROK;
90 }
91 /*******************************************************************
92  *
93  * @brief Read RIC related configuration
94  *
95  * @details
96  *
97  *    Function : readRicCfg
98  *
99  *    Functionality:
100  *            - Read RIC related configuration
101  *
102  * @params[in] 
103  * @return ROK     - success
104  *         RFAILED - failure
105  *
106  * ****************************************************************/
107
108 void readRicCfg()
109 {
110    uint8_t *numDu;
111    uint32_t ipv4_du, ipv4_ric;
112
113    DU_LOG("\nINFO  --> RIC : Reading RIC configurations");
114
115    ricCfgParams.ricId = RIC_ID;
116    strcpy(ricCfgParams.ricName, RIC_NAME);
117 #ifdef O1_ENABLE
118    if( getStartupConfigForStub(&g_cfg) != ROK )
119    {
120       DU_LOG("\nError  -->  RIC : Could not fetch startup "\
121              "configurations from Netconf interface\n");
122       exit(1);
123    }
124
125    cmInetAddr((S8*)g_cfg.DU_IPV4_Addr,  &ipv4_du);
126    cmInetAddr((S8*)g_cfg.RIC_IPV4_Addr, &ipv4_ric);
127    
128    ricCfgParams.sctpParams.sctpAssoc[0].duIpAddr.ipV4Addr = ipv4_du;
129    ricCfgParams.sctpParams.sctpAssoc[0].duIpAddr.ipV6Pres = false;
130    ricCfgParams.sctpParams.sctpAssoc[0].duPort = g_cfg.RIC_Port;
131
132    ricCfgParams.sctpParams.sctpAssoc[0].ricIpAddr.ipV4Addr = ipv4_ric;
133    ricCfgParams.sctpParams.sctpAssoc[0].ricIpAddr.ipV6Pres = false;
134    ricCfgParams.sctpParams.sctpAssoc[0].ricPort = g_cfg.RIC_Port;
135
136    ricCfgParams.sctpParams.numDu = 1;
137
138 #else
139    ricCfgParams.sctpParams.numDu = 0;
140    numDu = &ricCfgParams.sctpParams.numDu;
141    while(*numDu < MAX_DU_SUPPORTED)
142    {   
143       /* DU IP Address and Port*/
144       memset(&ipv4_du, 0, sizeof(uint32_t));
145       cmInetAddr((S8*)DU_IP_V4_ADDR[*numDu], &ipv4_du);
146       ricCfgParams.sctpParams.sctpAssoc[*numDu].duIpAddr.ipV4Addr = ipv4_du;
147       ricCfgParams.sctpParams.sctpAssoc[*numDu].duIpAddr.ipV6Pres = false;
148       ricCfgParams.sctpParams.sctpAssoc[*numDu].duPort = DU_SCTP_PORT[*numDu];
149
150       /* RIC IP Address and Port*/
151       memset(&ipv4_du, 0, sizeof(uint32_t));
152       cmInetAddr((S8*)RIC_IP_V4_ADDR, &ipv4_ric);
153       ricCfgParams.sctpParams.sctpAssoc[*numDu].ricIpAddr.ipV4Addr = ipv4_ric;
154       ricCfgParams.sctpParams.sctpAssoc[*numDu].ricIpAddr.ipV6Pres = false;
155       ricCfgParams.sctpParams.sctpAssoc[*numDu].ricPort = RIC_SCTP_PORT_TO_DU[*numDu];
156       (*numDu)++;
157    }   
158 #endif
159
160    /*PLMN*/
161    ricCfgParams.plmn.mcc[0] = PLMN_MCC0;
162    ricCfgParams.plmn.mcc[1] = PLMN_MCC1;
163    ricCfgParams.plmn.mcc[2] = PLMN_MCC2;
164    ricCfgParams.plmn.mnc[0] = PLMN_MNC0;
165    ricCfgParams.plmn.mnc[1] = PLMN_MNC1;
166    ricCfgParams.plmn.mnc[2] = PLMN_MNC2;
167   
168 } /* End of readCuCfg */
169 /**********************************************************************
170          End of file
171 **********************************************************************/