From: Vidhu Date: Mon, 19 Oct 2020 19:28:16 +0000 (+0530) Subject: Implement Alarm Manager.[Issue-Id: ODUHIGH-243] X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F62%2F4862%2F5;p=o-du%2Fl2.git Implement Alarm Manager.[Issue-Id: ODUHIGH-243] Signed-off-by: Vidhu Change-Id: Ib5faddb6b5d97ce928054ed148cdc0fafa1e643b --- 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/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/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/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 +**********************************************************************/