Skip to content

Commit

Permalink
requester: MctpDiscovery: Added inventory path
Browse files Browse the repository at this point in the history
Made it get the inventory path from association created by `mctpd`
or configuration in static endpoint table.

The inventory path is for platform-mc terminus.

Tested with:
CodeConstruct/mctp#17
https://gerrit.openbmc.org/c/openbmc/entity-manager/+/66750
which gets static EID from entity-manager and creates association
definition D-Bus interface.

Change-Id: Ic9d0b6cd602d71a6fa51a73bd45964c2a0dac6aa
Signed-off-by: Delphine CC Chiu <[email protected]>
  • Loading branch information
DelphineCCChiu committed Feb 1, 2024
1 parent 4afc825 commit e3f13c9
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 26 deletions.
10 changes: 6 additions & 4 deletions common/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ using Request = std::vector<uint8_t>;
using Response = std::vector<uint8_t>;
using Command = uint8_t;

using Association = std::tuple<std::string, std::string, std::string>;
using InventoryPath = std::string;
using MctpMedium = std::string;
using NetworkId = uint32_t;
using MctpInfo = std::tuple<eid, UUID, MctpMedium, NetworkId>;
using MctpInfo = std::tuple<eid, UUID, MctpMedium, NetworkId, InventoryPath>;
using MctpInfos = std::vector<MctpInfo>;
using tid_t = uint8_t;

Expand All @@ -36,9 +38,9 @@ using Interface = std::string;
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<Association>>;

using PropertyMap = std::map<Property, Value>;
using InterfaceMap = std::map<Interface, PropertyMap>;
Expand Down
4 changes: 2 additions & 2 deletions platform-mc/test/event_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ TEST_F(EventManagerTest, getSensorThresholdMessageIdTest)
TEST_F(EventManagerTest, SetEventReceiverTest)
{
// Add terminus
auto mappedTid = terminusManager.mapTid(pldm::MctpInfo(1, "", "", 1));
auto mappedTid = terminusManager.mapTid(pldm::MctpInfo(1, "", "", 1, ""));
auto tid = mappedTid.value();
termini[tid] =
std::make_shared<Terminus>(tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
Expand Down Expand Up @@ -349,7 +349,7 @@ TEST_F(EventManagerTest, SetEventReceiverTest)
TEST_F(EventManagerTest, pollForPlatformEventTaskMultipartTransferTest)
{
// Add terminus
auto mappedTid = terminusManager.mapTid(pldm::MctpInfo(1, "", "", 1));
auto mappedTid = terminusManager.mapTid(pldm::MctpInfo(1, "", "", 1, ""));
auto tid = mappedTid.value();
termini[tid] =
std::make_shared<Terminus>(tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
Expand Down
9 changes: 6 additions & 3 deletions platform-mc/test/platform_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class PlatformManagerTest : public testing::Test
TEST_F(PlatformManagerTest, initTerminusTest)
{
// Add terminus
auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(1, "", "", 1));
auto mappedTid =
mockTerminusManager.mapTid(pldm::MctpInfo(1, "", "", 1, ""));
auto tid = mappedTid.value();
termini[tid] =
std::make_shared<Terminus>(tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
Expand Down Expand Up @@ -164,7 +165,8 @@ TEST_F(PlatformManagerTest, initTerminusTest)
TEST_F(PlatformManagerTest, negativeInitTerminusTest1)
{
// terminus doesn't Type2 support
auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(1, "", "", 1));
auto mappedTid =
mockTerminusManager.mapTid(pldm::MctpInfo(1, "", "", 1, ""));
auto tid = mappedTid.value();
termini[tid] = std::make_shared<Terminus>(tid, 1 << PLDM_BASE);
auto terminus = termini[tid];
Expand All @@ -178,7 +180,8 @@ TEST_F(PlatformManagerTest, negativeInitTerminusTest1)
TEST_F(PlatformManagerTest, negativeInitTerminusTest2)
{
// terminus responses error
auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(1, "", "", 1));
auto mappedTid =
mockTerminusManager.mapTid(pldm::MctpInfo(1, "", "", 1, ""));
auto tid = mappedTid.value();
termini[tid] =
std::make_shared<Terminus>(tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
Expand Down
22 changes: 11 additions & 11 deletions platform-mc/test/terminus_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TerminusManagerTest : public testing::Test

TEST_F(TerminusManagerTest, mapTidTest)
{
pldm::MctpInfo mctpInfo1(1, "", "", 0);
pldm::MctpInfo mctpInfo1(1, "", "", 0, "");

auto mappedTid1 = terminusManager.mapTid(mctpInfo1);
EXPECT_NE(mappedTid1, std::nullopt);
Expand All @@ -68,38 +68,38 @@ TEST_F(TerminusManagerTest, mapTidTest)
TEST_F(TerminusManagerTest, negativeMapTidTest)
{
// map null EID(0) to TID
pldm::MctpInfo m0(0, "", "", 0);
pldm::MctpInfo m0(0, "", "", 0, "");
auto mappedTid = terminusManager.mapTid(m0);
EXPECT_EQ(mappedTid, std::nullopt);

// map broadcast EID(0xff) to TID
pldm::MctpInfo m1(0xff, "", "", 0);
pldm::MctpInfo m1(0xff, "", "", 0, "");
mappedTid = terminusManager.mapTid(m1);
EXPECT_EQ(mappedTid, std::nullopt);

// map EID to tid which has been assigned
pldm::MctpInfo m2(2, "", "", 1);
pldm::MctpInfo m3(3, "", "", 1);
pldm::MctpInfo m2(2, "", "", 1, "");
pldm::MctpInfo m3(3, "", "", 1, "");
auto mappedTid2 = terminusManager.mapTid(m2);
auto mappedTid3 = terminusManager.mapTid(m3, mappedTid2.value());
EXPECT_NE(mappedTid2, std::nullopt);
EXPECT_EQ(mappedTid3, std::nullopt);

// map two mctpInfo with same EID but different network Id
pldm::MctpInfo m4(12, "", "", 1);
pldm::MctpInfo m5(12, "", "", 2);
pldm::MctpInfo m4(12, "", "", 1, "");
pldm::MctpInfo m5(12, "", "", 2, "");
auto mappedTid4 = terminusManager.mapTid(m4);
auto mappedTid5 = terminusManager.mapTid(m5);
EXPECT_NE(mappedTid4.value(), mappedTid5.value());

// map same mctpInfo twice
pldm::MctpInfo m6(12, "", "", 3);
pldm::MctpInfo m6(12, "", "", 3, "");
auto mappedTid6 = terminusManager.mapTid(m6);
auto mappedTid6_1 = terminusManager.mapTid(m6);
EXPECT_EQ(mappedTid6.value(), mappedTid6_1.value());

// look up an unmapped MctpInfo to TID
pldm::MctpInfo m7(1, "", "", 0);
pldm::MctpInfo m7(1, "", "", 0, "");
auto mappedTid7 = terminusManager.toTid(m7);
EXPECT_EQ(mappedTid7, std::nullopt);

Expand Down Expand Up @@ -153,7 +153,7 @@ TEST_F(TerminusManagerTest, discoverMctpTerminusTest)
EXPECT_EQ(rc, PLDM_SUCCESS);

pldm::MctpInfos mctpInfos{};
mctpInfos.emplace_back(pldm::MctpInfo(12, "", "", 1));
mctpInfos.emplace_back(pldm::MctpInfo(12, "", "", 1, ""));
mockTerminusManager.discoverMctpTerminus(mctpInfos);
EXPECT_EQ(1, termini.size());

Expand Down Expand Up @@ -198,7 +198,7 @@ TEST_F(TerminusManagerTest, negativeDiscoverMctpTerminusTest)
EXPECT_EQ(rc, PLDM_SUCCESS);

pldm::MctpInfos mctpInfos{};
mctpInfos.emplace_back(pldm::MctpInfo(12, "", "", 1));
mctpInfos.emplace_back(pldm::MctpInfo(12, "", "", 1, ""));
mockTerminusManager.discoverMctpTerminus(mctpInfos);
EXPECT_EQ(0, termini.size());

Expand Down
71 changes: 65 additions & 6 deletions requester/mctp_endpoint_discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ constexpr auto PROPERTY_INTERFACE = "org.freedesktop.DBus.Properties";

constexpr auto MCTP_INTERFACE = "xyz.openbmc_project.MCTP.Endpoint";
constexpr auto MCTP_OBJECT_PATH = "/xyz/openbmc_project/mctp";
constexpr auto ASSOCIATION_INTERFACE =
"xyz.openbmc_project.Association.Definitions";

MctpDiscovery::MctpDiscovery(
sdbusplus::bus::bus& bus,
Expand Down Expand Up @@ -74,6 +76,9 @@ void MctpDiscovery::getMctpInfos(MctpInfos& mctpInfos)
for (const auto& serviceIter : services)
{
const std::string& service = serviceIter.first;
MctpInfo mctpInfo;
using Property = std::string;
using PropertyMap = std::map<Property, dbus::Value>;

try
{
Expand All @@ -82,8 +87,6 @@ void MctpDiscovery::getMctpInfos(MctpInfos& mctpInfos)
method.append(MCTP_INTERFACE);

auto response = bus.call(method, dbusTimeout);
using Property = std::string;
using PropertyMap = std::map<Property, dbus::Value>;
PropertyMap properties;
response.read(properties);

Expand All @@ -102,7 +105,11 @@ void MctpDiscovery::getMctpInfos(MctpInfos& mctpInfos)
std::cerr << "Adding Endpoint networkId " << networkId
<< " EID " << unsigned(eid) << "\n";
mctpInfos.emplace_back(
MctpInfo(eid, emptyUUID, "", networkId));
MctpInfo(eid, emptyUUID, "", networkId, ""));
}
else
{
continue;
}
}
}
Expand All @@ -113,6 +120,39 @@ void MctpDiscovery::getMctpInfos(MctpInfos& mctpInfos)
<< " PATH: " << path << std::endl;
return;
}

const auto interfaces = serviceIter.second;
if (std::find(interfaces.begin(), interfaces.end(),
ASSOCIATION_INTERFACE) != interfaces.end())
{
try
{
auto method =
bus.new_method_call(service.c_str(), path.c_str(),
PROPERTY_INTERFACE, "GetAll");
method.append(ASSOCIATION_INTERFACE);

auto response = bus.call(method, dbusTimeout);
PropertyMap properties;
response.read(properties);

if (properties.contains("Associations"))
{
auto associations = std::get<std::vector<Association>>(
properties.at("Associations"));
std::get<4>(mctpInfos.back()) =
std::get<2>(associations.front());
}
}
catch (const sdbusplus::exception_t& e)
{
std::cerr
<< "Error reading MCTP Endpoint association, error: "
<< e.what() << " SERVICE: " << service
<< " PATH: " << path << std::endl;
return;
}
}
}
}
}
Expand All @@ -138,6 +178,7 @@ void MctpDiscovery::getAddedMctpInfos(sdbusplus::message_t& msg,
return;
}

MctpInfo mctpInfo;
for (const auto& [intfName, properties] : interfaces)
{
if (intfName == MCTP_INTERFACE)
Expand All @@ -156,11 +197,28 @@ void MctpDiscovery::getAddedMctpInfos(sdbusplus::message_t& msg,
{
std::cerr << "Adding Endpoint networkId " << networkId
<< " EID " << unsigned(eid) << "\n";
mctpInfos.emplace_back(
MctpInfo(eid, emptyUUID, "", networkId));
std::get<0>(mctpInfo) = eid;
std::get<1>(mctpInfo) = emptyUUID;
std::get<2>(mctpInfo) = "";
std::get<3>(mctpInfo) = networkId;
}
}
}

if (intfName == ASSOCIATION_INTERFACE)
{
if (properties.contains("Associations"))
{
auto associations = std::get<std::vector<Association>>(
properties.at("Associations"));
std::get<4>(mctpInfo) = std::get<2>(associations.front());
}
}
}
// Make sure we got the eid
if (std::get<0>(mctpInfo))
{
mctpInfos.emplace_back(mctpInfo);
}
}

Expand Down Expand Up @@ -238,9 +296,10 @@ void MctpDiscovery::loadStaticEndpoints(MctpInfos& mctpInfos)
auto networkId = endpoint.value("NetworkId", 0xFF);
auto eid = endpoint.value("EID", 0xFF);
auto types = endpoint.value("SupportedMessageTypes", emptyUnit8Array);
auto inventoryPath = endpoint.value("InventoryPath", "");
if (std::find(types.begin(), types.end(), mctpTypePLDM) != types.end())
{
MctpInfo mctpInfo(eid, emptyUUID, "", networkId);
MctpInfo mctpInfo(eid, emptyUUID, "", networkId, inventoryPath);
if (std::find(mctpInfos.begin(), mctpInfos.end(), mctpInfo) ==
mctpInfos.end())
{
Expand Down

0 comments on commit e3f13c9

Please sign in to comment.