0a283ae51393d0f006a7c85ab2a8f5713a6c501b
[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
29 StartupConfig g_cfg;
30
31 /*******************************************************************
32  *
33  * @brief Get the startup config from Netconf
34  *
35  * @details
36  *
37  *    Function : getStartupConfig
38  *
39  *    Functionality:
40  *      - Get the start up IP and port for DU
41  *
42  * @params[in] pointer to StartupConfig
43  * @return O1::SUCCESS - success
44  *         O1::FAILURE - failure
45  ******************************************************************/
46 uint8_t getStartupConfig(StartupConfig *cfg)
47 {
48    if ( InitConfig::instance().getCurrInterfaceConfig(*cfg) )
49    {
50       O1_LOG("\nO1 StartupConfig : "
51              "cfg.DU_IPV4_Addr [%s]",
52               cfg->DU_IPV4_Addr);
53       O1_LOG("\nO1 StartupConfig : "
54              "cfg.DU_Port [%d]", 
55               cfg->DU_Port);
56       O1_LOG("\nO1 StartupConfig : "
57              "cfg.CU_IPV4_Addr [%s]", 
58               cfg->CU_IPV4_Addr);
59       O1_LOG("\nO1 StartupConfig : "
60              "cfg.CU_Port [%d]", 
61               cfg->CU_Port);
62       O1_LOG("\nO1 StartupConfig : "
63              "cfg.RIC_IPV4_Addr [%s]", 
64               cfg->RIC_IPV4_Addr);
65       O1_LOG("\nO1 StartupConfig : "
66              "cfg.RIC_Port [%d]", 
67               cfg->RIC_Port);
68       return O1::SUCCESS;
69    }
70    return O1::FAILURE;
71 }
72
73 /*******************************************************************
74  *
75  * @brief Get the startup config from Netconf
76  *
77  * @details
78  *
79  *    Function : getStartupConfig
80  *
81  *    Functionality:
82  *      - Get the start up IP and port for CU and RIC
83  *
84  * @params[in] pointer to StartupConfig
85  * @return O1::SUCCESS - success
86  *         O1::FAILURE - failure
87  ******************************************************************/
88 uint8_t getStartupConfigForStub(StartupConfig *cfg)
89 {
90 #if 0
91    UnixSocketClient uxClient(O1::ALARM_SOCK_PATH);
92    O1_LOG("\nO1 CONFIG : getStartupConfig ------ \n");
93    MsgHeader msg;
94    msg.msgType = CONFIGURATION;
95    msg.action = GET_STARTUP_CONFIG;
96    if (uxClient.openSocket() == O1::FAILURE)
97    {
98       return O1::FAILURE;
99    }
100    if (uxClient.sendData(&msg,sizeof(msg)) < 0 )
101    {
102       uxClient.closeSocket();
103       return O1::FAILURE;
104    }
105    if (uxClient.receiveData(cfg, sizeof(StartupConfig)) < 0)
106    {
107       uxClient.closeSocket();
108       return O1::FAILURE;
109    }
110    O1_LOG("\nO1 CONFIG : ip du %s\n",cfg->DU_IPV4_Addr );
111    O1_LOG("\nO1 CONFIG : ip cu %s\n",cfg->CU_IPV4_Addr );
112    O1_LOG("\nO1 CONFIG : ip ric %s\n",cfg->RIC_IPV4_Addr );
113    O1_LOG("\nO1 CONFIG : port cu %hu\n",cfg->CU_Port);
114    O1_LOG("\nO1 CONFIG : port du %hu\n",cfg->DU_Port);
115    O1_LOG("\nO1 CONFIG : port ric %hu\n",cfg->RIC_Port);
116
117    uxClient.closeSocket();
118 #endif
119    SessionHandler sessHdlr;
120    if ( sessHdlr.init() )
121    {
122       if ( InitConfig::instance().getCurrInterfaceConfig(*cfg) )
123       {
124          O1_LOG("\nO1 StartupConfig : "
125                 "cfg.DU_IPV4_Addr [%s]",
126                  cfg->DU_IPV4_Addr);
127          O1_LOG("\nO1 StartupConfig : "
128                 "cfg.DU_Port [%d]", 
129                  cfg->DU_Port);
130          O1_LOG("\nO1 StartupConfig : "
131                 "cfg.CU_IPV4_Addr [%s]", 
132                  cfg->CU_IPV4_Addr);
133          O1_LOG("\nO1 StartupConfig : "
134                 "cfg.CU_Port [%d]", 
135                  cfg->CU_Port);
136          O1_LOG("\nO1 StartupConfig : "
137                 "cfg.RIC_IPV4_Addr [%s]", 
138                  cfg->RIC_IPV4_Addr);
139          O1_LOG("\nO1 StartupConfig : "
140                 "cfg.RIC_Port [%d]", 
141                  cfg->RIC_Port);
142         return O1::SUCCESS;
143       }
144    }
145    return O1::FAILURE;
146 }
147
148
149 /**********************************************************************
150          End of file
151 **********************************************************************/