Implement Alarm Manager.[Issue-Id: ODUHIGH-243] 62/4862/5
authorVidhu <vidhu.pandey@hcl.com>
Mon, 19 Oct 2020 19:28:16 +0000 (00:58 +0530)
committerVidhu <vidhu.pandey@hcl.com>
Fri, 13 Nov 2020 12:05:57 +0000 (17:35 +0530)
Signed-off-by: Vidhu <vidhu.pandey@hcl.com>
Change-Id: Ib5faddb6b5d97ce928054ed148cdc0fafa1e643b

src/o1/Alarm.hpp [new file with mode: 0644]
src/o1/AlarmManager.cpp [new file with mode: 0644]
src/o1/AlarmManager.hpp [new file with mode: 0644]
src/o1/Singleton.hpp [new file with mode: 0644]
src/o1/o1_client/Alarm.h [new file with mode: 0644]

diff --git a/src/o1/Alarm.hpp b/src/o1/Alarm.hpp
new file mode 100644 (file)
index 0000000..ced49d0
--- /dev/null
@@ -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 <string>
+#include <string.h>
+#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 (file)
index 0000000..3ed8aca
--- /dev/null
@@ -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 <iostream>
+#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<map<uint16_t,Alarm>::iterator,bool> ret;
+   ret = mAlarmList.insert(pair<uint16_t,Alarm>(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<uint16_t,Alarm>::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<int, Alarm> 
+**********************************************************************/
+const map<uint16_t, Alarm>& AlarmManager::getAlarmList()const
+{
+   return mAlarmList;
+}
+
+
+/**********************************************************************
+         End of file
+**********************************************************************/
diff --git a/src/o1/AlarmManager.hpp b/src/o1/AlarmManager.hpp
new file mode 100644 (file)
index 0000000..a30fa9a
--- /dev/null
@@ -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 <map>
+#include "Alarm.hpp"
+#include "Singleton.hpp"
+
+using std::map;
+
+
+class AlarmManager : public Singleton<AlarmManager>
+{
+
+   friend Singleton<AlarmManager>;
+
+   private:
+   map<uint16_t,Alarm> mAlarmList;         
+
+   protected:
+   AlarmManager();    
+   ~AlarmManager();
+
+   public:
+   bool raiseAlarm(const Alarm& alarm);
+   bool clearAlarm(const uint16_t& alarmId);
+   bool clearAlarm(const Alarm& alarm );
+   const map<uint16_t, Alarm>& getAlarmList()const;
+
+};
+
+
+#endif
+
+/**********************************************************************
+         End of file
+**********************************************************************/
diff --git a/src/o1/Singleton.hpp b/src/o1/Singleton.hpp
new file mode 100644 (file)
index 0000000..2d61843
--- /dev/null
@@ -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 T>
+class Singleton
+{
+  public:
+  static T& instance();
+  static T  *instancePtr();
+
+  protected:
+  Singleton() { } 
+  ~Singleton() { }
+
+  private:
+  static T* mPtr;
+};
+
+/* Define and initialize the static instance pointer */
+template<class T>
+T* Singleton<T>::mPtr = 0;
+
+
+/********************************************************************** 
+   Description : Check if instance already exists.
+                 Create a new instance if none exists  
+   Params[In]  : None
+   Return      : Reference to the instance 
+***********************************************************************/
+template<class T>
+T& Singleton<T>::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<class T>
+T *Singleton<T>::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 (file)
index 0000000..3506f4b
--- /dev/null
@@ -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 <string.h>
+#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
+**********************************************************************/