From 0a4589de6e89782d734930a2a7648d5921b176d8 Mon Sep 17 00:00:00 2001 From: Vidhu Date: Wed, 20 Apr 2022 01:21:55 +0530 Subject: [PATCH 1/1] Cell down alarm notification [Issue-Id: ODUHIGH-430] Signed-off-by: Vidhu Change-Id: Ie766628586f8388e084cc4f46b42a03dbec1a5ab --- src/o1/AlarmManager.cpp | 134 ++++++++++++++++-- src/o1/AlarmManager.hpp | 12 +- src/o1/O1App.cpp | 17 +-- src/o1/Observer.cpp | 71 ++++++++++ src/o1/Observer.hpp | 43 ++++++ src/o1/Subject.cpp | 82 +++++++++++ src/o1/Subject.hpp | 48 +++++++ src/o1/UnixSocketServer.cpp | 107 +++----------- src/o1/UnixSocketServer.hpp | 13 +- src/o1/ves/CellStateChange.cpp | 142 +++++++++++++++++++ src/o1/ves/CellStateChange.hpp | 65 +++++++++ src/o1/ves/CellStateChangeStdDef.cpp | 225 ++++++++++++++++++++++++++++++ src/o1/ves/CellStateChangeStdDef.hpp | 73 ++++++++++ src/o1/ves/JsonHelper.cpp | 24 ++++ src/o1/ves/JsonHelper.hpp | 3 +- src/o1/ves/Notification.cpp | 36 +++++ src/o1/ves/Notification.hpp | 34 +++++ src/o1/ves/SliceMeasurementEvent.cpp | 2 +- src/o1/ves/VesCommonHeader.cpp | 261 ++++++++++++++++++++++++++++------- src/o1/ves/VesCommonHeader.hpp | 12 +- src/o1/ves/VesEvent.cpp | 6 +- src/o1/ves/VesEventHandler.cpp | 13 ++ src/o1/ves/VesUtils.hpp | 15 +- 23 files changed, 1258 insertions(+), 180 deletions(-) create mode 100644 src/o1/Observer.cpp create mode 100644 src/o1/Observer.hpp create mode 100644 src/o1/Subject.cpp create mode 100644 src/o1/Subject.hpp create mode 100755 src/o1/ves/CellStateChange.cpp create mode 100755 src/o1/ves/CellStateChange.hpp create mode 100755 src/o1/ves/CellStateChangeStdDef.cpp create mode 100755 src/o1/ves/CellStateChangeStdDef.hpp create mode 100755 src/o1/ves/Notification.cpp create mode 100755 src/o1/ves/Notification.hpp diff --git a/src/o1/AlarmManager.cpp b/src/o1/AlarmManager.cpp index b396188d4..0183da5f5 100644 --- a/src/o1/AlarmManager.cpp +++ b/src/o1/AlarmManager.cpp @@ -1,6 +1,6 @@ /******************************************************************************* ################################################################################ -# Copyright (c) [2020] [HCL Technologies Ltd.] # +# Copyright (c) [2020-2022] [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. # @@ -17,14 +17,15 @@ *******************************************************************************/ /* This file contains AlarmManager singleton class which is responsible for - storing and managing alarms. -*/ + storing and managing alarms. +*/ #include #include "AlarmManager.hpp" using std::pair; + /* Default constructor */ AlarmManager::AlarmManager() { @@ -38,12 +39,116 @@ AlarmManager::~AlarmManager() } +/******************************************************************* + * + * @brief Read the data from the connected client application + * + * @details + * + * Function : update + * + * Functionality: + * - Reads the data from the connected client application + * + * + * @params[in] char* + * @return void + ******************************************************************/ + +void AlarmManager::update(char* recvBuf) +{ + O1_LOG("\nO1 AlarmManager update received"); + AlarmRecord *alrmRec = NULL; + Alarm alrm; + MsgHeader *msgHdr = (MsgHeader*)recvBuf; + O1_LOG("\nO1 AlarmManager: MsgType %d",msgHdr->msgType); + + + if ( msgHdr->msgType == ALARM ){ + uint16_t alrmId; + alrmRec = (AlarmRecord*) recvBuf; + O1_LOG("\nO1 AlarmManager:Alarm info\n" + " Action %d\n" + " Alarm ID %s\n" + " Severity %d\n" + " Additional Text %s\n" + " Specific Problem %s\n" + " Additional Info %s\n" + " Alarm Raise Time %s\n", + alrmRec->msgHeader.action, + alrmRec->alarmId, + alrmRec->perceivedSeverity, + alrmRec->additionalText, + alrmRec->specificProblem, + alrmRec->additionalInfo, + alrmRec->alarmRaiseTime + ); + + /*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(msgHdr->action) + { + case RAISE_ALARM: + + if(raiseAlarm(alrm)) + { + VesEventHandler vesEventHandler; + if (!vesEventHandler.prepare(VesEventType::FAULT_NOTIFICATION, &alrm)) + return ;//O1::FAILURE; + + O1_LOG("\nO1 AlarmManager : Sending Alarm Data"); + if ( !vesEventHandler.send() ) + return ;//O1::FAILURE; + + O1_LOG("\nO1 AlarmManager : " + "Alarm raised for alarm Id %s", + alrmRec->alarmId); + } + + else + { + O1_LOG("\nO1 AlarmManager : " + "Error in raising alarm for alrm Id %s", + alrmRec->alarmId); + } + break; + + case CLEAR_ALARM: + if(clearAlarm(alrm)) + { + O1_LOG("\nO1 AlarmManager : " + "Alarm cleared for alarm Id %s", + alrmRec->alarmId); + + } + else + { + O1_LOG("\nO1 AlarmManager : " + "Error in clearing alarm for alarm Id %s", + alrmRec->alarmId); + } + break; + default: + O1_LOG("\nO1 AlarmManager : No action performed"); + break; + } + +} + -/********************************************************************** +/********************************************************************** Description : Raise an Alarm and store it in alarm list Params[In] : Alarm Return : true - insert in map successful - false - insert in map unsuccessful + false - insert in map unsuccessful **********************************************************************/ bool AlarmManager::raiseAlarm(const Alarm& alarm) { @@ -52,16 +157,16 @@ bool AlarmManager::raiseAlarm(const Alarm& alarm) ret = mAlarmList.insert(pair(alarm.getAlarmId(),alarm)); return ret.second; - + } -/********************************************************************** - Description : Clear an Alarm and delete it from alarm list +/********************************************************************** + Description : Clear an Alarm and delete it from alarm list Params[In] : Alarm instance Return : true - delete successful - false - delete unsuccessful + false - delete unsuccessful **********************************************************************/ bool AlarmManager::clearAlarm(const Alarm& alarm) { @@ -72,17 +177,18 @@ bool AlarmManager::clearAlarm(const Alarm& alarm) { mAlarmList.erase(it); ret = true; - } + } return ret; } -/********************************************************************** + +/********************************************************************** Description : Clear an Alarm and delete it from alarm list with - alarmId + alarmId Params[In] : Alarm Id Return : true - delete successful - false - delete unsuccessful + false - delete unsuccessful **********************************************************************/ bool AlarmManager::clearAlarm(const uint16_t& alarmId) { @@ -90,7 +196,7 @@ bool AlarmManager::clearAlarm(const uint16_t& alarmId) } -/********************************************************************** +/********************************************************************** Description : Return the list of active alarms Params[In] : None Return : constant reference to the map diff --git a/src/o1/AlarmManager.hpp b/src/o1/AlarmManager.hpp index 0562f63bf..8382669d8 100644 --- a/src/o1/AlarmManager.hpp +++ b/src/o1/AlarmManager.hpp @@ -1,6 +1,6 @@ /******************************************************************************* ################################################################################ -# Copyright (c) [2020] [HCL Technologies Ltd.] # +# Copyright (c) [2020-2022] [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. # @@ -30,23 +30,25 @@ #include "PnfRegistrationThread.hpp" #include "VesUtils.hpp" #include "VesEventHandler.hpp" +#include "Observer.hpp" using std::map; - -class AlarmManager : public Singleton +class AlarmManager : public Singleton ,public Observer { friend Singleton; private: - map mAlarmList; + map mAlarmList; protected: - AlarmManager(); + AlarmManager(); ~AlarmManager(); public: + + void update(char* recvBuf); bool raiseAlarm(const Alarm& alarm); bool clearAlarm(const uint16_t& alarmId); bool clearAlarm(const Alarm& alarm ); diff --git a/src/o1/O1App.cpp b/src/o1/O1App.cpp index d63498f38..0d2ba2e1b 100644 --- a/src/o1/O1App.cpp +++ b/src/o1/O1App.cpp @@ -73,7 +73,7 @@ O1App::~O1App() /******************************************************************* * - * @brief Runs the O1 modules as a thread + * @brief Runs the O1 modules as a thread * * @details * @@ -103,28 +103,29 @@ bool O1App::run() { if( !sessHdlr.init() ) { - O1_LOG("\nO1 O1App : SessionHandler initialization failed "); + O1_LOG("\nO1 O1App : SessionHandler initialization failed "); return false; } } - catch( const std::exception& e ) + catch( const std::exception& e ) { O1_LOG("\nO1 O1App : Exception : %s", e.what()); return false; } - + /* Start the Unix Socket Server to listen for alarm messages */ + AlarmManager::instance().subscribe(&mUxSocketServer); if( mUxSocketServer.start() ) - { - + { + if(mUxSocketServer.setAffinity(O1::CPU_CORE)) { O1_LOG("\nO1 O1App : CPU affinity set for UnixSocketServer thread to " ); mUxSocketServer.printAffinity(); } - + sleep(SLEEP_INTERVAL); - if( mUxSocketServer.isRunning() ) + if( mUxSocketServer.isRunning() ) { mStartupStatus = true; O1_LOG("\nO1 O1App : Unix Socket server started"); diff --git a/src/o1/Observer.cpp b/src/o1/Observer.cpp new file mode 100644 index 000000000..f4d8bdbdb --- /dev/null +++ b/src/o1/Observer.cpp @@ -0,0 +1,71 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020-2022] [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. # +################################################################################ +*******************************************************************************/ + +#include "Observer.hpp" +#include "GlobalDefs.hpp" +#include "Subject.hpp" + +/* Default Constructor*/ +Observer::Observer() +{ + +} + +/* Default destructor*/ +Observer::~Observer() +{ + +} + +/********************************************************************** + Description : Getting message from Subject + Params[In] : char* + Return : void +**********************************************************************/ + +void Observer::update(char* message) { + this->mMessage = message; + +} + +/********************************************************************** + Description : Subscribe Observer to Subject + Params[In] : Subject + Return : void +**********************************************************************/ + +void Observer::subscribe(Subject *subject) +{ + this->mSubject = subject; + this->mSubject->registerObserver(this); +} + +/********************************************************************** + Description : Unsubscribe observer from Subject + Params[In] : void + Return : void +**********************************************************************/ + +void Observer::unsubscribe() { + this->mSubject->unregisterObserver(this); +} + + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/Observer.hpp b/src/o1/Observer.hpp new file mode 100644 index 000000000..bac1152c6 --- /dev/null +++ b/src/o1/Observer.hpp @@ -0,0 +1,43 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020-2022] [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. # +################################################################################ +*******************************************************************************/ + +#ifndef __OBSERVER_HPP__ +#define __OBSERVER_HPP__ + +#include + +class Subject; +class Observer +{ + public: + Observer(); + ~Observer(); + virtual void update(char* message); + virtual void unsubscribe(); + virtual void subscribe(Subject *subject); + + protected: + char* mMessage; + Subject *mSubject; +}; + +#endif + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/Subject.cpp b/src/o1/Subject.cpp new file mode 100644 index 000000000..626b0d8e3 --- /dev/null +++ b/src/o1/Subject.cpp @@ -0,0 +1,82 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020-2022] [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. # +################################################################################ +*******************************************************************************/ + +#include +#include "Subject.hpp" +#include "GlobalDefs.hpp" + +/* Constructor*/ +Subject::Subject() { + mMessage=NULL; +} + +/* Default destructor*/ +Subject::~Subject() { + +} + +/********************************************************************** + Description : Register an Observer + Params[In] : Observer + Return : void +**********************************************************************/ +void Subject::registerObserver(Observer *observer) +{ + mObserversList.push_back(observer); +} + +/********************************************************************** + Description : Unregister an Observer + Params[In] : Observer + Return : void +**********************************************************************/ +void Subject::unregisterObserver(Observer *observer) +{ + mObserversList.remove(observer); +} + +/********************************************************************** + Description : Notify all observers on new message + Params[In] : void + Return : void +**********************************************************************/ +void Subject::notifyObservers() +{ + std::list::iterator iterator = mObserversList.begin(); + while (iterator != mObserversList.end()) + { + (*iterator)->update(mMessage); + iterator++; + } +} + +/********************************************************************** + Description : Accept a message + Params[In] : Message + Return : void +**********************************************************************/ +void Subject::createMessage(char* message ) +{ + mMessage = message; + notifyObservers(); +} + + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/Subject.hpp b/src/o1/Subject.hpp new file mode 100644 index 000000000..83ac7af72 --- /dev/null +++ b/src/o1/Subject.hpp @@ -0,0 +1,48 @@ +/******************************************************************************* +################################################################################ +# 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. # +################################################################################ +*******************************************************************************/ + +#ifndef __SUBJECT_HPP__ +#define __SUBJECT_HPP__ + + +#include +#include +#include "Observer.hpp" + + +class Subject +{ + public: + + Subject() ; + ~Subject() ; + + virtual void registerObserver(Observer *observer); + virtual void unregisterObserver(Observer *observer); + virtual void notifyObservers(); + virtual void createMessage(char* message ); + protected: + std::list mObserversList; + char* mMessage; +}; + +#endif + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/UnixSocketServer.cpp b/src/o1/UnixSocketServer.cpp index ef954fa87..28a920a46 100644 --- a/src/o1/UnixSocketServer.cpp +++ b/src/o1/UnixSocketServer.cpp @@ -16,14 +16,12 @@ ################################################################################ *******************************************************************************/ -/* This file contains UnixSocketServer class that listens for Netconf Alarm +/* This file contains UnixSocketServer class that listens for Netconf Alarm messages on a Unix socket from ODU. It calls the AlarmManager functions - for raising or clearing the alarms based on the actions received -*/ + for raising or clearing the alarms based on the actions received */ #include "UnixSocketServer.hpp" #include "Alarm.hpp" -#include "AlarmManager.hpp" #include "CmInterface.h" #include "GlobalDefs.hpp" #include @@ -59,11 +57,11 @@ using std::pair; ******************************************************************/ UnixSocketServer::UnixSocketServer(const string& sockPath) : mSockPath(sockPath), - mIsRunning(false) + mIsRunning(false) { -} - +} + /******************************************************************* * * @brief Destructor @@ -101,89 +99,18 @@ UnixSocketServer::~UnixSocketServer() ******************************************************************/ int UnixSocketServer::readMessage(int fd) { - AlarmRecord *alrmRec = NULL; char recvBuf[BUFLEN]; - Alarm alrm; bzero(&recvBuf,sizeof(recvBuf)); - + int nbytes = read (fd, &recvBuf, sizeof(recvBuf)); - + if (nbytes > 0) { - MsgHeader *msgHdr = (MsgHeader*)recvBuf; - - O1_LOG("\nO1 UnixSocketServer :\nMsgType %d",msgHdr->msgType); - - if ( msgHdr->msgType == ALARM ){ - uint16_t alrmId; - alrmRec = (AlarmRecord*) recvBuf; - O1_LOG("\nO1 UnixSocketServer :\n" - "Action %d\n" - "Alarm ID %s\n" - "Severity %d\n" - "Additional Text %s\n" - "Specific Problem %s\n" - "Additional Info %s\n" - "Alarm Raise Time %s\n", - alrmRec->msgHeader.action, - alrmRec->alarmId, - alrmRec->perceivedSeverity, - alrmRec->additionalText, - alrmRec->specificProblem, - alrmRec->additionalInfo, - alrmRec->alarmRaiseTime - ); - - /*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(msgHdr->action) - { - case RAISE_ALARM: - - if(AlarmManager::instance().raiseAlarm(alrm)) - { - O1_LOG("\nO1 UnixSocketServer : " - "Alarm raised for alarm Id %s", - alrmRec->alarmId); - } - - else - { - O1_LOG("\nO1 UnixSocketServer : " - "Error in raising alarm for alrm Id %s", - alrmRec->alarmId); - } - break; - - case CLEAR_ALARM: - if(AlarmManager::instance().clearAlarm(alrm)) - { - O1_LOG("\nO1 UnixSocketServer : " - "Alarm cleared for alarm Id %s", - alrmRec->alarmId); - - } - else - { - O1_LOG("\nO1 UnixSocketServer : " - "Error in clearing alarm for alarm Id %s", - alrmRec->alarmId); - } - break; - default: - O1_LOG("\nO1 UnixSocketServer : No action performed"); - break; - } + /* sending message to all Unix Socket Server subscribers */ + createMessage(recvBuf); } + return nbytes; } @@ -204,7 +131,7 @@ int UnixSocketServer::readMessage(int fd) * O1:FAILURE - failure ******************************************************************/ -int UnixSocketServer::makeSocket() +int UnixSocketServer::makeSocket() { struct sockaddr_un name; /* Create the socket. */ @@ -218,13 +145,13 @@ int UnixSocketServer::makeSocket() bzero(&name, sizeof(name)); name.sun_family = AF_UNIX; - /* Remove the socket file if it already exists */ + /* Remove the socket file if it already exists */ if ( unlink(mSockPath.c_str()) == 0) { O1_LOG("\nO1 UnixSocketServer : " "Removing the existing socket path %s", mSockPath.c_str()); - } + } strcpy(name.sun_path, mSockPath.c_str()); if (bind (mSock, (struct sockaddr *) &name, sizeof (name)) < 0) { @@ -245,7 +172,7 @@ int UnixSocketServer::makeSocket() * Function : run * * Functionality: - * - A Unix server to handle multiple connection + * - A Unix server to handle multiple connection * Uses select multiplexing * * @params[in] void @@ -309,7 +236,7 @@ bool UnixSocketServer::run() } O1_LOG("\nO1 UnixSocketServer : Connected from client\n"); FD_SET (newFd, &active_fd_set); - } + } else { /* Data arriving on an already-connected socket. */ @@ -319,8 +246,8 @@ bool UnixSocketServer::run() FD_CLR (i, &active_fd_set); } } - } - }/* for loop ends */ + } + }/* for loop ends */ } /* while(1) ends */ } /* else ends */ } /* outer if ends */ diff --git a/src/o1/UnixSocketServer.hpp b/src/o1/UnixSocketServer.hpp index cf3c18d27..d81478db9 100644 --- a/src/o1/UnixSocketServer.hpp +++ b/src/o1/UnixSocketServer.hpp @@ -17,8 +17,8 @@ *******************************************************************************/ /* This file contains UnixSocketServer class that listens for Netconf Alarm messages - on a Unix socket from ODU. It calls the AlarmManager functions for raising - or clearing the alarms based on the actions received + on a Unix socket from ODU. It calls the AlarmManager functions for raising + or clearing the alarms based on the actions received */ #ifndef __UNIX_SOCKET_SERVER_HPP__ @@ -26,11 +26,12 @@ #include #include #include "Thread.hpp" +#include "Subject.hpp" using std::string; #define BUFLEN 512 -class UnixSocketServer : public Thread +class UnixSocketServer : public Thread , public Subject { private: @@ -38,15 +39,15 @@ class UnixSocketServer : public Thread string mSockPath; int readMessage(int); int makeSocket(); - + protected: bool run(); bool mIsRunning; public: - UnixSocketServer(const string& sockPath); + UnixSocketServer(const string& sockPath); ~UnixSocketServer(); - bool isRunning() const; + bool isRunning() const; virtual void cleanUp(void); }; diff --git a/src/o1/ves/CellStateChange.cpp b/src/o1/ves/CellStateChange.cpp new file mode 100755 index 000000000..94d572c86 --- /dev/null +++ b/src/o1/ves/CellStateChange.cpp @@ -0,0 +1,142 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020-2022] [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. # +################################################################################ +*******************************************************************************/ + +#include +#include +#include +#include +#include "CellStateChange.hpp" +#include "JsonHelper.hpp" + +/* Default constructor*/ +CellStateChange::CellStateChange() : Notification(VesEventType::FAULT_NOTIFICATION) +{ + +} + +/* Default Destructor*/ +CellStateChange::~CellStateChange() +{ + +} + +/******************************************************************* + * + * @brief Returns ISO time String + * + * @details + * + * Function :getISOEventTime + * + * Functionality: + * - Returns ISO time String + * + * @params[in] IN - void + * @return value of string - success + * empty string - failure + * + * ****************************************************************/ + +std::string CellStateChange::getISOEventTime() { + auto now = std::chrono::system_clock::now(); + auto itt = std::chrono::system_clock::to_time_t(now); + std::ostringstream os; + os << std::put_time(gmtime(&itt), "%FT%TZ"); + return os.str(); +} + +/******************************************************************* + * + * @brief prepare CellStateChange Fields + * + * @details + * + * Function : prepareCellStateChangeEventFields + * + * Functionality: + * - prepare CellStateChange Fields in json format + * + * @params[in] IN - pointer to pnfFields + * @return true - success + * false - failure + * + * ****************************************************************/ + +bool CellStateChange::prepareEventFields(const Message* msg) { + const Alarm* alrm = dynamic_cast (msg); + if(!alrm) { + O1_LOG("\nO1 CellStateChange : Casting failed in prepareEventFields"); + return false; + } + bool ret = true; + + + cJSON* faultFields = this->mVesEventFields; + + if(JsonHelper::addNodeToObject(faultFields, "faultFieldsVersion", FAULT_FIELDS_VERSION) == 0) { + ret = false; + } + if(JsonHelper::addNodeToObject(faultFields, "alarmCondition", ALARM_CONDITION) == 0) { + ret = false; + } + if(JsonHelper::addNodeToObject(faultFields, "alarmInterfaceA", ALARM_INTERFACE_A) == 0) { + ret = false; + } + if(JsonHelper::addNodeToObject(faultFields, "eventSourceType", EVENT_SOURCE_TYPE) == 0) { + ret = false; + } + if(JsonHelper::addNodeToObject(faultFields, "specificProblem", SPECIFIC_PROBLEM) == 0) { + ret = false; + } + if(JsonHelper::addNodeToObject(faultFields, "eventSeverity", EVENT_SEVERITY) == 0) { + ret = false; + } + if(JsonHelper::addNodeToObject(faultFields, "vfStatus", VF_STATUS) == 0) { + ret = false; + } + + cJSON* alarmAdditionalInformation = JsonHelper::createNode(); + if(alarmAdditionalInformation == 0) { + O1_LOG("\nO1 CellStateChange : could not create alarmAdditionalInformation JSON object"); + return false; + } + else if(JsonHelper::addJsonNodeToObject(faultFields, "alarmAdditionalInformation", \ + alarmAdditionalInformation ) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(alarmAdditionalInformation, "eventTime", getISOEventTime().c_str()) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(alarmAdditionalInformation, "equipType", EQUIP_TYPE) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(alarmAdditionalInformation, "vendor", VENDOR) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(alarmAdditionalInformation, "model", MODEL) == 0) { + ret = false; + } + + + return ret; +} + + +/********************************************************************** + End of file + **********************************************************************/ diff --git a/src/o1/ves/CellStateChange.hpp b/src/o1/ves/CellStateChange.hpp new file mode 100755 index 000000000..071f54056 --- /dev/null +++ b/src/o1/ves/CellStateChange.hpp @@ -0,0 +1,65 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020-2022] [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. # +################################################################################ +*******************************************************************************/ + +#ifndef __CELL_STATE_CHANGE_HPP__ +#define __CELL_STATE_CHANGE_HPP__ + + +#include + +#include "VesEvent.hpp" +#include "AlarmMessages.h" +#include "Alarm.hpp" +#include "AlarmManager.hpp" +#include "Message.hpp" +#include "Notification.hpp" + +using namespace std; + +//macros +#define FAULT_FIELDS_VERSION "4.0" +#define ALARM_CONDITION "CELL Down" +#define ALARM_INTERFACE_A "Slot-0-CELL-1" +#define EVENT_SOURCE_TYPE "O_RAN_COMPONENT" +#define SPECIFIC_PROBLEM "CELL 1 Down" +#define EVENT_SEVERITY "MAJOR" +#define VF_STATUS "Active" +#define EQUIP_TYPE "O-RAN-DU" +#define VENDOR "Melacon" +#define MODEL "ODU Device" + +class CellStateChange : public Notification +{ + + public: + CellStateChange(); + ~CellStateChange(); + + std::string getISOEventTime(); + + protected: + bool prepareEventFields(const Message* msg = NULL); + +}; + + +#endif + +/********************************************************************** + End of file + **********************************************************************/ diff --git a/src/o1/ves/CellStateChangeStdDef.cpp b/src/o1/ves/CellStateChangeStdDef.cpp new file mode 100755 index 000000000..17bf96d2e --- /dev/null +++ b/src/o1/ves/CellStateChangeStdDef.cpp @@ -0,0 +1,225 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020-2022] [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. # +################################################################################ +*******************************************************************************/ + +#include +#include +#include +#include +#include "CellStateChangeStdDef.hpp" +#include "JsonHelper.hpp" +/* Default constructor*/ +CellStateChangeStdDef::CellStateChangeStdDef() : Notification(VesEventType::FAULT_NOTIFICATION) +{ + +} + +/* Default Destructor*/ +CellStateChangeStdDef::~CellStateChangeStdDef() +{ + +} + + +/******************************************************************* + * + * @brief Returns ISO time String + * + * @details + * + * Function :getISOEventTime + * + * Functionality: + * - Returns ISO time String + * + * @params[in] IN - void + * @return value of string - success + * empty string - failure + * + * ****************************************************************/ + +std::string CellStateChangeStdDef::getISOEventTime() { + auto now = std::chrono::system_clock::now(); + auto itt = std::chrono::system_clock::to_time_t(now); + std::ostringstream os; + os << std::put_time(gmtime(&itt), "%FT%TZ"); + return os.str(); +} + +/******************************************************************* + * + * @brief prepare CellStateChangeStdDef Fields + * + * @details + * + * Function : prepareCellStateChangeStdDefEventFields + * + * Functionality: + * - prepare CellStateChangeStdDef Fields in json format + * + * @params[in] IN - pointer to pnfFields + * @return true - success + * false - failure + * + * ****************************************************************/ + +bool CellStateChangeStdDef::prepareEventFields(const Message* msg) { + const Alarm* alrm = dynamic_cast (msg); + if(!alrm) { + O1_LOG("\nO1 CellStateChangeStdDef : Casting failed in prepareEventFields"); + return false; + } + bool ret = true; + + + cJSON* stndDefinedFields = this->mVesEventFields; + + if(JsonHelper::addNodeToObject(stndDefinedFields, "schemaReference", FAULT_SCHEMA) == 0) { + ret = false; + } + + cJSON* data = JsonHelper::createNode(); + if(data == 0) { + O1_LOG("\nO1 CellStateChangeStdDef : could not create data JSON object"); + return false; + } + else if(JsonHelper::addJsonNodeToObject(stndDefinedFields, "data", \ + data) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(data, "href", HREF) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(data, "uri", URI) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(data, "notificationId", NOTIFICATION_ID) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(data, "notificationType", NOTIFICATION_TYPE) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(data, "eventTime", getISOEventTime().c_str()) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(data, "systemDN", "") == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(data, "probableCause", PROBABLE_CAUSE) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(data, "perceivedSeverity",PERCEIVED_SEVERITY) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(data, "rootCauseIndicator", (bool)false ) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(data, "specificProblem", "") == 0) { + ret = false; + } + + cJSON* correlatedNotificationsArr= cJSON_CreateArray(); + if (correlatedNotificationsArr == NULL) + { + ret = false; + } + cJSON_AddItemToObject(data, "correlatedNotifications", correlatedNotificationsArr); + + if(JsonHelper::addNodeToObject(data, "backedUpStatus", (bool)true) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(data, "backUpObject", "") == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(data, "trendIndication", TRND_INDICATION) == 0) { + ret = false; + } + + cJSON* thresholdInfo = JsonHelper::createNode(); + if(thresholdInfo == 0) { + O1_LOG("\nO1 CellStateChange : could not create thresholdInfo JSON object"); + return false; + } + else if(JsonHelper::addJsonNodeToObject(data, "thresholdInfo", \ + thresholdInfo ) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(thresholdInfo, "observedMeasurement", OBSRVED_MEASUREMENT) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(thresholdInfo, "observedValue", OBSERVED_VALUE) == 0) { + ret = false; + } + + cJSON* stateChangeDefinitionArr= cJSON_CreateArray(); + if (stateChangeDefinitionArr == NULL) + { + ret = false; + } + cJSON_AddItemToObject(data, "stateChangeDefinition", stateChangeDefinitionArr); + + cJSON* monitoredAttributes = JsonHelper::createNode(); + if( monitoredAttributes == 0) { + O1_LOG("\nO1 CellStateChange : could not create monitoredAttributes JSON object"); + return false; + } + else if(JsonHelper::addJsonNodeToObject(data , "monitoredAttributes", \ + monitoredAttributes ) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(monitoredAttributes, "newAtt", NEW_ATT) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(data, "proposedRepairActions", PROPOSED_REPAIR_ACTION) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(data, "additionalText", ADDITIONAL_TEXT) == 0) { + ret = false; + } + + cJSON* additionalInformation = JsonHelper::createNode(); + if(additionalInformation == 0) { + O1_LOG("\nO1 CellStateChangeStdDef : could not create additionalInformation JSON object"); + return false; + } + else if(JsonHelper::addJsonNodeToObject(data , "additionalInformation", \ + additionalInformation ) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject( additionalInformation, "addInfo", ADD_INFO) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(data , "alarmId", ALARM_ID) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(data , "alarmType",ALRAM_TYPE ) == 0) { + ret = false; + } + + else if(JsonHelper::addNodeToObject(stndDefinedFields, "stndDefinedFieldsVersion", STND_DEFINED_FEILD_VERSION) == 0) { + ret = false; + } + + + + return ret; +} + + +/********************************************************************** + End of file + **********************************************************************/ diff --git a/src/o1/ves/CellStateChangeStdDef.hpp b/src/o1/ves/CellStateChangeStdDef.hpp new file mode 100755 index 000000000..fe83e5051 --- /dev/null +++ b/src/o1/ves/CellStateChangeStdDef.hpp @@ -0,0 +1,73 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020-2022] [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. # +################################################################################ +*******************************************************************************/ + +#ifndef __CELL_STATE_CHANGE_STD_DEF_HPP__ +#define __CELL_STATE_CHANGE_STD_DEF_HPP__ + + +#include + +#include "VesEvent.hpp" +#include "AlarmMessages.h" +#include "Alarm.hpp" +#include "AlarmManager.hpp" +#include "Message.hpp" +#include "Notification.hpp" + +using namespace std; + +#define FAULT_SCHEMA "https://forge.3gpp.org/rep/sa5/MnS/blob/SA88-Rel16/OpenAPI/faultMnS.yaml#components/schemas/NotifyNewAlarm" +#define HREF "1" +#define URI "1" +#define NOTIFICATION_ID 1.0 +#define NOTIFICATION_TYPE "notifyNewAlarm" +#define PROBABLE_CAUSE "real-issue" +#define TRND_INDICATION "MORE_SEVERE" +#define OBSRVED_MEASUREMENT "new" +#define OBSERVED_VALUE 123.2 +#define NEW_ATT "new" +#define ADD_INFO "new" +#define ALARM_ID "1" +#define ALRAM_TYPE "COMMUNICATIONS_ALARM" +#define STND_DEFINED_FEILD_VERSION "1.0" +#define PERCEIVED_SEVERITY "INDETERMINATE" +#define PROPOSED_REPAIR_ACTION "Call the police!" +#define ADDITIONAL_TEXT "O-RAN Software Community" + + +class CellStateChangeStdDef : public Notification +{ + + public: + CellStateChangeStdDef(); + ~CellStateChangeStdDef(); + + std::string getISOEventTime(); + + protected: + bool prepareEventFields(const Message* msg = NULL); + + +}; + + +#endif + +/********************************************************************** + End of file + **********************************************************************/ diff --git a/src/o1/ves/JsonHelper.cpp b/src/o1/ves/JsonHelper.cpp index 340f8690e..595222c99 100644 --- a/src/o1/ves/JsonHelper.cpp +++ b/src/o1/ves/JsonHelper.cpp @@ -94,6 +94,29 @@ cJSON* JsonHelper::addNodeToObject(cJSON * parent, \ } +/******************************************************************* + * + * @brief wraps cJSON_AddNumberToObject cJSON library function + * + * @details + * + * Function : addNodeToObject + * + * Functionality: + * - wraps cJSON_AddNumberToObject cJSON library function + * + * @params[in] cJSON * parent, const char * nodeName, bool value + * @return pointer to cJSON object - success + * NULL - failure + * + * ****************************************************************/ + +cJSON* JsonHelper::addNodeToObject(cJSON * parent, \ + const char * nodeName, bool value) +{ + return cJSON_AddBoolToObject(parent, nodeName, (bool) value); +} + /******************************************************************* * * @brief wraps cJSON_AddItemToObject cJSON library function @@ -117,6 +140,7 @@ cJSON_bool JsonHelper::addJsonNodeToObject(cJSON * parent, \ return cJSON_AddItemToObject(parent, nodeName, node); } + /******************************************************************* * * @brief wraps cJSON_Delete cJSON library function diff --git a/src/o1/ves/JsonHelper.hpp b/src/o1/ves/JsonHelper.hpp index 7d5f0d5bc..441fd92a7 100644 --- a/src/o1/ves/JsonHelper.hpp +++ b/src/o1/ves/JsonHelper.hpp @@ -39,7 +39,8 @@ class JsonHelper const char* value); static cJSON* addNodeToObject(cJSON * parent, \ const char * nodeName, double value); - + static cJSON* addNodeToObject(cJSON * parent, \ + const char * nodeName, bool value); static void deleteNode(cJSON * node); static cJSON_bool addJsonNodeToObject(cJSON * parent, \ const char * nodeName, cJSON * node); diff --git a/src/o1/ves/Notification.cpp b/src/o1/ves/Notification.cpp new file mode 100755 index 000000000..14bf5bc41 --- /dev/null +++ b/src/o1/ves/Notification.cpp @@ -0,0 +1,36 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020-2022] [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. # +################################################################################ +*******************************************************************************/ + +#include "Notification.hpp" + +/* Default constructor*/ +Notification::Notification(VesEventType eventType) + :VesEvent(eventType) +{ + +} + +/* Default Destructor*/ +Notification::~Notification() +{ + +} + +/********************************************************************** + End of file + **********************************************************************/ diff --git a/src/o1/ves/Notification.hpp b/src/o1/ves/Notification.hpp new file mode 100755 index 000000000..98a2a1038 --- /dev/null +++ b/src/o1/ves/Notification.hpp @@ -0,0 +1,34 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020-2022] [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. # +################################################################################ +*******************************************************************************/ + +#ifndef __NOTIFICATION__ +#define __NOTIFICATION__ + +#include "VesEvent.hpp" + +class Notification : public VesEvent { + +public: + Notification(VesEventType eventType); + ~Notification(); +}; + +#endif +/********************************************************************** + End of file + **********************************************************************/ diff --git a/src/o1/ves/SliceMeasurementEvent.cpp b/src/o1/ves/SliceMeasurementEvent.cpp index 59a229ea5..efbba0e06 100644 --- a/src/o1/ves/SliceMeasurementEvent.cpp +++ b/src/o1/ves/SliceMeasurementEvent.cpp @@ -23,7 +23,7 @@ #include "JsonHelper.hpp" #include "PmInterface.h" -#define MEASUREMENT_INTERVAL 60 +#define MEASUREMENT_INTERVAL 60.0 #define MEASUREMENT_FIELDS_VERSION "4.0" /* Constructor*/ diff --git a/src/o1/ves/VesCommonHeader.cpp b/src/o1/ves/VesCommonHeader.cpp index ce7214ddd..4cbb8ed44 100644 --- a/src/o1/ves/VesCommonHeader.cpp +++ b/src/o1/ves/VesCommonHeader.cpp @@ -27,8 +27,9 @@ #include #include "JsonHelper.hpp" #include "VesCommonHeader.hpp" +#include "VesUtils.hpp" -static uint16_t seqNo = 0; +static double seqNo = 0; #define MAX_TIME_STR 35 @@ -48,7 +49,7 @@ static uint16_t seqNo = 0; * * ****************************************************************/ -uint16_t VesCommonHeader::nextSequenceNo() +double VesCommonHeader::nextSequenceNo() { return seqNo++; } @@ -69,7 +70,7 @@ uint16_t VesCommonHeader::nextSequenceNo() * * ****************************************************************/ -uint16_t VesCommonHeader::getSequenceNo() +double VesCommonHeader::getSequenceNo() { return seqNo; } @@ -100,7 +101,11 @@ string VesCommonHeader::getEventTypeToStr() str = "pnfRegistration"; break; case VesEventType::FAULT_NOTIFICATION: - str = "faultNotification"; + #ifdef StdDef + str = "stndDefined"; + #else + str = "fault"; + #endif break; case VesEventType::PM_NOTIFICATION: str = "pmNotification"; @@ -155,7 +160,11 @@ string VesCommonHeader::getEventId() evntId = "_" + stringEpochTime + "_" + "PM1min"; break; case VesEventType::FAULT_NOTIFICATION: - evntId = getSourceName() + "_" + MODEL_NUMBER_007_DEV; + #ifdef StdDef + evntId = FAULT_EVENTID; + #else + evntId ="O_RAN_COMPONENT_Alarms-61"; + #endif break; default: O1_LOG("\nO1 VesCommonHeader : this VES msg Type support in getEventId is \ @@ -167,14 +176,14 @@ not available"); /******************************************************************* * - * @brief create Ves Event Type + * @brief create Ves Event Type from Ves Event type * * @details * * Function : getEventType * * Functionality: - * - create Ves Event Type + * - create Ves Event Type from Ves Event type * * @params[in] IN - void * @return value of string - success @@ -200,7 +209,7 @@ string VesCommonHeader::getEventType() evntType = EVENT_TYPE_ORAN_COMPONENT_PM; break; case VesEventType::FAULT_NOTIFICATION: - evntType = EVENT_TYPE_5G; + evntType = FAULT_TYPE; break; default: O1_LOG("\nO1 VesCommonHeader : this VES msg Type support in getEvenType is \ @@ -291,7 +300,11 @@ string VesCommonHeader::getEventName() evntName = getEventTypeToStr() + "_" + EVENT_TYPE_ORAN_COMPONENT_PM; break; case VesEventType::FAULT_NOTIFICATION: - evntName = getEventTypeToStr() + "_" + EVENT_TYPE_5G; + #ifdef StdDef + evntName = FAULT_EVENT_NAME; + #else + evntName ="O_RAN_COMPONENT_Alarms"; + #endif break; default: O1_LOG("\nO1 VesCommonHeader : This VES msg Type support in getEventName is \ @@ -307,7 +320,7 @@ string VesCommonHeader::getEventName() * * @details * - * Function : getReportingEntityName + * Function : getReportingEntityId * * Functionality: * - create Ves Event Name from Ves Event type @@ -317,11 +330,45 @@ string VesCommonHeader::getEventName() * empty string - failure * ****************************************************************/ -string VesCommonHeader::getReportingEntityName() +string VesCommonHeader::getReportingEntityId() { - /*Currently PNF_REGISTRATION and PM_SLICE are only supported. + /*Currently PNF_REGISTRATION and PM_SLICE are only supported. This function must be updated in later releases*/ + string evntName = ""; + switch(mEventType) + { + case VesEventType::PNF_REGISTRATION: + evntName = ODU_HIGH; + break; + + case VesEventType::FAULT_NOTIFICATION: + evntName = ODU_HIGH; + break; + default: + break; + } + return evntName; +} + +/******************************************************************* + * + * @brief create Reporting Entity Name from Ves Event type + * + * @details + * + * Function : getReportingEntityName + * + * Functionality: + * - create Reporting Entity Name from Ves Event type + * + * @params[in] IN - void + * @return value of string - success + * empty string - failure + * ****************************************************************/ + +string VesCommonHeader::getReportingEntityName() +{ string evntName = ""; switch(mEventType) { @@ -332,7 +379,7 @@ string VesCommonHeader::getReportingEntityName() evntName = PM_REPORTING_ENTITY; break; case VesEventType::FAULT_NOTIFICATION: - evntName = getSourceName(); + evntName = ODU_HIGH; break; default: O1_LOG("\nO1 VesCommonHeader : This VES msg Type support in \ @@ -344,14 +391,14 @@ string VesCommonHeader::getReportingEntityName() /******************************************************************* * - * @brief create Ves Event Name from Ves Event type + * @brief create Source Name from Ves Event type * * @details * - * Function : getReportingEntityName + * Function : getSourceName * * Functionality: - * - create Ves Event Name from Ves Event type + * - create Source Name from Ves Event type * * @params[in] IN - void * @return value of string - success @@ -360,7 +407,78 @@ string VesCommonHeader::getReportingEntityName() string VesCommonHeader::getSourceName() { - return ODU_HIGH; + string sourceName = ""; + switch(mEventType) + + { + case VesEventType::PNF_REGISTRATION: + sourceName = ODU_HIGH; + break; + case VesEventType::FAULT_NOTIFICATION: + sourceName = ODU_HIGH; + break; + default: + break; + } + return sourceName; +} + +/******************************************************************* + * + * @brief create Ves Event SourceId from Ves Event type + * + * @details + * + * Function : getSourceId + * + * Functionality: + * - create Ves Event SourceId from Ves Event type + * + * @params[in] IN - void + * @return value of string - success + * empty string - failure + * ****************************************************************/ +string VesCommonHeader::getSourceId() +{ + string sourceId = ""; + switch(mEventType) + { + case VesEventType::FAULT_NOTIFICATION: + sourceId = SOURCE_ID; + break; + default: + break; + } + return sourceId; +} + +/******************************************************************* + * + * @brief create Ves Event Name from Ves Event type + * + * @details + * + * Function : getnfcNamingCode + * + * Functionality: create Ves Event nfc naming code + * + * @params[in] IN - void + * @return value of string - success + * empty string - failure + * ****************************************************************/ + +string VesCommonHeader::getnfcNamingCode() +{ + string name = ""; + switch(mEventType) + { + case VesEventType::FAULT_NOTIFICATION: + name = NFC_NAMING_CODE; + break; + default: + break; + } + return name; } /******************************************************************* @@ -382,7 +500,24 @@ string VesCommonHeader::getSourceName() string VesCommonHeader::getNamingCode() { - return NAMING_CODE_ODU; + + string nammingcdoe = ""; + switch(mEventType) + { + case VesEventType::PNF_REGISTRATION: + nammingcdoe = NAMING_CODE_ODU; + break; + case VesEventType::PM_SLICE: + break; + case VesEventType::FAULT_NOTIFICATION: + nammingcdoe = NAMING_CODE_ODU; + break; + default: + O1_LOG("\nO1 VesCommonHeader : This VES msg Type support in \ + getReportingEntityName is not available"); + break; + } + return nammingcdoe; } @@ -403,9 +538,9 @@ string VesCommonHeader::getNamingCode() * * ****************************************************************/ -uint64_t VesCommonHeader::getEpochTime() +double VesCommonHeader::getEpochTime() { - uint64_t epochTimeInMicrosec = std::chrono::duration_cast \ + double epochTimeInMicrosec = std::chrono::duration_cast \ \ (std::chrono::system_clock::now().time_since_epoch()).count(); return epochTimeInMicrosec; @@ -459,23 +594,55 @@ std::string VesCommonHeader::formatTime(time_t t) { return oss.str(); } + /******************************************************************* * - * @brief create Ves Event Name from Ves Event type + * @brief create Ves stndDefinedNamespace from Ves Event type * * @details * - * Function : getEventName + * Function : getstndDefinedNamespace + * + * Functionality: create Ves tndDefinedNamespace + * + * @params[in] IN - void + * @return value of string - success + * empty string - failure + * ****************************************************************/ + +string VesCommonHeader::getstndDefinedNamespace() +{ + string stndDefinedNamespace=""; + switch(mEventType) + { + case VesEventType::FAULT_NOTIFICATION: + stndDefinedNamespace = STND_DEFINED_NAMESPACE; + break; + default: + break; + } + return stndDefinedNamespace; + +} + +/******************************************************************* + * + * @brief Prepare VES Message + * + * @details + * + * Function : prepare * * Functionality: - * - create Ves Event Name from Ves Event type + * - prepare VES event * - * @params[in] IN - VesEventType , OUT - Ves Event Name - * @return ture - success + * @params[in] void + * @return true - success * false - failure * * ****************************************************************/ + bool VesCommonHeader::prepare(cJSON *commonHeader, \ VesEventType type) { @@ -489,7 +656,7 @@ bool VesCommonHeader::prepare(cJSON *commonHeader, \ //local utility variables: time_t intervalStartTime = getCurrentTime(); time_t intervalEndTime = intervalStartTime+60; /*adding 1 min to system time*/ - uint64_t startEpochTime = getEpochTime(); + double startEpochTime = getEpochTime(); mLastEpochTime = startEpochTime+60*100000; /*adding 1 min to epoch time*/ if(JsonHelper::addNodeToObject(commonHeader, "domain", \ @@ -534,18 +701,8 @@ bool VesCommonHeader::prepare(cJSON *commonHeader, \ { ret = false; } - else if(JsonHelper::addNodeToObject(commonHeader, "nfcNamingCode", \ - "") == 0) - { - ret = false; - } - else if(JsonHelper::addNodeToObject(commonHeader, "stndDefinedNamespace", \ - "") == 0) - { - ret = false; - } } - + if (mEventType == VesEventType::PNF_REGISTRATION) { @@ -562,7 +719,7 @@ bool VesCommonHeader::prepare(cJSON *commonHeader, \ ret = false; } else if(JsonHelper::addNodeToObject(commonHeader, "reportingEntityId", \ - "") == 0) + getReportingEntityId().c_str() ) == 0) { ret = false; } @@ -572,7 +729,7 @@ bool VesCommonHeader::prepare(cJSON *commonHeader, \ ret = false; } else if(JsonHelper::addNodeToObject(commonHeader, "sourceId", \ - "") == 0) + getSourceId().c_str() ) == 0) { ret = false; } @@ -582,23 +739,27 @@ bool VesCommonHeader::prepare(cJSON *commonHeader, \ ret = false; } else if(JsonHelper::addNodeToObject(commonHeader, "startEpochMicrosec", \ - (double)startEpochTime) == 0) + startEpochTime) == 0) { ret = false; } else if(JsonHelper::addNodeToObject(commonHeader, "lastEpochMicrosec", \ - (double)mLastEpochTime) == 0) + mLastEpochTime) == 0) { ret = false; } else if(JsonHelper::addNodeToObject(commonHeader, "nfNamingCode", \ - (type==VesEventType::PNF_REGISTRATION) ? \ - getNamingCode().c_str() : "") == 0) + getNamingCode().c_str() ) == 0) { ret = false; } else if(JsonHelper::addNodeToObject(commonHeader, "nfVendorName", \ - "") == 0) + "POC") == 0) + { + ret = false; + } + else if(JsonHelper::addNodeToObject(commonHeader, "nfcNamingCode", \ + getnfcNamingCode().c_str() ) == 0) { ret = false; } @@ -616,17 +777,21 @@ bool VesCommonHeader::prepare(cJSON *commonHeader, \ ret = false; } } - else + else { if(JsonHelper::addNodeToObject(commonHeader, "version", \ - VERSION_4_0_1) == 0) + COMMON_HEADER_VERSION) == 0) { ret = false; } } - + if(JsonHelper::addNodeToObject(commonHeader, "stndDefinedNamespace", \ + getstndDefinedNamespace().c_str())== 0) + { + ret = false; + } if(JsonHelper::addNodeToObject(commonHeader, "vesEventListenerVersion", \ - VES_EVENT_LISTENER_7_2_1) == 0) + VES_EVENT_LISNERT_VERSION) == 0) { ret = false; } diff --git a/src/o1/ves/VesCommonHeader.hpp b/src/o1/ves/VesCommonHeader.hpp index 96f850b92..0de58a88c 100644 --- a/src/o1/ves/VesCommonHeader.hpp +++ b/src/o1/ves/VesCommonHeader.hpp @@ -44,20 +44,24 @@ class VesCommonHeader{ bool prepare(cJSON *node, VesEventType type); private: - uint16_t getSequenceNo(); - uint16_t nextSequenceNo(); + double getSequenceNo(); + double nextSequenceNo(); string getEventTypeToStr(); string getEventType(); string getEventId(); string getPriority(); string getEventName(); + string getSourceId(); + string getReportingEntityId(); string getReportingEntityName(); string getSourceName(); string getNamingCode(); - uint64_t getEpochTime(); + string getnfcNamingCode(); + string getstndDefinedNamespace(); + double getEpochTime(); time_t getCurrentTime(); string formatTime(time_t); - uint64_t mLastEpochTime; + double mLastEpochTime; VesEventType mEventType; }; diff --git a/src/o1/ves/VesEvent.cpp b/src/o1/ves/VesEvent.cpp index b19391ba1..f06cb2a59 100644 --- a/src/o1/ves/VesEvent.cpp +++ b/src/o1/ves/VesEvent.cpp @@ -192,7 +192,7 @@ bool VesEvent::send() * @return string : Ves Event Name ******************************************************************/ -string VesEvent::getEventFieldName() +string VesEvent::getEventFieldName() { switch(mVesEventType) @@ -203,7 +203,11 @@ string VesEvent::getEventFieldName() } case VesEventType::FAULT_NOTIFICATION: { + #ifdef StdDef + return "stndDefinedFields"; + #else return "faultFields"; + #endif } case VesEventType::PM_SLICE: { diff --git a/src/o1/ves/VesEventHandler.cpp b/src/o1/ves/VesEventHandler.cpp index 09339cfcd..18e45a75d 100644 --- a/src/o1/ves/VesEventHandler.cpp +++ b/src/o1/ves/VesEventHandler.cpp @@ -24,6 +24,8 @@ #include "PnfRegistrationEvent.hpp" #include "SliceMeasurementEvent.hpp" #include "Message.hpp" +#include "CellStateChange.hpp" +#include "CellStateChangeStdDef.hpp" /******************************************************************* * @@ -99,6 +101,17 @@ bool VesEventHandler::prepare(VesEventType evtType, const Message* msg) O1_LOG("\nO1 VesEventHandler : Preparing VES PM Slice"); break; } + case VesEventType::FAULT_NOTIFICATION: + { + #ifdef StdDef + O1_LOG("\nO1 VesEventHandler : Preparing Standard VES fault notification"); + mVesEvent = new CellStateChangeStdDef(); + #else + O1_LOG("\nO1 VesEventHandler : Preparing VES fault notification"); + mVesEvent = new CellStateChange(); + #endif + break; + } default: O1_LOG("\nO1 VesEventHandler : VES message type does not exist "); diff --git a/src/o1/ves/VesUtils.hpp b/src/o1/ves/VesUtils.hpp index c9da3fff0..84df3bda8 100644 --- a/src/o1/ves/VesUtils.hpp +++ b/src/o1/ves/VesUtils.hpp @@ -24,12 +24,16 @@ #include #include "GlobalDefs.hpp" +#define StdDef 1 //config file path #define NETCONF_CONFIG "config/netconfConfig.json" #define OAM_VES_CONFIG "config/oamVesConfig.json" #define SMO_VES_CONFIG "config/smoVesConfig.json" //Common Header Macros +#define STND_DEFINED_NAMESPACE "3GPP-FaultSupervision" +#define COMMON_HEADER_VERSION "4.0.1" +#define VES_EVENT_LISNERT_VERSION "7.2.1" //Event Type #define EVENT_TYPE_5G "EventType5G" @@ -42,9 +46,11 @@ //Source Name #define ODU_HIGH "ODU-High" +#define SOURCE_ID "device_id_cc305d54-75b4-431b-adb2-eb6b9e541234" -//Naming Code +//Naming Code #define NAMING_CODE_ODU "7odu" +#define NFC_NAMING_CODE "NFC" //Timezone Offset #define TIME_ZONE_00_00 "+00:00" @@ -81,8 +87,13 @@ #define PM_REPORTING_ENTITY "ORAN-DEV" #define EVENT_TYPE_ORAN_COMPONENT_PM "O_RAN_COMPONENT_PM1min" +//NOTIFICATION Macros +#define FAULT_EVENTID "Alarm000000001" +#define FAULT_TYPE "alarm" +#define FAULT_EVENT_NAME "COMMUNICATIONS_ALARM" + enum class VesEventType -{ +{ PNF_REGISTRATION, FAULT_NOTIFICATION, PM_NOTIFICATION, -- 2.16.6