VES PM data for slicing use case. [Issue-Id: ODUHIGH-384]
[o-du/l2.git] / src / o1 / NetconfConfigFile.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 /* This class defines functions to read Netconf Config file */
19
20 #include "NetconfConfigFile.hpp"
21 #include "JsonHelper.hpp"
22 #include "GlobalDefs.hpp"
23
24
25 // Constructor
26 NetconfConfigFile::NetconfConfigFile(string filepath)
27     :ConfigFile(filepath) 
28 {
29 }
30 // Default Destructor
31 NetconfConfigFile::~NetconfConfigFile()
32 {
33 }
34
35 //Getters
36 string NetconfConfigFile::getNetconfMacAddr() const
37 {
38     return mNetconfMacAddr;
39 }
40 string NetconfConfigFile::getNetconfIpv4() const
41 {
42     return mNetconfIpv4;
43 }
44 string NetconfConfigFile::getNetconfIpv6() const
45 {
46     return mNetconfIpv6;
47 }
48 string NetconfConfigFile::getNetconfPort() const
49 {
50     return mNetconfPort;
51 }
52 string NetconfConfigFile::getNetconfUsername() const
53 {
54     return mNetconfUsername;
55 }
56 string NetconfConfigFile::getNetconfPassword() const
57 {
58     return mNetconfPassword;
59 }
60
61 /*******************************************************************
62 *
63 * @brief load Netconf config file
64 *
65 * @details
66 *
67 * Function : loadConfigFile
68 *
69 * Functionality:
70 * - read Netconf Config file and store its contents
71 *
72 * @params[in] IN - NULL
73 * @return true - success
74 *         false - failure
75 *
76 * ****************************************************************/
77
78 bool NetconfConfigFile::loadConfigFile()
79 {
80    cJSON *json = JsonHelper::read(mFilepath.c_str());
81    if(json == NULL) {
82        O1_LOG("\nO1 PnfRegistrationEvent : Config file reading error is  :%s", JsonHelper::getError());
83     return false;
84     }
85     else {
86        cJSON *rootNode = NULL;
87        rootNode = JsonHelper::getNode(json, "NetconfServer");
88        if(rootNode) {
89           O1_LOG("\nO1 PnfRegistrationEvent : Reading NetconfServer config file");
90           mNetconfMacAddr = JsonHelper::getValue(rootNode, "MacAddress");
91           mNetconfIpv4 = JsonHelper::getValue(rootNode, "NetconfServerIpv4");
92           mNetconfIpv6 = JsonHelper::getValue(rootNode, "NetconfServerIpv6");
93           mNetconfPort = JsonHelper::getValue(rootNode, "NetconfPort");
94           mNetconfUsername = JsonHelper::getValue(rootNode, "NetconfUsername");
95           mNetconfPassword = JsonHelper::getValue(rootNode, "NetconfPassword");
96       }
97       else {
98          O1_LOG("\nO1 PnfRegistrationEvent : smoConfig Object is not available in config file");
99          return false;
100       }
101    }
102    JsonHelper::deleteNode(json);
103    return true;
104 }
105
106 /**********************************************************************
107   End of file
108  **********************************************************************/