Edit-conf changes for CLA use case.
[o-du/l2.git] / src / o1 / ConfigInterface.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 "ConfigInterface.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 #if 0
92    UnixSocketClient uxClient(O1::ALARM_SOCK_PATH);
93    O1_LOG("\nO1 CONFIG : getStartupConfig ------ \n");
94    MsgHeader msg;
95    msg.msgType = CONFIGURATION;
96    msg.action = GET_STARTUP_CONFIG;
97    if (uxClient.openSocket() == O1::FAILURE)
98    {
99       return O1::FAILURE;
100    }
101    if (uxClient.sendData(&msg,sizeof(msg)) < 0 )
102    {
103       uxClient.closeSocket();
104       return O1::FAILURE;
105    }
106    if (uxClient.receiveData(cfg, sizeof(StartupConfig)) < 0)
107    {
108       uxClient.closeSocket();
109       return O1::FAILURE;
110    }
111    O1_LOG("\nO1 CONFIG : ip du %s\n",cfg->DU_IPV4_Addr );
112    O1_LOG("\nO1 CONFIG : ip cu %s\n",cfg->CU_IPV4_Addr );
113    O1_LOG("\nO1 CONFIG : ip ric %s\n",cfg->RIC_IPV4_Addr );
114    O1_LOG("\nO1 CONFIG : port cu %hu\n",cfg->CU_Port);
115    O1_LOG("\nO1 CONFIG : port du %hu\n",cfg->DU_Port);
116    O1_LOG("\nO1 CONFIG : port ric %hu\n",cfg->RIC_Port);
117
118    uxClient.closeSocket();
119 #endif
120    SessionHandler sessHdlr;
121    if ( sessHdlr.init() )
122    {
123       if ( InitConfig::instance().getCurrInterfaceConfig(*cfg) )
124       {
125          O1_LOG("\nO1 StartupConfig : "
126                 "cfg.DU_IPV4_Addr [%s]",
127                  cfg->DU_IPV4_Addr);
128          O1_LOG("\nO1 StartupConfig : "
129                 "cfg.DU_Port [%d]", 
130                  cfg->DU_Port);
131          O1_LOG("\nO1 StartupConfig : "
132                 "cfg.CU_IPV4_Addr [%s]", 
133                  cfg->CU_IPV4_Addr);
134          O1_LOG("\nO1 StartupConfig : "
135                 "cfg.CU_Port [%d]", 
136                  cfg->CU_Port);
137          O1_LOG("\nO1 StartupConfig : "
138                 "cfg.RIC_IPV4_Addr [%s]", 
139                  cfg->RIC_IPV4_Addr);
140          O1_LOG("\nO1 StartupConfig : "
141                 "cfg.RIC_Port [%d]", 
142                  cfg->RIC_Port);
143         return O1::SUCCESS;
144       }
145    }
146    return O1::FAILURE;
147 }
148
149 /*******************************************************************
150  *
151  * @brief update cell and operational state
152  *
153  * @details
154  *
155  *    Function : setCellOpState
156  *
157  *    Functionality:
158  *      - send update of cell and operational state to it's handler
159  *
160  *
161  * @params[in] cellId, opState, cellState
162  * @return cell operational in string form
163  ******************************************************************/
164
165
166 bool setCellOpState(uint16_t cellId, OpState opState, CellState cellState)
167 {
168    O1_LOG("\nO1  ConfigInterface: Setting cellId = %d, opState=%d, \
169 cellState=%d\n", cellId, opState, cellState);
170    return NrCellList::instance().setCellOpState(cellId, opState, \
171                                                       cellState);
172 }
173
174 /**********************************************************************
175          End of file
176 **********************************************************************/