Merge "VES PM data for slicing use case. [Issue-Id: ODUHIGH-384]"
[o-du/l2.git] / src / o1 / CmInterface.cpp
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2020-2021] [HCL Technologies Ltd.]                          #
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 file contains C interface for ODU and stubs to get startup
20    configuration
21 */
22
23 #include "CmInterface.h"
24 #include "GlobalDefs.hpp"
25 #include "UnixSocketClient.hpp"
26 #include "SessionHandler.hpp"
27 #include "InitConfig.hpp"
28 #include "NrCellList.hpp"
29
30 StartupConfig g_cfg;
31
32 /*******************************************************************
33  *
34  * @brief Get the startup config from Netconf
35  *
36  * @details
37  *
38  *    Function : getStartupConfig
39  *
40  *    Functionality:
41  *      - Get the start up IP and port for DU
42  *
43  * @params[in] pointer to StartupConfig
44  * @return O1::SUCCESS - success
45  *         O1::FAILURE - failure
46  ******************************************************************/
47 uint8_t getStartupConfig(StartupConfig *cfg)
48 {
49    if ( InitConfig::instance().getCurrInterfaceConfig(*cfg) )
50    {
51       O1_LOG("\nO1 StartupConfig : "
52              "cfg.DU_IPV4_Addr [%s]",
53               cfg->DU_IPV4_Addr);
54       O1_LOG("\nO1 StartupConfig : "
55              "cfg.DU_Port [%d]", 
56               cfg->DU_Port);
57       O1_LOG("\nO1 StartupConfig : "
58              "cfg.CU_IPV4_Addr [%s]", 
59               cfg->CU_IPV4_Addr);
60       O1_LOG("\nO1 StartupConfig : "
61              "cfg.CU_Port [%d]", 
62               cfg->CU_Port);
63       O1_LOG("\nO1 StartupConfig : "
64              "cfg.RIC_IPV4_Addr [%s]", 
65               cfg->RIC_IPV4_Addr);
66       O1_LOG("\nO1 StartupConfig : "
67              "cfg.RIC_Port [%d]", 
68               cfg->RIC_Port);
69       return O1::SUCCESS;
70    }
71    return O1::FAILURE;
72 }
73
74 /*******************************************************************
75  *
76  * @brief Get the startup config from Netconf
77  *
78  * @details
79  *
80  *    Function : getStartupConfig
81  *
82  *    Functionality:
83  *      - Get the start up IP and port for CU and RIC
84  *
85  * @params[in] pointer to StartupConfig
86  * @return O1::SUCCESS - success
87  *         O1::FAILURE - failure
88  ******************************************************************/
89 uint8_t getStartupConfigForStub(StartupConfig *cfg)
90 {
91    SessionHandler sessHdlr;
92    if ( sessHdlr.init() )
93    {
94       if ( InitConfig::instance().getCurrInterfaceConfig(*cfg) )
95       {
96          O1_LOG("\nO1 StartupConfig : "
97                 "cfg.DU_IPV4_Addr [%s]",
98                  cfg->DU_IPV4_Addr);
99          O1_LOG("\nO1 StartupConfig : "
100                 "cfg.DU_Port [%d]", 
101                  cfg->DU_Port);
102          O1_LOG("\nO1 StartupConfig : "
103                 "cfg.CU_IPV4_Addr [%s]", 
104                  cfg->CU_IPV4_Addr);
105          O1_LOG("\nO1 StartupConfig : "
106                 "cfg.CU_Port [%d]", 
107                  cfg->CU_Port);
108          O1_LOG("\nO1 StartupConfig : "
109                 "cfg.RIC_IPV4_Addr [%s]", 
110                  cfg->RIC_IPV4_Addr);
111          O1_LOG("\nO1 StartupConfig : "
112                 "cfg.RIC_Port [%d]", 
113                  cfg->RIC_Port);
114         return O1::SUCCESS;
115       }
116    }
117    return O1::FAILURE;
118 }
119
120 /*******************************************************************
121  *
122  * @brief update cell and operational state
123  *
124  * @details
125  *
126  *    Function : setCellOpState
127  *
128  *    Functionality:
129  *      - send update of cell and operational state to it's handler
130  *
131  *
132  * @params[in] cellId, opState, cellState
133  * @return cell operational in string form
134  ******************************************************************/
135
136
137 bool setCellOpState(uint16_t cellId, OpState opState, CellState cellState)
138 {
139    O1_LOG("\nO1  CmInterface: Setting cellId = %d, opState=%d, \
140 cellState=%d", cellId, opState, cellState);
141    return NrCellList::instance().setCellOpState(cellId, opState, \
142                                                       cellState);
143 }
144
145 /**********************************************************************
146          End of file
147 **********************************************************************/