VES PNF Registration Request changes. 23/6023/8
authorHariomGupta <hariom.g@hcl.com>
Mon, 10 May 2021 09:01:36 +0000 (14:31 +0530)
committerHariomGupta <hariom.g@hcl.com>
Wed, 19 May 2021 10:12:11 +0000 (15:42 +0530)
Issue-Id: ODUHIGH-327

Signed-off-by: HariomGupta <hariom.g@hcl.com>
Change-Id: I2b5424e2bdfc3c33995838741f2690c76a12d548

24 files changed:
Dockerfile
build/common/o1.mak
build/common/ves.mak [new file with mode: 0644]
build/config/netconfConfig.json [new file with mode: 0644]
build/config/vesConfig.json [new file with mode: 0644]
build/odu/makefile
build/scripts/install_lib.sh
docs/README
docs/installation-guide.rst
docs/user-guide.rst
src/o1/O1App.cpp
src/o1/ves/HttpClient.cpp [new file with mode: 0644]
src/o1/ves/HttpClient.hpp [new file with mode: 0644]
src/o1/ves/JsonHelper.cpp [new file with mode: 0644]
src/o1/ves/JsonHelper.hpp [new file with mode: 0644]
src/o1/ves/PnfRegistration.cpp [new file with mode: 0644]
src/o1/ves/PnfRegistration.hpp [new file with mode: 0644]
src/o1/ves/VesCommonHeader.cpp [new file with mode: 0644]
src/o1/ves/VesCommonHeader.hpp [new file with mode: 0644]
src/o1/ves/VesEvent.cpp [new file with mode: 0644]
src/o1/ves/VesEvent.hpp [new file with mode: 0644]
src/o1/ves/VesEventHandler.cpp [new file with mode: 0644]
src/o1/ves/VesEventHandler.hpp [new file with mode: 0644]
src/o1/ves/VesUtils.hpp [new file with mode: 0644]

index cfeffb2..3274200 100644 (file)
@@ -4,7 +4,7 @@ FROM nexus3.o-ran-sc.org:10002/o-ran-sc/bldr-ubuntu18-c-go:1.9.0
 # add netconf user
 RUN \
       adduser --system netconf && \
-      echo "netconf:netconf" | chpasswd
+      echo "netconf:netconf!" | chpasswd
 
 # generate ssh keys for netconf user
 RUN \
index 5815798..4b27b80 100755 (executable)
@@ -32,6 +32,7 @@ L_OPTS=-lsysrepo -lyang
 L_OPTS+= -lsysrepo-cpp -lyang-cpp
 L_OPTS+= -lm -lpthread
 I_OPTS=-I$(ROOT_DIR)/src/o1/
+I_OPTS+=-I$(ROOT_DIR)/src/o1/ves/
 
 #-------------------------------------------------------------#
 #Linker macros
diff --git a/build/common/ves.mak b/build/common/ves.mak
new file mode 100644 (file)
index 0000000..4f50d2a
--- /dev/null
@@ -0,0 +1,56 @@
+################################################################################
+#   Copyright (c) [2017-2019] [Radisys]                                        #
+#                                                                              #
+#   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 is makefile for O1 module
+
+include ../common/rsys_fancy.mak
+include ../common/env.mak
+COLOR=$(COLOR_RED)
+
+SRC_DIR=$(ROOT_DIR)/src/o1/ves
+CPP_SRCS=$(wildcard $(SRC_DIR)/*.cpp)
+CPP_OBJS=$(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(CPP_SRCS))
+
+PLTFRM_FLAGS=
+lib: $(LIB_DIR)/libo1.a
+include $(COM_BUILD_DIR)/compile.mak
+
+L_OPTS=-lsysrepo -lyang
+L_OPTS+= -lsysrepo-cpp -lyang-cpp
+L_OPTS+= -lm -lpthread
+L_OPTS+= -lnetconf2 -lcjson -lcurl
+I_OPTS=-I$(ROOT_DIR)/src/o1/ves
+I_OPTS+=-I$(ROOT_DIR)/src/o1
+
+#-------------------------------------------------------------#
+#Linker macros
+#-------------------------------------------------------------#
+
+$(LIB_DIR)/libo1.a:$(CPP_OBJS)
+                 @echo -e "Creating Archive $(COLOR) $@ $(REVERT_COLOR)"
+                 $(Q)ar -cr $(LIB_DIR)/libo1.a $(CPP_OBJS)
+
+#-------------------------------------------------------------#
+#Clean macros
+#-------------------------------------------------------------#
+clean:
+                 @echo -e "$(COLOR_RED)Cleaning O1$(REVERT_COLOR)"
+                 $(Q)\rm -f $(LIB_DIR)/libo1.a $(CPP_OBJS)
+
+#**********************************************************************
+#         End of file
+#**********************************************************************
+
diff --git a/build/config/netconfConfig.json b/build/config/netconfConfig.json
new file mode 100644 (file)
index 0000000..272f686
--- /dev/null
@@ -0,0 +1,10 @@
+{
+    "NetconfServer": {
+        "MacAddress": "02:42:f7:d4:62:ce",
+        "NetconfServerIpv4": "10.0.2.132",
+        "NetconfServerIpv6": "0:0:0:0:0:ffff:a0a:013",
+        "NetconfPort": "830",
+        "NetconfUsername": "netconf",
+        "NetconfPassword": "netconf!"
+    }
+}
diff --git a/build/config/vesConfig.json b/build/config/vesConfig.json
new file mode 100644 (file)
index 0000000..01babd3
--- /dev/null
@@ -0,0 +1,8 @@
+{
+    "vesConfig": {
+        "vesV4IpAddress" : "10.0.2.132",
+        "vesPort" : "8443",
+        "username" : "sample1",
+        "password" : "sample1"
+    }
+}
index 9652f5d..99cd9df 100644 (file)
@@ -141,6 +141,7 @@ endif
 ifeq ($(O1_ENABLE),YES)
   L_OPTS+=-lsysrepo -lyang
   L_OPTS+=-lsysrepo-cpp -lyang-cpp
+L_OPTS+= -lnetconf2 -lcjson -lcurl
   L_OPTS+=-lstdc++
 endif
 
@@ -211,6 +212,7 @@ du:
                $(Q)$(MAKE) -f $(COM_BUILD_DIR)/phy_stub.mak OBJ_DIR=$(OBJ_ROOT)/odu LIB_DIR=$(LIB_ROOT)/odu LOG_DIR=$(LOG_ROOT)/odu CC='$(CC1)'
 ifeq ($(O1_ENABLE),YES)
                $(Q)$(MAKE) -f $(COM_BUILD_DIR)/o1.mak OBJ_DIR=$(OBJ_ROOT)/odu LIB_DIR=$(LIB_ROOT)/odu LOG_DIR=$(LOG_ROOT)/odu CC='$(CCPP1)'
+               $(Q)$(MAKE) -f $(COM_BUILD_DIR)/ves.mak OBJ_DIR=$(OBJ_ROOT)/odu LIB_DIR=$(LIB_ROOT)/odu LOG_DIR=$(LOG_ROOT)/odu CC='$(CCPP1)'
 endif
 
 link_du: du
@@ -231,6 +233,7 @@ clean_odu:
                $(Q)$(MAKE) -f $(COM_BUILD_DIR)/phy_stub.mak clean OBJ_DIR=$(OBJ_ROOT)/odu LIB_DIR=$(LIB_ROOT)/odu LOG_DIR=$(LOG_ROOT)/odu CC='$(CC1)'
 ifeq ($(O1_ENABLE),YES)
                $(Q)$(MAKE) -f $(COM_BUILD_DIR)/o1.mak clean OBJ_DIR=$(OBJ_ROOT)/odu LIB_DIR=$(LIB_ROOT)/odu LOG_DIR=$(LOG_ROOT)/odu CC='$(CCPP1)'
+               $(Q)$(MAKE) -f $(COM_BUILD_DIR)/ves.mak clean OBJ_DIR=$(OBJ_ROOT)/odu LIB_DIR=$(LIB_ROOT)/odu LOG_DIR=$(LOG_ROOT)/odu CC='$(CCPP1)'
 endif
                $(Q)rm -rf $(OBJ_ROOT)/odu/*
                $(Q)rm -rf $(LIB_ROOT)/odu/*
@@ -255,6 +258,7 @@ cu:
         $(Q)$(MAKE) -f $(COM_BUILD_DIR)/mt.mak OBJ_DIR=$(OBJ_ROOT)/cu_stub LIB_DIR=$(LIB_ROOT)/cu_stub LOG_DIR=$(LOG_ROOT)/cu_stub CC='$(CC1)'
 ifeq ($(O1_ENABLE),YES)
                $(Q)$(MAKE) -f $(COM_BUILD_DIR)/o1.mak OBJ_DIR=$(OBJ_ROOT)/cu_stub LIB_DIR=$(LIB_ROOT)/cu_stub LOG_DIR=$(LOG_ROOT)/cu_stub CC='$(CCPP1)'
+               $(Q)$(MAKE) -f $(COM_BUILD_DIR)/ves.mak OBJ_DIR=$(OBJ_ROOT)/cu_stub LIB_DIR=$(LIB_ROOT)/cu_stub LOG_DIR=$(LOG_ROOT)/cu_stub CC='$(CCPP1)'
 endif
 
 clean_cu:
@@ -266,6 +270,7 @@ clean_cu:
         $(Q)$(MAKE) -f $(COM_BUILD_DIR)/mt.mak clean OBJ_DIR=$(OBJ_ROOT)/cu_stub LIB_DIR=$(LIB_ROOT)/cu_stub LOG_DIR=$(LOG_ROOT)/cu_stub CC='$(CC1)'
 ifeq ($(O1_ENABLE),YES)
                $(Q)$(MAKE) -f $(COM_BUILD_DIR)/o1.mak clean OBJ_DIR=$(OBJ_ROOT)/cu_stub LIB_DIR=$(LIB_ROOT)/cu_stub LOG_DIR=$(LOG_ROOT)/cu_stub CC='$(CCPP1)'
+               $(Q)$(MAKE) -f $(COM_BUILD_DIR)/ves.mak clean OBJ_DIR=$(OBJ_ROOT)/cu_stub LIB_DIR=$(LIB_ROOT)/cu_stub LOG_DIR=$(LOG_ROOT)/cu_stub CC='$(CCPP1)'
 endif
         $(Q)rm -rf $(OBJ_ROOT)/cu_stub/*
         $(Q)rm -rf $(LIB_ROOT)/cu_stub/*
@@ -289,6 +294,7 @@ ric:
         $(Q)$(MAKE) -f $(COM_BUILD_DIR)/mt.mak OBJ_DIR=$(OBJ_ROOT)/ric_stub LIB_DIR=$(LIB_ROOT)/ric_stub LOG_DIR=$(LOG_ROOT)/ric_stub CC='$(CC1)'
 ifeq ($(O1_ENABLE),YES)
                $(Q)$(MAKE) -f $(COM_BUILD_DIR)/o1.mak OBJ_DIR=$(OBJ_ROOT)/ric_stub LIB_DIR=$(LIB_ROOT)/ric_stub LOG_DIR=$(LOG_ROOT)/ric_stub CC='$(CCPP1)'
+               $(Q)$(MAKE) -f $(COM_BUILD_DIR)/ves.mak OBJ_DIR=$(OBJ_ROOT)/ric_stub LIB_DIR=$(LIB_ROOT)/ric_stub LOG_DIR=$(LOG_ROOT)/ric_stub CC='$(CCPP1)'
 endif
 
 clean_ric:
@@ -300,6 +306,7 @@ clean_ric:
         $(Q)$(MAKE) -f $(COM_BUILD_DIR)/mt.mak clean OBJ_DIR=$(OBJ_ROOT)/ric_stub LIB_DIR=$(LIB_ROOT)/ric_stub LOG_DIR=$(LOG_ROOT)/ric_stub CC='$(CC1)'
 ifeq ($(O1_ENABLE),YES)
                $(Q)$(MAKE) -f $(COM_BUILD_DIR)/o1.mak clean OBJ_DIR=$(OBJ_ROOT)/ric_stub LIB_DIR=$(LIB_ROOT)/ric_stub LOG_DIR=$(LOG_ROOT)/ric_stub CC='$(CCPP1)'
+               $(Q)$(MAKE) -f $(COM_BUILD_DIR)/ves.mak clean OBJ_DIR=$(OBJ_ROOT)/ric_stub LIB_DIR=$(LIB_ROOT)/ric_stub LOG_DIR=$(LOG_ROOT)/ric_stub CC='$(CCPP1)'
 endif
         $(Q)rm -rf $(OBJ_ROOT)/ric_stub/*
         $(Q)rm -rf $(LIB_ROOT)/ric_stub/*
@@ -320,6 +327,7 @@ copy_build: link_du
                        $(Q)cp -f ./obj/odu/odu ./bin/odu
                        $(Q)cp -rf ./bin/odu $(ROOT_DIR)/bin/
                        $(Q)cp -f ../scripts/odu_script.sh $(ROOT_DIR)/bin/odu
+                       $(Q)cp -rf ../config/ $(ROOT_DIR)/bin/odu
                        $(Q)cp -f ./lib/odu/*.a $(ROOT_DIR)/libs/
                   $(Q)echo -e "***** BUILD COMPLETE *****"
 
index 2aec974..f4e2df5 100755 (executable)
@@ -105,6 +105,28 @@ install_netconf_lib() {
 
    check_ret "LIBSSH" "$?"
 
+   #cJSON
+   cd $NETCONF_PATH && \
+      git clone --single-branch --branch v1.7.14 https://github.com/DaveGamble/cJSON.git && \
+      cd cJSON && \
+      mkdir build && cd build && \
+      cmake .. -DENABLE_CJSON_UTILS=On -DENABLE_CJSON_TEST=Off && \
+      make -j4 && \
+      $SUDO make install && \
+      $SUDO ldconfig
+   check_ret "LIBJSON" "$?"
+
+   #CURL
+   cd $NETCONF_PATH && \
+      git clone --single-branch --branch curl-7_72_0 https://github.com/curl/curl.git &&\
+      cd curl && \
+      mkdir build && cd build && \
+      cmake -DBUILD_TESTING=OFF .. && \
+      make -j4 && \
+      $SUDO make install && \
+      $SUDO ldconfig
+   check_ret "LIBCURL" "$?"
+
    # libyang
    cd $NETCONF_PATH && \
       git clone -b v1.0.184 --depth 1 https://github.com/CESNET/libyang.git && \
index cc9d638..d0671ac 100644 (file)
@@ -39,7 +39,7 @@ C. Pre-requisite for O1 Interface (Required only if run with O1 interface enable
 
        Create new netconf user (login with root user and run following commands)
        $adduser --system netconf && \
-        echo "netconf:netconf" | chpasswd
+        echo "netconf:netconf!" | chpasswd
 
        $mkdir -p /home/netconf/.ssh && \
        ssh-keygen -A && \
@@ -68,6 +68,18 @@ C. Pre-requisite for O1 Interface (Required only if run with O1 interface enable
 
    $sysrepocfg --import=startup_config.xml --datastore running --module  o-ran-sc-odu-interface-v1 
 
+5. Configure the netconf server details for VES PNF Event
+
+   $cd l2/build/config
+
+   Open the netconfConfig.xml and edit the desired MAC address, IP, Port, Username and Password for VES PNF Registration.
+
+6. Configure the VES server details to send VES Events
+
+   $cd l2/build/config
+
+   Open the vesConfig.xml and edit the desired IP, Port, Username and Password to send VES Event.
+
 
 D. How to Clean and Build:
 --------------------------
@@ -235,7 +247,7 @@ H. How to execute the Health Check : get alarm-list
    2. Connect to the server with 
 
         user: netconf
-        pwd:  netconf
+        pwd:  netconf!
 
    3. Send a Netconf get request for alarms xpath
 
index 7de60d3..700180e 100644 (file)
@@ -138,7 +138,7 @@ Setting up Netconf server
    - Ubuntu :  
    
       | adduser --system netconf && \\
-      |    echo "netconf:netconf" | chpasswd
+      |    echo "netconf:netconf!" | chpasswd
 
       | mkdir -p /home/netconf/.ssh && \\
       | ssh-keygen -A && \\
index d8ca936..3d6a845 100644 (file)
@@ -215,7 +215,7 @@ To execute the get alarm-list flow, following steps are required to be executed:
    2. Connect to the server with 
 
       | user: netconf
-      | pwd:  netconf
+      | pwd:  netconf!
 
    3. Send a Netconf get request for alarms xpath
 
index b4cfbde..05bdf7e 100644 (file)
@@ -27,6 +27,8 @@
 #include "ConfigInterface.h"
 #include <unistd.h>
 
+#include "VesUtils.hpp"
+#include "VesEventHandler.hpp"
 /*******************************************************************
  *
  * @brief Constructor
@@ -89,6 +91,15 @@ bool O1App::run()
 {
     
    SessionHandler sessHdlr;
+   /*send ves PNF registration request*/
+   VesEventHandler vesEvtHdr;
+   O1_LOG("\nO1 O1App : Sending VES Event");
+   if(!vesEvtHdr.send(VesEventType::PNF_REGISTRATION))
+   {
+      O1_LOG("\nO1 O1App : Could not send VES Request");
+      return false;
+   }
+
    /* Start Netconf session and subscribe to yang modules */
    try
    {
diff --git a/src/o1/ves/HttpClient.cpp b/src/o1/ves/HttpClient.cpp
new file mode 100644 (file)
index 0000000..4fc675c
--- /dev/null
@@ -0,0 +1,333 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020-2021] [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 functions to support the curl/http related operation*/
+
+#include <string.h>
+#include <stdlib.h>
+#include <sstream>
+#include "HttpClient.hpp"
+
+/* Overloaded constructor */
+HttpClient::HttpClient(string ip, string port, string username, \
+                       string password): mServerIp(ip), mServerPort(port), \
+                       mServerUsername(username), mServerPassword(password)
+{
+
+}
+
+/*******************************************************************
+ *
+ * @brief set options in the curl object
+ *
+ * @details
+ *
+ *    Function : setCurlOptions
+ *
+ *    Functionality:
+ *      - sets curl options in its object
+ *
+ *
+ * @params[in] pointer to curl
+ * @return true  : success
+ *         false : failure
+ ******************************************************************/
+
+bool HttpClient::setCurlOptions(CURL *curl)
+{
+   const char *method = "POST";
+   curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 1L);
+   curl_easy_setopt(curl, CURLOPT_TIMEOUT, 1L);
+   curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1L);
+   curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
+
+    // disable SSL verifications
+   curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
+   curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
+   curl_easy_setopt(curl, CURLOPT_PROXY_SSL_VERIFYPEER, 0L);
+   curl_easy_setopt(curl, CURLOPT_PROXY_SSL_VERIFYHOST, 0L);
+
+   curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, method);
+   return true;
+}
+
+/*******************************************************************
+ *
+ * @brief prepare HTTP Header componentes
+ *
+ * @details
+ *
+ *    Function : prepareHttpHeader
+ *
+ *    Functionality:
+ *      - prepares HTTP Header componentes and set in the
+ *        header object
+ *
+ *
+ * @params[in] pointer to curl and header
+ * @return true  : success
+ *         false : failure
+ ******************************************************************/
+
+bool HttpClient::prepareHttpHeader(struct curl_slist *header, CURL *curl)
+{
+
+   if(!setUserPassword(curl))
+   {
+      O1_LOG("O1 VES : unable to set user:password \n");
+      curl_slist_free_all(header);
+   }
+   setCurlOptions(curl);
+
+   header = curl_slist_append(header, "Content-Type: application/json");
+   if(!header) {
+       O1_LOG("O1 VES : curl_slist_append failed\n");
+       curl_easy_cleanup(curl);
+       return false;
+   }
+
+    header = curl_slist_append(header, "Accept: application/json");
+    if(!header) {
+        O1_LOG("O1 VES : curl_slist_append failed\n");
+        curl_easy_cleanup(curl);
+        return false;
+    }
+    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
+    if(!createUrl(curl))
+    {
+        O1_LOG("O1 VES : could not create URL\n");
+        return false;
+    }
+   return true;
+}
+
+/*******************************************************************
+ *
+ * @brief set username and password into the curl header
+ *
+ * @details
+ *
+ *    Function : setUserPassword
+ *
+ *    Functionality:
+ *      - prepares username and password string and set into the
+ *        header object
+ *
+ *
+ * @params[in] pointer to curl
+ * @return true  : success
+ *         false : failure
+ ******************************************************************/
+
+
+bool HttpClient::setUserPassword(CURL *curl)
+{
+   //make string username:password
+   char *credentials = 0;
+   if((mServerUsername.c_str()) && (mServerPassword.c_str())) {
+      asprintf(&credentials, "%s:%s", mServerUsername.c_str(), mServerPassword.c_str());
+      if(credentials == 0) {
+         O1_LOG("O1 VES : credentials is blank\n");
+         curl_easy_cleanup(curl);
+         return false;
+      }
+   }
+   else {
+      return false;
+   }
+   curl_easy_setopt(curl, CURLOPT_USERPWD, credentials);
+   free(credentials);
+   return true;
+}
+
+/*******************************************************************
+ *
+ * @brief creates and set URL into the curl header
+ *
+ * @details
+ *
+ *    Function : createUrl
+ *
+ *    Functionality:
+ *      - creates URL string and set into the curl
+ *
+ *
+ * @params[in] pointer to curl
+ * @return true  : success
+ *         false : failure
+ ******************************************************************/
+
+
+bool HttpClient::createUrl(CURL *curl)
+{
+   //make the url format -- https://10.0.2.132:8443/eventListener/v7
+
+   std::ostringstream oss;
+   if((mServerIp.c_str()) && (mServerPort.c_str())) {
+      oss <<"https://"<<mServerIp<<":"<<mServerPort<<"/eventListener/v7";
+      string url = oss.str();
+      O1_LOG("O1 VES : URL=%s\n", url.c_str());
+      curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
+      return true;
+   }
+   else
+   {
+      return false;
+   }
+}
+
+/*******************************************************************
+ *
+ * @brief sends HTTP Request with help of curl API
+ *
+ * @details
+ *
+ *    Function : sendHttpRequest
+ *
+ *    Functionality:
+ *      - set curl callback function
+ *      - sends HTTP Request with help of curl API
+ *
+ *
+ * @params[in] pointer to curl, pointer to header
+ * @return true  : success
+ *         false : failure
+ ******************************************************************/
+
+
+bool HttpClient::sendHttpRequest(struct curl_slist *header, CURL *curl)
+{
+   struct response response_data = {0};
+   char **recvData = 0;
+   int *response_code = 0;
+   if(recvData) {
+        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCb);
+        curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&response_data);
+    }
+
+    CURLcode res = curl_easy_perform(curl);
+    curl_slist_free_all(header);
+
+    if(res != CURLE_OK) {
+        O1_LOG("O1 VES : could not send data , received error: %s\n", \
+               curl_easy_strerror(res));
+        curl_easy_cleanup(curl);
+        return false;
+    }
+
+    if(response_code) {
+        long http_rc;
+        curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_rc);
+        *response_code = http_rc;
+    }
+
+    if(recvData) {
+        *recvData = response_data.res;
+    }
+   return true;
+}
+
+/*******************************************************************
+ *
+ * @brief sends VES event to VES collector
+ *
+ * @details
+ *
+ *    Function : send
+ *
+ *    Functionality:
+ *      - prepare curl header
+ *      - sends VES event with help of curl API
+ *
+ *
+ * @params[in] pointer to data buffer
+ * @return true  : success
+ *         false : failure
+ ******************************************************************/
+
+bool HttpClient::send(const char *sendData)
+{
+   assert(sendData);
+
+   struct curl_slist *header = 0;
+   const char *sendMsg = sendData;
+   if(!sendMsg) {
+       sendMsg = "";
+   }
+
+   CURL *curl = curl_easy_init();
+   if(curl == 0) {
+       O1_LOG("O1 VES : could not initialize CURL\n");
+       return false;
+   }
+
+   curl_easy_setopt(curl, CURLOPT_POSTFIELDS, sendMsg);
+   if(!prepareHttpHeader(header, curl))
+   {
+      O1_LOG("O1 VES : could not prepare HTTP header\n");
+      curl_easy_cleanup(curl);
+      return false;
+   }
+   else if(!sendHttpRequest(header, curl))
+   {
+      O1_LOG("O1 VES : could not send HTTP request\n");
+      return false;
+   }
+    curl_easy_cleanup(curl);
+    return true;
+}
+
+/*******************************************************************
+ *
+ * @brief callback of VES event send
+ *
+ * @details
+ *
+ *    Function : writeCb
+ *
+ *    Functionality:
+ *      - callback function of HTTP curl request
+ *
+ *
+ * @params[in] void
+ * @return size of return buffer  : success
+ *         zero                   : failure
+ ******************************************************************/
+
+size_t HttpClient::writeCb(void *data, size_t size, size_t nmemb, void *userp) {
+    O1_LOG("O1 VES : write Callback called\n");
+    size_t realsize = size * nmemb;
+    struct response *mem = (struct response *)userp;
+
+    char *ptr = (char *) realloc(mem->res, mem->size + realsize + 1);
+    if(ptr == NULL) {
+        O1_LOG("O1 VES : realloc failed");
+        return 0;
+    }
+
+    mem->res = ptr;
+    memcpy(&(mem->res[mem->size]), data, realsize);
+    mem->size += realsize;
+    mem->res[mem->size] = 0;
+
+    return realsize;
+}
+
+/**********************************************************************
+  End of file
+ **********************************************************************/
diff --git a/src/o1/ves/HttpClient.hpp b/src/o1/ves/HttpClient.hpp
new file mode 100644 (file)
index 0000000..fba7242
--- /dev/null
@@ -0,0 +1,72 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020-2021] [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 functions to support the preparation of VES common header
+   parameters*/
+
+#ifndef __HTTP_CLIENT_HPP__
+#define __HTTP_CLIENT_HPP__
+
+#include <assert.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <curl/curl.h>
+#include <iostream>
+#include <string>
+#include "VesUtils.hpp"
+#include "JsonHelper.hpp"
+
+using namespace std;
+
+struct response {
+    char *res;
+    size_t size;
+};
+
+class HttpClient
+{
+
+   public:
+      /* Default constructor/Destructor */
+      HttpClient(){}
+      ~HttpClient(){}
+
+      HttpClient(string ip, string port, string username, string password);
+      bool send(const char *send_data);
+
+   private:
+      //member functions
+      static size_t writeCb(void *data, size_t size, size_t nmemb, void *userp);
+      bool prepareHttpHeader(struct curl_slist *header, CURL *curl);
+      bool sendHttpRequest(struct curl_slist *header, CURL *curl);
+      bool setCurlOptions(CURL *curl);
+      bool setUserPassword(CURL *curl);
+      bool createUrl(CURL *curl);
+
+      //member variable
+      string mServerIp;
+      string mServerPort;
+      string mServerUsername;
+      string mServerPassword;
+};
+
+#endif
+/**********************************************************************
+  End of file
+ **********************************************************************/
diff --git a/src/o1/ves/JsonHelper.cpp b/src/o1/ves/JsonHelper.cpp
new file mode 100644 (file)
index 0000000..5eeb39f
--- /dev/null
@@ -0,0 +1,300 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020-2021] [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 functions to support Json related operation (read/write)*/
+
+#include <bits/stdc++.h>
+#include "JsonHelper.hpp"
+#include "VesUtils.hpp"
+
+using namespace std;
+
+/*******************************************************************
+ *
+ * @brief wraps cJSON_CreateObject cJSON library function
+ *
+ * @details
+ *
+ *    Function : createNode
+ *
+ *    Functionality:
+ *      - wraps cJSON_CreateObject cJSON library function
+ *
+ * @params[in] void
+ * @return pointer to cJSON object     - success
+ *         NULL                      - failure
+ *
+ * ****************************************************************/
+
+cJSON * JsonHelper::createNode()
+{
+   return  cJSON_CreateObject();
+}
+
+/*******************************************************************
+ *
+ * @brief wraps cJSON_AddStringToObject cJSON library function
+ *
+ * @details
+ *
+ *    Function : addNodeToObject
+ *
+ *    Functionality:
+ *      - wraps cJSON_AddStringToObject cJSON library function
+ *
+ * @params[in] cJSON * parent, const char * nodeName, const char* value
+ * @return pointer to cJSON object     - success
+ *         NULL                        - failure
+ *
+ * ****************************************************************/
+
+cJSON* JsonHelper::addNodeToObject(cJSON * parent, \
+                                          const char * nodeName, \
+                                          const char* value)
+{
+   return cJSON_AddStringToObject(parent, nodeName, value);
+}
+
+/*******************************************************************
+ *
+ * @brief wraps cJSON_AddNumberToObject cJSON library function
+ *
+ * @details
+ *
+ *    Function : addNodeToObject
+ *
+ *    Functionality:
+ *      - wraps cJSON_AddNumberToObject cJSON library function
+ *
+ * @params[in] cJSON * parent, const char * nodeName, double value
+ * @return pointer to cJSON object     - success
+ *         NULL                        - failure
+ *
+ * ****************************************************************/
+
+cJSON* JsonHelper::addNodeToObject(cJSON * parent, \
+                                          const char * nodeName, double value)
+{
+   return cJSON_AddNumberToObject(parent, nodeName, (double) value);
+}
+
+
+/*******************************************************************
+ *
+ * @brief wraps cJSON_AddItemToObject cJSON library function
+ *
+ * @details
+ *
+ *    Function : addJsonNodeToObject
+ *
+ *    Functionality:
+ *      - wraps cJSON_AddItemToObject cJSON library function
+ *
+ * @params[in] cJSON * parent, const char * nodeName, cJSON * node
+ * @return cJSON_bool non zero  - success
+ *         cJSON_bool 0         - failure
+ *
+ * ****************************************************************/
+
+cJSON_bool JsonHelper::addJsonNodeToObject(cJSON * parent, \
+                                   const char * nodeName, cJSON * node)
+{
+   return cJSON_AddItemToObject(parent, nodeName, node);
+}
+
+/*******************************************************************
+ *
+ * @brief wraps cJSON_Delete cJSON library function
+ *
+ * @details
+ *
+ *    Function : deleteNode
+ *
+ *    Functionality:
+ *      - wrapper of cJSON_AddNumberToObject
+ *
+ * @params[in] cJSON * node
+ * @return void
+ *
+ * ****************************************************************/
+
+
+void JsonHelper::deleteNode(cJSON * node)
+{
+   cJSON_Delete(node);
+}
+
+/*******************************************************************
+ *
+ * @brief wraps cJSON_PrintUnformatted cJSON library function
+ *
+ * @details
+ *
+ *    Function : addNodeToObject
+ *
+ *    Functionality:
+ *      - wraps cJSON_PrintUnformatted cJSON library function
+ *
+ * @params[in] cJSON * node
+ * @return char pointer to string  - success
+ *         nullptr                 - failure
+ *
+ * ****************************************************************/
+
+char *JsonHelper::printUnformatted(cJSON * node)
+{
+   return cJSON_PrintUnformatted(node);
+}
+
+/*******************************************************************
+ *
+ * @brief wraps cJSON_PrintUnformatted cJSON library function
+ *
+ * @details
+ *
+ *    Function : addNodeToObject
+ *
+ *    Functionality:
+ *      - wraps cJSON_PrintUnformatted cJSON library function
+ *
+ * @params[in] cJSON * node
+ * @return char pointer to json message  - success
+ *         nullptr                       - failure
+ *
+ * ****************************************************************/
+
+char *JsonHelper::print(cJSON * node)
+{
+   return cJSON_Print(node);
+}
+
+/*******************************************************************
+ *
+ * @brief wraps cJSON_PrintUnformatted cJSON library function
+ *
+ * @details
+ *
+ *    Function : addNodeToObject
+ *
+ *    Functionality:
+ *      - wraps cJSON_PrintUnformatted cJSON library function
+ *
+ * @params[in] void
+ * @return char pointer to string  - success
+ *         nullptr                 - failure
+ *
+ * ****************************************************************/
+
+const char *JsonHelper::getError()
+{
+   return cJSON_GetErrorPtr();
+}
+
+
+/*******************************************************************
+ *
+ * @brief get value of the provided node
+ *
+ * @details
+ *
+ *    Function : getValue
+ *
+ *    Functionality:
+ *      - fetch the value of the provided node
+ *
+ * @params[in] void
+ * @return pointer to string value         - success
+ *         NULL                            - failure
+ *
+ * ****************************************************************/
+
+char* JsonHelper::getValue(cJSON *json, const char *node)
+{
+   cJSON *object;
+   char * value = NULL;
+   object = cJSON_GetObjectItem(json, node);
+   if(object)
+   {
+      value = object->valuestring;
+      O1_LOG("O1 VES : [ %s] : [%s]\n",node, value );
+   }
+   else
+      O1_LOG("O1 VES : node [ %s] not found\n",node);
+   return value;
+}
+
+/*******************************************************************
+ *
+ * @brief wraps cJSON_GetObjectItem cJSON library function
+ *
+ * @details
+ *
+ *    Function : addNodeToObject
+ *
+ *    Functionality:
+ *      - wraps cJSON_GetObjectItem cJSON library function
+ *
+ * @params[in] cJSON *json, const char *node
+ * @return pointer to cJSON node   - success
+ *         nullptr                 - failure
+ *
+ * ****************************************************************/
+
+cJSON * JsonHelper::getNode(cJSON *json, const char *node)
+{
+   return cJSON_GetObjectItem(json, node);
+}
+
+
+/*******************************************************************
+ *
+ * @brief reads json file
+ *
+ * @details
+ *
+ *    Function : read
+ *
+ *    Functionality:
+ *      - opens and reads json file and returns point to that file.
+ *
+ * @params[in] const char * fileName
+ * @return point to json file root node    - success
+ *         NULL                            - failure
+ *
+ * ****************************************************************/
+
+cJSON* JsonHelper::read(const char * fileName)
+{
+   std::fstream fs(fileName, std::ios::in | std::ios::binary);
+
+   if (!fs) {
+       O1_LOG("O1 VES : json can NOT open file %s\n", fileName);
+        return NULL;
+   }
+
+   std::stringstream iss;
+
+   iss << fs.rdbuf();
+
+    cJSON *json = cJSON_Parse(iss.str().c_str());
+    return json;
+}
+
+/**********************************************************************
+  End of file
+ **********************************************************************/
diff --git a/src/o1/ves/JsonHelper.hpp b/src/o1/ves/JsonHelper.hpp
new file mode 100644 (file)
index 0000000..1546776
--- /dev/null
@@ -0,0 +1,58 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020-2021] [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 functions to support Json related operation (read/write)*/
+
+#ifndef __JSON_HELPER_HPP__
+#define __JSON_HELPER_HPP__
+
+#include <iostream>
+#include <stdlib.h>
+#include <assert.h>
+#include <cjson/cJSON.h>
+#include <string>
+
+class JsonHelper
+{
+
+   public:
+      /* Default constructor/Destructor */
+      JsonHelper(){}
+      ~JsonHelper(){}
+      static cJSON * createNode();
+      static cJSON* addNodeToObject(cJSON * parent, const char * nodeName, \
+                                  const char* value);
+      static cJSON* addNodeToObject(cJSON * parent, \
+                                  const char * nodeName, double value);
+
+      static void deleteNode(cJSON * node);
+      static cJSON_bool addJsonNodeToObject(cJSON * parent, \
+                             const char * nodeName, cJSON * node);
+      static cJSON* read(const char * fileName);
+      static char* getValue(cJSON *json, const char *node);
+      static cJSON * getNode(cJSON *json, const char *node);
+      static char *printUnformatted(cJSON * node);
+      static char *print(cJSON * node);
+      static const char *getError();
+
+};
+
+#endif
+/**********************************************************************
+  End of file
+ **********************************************************************/
diff --git a/src/o1/ves/PnfRegistration.cpp b/src/o1/ves/PnfRegistration.cpp
new file mode 100644 (file)
index 0000000..37eae20
--- /dev/null
@@ -0,0 +1,509 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020-2021] [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 macros and functions to support the preparation of pnf
+   Registration VES Event*/
+
+#include <ctime>
+#include <string.h>
+#include <stdlib.h>
+#include <sstream>
+#include "PnfRegistration.hpp"
+#include "JsonHelper.hpp"
+#include "VesUtils.hpp"
+
+/* Default constructor*/
+PnfRegistration::PnfRegistration()
+{
+   this->mVesEventType = VesEventType::PNF_REGISTRATION;
+}
+
+/* Default Destructor*/
+PnfRegistration::~PnfRegistration()
+{
+}
+
+/*******************************************************************
+ *
+ * @brief get today's date in YYYY-MM-DD format
+ *
+ * @details
+ *
+ *    Function : getCurrentDate
+ *
+ *    Functionality:
+ *      - get today's date in YYYY-MM-DD format
+ *
+ * @params[in] OUT - date string pointer
+ * @return true     - success
+ *         false    - failure
+ *
+ * ****************************************************************/
+
+string PnfRegistration::getCurrentDate()
+{
+   time_t t = time(0);
+   char dateStr[MAX_TIME_STR];
+   strftime(dateStr, MAX_TIME_STR, "%F", localtime(&t));
+   std::ostringstream oss;
+   oss<< dateStr;
+   return oss.str();
+}
+
+/*******************************************************************
+ *
+ * @brief provide mac address of netconf server
+ *
+ * @details
+ *
+ *    Function : getMacAddr
+ *
+ *    Functionality:
+ *      - provide mac address of netconf server
+ *
+ * @params[in] void
+ * @return mac address as string - success
+ *
+ * ****************************************************************/
+
+string PnfRegistration::getNetconfMacAddr()
+{
+   if(mNetconfMacAddr != "") {
+      return mNetconfMacAddr;
+   }
+   else {
+      O1_LOG("O1 VES : could not get Netconf Mac Address\n");
+      return "";
+   }
+}
+
+
+/*******************************************************************
+ *
+ * @brief provide ipv4 address of netconf server
+ *
+ * @details
+ *
+ *    Function : getNetconfV4ServerIP
+ *
+ *    Functionality:
+ *      - provide ipv4 address of netconf server
+ *
+ * @params[in] void
+ * @return ipv4 address as string - success
+ *
+ * ****************************************************************/
+
+string PnfRegistration::getNetconfV4ServerIP()
+{
+   if(mNetconfIpv4 != "") {
+      return mNetconfIpv4;
+   }
+   else {
+      O1_LOG("O1 VES : could not get Netconf IPv4 ip\n");
+      return "";
+   }
+}
+
+/*******************************************************************
+ *
+ * @brief provides Netconf Server Port number
+ *
+ * @details
+ *
+ *    Function : getNetconfPort
+ *
+ *    Functionality:
+ *      - provides Netconf Server Port number
+ *      - provide default port if not provided
+ *
+ * @params[in] void
+ * @return port number - success
+ *
+ * ****************************************************************/
+
+string PnfRegistration::getNetconfPort()
+{
+   if(mNetconfPort != "") {
+      return mNetconfPort;
+   }
+   else {
+      O1_LOG("O1 VES : Could not get Netconf Port number\n");
+      return NETCONF_DEFAULT_PORT;
+   }
+}
+
+/*******************************************************************
+ *
+ *
+ * @brief provides Netconf Server Username
+ *
+ * @details
+ *
+ *    Function : getUsername
+ *
+ *    Functionality:
+ *      - provides Netconf Server Username
+ *
+ * @params[in] void
+ * @return port number - success
+ *
+ * ****************************************************************/
+
+
+string PnfRegistration::getUsername()
+{
+   if(mNetconfUsername != "") {
+      return mNetconfUsername;
+   }
+   else {
+      O1_LOG("O1 VES : could not get Netconf username\n");
+      return "";
+   }
+}
+
+/*******************************************************************
+ *
+ *
+ * @brief provides Netconf Server Password
+ *
+ * @details
+ *
+ *    Function : getPassword
+ *
+ *    Functionality:
+ *      - provides Netconf Server password
+ *
+ * @params[in] void
+ * @return port number - success
+ *
+ * ****************************************************************/
+
+string PnfRegistration::getPassword()
+{
+   if(mNetconfPassword != "") {
+      return mNetconfPassword;
+   }
+   else {
+      O1_LOG("O1 VES : could not get Netconf password\n");
+      return "";
+   }
+}
+
+/*******************************************************************
+ *
+ * @brief provides ipv6 address of netconf server
+ *
+ * @details
+ *
+ *    Function : getNetconfV6ServerIP
+ *
+ *    Functionality:
+ *      - provides ipv6 address of netconf server
+ *
+ * @params[in] void
+ * @return ipv6 address as string - success
+ *
+ * ****************************************************************/
+
+string PnfRegistration::getNetconfV6ServerIP()
+{
+   if(mNetconfIpv6 != "") {
+      return mNetconfIpv6;
+   }
+   else {
+      O1_LOG("O1 VES : could not get Netconf IPv6 ip\n");
+      return "";
+   }
+}
+
+/*******************************************************************
+ *
+ * @brief provide Serial Number
+ *
+ * @details
+ *
+ *    Function : getSerialNumber
+ *
+ *    Functionality:
+ *      - provide  Serial Number
+ *
+ * @params[in] void
+ * @return serial number - success
+ *         empty string  - failure
+ *
+ * ****************************************************************/
+
+string PnfRegistration::getSerialNumber()
+{
+      string serialNum;
+      serialNum.append(VENDER_NAME_VENDORB).append("-").append(UNIT_TYPE_7DEV);
+      serialNum.append("-").append(getNetconfV4ServerIP()).append("-");
+      serialNum.append(MODEL_NUMBER_007_DEV);
+      //string serialNum = VENDER_NAME_VENDORB + "-" + UNIT_TYPE_7DEV + "-" \
+                         + getNetconfV4ServerIP() + "-" + MODEL_NUMBER_007_DEV;
+   return serialNum;
+}
+
+/*******************************************************************
+ *
+ * @brief provide Unit Family
+ *
+ * @details
+ *
+ *    Function : getUnitFamily
+ *
+ *    Functionality:
+ *      - provide  Unit Family
+ *
+ * @params[in] void
+ * @return serial number - success
+ *         empty string  - failure
+ *
+ * ****************************************************************/
+
+string PnfRegistration::getUnitFamily()
+{
+   string unitFamily;
+   unitFamily.append(VENDER_NAME_VENDORB).append("-").append(UNIT_TYPE_7DEV);
+   return unitFamily;
+}
+
+
+/*******************************************************************
+ *
+ * @brief prepare PNF registration Fields
+ *
+ * @details
+ *
+ *    Function : preparePnfRegistrationFields
+ *
+ *    Functionality:
+ *      - prepare PNF registration Fields in json format
+ *
+ * @params[in] IN   - pointer to pnfFields 
+ * @return true     - success
+ *         false    - failure
+ *
+ * ****************************************************************/
+
+bool PnfRegistration::prepareEventFields()
+{
+   bool ret = true;
+   cJSON* pnfFields = this->mVesEventFields;
+   if(!readConfigFile())
+   {
+      O1_LOG("O1 VES : config file reading failed\n");
+      //return false;
+   }
+   if(JsonHelper::addNodeToObject(pnfFields, "pnfRegistrationFieldsVersion", \
+                                       PNF_REGISTRATION_VERSION_2_1) == 0) {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(pnfFields, \
+                       "lastServiceDate", getCurrentDate().c_str()) == 0) {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(pnfFields, "macAddress", \
+                                       getNetconfMacAddr().c_str()) == 0) {
+      ret = false;
+   }
+   if(JsonHelper::addNodeToObject(pnfFields, \
+                  "manufactureDate", getCurrentDate().c_str()) == 0) {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(pnfFields, "modelNumber", \
+                                       MODEL_NUMBER_007_DEV) == 0) {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(pnfFields, "oamV4IpAddress", \
+                                       getNetconfV4ServerIP().c_str()) == 0) {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(pnfFields, "oamV6IpAddress", \
+                                       getNetconfV6ServerIP().c_str()) == 0) {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(pnfFields, "serialNumber", \
+                                       getSerialNumber().c_str()) == 0) {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(pnfFields, "softwareVersion", \
+                                       SOFTWARE_VERSION_2_3_5) == 0) {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(pnfFields, "unitFamily", \
+                                       getUnitFamily().c_str()) == 0) {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(pnfFields, "unitType", \
+                                       UNIT_TYPE_7DEV) == 0) {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(pnfFields, "vendorName", \
+                                       VENDER_NAME_VENDORB) == 0) {
+      ret = false;
+   }
+   else
+   {
+      cJSON *addFields = JsonHelper::createNode();
+      if(addFields == 0) {
+         O1_LOG("O1 VES : could not create additional fields JSON object\n");
+         return false;
+      }
+
+      if(prepareAdditionalFields(addFields))
+      {
+         O1_LOG("O1 VES : PNF parameter prepration done adding additional parameters \
+if required \n");
+      if(addFields == 0) {
+         O1_LOG("O1 VES : could not prepare additional fields cJSON object\n");
+         JsonHelper::deleteNode(pnfFields);
+         return false;
+         }
+
+      if(JsonHelper::addJsonNodeToObject(pnfFields, "additionalFields", \
+                               addFields) == 0) {
+         O1_LOG("O1 VES : could not add additional fileds\n");
+         JsonHelper::deleteNode(pnfFields);
+         return false;
+         }
+       }
+       O1_LOG("O1 VES : Preparation on PNF registration additional fields done \
+successfully \n");
+   }
+   return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief prepare PNF registration additional Fields
+ *
+ * @details
+ *
+ *    Function : prepareAdditionalFields
+ *
+ *    Functionality:
+ *      - prepare PNF registration additional Fields in json formate
+ *
+ * @params[in] IN   - pointer to addField
+ * @return true     - success
+ *         false    - failure
+ *
+ * ****************************************************************/
+
+bool PnfRegistration::prepareAdditionalFields(cJSON *addFields)
+{
+   bool ret = true;
+   if(JsonHelper::addNodeToObject(addFields, "oamPort", getNetconfPort().c_str()) == 0) {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(addFields, "protocol", \
+                                       NETCONF_PROTOCOL_SSH) == 0) {
+      ret = false;
+   }
+
+   else if(JsonHelper::addNodeToObject(addFields, "username", \
+                                       getUsername().c_str()) == 0) {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(addFields, "password", \
+                                       getPassword().c_str()) == 0) {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(addFields, "reconnectOnChangedSchema", \
+                                       RECONNECT_ON_SCHEMA_CHANGE_FALSE) == 0) {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(addFields, "sleep-factor", \
+                                       SLEEP_FACTOR_1_5) == 0) {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(addFields, "tcpOnly", \
+                                       TCP_ONLY_FALSE) == 0) {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(addFields, "connectionTimeout", \
+                                       CONNECTION_TIMEOUT_20000) == 0) {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(addFields, "maxConnectionAttempts", \
+                                       MAX_CONNECTION_ATTEMPTS_100) == 0) {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(addFields, "betweenAttemptsTimeout", \
+                                       BETWEEN_ATTEMPTS_TIMEOUT_2000) == 0) {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(addFields, "keepaliveDelay", \
+                                       KEEPALIVE_DELAY_120) == 0) {
+      ret = false;
+   }
+   O1_LOG("O1 VES : additonal field preparation of PNF done successfully \n");
+   return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief Read json file
+ *
+ * @details
+ *
+ *    Function : readConfigFile
+ *
+ *    Functionality:
+ *      - Read json file
+ *
+ *
+ * @params[in] void
+ * @return true  : success
+ *         false : failure
+ ******************************************************************/
+
+bool PnfRegistration::readConfigFile()
+{
+   cJSON *json = JsonHelper::read(NETCONF_CONFIG);
+   if(json == NULL) {
+       O1_LOG("O1 VES : Config file reading error is  :%s\n", JsonHelper::getError());
+    return false;
+    }
+    else {
+       cJSON *rootNode = NULL;
+       rootNode = JsonHelper::getNode(json, "NetconfServer");
+       if(rootNode) {
+          O1_LOG("O1 VES : Reading NetconfServer config file\n");
+          mNetconfMacAddr = JsonHelper::getValue(rootNode, "MacAddress");
+          mNetconfIpv4 = JsonHelper::getValue(rootNode, "NetconfServerIpv4");
+          mNetconfIpv6 = JsonHelper::getValue(rootNode, "NetconfServerIpv6");
+          mNetconfPort = JsonHelper::getValue(rootNode, "NetconfPort");
+          mNetconfUsername = JsonHelper::getValue(rootNode, "NetconfUsername");
+          mNetconfPassword = JsonHelper::getValue(rootNode, "NetconfPassword");
+      }
+      else {
+         O1_LOG("O1 VES : smoConfig Object is not availbale in config file\n");
+         return false;
+      }
+   }
+   JsonHelper::deleteNode(json);
+   return true;
+}
+
+/**********************************************************************
+  End of file
+ **********************************************************************/
diff --git a/src/o1/ves/PnfRegistration.hpp b/src/o1/ves/PnfRegistration.hpp
new file mode 100644 (file)
index 0000000..72f0d22
--- /dev/null
@@ -0,0 +1,74 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020-2021] [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 macros and functions to support the preparation of pnf
+   Registration VES Event*/
+
+
+#ifndef __PNF_REGISTRATION_HPP__
+#define __PNF_REGISTRATION_HPP__
+
+#include <iostream>
+#include <string>
+#include <cjson/cJSON.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "VesUtils.hpp"
+#include "VesEvent.hpp"
+
+#define MAX_TIME_STR 11
+
+using namespace std;
+
+class PnfRegistration : public VesEvent
+{
+
+   public:
+      /* Default constructor/Destructor */
+      PnfRegistration();
+      ~PnfRegistration();
+
+   protected:
+      bool prepareEventFields();
+
+   private:
+      bool prepareAdditionalFields(cJSON *addFields);
+      string getCurrentDate();
+      string getNetconfMacAddr();
+      string getNetconfV4ServerIP();
+      string getNetconfV6ServerIP();
+      string getNetconfPort();
+      string getUsername();
+      string getPassword();
+      string getSerialNumber();
+      string getUnitFamily();
+      bool readConfigFile();
+
+      //member variables
+      string mNetconfMacAddr;
+      string mNetconfIpv4;
+      string mNetconfIpv6;
+      string mNetconfPort;
+      string mNetconfUsername;
+      string mNetconfPassword;
+};
+
+#endif
+/**********************************************************************
+  End of file
+ **********************************************************************/
diff --git a/src/o1/ves/VesCommonHeader.cpp b/src/o1/ves/VesCommonHeader.cpp
new file mode 100644 (file)
index 0000000..3c4b1f9
--- /dev/null
@@ -0,0 +1,529 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020-2021] [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 functions to support the preparation of VES common header
+   parameters*/
+
+#include <stdio.h>
+#include <typeinfo>
+#include <chrono>
+#include <sys/time.h>
+#include <ctime>
+#include <sstream>
+#include "JsonHelper.hpp"
+#include "VesCommonHeader.hpp"
+
+static uint16_t seqNo = 0;
+
+/*******************************************************************
+ *
+ * @brief provide next sequence number of VES event
+ *
+ * @details
+ *
+ *    Function : nextSequenceNo
+ *
+ *    Functionality:
+ *      - provide next sequence number of VES event
+ *
+ * @params[in] void
+ * @return next sequence number of event  - success
+ *
+ * ****************************************************************/
+
+uint16_t VesCommonHeader::nextSequenceNo()
+{
+   return seqNo++;
+}
+
+/*******************************************************************
+ *
+ * @brief provide current sequence number of VES event
+ *
+ * @details
+ *
+ *    Function : getSequenceNo
+ *
+ *    Functionality:
+ *      - provide current sequence number of VES event
+ *
+ * @params[in] void
+ * @return current sequence number of event  - success
+ *
+ * ****************************************************************/
+
+uint16_t VesCommonHeader::getSequenceNo()
+{
+   return seqNo;
+}
+
+/*******************************************************************
+ *
+ * @brief Convert Ves Event type to string
+ *
+ * @details
+ *
+ *    Function : getEventTypeToStr
+ *
+ *    Functionality:
+ *      - Convert Ves Event type to String
+ *
+ * @params[in] IN - void
+ * @return value of string     - success
+ *         empty string        - failure
+ *
+ * ****************************************************************/
+
+string VesCommonHeader::getEventTypeToStr()
+{
+   string str = "";
+   switch(mEventType)
+   {
+      case VesEventType::PNF_REGISTRATION:
+         str = "pnfRegistration";
+         break;
+      case VesEventType::FAULT_NOTIFICATION:
+         str = "faultNotification";
+         break;
+      case VesEventType::PM_NOTIFICATION:
+         str = "pmNotification";
+         break;
+      case VesEventType::HEARTBEAT:
+         str = "heartbeat";
+         break;
+      default:
+         O1_LOG("O1 VES : VES msg Type is not avilable\n");
+         break;
+   }
+   return str;
+}
+
+/*******************************************************************
+ *
+ * @brief create Ves Event Id from Ves Event type
+ *
+ * @details
+ *
+ *    Function : getEventId
+ *
+ *    Functionality:
+ *      - create Ves Event Id from Ves Event type
+ *
+ * @params[in] IN - void
+ * @return value of string     - success
+ *         empty string        - failure
+ *
+ * ****************************************************************/
+
+string VesCommonHeader::getEventId()
+{
+  /*Currently PNF_REGISTRATION only supported. This function must be updated
+    in later releases*/
+   string evntId = "";
+   switch(mEventType)
+   {
+      case VesEventType::PNF_REGISTRATION:
+         evntId = getSourceName() + "_" + MODEL_NUMBER_007_DEV;
+         break;
+      case VesEventType::HEARTBEAT:
+         evntId = getEventTypeToStr() + "_" + getCurrentTime();
+         break;
+      default:
+         O1_LOG("O1 VES : this VES msg Type support in getEventId is \
+not available\n");
+         break;
+   }
+   return evntId;
+
+}
+
+/*******************************************************************
+ *
+ * @brief create Ves Event Type
+ *
+ * @details
+ *
+ *    Function : getEventType
+ *
+ *    Functionality:
+ *      - create Ves Event Type
+ *
+ * @params[in] IN - void
+ * @return value of string     - success
+ *         empty string        - failure
+ *
+ * ****************************************************************/
+
+string VesCommonHeader::getEventType()
+{
+  /*Currently PNF_REGISTRATION only supported. This function must be updated
+    in later releases*/
+
+   string evntType = "";
+   switch(mEventType)
+   {
+      case VesEventType::PNF_REGISTRATION:
+         evntType = EVENT_TYPE_5G;
+         break;
+      case VesEventType::HEARTBEAT:
+         evntType = EVENT_TYPE_ORAN_COMPONENET;
+         break;
+      default:
+         O1_LOG("O1 VES : this VES msg Type support in getEvenType is \
+not available\n");
+         break;
+   }
+   return evntType;
+}
+
+/*******************************************************************
+ *
+ * @brief return priority of event
+ *
+ * @details
+ *
+ *    Function : getPriority
+ *
+ *    Functionality:
+ *      - send priority of event
+ *
+ * @params[in] IN - void
+ * @return value of string     - success
+ *         empty string        - failure
+ *
+ * ****************************************************************/
+
+string VesCommonHeader::getPriority()
+{
+  /*Currently PNF_REGISTRATION only supported. This function must be updated
+    in later releases*/
+
+   string evntId = "";
+   switch(mEventType)
+   {
+      case VesEventType::PNF_REGISTRATION:
+         evntId = PRIORITY_LOW ;
+         break;
+      case VesEventType::HEARTBEAT:
+         evntId = PRIORITY_LOW;
+         break;
+      default:
+         O1_LOG("O1 VES : This VES msg Type support in getPriority is \
+not available\n");
+         break;
+   }
+   return evntId;
+}
+
+
+
+/*******************************************************************
+ *
+ * @brief create Ves Event Name from Ves Event type
+ *
+ * @details
+ *
+ *    Function : getEventName
+ *
+ *    Functionality:
+ *      - create Ves Event Name from Ves Event type
+ *
+ * @params[in] IN - void
+ * @return value of string     - success
+ *         empty string        - failure
+ * ****************************************************************/
+
+string VesCommonHeader::getEventName()
+{
+  /*Currently PNF_REGISTRATION only supported. This function must be updated
+    in later releases*/
+
+   string evntName = "";
+   switch(mEventType)
+   {
+      case VesEventType::PNF_REGISTRATION:
+         evntName = getEventTypeToStr() + "_" + EVENT_TYPE_5G;
+         break;
+      case VesEventType::HEARTBEAT:
+         evntName = getEventTypeToStr() + "_" + EVENT_TYPE_ORAN_COMPONENET;
+         break;
+      default:
+         O1_LOG("O1 VES : This VES msg Type support in getEventName is \
+not available\n");
+         break;
+   }
+   return evntName;
+}
+
+/*******************************************************************
+ *
+ * @brief create Ves Event Name from Ves Event type
+ *
+ * @details
+ *
+ *    Function : getReportingEntityName
+ *
+ *    Functionality:
+ *      - create Ves Event Name from Ves Event type
+ *
+ * @params[in] IN - void
+ * @return value of string     - success
+ *         empty string        - failure
+ * ****************************************************************/
+
+string VesCommonHeader::getReportingEntityName()
+{
+  /*Currently PNF_REGISTRATION only supported. This function must be updated
+    in later releases*/
+
+   string evntName = "";
+   switch(mEventType)
+   {
+      case VesEventType::PNF_REGISTRATION:
+         evntName = getSourceName();
+         break;
+      default:
+         O1_LOG("O1 VES : This VES msg Type support in \
+getReportingEntityName is not available\n");
+         break;
+   }
+   return evntName;
+}
+
+/*******************************************************************
+ *
+ * @brief create Ves Event Name from Ves Event type
+ *
+ * @details
+ *
+ *    Function : getReportingEntityName
+ *
+ *    Functionality:
+ *      - create Ves Event Name from Ves Event type
+ *
+ * @params[in] IN - void
+ * @return value of string     - success
+ *         empty string        - failure
+ * ****************************************************************/
+
+string VesCommonHeader::getSourceName()
+{
+  /*Currently PNF_REGISTRATION only supported. This function need to be updated
+    in later releases*/
+   return ODU_HIGH;
+}
+
+/*******************************************************************
+ *
+ * @brief create Ves Event Name from Ves Event type
+ *
+ * @details
+ *
+ *    Function : getNamingCode
+ *
+ *    Functionality:
+ *      - Network function type: 4 characters (aligned with vnf and pnf
+           naming standards)
+ *
+ * @params[in] IN - void
+ * @return value of string     - success
+ *         empty string        - failure
+ * ****************************************************************/
+
+string VesCommonHeader::getNamingCode()
+{
+  /*Currently PNF_REGISTRATION only supported. This function need to be updated
+    in later releases*/
+   return NAMING_CODE_ODU;
+}
+
+
+
+/*******************************************************************
+ *
+ * @brief provide current epoch time
+ *
+ * @details
+ *
+ *    Function : getEpochTime
+ *
+ *    Functionality:
+ *      - provide current epoch time
+ *
+ * @params[in] void
+ * @return epoch time     - success
+ *
+ * ****************************************************************/
+
+uint64_t VesCommonHeader::getEpochTime()
+{
+    uint64_t epochTimeInMicrosec = std::chrono::duration_cast \
+            <std::chrono::microseconds> \
+            (std::chrono::system_clock::now().time_since_epoch()).count();
+    return epochTimeInMicrosec;
+}
+
+/*******************************************************************
+ *
+ * @brief get current date-time
+ *
+ * @details
+ *
+ *    Function : getCurrentTime
+ *
+ *    Functionality:
+ *      - get current date-time
+ *
+ * @params[in] void
+ * @return time-date     - success
+ *
+ * ****************************************************************/
+
+string VesCommonHeader::getCurrentTime()
+{
+   time_t t = time(0);
+   std::ostringstream oss;
+   char *dateStr;
+   strftime(dateStr, MAX_TIME_STR, "%F", localtime(&t));
+    oss << dateStr;
+    return oss.str();
+}
+
+/*******************************************************************
+ *
+ * @brief create Ves Event Name from Ves Event type
+ *
+ * @details
+ *
+ *    Function : getEventName
+ *
+ *    Functionality:
+ *      - create Ves Event Name from Ves Event type
+ *
+ * @params[in] IN - VesEventType , OUT - Ves Event Name
+ * @return ture     - success
+ *         false    - failure
+ *
+ * ****************************************************************/
+
+bool VesCommonHeader::prepare(cJSON *commonHeader, \
+                              VesEventType type)
+{
+   O1_LOG("O1 VES : createCommonHeader fuction started\n");
+   bool ret=true;
+   string typeStr;
+   string evntId;
+   string evntName;
+   mEventType = type;
+   seqNo=0;
+   nextSequenceNo(); //update the sequence number for next message
+   if(JsonHelper::addNodeToObject(commonHeader, "domain", \
+       getEventTypeToStr().c_str()) == 0) {
+      ret=false;
+   }
+   else if ( JsonHelper::addNodeToObject(commonHeader, "eventId", \
+                                         getEventId().c_str()) == 0)
+   {
+      ret =false;
+   }
+   else if(JsonHelper::addNodeToObject(commonHeader, "eventName", \
+                                       getEventName().c_str()) == 0)
+   {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(commonHeader, "eventType", \
+                                       getEventType().c_str()) == 0)
+   {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(commonHeader, "sequence", \
+                                       getSequenceNo()) == 0)
+   {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(commonHeader, "priority", \
+                                       getPriority().c_str()) == 0)
+   {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(commonHeader, "reportingEntityId", \
+                                       "") == 0)
+   {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(commonHeader, "reportingEntityName", \
+                                       getReportingEntityName().c_str()) == 0)
+   {
+      ret = false;
+   }
+  else if(JsonHelper::addNodeToObject(commonHeader, "sourceId", \
+                                      "") == 0)
+   {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(commonHeader, "sourceName", \
+                                       getSourceName().c_str()) == 0)
+   {
+      ret = false;
+   }
+  else if(JsonHelper::addNodeToObject(commonHeader, "startEpochMicrosec", \
+                                      (double) getEpochTime()) == 0)
+   {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(commonHeader, "lastEpochMicrosec", \
+                                       (double) getEpochTime()) == 0)
+   {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(commonHeader, "nfNamingCode", \
+                                       getNamingCode().c_str()) == 0)
+   {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(commonHeader, "nfVendorName", \
+                                       "") == 0)
+   {
+      ret = false;
+   }
+  else if(JsonHelper::addNodeToObject(commonHeader, "timeZoneOffset", \
+                                      TIME_ZONE_00_00) == 0)
+   {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(commonHeader, "version", \
+                                       VERSION_4_0_1) == 0)
+   {
+      ret = false;
+   }
+   else if(JsonHelper::addNodeToObject(commonHeader, "vesEventListenerVersion", \
+                                       VES_EVENT_LISTENER_7_2_1) == 0)
+   {
+      ret = false;
+   }
+   else
+   {
+      O1_LOG("O1 VES : VES common Header prepared successfully \n");
+   }
+   return ret;
+
+}
+
+/**********************************************************************
+  End of file
+ **********************************************************************/
diff --git a/src/o1/ves/VesCommonHeader.hpp b/src/o1/ves/VesCommonHeader.hpp
new file mode 100644 (file)
index 0000000..21e0d6e
--- /dev/null
@@ -0,0 +1,67 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020-2021] [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 functions to support the preparation of VES common header
+   parameters*/
+
+#ifndef __VES_COMMON_HEADER_HPP__
+#define __VES_COMMON_HEADER_HPP__
+
+
+#include <iostream>
+#include <string>
+#include <cstdint>
+#include <cjson/cJSON.h>
+#include <sys/time.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "VesUtils.hpp"
+
+#define MAX_TIME_STR 11
+using namespace std;
+
+class VesCommonHeader{
+
+   public:
+      /* Default constructor/Destructor*/
+      VesCommonHeader(){}
+      ~VesCommonHeader(){}
+
+      bool prepare(cJSON *node, VesEventType type);
+
+   private:
+      uint16_t getSequenceNo();
+      uint16_t nextSequenceNo();
+      string getEventTypeToStr();
+      string getEventType();
+      string getEventId();
+      string getPriority();
+      string getEventName();
+      string getReportingEntityName();
+      string getSourceName();
+      string getNamingCode();
+      uint64_t getEpochTime();
+      string getCurrentTime();
+
+      VesEventType mEventType;
+};
+
+#endif
+/**********************************************************************
+  End of file
+ **********************************************************************/
diff --git a/src/o1/ves/VesEvent.cpp b/src/o1/ves/VesEvent.cpp
new file mode 100644 (file)
index 0000000..6565fdf
--- /dev/null
@@ -0,0 +1,210 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020-2021] [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 functions to support the preparation of VES Event
+   It is the parent class of Ves Event, Every event need to override at
+   least prepareEventFields function and fill specific values of event
+   fields */
+
+#include "VesEvent.hpp"
+
+
+/* Default constructor*/
+VesEvent::VesEvent()
+{
+   mHttpClient = NULL;
+}
+
+
+/* Default Destructor*/
+VesEvent::~VesEvent()
+{
+   if(mHttpClient != NULL)
+   {
+      delete mHttpClient;
+   }
+}
+
+/*******************************************************************
+ *
+ * @brief prepare Ves Event Fields
+ *
+ * @details
+ *
+ *    Function : prepare
+ *
+ *    Functionality:
+ *      - prepare Ves Event Fields in json format
+ *
+ * @params[in] IN   - void
+ * @return true     - success
+ *         false    - failure
+ *
+ * ****************************************************************/
+
+bool VesEvent::prepare()
+{
+
+   O1_LOG("O1 VES : prepare PNF Registration start\n");
+   if(!getVesCollectorDetails()) {
+      O1_LOG("O1 VES : Could not get successfully details of Ves Collector\n");
+      return false;
+   }
+
+   mHttpClient = new HttpClient(mVesServerIp, mVesServerPort, mVesServerUsername, \
+                         mVesServerPassword);
+
+   cJSON *rootNode = JsonHelper::createNode();
+   if(rootNode == 0) {
+       O1_LOG("O1 VES : could not create cJSON root Node object\n");
+       return false;
+   }
+
+   cJSON *event = JsonHelper::createNode();
+   if(event == 0) {
+      O1_LOG("O1 VES : could not create event cJSON object\n");
+      JsonHelper::deleteNode(rootNode);
+      return false;
+   }
+
+   if(JsonHelper::addJsonNodeToObject(rootNode, "event", event) == 0) {
+      O1_LOG("O1 VES : could not add event Object\n");
+      JsonHelper::deleteNode(rootNode);
+      return false;
+   }
+
+   cJSON *commHdrNode = JsonHelper::createNode();
+   if(commHdrNode == 0) {
+      O1_LOG("O1 VES : could not create common header Node JSON object");
+      return false;
+   }
+
+   VesCommonHeader vesCommHdr;
+
+   if(vesCommHdr.prepare(commHdrNode, mVesEventType))
+   {
+       if(JsonHelper::addJsonNodeToObject(event, "commonEventHeader", \
+                                commHdrNode) == 0) {
+       O1_LOG("O1 VES : could not add commonEventHeader object\n");
+       JsonHelper::deleteNode(rootNode);
+       return false;
+      }
+      else {
+
+         //add header into the message and create pnfFields
+         mVesEventFields = JsonHelper::createNode();
+         if(mVesEventFields == 0) {
+            O1_LOG("O1 VES : could not create Ves Event Fields JSON object\n");
+            return false;
+         }
+
+         if(!prepareEventFields()) {
+         O1_LOG("O1 VES : could not prepare Ves Event Fields Node \n");
+         JsonHelper::deleteNode(rootNode);
+         return false;
+         }
+
+         if(JsonHelper::addJsonNodeToObject(event, "pnfRegistrationFields", mVesEventFields) == 0) {
+            O1_LOG("O1 VES : could not add mVesEventFields object\n");
+            JsonHelper::deleteNode(rootNode);
+            return false;
+         }
+
+      mSendData = JsonHelper::printUnformatted(rootNode);
+      O1_LOG("O1 VES : final ves request : -- \n%s\n", JsonHelper::print(rootNode));
+      }
+   }
+   else
+   {
+      O1_LOG("O1 VES : preparePnfRegistration common header preparation failed\n");
+      JsonHelper::deleteNode(rootNode);
+      return false;
+   }
+   return true;
+}
+
+bool VesEvent::send()
+{
+   return mHttpClient->send(mSendData);
+}
+
+/*******************************************************************
+ *
+ * @brief Gets the Ves Collector Server details
+ *
+ * @details
+ *
+ *    Function : getVesCollectorDetails
+ *
+ *    Functionality:
+ *      - Gets the Ves Collector Server details by reading config file
+ *
+ * @params[in] IN   - pointer to pnfFields
+ * @return true     - success
+ *         false    - failure
+ *
+ * ****************************************************************/
+
+
+bool VesEvent::getVesCollectorDetails()
+{
+   return readConfigFile();
+}
+
+/*******************************************************************
+ *
+ * @brief Read Ves Collector config json file
+ *
+ * @details
+ *
+ *    Function : readConfigFile
+ *
+ *    Functionality:
+ *      - Reads json file.
+ *
+ *
+ * @params[in] void
+ * @return true  : success
+ *         false : failure
+ ******************************************************************/
+
+bool VesEvent::readConfigFile()
+{
+   cJSON *json = JsonHelper::read(VES_CONFIG);
+   if(json == NULL) {
+       O1_LOG("O1 VES : Config file reading error is  :%s\n", JsonHelper::getError());
+    return false;
+   }
+   else {
+      cJSON *rootNode = NULL;
+      rootNode = JsonHelper::getNode(json, "vesConfig");
+      if(rootNode) {
+         O1_LOG("O1 VES : Reading smoConfig.json file\n");
+         mVesServerIp = JsonHelper::getValue(rootNode, "vesV4IpAddress");
+         mVesServerPort = JsonHelper::getValue(rootNode, "vesPort");
+         mVesServerUsername = JsonHelper::getValue(rootNode, "username");
+         mVesServerPassword = JsonHelper::getValue(rootNode, "password");
+      }
+      else {
+         O1_LOG("O1 VES : smoConfig Object is not availbale in config file\n");
+         return false;
+      }
+   }
+   JsonHelper::deleteNode(json);
+   return true;
+}
diff --git a/src/o1/ves/VesEvent.hpp b/src/o1/ves/VesEvent.hpp
new file mode 100644 (file)
index 0000000..f6e746d
--- /dev/null
@@ -0,0 +1,64 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020-2021] [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 Base call functions to support send VES Event*/
+
+
+#ifndef __VES_EVENT_HPP__
+#define __VES_EVENT_HPP__
+
+#include <iostream>
+#include <string>
+#include <cjson/cJSON.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "VesUtils.hpp"
+#include "VesCommonHeader.hpp"
+#include "HttpClient.hpp"
+
+using namespace std;
+
+class VesEvent{
+
+   public:
+      VesEvent();
+      ~VesEvent();
+      bool prepare();
+      bool send();
+
+   protected:
+      virtual bool prepareEventFields() = 0;
+      VesEventType mVesEventType;
+      cJSON* mVesEventFields;
+
+   private:
+      //Member variable
+      bool readConfigFile();
+      bool getVesCollectorDetails();
+      char * mSendData;
+      HttpClient *mHttpClient;
+      string mVesServerIp;
+      string mVesServerPort;
+      string mVesServerUsername;
+      string mVesServerPassword;
+};
+
+#endif
+/**********************************************************************
+  End of file
+ **********************************************************************/
diff --git a/src/o1/ves/VesEventHandler.cpp b/src/o1/ves/VesEventHandler.cpp
new file mode 100644 (file)
index 0000000..18258e1
--- /dev/null
@@ -0,0 +1,86 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020-2021] [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 functions to support the preparation of Common Header part
+   of VES Event*/
+
+
+#include "VesEventHandler.hpp"
+#include "PnfRegistration.hpp"
+
+/*******************************************************************
+ *
+ * @brief prepare and send  Ves Message
+ *
+ * @details
+ *
+ *    Function : sendVesEvent
+ *
+ *    Functionality:
+ *      - prepare VES event and send to oam
+ *
+ * @params[in] void
+ * @return true     - success
+ *         false    - failure
+ *
+ * ****************************************************************/
+
+bool VesEventHandler::send(VesEventType evtType)
+{
+   //check event type and call funtions accordingly
+   bool ret = true;
+   //char *sendData;
+   O1_LOG("O1 VES : sendVesEvent started\n");
+   VesEvent *vesEvent;
+   //common header
+   switch(evtType)
+   {
+      case VesEventType::PNF_REGISTRATION:
+         {
+            O1_LOG("O1 VES : send PNP registration\n");
+            vesEvent = new PnfRegistration;
+            break;
+         }
+      case VesEventType::FAULT_NOTIFICATION:
+         O1_LOG("O1 VES : send VES fault notification\n");
+         break;
+      case VesEventType::PM_NOTIFICATION:
+         O1_LOG("O1 VES : send VES pm notification\n");
+         break;
+      case VesEventType::HEARTBEAT:
+         O1_LOG("O1 VES : send VES heartbeat \n");
+         break;
+      default:
+         O1_LOG("O1 VES : send VES msg Type is not avilable\n");
+         ret = false;
+         break;
+   }
+   if(!vesEvent->prepare()) {
+      O1_LOG("O1 VES : could not send VES Event\n");
+      ret = false;
+   }
+   else if (!vesEvent->send()) {
+      O1_LOG("O1 VES : could not send VES Event\n");
+      ret = false;
+   }
+   delete vesEvent;
+   return ret;
+}
+/**********************************************************************
+  End of file
+ **********************************************************************/
diff --git a/src/o1/ves/VesEventHandler.hpp b/src/o1/ves/VesEventHandler.hpp
new file mode 100644 (file)
index 0000000..614967a
--- /dev/null
@@ -0,0 +1,44 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020-2021] [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 functions to support the preparation of Common Header part of VES Event*/
+
+
+#ifndef __VES_EVENT_HANDLER_HPP__
+#define __VES_EVENT_HANDLER_HPP__
+
+#include <iostream>
+#include <stdio.h>
+#include "VesUtils.hpp"
+#include "VesEvent.hpp"
+
+class VesEventHandler
+{
+
+   public:
+      /* Default constructor/Destructor*/
+      VesEventHandler(){}
+      ~VesEventHandler(){}
+      bool send(VesEventType evtType);
+
+};
+
+#endif
+/**********************************************************************
+  End of file
+ **********************************************************************/
diff --git a/src/o1/ves/VesUtils.hpp b/src/o1/ves/VesUtils.hpp
new file mode 100644 (file)
index 0000000..a86d72b
--- /dev/null
@@ -0,0 +1,91 @@
+/*******************************************************************************
+################################################################################
+#   Copyright (c) [2020-2021] [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 message handling functionality for DU APP */
+
+#ifndef __VES_UTILS_HPP__
+#define __VES_UTILS_HPP__
+
+#include <iostream>
+#include "GlobalDefs.hpp"
+
+//config file path
+#define NETCONF_CONFIG "config/netconfConfig.json"
+#define VES_CONFIG "config/vesConfig.json"
+
+//Common Header Macros
+
+//Event Type
+#define EVENT_TYPE_5G "EventType5G"
+#define EVENT_TYPE_ORAN_COMPONENET "O_RAN_COMPONENT"
+#define EVENT_TYPE_CONTROLLER "Controller"
+
+//Priority
+#define PRIORITY_LOW "Low"
+#define PRIORITY_HIGH "High"
+
+//Source Name
+#define ODU_HIGH "ODU-High"
+
+//Naming Code 
+#define NAMING_CODE_ODU "7odu"
+
+//Timezone Offset
+#define TIME_ZONE_00_00 "+00:00"
+
+//version
+#define VERSION_4_0_1 "4.0.1"
+
+//Ves Event Listener Version
+#define VES_EVENT_LISTENER_7_2_1 "7.2.1"
+
+
+
+//PNF Registration Macros
+#define PNF_REGISTRATION_VERSION_2_1 "2.1"
+#define SOFTWARE_VERSION_2_3_5 "2.3.5"
+#define UNIT_TYPE_7DEV "7DEV"
+#define VENDER_NAME_VENDORB "VENDORB"
+#define MODEL_NUMBER_007_DEV "007DEV"
+
+
+//Additional fields macros for PNF Registration
+
+#define NETCONF_DEFAULT_PORT "830"
+#define NETCONF_PROTOCOL_SSH "SSH"
+#define RECONNECT_ON_SCHEMA_CHANGE_FALSE "false"
+#define SLEEP_FACTOR_1_5 "1.5"
+#define TCP_ONLY_FALSE "false"
+#define CONNECTION_TIMEOUT_20000 "20000"
+#define MAX_CONNECTION_ATTEMPTS_100 "100"
+#define BETWEEN_ATTEMPTS_TIMEOUT_2000 "2000"
+#define KEEPALIVE_DELAY_120 "120"
+
+enum class VesEventType
+{ 
+   PNF_REGISTRATION,
+   FAULT_NOTIFICATION,
+   PM_NOTIFICATION,
+   HEARTBEAT
+};
+
+
+#endif
+/**********************************************************************
+  End of file
+ **********************************************************************/