host-bmc: Implement Availability interface
Adding support to host Availability dbus interface. PLDM hosts this dbus
interface to provide the availability of the FRUs hosted by PLDM. The
Availability interface is defined at [1].
Tested:
Functional test passed
[1]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/State/Decorator/Availability.interface.yaml
Change-Id: Ie5912b3683ce102a249c8b503ea9f455f0fbcabf
Signed-off-by: Archana Kakani <archana.kakani@ibm.com>
diff --git a/host-bmc/dbus/availability.cpp b/host-bmc/dbus/availability.cpp
new file mode 100644
index 0000000..c4f10e1
--- /dev/null
+++ b/host-bmc/dbus/availability.cpp
@@ -0,0 +1,21 @@
+#include "availability.hpp"
+
+namespace pldm
+{
+namespace dbus
+{
+
+bool Availability::available() const
+{
+ return sdbusplus::xyz::openbmc_project::State::Decorator::server::
+ Availability::available();
+}
+
+bool Availability::available(bool value)
+{
+ return sdbusplus::xyz::openbmc_project::State::Decorator::server::
+ Availability::available(value);
+}
+
+} // namespace dbus
+} // namespace pldm
diff --git a/host-bmc/dbus/availability.hpp b/host-bmc/dbus/availability.hpp
new file mode 100644
index 0000000..5788f70
--- /dev/null
+++ b/host-bmc/dbus/availability.hpp
@@ -0,0 +1,42 @@
+#pragma once
+
+#include <sdbusplus/bus.hpp>
+#include <sdbusplus/server.hpp>
+#include <sdbusplus/server/object.hpp>
+#include <xyz/openbmc_project/State/Decorator/Availability/server.hpp>
+
+#include <string>
+
+namespace pldm
+{
+namespace dbus
+{
+using AvailabilityIntf = sdbusplus::server::object_t<
+ sdbusplus::xyz::openbmc_project::State::Decorator::server::Availability>;
+
+class Availability : public AvailabilityIntf
+{
+ public:
+ Availability() = delete;
+ ~Availability() = default;
+ Availability(const Availability&) = delete;
+ Availability& operator=(const Availability&) = delete;
+ Availability(Availability&&) = delete;
+ Availability& operator=(Availability&&) = delete;
+
+ Availability(sdbusplus::bus_t& bus, const std::string& objPath) :
+ AvailabilityIntf(bus, objPath.c_str()), path(objPath)
+ {}
+
+ /** Get value of Available */
+ bool available() const override;
+
+ /** Set value of Available */
+ bool available(bool value) override;
+
+ private:
+ std::string path;
+};
+
+} // namespace dbus
+} // namespace pldm
diff --git a/host-bmc/dbus/custom_dbus.cpp b/host-bmc/dbus/custom_dbus.cpp
index f5dd592..f4581d8 100644
--- a/host-bmc/dbus/custom_dbus.cpp
+++ b/host-bmc/dbus/custom_dbus.cpp
@@ -166,5 +166,18 @@
}
}
+void CustomDBus::setAvailabilityState(const std::string& path,
+ const bool& state)
+{
+ if (!availabilityState.contains(path))
+ {
+ availabilityState.emplace(
+ path, std::make_unique<Availability>(
+ pldm::utils::DBusHandler::getBus(), path.c_str()));
+ }
+
+ availabilityState.at(path)->available(state);
+}
+
} // namespace dbus
} // namespace pldm
diff --git a/host-bmc/dbus/custom_dbus.hpp b/host-bmc/dbus/custom_dbus.hpp
index 7988bd9..281f928 100644
--- a/host-bmc/dbus/custom_dbus.hpp
+++ b/host-bmc/dbus/custom_dbus.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "asset.hpp"
+#include "availability.hpp"
#include "cable.hpp"
#include "chassis.hpp"
#include "common/utils.hpp"
@@ -165,8 +166,18 @@
*/
void implementAssetInterface(const std::string& path);
+ /** @brief Set the availability state property
+ *
+ * @param[in] path - The object path
+ *
+ * @param[in] state - Availability state
+ */
+ void setAvailabilityState(const std::string& path, const bool& state);
+
private:
std::unordered_map<ObjectPath, std::unique_ptr<Asset>> asset;
+ std::unordered_map<ObjectPath, std::unique_ptr<Availability>>
+ availabilityState;
std::unordered_map<ObjectPath, std::unique_ptr<LocationIntf>> location;
std::unordered_map<ObjectPath, std::unique_ptr<CPUCore>> cpuCore;
std::unordered_map<ObjectPath, std::unique_ptr<ItemChassis>> chassis;
diff --git a/host-bmc/host_pdr_handler.cpp b/host-bmc/host_pdr_handler.cpp
index 7c5e33d..524c55b 100644
--- a/host-bmc/host_pdr_handler.cpp
+++ b/host-bmc/host_pdr_handler.cpp
@@ -115,6 +115,9 @@
const auto& [key, value] = item;
return key != TERMINUS_HANDLE;
});
+ // when the host is powered off, set the availability
+ // state of all the dbus objects to false
+ this->setPresenceFrus();
pldm_pdr_remove_remote_pdrs(repo);
pldm_entity_association_tree_destroy_root(entityTree);
pldm_entity_association_tree_copy_root(bmcEntityTree,
@@ -127,6 +130,15 @@
});
}
+void HostPDRHandler::setPresenceFrus()
+{
+ // iterate over all dbus objects
+ for (const auto& [path, entityId] : objPathMap)
+ {
+ CustomDBus::getCustomDBus().setAvailabilityState(path, false);
+ }
+}
+
void HostPDRHandler::fetchPDR(PDRRecordHandles&& recordHandles)
{
pdrRecordHandles.clear();
@@ -1122,11 +1134,21 @@
}
#endif
}
+
+void HostPDRHandler::setAvailabilityState(const std::string& path)
+{
+ CustomDBus::getCustomDBus().setAvailabilityState(path, true);
+}
+
void HostPDRHandler::createDbusObjects(const PDRList& fruRecordSetPDRs)
{
- // TODO: Creating and Refreshing dbus hosted by remote PLDM entity Fru PDRs
+ // Creating and Refreshing dbus hosted by remote PLDM entity Fru PDRs
+
for (const auto& entity : objPathMap)
{
+ // Implement & update the Availability to true
+ setAvailabilityState(entity.first);
+
pldm_entity node = pldm_entity_extract(entity.second);
switch (node.entity_type)
{
diff --git a/host-bmc/host_pdr_handler.hpp b/host-bmc/host_pdr_handler.hpp
index cabe525..352dbf4 100644
--- a/host-bmc/host_pdr_handler.hpp
+++ b/host-bmc/host_pdr_handler.hpp
@@ -264,6 +264,15 @@
*/
void createDbusObjects(const PDRList& fruRecordSetPDRs);
+ /** @brief set the FRU presence based on the remote PLDM terminus off signal
+ */
+ void setPresenceFrus();
+
+ /** @brief Set the availabilty dbus Property
+ * @param[in] path - object path
+ */
+ void setAvailabilityState(const std::string& path);
+
/** @brief Get FRU Record Set Identifier from FRU Record data Format
* @param[in] fruRecordSetPDRs - fru record set pdr
* @param[in] entity - PLDM entity information
diff --git a/host-bmc/test/meson.build b/host-bmc/test/meson.build
index 0b9271e..5f7ba7b 100644
--- a/host-bmc/test/meson.build
+++ b/host-bmc/test/meson.build
@@ -8,6 +8,7 @@
'../utils.cpp',
'../dbus/custom_dbus.cpp',
'../dbus/asset.cpp',
+ '../dbus/availability.cpp',
'../dbus/cable.cpp',
'../dbus/chassis.cpp',
'../dbus/cpu_core.cpp',