summaryrefslogtreecommitdiffstats
path: root/data/mnet/Common/Alarm
diff options
context:
space:
mode:
Diffstat (limited to 'data/mnet/Common/Alarm')
-rw-r--r--data/mnet/Common/Alarm/Makefile47
-rw-r--r--data/mnet/Common/Alarm/include/AlarmTask.h151
-rw-r--r--data/mnet/Common/Alarm/include/alarm.h168
-rw-r--r--data/mnet/Common/Alarm/include/alarm_interface.h127
-rw-r--r--data/mnet/Common/Alarm/src/Makefile44
-rw-r--r--data/mnet/Common/Alarm/src/alarm_diskFile.cpp198
-rw-r--r--data/mnet/Common/Alarm/src/alarm_event.cpp196
-rw-r--r--data/mnet/Common/Alarm/src/alarm_main.cpp187
-rw-r--r--data/mnet/Common/Alarm/src/alarm_message.cpp101
-rw-r--r--data/mnet/Common/Alarm/src/alarm_modules.cpp441
-rw-r--r--data/mnet/Common/Alarm/src/alarm_socket.cpp445
-rw-r--r--data/mnet/Common/Alarm/src/alarm_sysCmd.cpp173
12 files changed, 2278 insertions, 0 deletions
diff --git a/data/mnet/Common/Alarm/Makefile b/data/mnet/Common/Alarm/Makefile
new file mode 100644
index 0000000..cad5689
--- /dev/null
+++ b/data/mnet/Common/Alarm/Makefile
@@ -0,0 +1,47 @@
+##########################################################
+#
+# (c) Copyright Cisco 2000
+# All Rights Reserved
+#
+# Use Examples:
+#
+# Case 1:
+# make all VOB=GP10 -
+# Places .out in VOB/bin directory
+#
+# Case 2:
+# make all VOB=GP10 APPDIR=Host\<Application Name>\<Source Directory> -
+# Places .o file(s) in VOB\$(APPDIR)\bin directory.
+#
+# <Application Name> = Name of Application directory
+# <Source Directory> = application sub directory where the calling
+# Makefile resides.
+#
+# Example: make all VOB=GP10 APPDIR=Host\vxTemplate\src
+#
+# (OPTIONAL) Append REPLACE - Replaces the List of directories
+# to be used in the SUBDIRS variable
+#
+# Example: make all VOB=GP10 APPDIR=Host\vxTemplate\src REPLACE=src
+#
+# Note: This make file must reference a VOB that
+# has a defs.mk in the top level directory.
+#
+##########################################################
+
+SUBDIRS = src
+
+# TOP_OF_VOB must be defined before including l3defs.mk
+TOP_OF_VOB = ..\..
+
+VOBDIR = $(TOP_OF_VOB)/$(VOB)
+
+# Allows a sub-set of the source code directories to be used
+
+ifneq ($(REPLACE),)
+ SUBDIRS = $(REPLACE)
+endif
+
+include $(VOBDIR)/l3defs.mk
+
+
diff --git a/data/mnet/Common/Alarm/include/AlarmTask.h b/data/mnet/Common/Alarm/include/AlarmTask.h
new file mode 100644
index 0000000..09bb68c
--- /dev/null
+++ b/data/mnet/Common/Alarm/include/AlarmTask.h
@@ -0,0 +1,151 @@
+/*********************************************************************/
+/* */
+/* (c) Copyright Cisco 2000 */
+/* All Rights Reserved */
+/* */
+/*********************************************************************/
+
+/*********************************************************************/
+/* */
+/* Version : 1.0 */
+/* Status : Under development */
+/* File : AlarmTask.h */
+/* Author(s) : Bhawani Sapkota */
+/* Create Date : 9/18/2000 */
+/* Description : This file contains Alarm task routines */
+/* */
+/*********************************************************************/
+/* REVISION HISTORY
+/*___________________________________________________________________*/
+/*----------+--------+-----------------------------------------------*/
+/* Name | Date | Reason */
+/*----------+--------+-----------------------------------------------*/
+/* Bhawani |09/28/00| Initial Draft */
+/*----------+--------+-----------------------------------------------*/
+/*********************************************************************/
+
+#ifndef _ALARMTASK_H_
+#define _ALARMTASK_H_ /* include once only */
+
+#include "Alarm.h"
+
+
+/* Include product specific code here */
+#if defined (MNET_PRODUCT_SPECIFIC_GS)
+#include "GSOsTune.h"
+#elif defined (MNET_PRODUCT_SPECIFIC_GMC)
+#include "vclogging.h"
+#elif defined (MNET_PRODUCT_SPECIFIC_GP10)
+#include "Logging/vclogging.h"
+#endif
+
+typedef struct _AlarmEntry_t
+{
+ AlarmCode_t code; // last error code
+ int id; // first alarm ID
+ Alarm_severity_t severity; // severity
+ ubyte4 utc; // outstanding since this time
+ int count;
+ struct _AlarmEntry_t *next;
+}AlarmEntry_t;
+
+
+class AlarmTask:public JCTask {
+public:
+
+ AlarmTask(char *);
+ ~AlarmTask();
+
+ int InitAlarmTask();
+
+ static int bootupTimeoutHandler();
+ static int entryPoint();
+
+ static int AlarmMain(void);
+ static char *srcName();
+
+ static AlarmTask *theAlarmTask;
+
+ // disk operation
+ STATUS saveAlarm(const char* msg);
+ STATUS renameOldLogFile();
+ STATUS getLastId(unsigned long *id);
+ int generateNextId();
+
+ AlarmEntry_t *findAlarmEntry(MNET_MODULE_ID mid, AlarmCode_t errorCode);
+ bool addAlarmEntry(MNET_MODULE_ID mid, MibTag moduleErrorTag, AlarmCode_t code, char *arg1=NULL, char *arg2=NULL);
+ bool delAlarmEntry(MNET_MODULE_ID mid, MibTag moduleErrorTag, AlarmCode_t code);
+ EnableDisableState_t updateOperationalState();
+
+
+ // module handling
+ AlarmCode_t getMdlStatus(MNET_MODULE_ID mid);
+ AlarmEntry_t *allocEntry(MNET_MODULE_ID id);
+
+ void printStatus();
+ void getOutstandingAlarmCount(ubyte1 &, ubyte1 &, ubyte1 &);
+
+ // message q operation
+ JC_STATUS msgqSend( unsigned int msgType, char * buffer, unsigned int nBytes);
+ JC_STATUS alarmSend(InterModuleAlarmMsgType_t mtype,
+ MNET_MODULE_ID mid,
+ MibTag moduleErrorTag=0,
+ AlarmCode_t alarm_code=EC_COMMON_NOERROR,
+ char *arg1=NULL,
+ char *arg2=NULL
+ );
+
+ //AMS Operation
+ bool sendSummaryUpdateToAms();
+ void reportNewAlarm(int id, MNET_MODULE_ID mid, AlarmCode_t ecode,
+ Alarm_severity_t severity, char * arg1=0, char * arg2=0);
+
+ //Operational State Management
+ EnableDisableState_t getOperationState();
+ void setOperationState(EnableDisableState_t opstate );
+
+ // Mib access control status
+ EnableDisableState_t getMibAcessControlState();
+ void setMibAcessControlState(EnableDisableState_t opstate);
+
+ void updateModuleLastError(MNET_MODULE_ID mid, MibTag moduleErrorTag);
+ void setModuleLastError(MibTag moduleErrorTag, AlarmCode_t alarm_code);
+
+ // startup and quit
+ void quit();
+ int startup();
+ void closeSocket();
+
+
+private:
+ JCMsgQueue *jcMsgQ;
+ JCCTimer *initTimer;
+ char *_mnetbase; /* holds MNET_BASE environment variable */
+ char *_logfilename; /* holds absolute path of the logfilename */
+
+ char *_sourceName; /* holds the source name */
+ char *_sourceType; /* type of the source (Gp, Gmc, Itp, */
+
+ char *_msgRecvBuff; /* holds received message */
+ AlarmEntry_t *_ms[MNET_MAX_MODULE_IDS]; /* current module Alarm Status */
+ AlarmEntry_t *_ap; /* Alarm pools */
+
+ int _statistics[2][Alarm_max_severity];
+
+ void populateSourceName();
+
+ //status variables
+ bool _quit;
+ bool _mibAccessState;
+
+ static bool isOneCreated;
+
+ // Disallow the following functions
+ AlarmTask();
+ AlarmTask(const AlarmTask&);
+ AlarmTask& operator=(const AlarmTask&);
+ int operator== (const AlarmTask&) const;
+};
+
+
+#endif
diff --git a/data/mnet/Common/Alarm/include/alarm.h b/data/mnet/Common/Alarm/include/alarm.h
new file mode 100644
index 0000000..ba5edd0
--- /dev/null
+++ b/data/mnet/Common/Alarm/include/alarm.h
@@ -0,0 +1,168 @@
+/*********************************************************************/
+/* */
+/* (c) Copyright Cisco 2000 */
+/* All Rights Reserved */
+/* */
+/*********************************************************************/
+
+/*********************************************************************/
+/* */
+/* Version : 1.0 */
+/* Status : Under development */
+/* File : AlarmTask.h */
+/* Author(s) : Bhawani Sapkota */
+/* Create Date : 9/18/2000 */
+/* Description : This file contains alarm task basic defination */
+/* routines */
+/* */
+/*********************************************************************/
+/* REVISION HISTORY
+/*___________________________________________________________________*/
+/*----------+--------+-----------------------------------------------*/
+/* Name | Date | Reason */
+/*----------+--------+-----------------------------------------------*/
+/* Bhawani |07/14/00| Initial Draft */
+/* Bhawani |11/20/00| resturctured to share among GP, GMS and GS */
+/*----------+--------+-----------------------------------------------*/
+/*********************************************************************/
+
+
+#if !defined(_ALARM_H_)
+#define _ALARM_H_
+
+#include "AlarmCode.h"
+#include "Os/JCMsgQueue.h"
+#include "Os/JCModule.h"
+#include "Os/JCCTimer.h"
+#include "Os/JCTask.h"
+
+#include "alarm_prodSpec.h"
+
+typedef unsigned short ubyte2;
+typedef unsigned long ubyte4;
+typedef unsigned char ubyte1;
+
+typedef short sbyte2;
+typedef long sbyte4;
+
+
+#define ALARM_q_maxMsgs 32
+#define ALARM_q_maxMsgLength 100
+#define ALARM_q_option MSG_Q_PRIORITY
+#define ALARM_q_timeout 18000 /* 5 minutes */
+
+#define ALARM_task_name "tAlarm"
+#define ALARM_mib_lock_timeout 7200 /* 2 minutes */
+
+#define ALARM_record_length 70
+#define ALARM_max_records 58
+#define ALARM_max_outstanding 50
+
+
+/* It is assumeed that current working directory is ViperCall */
+
+#define ALARM_logFile "/Alarm/alarm.log"
+#define ALARM_logFileMaxSize 128
+#define ALARM_dirChar '/'
+
+#define ALARM_maxMsgSize 1024
+#define ALARM_defaultRecvBuffer 128
+#define ALARM_optionalArgSize 40
+
+
+#define ALARM_monStation "QSEvent"
+#define ALARM_mchResponse "mchResponse"
+
+typedef enum Alarm_severity
+{
+ Alarm_critical=0,
+ Alarm_major,
+ Alarm_minor,
+ Alarm_info,
+ Alarm_max_severity
+} Alarm_severity_t;
+
+
+typedef enum
+{
+ InterModuleAlarmMsgTypeClearAlarm = 0,
+ InterModuleAlarmMsgTypeRaiseAlarm,
+ InterModuleAlarmMsgTypeShutdown,
+ InterModuleAlarmMsgTypeReboot
+}InterModuleAlarmMsgType_t;
+
+
+typedef struct
+{
+ ubyte1 senderId; /* message originator */
+ InterModuleAlarmMsgType_t msgType; /* message type (MT_TRAP) */
+ MNET_MODULE_ID srcModuleId; /* Alarm source module ID */
+ MibTag errorTag; /* This module's ErrorTag */
+ AlarmCode_t code; /* Alarm code */
+ char arg1[ALARM_optionalArgSize]; /* argument 1 */
+ char arg2[ALARM_optionalArgSize]; /* argument 2 */
+}InterModuleAlarmMsg_t;
+
+
+typedef enum
+{
+ stateDisabled=0,
+ stateEnabled=1
+} EnableDisableState_t;
+
+
+/* Printing and sending to logging module */
+void alarm_print(char *format, ...);
+
+#ifdef _UT
+void HexDumper(ubyte1 *buffer, int length);
+#define alarm_debug(XX) printf("[ALARM TRACE] %s ->", fname); alarm_print XX
+#define alarm_error(XX) printf("[Alarm Error] %s ->", fname); alarm_print XX
+#define alarm_warning(XX) printf("[Alarm Warning] %s ->", fname); alarm_print XX
+#define alarm_dump(x,y); HexDumper(x, y);
+#define alarm_fenter(XX); static char fname[] = XX;
+#define alarm_fexit();
+#else
+#define alarm_fenter(XXX); \
+ DBG_FUNC(XXX, MY_LOGID); \
+ DBG_ENTER(); \
+
+#define alarm_fexit(); DBG_LEAVE();
+
+#define alarm_debug(XX) DBG_TRACE XX
+#define alarm_error(XX) DBG_ERROR XX
+#define alarm_warning(XX) DBG_WARNING XX
+#define alarm_dump(x,y); DBG_HEXDUMP(x,y);
+#endif
+
+
+/* defined at alarm_main module */
+int alarmTask();
+int alarm_taskCreate();
+void alarm_taskQuit ();
+void alarm_msgPrint(char *format, ...);
+void alarm_rebootHandler ( int startType );
+
+
+/* In file alarm_modules.cpp */
+void alarm_rptMdlStatus(int id, int mid, int ecode, int severity=Alarm_critical,
+ char* arg1= (char *) NULL, char* arg2= (char *) NULL);
+void alarm_printStatus();
+
+
+/* In file alarm_message.cpp */
+void alarm_processMsg(char *inComingMsg);
+
+/* It will go to alarm_event.cpp */
+void alarm_clientMsg (char *, short, unsigned long);
+void alarm_broadcast(const char *msg);
+int alarm_generateNextId();
+
+
+/* alarm_diskFile.cpp */
+STATUS alarm_renameOldLogFile();
+
+/* TimeSync api from Time Sync module */
+extern void time_syncTime();
+
+#endif
diff --git a/data/mnet/Common/Alarm/include/alarm_interface.h b/data/mnet/Common/Alarm/include/alarm_interface.h
new file mode 100644
index 0000000..9d30b45
--- /dev/null
+++ b/data/mnet/Common/Alarm/include/alarm_interface.h
@@ -0,0 +1,127 @@
+/*********************************************************************/
+/* */
+/* (c) Copyright Cisco 2000 */
+/* All Rights Reserved */
+/* */
+/*********************************************************************/
+
+/*********************************************************************/
+/* */
+/* Version : 1.0 */
+/* Status : Under development */
+/* File : AlarmTask.h */
+/* Author(s) : Bhawani Sapkota */
+/* Create Date : 9/18/2000 */
+/* Description : This file contains interface defination between */
+/* Alarm Source (GP, GMC, GS) and Alarm Monitoring */
+/* Server (APM1) */
+/* */
+/*********************************************************************/
+/* REVISION HISTORY
+/*___________________________________________________________________*/
+/*----------+--------+-----------------------------------------------*/
+/* Name | Date | Reason */
+/*----------+--------+-----------------------------------------------*/
+/* Bhawani |07/14/00| Initial Draft */
+/* Bhawani |11/20/00| resturctured to share among GP, GMS and GS */
+/* Bhawani |12/05/00| Added UDP server and client port so that the */
+/* | | server and clients can reside on the same IP */
+/* Bhawani |12/05/00| swaped the server and client port to make the */
+/* | | original port as the server port. */
+/*----------+--------+-----------------------------------------------*/
+/*********************************************************************/
+
+
+#if !defined(_ALARM_INTERFACE_H_)
+#define _ALARM_INTERFACE_H_
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+#define ALARM_viperCellNameMaxSize 41
+#define ALARM_viperCellIpMaxSize 16
+#define ALARM_unknownAlarmId 0x00
+
+/* Alarm Server's IP address is Gate Keeper's IP address */
+
+/* Alarm Client/Server's Universal UPD ports */
+#define ALARM_interfaceUdpPortClient 12791
+#define ALARM_interfaceUdpPortServer 11788
+
+#define ALARM_periodicUpdateInterval 300 /* seconds */
+
+
+/* Alarm Source Type */
+#define ALARM_srcTypViperCell 128
+#define ALARM_srcTypViperBase 129
+
+
+/* Alarm Message Type */
+#define ALARM_msgTypSummaryUpdate 1
+#define ALARM_msgTypAlarmEvent 2
+
+typedef char sbyte1;
+typedef short sbyte2;
+typedef long sbyte4;
+
+typedef unsigned char ubyte1;
+typedef unsigned short ubyte2;
+typedef unsigned long ubyte4;
+
+/* Message header */
+typedef struct AlarmInterfaceMsgHeader_{
+ ubyte1 alarmSrcType;
+ ubyte1 alarmMsgType;
+ ubyte2 alarmMsgLen;
+}AlarmInterfaceMsgHeader;
+
+#define ALARM_interfaceMsgHdrLen 4
+
+/* Summary update data */
+typedef struct AlarmSummaryUpdateData_{
+ ubyte4 alarmSrcIp;
+ sbyte1 alarmSrcName[ALARM_viperCellNameMaxSize];
+ ubyte1 alarmCriticalCount;
+ ubyte1 alarmMajorCount;
+ ubyte1 alarmMinorCount;
+}AlarmSummaryUpdateData;
+
+#define ALARM_summaryUpdateDataLen (7 + ALARM_viperCellNameMaxSize)
+#define ALARM_summaryUpdateMsgLen (ALARM_interfaceMsgHdrLen + ALARM_summaryUpdateDataLen + sizeof(long))
+
+#define ALARM_eventDataLen (28 + ALARM_viperCellNameMaxSize)
+#define ALARM_eventMsgLen (ALARM_interfaceMsgHdrLen + ALARM_eventDataLen + sizeof(long))
+
+
+/* Stubs for new event data */
+typedef struct AlarmEventData_ {
+ ubyte4 alarmId;
+ ubyte4 alarmCode;
+ ubyte4 alarmTimestamp;
+ ubyte4 alarmSrcIp;
+ sbyte1 alarmSrcModuleName[ALARM_viperCellNameMaxSize];
+ ubyte4 alarmSrcModuleId;
+ ubyte4 opt1;
+ ubyte4 opt2;
+}AlarmEventData;
+
+
+/* Alarm Complete message */
+typedef long Align;
+typedef struct Alarm
+{
+ AlarmInterfaceMsgHeader hdr;
+ union {
+ AlarmSummaryUpdateData summaryUpdateData;
+ AlarmEventData eventData;
+ }body;
+ Align x;
+}AlarmViperCellToAmsMsg;
+
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* _ALARM_INTERFACE_H_ */
diff --git a/data/mnet/Common/Alarm/src/Makefile b/data/mnet/Common/Alarm/src/Makefile
new file mode 100644
index 0000000..146a01d
--- /dev/null
+++ b/data/mnet/Common/Alarm/src/Makefile
@@ -0,0 +1,44 @@
+
+##########################################################
+#
+# (c) Copyright Cisco 2000
+# All Rights Reserved
+#
+# Use Examples:
+#
+# Case 1:
+# make all VOB=GP10 -
+# Places .out in VOB/bin directory
+#
+# Case 2:
+# make all VOB=GP10 APPDIR=Host\<Application Name>\<Source Directory> -
+# Places .o file(s) in VOB\$(APPDIR)\bin directory.
+#
+# <Application Name> = Name of Application directory
+# <Source Directory> = application sub directory where the calling
+# Makefile resides.
+#
+# Example: make all VOB=GP10 APPDIR=Host\vxTemplate\src
+#
+#
+# Note: This make file must reference a VOB that
+# has a defs.mk in the top level directory.
+#
+##########################################################
+
+# TOP_OF_VOB must be defined before including l3defs.mk
+TOP_OF_VOB = ..\..
+
+# Name of this App's Directory
+THIS_APP_DIR = Alarm
+
+VOB2DIR = $(TOP_OF_VOB)\..\$(VOB)
+BINDIR = ..\bin
+
+include $(VOB2DIR)\l3defs.mk
+
+all: $(MODULE_OBJS)
+
+cleanall:
+ @for %f in ($(notdir $(MODULE_OBJS))) do \
+ $(RM) ..\bin\%f
diff --git a/data/mnet/Common/Alarm/src/alarm_diskFile.cpp b/data/mnet/Common/Alarm/src/alarm_diskFile.cpp
new file mode 100644
index 0000000..e7d2564
--- /dev/null
+++ b/data/mnet/Common/Alarm/src/alarm_diskFile.cpp
@@ -0,0 +1,198 @@
+
+/*********************************************************************/
+/* */
+/* (c) Copyright Cisco 2000 */
+/* All Rights Reserved */
+/* */
+/*********************************************************************/
+
+/*********************************************************************/
+/* */
+/* Version : 1.0 */
+/* Status : Under development */
+/* File : AlarmTask.h */
+/* Author(s) : Bhawani Sapkota */
+/* Create Date : 07/11/99 */
+/* Description : This file contains routines to perform disk I/O to */
+/* save alarm to the disk file. */
+/* */
+/*********************************************************************/
+/* REVISION HISTORY
+/*___________________________________________________________________*/
+/*----------+--------+-----------------------------------------------*/
+/* Name | Date | Reason */
+/*----------+--------+-----------------------------------------------*/
+/* Bhawani |09/28/00| Initial Draft */
+/* Bhawani |11/20/00| resturctured to share among GP, GMS and GS */
+/*----------+--------+-----------------------------------------------*/
+/*********************************************************************/
+#include "AlarmTask.h"
+
+#include "dirent.h"
+#include "stat.h"
+#include "time.h"
+#include "string.h"
+static unsigned long CyclicFileRecordIndex = 0;
+
+STATUS AlarmTask::saveAlarm(const char* msg)
+{
+ FILE *alarmfd;
+
+ alarm_fenter("AlarmTask::saveAlarm");
+
+ // Opens for reading and writing;
+ alarmfd = fopen(_logfilename, "r+");
+ if (alarmfd == NULL)
+ {
+ alarm_error(("Could not open alarm log file %s (Reason: %s)\n", _logfilename, strerror(errno)));
+ alarm_fexit();
+ return ERROR;
+ }
+
+ long fpos = ALARM_record_length*CyclicFileRecordIndex++;
+ CyclicFileRecordIndex = CyclicFileRecordIndex%ALARM_max_records;
+
+ fseek(alarmfd, fpos, SEEK_SET);
+
+ fputs(msg, alarmfd);
+ fclose(alarmfd);
+ alarm_debug(("Alarm Message successfully saved\n"));
+ alarm_fexit();
+ return OK;
+}
+
+STATUS AlarmTask::renameOldLogFile()
+{
+ struct stat fileStat;
+
+ alarm_fenter("alarm_renameOldLogFile");
+
+ /* check if old Alarrm log file exists */
+ if (stat (_logfilename, &fileStat) == OK)
+ {
+ /* The file exist */
+ struct tm localTime;
+ struct tm *ltime = &localTime;
+ time_t longTime;
+ char *pdest;
+ char newFileName[ALARM_logFileMaxSize];
+
+ longTime = time(NULL);
+
+ ltime = localtime(&longTime);
+
+ strcpy(newFileName, _logfilename);
+
+ /* Assumes that file name is long enough */
+ pdest = strrchr(newFileName, ALARM_dirChar);
+ if( pdest != NULL )
+ {
+ sprintf(pdest+1, "AlarmLogAsOf_%d-%d-%d,%d:%d", ltime->tm_mon+1, ltime->tm_mday,
+ ltime->tm_year+1900,ltime->tm_hour, ltime->tm_min);
+ } else {
+ sprintf(newFileName, "AlarmLogAsOf_%d-%d-%d,%d:%d", ltime->tm_mon+1, ltime->tm_mday,
+ ltime->tm_year+1900,ltime->tm_hour, ltime->tm_min);
+ }
+ alarm_debug(("Renaming %s file to %s\n", _logfilename, newFileName));
+ if (rename(_logfilename, newFileName) == ERROR)
+ {
+
+ /* rename failed */
+ FILE *alarmfd;
+
+ alarm_error(("Could not rename old file (Reason: %s)\n", strerror(errno)));
+ alarm_warning(("Truncating the old alarm file: %s\n", _logfilename));
+
+ alarmfd = fopen(_logfilename, "w");
+ if (alarmfd == NULL)
+ {
+ alarm_error(("Could not truncate file(Reason: %s)\n",strerror(errno)));
+ } else {
+ fclose(alarmfd);
+ }
+
+ } else {
+ alarm_debug(("Old alarm file successfully renamed to %s\n", newFileName));
+ }
+
+ } else {
+ alarm_warning(("Old alarm log file \"%s\" does not exist.\n", _logfilename));
+ }
+
+ alarm_fexit();
+ return OK;
+
+}
+
+
+STATUS AlarmTask::getLastId(unsigned long *id)
+{
+ FILE *alarmfd;
+ struct stat statBuff;
+ alarm_fenter("AlarmTask::getLastId");
+ STATUS status;
+
+
+ status = stat(_logfilename, &statBuff);
+
+
+ if ( status == ERROR // file does not exist
+ || statBuff.st_size == 0 // newly created
+ || statBuff.st_size % ALARM_record_length != 0 // corrupt file
+ || statBuff.st_size > ALARM_max_records*ALARM_record_length // corrupt file
+ )
+ {
+ // if size is a zero, there was no alarm file
+ *id = 1;
+ CyclicFileRecordIndex = 0;
+ alarmfd = fopen(_logfilename, "w"); // truncate file
+ if (alarmfd != NULL)
+ fclose(alarmfd);
+ else
+ {
+ alarm_error(("Could not create %s for writing: %s\n", _logfilename, strerror(errno)));
+ }
+
+ } else {
+
+ alarm_debug(("Current Alarm disk file size = %d\n", statBuff.st_size));
+
+ if (statBuff.st_size < ALARM_max_records*ALARM_record_length)
+ {
+
+ // the size less then max size
+ CyclicFileRecordIndex = statBuff.st_size / ALARM_record_length;
+ *id = CyclicFileRecordIndex+1;
+ } else {
+ unsigned long id1, id2, i;
+
+ alarmfd= fopen(_logfilename, "r");
+ if (alarmfd == NULL)
+ {
+ alarm_error(("Cannot open() Alarm disk file %s to read (Reason: %s)\n", _logfilename, strerror(errno)));
+ *id =1;
+ CyclicFileRecordIndex = 0;
+ status = ERROR;
+ } else {
+ // file is ALARM_max_records*ALARM_record_length size
+ fseek(alarmfd, 0, SEEK_SET);
+ fscanf(alarmfd, "%u", &id1);
+ for(i=1; i< ALARM_max_records; i++)
+ {
+ fseek(alarmfd, i*ALARM_record_length, SEEK_SET);
+ fscanf(alarmfd, "%u", &id2);
+ if(id1> id2)
+ {
+ break;
+ } else {
+ id1 = id2;
+ }
+ }
+ CyclicFileRecordIndex = i % ALARM_max_records;
+ *id = id1+1;
+ }
+ }
+ }
+ alarm_fexit();
+ return status;
+}
diff --git a/data/mnet/Common/Alarm/src/alarm_event.cpp b/data/mnet/Common/Alarm/src/alarm_event.cpp
new file mode 100644
index 0000000..1fb3713
--- /dev/null
+++ b/data/mnet/Common/Alarm/src/alarm_event.cpp
@@ -0,0 +1,196 @@
+
+/*********************************************************************/
+/* */
+/* (c) Copyright Cisco 2000 */
+/* All Rights Reserved */
+/* */
+/*********************************************************************/
+
+/*********************************************************************/
+/* */
+/* Version : 1.0 */
+/* Status : Under development */
+/* File : AlarmTask.h */
+/* Author(s) : Bhawani Sapkota */
+/* Create Date : 07/11/99 */
+/* Description : contains alarm module message that interact with */
+/* other module . */
+/* */
+/*********************************************************************/
+/* REVISION HISTORY
+/*___________________________________________________________________*/
+/*----------+--------+-----------------------------------------------*/
+/* Name | Date | Reason */
+/*----------+--------+-----------------------------------------------*/
+/* Bhawani |07/11/99| Initial Draft */
+/* Bhawani |11/20/00| resturctured to share among GP, GMS and GS */
+/*----------+--------+-----------------------------------------------*/
+
+#ifndef _ALARM_EVENT_CPP_
+#define _ALARM_EVENT_CPP_
+
+#include "AlarmTask.h"
+
+void alarm_clientMsg ( char * message, // the message from the client
+ short size, // size of the message
+ unsigned long clientId // unique client ID of the requester client
+ )
+{
+
+ alarm_fenter("alarm_clientMsg");
+ alarm_debug(("Message receive from client (ID = %d)", clientId));
+ alarm_debug(("%s\n", message));
+ alarm_fexit();
+}
+
+
+void alarm_broadcast(const char *msg)
+{
+ int len;
+ alarm_fenter("alarm_broadcast");
+ fflush(stdout);
+
+ len = strlen(msg);
+ //TcpSrvSendResponse(msg, len, kAlarmGpName);
+ alarm_debug(("Alarm message was sent\n"));
+ alarm_fexit();
+}
+
+JC_STATUS AlarmTask::msgqSend(unsigned int msgType, char * buffer, unsigned int nBytes)
+{
+ return jcMsgQ->JCMsgQSend(this->jcMsgQ, msgType, MY_MODULE_ID, buffer, nBytes, JC_NO_WAIT, JC_MSG_Q_FIFO);
+}
+
+
+JC_STATUS AlarmTask::alarmSend
+ (
+ InterModuleAlarmMsgType_t mtype,
+ MNET_MODULE_ID mid,
+ MibTag moduleErrorTag,
+ AlarmCode_t alarm_code,
+ char *arg1,
+ char *arg2
+ )
+{
+ InterModuleAlarmMsg_t alarmMsg;
+
+ memset(&alarmMsg, 0, sizeof(InterModuleAlarmMsg_t));
+
+ alarmMsg.errorTag = moduleErrorTag;
+ alarmMsg.code = alarm_code;
+ alarmMsg.senderId = (ubyte1) MY_MODULE_ID;
+ alarmMsg.msgType = mtype;
+ alarmMsg.srcModuleId = mid;
+
+ if (NULL != arg1)
+ {
+ strncpy(alarmMsg.arg1, arg1, ALARM_optionalArgSize-1);
+ }
+
+ if (NULL != arg2)
+ {
+ strncpy(alarmMsg.arg2, arg2, ALARM_optionalArgSize-1);
+ }
+
+ return AlarmTask::theAlarmTask->msgqSend
+ (InterModuleAlarmMsgTypeRaiseAlarm,
+ (char *) &alarmMsg,
+ sizeof(InterModuleAlarmMsg_t));
+
+}
+
+extern "C" JC_STATUS alarm_raise(MNET_MODULE_ID mid, MibTag moduleErrorTag, AlarmCode_t alarm_code)
+{
+ return AlarmTask::theAlarmTask->alarmSend(InterModuleAlarmMsgTypeRaiseAlarm, mid, moduleErrorTag, alarm_code);
+
+}
+
+extern "C" JC_STATUS alarm_raise_args(MNET_MODULE_ID mid, MibTag moduleErrorTag, AlarmCode_t alarm_code, int arg1, int arg2)
+{
+ char pszArg1[ALARM_optionalArgSize];
+ char pszArg2[ALARM_optionalArgSize];
+ sprintf (pszArg1, "%d", arg1);
+ sprintf (pszArg2, "%d", arg2);
+
+ return AlarmTask::theAlarmTask->alarmSend(InterModuleAlarmMsgTypeRaiseAlarm, mid, moduleErrorTag, alarm_code, pszArg1, pszArg2);
+
+}
+
+extern "C" JC_STATUS alarm_clear(MNET_MODULE_ID mid, MibTag moduleErrorTag, AlarmCode_t alarm_code)
+{
+ return AlarmTask::theAlarmTask->alarmSend(InterModuleAlarmMsgTypeClearAlarm, mid, moduleErrorTag, alarm_code);
+}
+
+EnableDisableState_t AlarmTask::getOperationState()
+{
+ long opState;
+ oam_getMibIntVar(MY_MIB_OPERATION_STATE, &opState);
+ return (EnableDisableState_t) opState;
+}
+
+
+
+void AlarmTask::setOperationState(EnableDisableState_t opstate )
+{
+ EnableDisableState_t state = getOperationState();
+
+ if(state != opstate)
+ {
+ oam_setMibIntVar(MY_MODULE_ID, MY_MIB_OPERATION_STATE, opstate);
+ }
+}
+
+
+EnableDisableState_t AlarmTask::getMibAcessControlState()
+{
+ long opState;
+ oam_getMibIntVar(MY_MIB_ACCESS_CONTROL_TAG, &opState);
+ return (EnableDisableState_t) opState;
+}
+
+
+void AlarmTask::setMibAcessControlState(EnableDisableState_t opstate )
+{
+ EnableDisableState_t state = getMibAcessControlState();
+ alarm_fenter("AlarmTask::setMibAcessControlState");
+
+ if(state != opstate)
+ {
+ oam_setMibIntVar(MY_MODULE_ID, MY_MIB_ACCESS_CONTROL_TAG, opstate);
+ }
+
+ // local mib status
+ _mibAccessState = (opstate == stateEnabled);
+
+ if (_mibAccessState)
+ {
+ // This is the first time
+ initTimer->cancelTimer();
+ alarm_debug (("Mib access is now enabled\n"));
+ }
+ alarm_fexit();
+}
+
+void AlarmTask::setModuleLastError(MibTag moduleErrorTag, AlarmCode_t alarm_code)
+{
+ oam_setMibIntVar(MY_MODULE_ID, moduleErrorTag, alarm_code);
+}
+
+void AlarmTask::populateSourceName()
+{
+ const int kDisplayStringSize = 256;
+ char name[kDisplayStringSize];
+
+ memset(name, 0, kDisplayStringSize);
+ oam_getMibByteAry(MY_MIB_SOURCE_NAME, (ubyte1 *) name, kDisplayStringSize-1);
+ _sourceName = new char[strlen(name+1)];
+ strcpy(_sourceName, name);
+}
+
+char * AlarmTask::srcName()
+{
+ return theAlarmTask->_sourceName;
+}
+
+
+#endif /* _ALARM_EVENT_CPP_ */ \ No newline at end of file
diff --git a/data/mnet/Common/Alarm/src/alarm_main.cpp b/data/mnet/Common/Alarm/src/alarm_main.cpp
new file mode 100644
index 0000000..19682dc
--- /dev/null
+++ b/data/mnet/Common/Alarm/src/alarm_main.cpp
@@ -0,0 +1,187 @@
+/*********************************************************************/
+/* */
+/* (c) Copyright Cisco 2000 */
+/* All Rights Reserved */
+/* */
+/*********************************************************************/
+
+/*********************************************************************/
+/* */
+/* Version : 1.0 */
+/* Status : Under development */
+/* File : AlarmTask.h */
+/* Author(s) : Bhawani Sapkota */
+/* Create Date : 9/18/2000 */
+/* Description : This file contains main routines for the alarm task */
+/* */
+/*********************************************************************/
+/* REVISION HISTORY
+/*___________________________________________________________________*/
+/*----------+--------+-----------------------------------------------*/
+/* Name | Date | Reason */
+/*----------+--------+-----------------------------------------------*/
+/* Bhawani |09/28/00| Initial Draft */
+/* Bhawani |11/20/00| resturctured to share among GP, GMS and GS */
+/*----------+--------+-----------------------------------------------*/
+/*********************************************************************/
+
+
+#include "AlarmTask.h"
+#include "ctype.h"
+
+#if defined( _TCP_SERVER_EXIST)
+#include "TcpServer/TcpSrvApi.h"
+#endif
+
+AlarmTask * AlarmTask::theAlarmTask = NULL;
+
+bool AlarmTask::isOneCreated = false;
+
+AlarmTask::~AlarmTask()
+{
+ alarm_fenter("AlarmTask::~AlarmTask");
+ alarm_debug(("Alarm Task instance is being deleted"));
+ delete jcMsgQ;
+ delete initTimer;
+ alarm_fexit();
+}
+
+int AlarmTask::entryPoint()
+{
+
+ return theAlarmTask->startup();
+
+}
+
+int AlarmTask::startup()
+{
+ int status;
+ unsigned int msgType;
+ MNET_MODULE_ID senderId;
+ unsigned int recvMsgsize;
+
+
+ alarm_fenter("alarmTask");
+
+ // Rename the old alarm file
+ // alarm_renameOldLogFile();
+
+#if defined( _TCP_SERVER_EXIST)
+
+ // Register TCP server call back function
+ TcpSrvRegHand(kAlarmGpName, // Client Group Name (<= kClientGpNameMax)
+ alarm_clientMsg); // Function pointer to be called
+
+#endif
+
+ /* now go into the message loop */
+ JCTaskEnterLoop();
+ _quit = false;
+
+ while(_quit == false)
+ {
+
+ /* get message from queue; if necessary wait for a maximum of ALARM_q_timeout ticks */
+ status = jcMsgQ->JCMsgQReceive(&jcMsgQ, &msgType, &senderId, _msgRecvBuff, &recvMsgsize, ALARM_q_timeout);
+ if (status == ERROR)
+ {
+ if (errno == S_objLib_OBJ_TIMEOUT)
+ {
+
+ /* Send heartbeat message to AMS in case it was down and now it has been up */
+ sendSummaryUpdateToAms();
+ continue;
+ }
+
+ }
+ else
+ {
+
+ alarm_processMsg(_msgRecvBuff);
+ sendSummaryUpdateToAms();
+ }
+ }
+
+ JCTaskNormExit();
+
+ closeSocket();
+
+ isOneCreated = false;
+ //delete theAlarmTask;
+ theAlarmTask = NULL;
+
+ /* The application need to unsunscribe trap before exiting. */
+ alarm_debug(("Alarm Task is exiting ... \n"));
+ alarm_fexit();
+ return OK;
+}
+
+
+/* print alarm messages */
+void alarm_print(char *format, ...)
+{
+ va_list marker;
+ va_start( marker, format ); /* Initialize variable arguments. */
+ vprintf(format, marker);
+ fflush(stdout);
+ va_end( marker ); /* Reset variable arguments. */
+ return;
+
+}
+
+#ifdef _UT
+void HexDumper(ubyte1 *buffer, int length )
+/*++ Purpose:
+Put the inbound data in a hex dump format
+Arguments:
+buffer - points to the extension control block
+length - specifies the number of bytes to dump --*/
+{
+ int size;
+ int i;
+ int dwPos = 0;
+ while (length > 0) {
+ //
+ // Take min of 16 or length
+ //
+ size = min(16, length );
+ //
+ // Build text line
+ //
+ printf(" %04X ", dwPos );
+ for (i = 0; i < size; i++)
+ {
+ printf("%02X ", buffer[i] );
+ }
+ //
+ // Add spaces for short lines
+ //
+ while (i < 16)
+ {
+ printf(" " );
+ i++;
+ }
+ //
+ // Add ASCII chars
+ //
+ for (i = 0; i < size; i++)
+ {
+ if (isprint(buffer[i]))
+ {
+ printf("%c", buffer[i] );
+ } else {
+ printf("." );
+ }
+ }
+
+ printf("\n");
+ //
+ // Advance positions
+ //
+ length -= size;
+ dwPos += size;
+ buffer += size;
+ }
+}
+#endif /* _UT */
+
diff --git a/data/mnet/Common/Alarm/src/alarm_message.cpp b/data/mnet/Common/Alarm/src/alarm_message.cpp
new file mode 100644
index 0000000..a629ba6
--- /dev/null
+++ b/data/mnet/Common/Alarm/src/alarm_message.cpp
@@ -0,0 +1,101 @@
+
+/*********************************************************************/
+/* */
+/* (c) Copyright Cisco 2000 */
+/* All Rights Reserved */
+/* */
+/*********************************************************************/
+
+/*********************************************************************/
+/* */
+/* Version : 1.0 */
+/* Status : Under development */
+/* File : AlarmTask.h */
+/* Author(s) : Bhawani Sapkota */
+/* Create Date : 9/18/2000 */
+/* Description : This file contains alarm task message processing */
+/* routines */
+/* */
+/*********************************************************************/
+/* REVISION HISTORY
+/*___________________________________________________________________*/
+/*----------+--------+-----------------------------------------------*/
+/* Name | Date | Reason */
+/*----------+--------+-----------------------------------------------*/
+/* Bhawani |07/14/00| Initial Draft */
+/* Bhawani |11/20/00| resturctured to share among GP, GMS and GS */
+/*----------+--------+-----------------------------------------------*/
+/*********************************************************************/
+
+
+
+#ifndef _ALARM_MESSAGE_CPP_
+#define _ALARM_MESSAGE_CPP_
+
+#include "AlarmTask.h"
+
+
+void alarm_processTrap(TrapMsg *trapMsg)
+{
+ /* The Oam Message */
+ MibTag tag = trapMsg->mibTag;
+ int table = MIB_TBL(tag);
+ int mid = MIB_ITM(tag) - 1; // need to do this
+
+ alarm_fenter("alarm_processOamMsg");
+
+ alarm_fexit();
+ return;
+}
+
+void alarm_processAlarmMsg(InterModuleAlarmMsg_t * alarmMsg)
+{
+ alarm_fenter("alarm_processAlarmMsg");
+ switch(alarmMsg->msgType)
+ {
+
+ case InterModuleAlarmMsgTypeClearAlarm:
+ AlarmTask::theAlarmTask->delAlarmEntry(alarmMsg->srcModuleId, alarmMsg->errorTag, alarmMsg->code);
+ break;
+
+ case InterModuleAlarmMsgTypeRaiseAlarm:
+ AlarmTask::theAlarmTask->addAlarmEntry(alarmMsg->srcModuleId, alarmMsg->errorTag, alarmMsg->code, alarmMsg->arg1, alarmMsg->arg2);
+ break;
+
+ case InterModuleAlarmMsgTypeShutdown:
+ AlarmTask::theAlarmTask->quit();
+ break;
+
+ case InterModuleAlarmMsgTypeReboot:
+ AlarmTask::theAlarmTask->quit();
+ break;
+
+ default:
+ alarm_warning(("Not recognized alarm message type (message type = %d)", alarmMsg->msgType));
+ break;
+ }
+ alarm_fexit();
+ return;
+}
+
+void alarm_processMsg(char *inComingMsg)
+{
+ /* process the trap message here*/
+ alarm_fenter("alarm_processMsg");
+ alarm_debug(("A new message has just arrived.\n"));
+
+ switch(inComingMsg[0])
+ {
+ case MNET_MODULE_SNMP:
+ alarm_processTrap((TrapMsg *) inComingMsg);
+ break;
+ case MY_MODULE_ID:
+ alarm_processAlarmMsg((InterModuleAlarmMsg_t *) inComingMsg);
+ break;
+ default:
+ alarm_error(("Message from unsupported module (ID = %d)\n", inComingMsg[0]));
+ }
+ alarm_fexit();
+}
+
+#endif /* _ALARM_MESSAGE_CPP_ */ \ No newline at end of file
diff --git a/data/mnet/Common/Alarm/src/alarm_modules.cpp b/data/mnet/Common/Alarm/src/alarm_modules.cpp
new file mode 100644
index 0000000..3d3fb6f
--- /dev/null
+++ b/data/mnet/Common/Alarm/src/alarm_modules.cpp
@@ -0,0 +1,441 @@
+/*********************************************************************/
+/* */
+/* (c) Copyright Cisco 2000 */
+/* All Rights Reserved */
+/* */
+/*********************************************************************/
+
+/*********************************************************************/
+/* */
+/* Version : 1.0 */
+/* Status : Under development */
+/* File : AlarmTask.h */
+/* Author(s) : Bhawani Sapkota */
+/* Create Date : 9/18/2000 */
+/* Description : This file contains alarm task module handling */
+/* routines */
+/* */
+/*********************************************************************/
+/* REVISION HISTORY
+/*___________________________________________________________________*/
+/*----------+--------+-----------------------------------------------*/
+/* Name | Date | Reason */
+/*----------+--------+-----------------------------------------------*/
+/* Bhawani |07/14/00| Initial Draft */
+/* Bhawani |11/20/00| resturctured to share among GP, GMS and GS */
+/*----------+--------+-----------------------------------------------*/
+/*********************************************************************/
+
+#ifndef _ALARM_MODULE_CPP_
+#define _ALARM_MODULE_CPP_
+
+#include "AlarmTask.h"
+#include <time.h>
+
+Alarm_severity_t getSeverity(AlarmCode_t acode)
+{
+ Alarm_severity_t severity = Alarm_info;
+ int tmp = (acode & 0xFFFF);
+
+
+ if (tmp < ALARM_CRITICAL_START_POINT)
+ {
+ severity = Alarm_info;
+ } else if (tmp < ALARM_MAJOR_START_POINT) {
+ severity = Alarm_critical;
+ } else if (tmp < ALARM_MINOR_START_POINT) {
+ severity = Alarm_major;
+ } else if (tmp < ALARM_INFO_START_POINT) {
+ severity = Alarm_minor;
+ } else {
+ severity = Alarm_info;
+ }
+ return severity;
+}
+
+
+int AlarmTask::generateNextId()
+{
+ alarm_fenter("AlarmTask::generateNextId");
+ static unsigned long id = 0;
+
+ if(id == 0)
+ {
+ getLastId( &id);
+ alarm_debug(("Last Module ID = %d\n", id ));
+ }
+ alarm_fexit();
+ return id++;
+}
+
+
+AlarmCode_t AlarmTask::getMdlStatus(MNET_MODULE_ID mid)
+{
+ if (mid >=0 && mid < MNET_MAX_MODULE_IDS)
+ {
+ if (_ms[mid])
+ return (_ap[mid].code);
+ }
+ return EC_COMMON_NOERROR;
+}
+
+AlarmEntry_t *AlarmTask::allocEntry(MNET_MODULE_ID mid)
+{
+ int i = 0;
+
+ while ( _ap[i].code != EC_COMMON_NOERROR)
+ {
+ if ( i == ALARM_max_outstanding)
+ return NULL;
+ i++;
+ }
+
+
+ _ap[i].next = NULL;
+ if (mid >=0 && mid < MNET_MAX_MODULE_IDS)
+ {
+ if (_ms[mid] == NULL)
+ {
+ _ms[mid] = &_ap[i];
+ }
+ else
+ {
+ AlarmEntry_t * tmpentry = _ms[mid];
+
+ while ( tmpentry->next != NULL)
+ tmpentry = tmpentry->next;
+
+ tmpentry->next = &_ap[i];
+ }
+ return &_ap[i];
+ }
+ return NULL;
+}
+
+EnableDisableState_t AlarmTask::updateOperationalState()
+{
+ int i = 0;
+ EnableDisableState_t state = stateEnabled;
+
+ while ((state == stateEnabled) && (i < MNET_MAX_MODULE_IDS))
+ {
+ AlarmEntry_t * tmpentry = _ms[i];
+ while(tmpentry)
+ {
+ if (tmpentry->severity == Alarm_critical)
+ {
+ state = stateDisabled;
+ break;
+ }
+ tmpentry = tmpentry->next;
+ }
+ i++;
+ }
+ if ( (state == stateEnabled) && (i == MNET_MAX_MODULE_IDS))
+ {
+ // enable operational state
+ setOperationState(stateEnabled);
+
+ // set mib control state enable (in case this is first time)
+ if (_mibAccessState == false)
+ {
+ setMibAcessControlState(stateEnabled);
+ }
+
+ } else {
+ // disable operation state
+ setOperationState(stateDisabled);
+ }
+ return state;
+}
+
+
+void AlarmTask::updateModuleLastError(MNET_MODULE_ID mid, MibTag moduleErrorTag)
+{
+
+ AlarmEntry_t * curnode = _ms[mid];
+ AlarmCode_t errorcode = EC_COMMON_NOERROR;
+ alarm_fenter("AlarmTask::updateModuleLastError");
+
+ while(curnode)
+ {
+ errorcode = curnode->code;
+ curnode = curnode->next;
+ }
+
+ setModuleLastError(moduleErrorTag, errorcode);
+ alarm_fexit();
+}
+
+
+
+bool AlarmTask::addAlarmEntry(MNET_MODULE_ID mid, MibTag moduleErrorTag, AlarmCode_t errorCode, char *arg1, char *arg2)
+{
+ bool status = true;
+ Alarm_severity_t severity;
+ int id;
+ AlarmEntry_t *aentry;
+
+ alarm_fenter("addAlarmEntry");
+
+
+ aentry = findAlarmEntry(mid, errorCode);
+
+ if (aentry != NULL)
+ {
+ alarm_warning(("Alarm (code = 0x%06x) was raised %d times by %s, since UTC %s",
+ errorCode, ++aentry->count, GetMnetModuleName(mid), ctime(&aentry->utc)));
+ return true;
+ }
+
+ severity = getSeverity(errorCode);
+
+ if (severity < Alarm_max_severity)
+ {
+ _statistics[0][severity]++;
+ _statistics[1][severity]++;
+ }
+
+ switch (severity)
+ {
+ case Alarm_critical:
+ /* disable Network Elelemt Operational state if it is not already disabled */
+ setOperationState(stateDisabled);
+ case Alarm_major:
+ case Alarm_minor:
+ case Alarm_info:
+ aentry = allocEntry(mid);
+ id = generateNextId();
+
+ if (aentry )
+ {
+ aentry->count = 1;
+ aentry->code = errorCode;
+ aentry->id = id;
+ aentry->severity = severity;
+ aentry->utc = time(NULL);
+ } else {
+ alarm_error(("Too many alarm entries.\n"));
+ }
+
+ updateModuleLastError(mid, moduleErrorTag);
+ reportNewAlarm(id, mid, errorCode, severity, arg1, arg2);
+ break;
+
+ default:
+ alarm_error(("Illegle Severity code\n"));
+ break;
+ }
+ alarm_fexit();
+ return status;
+}
+
+
+AlarmEntry_t * AlarmTask::findAlarmEntry(MNET_MODULE_ID mid, AlarmCode_t errorCode)
+{
+ AlarmEntry_t * curnode = _ms[mid];
+
+ while (curnode )
+ {
+ if (curnode->code == errorCode)
+ return curnode;
+ curnode= curnode->next;
+ }
+ return NULL;
+}
+
+
+
+bool AlarmTask::delAlarmEntry(MNET_MODULE_ID mid, MibTag moduleErrorTag, AlarmCode_t errorCode)
+{
+ bool status = true;
+ char prevAlarm[20];
+ char prevId[20];
+ AlarmCode_t lastError = (AlarmCode_t) 0;
+ Alarm_severity_t severity;
+ int lastId = 0;
+
+ memset(prevAlarm, 0, 20);
+
+
+ if ((mid >=0) && (mid < MNET_MAX_MODULE_IDS))
+ {
+ AlarmEntry_t * curnode = _ms[mid];
+ AlarmEntry_t * prevnode = curnode;
+
+ if (errorCode == EC_COMMON_NOERROR)
+ {
+ // clear all the error for this module
+ _ms[mid] = NULL;
+ while (curnode )
+ {
+ prevnode = curnode;
+ curnode = curnode->next;
+
+ severity = getSeverity(prevnode->code);
+
+ if (severity < Alarm_max_severity)
+ {
+ _statistics[1][severity]--;
+ }
+ lastError = prevnode->code;
+ lastId = prevnode->id;
+ prevnode->code = EC_COMMON_NOERROR;
+ prevnode->next = NULL;
+ }
+ } else {
+
+ while (curnode && (curnode->code != errorCode))
+ {
+ prevnode = curnode;
+ curnode = curnode->next;
+ }
+
+ if (curnode)
+ {
+ if (curnode == prevnode)
+ {
+ // the first node
+ _ms[mid] = curnode->next;
+ } else {
+ prevnode->next = curnode->next;
+ }
+
+ severity = getSeverity(curnode->code);
+
+ if (severity < Alarm_max_severity)
+ {
+ _statistics[1][severity]--;
+ }
+ lastError = prevnode->code;
+ lastId = prevnode->id;
+ curnode->code = EC_COMMON_NOERROR;
+ curnode->next = NULL;
+ }
+ }
+ int id = generateNextId();
+ sprintf(prevAlarm,"%d", lastError);
+ sprintf(prevId, "%d", lastId);
+ reportNewAlarm(id, mid, EC_COMMON_NOERROR, Alarm_info, prevAlarm, prevId);
+ updateOperationalState();
+ updateModuleLastError(mid, moduleErrorTag);
+ } else {
+ status = false;
+ }
+ return status;
+}
+
+
+void AlarmTask::reportNewAlarm(int id, MNET_MODULE_ID mid, AlarmCode_t ecode, Alarm_severity_t severity,
+ char * arg1, char * arg2)
+{
+ extern bool alarm_sendAlarmEventToAms(ubyte4, ubyte4, ubyte4, ubyte4, char*, char*);
+
+ char strMsg[ALARM_maxMsgSize];
+ time_t ltime;
+ int posCount = 0;
+ alarm_fenter("AlarmTask::reportNewAlarm");
+
+
+ alarm_debug(("Formating alarm message to the GUI\n"));
+ memset((void *) strMsg,0,ALARM_maxMsgSize);
+ posCount += sprintf(strMsg + posCount, "%d|", id);
+
+ /* Get current local time */
+ time( &ltime );
+
+ posCount += sprintf(strMsg + posCount, "%ld|", ltime);
+ posCount += sprintf(strMsg + posCount, "%d|", severity);
+ posCount += sprintf(strMsg + posCount, "%d|", mid);
+ posCount += sprintf(strMsg + posCount, "%s|", GetMnetModuleName(mid));
+ posCount += sprintf(strMsg + posCount, "%d", ecode);
+
+ if (arg1 != NULL)
+ posCount += sprintf(strMsg + posCount, "|%s", arg1);
+ if(arg2 != NULL)
+ posCount += sprintf(strMsg + posCount, "|%s", arg2);
+
+ for (int i = posCount; i < ALARM_record_length-1; i++)
+ strMsg[i] = ' ';
+
+ strMsg[ALARM_record_length-1] = '\n';
+ strMsg[ALARM_record_length] = '\0';
+
+
+ // Broadcast message to all the Java Client Applets
+ alarm_broadcast(strMsg);
+
+ // we write to flash for all events
+ saveAlarm(strMsg);
+
+ // Send message to First AMS server
+ alarm_sendAlarmEventToAms(id, ecode, ltime, mid, arg1, arg2);
+
+ if (ecode == 0)
+ {
+ alarm_warning(("Alarm (Id = %d) in module \"%s\" has been cleared\n", id, GetMnetModuleName( mid)));
+ } else {
+ alarm_warning(("The module \"%s\" has raised an alarm (Id= %d, Code = %d)\n", GetMnetModuleName(mid), id, ecode));
+ }
+ alarm_fexit();
+
+}
+
+extern "C" void AlarmPrintStatus()
+{
+
+ AlarmTask::theAlarmTask->printStatus();
+
+}
+
+void AlarmTask::printStatus()
+{
+ int i;
+ AlarmEntry_t * tmpentry;
+
+ printf("\nNetwork Element Operational State: %d\n", getOperationState());
+ printf("Mib Access Status: %d\n", _mibAccessState);
+
+ printf("\nAlarm Statistics:\n");
+ printf("Total Alarms in this session:\n");
+ printf("\tCritical: %d\n", _statistics[0][Alarm_critical]);
+ printf("\tMajor: %d\n", _statistics[0][Alarm_major]);
+ printf("\tMinor: %d\n", _statistics[0][Alarm_minor]);
+ printf("\tInformational: %d\n", _statistics[0][Alarm_info]);
+
+ printf("Total Outstanding Alarms:\n");
+ printf("\tCritical: %d\n", _statistics[1][Alarm_critical]);
+ printf("\tMajor: %d\n", _statistics[1][Alarm_major]);
+ printf("\tMinor: %d\n", _statistics[1][Alarm_minor]);
+
+ if (_statistics[1][Alarm_critical]
+ + _statistics[1][Alarm_major]
+ + _statistics[1][Alarm_minor])
+ {
+ printf("%20s%20s\n", "MODULE NAME", "Outstanding Alarms");
+ printf("%20s%20s\n", "===========", "===================");
+ for(i=0; i< MNET_MAX_MODULE_IDS; i++)
+ {
+ if (_ms[i])
+ {
+ tmpentry = _ms[i];
+ printf("%20s ", GetMnetModuleName((MNET_MODULE_ID)i));
+ while(tmpentry)
+ {
+ printf(" %06x", tmpentry->code);
+ tmpentry = tmpentry->next;
+ }
+ printf("\n");
+ }
+ }
+ }
+}
+
+void AlarmTask::getOutstandingAlarmCount(ubyte1 &critical, ubyte1 &major, ubyte1 &minor)
+{
+ critical = _statistics[1][Alarm_critical];
+ major= _statistics[1][Alarm_major];
+ minor= _statistics[1][Alarm_minor];
+}
+
+#endif /* _ALARM_MODULE_CPP_ */
diff --git a/data/mnet/Common/Alarm/src/alarm_socket.cpp b/data/mnet/Common/Alarm/src/alarm_socket.cpp
new file mode 100644
index 0000000..12706c6
--- /dev/null
+++ b/data/mnet/Common/Alarm/src/alarm_socket.cpp
@@ -0,0 +1,445 @@
+/*********************************************************************/
+/* */
+/* (c) Copyright Cisco 2000 */
+/* All Rights Reserved */
+/* */
+/*********************************************************************/
+
+/*********************************************************************/
+/* */
+/* Version : 1.0 */
+/* Status : Under development */
+/* File : AlarmTask.h */
+/* Author(s) : Bhawani Sapkota */
+/* Create Date : 9/18/2000 */
+/* Description : This file contains alarm task socket handling */
+/* routines */
+/* */
+/*********************************************************************/
+/* REVISION HISTORY
+/*___________________________________________________________________*/
+/*----------+--------+-----------------------------------------------*/
+/* Name | Date | Reason */
+/*----------+--------+-----------------------------------------------*/
+/* Bhawani |07/14/00| Initial Draft */
+/* Bhawani |11/20/00| resturctured to share among GP, GMS and GS */
+/* Bhawani |03/10/01| Added alarm_raiseForGp10 Api */
+/*----------+--------+-----------------------------------------------*/
+/*********************************************************************/
+
+
+#ifndef _ALARM_SOCKET_CPP_
+#define _ALARM_SOCKET_CPP_
+
+#include "AlarmTask.h"
+
+#include "alarm_interface.h"
+#include <time.h>
+#include <selectLib.h>
+
+typedef int OS_SPECIFIC_SOCKET_HANDLE;
+
+/*-----------------------------------------------------------------------*/
+
+static OS_SPECIFIC_SOCKET_HANDLE SOCKET_UdpCreate()
+{
+ alarm_fenter("SOCKET_UdpCreate");
+
+ OS_SPECIFIC_SOCKET_HANDLE soc = socket(AF_INET, SOCK_DGRAM, 0);
+
+ if (ERROR == soc)
+ {
+ alarm_error(("Could not open datagram socket %s\n", strerror(errno)));
+ }
+
+ alarm_fexit();
+ return soc;
+}
+
+
+/*-----------------------------------------------------------------------*/
+
+static bool SOCKET_UdpBind(OS_SPECIFIC_SOCKET_HANDLE soc, ubyte2 port)
+{
+ struct sockaddr_in LocalAddr;
+ bool status = true;
+ alarm_fenter("SOCKET_UdpBind");
+
+
+
+ /* ask the system to allocate a port and bind to INADDR_ANY */
+ memset(&LocalAddr, 0x00, sizeof(LocalAddr));
+
+ /* get system to allocate a port number by binding a host address */
+ LocalAddr.sin_family = AF_INET;
+ LocalAddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ LocalAddr.sin_port = htons(port);
+
+ /* bind socket to local address */
+ if (ERROR == bind(soc, (struct sockaddr *) &LocalAddr, sizeof(LocalAddr)))
+ {
+ alarm_error(("Could not bind datagram socket to port %d: %s\n", port, strerror(errno)));
+ status = false;
+
+ }
+
+ alarm_fexit();
+ return status;
+}
+
+/*-----------------------------------------------------------------------*/
+
+static bool SOCKET_SetRecvBuffer(OS_SPECIFIC_SOCKET_HANDLE soc, int nBytes)
+{
+ alarm_fenter("SOCKET_SetRecvBuffer");
+ bool status = true;
+
+ if (ERROR == setsockopt(soc, SOL_SOCKET, SO_RCVBUF, (char *) &nBytes, sizeof(int)))
+ {
+
+ alarm_error(("Could not set Receive buffer to %d\n", nBytes));
+ status = false;
+ }
+ alarm_fexit();
+ return status;
+}
+
+
+/*-----------------------------------------------------------------------*/
+
+void SOCKET_UdpClearRecvQ(OS_SPECIFIC_SOCKET_HANDLE sock)
+{
+ struct timeval timeout;
+ fd_set readFdSet;
+ static char buffer[512];
+ int bufferlen = 512;
+ struct sockaddr_in Addr;
+ int iAddrLen;
+
+
+ alarm_fenter("SOCKET_UdpClearInQueue");
+
+
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 0;
+
+ FD_ZERO(&readFdSet);
+ FD_SET(sock, &readFdSet);
+
+
+ if(select(FD_SETSIZE, &readFdSet, NULL, NULL, &timeout) > 0)
+ {
+ /* Socket is ready for reading */
+
+ bufferlen = recvfrom(sock, buffer, bufferlen, 0, (struct sockaddr *)&Addr, &iAddrLen);
+ if (bufferlen > 0)
+ {
+ alarm_warning (("Cleared %d bytes of unexpected data from %s:%u\n",
+ bufferlen, inet_ntoa(Addr.sin_addr), Addr.sin_port));
+ }
+ }
+ alarm_fexit();
+}
+
+/*-----------------------------------------------------------------------*/
+
+extern bool
+SOCKET_UdpSendTo(OS_SPECIFIC_SOCKET_HANDLE sock,
+ struct sockaddr_in *pAddrTo,
+ char *message,
+ ubyte4 msglen)
+{
+ alarm_fenter("SOCKET_UdpSendTo");
+ bool status = true;
+ char pszIPbuf[20];
+
+
+ if (ERROR == sendto(sock, message, msglen, 0,
+ (struct sockaddr *) pAddrTo,
+ sizeof(struct sockaddr)) )
+ {
+ status = false;
+ }
+ inet_ntoa_b(pAddrTo->sin_addr, pszIPbuf);
+ alarm_debug(( "Sending %d bytes to Alarm server (ip=%s, port=%d) \n", msglen, pszIPbuf, ntohs(pAddrTo->sin_port)));
+ alarm_dump((ubyte1 *) message, msglen);
+
+ // clear any message in the incoming queue
+ SOCKET_UdpClearRecvQ(sock);
+
+ alarm_fexit();
+ return status;
+}
+
+/*-----------------------------------------------------------------------*/
+
+extern bool
+SOCKET_UdpReceive(OS_SPECIFIC_SOCKET_HANDLE sock,
+ char *msg,
+ ubyte4 *msgSize,
+ ubyte4 *peerAddr)
+{
+ struct sockaddr_in pAddr;
+ int iAddrLen;
+ int retval = recvfrom(sock, msg, *msgSize, 0, (struct sockaddr *)&pAddr, &iAddrLen );
+
+ if (retval == ERROR)
+ {
+ *msgSize = 0;
+ return false;
+ }
+
+ *msgSize = retval;
+ *peerAddr = pAddr.sin_addr.s_addr;
+ return true;
+}
+
+
+/*-----------------------------------------------------------------------*/
+
+extern bool SOCKET_Close(OS_SPECIFIC_SOCKET_HANDLE sock)
+{
+ bool retval = true;
+ alarm_fenter("SOCKET_Close");
+
+ if (ERROR == close(sock) )
+ {
+ alarm_error(("Could not close socket %s\n", strerror(errno)));
+ retval = false;
+ }
+
+ alarm_fexit();
+ return retval;
+}
+
+/*-----------------------------------------------------------------------*/
+
+ubyte4 GetHostAddress(char *pszHostName)
+{
+
+ return hostGetByName ( pszHostName );
+
+}
+
+/*-----------------------------------------------------------------------*/
+
+static ubyte4 GetLocalHostAddress()
+{
+#define MAX_PATH 80
+ char szHostName[MAX_PATH];
+ ubyte4 ulHostAddr = 0;
+
+ if (ERROR != gethostname(szHostName, MAX_PATH-1))
+ ulHostAddr = GetHostAddress ( szHostName );
+
+ return (ulHostAddr);
+}
+
+/*-----------------------------------------------------------------------*/
+
+static bool initialized = false;
+/*
+static AlarmViperCellToAmsMsg amsMsg;
+*/
+static struct sockaddr_in addrTo;
+static OS_SPECIFIC_SOCKET_HANDLE sock;
+
+bool
+initSocketAndMsgHdr()
+{
+ char pszIpBuf[20];
+ alarm_fenter("initSocketAndMsgHdr");
+
+ if (!initialized)
+ {
+ int ip;
+ /* 1. prepare udp socket */
+ sock = SOCKET_UdpCreate();
+
+ if (sock == ERROR)
+ {
+ alarm_fexit();
+ return false;
+ }
+
+ if (SOCKET_UdpBind(sock, ALARM_interfaceUdpPortClient) != true)
+ {
+ SOCKET_Close(sock);
+ alarm_fexit();
+ return false;
+
+ }
+
+ /* 2. get IP address from MIB */
+
+ if (oam_getMibIntVar(MY_MIB_APM1_IP_ADDRESS, (long *) &ip) != STATUS_OK)
+ {
+ // alarm_error(("Unable to get alarm server's IP from the MIB\n"));
+ SOCKET_Close(sock);
+ return false;
+ }
+
+ /* 3. prepare the the server's address */
+ memset (&addrTo, 0, sizeof(sockaddr_in));
+
+ addrTo.sin_family = AF_INET;
+ addrTo.sin_addr.s_addr = ip;
+ addrTo.sin_port = htons((ubyte2)ALARM_interfaceUdpPortServer);
+
+ inet_ntoa_b( addrTo.sin_addr, pszIpBuf);
+
+ /* Set small receive buffer */
+ SOCKET_SetRecvBuffer(sock, ALARM_defaultRecvBuffer);
+
+ alarm_debug (("APM1 server: ip = %s, port=%d\n", pszIpBuf, ALARM_interfaceUdpPortServer));
+ initialized = true;
+ }
+ alarm_fexit();
+ return true;
+}
+
+/*-----------------------------------------------------------------------*/
+
+bool
+alarm_sendAlarmEventToAms(ubyte4 id, ubyte4 code, ubyte4 timestamp, ubyte4 moduleId, char* opt1, char* opt2)
+{
+ AlarmViperCellToAmsMsg amsMsg;
+ ubyte4 opt;
+
+ alarm_fenter("alarm_sendAlarmMsgToAms");
+
+ if (!initSocketAndMsgHdr())
+ {
+ alarm_fexit();
+ return false;
+ }
+
+ memset(&amsMsg, 0, sizeof(AlarmViperCellToAmsMsg));
+
+ amsMsg.hdr.alarmSrcType = (ubyte1) MY_PRODUCT_ID;
+ amsMsg.hdr.alarmMsgType = ALARM_msgTypAlarmEvent;
+ amsMsg.hdr.alarmMsgLen = htons(sizeof(AlarmEventData));
+
+ strncpy(amsMsg.body.eventData.alarmSrcModuleName, GetMnetModuleName((MNET_MODULE_ID)moduleId),
+ ALARM_viperCellNameMaxSize);
+ amsMsg.body.eventData.alarmSrcIp = GetLocalHostAddress();
+
+ amsMsg.body.eventData.alarmId = htonl(id);
+ amsMsg.body.eventData.alarmCode = htonl(code);
+ amsMsg.body.eventData.alarmTimestamp = htonl(timestamp);
+ amsMsg.body.eventData.alarmSrcModuleId = htonl(moduleId);
+ if (NULL != opt1)
+ {
+ opt = atoi(opt1);
+ amsMsg.body.eventData.opt1 = htonl(opt);
+ }
+
+ if (NULL != opt1)
+ {
+ opt = atoi(opt2);
+ amsMsg.body.eventData.opt2 = htonl(opt);
+ }
+ SOCKET_UdpSendTo(sock, &addrTo, (char *) &amsMsg, ALARM_eventMsgLen);
+
+ alarm_fexit();
+ return true;
+
+}
+
+/*-----------------------------------------------------------------------*/
+#ifdef MNET_PRODUCT_SPECIFIC_GMC
+
+JC_STATUS alarm_raiseForGp10
+(
+ MNET_MODULE_ID mid, /* Gp10 source module ID */
+ AlarmCode_t alarm_code, /* Gp10 Alarm code */
+ unsigned long ip, /* GP10 IP address */
+ char *sourceName /* GP10's official name */
+ )
+{
+ AlarmViperCellToAmsMsg amsMsg;
+ const int MODULE_VBLINK = 0x11; /* ViperBase - ViperCell link client */
+ static char gp10SrcName[] = "VBLink"; /* GP10's Module name */
+
+ alarm_fenter("alarm_raiseForGp10");
+
+ if (!initSocketAndMsgHdr())
+ {
+ alarm_fexit();
+ return JC_ERROR;
+ }
+
+
+ memset(&amsMsg, 0, sizeof(AlarmViperCellToAmsMsg));
+
+ amsMsg.hdr.alarmSrcType = (ubyte1) MNET_PRODUCT_GP10;
+ amsMsg.hdr.alarmMsgType = ALARM_msgTypAlarmEvent;
+ amsMsg.hdr.alarmMsgLen = htons(sizeof(AlarmEventData));
+
+ strncpy(amsMsg.body.eventData.alarmSrcModuleName, gp10SrcName, ALARM_viperCellNameMaxSize);
+ amsMsg.body.eventData.alarmSrcIp = ip;
+
+ amsMsg.body.eventData.alarmId = htonl(ALARM_unknownAlarmId);
+ amsMsg.body.eventData.alarmCode = htonl(alarm_code);
+ amsMsg.body.eventData.alarmTimestamp = htonl(time(NULL));
+ amsMsg.body.eventData.alarmSrcModuleId = htonl(mid);
+ SOCKET_UdpSendTo(sock, &addrTo, (char *) &amsMsg, ALARM_eventMsgLen);
+
+ alarm_fexit();
+ return true;
+
+}
+
+#endif
+
+/*-----------------------------------------------------------------------*/
+
+bool AlarmTask::sendSummaryUpdateToAms()
+{
+ AlarmViperCellToAmsMsg amsMsg;
+
+ alarm_fenter("AlarmTask::sendSummaryUpdateToAms");
+ ubyte1 critical, major, minor;
+
+ if (!initSocketAndMsgHdr())
+ {
+ alarm_fexit();
+ return false;
+ }
+
+ /* 4. initialize the fixed fields */
+ memset(&amsMsg, 0, sizeof(AlarmViperCellToAmsMsg));
+
+ // populate the header
+ amsMsg.hdr.alarmSrcType = ALARM_srcTypViperCell;
+ amsMsg.hdr.alarmMsgType = ALARM_msgTypSummaryUpdate;
+ amsMsg.hdr.alarmMsgLen = htons(sizeof(AlarmSummaryUpdateData));
+
+ strncpy(amsMsg.body.summaryUpdateData.alarmSrcName, AlarmTask::srcName(),
+ ALARM_viperCellNameMaxSize);
+ amsMsg.body.summaryUpdateData.alarmSrcIp = GetLocalHostAddress();
+
+ getOutstandingAlarmCount(critical, major, minor);
+ amsMsg.body.summaryUpdateData.alarmCriticalCount = critical;
+ amsMsg.body.summaryUpdateData.alarmMajorCount = major;
+ amsMsg.body.summaryUpdateData.alarmMinorCount = minor;
+ SOCKET_UdpSendTo(sock, &addrTo, (char *) &amsMsg, ALARM_summaryUpdateMsgLen);
+
+ alarm_fexit();
+ return true;
+}
+
+
+void AlarmTask::quit ()
+{
+ _quit = true;
+}
+
+void AlarmTask::closeSocket ()
+{
+ initialized = false;
+ SOCKET_Close(sock);
+}
+
+
+#endif /* _ALARM_SOCKET_CPP_ */
diff --git a/data/mnet/Common/Alarm/src/alarm_sysCmd.cpp b/data/mnet/Common/Alarm/src/alarm_sysCmd.cpp
new file mode 100644
index 0000000..ba2ce56
--- /dev/null
+++ b/data/mnet/Common/Alarm/src/alarm_sysCmd.cpp
@@ -0,0 +1,173 @@
+/*********************************************************************/
+/* */
+/* (c) Copyright Cisco 2000 */
+/* All Rights Reserved */
+/* */
+/*********************************************************************/
+
+/*********************************************************************/
+/* */
+/* Version : 1.0 */
+/* Status : Under development */
+/* File : AlarmTask.h */
+/* Author(s) : Bhawani Sapkota */
+/* Create Date : 9/18/2000 */
+/* Description : This file contains alarm task syscommand handling */
+/* routines */
+/* */
+/*********************************************************************/
+/* REVISION HISTORY
+/*___________________________________________________________________*/
+/*----------+--------+-----------------------------------------------*/
+/* Name | Date | Reason */
+/*----------+--------+-----------------------------------------------*/
+/* Bhawani |07/14/00| Initial Draft */
+/* Bhawani |11/20/00| resturctured to share among GP, GMS and GS */
+/* Bhawani |03/09/01| Changed alarm log directory to match others */
+/*----------+--------+-----------------------------------------------*/
+/*********************************************************************/
+
+
+#ifndef __ALARM_SYSCMD_CPP__
+#define __ALARM_SYSCMD_CPP__
+
+#include "AlarmTask.h"
+
+/*
+*********************************************************************
+** Global variables
+********************************************************************
+*/
+
+/* Initialize the alarm task */
+
+AlarmTask::AlarmTask(char *name): JCTask(name)
+{
+ alarm_fenter("AlarmTask::AlarmTask");
+ if (isOneCreated == false)
+ {
+ int size, i,j;
+
+ // Initialize the message queue first
+ jcMsgQ = new JCMsgQueue(ALARM_q_maxMsgs, ALARM_q_maxMsgLength, MSG_Q_FIFO);
+
+#ifdef MNET_PRODUCT_SPECIFIC_GP10
+ // Initialize the timer
+ initTimer = new JCCTimer( (FUNCPTR ) &AlarmTask::bootupTimeoutHandler);
+ initTimer->setTimer(ALARM_mib_lock_timeout);
+#else
+ _mibAccessState = stateEnabled;
+#endif
+
+ // message receive buffer
+ _msgRecvBuff = new char[ALARM_q_maxMsgLength];
+
+ _mnetbase = getenv( "MNET_BASE" );
+
+ // compute the log file size
+ size = strlen(_mnetbase) + strlen(ALARM_logFile) + 1;
+ _logfilename = new char[size];
+ sprintf(_logfilename, "%s%s", _mnetbase, ALARM_logFile);
+
+ // initialize the module status table
+ for (i = 0; i < MNET_MAX_MODULE_IDS; i++)
+ _ms[i] = NULL;
+
+
+ // initialize the alarm pool
+ _ap = new AlarmEntry_t[ALARM_max_outstanding];
+ for (i =0; i <ALARM_max_outstanding; i++)
+ {
+ _ap[i].code = EC_COMMON_NOERROR;
+ _ap[i].next = NULL;
+ }
+
+ for (i=0; i <2; i++)
+ for (j=0; j< Alarm_max_severity; j++)
+ _statistics[i][j] = 0;
+
+ theAlarmTask = this;
+ populateSourceName();
+ isOneCreated = true;
+ }
+ alarm_fexit();
+}
+
+int AlarmTask::bootupTimeoutHandler()
+{
+ alarm_fenter("alarm_bootupTimeoutHandler");
+
+ /* The timer has expired and mib access needs to be enabled. */
+ theAlarmTask->setMibAcessControlState(stateEnabled);
+ alarm_warning(("The system did not complete reboot. Mib access has been re-enabled\n"));
+ alarm_fexit();
+ return 0;
+}
+
+
+int SysCommand_Alarm (T_SYS_CMD action)
+{
+ char *home;
+ JC_STATUS status = OK;
+
+ alarm_fenter("SysCommand_Alarm");
+ switch(action)
+ {
+ case SYS_SHUTDOWN:
+ break;
+
+ case SYS_REBOOT:
+ alarm_warning(("Reboot notification has been received\n"));
+ AlarmTask::theAlarmTask->alarmSend(InterModuleAlarmMsgTypeReboot, MY_MODULE_ID);
+ break;
+
+ case SYS_START:
+ alarm_debug(("Alarm initialization has been invoked\n"));
+
+ /* Get the value of the MNET_BASE environment variable. */
+ home = getenv( "MNET_BASE" );
+
+ if( home == NULL )
+ {
+ alarm_error(("Environment variable \"MNET_BASE\" must be defined!!\n"));
+ alarm_fexit();
+ return ERROR;
+ }
+ {
+ AlarmTask *mytask = new AlarmTask(ALARM_task_name);
+
+#ifdef MNET_PRODUCT_SPECIFIC_GP10
+ /* block the mib access */
+ mytask->setMibAcessControlState(stateDisabled);
+#endif
+
+ status = mytask->JCTaskSpawn(
+ ALARM_TASK_PRIORITY,
+ ALARM_TASK_OPTION,
+ ALARM_TASK_STACK_SIZE,
+ (FUNCPTR) AlarmTask::entryPoint,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ MY_MODULE_ID, JC_CRITICAL_TASK);
+
+ if(status == JC_ERROR)
+ {
+ alarm_error(("Alarm task spawn failure\n"));
+ status = ERROR;
+ }
+
+ }
+ break;
+
+ default:
+ alarm_warning(("Unknown SysCommand: %d\n", action));
+ status = ERROR;
+ break;
+ }
+ alarm_fexit();
+ return status;
+
+}
+
+#endif /* __ALARM_SYSCMD_CPP__ */
+
+