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/<id>".

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 <tejaspp@ami.com>
Change-Id: I8f55b3b5016503baecb7b85784d1a8bece69a258
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index ee8d2cd..0561c67 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -85,6 +85,7 @@
 struct EthernetInterfaceData
 {
     uint32_t speed;
+    size_t mtuSize;
     bool auto_neg;
     bool DNSEnabled;
     bool NTPEnabled;
@@ -256,6 +257,15 @@
                                 ethData.speed = *speed;
                             }
                         }
+                        else if (propertyPair.first == "MTU")
+                        {
+                            const uint32_t* mtuSize =
+                                std::get_if<uint32_t>(&propertyPair.second);
+                            if (mtuSize != nullptr)
+                            {
+                                ethData.mtuSize = *mtuSize;
+                            }
+                        }
                         else if (propertyPair.first == "LinkUp")
                         {
                             const bool* linkUp =
@@ -1050,6 +1060,25 @@
 }
 
 inline void
+    handleMTUSizePatch(const std::string& ifaceId, const size_t mtuSize,
+                       const std::shared_ptr<bmcweb::AsyncResp>& 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<size_t>(mtuSize));
+}
+
+inline void
     handleDomainnamePatch(const std::string& ifaceId,
                           const std::string& domainname,
                           const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
@@ -1712,6 +1741,7 @@
 
     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 @@
                 std::optional<nlohmann::json> dhcpv4;
                 std::optional<nlohmann::json> dhcpv6;
                 std::optional<bool> interfaceEnabled;
+                std::optional<size_t> mtuSize;
                 DHCPParameters v4dhcpParms;
                 DHCPParameters v6dhcpParms;
 
@@ -1944,7 +1975,8 @@
                         staticNameServers, "IPv6DefaultGateway",
                         ipv6DefaultGateway, "IPv6StaticAddresses",
                         ipv6StaticAddresses, "DHCPv4", dhcpv4, "DHCPv6", dhcpv6,
-                        "InterfaceEnabled", interfaceEnabled))
+                        "MTUSize", mtuSize, "InterfaceEnabled",
+                        interfaceEnabled))
                 {
                     return;
                 }
@@ -1985,7 +2017,7 @@
                      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 @@
                                 ifaceId, "NICEnabled", *interfaceEnabled,
                                 asyncResp);
                         }
+
+                        if (mtuSize)
+                        {
+                            handleMTUSizePatch(ifaceId, *mtuSize, asyncResp);
+                        }
                     });
             });