O1 IP PORT configuration for CM .[Issue-Id: ODUHIGH-196]
[o-du/l2.git] / src / o1 / SessionHandler.cpp
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2020] [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 methods of Session/Connection creation and Subscription to
20    YANG modules */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include "sysrepo.h"
25 #include "SessionHandler.hpp"
26 #include "InitConfig.hpp"
27 #include <iostream>
28
29 using namespace std;
30 /* Default constructor */
31 SessionHandler::SessionHandler()
32 {    
33 }
34
35
36 /* Destructor */
37 SessionHandler::~SessionHandler()
38 {  
39 }
40
41 /********************************************************************** 
42    Description : This function will create Connection, Session, and 
43                  subscribe. These sysrepo class provide netconf connection
44                  related services.
45    Params[In]  : void
46    Return      : true  - started successful
47                  false - start failed
48 **********************************************************************/
49 bool SessionHandler::init()
50 {
51    try
52    {
53       O1_LOG("\nO1 SessionHandler : Initialization done");
54       mConn = createConnection();
55       O1_LOG("\nO1 SessionHandler : Initialization done");
56       mSess = createSession(mConn);
57       mSub  = createSubscribe(mSess);
58       O1_LOG("\nO1 SessionHandler : Initialization done");
59       //InitConfig initConf;
60       InitConfig::instance().init(mSess);
61       return true;
62    }
63    catch( const std::exception& e )
64    {
65       O1_LOG("\nO1 SessionHandler : Exception : %s", e.what());
66       return false;
67    }
68 }
69
70 /********************************************************************** 
71    Description : This function will create Connection instance and 
72                  return the same  
73    Params[In]  : void
74    Return      : sysrepo::S_Connection instance
75 **********************************************************************/
76 sysrepo::S_Connection SessionHandler::createConnection()
77 {
78    sysrepo::S_Connection conn(new sysrepo::Connection());
79    return conn;
80 }
81
82
83 /********************************************************************** 
84    Description : This function will create Session instance and
85                  return the same
86    Params[In]  : sysrepo::S_Connection
87    Return      : sysrepo::S_Session instance
88 **********************************************************************/
89 sysrepo::S_Session SessionHandler::createSession(sysrepo::S_Connection conn)
90 {
91    sysrepo::S_Session sess(new sysrepo::Session(conn));
92    return sess;
93 }
94
95
96
97 /**********************************************************************
98    Description : This function will create Subscribe instance and
99                  return the same
100    Params[In]  : sysrepo::S_Session
101    Return      : sysrepo::S_Subscribe instance
102 **********************************************************************/
103 sysrepo::S_Subscribe SessionHandler::createSubscribe(sysrepo::S_Session sess)
104 {
105    sysrepo::S_Subscribe subscrb(new sysrepo::Subscribe(sess));
106    if(subscribeModule(subscrb))
107    {
108       O1_LOG("\nO1 SessionHandler : Subscription done successfully");
109    }
110    return subscrb;
111 }
112
113
114 /********************************************************************** 
115    Description : This function will create a callback object and register
116                  it for callback. 
117    Params[In]  : sysrepo::S_Subscribe
118    Return      : true   - on success
119 **********************************************************************/
120 bool SessionHandler::subscribeModule(sysrepo::S_Subscribe subscrb)
121 {
122    sysrepo::S_Callback alarmOranCb(new AlarmOranYangModel());
123
124    subscrb->oper_get_items_subscribe(ALARM_MODULE_NAME_ORAN, \
125                                      ALARM_MODULE_PATH_ORAN, \
126                                      alarmOranCb);
127    return true;
128 }
129
130 /**********************************************************************
131          End of file
132 **********************************************************************/