This ticket adds support for implementing sections 3.1.3.5 and 6.2.1.1 of
the PLM spec. For now this support is only for threshold sensors.
---
 src/plm/common/plms_hsm.c           |  80 ++++++++++++++++++++++
 src/plm/common/plms_notifications.h |   2 +-
 src/plm/plmd/plms_he_pres_fsm.c     | 101 +++++++++++++++++++++++++++-
 src/plm/plmd/plms_notifications.c   |  24 +++++--
 4 files changed, 200 insertions(+), 7 deletions(-)

diff --git a/src/plm/common/plms_hsm.c b/src/plm/common/plms_hsm.c
index f8f7b6275..fe53f2fbd 100644
--- a/src/plm/common/plms_hsm.c
+++ b/src/plm/common/plms_hsm.c
@@ -99,6 +99,8 @@ static SaUint32T hsm_send_hotswap_event(SaHpiRptEntryT 
*rpt_entry,
                                        SaUint32T retriev_idr_info);
 static SaUint32T hsm_send_resource_event(const SaHpiRptEntryT *rpt_entry,
                                         const SaHpiEventT *event);
+static SaUint32T hsm_send_sensor_event(const SaHpiRptEntryT *rpt_entry,
+                                       const SaHpiEventT *event);
 SaUint32T hsm_correct_length(SaHpiIdrFieldT *thisfield);
 SaUint32T hsm_get_idr_info(SaHpiRptEntryT *rpt_entry, PLMS_INV_DATA *inv_data);
 static SaUint32T hsm_get_idr_product_info(SaHpiRptEntryT *rpt_entry,
@@ -766,6 +768,8 @@ static void *plms_hsm(void)
                SAHPI_ENTITY_PRESENCE will be generated, send the status after
                upgrade to check that the state has not changed */
                if (event.EventType == SAHPI_ET_SENSOR) {
+                       hsm_send_sensor_event(&rpt_entry, &event);
+
                        if (event.EventDataUnion.SensorEvent.SensorType ==
                            SAHPI_ENTITY_PRESENCE) {
                                hsm_send_hotswap_event(
@@ -1313,6 +1317,82 @@ static SaUint32T hsm_send_resource_event(const 
SaHpiRptEntryT *rpt_entry,
        return rc;
 }
 
+/**********************************************************************
+* @brief Sends resource event to PLM main thread
+*
+*
+* @param[in] rpt_entry
+* @param[in] retriev_idr_info
+*
+* @return NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE
+***********************************************************************/
+static SaUint32T hsm_send_sensor_event(const SaHpiRptEntryT *rpt_entry,
+                                        const SaHpiEventT *event)
+{
+       PLMS_CB *cb = plms_cb;
+       PLMS_EVT *plms_evt = NULL;
+       PLMS_EVT_REQ req_evt;
+       SaHpiEntityPathT entity_path;
+       SaInt8T *entity_path_str = NULL;
+       SaUint32T i, rc;
+
+       TRACE_ENTER();
+
+       if (NULL == rpt_entry) {
+               LOG_ER("Invalid rpt_entry");
+               return NCSCC_RC_FAILURE;
+       }
+
+       /* Get the entity path */
+       memset(&entity_path, 0, sizeof(SaHpiEntityPathT));
+       for (i = 0; i < SAHPI_MAX_ENTITY_PATH; i++) {
+               entity_path.Entry[i] = rpt_entry->ResourceEntity.Entry[i];
+
+               /* Stop copying when we see SAHPI_ENT_ROOT */
+               if (rpt_entry->ResourceEntity.Entry[i].EntityType ==
+                   SAHPI_ENT_ROOT)
+                       break;
+       }
+
+       memset(&req_evt, 0, sizeof(PLMS_EVT_REQ));
+
+       req_evt.req_type = PLMS_HPI_EVT_T;
+       req_evt.hpi_evt.sa_hpi_evt = *event;
+
+       /* convert SaHpiEntityPathT to string format */
+       rc = convert_entitypath_to_string(&entity_path, &entity_path_str);
+       if (NCSCC_RC_FAILURE == rc) {
+               /* Log */
+               return NCSCC_RC_FAILURE;
+       }
+       req_evt.hpi_evt.entity_path = entity_path_str;
+
+       /* Copy entity key to req_evt*/
+       memcpy(&req_evt.hpi_evt.epath_key, &entity_path, sizeof(entity_path));
+
+       plms_evt = (PLMS_EVT *)malloc(sizeof(PLMS_EVT));
+       if (NULL == plms_evt) {
+               LOG_ER("Memory allocation failed ret:%s", strerror(errno));
+               assert(0);
+       }
+       memset(plms_evt, 0, sizeof(PLMS_EVT));
+       plms_evt->req_res = PLMS_REQ;
+       plms_evt->req_evt = req_evt;
+
+       TRACE("Sending Sensor_event for res:%u entity:%s  Sensor Num:%u \n",
+             rpt_entry->ResourceId, entity_path_str,
+             event->EventDataUnion.SensorEvent.SensorNum);
+
+       /*  post event to PLM mailbox */
+       rc = m_NCS_IPC_SEND(&cb->mbx, (NCSCONTEXT)plms_evt,
+                           MDS_SEND_PRIORITY_MEDIUM);
+       if (rc != NCSCC_RC_SUCCESS)
+               LOG_ER("m_NCS_IPC_SEND failed error %u", rc);
+
+       TRACE_LEAVE();
+       return rc;
+}
+
 /***********************************************************************
  * @brief       This function retrieves Inventory Data  Record (IDR) for
  *              the given resource
diff --git a/src/plm/common/plms_notifications.h 
b/src/plm/common/plms_notifications.h
index 03cba1088..ea2929d6b 100644
--- a/src/plm/common/plms_notifications.h
+++ b/src/plm/common/plms_notifications.h
@@ -45,7 +45,7 @@ SaAisErrorT plms_hpi_evt_ntf_send(SaNtfHandleT plm_ntf_hdl, 
SaNameT *object,
 SaAisErrorT plms_alarm_ntf_send(SaNtfHandleT plm_ntf_hdl, SaNameT *object,
                                 SaUint32T event_type, SaInt8T *entity_path,
                                 SaUint32T severity, SaUint32T cause,
-                                SaUint32T minor_id,
+                                SaUint32T minor_id, SaTimeT timestamp,
                                 SaUint16T no_of_corr_notifications,
                                 SaNtfIdentifierT *corr_ids,
                                 SaNtfIdentifierT *ntf_id);
diff --git a/src/plm/plmd/plms_he_pres_fsm.c b/src/plm/plmd/plms_he_pres_fsm.c
index 1cba2e256..244b94199 100644
--- a/src/plm/plmd/plms_he_pres_fsm.c
+++ b/src/plm/plmd/plms_he_pres_fsm.c
@@ -71,6 +71,33 @@ static SaUint32T plms_act_resp_mngt_flag_clear(PLMS_ENTITY 
*);
 
 static SaUint32T plms_hpi_hs_evt_process(PLMS_EVT *);
 static SaUint32T plms_hpi_resource_evt_process(PLMS_EVT *);
+static SaUint32T plms_hpi_sensor_evt_process(PLMS_EVT *);
+
+static SaNtfSeverityT convertSeverity(SaHpiSeverityT hpiSeverity, bool 
asserted)
+{
+       SaNtfSeverityT ntfSeverity = SA_NTF_SEVERITY_INDETERMINATE;
+
+       if (!asserted)
+               ntfSeverity = SA_NTF_SEVERITY_CLEARED;
+       else if (hpiSeverity == SAHPI_CRITICAL)
+               ntfSeverity = SA_NTF_SEVERITY_CRITICAL;
+       else if (hpiSeverity == SAHPI_MAJOR)
+               ntfSeverity = SA_NTF_SEVERITY_MAJOR;
+       else if (hpiSeverity == SAHPI_MINOR)
+               ntfSeverity = SA_NTF_SEVERITY_MINOR;
+
+       return ntfSeverity;
+}
+
+static SaNtfProbableCauseT convertCause(SaHpiEventCategoryT category)
+{
+       SaNtfProbableCauseT cause = SA_NTF_UNSPECIFIED_REASON;
+
+       if (category == SAHPI_EC_THRESHOLD)
+               cause = SA_NTF_THRESHOLD_CROSSED;
+
+       return cause;
+}
 
 /******************************************************************************
 @brief         : Initializes the HE presence state FSM function pointers.
@@ -3114,6 +3141,8 @@ SaUint32T plms_hpi_evt_process(PLMS_EVT *evt)
                rc = plms_hpi_hs_evt_process(evt);
        else if (evt->req_evt.hpi_evt.sa_hpi_evt.EventType == SAHPI_ET_RESOURCE)
                rc = plms_hpi_resource_evt_process(evt);
+       else if (evt->req_evt.hpi_evt.sa_hpi_evt.EventType == SAHPI_ET_SENSOR)
+               rc = plms_hpi_sensor_evt_process(evt);
        else {
                LOG_ER("Unknown HPI event received: %i",
                       evt->req_evt.hpi_evt.sa_hpi_evt.EventType);
@@ -3208,7 +3237,8 @@ static SaUint32T plms_hpi_hs_evt_process(PLMS_EVT *evt)
                                    hpi_evt->entity_path,
                                    SA_NTF_SEVERITY_CRITICAL,
                                    SA_NTF_AUTHENTICATION_FAILURE,
-                                   SA_PLM_NTFID_UNMAPPED_HE_ALARM, 0,
+                                   SA_PLM_NTFID_UNMAPPED_HE_ALARM,
+                                   hpi_evt->sa_hpi_evt.Timestamp, 0,
                                    NULL /*cor_ids*/, NULL /*buf*/);
                                if (NCSCC_RC_SUCCESS != ret_err) {
                                        LOG_ER("Unmapped HE notification \
@@ -3437,6 +3467,75 @@ static SaUint32T plms_hpi_resource_evt_process(PLMS_EVT 
*evt)
        return rc;
 }
 /******************************************************************************
+@brief         : Process HPI sensor events. This function does the
+following things 1. Handle SAHPI_RESE_RESOURCE_FAILURE event, and set 
management
+lost 2. Handle SAHPI_RESE_RESOURCE_RESTORED, and clear management lost
+
+@param[in]     : evt - PLMS_EVT representation of the SENSOR event.
+
+@return                : NCSCC_RC_FAILURE/NCSCC_RC_SUCCESS
+******************************************************************************/
+static SaUint32T plms_hpi_sensor_evt_process(PLMS_EVT *evt)
+{
+       SaUint32T rc = NCSCC_RC_SUCCESS;
+       PLMS_HPI_EVT *hpi_evt = &(evt->req_evt.hpi_evt);
+       SaHpiSensorEventT *sensorEvent = 
&hpi_evt->sa_hpi_evt.EventDataUnion.SensorEvent;
+
+       TRACE_ENTER2("Entity: %s, sensor num: %u", hpi_evt->entity_path,
+                       sensorEvent->SensorNum);
+
+       do {
+               PLMS_EPATH_TO_ENTITY_MAP_INFO *epath_to_ent;
+               PLMS_ENTITY *ent;
+               PLMS_CB *cb = plms_cb;
+
+               if (cb->ha_state == SA_AMF_HA_STANDBY) {
+                       TRACE_LEAVE2(
+                           "Ignoring the event as current role is standby");
+                       break;
+               }
+
+               if (hpi_evt->sa_hpi_evt.Severity > SAHPI_MINOR)
+                       break;
+
+               epath_to_ent =
+                   (PLMS_EPATH_TO_ENTITY_MAP_INFO *)ncs_patricia_tree_get(
+                       &(cb->epath_to_entity_map_info),
+                       (SaUint8T *)&(hpi_evt->epath_key));
+
+               if (NULL == epath_to_ent) {
+                       LOG_ER(
+                           "Received SENSOR event num %u for unknown resource 
%s",
+                           sensorEvent->SensorNum,
+                           hpi_evt->entity_path);
+                       break;
+               }
+
+               ent = epath_to_ent->plms_entity;
+
+               rc = plms_alarm_ntf_send(cb->ntf_hdl,
+                                       &ent->dn_name,
+                                       SA_NTF_ALARM_EQUIPMENT,
+                                       hpi_evt->entity_path,
+                                       
convertSeverity(hpi_evt->sa_hpi_evt.Severity,
+                                               sensorEvent->Assertion),
+                                       
convertCause(sensorEvent->EventCategory),
+                                       SA_PLM_NTFID_HE_ALARM,
+                                       hpi_evt->sa_hpi_evt.Timestamp,
+                                       0,
+                                       0,
+                                       0);
+
+               if (rc != NCSCC_RC_SUCCESS) {
+                       LOG_ER("Failed to send NTF alarm for %s",
+                               hpi_evt->entity_path);
+               }
+       } while (false);
+
+       TRACE_LEAVE2("Return Val: %d", rc);
+       return rc;
+}
+/******************************************************************************
 @brief         : Verifies the HE.
                1. Verifies configured entity paths against hpi published.
                2. Verifies configured inv date against the published one.
diff --git a/src/plm/plmd/plms_notifications.c 
b/src/plm/plmd/plms_notifications.c
index 95a61501c..02e9f97a0 100644
--- a/src/plm/plmd/plms_notifications.c
+++ b/src/plm/plmd/plms_notifications.c
@@ -369,6 +369,7 @@ SaAisErrorT plms_alarm_ntf_send(SaNtfHandleT plm_ntf_hdl, 
SaNameT *object,
                                SaUint32T event_type, SaInt8T *entity_path,
                                SaUint32T severity, SaUint32T cause,
                                SaUint32T minor_id,
+                               SaTimeT timestamp,
                                SaUint16T no_of_corr_notifications,
                                SaNtfIdentifierT *corr_ids,
                                SaNtfIdentifierT *ntf_id)
@@ -376,12 +377,21 @@ SaAisErrorT plms_alarm_ntf_send(SaNtfHandleT plm_ntf_hdl, 
SaNameT *object,
        SaNtfAlarmNotificationT plm_notification;
        SaAisErrorT ret;
        SaStringT dest_ptr = NULL;
-       SaUint16T ntf_obj_len = 0;
+       SaUint16T ntf_obj_len = 0, lengthAdditionalText = 0;
+       char additionalText[SA_MAX_NAME_LENGTH + 23] = { 0 };
+
+       if (minor_id == SA_PLM_NTFID_HE_ALARM) {
+               snprintf(additionalText,
+                       object->length,
+                       "Hardware element %s alarm",
+                       object->value);
+               lengthAdditionalText = strlen(additionalText) + 1;
+       }
 
        ret = saNtfAlarmNotificationAllocate(
            plm_ntf_hdl, &plm_notification,
            no_of_corr_notifications, /* FIXME no of corelated notifications */
-           0,                        /* FIXME Length of additional text */
+           lengthAdditionalText,
            1,                        /* FIXME assuming only entity path */
            0,                        /* FIXME no of specific problems */
            0,                        /* FIXME No of monitored attributes */
@@ -395,9 +405,7 @@ SaAisErrorT plms_alarm_ntf_send(SaNtfHandleT plm_ntf_hdl, 
SaNameT *object,
 
        /* Fill the common parameters of HE, EE and unmapped HE Alarm */
        *(plm_notification.notificationHeader.eventType) = event_type;
-       *(plm_notification.notificationHeader.eventTime) =
-           (SaTimeT)SA_TIME_UNKNOWN; /* FIXME */
-       ;                             /* Put current time */
+       *(plm_notification.notificationHeader.eventTime) = timestamp;
 
        /* Copy noticationObject details give above */
        plm_notification.notificationHeader.notificationObject->length =
@@ -449,6 +457,12 @@ SaAisErrorT plms_alarm_ntf_send(SaNtfHandleT plm_ntf_hdl, 
SaNameT *object,
                memcpy(dest_ptr, entity_path, strlen(entity_path));
        }
 
+       if (lengthAdditionalText) {
+               strncpy(plm_notification.notificationHeader.additionalText,
+                       additionalText,
+                       lengthAdditionalText);
+       }
+
        ret = saNtfNotificationSend(plm_notification.notificationHandle);
 
        if (ret != SA_AIS_OK) {
-- 
2.17.2


-----------------------------------------------------------------------------------------------------------------------
Notice: This e-mail together with any attachments may contain information of 
Ribbon Communications Inc. that
is confidential and/or proprietary for the sole use of the intended recipient.  
Any review, disclosure, reliance or
distribution by others or forwarding without express permission is strictly 
prohibited.  If you are not the intended
recipient, please notify the sender immediately and then delete all copies, 
including any attachments.
-----------------------------------------------------------------------------------------------------------------------

_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to