1f5bc3b607f79ebca6fbcca97b6d0f5a2409e10b
[o-du/l2.git] / src / o1 / o1_client / AlarmInterface.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2020] [HCL Technologies Ltd.]                               #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /* This file contains interfaces to raise and clear alarms */
20
21 #include "AlarmInterface.h"
22 #include "TcpClient.h"
23
24
25 /********************************************************************** 
26    Description : Raise an alarm by sending alarm info to O1 module over
27                  TCP socket with action set to RAISE
28    Params[In]  : Alarm information
29    Return      : ROK     - success
30                  RFAILED - failure
31 **********************************************************************/
32 uint8_t raiseAlarm(AlarmRecord* alrm)
33 {
34    if (openSocket(TCP_SERVER_IP,TCP_PORT) == RFAILED)
35    {
36       return RFAILED;
37    }
38    alrm->msgHeader.action = RAISE;
39    if (sendData(alrm,sizeof(AlarmRecord)) < 0 )
40    {
41       closeSocket();
42       return RFAILED;
43    }
44    closeSocket();
45    return ROK;
46 }
47
48 /********************************************************************** 
49    Description : Clears an alarm raised earlier by sending the alrm
50                  information to O1 module over TCP socket with action
51                  set to CLEAR 
52    Params[In]  : Alarm information
53    Return      : ROK     - success
54                  RFAILED - failure
55 **********************************************************************/
56 uint8_t clearAlarm(AlarmRecord* alrm)
57 {
58    if (openSocket(TCP_SERVER_IP,TCP_PORT) == RFAILED)
59    {
60       return RFAILED;
61    }
62    alrm->msgHeader.action = CLEAR;
63    if (sendData(alrm,sizeof(AlarmRecord)) < 0)
64    {
65       closeSocket();
66       return RFAILED;
67    }
68    closeSocket();
69    return ROK;
70 }
71
72
73 /********************************************************************** 
74    Description : Fill the cell specific alarm parmeters and generate
75                  the alarm
76    Params[In]  : alarm Id, cell Id
77    Return      : ROK     - success
78                  RFAILED - failure
79 **********************************************************************/
80 uint8_t raiseCellAlrm(uint16_t alrmId, uint16_t cellId)
81 {
82   char buff[BUFF_SIZE];
83   time_t now = time(NULL);
84
85   AlarmRecord alrm;
86   alrm.eventType = COMMUNICATIONS_ALARM;
87   snprintf (alrm.alarmId, sizeof(alrm.alarmId), "%d",alrmId);
88   alrm.perceivedSeverity = INDETERMINATE;
89   
90   strftime(buff, BUFF_SIZE, "%Y-%m-%d %H:%M:%S", localtime(&now));
91   if(CELL_UP_ALARM_ID == alrmId)
92   {
93     /* Fill cell up parameters */
94     snprintf (alrm.additionalText, sizeof(alrm.additionalText), \
95              "cell id  [%d] is up",cellId);
96     strcpy(alrm.additionalInfo , "cell UP");
97     strcpy(alrm.specificProblem, "Active");
98     strcpy(alrm.alarmRaiseTime, buff);
99   }
100   else
101   {
102     /* Clear the cell up alarm */
103     clearCellAlrm(CELL_UP_ALARM_ID);
104     /* Fill the cell down parameters */
105     snprintf (alrm.additionalText, sizeof(alrm.additionalText), \
106               "cell [%d] is down",cellId);
107     strcpy(alrm.additionalInfo , "cell down");
108     strcpy(alrm.specificProblem, "Active");
109     strcpy(alrm.alarmRaiseTime, buff);
110   }
111   /*Raise the alarm */
112   return raiseAlarm(&alrm);
113 }
114
115 /********************************************************************** 
116    Description : Clear the cell alarm
117    Params[In]  : alarm Id
118    Return      : ROK     - success
119                  RFAILED - failure
120 **********************************************************************/
121 uint8_t clearCellAlrm(uint16_t alrmId)
122 {
123   AlarmRecord alrm;
124   snprintf (alrm.alarmId, sizeof(alrm.alarmId), "%d",alrmId);
125   return clearAlarm(&alrm);
126 }
127   
128
129 /**********************************************************************
130          End of file
131 **********************************************************************/