O1 main, Netconf and sysrepo handlers.[Issue-Id: ODUHIGH-245] 24/4924/5
authorHariomGupta <hariom.g@hcl.com>
Tue, 27 Oct 2020 09:12:49 +0000 (14:42 +0530)
committerHariomGupta <hariom.g@hcl.com>
Fri, 13 Nov 2020 14:33:16 +0000 (20:03 +0530)
Signed-off-by: HariomGupta <hariom.g@hcl.com>
Change-Id: Ifec3ff04160bd0ec796d30472dcf1bb2eb0520a1

13 files changed:
build/common/du_app.mak
build/o1/yang/o-ran-sc-odu-alarm-v1.yang [new file with mode: 0644]
docs/README
src/du_app/du_msg_hdl.c
src/o1/Alarm3GPPYangModel.cpp [new file with mode: 0644]
src/o1/Alarm3GPPYangModel.hpp [new file with mode: 0644]
src/o1/AlarmOranYangModel.cpp [new file with mode: 0644]
src/o1/AlarmOranYangModel.hpp [new file with mode: 0644]
src/o1/NetconfManager.cpp [new file with mode: 0644]
src/o1/NetconfManager.hpp [new file with mode: 0644]
src/o1/O1_main.cpp [new file with mode: 0644]
src/o1/SessionHandler.cpp [new file with mode: 0644]
src/o1/SessionHandler.hpp [new file with mode: 0644]

index 43151c0..2cc8dc5 100644 (file)
@@ -43,6 +43,7 @@ I_OPTS+=-I$(ROOT_DIR)/src/codec_utils/common
 I_OPTS+=-I$(ROOT_DIR)/src/codec_utils/F1AP
 I_OPTS+=-I$(ROOT_DIR)/src/codec_utils/RRC
 I_OPTS+=-I$(ROOT_DIR)/src/codec_utils/E2AP
+I_OPTS+=-I$(ROOT_DIR)/src/o1/o1_client
 
 #-------------------------------------------------------------#
 #Linker macros
diff --git a/build/o1/yang/o-ran-sc-odu-alarm-v1.yang b/build/o1/yang/o-ran-sc-odu-alarm-v1.yang
new file mode 100644 (file)
index 0000000..10a7225
--- /dev/null
@@ -0,0 +1,89 @@
+module o-ran-sc-odu-alarm-v1 {
+  yang-version 1;
+  namespace "urn:o-ran:odu:alarm:1.0";
+  prefix rxad;
+
+  organization
+    "O-RAN Software Community";
+  contact
+    "www.o-ran.org";
+  description
+    "This module defines active alarm information visible to operators
+
+     Copyright 2020 the O-RAN Alliance.
+
+     Licensed under the Apache License, Version 2.0 (the 'License');
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an 'AS IS' BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.";
+
+  revision 2020-01-29 {
+    description
+      "initial revision";
+    reference
+      "O-RAN-OAM-Interface-Specification (O1)";
+  }
+
+  grouping alarm-info {
+    leaf alarm-id {
+      type string;
+      description
+        "The unique alarm ID";
+    }
+    leaf resource {
+      type string;
+      description
+        "The alarm  'resource' which is
+         basically the xpath to the entity
+         which raises the alarm and the
+         alarm-type-qualifier, which can be
+         in our case a static string for all
+         the alarms, e.g. 'O-RAN-SC:O-DU'.";
+    }
+    leaf alarm-text {
+      type string;
+      description
+        "The detailed text of the alarm";
+    }
+    leaf severity {
+      type string;
+      description
+        "The severity of the alarm";
+    }
+    leaf status {
+      type string;
+      description
+        "The status of the alarm";
+    }
+    leaf additional-info {
+      type string;
+      description
+        "Additional info about the alarm";
+    }
+    description
+      "Alarm information";
+  }
+
+  container odu {
+    container alarms {
+      config false;
+      list alarm {
+        key "alarm-id";
+        uses alarm-info;
+        description
+          "The list of active alarms in RIC";
+      }
+      description
+        "State data container of the alarms";
+    }
+    description
+      "Root object for RIC alarms";
+  }
+}
index 61147fb..21f7b31 100644 (file)
@@ -4,18 +4,20 @@ Directory Structure :
    a. common : contains individual module's makefile
    b. config : contains SSI memory configuration
    c. odu    : contains main makefile to generate an executable binary
+   d. o1     : contains main makefile to generate an executable binary
 
 2. l2/docs/  : contains README and other configuration files for building docs
        
-2. l2/src/ : contains layer specific source code
+3. l2/src/ : contains layer specific source code
    a. 5gnrmac  : MAC source code
-   b.  5gnrrlc  : RLC source code
+   b. 5gnrrlc  : RLC source code
    c. cm       : common, environment and interface files
    d. cu_stub  : Stub code for CU
    e. du_app   : DU application and F1 code 
    f. mt       : wrapper functions over OS
    g. phy_stub : Stub code for Physical layer
    h. rlog     : logging module
+   i. o1       : o1 module
 
 
 Pre-requisite for Compilation :
@@ -24,6 +26,29 @@ Pre-requisite for Compilation :
 2. GCC version 4.6.3 and above
 
 
+Pre-requisite for running O1 module
+-----------------------------------
+Install netconf server
+----------------------
+
+1.     Create new netconf user (login with root user and run following command)
+       $adduser --system netconf && \
+        echo "netconf:netconf" | chpasswd
+
+       $mkdir -p /home/netconf/.ssh && \
+       ssh-keygen -A && \
+       ssh-keygen -t dsa -P '' -f /home/netconf/.ssh/id_dsa && \
+        cat /home/netconf/.ssh/id_dsa.pub > /home/netconf/.ssh/authorized_keys
+2.     Install netconf packages. 
+       $cd l2/build/o1/
+       $chmod +x install_lib.sh
+       $ ./install_lib.sh
+3.     Enabling O1 module in ODU:
+        set the O1_ENABLE flag to 1 in following file
+        /src/o1/o1_client/GlobalDefs.h
+
+
+
 How to Clean and Build:
 -----------------------
 1. Building ODU binary:
@@ -42,7 +67,7 @@ How to Clean and Build:
    c. Cleaning CU Stub binary
          make clean_cu NODE=TEST_STUB MACHINE=BIT64 MODE=FDD
 
-2. Building RIC Stub binary:
+3. Building RIC Stub binary:
    a. Build folder
          cd l2/build/odu
    b. Building RIC Stub binary
@@ -53,6 +78,15 @@ How to Clean and Build:
 4. Cleaning ODU and CU Stub
       make clean_all MACHINE=BIT64 MODE=FDD
 
+5. Building O1 binary:
+   a. Build folder
+         cd l2/build/o1
+   b. Building O1 binary
+         make o1 MACHINE=BIT64
+   c. Cleaning O1 binary
+         make clean_o1 MACHINE=BIT64
+
+
 How to execute:
 ---------------
 1. Assign virtual IP addresses as follows:
@@ -72,10 +106,17 @@ How to execute:
 5. Run RIC Stub binary:
       ./ric_stub
 
-4. DU execution folder:
+6. DU execution folder:
       cd l2/bin/odu
      
-5. Run ODU binary:
+7. Run ODU binary:
       ./odu
 
-PS: CU stub and RIC stub must be run (in no particular sequence) before ODU
+8. O1 execution folder:
+      cd l2/build/o1/bin/o1
+
+9. Run O1 binary:
+      ./o1
+
+PS  CU stub and RIC stub must be run (in no particular sequence) before ODU
+    If O1 module is enabled it must be run before ODU
index 6dcb15a..a17b89a 100644 (file)
 #include "lphy_stub.h"
 #include "du_utils.h"
 
+#include "GlobalDefs.h"
+#ifdef O1_ENABLE
+
+#include "AlarmInterface.h"
+
+#endif 
+
 U8 rlcDlCfg = 0;
 U8 numRlcDlSaps = 0;
 U8 rlcUlCfg = 0;
@@ -1651,6 +1658,11 @@ uint8_t duHandleSlotInd(Pst *pst, SlotIndInfo *slotInfo)
       {
         DU_LOG("\nDU APP : 5G-NR Cell %d is UP", slotInfo->cellId);
         duCb.actvCellLst[slotInfo->cellId-1]->cellStatus = ACTIVATED;
+
+#ifdef O1_ENABLE
+    DU_LOG("\nDU APP : Raise cell UP alarm for cell id=%d", slotInfo->cellId);
+    raiseCellAlrm(CELL_UP_ALARM_ID, slotInfo->cellId);
+#endif
       }
 
    }
@@ -1784,7 +1796,13 @@ uint8_t duHandleStopInd(Pst *pst, MacCellStopInfo *cellStopId)
         {
            DU_LOG("\nDU APP : 5G-NR Cell %d is DOWN", cellStopId->cellId);
            duCb.actvCellLst[cellStopId->cellId-1]->cellStatus = DELETION_IN_PROGRESS;
-        }
+
+#ifdef O1_ENABLE
+       DU_LOG("\nDU APP : Raise cell down alarm for cell id=%d", cellStopId->cellId);
+       raiseCellAlrm(CELL_DOWN_ALARM_ID, cellStopId->cellId);
+#endif
+       
+    }
       }
    }
    if((pst->selector == ODU_SELECTOR_LWLC) || (pst->selector == ODU_SELECTOR_TC))
diff --git a/src/o1/Alarm3GPPYangModel.cpp b/src/o1/Alarm3GPPYangModel.cpp
new file mode 100644 (file)
index 0000000..42915a5
--- /dev/null
@@ -0,0 +1,84 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020] [HCL Technologies Ltd.]                               #
+#                                                                              #
+#   Licensed under the Apache License, Version 2.0 (the "License");            #
+#   you may not use this file except in compliance with the License.           #
+#   You may obtain a copy of the License at                                    #
+#                                                                              #
+#       http://www.apache.org/licenses/LICENSE-2.0                             #
+#                                                                              #
+#   Unless required by applicable law or agreed to in writing, software        #
+#   distributed under the License is distributed on an "AS IS" BASIS,          #
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
+#   See the License for the specific language governing permissions and        #
+#   limitations under the License.                                             #
+################################################################################
+*******************************************************************************/
+
+/* This file contains Alarm Yang model data filling and sending related methods */
+
+#include "Alarm3GPPYangModel.hpp"
+
+using namespace std;
+
+
+/********************************************************************** 
+   Description : It is a callback function, called on get request of
+                 alarm-list (overridden function of sysrepo::Callback )
+   Params[In]  : (sysrepo::S_Session, module_name, path,
+                 request_xpath, request_id, &parent, private_data)
+   Return      : SR_ERR_OK - success
+**********************************************************************/
+
+int Alarm3GPPYangModel::oper_get_items(sysrepo::S_Session session,
+                                       const char         *module_name,
+                                       const char         *path,
+                                       const char         *request_xpath,
+                                       uint32_t           request_id,
+                                       libyang::S_Data_Node &parent,
+                                       void *private_data) 
+{
+    O1_LOG("\n\n ========== CALLBACK CALLED TO PROVIDE \" %s DATA ==========\n", path); 
+
+    libyang::S_Context ctx = session->get_context();
+    libyang::S_Module mod = ctx->get_module(module_name);
+
+    parent.reset(new libyang::Data_Node(ctx, ALARM_MODULE_PATH_3GPP, nullptr, LYD_ANYDATA_CONSTSTRING, 0));
+    //read the data from map
+    //tree of alarmRecord  : AlarmList/AlarmListGrp/alarmRecordList/AlarmRecordGrp
+
+    libyang::S_Data_Node alarms(new libyang::Data_Node(parent, mod, "AlarmList"));
+    libyang::S_Data_Node alarm(new libyang::Data_Node(alarms, mod, "AlarmListGrp"));
+    libyang::S_Data_Node ifc3(new libyang::Data_Node(parent, mod, "alarmRecordList"));
+    libyang::S_Data_Node ifc4(new libyang::Data_Node(ifc3, mod, "AlarmRecordGrp"));
+    
+
+    libyang::S_Data_Node id;
+    libyang::S_Data_Node text;
+    libyang::S_Data_Node severity;
+    libyang::S_Data_Node status;
+    libyang::S_Data_Node add_info;
+
+    //read the data from map
+    map<uint16_t,Alarm>::const_iterator it;
+
+    AlarmManager& alrmMgr = AlarmManager::instance();
+    const map<uint16_t,Alarm>& alrmList = alrmMgr.getAlarmList();
+
+    for(it = alrmList.begin(); it !=alrmList.end(); it++)
+    {
+        O1_LOG("\nAlarm ID %hu", it->second.getAlarmId());
+        alarm.reset(new libyang::Data_Node(alarms, mod, "alarm"));
+        id.reset(new libyang::Data_Node(alarm, mod, "alarm-id", to_string(it->second.getAlarmId()).c_str()));
+        text.reset(new libyang::Data_Node(alarm, mod, "alarm-text", it->second.getAdditionalText().c_str()));
+        severity.reset(new libyang::Data_Node(alarm, mod, "severity", to_string(it->second.getEventType()).c_str()));
+        status.reset(new libyang::Data_Node(alarm, mod, "status", it->second.getSpecificProblem().c_str()));
+        add_info.reset(new libyang::Data_Node(alarm, mod, "additional-info", it->second.getAdditionalInfo().c_str()));
+    }
+    return SR_ERR_OK;
+}
+
+/**********************************************************************
+         End of file
+**********************************************************************/
diff --git a/src/o1/Alarm3GPPYangModel.hpp b/src/o1/Alarm3GPPYangModel.hpp
new file mode 100644 (file)
index 0000000..01c2363
--- /dev/null
@@ -0,0 +1,48 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020] [HCL Technologies Ltd.]                               #
+#                                                                              #
+#   Licensed under the Apache License, Version 2.0 (the "License");            #
+#   you may not use this file except in compliance with the License.           #
+#   You may obtain a copy of the License at                                    #
+#                                                                              #
+#       http://www.apache.org/licenses/LICENSE-2.0                             #
+#                                                                              #
+#   Unless required by applicable law or agreed to in writing, software        #
+#   distributed under the License is distributed on an "AS IS" BASIS,          #
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
+#   See the License for the specific language governing permissions and        #
+#   limitations under the License.                                             #
+################################################################################
+*******************************************************************************/
+
+/* This file contains Alarm Yang model data filling and sending related methods */
+
+#ifndef __ALARM_3GPP_YANG_MODEL_HPP__
+#define __ALARM_3GPP_YANG_MODEL_HPP__
+
+/*#include <string.h>
+#include <stdlib.h>
+#include "sysrepo-cpp/Session.hpp"
+#include "AlarmManager.hpp"
+#include "GlobalDefs.hpp"
+*/
+
+#include "AlarmOranYangModel.hpp"
+
+class Alarm3GPPYangModel:public sysrepo::Callback {
+   public:
+      int oper_get_items(sysrepo::S_Session session,\
+                         const char *module_name,\
+                         const char *path,\
+                         const char *request_xpath,\
+                         uint32_t request_id,\
+                         libyang::S_Data_Node &parent,\
+                         void *private_data) override;
+};
+
+#endif
+
+/**********************************************************************
+         End of file
+**********************************************************************/
diff --git a/src/o1/AlarmOranYangModel.cpp b/src/o1/AlarmOranYangModel.cpp
new file mode 100644 (file)
index 0000000..fba9f57
--- /dev/null
@@ -0,0 +1,81 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020] [HCL Technologies Ltd.]                               #
+#                                                                              #
+#   Licensed under the Apache License, Version 2.0 (the "License");            #
+#   you may not use this file except in compliance with the License.           #
+#   You may obtain a copy of the License at                                    #
+#                                                                              #
+#       http://www.apache.org/licenses/LICENSE-2.0                             #
+#                                                                              #
+#   Unless required by applicable law or agreed to in writing, software        #
+#   distributed under the License is distributed on an "AS IS" BASIS,          #
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
+#   See the License for the specific language governing permissions and        #
+#   limitations under the License.                                             #
+################################################################################
+*******************************************************************************/
+
+/* This file contains Alarm Yang model data filling and sending related methods */
+
+#include "AlarmOranYangModel.hpp"
+
+using namespace std;
+
+/********************************************************************** 
+   Description : It is a callback function, called on get request of
+                 alarm-list (overridden function of sysrepo::Callback )
+   Params[In]  : (sysrepo::S_Session, module_name, path, 
+                 request_xpath, request_id, &parent, private_data)
+   Return      : SR_ERR_OK - success
+**********************************************************************/
+
+int AlarmOranYangModel::oper_get_items(sysrepo::S_Session session, \
+                                       const char *module_name, \
+                                       const char *path, \
+                                       const char *request_xpath, \
+                                       uint32_t request_id, \
+                                       libyang::S_Data_Node &parent, \
+                                       void *private_data)
+{
+    O1_LOG("\n\n ========== CALLBACK CALLED TO PROVIDE \" %s DATA ==========\n", path); 
+    libyang::S_Context ctx = session->get_context();
+    libyang::S_Module mod = ctx->get_module(module_name);
+
+    //first create root of the tree then add nodes and leaves and fill data
+    parent.reset(new libyang::Data_Node(ctx, ALARM_MODULE_PATH_ORAN, nullptr, LYD_ANYDATA_CONSTSTRING, 0));
+    libyang::S_Data_Node alarms(new libyang::Data_Node(parent, mod, "alarms"));
+    
+    libyang::S_Data_Node alarm;
+    libyang::S_Data_Node id;
+    libyang::S_Data_Node text;
+    libyang::S_Data_Node severity;
+    libyang::S_Data_Node status;
+    libyang::S_Data_Node add_info;
+
+    //read the data from map
+    map<uint16_t,Alarm>::const_iterator it;
+
+    AlarmManager& alrmMgr = AlarmManager::instance();
+    const map<uint16_t,Alarm>& alrmList = alrmMgr.getAlarmList();
+    char alarmId[MAX_ALARM_ID_LEN];
+
+    for(it = alrmList.begin(); it !=alrmList.end(); it++)
+    {
+        strcpy(alarmId, to_string(it->second.getAlarmId()).c_str());
+        O1_LOG("\nAlarm ID %s",alarmId);
+        alarm.reset(new libyang::Data_Node(alarms, mod, "alarm"));
+        id.reset(new libyang::Data_Node(alarm, mod, "alarm-id", alarmId));
+        text.reset(new libyang::Data_Node(alarm, mod, "alarm-text", it->second.getAdditionalText().c_str()));
+        severity.reset(new libyang::Data_Node(alarm, mod, "severity", to_string(it->second.getEventType()).c_str()));
+        status.reset(new libyang::Data_Node(alarm, mod, "status", it->second.getSpecificProblem().c_str()));
+        add_info.reset(new libyang::Data_Node(alarm, mod, "additional-info", it->second.getAdditionalInfo().c_str()));
+    }
+
+    return SR_ERR_OK;
+}
+
+
+/**********************************************************************
+         End of file
+**********************************************************************/
diff --git a/src/o1/AlarmOranYangModel.hpp b/src/o1/AlarmOranYangModel.hpp
new file mode 100644 (file)
index 0000000..d8495af
--- /dev/null
@@ -0,0 +1,46 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020] [HCL Technologies Ltd.]                               #
+#                                                                              #
+#   Licensed under the Apache License, Version 2.0 (the "License");            #
+#   you may not use this file except in compliance with the License.           #
+#   You may obtain a copy of the License at                                    #
+#                                                                              #
+#       http://www.apache.org/licenses/LICENSE-2.0                             #
+#                                                                              #
+#   Unless required by applicable law or agreed to in writing, software        #
+#   distributed under the License is distributed on an "AS IS" BASIS,          #
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
+#   See the License for the specific language governing permissions and        #
+#   limitations under the License.                                             #
+################################################################################
+*******************************************************************************/
+
+/* This file contains Alarm Yang model data filling and sending related methods */
+
+#ifndef __ALARM_ORAN_YANG_MODEL_HPP__
+#define __ALARM_ORAN_YANG_MODEL_HPP__
+#include <string.h>
+#include <stdlib.h>
+#include "sysrepo-cpp/Session.hpp"
+#include "AlarmManager.hpp"
+#include "GlobalDefs.hpp"
+
+
+class AlarmOranYangModel : public sysrepo::Callback {
+   public:
+      int oper_get_items(sysrepo::S_Session session,\
+                         const char *module_name,\
+                         const char *path,\
+                         const char *request_xpath,\
+                         uint32_t request_id,\
+                         libyang::S_Data_Node &parent,\
+                         void *private_data);
+
+};
+
+#endif
+
+/**********************************************************************
+         End of file
+**********************************************************************/
diff --git a/src/o1/NetconfManager.cpp b/src/o1/NetconfManager.cpp
new file mode 100644 (file)
index 0000000..077cdfe
--- /dev/null
@@ -0,0 +1,149 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020] [HCL Technologies Ltd.]                               #
+#                                                                              #
+#   Licensed under the Apache License, Version 2.0 (the "License");            #
+#   you may not use this file except in compliance with the License.           #
+#   You may obtain a copy of the License at                                    #
+#                                                                              #
+#       http://www.apache.org/licenses/LICENSE-2.0                             #
+#                                                                              #
+#   Unless required by applicable law or agreed to in writing, software        #
+#   distributed under the License is distributed on an "AS IS" BASIS,          #
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
+#   See the License for the specific language governing permissions and        #
+#   limitations under the License.                                             #
+################################################################################
+*******************************************************************************/
+
+/* This class is the netconf manager class. It will handle netopeer-server start and stop along with session handler init. Additionally it will provide the
+   signal handling. */
+
+#include "NetconfManager.hpp"
+
+/* Default constructor */
+NetconfManager::NetconfManager()
+{
+}
+
+
+/* Destructor */
+NetconfManager::~NetconfManager()
+{
+   if( NULL != mSessHndl)
+   {
+      delete mSessHndl;
+   }  
+}
+
+/********************************************************************** 
+   Description : This function will start the netopeer2-server and 
+                 redirect logs to the /etc/netopeer2-server.log file
+   Params[In]  : void
+   Return      : true  - started successful
+                 false - start failed
+**********************************************************************/
+
+bool NetconfManager::startNetopeerServer ()
+{
+    int status = system("netopeer2-server -d -v3 > /etc/netopeer2-server.log 2>&1 &");
+    if (status < 0)
+    {
+       O1_LOG("\nO1 NetconfManager : Error during netopeer server start status : %s",\
+               strerror(errno));
+    }
+    else
+    {
+       if (WIFEXITED(status))
+          O1_LOG("\nO1 NetconfManager : netopeer server started normally with status : %d",\
+                  WEXITSTATUS(status));
+       else
+          O1_LOG("\nO1 NetconfManager : netopeer server started abnormally with status : %d",\
+                  WEXITSTATUS(status));
+    }
+    return (status == 0);
+}
+
+
+/********************************************************************** 
+   Description : This function will stop the netopeer2-server 
+   Params[In]  : void
+   Return      : true  - started successful
+                 false - start failed
+**********************************************************************/
+bool NetconfManager::stopNetopeerServer(void)
+{
+   int status = system("kill -9 `pidof netopeer2-server`");
+   if (status < 0)
+   {
+      O1_LOG("\nO1 NetconfManager : Error during Netopeer server stopped status : %s\n",\
+              strerror(errno));
+   }
+   else
+   {
+      if (WIFEXITED(status))
+      {
+         O1_LOG("\nO1 NetconfManager : Netopeer server stopped normally with status : %d\n",\
+                 WEXITSTATUS(status));
+      }
+      else
+      {
+         O1_LOG("\nO1  NetconfManager : Netopeer server stopped abnormally with status : %d\n",\
+                 WEXITSTATUS(status));
+      }
+   }
+   return (status == 0);
+}
+
+
+/********************************************************************** 
+   Description : catch and handle the SIGINT signal 
+   Params[In]  : signum
+   Return      : void 
+**********************************************************************/
+void NetconfManager::sigintHandler(int signum)
+{
+   if (true != NetconfManager::stopNetopeerServer())
+   {
+      O1_LOG("\nO1 NetconfManager : Error stopping Netopeer server");
+   }
+}
+
+
+/********************************************************************** 
+   Description : This function will start the netopeer2-server and 
+                 session handler  
+   Params[In]  : void
+   Return      : true  - started successful
+                 false - start failed
+**********************************************************************/
+bool NetconfManager::init(void)
+{
+   if(startNetopeerServer())
+   {
+      O1_LOG("\nO1 NetconfManager : netopeer server started");
+   }
+   
+   try
+   {
+      mSessHndl = new SessionHandler;
+      
+      O1_LOG("\nO1 NetconfManager : SessionHandler created ");
+
+      if( !mSessHndl->init())
+      {
+         O1_LOG("\nO1 NetconfManager : SessionHandler init failed ");         
+         return false;
+      }
+   }
+   catch( const std::exception& e ) 
+   {
+      O1_LOG("\nO1 O1_main : Exception : %s", e.what());
+      return false;
+   }
+}
+
+
+/**********************************************************************
+         End of file
+**********************************************************************/
diff --git a/src/o1/NetconfManager.hpp b/src/o1/NetconfManager.hpp
new file mode 100644 (file)
index 0000000..213ce8c
--- /dev/null
@@ -0,0 +1,62 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020] [HCL Technologies Ltd.]                               #
+#                                                                              #
+#   Licensed under the Apache License, Version 2.0 (the "License");            #
+#   you may not use this file except in compliance with the License.           #
+#   You may obtain a copy of the License at                                    #
+#                                                                              #
+#       http://www.apache.org/licenses/LICENSE-2.0                             #
+#                                                                              #
+#   Unless required by applicable law or agreed to in writing, software        #
+#   distributed under the License is distributed on an "AS IS" BASIS,          #
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
+#   See the License for the specific language governing permissions and        #
+#   limitations under the License.                                             #
+################################################################################
+*******************************************************************************/
+
+/* This class is the netconf manager class. It creates instance of the 
+   SessionHandler that provides connections/sessions related funtionality
+   and signal handling. 
+*/
+
+#ifndef __NETCONF_MANAGER_HPP__
+#define __NETCONF_MANAGER_HPP__
+
+#include "SessionHandler.hpp"
+#include "Singleton.hpp"
+
+class NetconfManager : public Singleton<NetconfManager>
+{
+
+   friend Singleton<NetconfManager>;
+
+   public:
+      /*initialize variables*/
+      bool init();
+
+      /*handler for netopeer server*/
+      bool startNetopeerServer(void);
+      static bool stopNetopeerServer(void);
+      static void sigintHandler(int signum);
+
+      /*getter setter for  SessionHandler obj*/
+      bool setSessionHandler (SessionHandler  sessMgr);
+      SessionHandler  getSessionHandler(void);
+
+
+   protected:
+      NetconfManager();
+      ~NetconfManager();
+
+   private:
+      SessionHandler *mSessHndl;
+};
+
+
+#endif
+
+/**********************************************************************
+         End of file
+**********************************************************************/
diff --git a/src/o1/O1_main.cpp b/src/o1/O1_main.cpp
new file mode 100644 (file)
index 0000000..c0ecce7
--- /dev/null
@@ -0,0 +1,68 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020] [HCL Technologies Ltd.]                               #
+#                                                                              #
+#   Licensed under the Apache License, Version 2.0 (the "License");            #
+#   you may not use this file except in compliance with the License.           #
+#   You may obtain a copy of the License at                                    #
+#                                                                              #
+#       http://www.apache.org/licenses/LICENSE-2.0                             #
+#                                                                              #
+#   Unless required by applicable law or agreed to in writing, software        #
+#   distributed under the License is distributed on an "AS IS" BASIS,          #
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
+#   See the License for the specific language governing permissions and        #
+#   limitations under the License.                                             #
+################################################################################
+*******************************************************************************/
+
+/* This file contains O1 main. 
+   Starts the Netopeer and TCP server
+*/
+
+#include "NetconfManager.hpp"
+#include "TcpServer.hpp"
+#include <signal.h>
+
+/********************************************************************** 
+   Description : Main function. Start of O1 module.
+   Params[In]  : None 
+   Return      : EXIT_SUCCESS 
+               : EXIT_FAILURE
+**********************************************************************/
+
+int main(int argc, char **argv)
+{
+   TcpServer tcpServer(O1::TCP_PORT);
+   /*SIGINT handling*/
+   //signal(SIGINT,  NetconfManager::sigintHandler);
+   /* Start Netconf server and subscribe to yang modules */
+   try
+   {
+      NetconfManager::instancePtr()->init();
+      O1_LOG("\nO1 O1_main : NetconfManager init successful");
+
+   }
+   catch( const std::exception& e ) 
+   {
+      O1_LOG("\nO1 O1_main : Exception : %s", e.what());
+      return EXIT_FAILURE;
+   }
+   /* Start the TCP Server to listen for alarm messages */
+   if( tcpServer.start() )
+   {
+      O1_LOG("\nO1 O1_main : TCP server started\n");
+      /* Wait for the TcpServer thread to end*/
+      tcpServer.wait();
+   }
+   else
+   {
+      O1_LOG("\nO1 O1_main : Failed to start TCP server");
+      return EXIT_FAILURE;
+   }
+   return EXIT_SUCCESS;
+}
+
+/**********************************************************************
+         End of file
+**********************************************************************/
diff --git a/src/o1/SessionHandler.cpp b/src/o1/SessionHandler.cpp
new file mode 100644 (file)
index 0000000..f4108c0
--- /dev/null
@@ -0,0 +1,123 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020] [HCL Technologies Ltd.]                               #
+#                                                                              #
+#   Licensed under the Apache License, Version 2.0 (the "License");            #
+#   you may not use this file except in compliance with the License.           #
+#   You may obtain a copy of the License at                                    #
+#                                                                              #
+#       http://www.apache.org/licenses/LICENSE-2.0                             #
+#                                                                              #
+#   Unless required by applicable law or agreed to in writing, software        #
+#   distributed under the License is distributed on an "AS IS" BASIS,          #
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
+#   See the License for the specific language governing permissions and        #
+#   limitations under the License.                                             #
+################################################################################
+*******************************************************************************/
+
+/* This file contains methods of Session/Connection creation and Subscription to
+   YANG modules */
+
+#include "SessionHandler.hpp"
+
+
+/* Default constructor */
+SessionHandler::SessionHandler()
+{    
+}
+
+
+/* Destructor */
+SessionHandler::~SessionHandler()
+{  
+}
+
+/********************************************************************** 
+   Description : This function will create Connection, Session, and 
+                 subscribe. These sysrepo class provide netconf connection
+                 related services.
+   Params[In]  : void
+   Return      : true  - started successful
+                 false - start failed
+**********************************************************************/
+bool SessionHandler::init()
+{
+   try
+   {
+      mConn = createConnection();
+      mSess = createSession(mConn);
+      mSub  = createSubscribe(mSess);
+      O1_LOG("\nO1 SessionHandler : Initialization done");
+      return true;
+   }
+   catch( const std::exception& e )
+   {
+      O1_LOG("\nO1 SessionHandler : Exception : %s", e.what());
+      return false;
+   }
+}
+
+/********************************************************************** 
+   Description : This function will create Connection instance and 
+                 return the same  
+   Params[In]  : void
+   Return      : sysrepo::S_Connection instance
+**********************************************************************/
+sysrepo::S_Connection SessionHandler::createConnection()
+{
+   sysrepo::S_Connection conn(new sysrepo::Connection());
+   return conn;
+}
+
+
+/********************************************************************** 
+   Description : This function will create Session instance and
+                 return the same
+   Params[In]  : sysrepo::S_Connection
+   Return      : sysrepo::S_Session instance
+**********************************************************************/
+sysrepo::S_Session SessionHandler::createSession(sysrepo::S_Connection conn)
+{
+   sysrepo::S_Session sess(new sysrepo::Session(conn));
+   return sess;
+}
+
+
+
+/**********************************************************************
+   Description : This function will create Subscribe instance and
+                 return the same
+   Params[In]  : sysrepo::S_Session
+   Return      : sysrepo::S_Subscribe instance
+**********************************************************************/
+sysrepo::S_Subscribe SessionHandler::createSubscribe(sysrepo::S_Session sess)
+{
+   sysrepo::S_Subscribe subscrb(new sysrepo::Subscribe(sess));
+   if(subscribeModule(subscrb))
+   {
+      O1_LOG("\nO1 SessionHandler : Subscription done successfully");
+   }
+   return subscrb;
+}
+
+
+/********************************************************************** 
+   Description : This function will create a callback object and register
+                 it for callback. 
+   Params[In]  : sysrepo::S_Subscribe
+   Return      : true   - on success
+**********************************************************************/
+bool SessionHandler::subscribeModule(sysrepo::S_Subscribe subscrb)
+{
+   sysrepo::S_Callback alarmOranCb(new AlarmOranYangModel());
+
+   subscrb->oper_get_items_subscribe(ALARM_MODULE_NAME_ORAN, \
+                                     ALARM_MODULE_PATH_ORAN, \
+                                     alarmOranCb);
+   return true;
+}
+
+/**********************************************************************
+         End of file
+**********************************************************************/
diff --git a/src/o1/SessionHandler.hpp b/src/o1/SessionHandler.hpp
new file mode 100644 (file)
index 0000000..0e0472d
--- /dev/null
@@ -0,0 +1,54 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020] [HCL Technologies Ltd.]                               #
+#                                                                              #
+#   Licensed under the Apache License, Version 2.0 (the "License");            #
+#   you may not use this file except in compliance with the License.           #
+#   You may obtain a copy of the License at                                    #
+#                                                                              #
+#       http://www.apache.org/licenses/LICENSE-2.0                             #
+#                                                                              #
+#   Unless required by applicable law or agreed to in writing, software        #
+#   distributed under the License is distributed on an "AS IS" BASIS,          #
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
+#   See the License for the specific language governing permissions and        #
+#   limitations under the License.                                             #
+################################################################################
+*******************************************************************************/
+
+/* This file contains SessionHandler class header*/
+
+#ifndef __SESSION_MANAGER_HPP__
+#define __SESSION_MANAGER_HPP__
+
+#include "sysrepo-cpp/Session.hpp"
+#include "Alarm3GPPYangModel.hpp"
+#include "AlarmOranYangModel.hpp"
+
+
+class SessionHandler
+{
+   public:
+      SessionHandler();
+      ~SessionHandler();
+      
+      bool init();
+
+
+   private:
+      sysrepo::S_Connection mConn;
+      sysrepo::S_Session mSess;
+      sysrepo::S_Subscribe mSub;
+      
+      /*creation of Connection, Session, Subscribe obj functions*/
+      bool subscribeModule(sysrepo::S_Subscribe sub);
+      sysrepo::S_Connection createConnection();
+      sysrepo::S_Session createSession(sysrepo::S_Connection conn);
+      sysrepo::S_Subscribe createSubscribe(sysrepo::S_Session sess);
+};
+
+#endif
+
+/**********************************************************************
+         End of file
+**********************************************************************/