requester: associate Entity Manager configs with MCTP endpoints
Currently, pldmd listens for new MCTP endpoint exposed by mctpd, but
they only shows their EID, Network Id, and SupportedMessageTypes, which
cannot fulfill some requirements, e.g., get the device's name or which
board it belongs to.
In openbmc, the additional information are exposed by Entity
Manager[1][2], so add this ability to `MctpDiscovery, it queries the
association between MCTP endpoints and Entity Manager configurations
from MCTP Reactor, when a new MCTP endpoint has been register by mctpd.
Added unit test for this commit to validate the association does work,
passed.
[1]: https://github.com/openbmc/entity-manager/blob/master/schemas/mctp.json
[2]: https://gerrit.openbmc.org/c/openbmc/dbus-sensors/+/69111
Change-Id: Ibf1717f1840e527f21bd8397e747ae121e2dcd25
Signed-off-by: Unive Tien <unive.tien.wiwynn@gmail.com>
diff --git a/common/test/mocked_utils.hpp b/common/test/mocked_utils.hpp
index ad6f8dc..1cec506 100644
--- a/common/test/mocked_utils.hpp
+++ b/common/test/mocked_utils.hpp
@@ -72,4 +72,13 @@
MOCK_METHOD(pldm::utils::GetSubTreePathsResponse, getSubTreePaths,
(const std::string&, int, const std::vector<std::string>&),
(const override));
+
+ MOCK_METHOD(pldm::utils::GetAssociatedSubTreeResponse, getAssociatedSubTree,
+ (const sdbusplus::message::object_path&,
+ const sdbusplus::message::object_path&, int,
+ const std::vector<std::string>&),
+ (const override));
+
+ MOCK_METHOD(pldm::utils::PropertyMap, getDbusPropertiesVariant,
+ (const char*, const char*, const char*), (const override));
};
diff --git a/common/types.hpp b/common/types.hpp
index 3c3613d..68d3c3c 100644
--- a/common/types.hpp
+++ b/common/types.hpp
@@ -32,14 +32,19 @@
*/
using NetworkId = uint32_t;
+/** @brief Type definition of MCTP name in string
+ */
+using MctpInfoName = std::optional<std::string>;
+
/** @brief Type definition of MCTP interface information between two endpoints.
* eid : Endpoint EID in byte. Defined to match with MCTP D-Bus
* interface
* UUID : Endpoint UUID which is used to different the endpoints
* MctpMedium: Endpoint MCTP Medium info (Resersed)
* NetworkId: MCTP network index
+ * name: Alias name of the endpoint, e.g. BMC, NIC, etc.
*/
-using MctpInfo = std::tuple<eid, UUID, MctpMedium, NetworkId>;
+using MctpInfo = std::tuple<eid, UUID, MctpMedium, NetworkId, MctpInfoName>;
/** @brief Type definition of MCTP endpoint D-Bus properties in
* xyz.openbmc_project.MCTP.Endpoint D-Bus interface.
@@ -79,9 +84,9 @@
using Interfaces = std::vector<std::string>;
using Property = std::string;
using PropertyType = std::string;
-using Value =
- std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t,
- uint64_t, double, std::string, std::vector<uint8_t>>;
+using Value = std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t,
+ int64_t, uint64_t, double, std::string,
+ std::vector<uint8_t>, std::vector<uint64_t>>;
using PropertyMap = std::map<Property, Value>;
using InterfaceMap = std::map<Interface, PropertyMap>;
@@ -89,6 +94,10 @@
} // namespace dbus
+/** @brief Binding of MCTP endpoint EID to Entity Manager's D-Bus object path
+ */
+using Configurations = std::map<dbus::ObjectPath, MctpInfo>;
+
namespace fw_update
{
diff --git a/common/utils.cpp b/common/utils.cpp
index 59b5d23..06c256c 100644
--- a/common/utils.cpp
+++ b/common/utils.cpp
@@ -408,6 +408,22 @@
return bus.call(method, dbusTimeout).unpack<PropertyValue>();
}
+GetAssociatedSubTreeResponse DBusHandler::getAssociatedSubTree(
+ const sdbusplus::message::object_path& objectPath,
+ const sdbusplus::message::object_path& subtree, int depth,
+ const std::vector<std::string>& ifaceList) const
+{
+ auto& bus = DBusHandler::getBus();
+ auto method = bus.new_method_call(
+ ObjectMapper::default_service, ObjectMapper::instance_path,
+ ObjectMapper::interface, "GetAssociatedSubTree");
+ method.append(objectPath, subtree, depth, ifaceList);
+ auto reply = bus.call(method, dbusTimeout);
+ GetAssociatedSubTreeResponse response;
+ reply.read(response);
+ return response;
+}
+
ObjectValueTree DBusHandler::getManagedObj(const char* service,
const char* rootPath)
{
diff --git a/common/utils.hpp b/common/utils.hpp
index 9964188..358d0d7 100644
--- a/common/utils.hpp
+++ b/common/utils.hpp
@@ -72,6 +72,7 @@
constexpr auto dbusProperties = "org.freedesktop.DBus.Properties";
constexpr auto mapperService = ObjectMapper::default_service;
constexpr auto inventoryPath = "/xyz/openbmc_project/inventory";
+
/** @struct CustomFD
*
* RAII wrapper for file descriptor.
@@ -174,7 +175,7 @@
using PropertyValue =
std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t,
uint64_t, double, std::string, std::vector<uint8_t>,
- std::vector<std::string>>;
+ std::vector<uint64_t>, std::vector<std::string>>;
using DbusProp = std::string;
using DbusChangedProps = std::map<DbusProp, PropertyValue>;
using DBusInterfaceAdded = std::vector<
@@ -194,6 +195,8 @@
using MapperServiceMap = std::vector<std::pair<ServiceName, Interfaces>>;
using GetSubTreeResponse = std::vector<std::pair<ObjectPath, MapperServiceMap>>;
using GetSubTreePathsResponse = std::vector<std::string>;
+using GetAssociatedSubTreeResponse =
+ std::map<std::string, std::map<std::string, std::vector<std::string>>>;
using GetAncestorsResponse =
std::vector<std::pair<ObjectPath, MapperServiceMap>>;
using PropertyMap = std::map<std::string, PropertyValue>;
@@ -232,6 +235,11 @@
virtual PropertyMap getDbusPropertiesVariant(
const char* serviceName, const char* objPath,
const char* dbusInterface) const = 0;
+
+ virtual GetAssociatedSubTreeResponse getAssociatedSubTree(
+ const sdbusplus::message::object_path& objectPath,
+ const sdbusplus::message::object_path& subtree, int depth,
+ const std::vector<std::string>& ifaceList) const = 0;
};
/**
@@ -362,6 +370,19 @@
return std::get<Property>(VariantValue);
}
+ /** @brief Get the associated subtree from the mapper
+ *
+ * @param[in] path - The D-Bus object path
+ *
+ * @param[in] interface - The D-Bus interface
+ *
+ * @return GetAssociatedSubtreeResponse - The associated subtree
+ */
+ GetAssociatedSubTreeResponse getAssociatedSubTree(
+ const sdbusplus::message::object_path& objectPath,
+ const sdbusplus::message::object_path& subtree, int depth,
+ const std::vector<std::string>& ifaceList) const override;
+
/** @brief Set Dbus property
*
* @param[in] dBusMap - Object path, property name, interface and property