Make containerId optional in the event json file

During the PDR exchange, normalization causes the container IDs of
remote entities to change. Therefore, checking for a predefined
container ID from a remote terminus for sensor events does not provide
any benefit. This commit adds support for optionally skipping the check
for remote container id for sensor events when needed.

Tested:
Unit tests passed.

Change-Id: I871044815194b7aed507c105ae04f1418e084de1
Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
diff --git a/host-bmc/host_pdr_handler.cpp b/host-bmc/host_pdr_handler.cpp
index f6a1a04..352a2e4 100644
--- a/host-bmc/host_pdr_handler.cpp
+++ b/host-bmc/host_pdr_handler.cpp
@@ -888,9 +888,9 @@
                                      entityInstance] = entityInfo;
                         auto stateSetId = stateSetIds[sensorOffset];
                         pldm::responder::events::StateSensorEntry
-                            stateSensorEntry{containerId, entityType,
+                            stateSensorEntry{containerId,    entityType,
                                              entityInstance, sensorOffset,
-                                             stateSetId};
+                                             stateSetId,     false};
                         handleStateSensorEvent(stateSensorEntry, eventState);
                     }
                 };
diff --git a/libpldmresponder/event_parser.cpp b/libpldmresponder/event_parser.cpp
index 611c7ec..b006d56 100644
--- a/libpldmresponder/event_parser.cpp
+++ b/libpldmresponder/event_parser.cpp
@@ -49,7 +49,7 @@
         {
             StateSensorEntry stateSensorEntry{};
             stateSensorEntry.containerId =
-                static_cast<uint16_t>(entry.value("containerID", 0));
+                static_cast<uint16_t>(entry.value("containerID", 0xFFFF));
             stateSensorEntry.entityType =
                 static_cast<uint16_t>(entry.value("entityType", 0));
             stateSensorEntry.entityInstance =
@@ -59,6 +59,10 @@
             stateSensorEntry.stateSetid =
                 static_cast<uint16_t>(entry.value("stateSetId", 0));
 
+            // container id is not found in the json
+            stateSensorEntry.skipContainerId =
+                (stateSensorEntry.containerId == 0xFFFF) ? true : false;
+
             pldm::utils::DBusMapping dbusInfo{};
 
             auto dbus = entry.value("dbus", emptyJson);
diff --git a/libpldmresponder/event_parser.hpp b/libpldmresponder/event_parser.hpp
index 7498c4c..471c151 100644
--- a/libpldmresponder/event_parser.hpp
+++ b/libpldmresponder/event_parser.hpp
@@ -28,28 +28,43 @@
     pdr::EntityInstance entityInstance;
     pdr::SensorOffset sensorOffset;
     pdr::StateSetId stateSetid;
+    bool skipContainerId;
 
     bool operator==(const StateSensorEntry& e) const
     {
-        return (
-            (containerId == e.containerId) && (entityType == e.entityType) &&
-            (entityInstance == e.entityInstance) &&
-            (sensorOffset == e.sensorOffset) && (stateSetid == e.stateSetid));
+        if (!skipContainerId)
+        {
+            return ((containerId == e.containerId) &&
+                    (entityType == e.entityType) &&
+                    (entityInstance == e.entityInstance) &&
+                    (sensorOffset == e.sensorOffset) &&
+                    (stateSetid == e.stateSetid));
+        }
+        else
+        {
+            return ((entityType == e.entityType) &&
+                    (entityInstance == e.entityInstance) &&
+                    (sensorOffset == e.sensorOffset) &&
+                    (stateSetid == e.stateSetid));
+        }
     }
 
     bool operator<(const StateSensorEntry& e) const
     {
-        return (
-            (containerId < e.containerId) ||
-            ((containerId == e.containerId) && (entityType < e.entityType)) ||
-            ((containerId == e.containerId) && (entityType == e.entityType) &&
-             (entityInstance < e.entityInstance)) ||
-            ((containerId == e.containerId) && (entityType == e.entityType) &&
-             (entityInstance == e.entityInstance) &&
-             (sensorOffset < e.sensorOffset)) ||
-            ((containerId == e.containerId) && (entityType == e.entityType) &&
-             (entityInstance == e.entityInstance) &&
-             (sensorOffset == e.sensorOffset) && (stateSetid < e.stateSetid)));
+        if (!skipContainerId)
+        {
+            return std::tie(entityType, entityInstance, containerId,
+                            sensorOffset, stateSetid) <
+                   std::tie(e.entityType, e.entityInstance, e.containerId,
+                            e.sensorOffset, e.stateSetid);
+        }
+        else
+        {
+            return std::tie(entityType, entityInstance, sensorOffset,
+                            stateSetid) <
+                   std::tie(e.entityType, e.entityInstance, e.sensorOffset,
+                            e.stateSetid);
+        }
     }
 };
 
diff --git a/libpldmresponder/platform.cpp b/libpldmresponder/platform.cpp
index be554dd..42bfc83 100644
--- a/libpldmresponder/platform.cpp
+++ b/libpldmresponder/platform.cpp
@@ -499,9 +499,12 @@
         }
 
         const auto& [containerId, entityType, entityInstance] = entityInfo;
-        events::StateSensorEntry stateSensorEntry{containerId, entityType,
-                                                  entityInstance, sensorOffset,
-                                                  stateSetIds[sensorOffset]};
+        events::StateSensorEntry stateSensorEntry{containerId,
+                                                  entityType,
+                                                  entityInstance,
+                                                  sensorOffset,
+                                                  stateSetIds[sensorOffset],
+                                                  false};
         return hostPDRHandler->handleStateSensorEvent(stateSensorEntry,
                                                       eventState);
     }
diff --git a/libpldmresponder/test/event_jsons/good/event_state_sensor.json b/libpldmresponder/test/event_jsons/good/event_state_sensor.json
index b966076..9974b72 100644
--- a/libpldmresponder/test/event_jsons/good/event_state_sensor.json
+++ b/libpldmresponder/test/event_jsons/good/event_state_sensor.json
@@ -63,6 +63,50 @@
                 "property_type": "string",
                 "property_values": ["Enabled", "Disabled", "Auto"]
             }
+        },
+        {
+            "entityType": 120,
+            "entityInstance": 2,
+            "sensorOffset": 0,
+            "stateSetId": 2,
+            "event_states": [0, 1, 2],
+            "dbus": {
+                "object_path": "/xyz/abc/mno",
+                "interface": "xyz.openbmc_project.example5.value",
+                "property_name": "value5",
+                "property_type": "string",
+                "property_values": ["Enabled", "Disabled", "Auto"]
+            }
+        },
+        {
+            "entityType": 120,
+            "containerID": 10,
+            "entityInstance": 2,
+            "sensorOffset": 0,
+            "stateSetId": 2,
+            "event_states": [0, 1, 2],
+            "dbus": {
+                "object_path": "/xyz/abc/opk",
+                "interface": "xyz.openbmc_project.example6.value",
+                "property_name": "value6",
+                "property_type": "string",
+                "property_values": ["Enabled", "Disabled", "Auto"]
+            }
+        },
+        {
+            "entityType": 120,
+            "containerID": 10,
+            "entityInstance": 2,
+            "sensorOffset": 0,
+            "stateSetId": 2,
+            "event_states": [0, 1, 2],
+            "dbus": {
+                "object_path": "/xyz/abc/ijl",
+                "interface": "xyz.openbmc_project.example7.value",
+                "property_name": "value7",
+                "property_type": "string",
+                "property_values": ["Enabled", "Disabled", "Auto"]
+            }
         }
     ]
 }
diff --git a/libpldmresponder/test/libpldmresponder_platform_test.cpp b/libpldmresponder/test/libpldmresponder_platform_test.cpp
index 9dbe0af..35da05a 100644
--- a/libpldmresponder/test/libpldmresponder_platform_test.cpp
+++ b/libpldmresponder/test/libpldmresponder_platform_test.cpp
@@ -602,7 +602,7 @@
 
     // Event Entry 1
     {
-        StateSensorEntry entry{1, 64, 1, 0, 1};
+        StateSensorEntry entry{1, 64, 1, 0, 1, false};
         const auto& [dbusMapping, eventStateMap] = handler.getEventInfo(entry);
         DBusMapping mapping{"/xyz/abc/def",
                             "xyz.openbmc_project.example1.value", "value1",
@@ -625,7 +625,7 @@
 
     // Event Entry 2
     {
-        StateSensorEntry entry{1, 64, 1, 1, 1};
+        StateSensorEntry entry{1, 64, 1, 1, 1, false};
         const auto& [dbusMapping, eventStateMap] = handler.getEventInfo(entry);
         DBusMapping mapping{"/xyz/abc/def",
                             "xyz.openbmc_project.example2.value", "value2",
@@ -642,7 +642,7 @@
 
     // Event Entry 3
     {
-        StateSensorEntry entry{2, 67, 2, 0, 1};
+        StateSensorEntry entry{2, 67, 2, 0, 1, false};
         const auto& [dbusMapping, eventStateMap] = handler.getEventInfo(entry);
         DBusMapping mapping{"/xyz/abc/ghi",
                             "xyz.openbmc_project.example3.value", "value3",
@@ -659,7 +659,7 @@
 
     // Event Entry 4
     {
-        StateSensorEntry entry{2, 67, 2, 0, 2};
+        StateSensorEntry entry{2, 67, 2, 0, 2, false};
         const auto& [dbusMapping, eventStateMap] = handler.getEventInfo(entry);
         DBusMapping mapping{"/xyz/abc/jkl",
                             "xyz.openbmc_project.example4.value", "value4",
@@ -677,9 +677,67 @@
         ASSERT_EQ(value2 == propValue2, true);
     }
 
+    // Event Entry 5
+    {
+        StateSensorEntry entry{0xFFFF, 120, 2, 0, 2, true};
+        const auto& [dbusMapping, eventStateMap] = handler.getEventInfo(entry);
+        DBusMapping mapping{"/xyz/abc/mno",
+                            "xyz.openbmc_project.example5.value", "value5",
+                            "string"};
+        ASSERT_EQ(mapping == dbusMapping, true);
+
+        const auto& propValue0 = eventStateMap.at(eventState0);
+        const auto& propValue1 = eventStateMap.at(eventState1);
+        const auto& propValue2 = eventStateMap.at(eventState2);
+        PropertyValue value0{std::in_place_type<std::string>, "Enabled"};
+        PropertyValue value1{std::in_place_type<std::string>, "Disabled"};
+        PropertyValue value2{std::in_place_type<std::string>, "Auto"};
+        ASSERT_EQ(value0 == propValue0, true);
+        ASSERT_EQ(value1 == propValue1, true);
+        ASSERT_EQ(value2 == propValue2, true);
+    }
+    // Event Entry 6
+    {
+        StateSensorEntry entry{10, 120, 2, 0, 2, true};
+        const auto& [dbusMapping, eventStateMap] = handler.getEventInfo(entry);
+        DBusMapping mapping{"/xyz/abc/opk",
+                            "xyz.openbmc_project.example6.value", "value6",
+                            "string"};
+        ASSERT_EQ(mapping == dbusMapping, true);
+
+        const auto& propValue0 = eventStateMap.at(eventState0);
+        const auto& propValue1 = eventStateMap.at(eventState1);
+        const auto& propValue2 = eventStateMap.at(eventState2);
+        PropertyValue value0{std::in_place_type<std::string>, "Enabled"};
+        PropertyValue value1{std::in_place_type<std::string>, "Disabled"};
+        PropertyValue value2{std::in_place_type<std::string>, "Auto"};
+        ASSERT_EQ(value0 == propValue0, true);
+        ASSERT_EQ(value1 == propValue1, true);
+        ASSERT_EQ(value2 == propValue2, true);
+    }
+    // Event Entry 7
+    {
+        StateSensorEntry entry{10, 120, 2, 0, 2, false};
+        const auto& [dbusMapping, eventStateMap] = handler.getEventInfo(entry);
+        DBusMapping mapping{"/xyz/abc/opk",
+                            "xyz.openbmc_project.example6.value", "value6",
+                            "string"};
+        ASSERT_EQ(mapping == dbusMapping, true);
+
+        const auto& propValue0 = eventStateMap.at(eventState0);
+        const auto& propValue1 = eventStateMap.at(eventState1);
+        const auto& propValue2 = eventStateMap.at(eventState2);
+        PropertyValue value0{std::in_place_type<std::string>, "Enabled"};
+        PropertyValue value1{std::in_place_type<std::string>, "Disabled"};
+        PropertyValue value2{std::in_place_type<std::string>, "Auto"};
+        ASSERT_EQ(value0 == propValue0, true);
+        ASSERT_EQ(value1 == propValue1, true);
+        ASSERT_EQ(value2 == propValue2, true);
+    }
+
     // Invalid Entry
     {
-        StateSensorEntry entry{0, 0, 0, 0, 1};
+        StateSensorEntry entry{0, 0, 0, 0, 1, false};
         ASSERT_THROW(handler.getEventInfo(entry), std::out_of_range);
     }
 }
diff --git a/oem/ibm/configurations/events/oem_ibm_event_state_sensor.json b/oem/ibm/configurations/events/oem_ibm_event_state_sensor.json
index e785466..9741b30 100644
--- a/oem/ibm/configurations/events/oem_ibm_event_state_sensor.json
+++ b/oem/ibm/configurations/events/oem_ibm_event_state_sensor.json
@@ -1,7 +1,6 @@
 {
     "entries": [
         {
-            "containerID": 0,
             "entityType": 57346,
             "entityInstance": 0,
             "sensorOffset": 1,
@@ -16,7 +15,6 @@
             }
         },
         {
-            "containerID": 0,
             "entityType": 57346,
             "entityInstance": 1,
             "sensorOffset": 1,
@@ -31,7 +29,6 @@
             }
         },
         {
-            "containerID": 0,
             "entityType": 57347,
             "entityInstance": 0,
             "sensorOffset": 1,
@@ -46,7 +43,6 @@
             }
         },
         {
-            "containerID": 0,
             "entityType": 57347,
             "entityInstance": 1,
             "sensorOffset": 1,