diff options
author | Ed Tanous <edtanous@google.com> | 2023-02-28 21:45:28 +0300 |
---|---|---|
committer | Ed Tanous <edtanous@google.com> | 2023-05-17 02:46:05 +0300 |
commit | 77179532f2082be00b69d62b5ec5b52bf5860be2 (patch) | |
tree | 4d26feaa25cd567a299801ee29e2bf10426e5a05 /redfish-core/lib | |
parent | 6331965943ef5ed5bb1b7680d26b916e53161ef3 (diff) | |
download | bmcweb-77179532f2082be00b69d62b5ec5b52bf5860be2.tar.xz |
Remove flat_set from EthernetInterfaces
None of these are actually used as a set, we should avoid taking the
overhead of using these as a set.
Tested in next commit.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I7a7f2c9761a2adc70f6c6ab127facc9d801a2209
Diffstat (limited to 'redfish-core/lib')
-rw-r--r-- | redfish-core/lib/ethernet.hpp | 159 | ||||
-rw-r--r-- | redfish-core/lib/hypervisor_system.hpp | 34 |
2 files changed, 81 insertions, 112 deletions
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp index 93c475ee59..416d5dc5c1 100644 --- a/redfish-core/lib/ethernet.hpp +++ b/redfish-core/lib/ethernet.hpp @@ -27,13 +27,13 @@ #include <boost/algorithm/string/classification.hpp> #include <boost/algorithm/string/split.hpp> -#include <boost/container/flat_set.hpp> #include <boost/url/format.hpp> #include <array> #include <optional> #include <regex> #include <string_view> +#include <vector> namespace redfish { @@ -55,13 +55,8 @@ struct IPv4AddressData std::string gateway; std::string netmask; std::string origin; - LinkType linktype; - bool isActive; - - bool operator<(const IPv4AddressData& obj) const - { - return id < obj.id; - } + LinkType linktype{}; + bool isActive{}; }; /** @@ -72,12 +67,7 @@ struct IPv6AddressData std::string id; std::string address; std::string origin; - uint8_t prefixLength; - - bool operator<(const IPv6AddressData& obj) const - { - return id < obj.id; - } + uint8_t prefixLength = 0; }; /** * Structure for keeping basic single Ethernet Interface information @@ -425,10 +415,9 @@ inline bool extractEthernetInterfaceData( } // Helper function that extracts data for single ethernet ipv6 address -inline void - extractIPV6Data(const std::string& ethifaceId, - const dbus::utility::ManagedObjectType& dbusData, - boost::container::flat_set<IPv6AddressData>& ipv6Config) +inline void extractIPV6Data(const std::string& ethifaceId, + const dbus::utility::ManagedObjectType& dbusData, + std::vector<IPv6AddressData>& ipv6Config) { const std::string ipPathStart = "/xyz/openbmc_project/network/" + ethifaceId; @@ -466,11 +455,7 @@ inline void // Instance IPv6AddressData structure, and set as // appropriate - std::pair< - boost::container::flat_set<IPv6AddressData>::iterator, - bool> - it = ipv6Config.insert(IPv6AddressData{}); - IPv6AddressData& ipv6Address = *it.first; + IPv6AddressData& ipv6Address = ipv6Config.emplace_back(); ipv6Address.id = objpath.first.str.substr(ipPathStart.size()); for (const auto& property : interface.second) @@ -523,10 +508,9 @@ inline void } // Helper function that extracts data for single ethernet ipv4 address -inline void - extractIPData(const std::string& ethifaceId, - const dbus::utility::ManagedObjectType& dbusData, - boost::container::flat_set<IPv4AddressData>& ipv4Config) +inline void extractIPData(const std::string& ethifaceId, + const dbus::utility::ManagedObjectType& dbusData, + std::vector<IPv4AddressData>& ipv4Config) { const std::string ipPathStart = "/xyz/openbmc_project/network/" + ethifaceId; @@ -564,11 +548,7 @@ inline void // Instance IPv4AddressData structure, and set as // appropriate - std::pair< - boost::container::flat_set<IPv4AddressData>::iterator, - bool> - it = ipv4Config.insert(IPv4AddressData{}); - IPv4AddressData& ipv4Address = *it.first; + IPv4AddressData& ipv4Address = ipv4Config.emplace_back(); ipv4Address.id = objpath.first.str.substr(ipPathStart.size()); for (const auto& property : interface.second) @@ -804,8 +784,8 @@ void getEthernetIfaceData(const std::string& ethifaceId, const boost::system::error_code& errorCode, const dbus::utility::ManagedObjectType& resp) { EthernetInterfaceData ethData{}; - boost::container::flat_set<IPv4AddressData> ipv4Data; - boost::container::flat_set<IPv6AddressData> ipv6Data; + std::vector<IPv4AddressData> ipv4Data; + std::vector<IPv6AddressData> ipv6Data; if (errorCode) { @@ -855,7 +835,7 @@ void getEthernetIfaceList(CallbackFunc&& callback) const dbus::utility::ManagedObjectType& resp) { // Callback requires vector<string> to retrieve all available // ethernet interfaces - boost::container::flat_set<std::string> ifaceList; + std::vector<std::string> ifaceList; ifaceList.reserve(resp.size()); if (errorCode) { @@ -881,7 +861,7 @@ void getEthernetIfaceList(CallbackFunc&& callback) continue; } // and put it into output vector. - ifaceList.emplace(ifaceId); + ifaceList.emplace_back(ifaceId); } } } @@ -1220,30 +1200,28 @@ inline void handleDHCPPatch(const std::string& ifaceId, setDHCPv4Config("HostNameEnabled", nextUseDomain, asyncResp); } -inline boost::container::flat_set<IPv4AddressData>::const_iterator - getNextStaticIpEntry( - const boost::container::flat_set<IPv4AddressData>::const_iterator& head, - const boost::container::flat_set<IPv4AddressData>::const_iterator& end) +inline std::vector<IPv4AddressData>::const_iterator getNextStaticIpEntry( + const std::vector<IPv4AddressData>::const_iterator& head, + const std::vector<IPv4AddressData>::const_iterator& end) { return std::find_if(head, end, [](const IPv4AddressData& value) { return value.origin == "Static"; }); } -inline boost::container::flat_set<IPv6AddressData>::const_iterator - getNextStaticIpEntry( - const boost::container::flat_set<IPv6AddressData>::const_iterator& head, - const boost::container::flat_set<IPv6AddressData>::const_iterator& end) +inline std::vector<IPv6AddressData>::const_iterator getNextStaticIpEntry( + const std::vector<IPv6AddressData>::const_iterator& head, + const std::vector<IPv6AddressData>::const_iterator& end) { return std::find_if(head, end, [](const IPv6AddressData& value) { return value.origin == "Static"; }); } -inline void handleIPv4StaticPatch( - const std::string& ifaceId, nlohmann::json& input, - const boost::container::flat_set<IPv4AddressData>& ipv4Data, - const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) +inline void + handleIPv4StaticPatch(const std::string& ifaceId, nlohmann::json& input, + const std::vector<IPv4AddressData>& ipv4Data, + const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { if ((!input.is_array()) || input.empty()) { @@ -1259,7 +1237,7 @@ inline void handleIPv4StaticPatch( // match it to the first JSON element in the IPv4StaticAddresses array. // Match each subsequent JSON element to the next static IP programmed // into the NIC. - boost::container::flat_set<IPv4AddressData>::const_iterator nicIpEntry = + std::vector<IPv4AddressData>::const_iterator nicIpEntry = getNextStaticIpEntry(ipv4Data.cbegin(), ipv4Data.cend()); for (nlohmann::json& thisJson : input) @@ -1446,7 +1424,7 @@ inline void handleStaticNameServersPatch( inline void handleIPv6StaticAddressesPatch( const std::string& ifaceId, const nlohmann::json& input, - const boost::container::flat_set<IPv6AddressData>& ipv6Data, + const std::vector<IPv6AddressData>& ipv6Data, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { if (!input.is_array() || input.empty()) @@ -1458,7 +1436,7 @@ inline void handleIPv6StaticAddressesPatch( return; } size_t entryIdx = 1; - boost::container::flat_set<IPv6AddressData>::const_iterator nicIpEntry = + std::vector<IPv6AddressData>::const_iterator nicIpEntry = getNextStaticIpEntry(ipv6Data.cbegin(), ipv6Data.cend()); for (const nlohmann::json& thisJson : input) { @@ -1566,11 +1544,12 @@ inline void handleIPv6StaticAddressesPatch( } } -inline void parseInterfaceData( - const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - const std::string& ifaceId, const EthernetInterfaceData& ethData, - const boost::container::flat_set<IPv4AddressData>& ipv4Data, - const boost::container::flat_set<IPv6AddressData>& ipv6Data) +inline void + parseInterfaceData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const std::string& ifaceId, + const EthernetInterfaceData& ethData, + const std::vector<IPv4AddressData>& ipv4Data, + const std::vector<IPv6AddressData>& ipv6Data) { constexpr std::array<std::string_view, 1> inventoryForEthernet = { "xyz.openbmc_project.Inventory.Item.Ethernet"}; @@ -1732,9 +1711,8 @@ inline void requestEthernetInterfacesRoutes(App& app) // Get eth interface list, and call the below callback for JSON // preparation getEthernetIfaceList( - [asyncResp]( - const bool& success, - const boost::container::flat_set<std::string>& ifaceList) { + [asyncResp](const bool& success, + const std::vector<std::string>& ifaceList) { if (!success) { messages::internalError(asyncResp->res); @@ -1775,10 +1753,10 @@ inline void requestEthernetInterfacesRoutes(App& app) } getEthernetIfaceData( ifaceId, - [asyncResp, ifaceId]( - const bool& success, const EthernetInterfaceData& ethData, - const boost::container::flat_set<IPv4AddressData>& ipv4Data, - const boost::container::flat_set<IPv6AddressData>& ipv6Data) { + [asyncResp, ifaceId](const bool& success, + const EthernetInterfaceData& ethData, + const std::vector<IPv4AddressData>& ipv4Data, + const std::vector<IPv6AddressData>& ipv6Data) { if (!success) { // TODO(Pawel)consider distinguish between non @@ -1873,8 +1851,8 @@ inline void requestEthernetInterfacesRoutes(App& app) v4dhcpParms = std::move(v4dhcpParms), v6dhcpParms = std::move(v6dhcpParms), interfaceEnabled]( const bool& success, const EthernetInterfaceData& ethData, - const boost::container::flat_set<IPv4AddressData>& ipv4Data, - const boost::container::flat_set<IPv6AddressData>& ipv6Data) { + const std::vector<IPv4AddressData>& ipv4Data, + const std::vector<IPv6AddressData>& ipv6Data) { if (!success) { // ... otherwise return error @@ -1974,12 +1952,11 @@ inline void requestEthernetInterfacesRoutes(App& app) // Get single eth interface data, and call the below callback // for JSON preparation - getEthernetIfaceData( - ifaceId, - [asyncResp, parentIfaceId, - ifaceId](const bool& success, const EthernetInterfaceData& ethData, - const boost::container::flat_set<IPv4AddressData>&, - const boost::container::flat_set<IPv6AddressData>&) { + getEthernetIfaceData(ifaceId, [asyncResp, parentIfaceId, ifaceId]( + const bool& success, + const EthernetInterfaceData& ethData, + const std::vector<IPv4AddressData>&, + const std::vector<IPv6AddressData>&) { if (success && ethData.vlanId) { asyncResp->res.jsonValue["Id"] = ifaceId; @@ -1998,7 +1975,7 @@ inline void requestEthernetInterfacesRoutes(App& app) messages::resourceNotFound(asyncResp->res, "VLanNetworkInterface", ifaceId); } - }); + }); }); BMCWEB_ROUTE( @@ -2037,12 +2014,12 @@ inline void requestEthernetInterfacesRoutes(App& app) // Get single eth interface data, and call the below callback // for JSON preparation - getEthernetIfaceData( - ifaceId, - [asyncResp, parentIfaceId, ifaceId, vlanEnable]( - const bool& success, const EthernetInterfaceData& ethData, - const boost::container::flat_set<IPv4AddressData>&, - const boost::container::flat_set<IPv6AddressData>&) { + getEthernetIfaceData(ifaceId, + [asyncResp, parentIfaceId, ifaceId, + vlanEnable](const bool& success, + const EthernetInterfaceData& ethData, + const std::vector<IPv4AddressData>&, + const std::vector<IPv6AddressData>&) { if (success && ethData.vlanId) { if (vlanEnable) @@ -2071,7 +2048,7 @@ inline void requestEthernetInterfacesRoutes(App& app) "VLanNetworkInterface", ifaceId); return; } - }); + }); }); BMCWEB_ROUTE( @@ -2095,12 +2072,11 @@ inline void requestEthernetInterfacesRoutes(App& app) // Get single eth interface data, and call the below callback // for JSON preparation - getEthernetIfaceData( - ifaceId, - [asyncResp, parentIfaceId, - ifaceId](const bool& success, const EthernetInterfaceData& ethData, - const boost::container::flat_set<IPv4AddressData>&, - const boost::container::flat_set<IPv6AddressData>&) { + getEthernetIfaceData(ifaceId, [asyncResp, parentIfaceId, ifaceId]( + const bool& success, + const EthernetInterfaceData& ethData, + const std::vector<IPv4AddressData>&, + const std::vector<IPv6AddressData>&) { if (success && ethData.vlanId) { auto callback = @@ -2123,7 +2099,7 @@ inline void requestEthernetInterfacesRoutes(App& app) messages::resourceNotFound(asyncResp->res, "VLanNetworkInterface", ifaceId); } - }); + }); }); BMCWEB_ROUTE(app, @@ -2140,17 +2116,16 @@ inline void requestEthernetInterfacesRoutes(App& app) } // Get eth interface list, and call the below callback for JSON // preparation - getEthernetIfaceList( - [asyncResp, rootInterfaceName]( - const bool& success, - const boost::container::flat_set<std::string>& ifaceList) { + getEthernetIfaceList([asyncResp, rootInterfaceName]( + const bool& success, + const std::vector<std::string>& ifaceList) { if (!success) { messages::internalError(asyncResp->res); return; } - - if (ifaceList.find(rootInterfaceName) == ifaceList.end()) + if (std::find(ifaceList.begin(), ifaceList.end(), + rootInterfaceName) == ifaceList.end()) { messages::resourceNotFound(asyncResp->res, "VLanNetworkInterfaceCollection", diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp index c87b7ef09a..64bcbbadba 100644 --- a/redfish-core/lib/hypervisor_system.hpp +++ b/redfish-core/lib/hypervisor_system.hpp @@ -10,7 +10,6 @@ #include "utils/ip_utils.hpp" #include "utils/json_utils.hpp" -#include <boost/container/flat_set.hpp> #include <boost/url/format.hpp> #include <sdbusplus/asio/property.hpp> @@ -151,8 +150,7 @@ inline void inline bool extractHypervisorInterfaceData( const std::string& ethIfaceId, const dbus::utility::ManagedObjectType& dbusData, - EthernetInterfaceData& ethData, - boost::container::flat_set<IPv4AddressData>& ipv4Config) + EthernetInterfaceData& ethData, std::vector<IPv4AddressData>& ipv4Config) { bool idFound = false; for (const auto& objpath : dbusData) @@ -201,10 +199,7 @@ inline bool extractHypervisorInterfaceData( if (objpath.first == "/xyz/openbmc_project/network/hypervisor/" + ethIfaceId + "/ipv4/addr0") { - std::pair<boost::container::flat_set<IPv4AddressData>::iterator, - bool> - it = ipv4Config.insert(IPv4AddressData{}); - IPv4AddressData& ipv4Address = *it.first; + IPv4AddressData& ipv4Address = ipv4Config.emplace_back(); if (ifacePair.first == "xyz.openbmc_project.Object.Enable") { for (const auto& property : ifacePair.second) @@ -321,7 +316,7 @@ void getHypervisorIfaceData(const std::string& ethIfaceId, const boost::system::error_code& error, const dbus::utility::ManagedObjectType& resp) { EthernetInterfaceData ethData{}; - boost::container::flat_set<IPv4AddressData> ipv4Data; + std::vector<IPv4AddressData> ipv4Data; if (error) { callback(false, ethData, ipv4Data); @@ -477,10 +472,10 @@ inline void setHypervisorIPv4Subnet(asyncResp, ifaceId, prefixLength); } -inline void parseInterfaceData( - nlohmann::json& jsonResponse, const std::string& ifaceId, - const EthernetInterfaceData& ethData, - const boost::container::flat_set<IPv4AddressData>& ipv4Data) +inline void parseInterfaceData(nlohmann::json& jsonResponse, + const std::string& ifaceId, + const EthernetInterfaceData& ethData, + const std::vector<IPv4AddressData>& ipv4Data) { jsonResponse["Id"] = ifaceId; jsonResponse["@odata.id"] = boost::urls::format( @@ -515,8 +510,7 @@ inline void parseInterfaceData( } } -inline void setDHCPEnabled(const std::string& ifaceId, - const bool& ipv4DHCPEnabled, +inline void setDHCPEnabled(const std::string& ifaceId, bool ipv4DHCPEnabled, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { const std::string dhcp = getDhcpEnabledEnumeration(ipv4DHCPEnabled, false); @@ -699,7 +693,7 @@ inline void handleHypervisorHostnamePatch( } inline void - setIPv4InterfaceEnabled(const std::string& ifaceId, const bool& isActive, + setIPv4InterfaceEnabled(const std::string& ifaceId, bool isActive, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { crow::connections::systemBus->async_method_call( @@ -779,8 +773,8 @@ inline void handleHypervisorEthernetInterfaceGet( } getHypervisorIfaceData( id, [asyncResp, ifaceId{std::string(id)}]( - const bool& success, const EthernetInterfaceData& ethData, - const boost::container::flat_set<IPv4AddressData>& ipv4Data) { + bool success, const EthernetInterfaceData& ethData, + const std::vector<IPv4AddressData>& ipv4Data) { if (!success) { messages::resourceNotFound(asyncResp->res, "EthernetInterface", @@ -876,9 +870,9 @@ inline void handleHypervisorEthernetInterfacePatch( ifaceId, [asyncResp, ifaceId, hostName = std::move(hostName), ipv4StaticAddresses = std::move(ipv4StaticAddresses), ipv4DHCPEnabled, - dhcpv4 = std::move(dhcpv4)]( - const bool& success, const EthernetInterfaceData& ethData, - const boost::container::flat_set<IPv4AddressData>&) { + dhcpv4 = std::move(dhcpv4)](bool success, + const EthernetInterfaceData& ethData, + const std::vector<IPv4AddressData>&) { if (!success) { messages::resourceNotFound(asyncResp->res, "EthernetInterface", |