From b85b99f4675173c33e39787be1ceec428cefd51c Mon Sep 17 00:00:00 2001 From: Vidhu Date: Thu, 19 Nov 2020 15:04:04 +0530 Subject: [PATCH] Get alarm-list implementation.[Issue-Id: ODUHIGH-230] Signed-off-by: Vidhu Change-Id: I0fdbfc5c8ecffa86f0e7d1c6b82db120e3d5135c --- build/common/du_app.mak | 1 + build/common/o1.mak | 55 +++++++ build/common/o1_client.mak | 53 ++++++ build/o1/install_lib.sh | 245 +++++++++++++++++++++++++++ build/o1/makefile | 126 ++++++++++++++ build/o1/yang/o-ran-sc-odu-alarm-v1.yang | 89 ++++++++++ build/odu/makefile | 7 + docs/README | 54 +++++- src/du_app/du_msg_hdl.c | 17 ++ src/o1/Alarm.hpp | 194 ++++++++++++++++++++++ src/o1/Alarm3GPPYangModel.cpp | 84 ++++++++++ src/o1/Alarm3GPPYangModel.hpp | 48 ++++++ src/o1/AlarmManager.cpp | 103 ++++++++++++ src/o1/AlarmManager.hpp | 58 +++++++ src/o1/AlarmOranYangModel.cpp | 81 +++++++++ src/o1/AlarmOranYangModel.hpp | 46 ++++++ src/o1/GlobalDefs.cpp | 29 ++++ src/o1/GlobalDefs.hpp | 50 ++++++ src/o1/NetconfManager.cpp | 149 +++++++++++++++++ src/o1/NetconfManager.hpp | 62 +++++++ src/o1/O1_main.cpp | 68 ++++++++ src/o1/SessionHandler.cpp | 123 ++++++++++++++ src/o1/SessionHandler.hpp | 54 ++++++ src/o1/Singleton.hpp | 78 +++++++++ src/o1/TcpServer.cpp | 275 +++++++++++++++++++++++++++++++ src/o1/TcpServer.hpp | 56 +++++++ src/o1/o1_client/Alarm.h | 86 ++++++++++ src/o1/o1_client/AlarmInterface.c | 131 +++++++++++++++ src/o1/o1_client/AlarmInterface.h | 41 +++++ src/o1/o1_client/GlobalDefs.h | 40 +++++ src/o1/o1_client/TcpClient.c | 132 +++++++++++++++ src/o1/o1_client/TcpClient.h | 34 ++++ 32 files changed, 2665 insertions(+), 4 deletions(-) create mode 100755 build/common/o1.mak create mode 100644 build/common/o1_client.mak create mode 100644 build/o1/install_lib.sh create mode 100644 build/o1/makefile create mode 100644 build/o1/yang/o-ran-sc-odu-alarm-v1.yang create mode 100644 src/o1/Alarm.hpp create mode 100644 src/o1/Alarm3GPPYangModel.cpp create mode 100644 src/o1/Alarm3GPPYangModel.hpp create mode 100644 src/o1/AlarmManager.cpp create mode 100644 src/o1/AlarmManager.hpp create mode 100644 src/o1/AlarmOranYangModel.cpp create mode 100644 src/o1/AlarmOranYangModel.hpp create mode 100644 src/o1/GlobalDefs.cpp create mode 100644 src/o1/GlobalDefs.hpp create mode 100644 src/o1/NetconfManager.cpp create mode 100644 src/o1/NetconfManager.hpp create mode 100644 src/o1/O1_main.cpp create mode 100644 src/o1/SessionHandler.cpp create mode 100644 src/o1/SessionHandler.hpp create mode 100644 src/o1/Singleton.hpp create mode 100644 src/o1/TcpServer.cpp create mode 100644 src/o1/TcpServer.hpp create mode 100644 src/o1/o1_client/Alarm.h create mode 100644 src/o1/o1_client/AlarmInterface.c create mode 100644 src/o1/o1_client/AlarmInterface.h create mode 100644 src/o1/o1_client/GlobalDefs.h create mode 100644 src/o1/o1_client/TcpClient.c create mode 100644 src/o1/o1_client/TcpClient.h diff --git a/build/common/du_app.mak b/build/common/du_app.mak index d194a0eab..ca0a07d86 100644 --- a/build/common/du_app.mak +++ b/build/common/du_app.mak @@ -40,6 +40,7 @@ I_OPTS+=-I$(ROOT_DIR)/src/codec_utils/common I_OPTS+=-I$(ROOT_DIR)/src/codec_utils/F1AP I_OPTS+=-I$(ROOT_DIR)/src/codec_utils/RRC I_OPTS+=-I$(ROOT_DIR)/src/codec_utils/E2AP +I_OPTS+=-I$(ROOT_DIR)/src/o1/o1_client #-------------------------------------------------------------# #Linker macros diff --git a/build/common/o1.mak b/build/common/o1.mak new file mode 100755 index 000000000..e3acf5462 --- /dev/null +++ b/build/common/o1.mak @@ -0,0 +1,55 @@ +################################################################################ +# 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) + +ROOT_DIR=$(patsubst %/build/o1,%,$(BUILD_DIR)) + +SRC_DIR=$(ROOT_DIR)/src/o1/ +CPP_SRCS=$(wildcard $(SRC_DIR)/*.cpp) +CPP_OBJS=$(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(CPP_SRCS)) + +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 +I_OPTS=-I$(ROOT_DIR)/src/o1/ +I_OPTS+=-I$(ROOT_DIR)/src/o1/o1_client + +#-------------------------------------------------------------# +#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/common/o1_client.mak b/build/common/o1_client.mak new file mode 100644 index 000000000..f3b553561 --- /dev/null +++ b/build/common/o1_client.mak @@ -0,0 +1,53 @@ +################################################################################ +# 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 client + +include ../common/rsys_fancy.mak +include ../common/env.mak +COLOR=$(COLOR_RED) + +SRC_DIR=$(ROOT_DIR)/src/o1/o1_client +C_SRCS=$(wildcard $(SRC_DIR)/*.c) +C_OBJS=$(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(C_SRCS)) + +lib: $(LIB_DIR)/libo1client.a +include $(COM_BUILD_DIR)/compile.mak + +L_OPTS=-lsysrepo -lyang +L_OPTS+= -lsysrepo-cpp -lyang-cpp +L_OPTS+= -lm -lpthread +I_OPTS+=-I$(ROOT_DIR)/src/o1/o1_client +I_OPTS+=-I$(ROOT_DIR)/src/cm +I_OPTS+=-I$(ROOT_DIR)/src/mt + +#-------------------------------------------------------------# +#Linker macros +#-------------------------------------------------------------# +$(LIB_DIR)/libo1client.a:$(C_OBJS) $(C_WO_PED_OBJS) + @echo -e "Creating Archive $(COLOR) $@ $(REVERT_COLOR)" + $(Q)ar -cr $(LIB_DIR)/libo1client.a $(C_OBJS) $(C_WO_PED_OBJS) + +#-------------------------------------------------------------# +#Clean macros +#-------------------------------------------------------------# +clean: + @echo -e "$(COLOR_RED)Cleaning O1 Client$(REVERT_COLOR)" + $(Q)\rm -f $(LIB_DIR)/libo1client.a $(C_OBJS) $(C_WO_PED_OBJS) $(LOG_FILES) $(BAK_FILES) + +#********************************************************************** +# End of file +#********************************************************************** diff --git a/build/o1/install_lib.sh b/build/o1/install_lib.sh new file mode 100644 index 000000000..f807ba35d --- /dev/null +++ b/build/o1/install_lib.sh @@ -0,0 +1,245 @@ +################################################################################ +# 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. # +################################################################################ + +#!/bin/bash + +# Pre-requisite script for installing Netconf Libraries +# and compiling the O1 module + +#variable declaration +CURRENT_PATH=`pwd` +HOME="$CURRENT_PATH/../.." +MAKE_PATH="$HOME/build/o1" +NETCONF_PATH="$HOME/build/o1/netconf" +SYSREPOCTL_PATH="$NETCONF_PATH/sysrepo/build/sysrepoctl" +YANG_PATH="$HOME/build/o1/yang" + +INSTALL="netconf" +CLEANUP="no" +SUDO="sudo" + +#logging functions +log_error(){ + echo "" + echo -e "\e[1;31m ***** $1 ***** \e[0m" + echo "" +} +log_warning() { + echo "" + echo -e "\e[1;35m ***** $1 ***** \e[0m" + echo "" +} +log_success() { + echo "" + echo -e "\e[1;32m ***** $1 ***** \e[0m" + echo "" +} +log() { + echo -e "$1 " +} + + + +#functions definitions +#TBD: install only mandatory packages + +#install pre-requisite packages + +prerequisite_netconf() { + $SUDO apt-get update + + $SUDO apt-get install -y jq \ + cmake \ + build-essential \ + supervisor \ + libpcre3-dev \ + pkg-config \ + libavl-dev \ + libev-dev \ + libprotobuf-c-dev \ + protobuf-c-compiler \ + libssh-dev \ + libssl-dev \ + swig \ + iputils-ping \ + python-dev +} + +#check return value +check_ret() { + + if [ $2 -eq 0 ]; then + log_success " $1 INSTALLATION DONE" + else + log_error " $1 INSTALLATION FAILED " + show_help + fi +} + + +#install netconf libraries +install_netconf_lib() { + + #with sudo we can not create new user so we need to create it manually using + #root credentials. + + #$SUDO adduser --system netconf && \ + # echo "netconf:netconf" | chpasswd + + #$SUDO mkdir -p /home/netconf/.ssh && \ + # ssh-keygen -A && \ + # ssh-keygen -t dsa -P '' -f /home/netconf/.ssh/id_dsa && \ + # cat /home/netconf/.ssh/id_dsa.pub > /home/netconf/.ssh/authorized_keys + + if [[ "$CLEANUP" == "cleanup" ]]; then + rm -rf $NETCONF_PATH + log_warning "DELETED $NETCONF_PATH" + fi + + mkdir -p $NETCONF_PATH + + #1. libssh + cd $NETCONF_PATH && \ + git clone http://git.libssh.org/projects/libssh.git && \ + cd libssh; mkdir build; cd build && \ + cmake .. && \ + make && \ + $SUDO make install + + check_ret "LIBSSH" "$?" + + # libyang + cd $NETCONF_PATH && \ + git clone https://github.com/CESNET/libyang.git && \ + cd libyang && mkdir build && cd build && \ + cmake -DGEN_LANGUAGE_BINDINGS=ON -DGEN_PYTHON_BINDINGS=OFF \ + -DCMAKE_BUILD_TYPE:String="Debug" -DENABLE_BUILD_TESTS=OFF .. && \ + make -j2 && \ + $SUDO make install && \ + $SUDO ldconfig + + check_ret "LIBYANG" "$?" + + # sysrepo + cd $NETCONF_PATH && \ + git clone https://github.com/sysrepo/sysrepo.git && \ + cd sysrepo && sed -i -e 's/2000/30000/g;s/5000/30000/g' src/common.h.in && \ + mkdir build && cd build && \ + cmake -DGEN_LANGUAGE_BINDINGS=ON -DGEN_PYTHON_BINDINGS=OFF \ + -DCMAKE_BUILD_TYPE:String="Debug" -DENABLE_TESTS=OFF \ + -DREPOSITORY_LOC:PATH=/etc/sysrepo .. && \ + make -j2 && \ + $SUDO make install && $SUDO make sr_clean && \ + $SUDO ldconfig + + check_ret "SYSREPO" "$?" + + # libnetconf2 + cd $NETCONF_PATH && \ + git clone https://github.com/CESNET/libnetconf2.git && \ + cd libnetconf2 && mkdir build && cd build && \ + cmake -DCMAKE_BUILD_TYPE:String="Debug" -DENABLE_BUILD_TESTS=OFF .. && \ + make -j2 && \ + $SUDO make install && \ + $SUDO ldconfig + + check_ret "LIBNETCONF2" "$?" + + # netopeer2 + cd $NETCONF_PATH && \ + git clone https://github.com/CESNET/Netopeer2.git && \ + cd Netopeer2 && mkdir build && cd build && \ + cmake -DCMAKE_BUILD_TYPE:String="Debug" -DNP2SRV_DATA_CHANGE_TIMEOUT=30000 \ + -DNP2SRV_DATA_CHANGE_WAIT=OFF .. && \ + make -j2 && \ + $SUDO make install -d + check_ret "NETOPEER2" "$?" + +} + +#install yang module + +install_yang_module() { + $SYSREPOCTL_PATH -i "$YANG_PATH/o-ran-sc-du-alarm-v1.yang" +} + + +#wait for ack of user +acknowledge() { + echo "$1" + read -n 1 -p "Press any key to continue, or CTRL+C to abort" mainmenuinout + echo + } + +#show help for user to provide valid input +show_help(){ + echo "use -c option for cleanup" + echo "ex : $./install_netconf.sh -c" + exit +} + +main() { + + unset INSTALL CLEANUP + while (( "$#" )); do + case "$1" in + -h|\?) + show_help + shift + exit 0 + ;; + -c) CLEANUP="cleanup" + shift + ;; + esac + done + + shift $((OPTIND-1)) + + [ "${1:-}" = "--" ] && shift + + log_success "MAIN: PARSING OF ARGUMENT DONE" + +} + +#start execution / function calls +if [[ "$#" -ge 2 ]] ; then + log_error " NUMBER OF PARAMETER : $# " + show_help +fi + +main $@ + +prerequisite_netconf + +install_netconf_lib + +#yang installation yet not enabled +if [[ "$INSTALL" == "yang" ]] ; then +{ + log " YANG INSTALLATION PROCESSING " + install_yang_module + log_success " YANG INSTALLATION DONE " +} +fi + + +log_success " SCRIPT COMPLETED" +exit + +#********************************************************************** +# End of file +#********************************************************************** diff --git a/build/o1/makefile b/build/o1/makefile new file mode 100644 index 000000000..ff985aff5 --- /dev/null +++ b/build/o1/makefile @@ -0,0 +1,126 @@ +################################################################################ +# 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. # +################################################################################ + +# Master makefile for O1 module + +# Identify the location our software which is used by rest +# of the build scripts + +include ../common/rsys_fancy.mak +include ../common/env.mak + +ROOT_DIR=$(patsubst %/build/o1,%,$(BUILD_DIR)) +RULE=$(COLOR_RED) +OPTS=$(COLOR_GREEN) +NORM=$(REVERT_COLOR) + +# For improved speed +CPUINFO=`cat /proc/cpuinfo | grep processor| wc -l` +ifeq ($(CPUINFO), 1) + NUM_PARALLEL=1 +else + NUM_PARALLEL=$(shell echo $(CPUINFO) - 1 |bc) +endif + +ifeq ($(FAST), 1) + NUM_PARALLEL=$(shell echo $(CPUINFO) + 2 |bc) +endif + +PARALLEL_COMP=-j $(NUM_PARALLEL) + +# Different options to O1 build +# # Other apsects of tool chain set here +# # These should be made available appropriately to the builds +ifeq ($(MACHINE),BIT64) +CC =gcc -m64 +CCPP =g++ -m64 +else +CC =gcc -m32 +CCPP =g++ -m32 +endif + +CC1= $(CC) +CCPP1= $(CCPP) + + +# The include options get merged with the options needed by +# # the called makefiles and hence we export these to make them +# # available to them. +BUILD=i686-linux + +# The called makefiles depend on these macros and these need to be exported +export PLTFRM +export PLTFRM_FLAGS +export BUILD +export I_OPTS + +# Add to the linker options the platform specific components +#L_OPTS+=-lnsl -lrt -lm -lpthread -lsctp +L_OPTS=-lsysrepo -lyang +L_OPTS+= -lsysrepo-cpp -lyang-cpp +L_OPTS+= -lm -lpthread + +# Export some of the flags expected from the command line. +# # These macros are made available for the makefiles called from this makefile +export MACHINE + +help: + @echo -e "******************************************************************" + @echo -e "BUILD COMMAND DESCRIPTION " + @echo -e "------------------------------------------------------------------" + @echo -e "$(RULE)o1 - Builds all components of O1$(NORM)" + @echo -e "$(RULE)clean_o1 - clean up O1$(NORM)" + @echo -e "$(RULE)clean_all - cleanup O1 and all directories$(NORM)" + @echo -e "$(OPTS) options: $(NORM)" + @echo -e "$(OPTS) MACHINE=BIT64/BIT32 - Default is BIT32$(NORM)" + @echo -e "******************************************************************" + +prepare_dirs: + $(Q)echo -e "Preparing directories for build..." + $(Q)mkdir -p $(BUILD_DIR)/obj/o1 + $(Q)mkdir -p $(LIB_ROOT)/o1 + $(Q)mkdir -p $(BIN_DIR)/o1 + $(Q)echo -e "Directories are successfully prepared" + +o1_mod: + $(Q)$(MAKE) -f $(COM_BUILD_DIR)/o1.mak OBJ_DIR=$(OBJ_ROOT)/o1 LIB_DIR=$(LIB_ROOT)/o1 LOG_DIR=$(LOG_ROOT)/o1 CC='$(CCPP1)' + +link_o1: o1_mod + $(Q)$(CCPP1) -g -o $(OBJ_ROOT)/o1/o1 -Wl,-R../lib/:. $(OBJ_ROOT)/o1/*.o\ + $(L_OPTS) -L$(LIB_ROOT)/o1 + +clean_o1: + $(Q)$(MAKE) -f $(COM_BUILD_DIR)/o1.mak clean OBJ_DIR=$(OBJ_ROOT)/o1 LIB_DIR=$(LIB_ROOT)/o1 LOG_DIR=$(LOG_ROOT)/o1 CC='$(CC1)' + $(Q)rm -rf $(OBJ_ROOT)/o1/* + $(Q)rm -rf $(LIB_ROOT)/o1/* + $(Q)rm -rf $(BIN_DIR)/o1/* + $(Q)echo -e "***** O1 CLEAN COMPLETE *****" + +clean_all: clean_o1 + $(Q)rm -rf $(OBJ_ROOT) + $(Q)rm -rf $(LIB_ROOT) + $(Q)rm -rf $(LOG_ROOT) + $(Q)rm -rf $(BIN_DIR) + +copy_build: link_o1 + $(Q)cp -f ./obj/o1/o1 ./bin/o1 + $(Q)echo -e "***** O1 BUILD COMPLETE *****" + +o1: prepare_dirs copy_build + +#********************************************************************** +# End of file +#********************************************************************** diff --git a/build/o1/yang/o-ran-sc-odu-alarm-v1.yang b/build/o1/yang/o-ran-sc-odu-alarm-v1.yang new file mode 100644 index 000000000..10a72255c --- /dev/null +++ b/build/o1/yang/o-ran-sc-odu-alarm-v1.yang @@ -0,0 +1,89 @@ +module o-ran-sc-odu-alarm-v1 { + yang-version 1; + namespace "urn:o-ran:odu:alarm:1.0"; + prefix rxad; + + organization + "O-RAN Software Community"; + contact + "www.o-ran.org"; + description + "This module defines active alarm information visible to operators + + Copyright 2020 the O-RAN Alliance. + + Licensed under the Apache License, Version 2.0 (the 'License'); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an 'AS IS' BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License."; + + revision 2020-01-29 { + description + "initial revision"; + reference + "O-RAN-OAM-Interface-Specification (O1)"; + } + + grouping alarm-info { + leaf alarm-id { + type string; + description + "The unique alarm ID"; + } + leaf resource { + type string; + description + "The alarm 'resource' which is + basically the xpath to the entity + which raises the alarm and the + alarm-type-qualifier, which can be + in our case a static string for all + the alarms, e.g. 'O-RAN-SC:O-DU'."; + } + leaf alarm-text { + type string; + description + "The detailed text of the alarm"; + } + leaf severity { + type string; + description + "The severity of the alarm"; + } + leaf status { + type string; + description + "The status of the alarm"; + } + leaf additional-info { + type string; + description + "Additional info about the alarm"; + } + description + "Alarm information"; + } + + container odu { + container alarms { + config false; + list alarm { + key "alarm-id"; + uses alarm-info; + description + "The list of active alarms in RIC"; + } + description + "State data container of the alarms"; + } + description + "Root object for RIC alarms"; + } +} diff --git a/build/odu/makefile b/build/odu/makefile index f4cea2960..46ea9992d 100644 --- a/build/odu/makefile +++ b/build/odu/makefile @@ -84,6 +84,10 @@ ifeq ($(NODE),TEST_STUB) PLTFRM_FLAGS+=-DODU_TEST_STUB endif +ifeq ($(O1_ENABLE),YES) + PLTFRM_FLAGS+=-DO1_ENABLE +endif + # The include options get merged with the options needed by # # the called makefiles and hence we export these to make them # # available to them. @@ -135,6 +139,7 @@ export OAM_ENABLE export CNM_ENABLE export TEXT_LOG export CA_ENABLE +export O1_ENABLE help: @echo -e "******************************************************************" @@ -189,6 +194,7 @@ du: $(Q)$(MAKE) -f $(COM_BUILD_DIR)/mt.mak OBJ_DIR=$(OBJ_ROOT)/odu LIB_DIR=$(LIB_ROOT)/odu LOG_DIR=$(LOG_ROOT)/odu CC='$(CC1)' $(Q)$(MAKE) -f $(COM_BUILD_DIR)/rl.mak OBJ_DIR=$(OBJ_ROOT)/odu LIB_DIR=$(LIB_ROOT)/odu LOG_DIR=$(LOG_ROOT)/odu CC='$(CC1)' $(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)' + $(Q)$(MAKE) -f $(COM_BUILD_DIR)/o1_client.mak OBJ_DIR=$(OBJ_ROOT)/odu LIB_DIR=$(LIB_ROOT)/odu LOG_DIR=$(LOG_ROOT)/odu CC='$(CC1)' link_du: du $(Q)$(CC1) -g -o $(OBJ_ROOT)/odu/odu -Wl,-R../lib/:. $(OBJ_ROOT)/odu/*.o\ @@ -207,6 +213,7 @@ clean_odu: $(Q)$(MAKE) -f $(COM_BUILD_DIR)/mt.mak clean OBJ_DIR=$(OBJ_ROOT)/odu LIB_DIR=$(LIB_ROOT)/odu LOG_DIR=$(LOG_ROOT)/odu CC='$(CC1)' $(Q)$(MAKE) -f $(COM_BUILD_DIR)/rl.mak clean OBJ_DIR=$(OBJ_ROOT)/odu LIB_DIR=$(LIB_ROOT)/odu LOG_DIR=$(LOG_ROOT)/odu CC='$(CC1)' $(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)' + $(Q)$(MAKE) -f $(COM_BUILD_DIR)/o1_client.mak clean OBJ_DIR=$(OBJ_ROOT)/odu LIB_DIR=$(LIB_ROOT)/odu LOG_DIR=$(LOG_ROOT)/odu CC='$(CC1)' $(Q)rm -rf $(OBJ_ROOT)/odu/* $(Q)rm -rf $(LIB_ROOT)/odu/* $(Q)rm -rf $(BIN_DIR)/odu/* diff --git a/docs/README b/docs/README index 9201a8e06..64549437f 100644 --- a/docs/README +++ b/docs/README @@ -4,10 +4,11 @@ Directory Structure : a. common : contains individual module's makefile b. odu : contains main makefile to generate an executable binary c. scripts: contains scripts for logging + d. o1 : contains main makefile to generate an executable binary 2. l2/docs/ : contains README and other configuration files for building docs -2. l2/src/ : contains layer specific source code +3. l2/src/ : contains layer specific source code a. 5gnrmac : MAC source code b. 5gnrrlc : RLC source code c. cm : common, environment and interface files @@ -16,6 +17,7 @@ Directory Structure : f. mt : wrapper functions over OS g. phy_stub : Stub code for Physical layer h. rlog : logging module + i. o1 : o1 module Pre-requisite for Compilation : @@ -30,6 +32,30 @@ Pre-requisite for Compilation : b. On CentOS : yum install libpcap-devel +Pre-requisite for running O1 module: +----------------------------------- +Install netconf server +---------------------- + +1. Create new netconf user (login with root user and run following command) + $adduser --system netconf && \ + echo "netconf:netconf" | chpasswd + + $mkdir -p /home/netconf/.ssh && \ + ssh-keygen -A && \ + ssh-keygen -t dsa -P '' -f /home/netconf/.ssh/id_dsa && \ + cat /home/netconf/.ssh/id_dsa.pub > /home/netconf/.ssh/authorized_keys +2. Install netconf packages. + $cd l2/build/o1/ + $chmod +x install_lib.sh + $ ./install_lib.sh + +Install the yang module +----------------------- +1. cd l2/build/o1/yang + sysrepoctl -i o-ran-sc-odu-alarm-v1.yang + + How to Clean and Build: ----------------------- 1. Building ODU binary: @@ -37,6 +63,10 @@ How to Clean and Build: cd l2/build/odu b. Building ODU binary make odu MACHINE=BIT64 MODE=FDD + + Build with O1 module enabled: + make odu MACHINE=BIT64 MODE=FDD O1_ENABLE=YES + c. Cleaning ODU binary make clean_odu MACHINE=BIT64 MODE=FDD @@ -48,7 +78,7 @@ How to Clean and Build: c. Cleaning CU Stub binary make clean_cu NODE=TEST_STUB MACHINE=BIT64 MODE=FDD -2. Building RIC Stub binary: +3. Building RIC Stub binary: a. Build folder cd l2/build/odu b. Building RIC Stub binary @@ -59,6 +89,15 @@ How to Clean and Build: 4. Cleaning ODU, CU Stub and RIC Stub: make clean_all +5. Building O1 binary: + a. Build folder + cd l2/build/o1 + b. Building O1 binary + make o1 MACHINE=BIT64 + c. Cleaning O1 binary + make clean_o1 + + How to execute: --------------- 1. Assign virtual IP addresses as follows: @@ -78,10 +117,17 @@ How to execute: 5. Run RIC Stub binary: ./ric_stub -4. DU execution folder: +6. DU execution folder: cd l2/bin/odu -5. Run ODU binary: +7. Run ODU binary: ./odu +8. O1 execution folder: + cd l2/build/o1/bin/o1 + +9. Run O1 binary: + ./o1 + PS: CU stub and RIC stub must be run (in no particular sequence) before ODU + If O1 module is enabled it must be run before ODU diff --git a/src/du_app/du_msg_hdl.c b/src/du_app/du_msg_hdl.c index e29be4088..b1424da90 100644 --- a/src/du_app/du_msg_hdl.c +++ b/src/du_app/du_msg_hdl.c @@ -40,6 +40,13 @@ #include "du_utils.h" #include "du_cell_mgr.h" +#ifdef O1_ENABLE + +#include "GlobalDefs.h" +#include "AlarmInterface.h" + +#endif + uint8_t rlcDlCfg = 0; uint8_t numRlcDlSaps = 0; uint8_t rlcUlCfg = 0; @@ -1651,6 +1658,11 @@ uint8_t duHandleSlotInd(Pst *pst, SlotIndInfo *slotInfo) { DU_LOG("\nDU APP : 5G-NR Cell %d is UP", slotInfo->cellId); cellCb->cellStatus = ACTIVATED; + +#ifdef O1_ENABLE + DU_LOG("\nDU APP : Raise cell UP alarm for cell id=%d", slotInfo->cellId); + raiseCellAlrm(CELL_UP_ALARM_ID, slotInfo->cellId); +#endif } } @@ -1785,6 +1797,11 @@ uint8_t duHandleStopInd(Pst *pst, MacCellStopInfo *cellStopId) { DU_LOG("\nDU APP : 5G-NR Cell %d is DOWN", cellStopId->cellId); cellCb->cellStatus = DELETION_IN_PROGRESS; + +#ifdef O1_ENABLE + DU_LOG("\nDU APP : Raise cell down alarm for cell id=%d", cellStopId->cellId); + raiseCellAlrm(CELL_DOWN_ALARM_ID, cellStopId->cellId); +#endif } } if((pst->selector == ODU_SELECTOR_LWLC) || (pst->selector == ODU_SELECTOR_TC)) diff --git a/src/o1/Alarm.hpp b/src/o1/Alarm.hpp new file mode 100644 index 000000000..ced49d0b1 --- /dev/null +++ b/src/o1/Alarm.hpp @@ -0,0 +1,194 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains Alarm class defining Netconf Yang based alarm fields */ + +#ifndef __ALARM_HPP__ +#define __ALARM_HPP__ + +#include +#include +#include "Alarm.h" + +using std::string; + + +class Alarm +{ + + private: + EventType mEventType; + string mObjectClassObjectInstance; + uint16_t mAlarmId; + string mAlarmRaiseTime; + string mAlarmChangeTime; + string mAlarmClearTime; + string mProbableCause; + SeverityLevel mPerceivedSeverity; + string mRootCauseIndicator; + string mAdditionalText; + string mAdditionalInfo; + string mSpecificProblem; + + public: + Alarm(){}; + ~Alarm(){}; + /* Getter functions */ + inline const EventType& getEventType()const + { + return mEventType; + } + inline const string& getObjectClassObjectInstance()const + { + return mObjectClassObjectInstance; + } + inline const uint16_t& getAlarmId()const + { + return mAlarmId; + } + inline const string& getAlarmRaiseTime()const + { + return mAlarmRaiseTime; + } + inline const string& getAlarmChangeTime()const + { + return mAlarmChangeTime; + } + inline const string& getAlarmClearTime()const + { + return mAlarmClearTime; + } + inline const string& getProbableCause()const + { + return mProbableCause; + } + inline const SeverityLevel getPerceivedSeverity()const + { + return mPerceivedSeverity; + } + inline const string getRootCauseIndicator()const + { + return mRootCauseIndicator; + } + inline const string getAdditionalText()const + { + return mAdditionalText; + } + inline const string getAdditionalInfo()const + { + return mAdditionalInfo; + } + inline const string getSpecificProblem()const + { + return mSpecificProblem; + } + + /* Setter functions */ + inline void setEventType(const EventType& eventType) + { + mEventType = eventType; + } + inline void setObjectClassObjectInstance(const string& objectClassObjectInstance ) + { + mObjectClassObjectInstance = objectClassObjectInstance; + } + inline void setObjectClassObjectInstance(const char* objectClassObjectInstance ) + { + mObjectClassObjectInstance = objectClassObjectInstance; + } + inline void setAlarmId(const uint16_t& alarmId) + { + mAlarmId = alarmId; + } + inline void setAlarmRaiseTime(const string& alarmRaiseTime) + { + mAlarmRaiseTime = alarmRaiseTime; + } + inline void setAlarmRaiseTime(const char* alarmRaiseTime) + { + mAlarmRaiseTime = alarmRaiseTime; + } + inline void setAlarmChangeTime(const string& alarmChangeTime) + { + mAlarmChangeTime = alarmChangeTime; + } + inline void setAlarmChangeTime(const char* alarmChangeTime) + { + mAlarmChangeTime = alarmChangeTime; + } + inline void setAlarmClearTime(const string& alarmClearTime) + { + mAlarmClearTime = alarmClearTime; + } + inline void setAlarmClearTime(const char* alarmClearTime) + { + mAlarmClearTime = alarmClearTime; + } + inline void setProbableCause(const string& probableCause) + { + mProbableCause = probableCause; + } + inline void setProbableCause(const char* probableCause) + { + mProbableCause = probableCause; + } + inline void setPerceivedSeverity(const SeverityLevel& perceivedSeverity) + { + mPerceivedSeverity = perceivedSeverity; + } + inline void setRootCauseIndicator(const string& rootCauseIndicator) + { + mRootCauseIndicator = rootCauseIndicator; + } + inline void setRootCauseIndicator(const char* rootCauseIndicator) + { + mRootCauseIndicator = rootCauseIndicator; + } + inline void setAdditionalText(const string& additionalText) + { + mAdditionalText = additionalText; + } + inline void setAdditionalText(const char* additionalText) + { + mAdditionalText = additionalText; + } + inline void setAdditionalInfo(const string& additionalInfo) + { + mAdditionalInfo = additionalInfo; + } + inline void setAdditionalInfo(const char* additionalInfo) + { + mAdditionalInfo = additionalInfo; + } + inline void setSpecificProblem(const string& specificProblem) + { + mSpecificProblem = specificProblem; + } + inline void setSpecificProblem(const char* specificProblem) + { + mSpecificProblem = specificProblem; + } + + +}; + +#endif + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/Alarm3GPPYangModel.cpp b/src/o1/Alarm3GPPYangModel.cpp new file mode 100644 index 000000000..42915a5b6 --- /dev/null +++ b/src/o1/Alarm3GPPYangModel.cpp @@ -0,0 +1,84 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains Alarm Yang model data filling and sending related methods */ + +#include "Alarm3GPPYangModel.hpp" + +using namespace std; + + +/********************************************************************** + Description : It is a callback function, called on get request of + alarm-list (overridden function of sysrepo::Callback ) + Params[In] : (sysrepo::S_Session, module_name, path, + request_xpath, request_id, &parent, private_data) + Return : SR_ERR_OK - success +**********************************************************************/ + +int Alarm3GPPYangModel::oper_get_items(sysrepo::S_Session session, + const char *module_name, + const char *path, + const char *request_xpath, + uint32_t request_id, + libyang::S_Data_Node &parent, + void *private_data) +{ + O1_LOG("\n\n ========== CALLBACK CALLED TO PROVIDE \" %s DATA ==========\n", path); + + libyang::S_Context ctx = session->get_context(); + libyang::S_Module mod = ctx->get_module(module_name); + + parent.reset(new libyang::Data_Node(ctx, ALARM_MODULE_PATH_3GPP, nullptr, LYD_ANYDATA_CONSTSTRING, 0)); + //read the data from map + //tree of alarmRecord : AlarmList/AlarmListGrp/alarmRecordList/AlarmRecordGrp + + libyang::S_Data_Node alarms(new libyang::Data_Node(parent, mod, "AlarmList")); + libyang::S_Data_Node alarm(new libyang::Data_Node(alarms, mod, "AlarmListGrp")); + libyang::S_Data_Node ifc3(new libyang::Data_Node(parent, mod, "alarmRecordList")); + libyang::S_Data_Node ifc4(new libyang::Data_Node(ifc3, mod, "AlarmRecordGrp")); + + + libyang::S_Data_Node id; + libyang::S_Data_Node text; + libyang::S_Data_Node severity; + libyang::S_Data_Node status; + libyang::S_Data_Node add_info; + + //read the data from map + map::const_iterator it; + + AlarmManager& alrmMgr = AlarmManager::instance(); + const map& alrmList = alrmMgr.getAlarmList(); + + for(it = alrmList.begin(); it !=alrmList.end(); it++) + { + O1_LOG("\nAlarm ID %hu", it->second.getAlarmId()); + alarm.reset(new libyang::Data_Node(alarms, mod, "alarm")); + id.reset(new libyang::Data_Node(alarm, mod, "alarm-id", to_string(it->second.getAlarmId()).c_str())); + text.reset(new libyang::Data_Node(alarm, mod, "alarm-text", it->second.getAdditionalText().c_str())); + severity.reset(new libyang::Data_Node(alarm, mod, "severity", to_string(it->second.getEventType()).c_str())); + status.reset(new libyang::Data_Node(alarm, mod, "status", it->second.getSpecificProblem().c_str())); + add_info.reset(new libyang::Data_Node(alarm, mod, "additional-info", it->second.getAdditionalInfo().c_str())); + } + return SR_ERR_OK; +} + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/Alarm3GPPYangModel.hpp b/src/o1/Alarm3GPPYangModel.hpp new file mode 100644 index 000000000..01c2363f0 --- /dev/null +++ b/src/o1/Alarm3GPPYangModel.hpp @@ -0,0 +1,48 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains Alarm Yang model data filling and sending related methods */ + +#ifndef __ALARM_3GPP_YANG_MODEL_HPP__ +#define __ALARM_3GPP_YANG_MODEL_HPP__ + +/*#include +#include +#include "sysrepo-cpp/Session.hpp" +#include "AlarmManager.hpp" +#include "GlobalDefs.hpp" +*/ + +#include "AlarmOranYangModel.hpp" + +class Alarm3GPPYangModel:public sysrepo::Callback { + public: + int oper_get_items(sysrepo::S_Session session,\ + const char *module_name,\ + const char *path,\ + const char *request_xpath,\ + uint32_t request_id,\ + libyang::S_Data_Node &parent,\ + void *private_data) override; +}; + +#endif + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/AlarmManager.cpp b/src/o1/AlarmManager.cpp new file mode 100644 index 000000000..3ed8aca7b --- /dev/null +++ b/src/o1/AlarmManager.cpp @@ -0,0 +1,103 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains AlarmManager singleton class which is responsible for + storing and managing alarms. +*/ + +#include +#include "AlarmManager.hpp" + +using std::pair; + +/* Default constructor */ +AlarmManager::AlarmManager() +{ + +} + +/* Destructor */ +AlarmManager::~AlarmManager() +{ + +} + + + +/********************************************************************** + Description : Raise an Alarm and store it in alarm list + Params[In] : Alarm + Return : true - insert in map successful + false - insert in map unsuccessful +**********************************************************************/ +bool AlarmManager::raiseAlarm(const Alarm& alarm) +{ + pair::iterator,bool> ret; + ret = mAlarmList.insert(pair(alarm.getAlarmId(),alarm)); + return ret.second; +} + + + +/********************************************************************** + Description : Clear an Alarm and delete it from alarm list + Params[In] : Alarm instance + Return : true - delete successful + false - delete unsuccessful +**********************************************************************/ +bool AlarmManager::clearAlarm(const Alarm& alarm) +{ + map::iterator it; + bool ret = false; + it = mAlarmList.find(alarm.getAlarmId()); + if( it != mAlarmList.end() ) + { + mAlarmList.erase(it); + ret = true; + } + return ret; +} + + +/********************************************************************** + Description : Clear an Alarm and delete it from alarm list with + alarmId + Params[In] : Alarm Id + Return : true - delete successful + false - delete unsuccessful +**********************************************************************/ +bool AlarmManager::clearAlarm(const uint16_t& alarmId) +{ + return (mAlarmList.erase(alarmId) > 0); +} + + +/********************************************************************** + Description : Return the list of active alarms + Params[In] : None + Return : constant reference to the map +**********************************************************************/ +const map& AlarmManager::getAlarmList()const +{ + return mAlarmList; +} + + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/AlarmManager.hpp b/src/o1/AlarmManager.hpp new file mode 100644 index 000000000..a30fa9a36 --- /dev/null +++ b/src/o1/AlarmManager.hpp @@ -0,0 +1,58 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains AlarmManager singleton class responsible for + storing and managing alarms. +*/ + +#ifndef __ALARM_MANAGER_HPP__ +#define __ALARM_MANAGER_HPP__ + +#include +#include "Alarm.hpp" +#include "Singleton.hpp" + +using std::map; + + +class AlarmManager : public Singleton +{ + + friend Singleton; + + private: + map mAlarmList; + + protected: + AlarmManager(); + ~AlarmManager(); + + public: + bool raiseAlarm(const Alarm& alarm); + bool clearAlarm(const uint16_t& alarmId); + bool clearAlarm(const Alarm& alarm ); + const map& getAlarmList()const; + +}; + + +#endif + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/AlarmOranYangModel.cpp b/src/o1/AlarmOranYangModel.cpp new file mode 100644 index 000000000..fba9f57eb --- /dev/null +++ b/src/o1/AlarmOranYangModel.cpp @@ -0,0 +1,81 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains Alarm Yang model data filling and sending related methods */ + +#include "AlarmOranYangModel.hpp" + +using namespace std; + +/********************************************************************** + Description : It is a callback function, called on get request of + alarm-list (overridden function of sysrepo::Callback ) + Params[In] : (sysrepo::S_Session, module_name, path, + request_xpath, request_id, &parent, private_data) + Return : SR_ERR_OK - success +**********************************************************************/ + +int AlarmOranYangModel::oper_get_items(sysrepo::S_Session session, \ + const char *module_name, \ + const char *path, \ + const char *request_xpath, \ + uint32_t request_id, \ + libyang::S_Data_Node &parent, \ + void *private_data) +{ + O1_LOG("\n\n ========== CALLBACK CALLED TO PROVIDE \" %s DATA ==========\n", path); + libyang::S_Context ctx = session->get_context(); + libyang::S_Module mod = ctx->get_module(module_name); + + //first create root of the tree then add nodes and leaves and fill data + parent.reset(new libyang::Data_Node(ctx, ALARM_MODULE_PATH_ORAN, nullptr, LYD_ANYDATA_CONSTSTRING, 0)); + libyang::S_Data_Node alarms(new libyang::Data_Node(parent, mod, "alarms")); + + libyang::S_Data_Node alarm; + libyang::S_Data_Node id; + libyang::S_Data_Node text; + libyang::S_Data_Node severity; + libyang::S_Data_Node status; + libyang::S_Data_Node add_info; + + //read the data from map + map::const_iterator it; + + AlarmManager& alrmMgr = AlarmManager::instance(); + const map& alrmList = alrmMgr.getAlarmList(); + char alarmId[MAX_ALARM_ID_LEN]; + + for(it = alrmList.begin(); it !=alrmList.end(); it++) + { + strcpy(alarmId, to_string(it->second.getAlarmId()).c_str()); + O1_LOG("\nAlarm ID %s",alarmId); + alarm.reset(new libyang::Data_Node(alarms, mod, "alarm")); + id.reset(new libyang::Data_Node(alarm, mod, "alarm-id", alarmId)); + text.reset(new libyang::Data_Node(alarm, mod, "alarm-text", it->second.getAdditionalText().c_str())); + severity.reset(new libyang::Data_Node(alarm, mod, "severity", to_string(it->second.getEventType()).c_str())); + status.reset(new libyang::Data_Node(alarm, mod, "status", it->second.getSpecificProblem().c_str())); + add_info.reset(new libyang::Data_Node(alarm, mod, "additional-info", it->second.getAdditionalInfo().c_str())); + } + + return SR_ERR_OK; +} + + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/AlarmOranYangModel.hpp b/src/o1/AlarmOranYangModel.hpp new file mode 100644 index 000000000..d8495afb4 --- /dev/null +++ b/src/o1/AlarmOranYangModel.hpp @@ -0,0 +1,46 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains Alarm Yang model data filling and sending related methods */ + +#ifndef __ALARM_ORAN_YANG_MODEL_HPP__ +#define __ALARM_ORAN_YANG_MODEL_HPP__ +#include +#include +#include "sysrepo-cpp/Session.hpp" +#include "AlarmManager.hpp" +#include "GlobalDefs.hpp" + + +class AlarmOranYangModel : public sysrepo::Callback { + public: + int oper_get_items(sysrepo::S_Session session,\ + const char *module_name,\ + const char *path,\ + const char *request_xpath,\ + uint32_t request_id,\ + libyang::S_Data_Node &parent,\ + void *private_data); + +}; + +#endif + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/GlobalDefs.cpp b/src/o1/GlobalDefs.cpp new file mode 100644 index 000000000..77ea38062 --- /dev/null +++ b/src/o1/GlobalDefs.cpp @@ -0,0 +1,29 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains global definitions for O1 interface modules */ + +#include "GlobalDefs.hpp" + +const short O1::TCP_PORT = 8282; +const int O1::SUCCESS = 0; +const int O1::FAILURE = 1; + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/GlobalDefs.hpp b/src/o1/GlobalDefs.hpp new file mode 100644 index 000000000..0f8d42a41 --- /dev/null +++ b/src/o1/GlobalDefs.hpp @@ -0,0 +1,50 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains global definitions for O1 interface modules */ + +#ifndef __GLOBAL_DEFS_HPP__ +#define __GLOBAL_DEFS_HPP__ + +#include + +#define O1_LOG(...) ( {\ + printf(__VA_ARGS__);\ + syslog(LOG_DEBUG,__VA_ARGS__);\ + } ) + +#define ALARM_MODULE_NAME_3GPP "_3gpp-common-fm" +#define ALARM_MODULE_PATH_3GPP "/_3gpp-common-fm:AlarmListGrp" +#define ALARM_MODULE_NAME_ORAN "o-ran-sc-odu-alarm-v1" +#define ALARM_MODULE_PATH_ORAN "/o-ran-sc-odu-alarm-v1:odu" + +#define MAX_ALARM_ID_LEN 10 + +class O1 +{ + public: + static const short TCP_PORT; + static const int SUCCESS; + static const int FAILURE; +}; + +#endif + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/NetconfManager.cpp b/src/o1/NetconfManager.cpp new file mode 100644 index 000000000..077cdfefb --- /dev/null +++ b/src/o1/NetconfManager.cpp @@ -0,0 +1,149 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This class is the netconf manager class. It will handle netopeer-server start and stop along with session handler init. Additionally it will provide the + signal handling. */ + +#include "NetconfManager.hpp" + +/* Default constructor */ +NetconfManager::NetconfManager() +{ +} + + +/* Destructor */ +NetconfManager::~NetconfManager() +{ + if( NULL != mSessHndl) + { + delete mSessHndl; + } +} + +/********************************************************************** + Description : This function will start the netopeer2-server and + redirect logs to the /etc/netopeer2-server.log file + Params[In] : void + Return : true - started successful + false - start failed +**********************************************************************/ + +bool NetconfManager::startNetopeerServer () +{ + int status = system("netopeer2-server -d -v3 > /etc/netopeer2-server.log 2>&1 &"); + if (status < 0) + { + O1_LOG("\nO1 NetconfManager : Error during netopeer server start status : %s",\ + strerror(errno)); + } + else + { + if (WIFEXITED(status)) + O1_LOG("\nO1 NetconfManager : netopeer server started normally with status : %d",\ + WEXITSTATUS(status)); + else + O1_LOG("\nO1 NetconfManager : netopeer server started abnormally with status : %d",\ + WEXITSTATUS(status)); + } + return (status == 0); +} + + +/********************************************************************** + Description : This function will stop the netopeer2-server + Params[In] : void + Return : true - started successful + false - start failed +**********************************************************************/ +bool NetconfManager::stopNetopeerServer(void) +{ + int status = system("kill -9 `pidof netopeer2-server`"); + if (status < 0) + { + O1_LOG("\nO1 NetconfManager : Error during Netopeer server stopped status : %s\n",\ + strerror(errno)); + } + else + { + if (WIFEXITED(status)) + { + O1_LOG("\nO1 NetconfManager : Netopeer server stopped normally with status : %d\n",\ + WEXITSTATUS(status)); + } + else + { + O1_LOG("\nO1 NetconfManager : Netopeer server stopped abnormally with status : %d\n",\ + WEXITSTATUS(status)); + } + } + return (status == 0); +} + + +/********************************************************************** + Description : catch and handle the SIGINT signal + Params[In] : signum + Return : void +**********************************************************************/ +void NetconfManager::sigintHandler(int signum) +{ + if (true != NetconfManager::stopNetopeerServer()) + { + O1_LOG("\nO1 NetconfManager : Error stopping Netopeer server"); + } +} + + +/********************************************************************** + Description : This function will start the netopeer2-server and + session handler + Params[In] : void + Return : true - started successful + false - start failed +**********************************************************************/ +bool NetconfManager::init(void) +{ + if(startNetopeerServer()) + { + O1_LOG("\nO1 NetconfManager : netopeer server started"); + } + + try + { + mSessHndl = new SessionHandler; + + O1_LOG("\nO1 NetconfManager : SessionHandler created "); + + if( !mSessHndl->init()) + { + O1_LOG("\nO1 NetconfManager : SessionHandler init failed "); + return false; + } + } + catch( const std::exception& e ) + { + O1_LOG("\nO1 O1_main : Exception : %s", e.what()); + return false; + } +} + + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/NetconfManager.hpp b/src/o1/NetconfManager.hpp new file mode 100644 index 000000000..213ce8c5e --- /dev/null +++ b/src/o1/NetconfManager.hpp @@ -0,0 +1,62 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This class is the netconf manager class. It creates instance of the + SessionHandler that provides connections/sessions related funtionality + and signal handling. +*/ + +#ifndef __NETCONF_MANAGER_HPP__ +#define __NETCONF_MANAGER_HPP__ + +#include "SessionHandler.hpp" +#include "Singleton.hpp" + +class NetconfManager : public Singleton +{ + + friend Singleton; + + public: + /*initialize variables*/ + bool init(); + + /*handler for netopeer server*/ + bool startNetopeerServer(void); + static bool stopNetopeerServer(void); + static void sigintHandler(int signum); + + /*getter setter for SessionHandler obj*/ + bool setSessionHandler (SessionHandler sessMgr); + SessionHandler getSessionHandler(void); + + + protected: + NetconfManager(); + ~NetconfManager(); + + private: + SessionHandler *mSessHndl; +}; + + +#endif + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/O1_main.cpp b/src/o1/O1_main.cpp new file mode 100644 index 000000000..c0ecce74f --- /dev/null +++ b/src/o1/O1_main.cpp @@ -0,0 +1,68 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains O1 main. + Starts the Netopeer and TCP server +*/ + +#include "NetconfManager.hpp" +#include "TcpServer.hpp" +#include + +/********************************************************************** + Description : Main function. Start of O1 module. + Params[In] : None + Return : EXIT_SUCCESS + : EXIT_FAILURE +**********************************************************************/ + +int main(int argc, char **argv) +{ + TcpServer tcpServer(O1::TCP_PORT); + /*SIGINT handling*/ + //signal(SIGINT, NetconfManager::sigintHandler); + /* Start Netconf server and subscribe to yang modules */ + try + { + NetconfManager::instancePtr()->init(); + O1_LOG("\nO1 O1_main : NetconfManager init successful"); + + } + catch( const std::exception& e ) + { + O1_LOG("\nO1 O1_main : Exception : %s", e.what()); + return EXIT_FAILURE; + } + /* Start the TCP Server to listen for alarm messages */ + if( tcpServer.start() ) + { + O1_LOG("\nO1 O1_main : TCP server started\n"); + /* Wait for the TcpServer thread to end*/ + tcpServer.wait(); + } + else + { + O1_LOG("\nO1 O1_main : Failed to start TCP server"); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/SessionHandler.cpp b/src/o1/SessionHandler.cpp new file mode 100644 index 000000000..f4108c003 --- /dev/null +++ b/src/o1/SessionHandler.cpp @@ -0,0 +1,123 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains methods of Session/Connection creation and Subscription to + YANG modules */ + +#include "SessionHandler.hpp" + + +/* Default constructor */ +SessionHandler::SessionHandler() +{ +} + + +/* Destructor */ +SessionHandler::~SessionHandler() +{ +} + +/********************************************************************** + Description : This function will create Connection, Session, and + subscribe. These sysrepo class provide netconf connection + related services. + Params[In] : void + Return : true - started successful + false - start failed +**********************************************************************/ +bool SessionHandler::init() +{ + try + { + mConn = createConnection(); + mSess = createSession(mConn); + mSub = createSubscribe(mSess); + O1_LOG("\nO1 SessionHandler : Initialization done"); + return true; + } + catch( const std::exception& e ) + { + O1_LOG("\nO1 SessionHandler : Exception : %s", e.what()); + return false; + } +} + +/********************************************************************** + Description : This function will create Connection instance and + return the same + Params[In] : void + Return : sysrepo::S_Connection instance +**********************************************************************/ +sysrepo::S_Connection SessionHandler::createConnection() +{ + sysrepo::S_Connection conn(new sysrepo::Connection()); + return conn; +} + + +/********************************************************************** + Description : This function will create Session instance and + return the same + Params[In] : sysrepo::S_Connection + Return : sysrepo::S_Session instance +**********************************************************************/ +sysrepo::S_Session SessionHandler::createSession(sysrepo::S_Connection conn) +{ + sysrepo::S_Session sess(new sysrepo::Session(conn)); + return sess; +} + + + +/********************************************************************** + Description : This function will create Subscribe instance and + return the same + Params[In] : sysrepo::S_Session + Return : sysrepo::S_Subscribe instance +**********************************************************************/ +sysrepo::S_Subscribe SessionHandler::createSubscribe(sysrepo::S_Session sess) +{ + sysrepo::S_Subscribe subscrb(new sysrepo::Subscribe(sess)); + if(subscribeModule(subscrb)) + { + O1_LOG("\nO1 SessionHandler : Subscription done successfully"); + } + return subscrb; +} + + +/********************************************************************** + Description : This function will create a callback object and register + it for callback. + Params[In] : sysrepo::S_Subscribe + Return : true - on success +**********************************************************************/ +bool SessionHandler::subscribeModule(sysrepo::S_Subscribe subscrb) +{ + sysrepo::S_Callback alarmOranCb(new AlarmOranYangModel()); + + subscrb->oper_get_items_subscribe(ALARM_MODULE_NAME_ORAN, \ + ALARM_MODULE_PATH_ORAN, \ + alarmOranCb); + return true; +} + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/SessionHandler.hpp b/src/o1/SessionHandler.hpp new file mode 100644 index 000000000..0e0472dab --- /dev/null +++ b/src/o1/SessionHandler.hpp @@ -0,0 +1,54 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains SessionHandler class header*/ + +#ifndef __SESSION_MANAGER_HPP__ +#define __SESSION_MANAGER_HPP__ + +#include "sysrepo-cpp/Session.hpp" +#include "Alarm3GPPYangModel.hpp" +#include "AlarmOranYangModel.hpp" + + +class SessionHandler +{ + public: + SessionHandler(); + ~SessionHandler(); + + bool init(); + + + private: + sysrepo::S_Connection mConn; + sysrepo::S_Session mSess; + sysrepo::S_Subscribe mSub; + + /*creation of Connection, Session, Subscribe obj functions*/ + bool subscribeModule(sysrepo::S_Subscribe sub); + sysrepo::S_Connection createConnection(); + sysrepo::S_Session createSession(sysrepo::S_Connection conn); + sysrepo::S_Subscribe createSubscribe(sysrepo::S_Session sess); +}; + +#endif + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/Singleton.hpp b/src/o1/Singleton.hpp new file mode 100644 index 000000000..2d618432d --- /dev/null +++ b/src/o1/Singleton.hpp @@ -0,0 +1,78 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file constains a singleton class template */ + +#ifndef __SINGLETON_HPP__ +#define __SINGLETON_HPP__ + +template +class Singleton +{ + public: + static T& instance(); + static T *instancePtr(); + + protected: + Singleton() { } + ~Singleton() { } + + private: + static T* mPtr; +}; + +/* Define and initialize the static instance pointer */ +template +T* Singleton::mPtr = 0; + + +/********************************************************************** + Description : Check if instance already exists. + Create a new instance if none exists + Params[In] : None + Return : Reference to the instance +***********************************************************************/ +template +T& Singleton::instance() +{ + + if( mPtr == 0) + mPtr = new T(); + + return *mPtr; +} + + +/********************************************************************** + Description : Check if instance already exists. + Create a new instance if none exists + Params[In] : None + Return : Pointer to the instance +***********************************************************************/ +template +T *Singleton::instancePtr() +{ + return &(instance()); +} + +#endif + +/********************************************************************** + End of file +**********************************************************************/ + diff --git a/src/o1/TcpServer.cpp b/src/o1/TcpServer.cpp new file mode 100644 index 000000000..47ce09475 --- /dev/null +++ b/src/o1/TcpServer.cpp @@ -0,0 +1,275 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains TcpServer class that listens for Netconf Alarm messages + on a TCP socket from ODU. It calls the AlarmManager functions for raising + or clearing the alarms based on the actions received +*/ + +#include "TcpServer.hpp" +#include "Alarm.hpp" +#include "AlarmManager.hpp" +#include "GlobalDefs.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using std::map; +using std::pair; + +/* Destructor */ +TcpServer::~TcpServer() +{ + +} + + +/********************************************************************** + Description : Read the data from the connected client application + Params[In] : fd - File descriptor + Return : int - No of bytes read +**********************************************************************/ +int TcpServer::readMessage(int fd) +{ + AlarmRecord alrmRec; + bzero(&alrmRec,sizeof(alrmRec)); + int nbytes = read (fd, &alrmRec, sizeof(alrmRec)); + if (nbytes > 0) + { + Alarm alrm; + uint16_t alrmId; + O1_LOG("\nO1 TcpServer :\nAction %d\nalarm ID %s\n%d\n%s\n%d\n%s\n%s\nbytes %d", + alrmRec.msgHeader.action, + alrmRec.alarmId, + alrmRec.perceivedSeverity, + alrmRec.additionalText, + alrmRec.eventType, + alrmRec.specificProblem, + alrmRec.additionalInfo, + nbytes + ); + + /*Fill the alarm structure */ + sscanf(alrmRec.alarmId,"%hu",&alrmId); + alrm.setAlarmId(alrmId); + alrm.setPerceivedSeverity(alrmRec.perceivedSeverity); + alrm.setAdditionalText(alrmRec.additionalText); + alrm.setEventType(alrmRec.eventType); + alrm.setSpecificProblem(alrmRec.specificProblem); + alrm.setAdditionalInfo(alrmRec.additionalInfo); + + switch(alrmRec.msgHeader.action) + { + case RAISE: + if(AlarmManager::instance().raiseAlarm(alrm)) + { + O1_LOG("\nO1 TcpServer : Alarm raised for alarm Id %s", alrmRec.alarmId); + } + else + { + O1_LOG("\nO1 TcpServer : Error in raising alarm for alrm Id %s", alrmRec.alarmId); + } + break; + case CLEAR: + if(AlarmManager::instance().clearAlarm(alrm)) + { + O1_LOG("\nO1 TcpServer : Alarm cleared for alarm Id %s", alrmRec.alarmId); + } + else + { + O1_LOG("\nO1 TcpServer : Error in clearing alarm for alarm Id %s", alrmRec.alarmId); + } + break; + default: + O1_LOG("\nO1 TcpServer : No action performed"); + break; + } + + } + return nbytes; +} + + +/********************************************************************** + Description : Open a TCP socket and bind on the port + Params[In] : None + Return : O1::SUCCESS - socket open and bind successful + O1::FAILURE - socket open and bind failed +**********************************************************************/ +int TcpServer::makeSocket() +{ + struct sockaddr_in name; + /* Create the socket. */ + mSock = socket (PF_INET, SOCK_STREAM, 0); + if (mSock < 0) + { + O1_LOG("\nO1 TcpServer : Socket error"); + return O1::FAILURE; + } + /* Give the socket a name. */ + bzero(&name, sizeof(name)); + name.sin_family = AF_INET; + name.sin_port = htons (mPort); + name.sin_addr.s_addr = htonl (INADDR_ANY); + if (bind (mSock, (struct sockaddr *) &name, sizeof (name)) < 0) + { + close(mSock); + O1_LOG("\nO1 TcpServer : Bind error"); + return O1::FAILURE; + } + return O1::SUCCESS; +} + + +/********************************************************************** + Description : Start TCP server in thread + Params[In] : None + Return : true - task launched in pthread successfully + false - task failed to launch +**********************************************************************/ +bool TcpServer::start() +{ + return (pthread_create(&mThreadId, NULL, task, this) == 0); +} + +/********************************************************************** + Description : A TCP server to handle multiple connection using + select multiplexing + Params[In] : None + Return : true - task launched in pthread successfully + false - task failed to launch +**********************************************************************/ +bool TcpServer::run() +{ + + fd_set active_fd_set, read_fd_set; + int i; + struct sockaddr_in clientName; + socklen_t size; + bool ret = true;; + + /* Create the socket and set it up to accept connections. */ + if( makeSocket() == O1::SUCCESS ) + { + if (listen (mSock, 1) < 0) + { + O1_LOG("\nO1 TcpServer : Listen error"); + close(mSock); + ret = false; + } + else + { + /* Initialize the set of active sockets. */ + FD_ZERO (&active_fd_set); + FD_SET (mSock, &active_fd_set); + + while (1) + { + /* Block until input arrives on one or more active sockets. */ + read_fd_set = active_fd_set; + if (select (FD_SETSIZE, &read_fd_set, NULL, NULL, NULL) < 0) + { + O1_LOG("\nO1 TcpServer : Select error"); + close(mSock); + ret = false; + break; + } + + /* Service all the sockets with input pending. */ + for (i = 0; i < FD_SETSIZE; ++i) + { + if (FD_ISSET (i, &read_fd_set)) + { + if (i == mSock) + { + /* Connection request on original socket. */ + int newFd; + bzero(&clientName, sizeof(clientName)); + size = sizeof (clientName); + newFd = accept(mSock,(struct sockaddr *) &clientName,&size); + if (newFd < 0) + { + O1_LOG("\nO1 TcpServer : Accept error"); + close(mSock); + ret = false; + break; + } + O1_LOG("\nO1 TcpServer : Connected from host %s, port %hd.\n", + inet_ntoa (clientName.sin_addr), + ntohs (clientName.sin_port)); + FD_SET (newFd, &active_fd_set); + } + else + { + /* Data arriving on an already-connected socket. */ + if (readMessage(i) < 0) + { + close (i); + FD_CLR (i, &active_fd_set); + } + } + } + }/* for loop ends */ + } /* while(1) ends */ + } /* else ends */ + } /* outer if ends */ + else + { + ret = false; + } + return ret; +} + + +/********************************************************************** + Description : Static function for launching a TCP server instance + in a thread + Params[In] : TcpServer instance + Return : NULL +**********************************************************************/ +void* TcpServer::task(void *args) +{ + TcpServer *tcpServer = (TcpServer*)args; + tcpServer->run(); + return NULL; +} + + +/********************************************************************** + Description : Wait for the thread to complete in the parent process + Params[In] : None + Return : true - pthread join success + false - pthread join failed +**********************************************************************/ +bool TcpServer::wait() +{ + return (pthread_join(mThreadId,NULL) == 0); +} + + + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/TcpServer.hpp b/src/o1/TcpServer.hpp new file mode 100644 index 000000000..19f0eba81 --- /dev/null +++ b/src/o1/TcpServer.hpp @@ -0,0 +1,56 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains TcpServer class that listens for Netconf Alarm messages + on a TCP socket from ODU. It calls the AlarmManager functions for raising + or clearing the alarms based on the actions received +*/ + +#ifndef __TCP_SERVER_HPP__ +#define __TCP_SERVER_HPP__ +#include +#include + +using std::string; + +class TcpServer +{ + + private: + pthread_t mThreadId; + int mSock; + const int16_t mPort; + int readMessage(int); + int makeSocket(); + bool run(); + static void* task(void*); + + public: + bool start(); + bool wait(); + TcpServer(const uint16_t port) : mPort(port){}; + ~TcpServer(); + +}; + +#endif + + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/o1_client/Alarm.h b/src/o1/o1_client/Alarm.h new file mode 100644 index 000000000..3506f4bfb --- /dev/null +++ b/src/o1/o1_client/Alarm.h @@ -0,0 +1,86 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains definitions of Alarm structure */ + +#ifndef __ALARM_H__ +#define __ALARM_H__ + +#include +#define ALRM_ID_SIZE 10 +#define OBJ_INST_SIZE 15 +#define TEXT_SIZE 50 +#define DATE_TIME_SIZE 30 + +typedef enum +{ + CRITICAL = 3, + MAJOR = 4, + MINOR = 5, + WARNING = 6, + INDETERMINATE = 7, + CLEARED = 8 +}SeverityLevel; + +typedef enum +{ + COMMUNICATIONS_ALARM = 2, + QUALITY_OF_SERVICE_ALARM = 3, + PROCESSING_ERROR_ALARM = 4, + EQUIPMENT_ALARM = 5, + ENVIRONMENTAL_ALARM = 6, + INTEGRITY_VIOLATION = 7, + OPERATIONAL_VIOLATION = 8, + PHYSICAL_VIOLATION = 9, + SECURITY_SERVICE_OR_MECHANISM_VIOLATION = 10, + TIME_DOMAIN_VIOLATION = 11 +}EventType; + +typedef enum +{ + CLEAR = 0, + RAISE = 1 +}AlarmAction; + +typedef struct +{ + AlarmAction action; +}MsgHeader; + +typedef struct +{ + MsgHeader msgHeader; + EventType eventType; + char objectClassObjectInstance[OBJ_INST_SIZE]; + char alarmId[ALRM_ID_SIZE]; + char alarmRaiseTime[DATE_TIME_SIZE]; + char alarmChangeTime[DATE_TIME_SIZE]; + char alarmClearTime[DATE_TIME_SIZE]; + char probableCause[TEXT_SIZE]; + SeverityLevel perceivedSeverity; + char rootCauseIndicator[TEXT_SIZE]; + char additionalText[TEXT_SIZE]; + char additionalInfo[TEXT_SIZE]; + char specificProblem[TEXT_SIZE]; +}AlarmRecord; + +#endif + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/o1_client/AlarmInterface.c b/src/o1/o1_client/AlarmInterface.c new file mode 100644 index 000000000..1f5bc3b60 --- /dev/null +++ b/src/o1/o1_client/AlarmInterface.c @@ -0,0 +1,131 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains interfaces to raise and clear alarms */ + +#include "AlarmInterface.h" +#include "TcpClient.h" + + +/********************************************************************** + Description : Raise an alarm by sending alarm info to O1 module over + TCP socket with action set to RAISE + Params[In] : Alarm information + Return : ROK - success + RFAILED - failure +**********************************************************************/ +uint8_t raiseAlarm(AlarmRecord* alrm) +{ + if (openSocket(TCP_SERVER_IP,TCP_PORT) == RFAILED) + { + return RFAILED; + } + alrm->msgHeader.action = RAISE; + if (sendData(alrm,sizeof(AlarmRecord)) < 0 ) + { + closeSocket(); + return RFAILED; + } + closeSocket(); + return ROK; +} + +/********************************************************************** + Description : Clears an alarm raised earlier by sending the alrm + information to O1 module over TCP socket with action + set to CLEAR + Params[In] : Alarm information + Return : ROK - success + RFAILED - failure +**********************************************************************/ +uint8_t clearAlarm(AlarmRecord* alrm) +{ + if (openSocket(TCP_SERVER_IP,TCP_PORT) == RFAILED) + { + return RFAILED; + } + alrm->msgHeader.action = CLEAR; + if (sendData(alrm,sizeof(AlarmRecord)) < 0) + { + closeSocket(); + return RFAILED; + } + closeSocket(); + return ROK; +} + + +/********************************************************************** + Description : Fill the cell specific alarm parmeters and generate + the alarm + Params[In] : alarm Id, cell Id + Return : ROK - success + RFAILED - failure +**********************************************************************/ +uint8_t raiseCellAlrm(uint16_t alrmId, uint16_t cellId) +{ + char buff[BUFF_SIZE]; + time_t now = time(NULL); + + AlarmRecord alrm; + alrm.eventType = COMMUNICATIONS_ALARM; + snprintf (alrm.alarmId, sizeof(alrm.alarmId), "%d",alrmId); + alrm.perceivedSeverity = INDETERMINATE; + + strftime(buff, BUFF_SIZE, "%Y-%m-%d %H:%M:%S", localtime(&now)); + if(CELL_UP_ALARM_ID == alrmId) + { + /* Fill cell up parameters */ + snprintf (alrm.additionalText, sizeof(alrm.additionalText), \ + "cell id [%d] is up",cellId); + strcpy(alrm.additionalInfo , "cell UP"); + strcpy(alrm.specificProblem, "Active"); + strcpy(alrm.alarmRaiseTime, buff); + } + else + { + /* Clear the cell up alarm */ + clearCellAlrm(CELL_UP_ALARM_ID); + /* Fill the cell down parameters */ + snprintf (alrm.additionalText, sizeof(alrm.additionalText), \ + "cell [%d] is down",cellId); + strcpy(alrm.additionalInfo , "cell down"); + strcpy(alrm.specificProblem, "Active"); + strcpy(alrm.alarmRaiseTime, buff); + } + /*Raise the alarm */ + return raiseAlarm(&alrm); +} + +/********************************************************************** + Description : Clear the cell alarm + Params[In] : alarm Id + Return : ROK - success + RFAILED - failure +**********************************************************************/ +uint8_t clearCellAlrm(uint16_t alrmId) +{ + AlarmRecord alrm; + snprintf (alrm.alarmId, sizeof(alrm.alarmId), "%d",alrmId); + return clearAlarm(&alrm); +} + + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/o1_client/AlarmInterface.h b/src/o1/o1_client/AlarmInterface.h new file mode 100644 index 000000000..4dabd43ee --- /dev/null +++ b/src/o1/o1_client/AlarmInterface.h @@ -0,0 +1,41 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains interfaces to raise and clear alarms */ + +#ifndef __ALARM_INTERFACE_H__ +#define __ALARM_INTERFACE_H__ + +#include +#include "Alarm.h" +#include "ssi.h" +#include "GlobalDefs.h" + +#define BUFF_SIZE 20 + +uint8_t raiseAlarm(AlarmRecord* alrm); +uint8_t clearAlarm(AlarmRecord* alrm); +uint8_t raiseCellAlrm(uint16_t alrmId, uint16_t cellId); +uint8_t clearCellAlrm(uint16_t alrmId); + +#endif + +/********************************************************************** + End of file +**********************************************************************/ + diff --git a/src/o1/o1_client/GlobalDefs.h b/src/o1/o1_client/GlobalDefs.h new file mode 100644 index 000000000..6323819e2 --- /dev/null +++ b/src/o1/o1_client/GlobalDefs.h @@ -0,0 +1,40 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* Class for global defines and constants for O1 interface */ + +#ifndef __GLOBAL_DEFS_H__ +#define __GLOBAL_DEFS_H__ + +#include + +#define O1_LOG(...) ({\ + printf(__VA_ARGS__);\ + syslog(LOG_DEBUG,__VA_ARGS__);\ + }) + +#define TCP_PORT 8282 +#define TCP_SERVER_IP "127.0.0.1" +#define CELL_UP_ALARM_ID 1009 +#define CELL_DOWN_ALARM_ID 1010 + +#endif + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/o1_client/TcpClient.c b/src/o1/o1_client/TcpClient.c new file mode 100644 index 000000000..a7187e387 --- /dev/null +++ b/src/o1/o1_client/TcpClient.c @@ -0,0 +1,132 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains functions to connect to TCP server and send massages */ + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "TcpClient.h" +#include "GlobalDefs.h" +#include "ssi.h" + +static int s_sock; +static struct sockaddr_in s_serverName; +static uint16_t s_port; +static const char* s_hostName = NULL; + + +/********************************************************************** + Description : Initilize the sockadd_in structure + Params[In] : None + Return : ROK - success + RFAILED - failure +**********************************************************************/ +static uint8_t initSockaddr() +{ + + struct hostent *hostInfo; + struct sockaddr_in *name = &s_serverName; + bzero(&s_serverName, sizeof(s_serverName)); + name->sin_family = AF_INET; + name->sin_port = htons (s_port); + hostInfo = gethostbyname (s_hostName); + if (hostInfo == NULL) + { + O1_LOG("\nO1 TcpClient : Unknown host %s", s_hostName); + return RFAILED; + } + name->sin_addr = *(struct in_addr *) hostInfo->h_addr; + return ROK; +} + + +/********************************************************************** + Description : Open a TCP socket + Params[In] : hostName, port + Return : ROK - success + RFAILED - failure +**********************************************************************/ +uint8_t openSocket(const char* hostName, const uint16_t port) +{ + /* Create the socket. */ + s_port = port; + s_hostName = hostName; + s_sock = socket (PF_INET, SOCK_STREAM, 0); + if (s_sock < 0) + { + O1_LOG("\nO1 TcpClient : Error opening socket"); + return RFAILED; + } + + /* Init the sockaddr_in structure */ + if (initSockaddr() == RFAILED) + { + return RFAILED; + } + /* Connect to the server */ + if (0 > connect (s_sock, + (struct sockaddr_in *)&s_serverName , + sizeof (s_serverName))) + { + O1_LOG("\nO1 TcpClient : Error connecting"); + return RFAILED; + } + + return ROK; + +} + +/********************************************************************** + Description : Send the message on TCP socket + Params[In] : message, size of the message + Return : Number of bytes sent +**********************************************************************/ +int sendData(void* data, const int size) +{ + int nbytes = write (s_sock, data, size); + if (nbytes < 0) + { + O1_LOG("\nO1 TcpClient : Error writing. %d bytes sent", nbytes); + } + return nbytes; +} + +/********************************************************************** + Description : Close the TCP socket + Params[In] : None + Return : ROK - success + RFAILED - failure +**********************************************************************/ +uint8_t closeSocket() +{ + if( close(s_sock) != 0 ) + return RFAILED; + return ROK; +} + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/o1_client/TcpClient.h b/src/o1/o1_client/TcpClient.h new file mode 100644 index 000000000..13d6b3f9b --- /dev/null +++ b/src/o1/o1_client/TcpClient.h @@ -0,0 +1,34 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains functions to connect to a TCP server and send massages */ + +#ifndef __TCP_CLIENT_H__ +#define __TCP_CLIENT_H__ +#include +#include "ssi.h" + +uint8_t openSocket(const char*, const uint16_t); +int sendData(void*, const int); +uint8_t closeSocket(); + +#endif + +/********************************************************************** + End of file +**********************************************************************/ -- 2.16.6