From 35fb5311303730c90395d1a7fb34bc710dfa5421 Mon Sep 17 00:00:00 2001 From: Tejas Patil Date: Mon, 20 Sep 2021 15:35:20 +0530 Subject: EthernetInterfaces:GET & PATCH support for MTUSize This commit add support for MTUSize property with GET and PATCH methods under Redfish URI "/redfish/v1/Managers/bmc/EthernetInterfaces/". This property shows the maximum size of the Protocol Data Uint (PDU) in bytes, that can be passed in an Ethernet frame on the network interface. User can GET and SET the MTU Size of any available network interface. The backend implementation for this is committed to below link https://gerrit.openbmc-project.xyz/c/openbmc/phosphor-networkd/+/455591 Testing: - Redfish Validator Test Passed. - curl -k -H "X-Auth-Token: $token" -X PATCH -d '{"MTUSize" : 1280}' https://${bmc}/redfish/v1/Managers/bmc/EthernetInterfaces/eth3 - curl -k -H "X-Auth-Token: $token" -X GET https://${bmc}/redfish/v1/Managers/bmc/EthernetInterfaces/eth3 { "@odata.id": "/redfish/v1/Managers/bmc/EthernetInterfaces/eth3", "@odata.type": "#EthernetInterface.v1_4_1.EthernetInterface", "DHCPv4": { "DHCPEnabled": true, "UseDNSServers": true, "UseDomainName": true, "UseNTPServers": true }, "DHCPv6": { "OperatingMode": "Stateful", "UseDNSServers": true, "UseDomainName": true, "UseNTPServers": true }, "Description": "Management Network Interface", "FQDN": "evb-ast2600", "HostName": "evb-ast2600", "IPv4Addresses": [ { "Address": "10.0.126.64", "AddressOrigin": "DHCP", "Gateway": "10.0.120.1", "SubnetMask": "255.255.248.0" } ], "IPv4StaticAddresses": [], "IPv6AddressPolicyTable": [], "IPv6Addresses": [ { "Address": "4001:df24:df25:df26:a069:c2ff:fe62:1c52", "AddressOrigin": "DHCPv6", "AddressState": null, "PrefixLength": 64 }, { "Address": "fe80::a069:c2ff:fe62:1c52", "AddressOrigin": "LinkLocal", "AddressState": null, "PrefixLength": 64 }, { "Address": "1001:7:7:7:a069:c2ff:fe62:1c52", "AddressOrigin": "DHCPv6", "AddressState": null, "PrefixLength": 64 } ], "IPv6DefaultGateway": "0:0:0:0:0:0:0:0", "IPv6StaticAddresses": [], "Id": "eth3", "InterfaceEnabled": true, "LinkStatus": "LinkUp", "MACAddress": "a2:69:c2:62:1c:52", "MTUSize": 1280, "Name": "Manager Ethernet Interface", "NameServers": [ "10.0.0.31", "10.0.0.32" ], "SpeedMbps": 0, "StaticNameServers": [], "Status": { "Health": "OK", "HealthRollup": "OK", "State": "Enabled" }, "VLANs": { "@odata.id": "/redfish/v1/Managers/bmc/EthernetInterfaces/eth3/VLANs" } } Signed-off-by: Tejas Patil Change-Id: I8f55b3b5016503baecb7b85784d1a8bece69a258 --- redfish-core/lib/ethernet.hpp | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp index ee8d2cd5b5..0561c6758e 100644 --- a/redfish-core/lib/ethernet.hpp +++ b/redfish-core/lib/ethernet.hpp @@ -85,6 +85,7 @@ struct IPv6AddressData struct EthernetInterfaceData { uint32_t speed; + size_t mtuSize; bool auto_neg; bool DNSEnabled; bool NTPEnabled; @@ -256,6 +257,15 @@ inline bool ethData.speed = *speed; } } + else if (propertyPair.first == "MTU") + { + const uint32_t* mtuSize = + std::get_if(&propertyPair.second); + if (mtuSize != nullptr) + { + ethData.mtuSize = *mtuSize; + } + } else if (propertyPair.first == "LinkUp") { const bool* linkUp = @@ -1049,6 +1059,25 @@ inline void dbus::utility::DbusVariantType(hostname)); } +inline void + handleMTUSizePatch(const std::string& ifaceId, const size_t mtuSize, + const std::shared_ptr& asyncResp) +{ + sdbusplus::message::object_path objPath = + "/xyz/openbmc_project/network/" + ifaceId; + crow::connections::systemBus->async_method_call( + [asyncResp](const boost::system::error_code ec) { + if (ec) + { + messages::internalError(asyncResp->res); + } + }, + "xyz.openbmc_project.Network", objPath, + "org.freedesktop.DBus.Properties", "Set", + "xyz.openbmc_project.Network.EthernetInterface", "MTU", + std::variant(mtuSize)); +} + inline void handleDomainnamePatch(const std::string& ifaceId, const std::string& domainname, @@ -1712,6 +1741,7 @@ inline void parseInterfaceData( jsonResponse["LinkStatus"] = ethData.linkUp ? "LinkUp" : "LinkDown"; jsonResponse["SpeedMbps"] = ethData.speed; + jsonResponse["MTUSize"] = ethData.mtuSize; jsonResponse["MACAddress"] = ethData.mac_address; jsonResponse["DHCPv4"]["DHCPEnabled"] = translateDHCPEnabledToBool(ethData.DHCPEnabled, true); @@ -1934,6 +1964,7 @@ inline void requestEthernetInterfacesRoutes(App& app) std::optional dhcpv4; std::optional dhcpv6; std::optional interfaceEnabled; + std::optional mtuSize; DHCPParameters v4dhcpParms; DHCPParameters v6dhcpParms; @@ -1944,7 +1975,8 @@ inline void requestEthernetInterfacesRoutes(App& app) staticNameServers, "IPv6DefaultGateway", ipv6DefaultGateway, "IPv6StaticAddresses", ipv6StaticAddresses, "DHCPv4", dhcpv4, "DHCPv6", dhcpv6, - "InterfaceEnabled", interfaceEnabled)) + "MTUSize", mtuSize, "InterfaceEnabled", + interfaceEnabled)) { return; } @@ -1985,7 +2017,7 @@ inline void requestEthernetInterfacesRoutes(App& app) ipv6StaticAddresses = std::move(ipv6StaticAddresses), staticNameServers = std::move(staticNameServers), dhcpv4 = std::move(dhcpv4), dhcpv6 = std::move(dhcpv6), - v4dhcpParms = std::move(v4dhcpParms), + mtuSize = mtuSize, v4dhcpParms = std::move(v4dhcpParms), v6dhcpParms = std::move(v6dhcpParms), interfaceEnabled]( const bool& success, const EthernetInterfaceData& ethData, @@ -2064,6 +2096,11 @@ inline void requestEthernetInterfacesRoutes(App& app) ifaceId, "NICEnabled", *interfaceEnabled, asyncResp); } + + if (mtuSize) + { + handleMTUSizePatch(ifaceId, *mtuSize, asyncResp); + } }); }); -- cgit v1.2.3