summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiaqing Zhao <jiaqing.zhao@intel.com>2022-04-14 13:58:06 +0300
committerEd Tanous <ed@tanous.net>2022-05-24 17:38:39 +0300
commit17e220249df3d8215261fb7f27878045aeded858 (patch)
treed4e4d7a0776bc0ca6b6631dd2711a15ca2bf8610
parent4ee8f0b7c758125b938ff7530f4ef460c3703b62 (diff)
downloadbmcweb-17e220249df3d8215261fb7f27878045aeded858.tar.xz
ethernet: Use std::optional<uint32> for VLAN ID
According to Redfish EthernetInterface and VLanNetworkInterface schema, VLANId is "The ID for this VLAN", meaning that each interface can only have at most one VLAN ID. (Though EthernetInterface schema says "If this interface supports more than one VLAN, the VLAN collection link shall be present", the collection link is depracated in 1.7.0 and the spec suggests "using individual EthernetInterface resources to show VLAN information".) OpenBMC network stack implementation uses linux's virtual interface to represent a VLAN (named as <interface-name>.<vlan-id>, e.g. eth0.100). In both design and implementation, an interface can have either zero or one VLAN ID. This patch replaces the std::vector for VLAN ID with std::optional to match the design. It has no impact on the Redfish response. Tested: Verified GET /redfish/v1/Managers/bmc/EthernetInterfaces/eth0 can list all VLANs on eth0, and GET, PATCH and DELETE /redfish/v1/Managers/bmc /EthernetInterfaces/eth0/VLANs/eth0_1 works. Change-Id: Iab05e859d76639b2e60546cd5549efd34effafb7 Signed-off-by: Jiaqing Zhao <jiaqing.zhao@intel.com>
-rw-r--r--redfish-core/lib/ethernet.hpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 734cab2d8e..d451904c50 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -91,7 +91,7 @@ struct EthernetInterfaceData
std::string defaultGateway;
std::string ipv6DefaultGateway;
std::string macAddress;
- std::vector<std::uint32_t> vlanId;
+ std::optional<uint32_t> vlanId;
std::vector<std::string> nameServers;
std::vector<std::string> staticNameServers;
std::vector<std::string> domainnames;
@@ -221,7 +221,7 @@ inline bool
std::get_if<uint32_t>(&propertyPair.second);
if (id != nullptr)
{
- ethData.vlanId.push_back(*id);
+ ethData.vlanId = *id;
}
}
}
@@ -1809,9 +1809,9 @@ inline void parseInterfaceData(nlohmann::json& jsonResponse,
parentIfaceId + "/VLANs/" + ifaceId;
jsonResponse["VLANEnable"] = true;
- if (!ethData.vlanId.empty())
+ if (ethData.vlanId)
{
- jsonResponse["VLANId"] = ethData.vlanId.back();
+ jsonResponse["VLANId"] = *ethData.vlanId;
}
}
@@ -2108,7 +2108,7 @@ inline void requestEthernetInterfacesRoutes(App& app)
const EthernetInterfaceData& ethData,
const boost::container::flat_set<IPv4AddressData>&,
const boost::container::flat_set<IPv6AddressData>&) {
- if (success && !ethData.vlanId.empty())
+ if (success && ethData.vlanId)
{
parseInterfaceData(asyncResp->res.jsonValue,
parentIfaceId, ifaceId, ethData);
@@ -2162,7 +2162,7 @@ inline void requestEthernetInterfacesRoutes(App& app)
const EthernetInterfaceData& ethData,
const boost::container::flat_set<IPv4AddressData>&,
const boost::container::flat_set<IPv6AddressData>&) {
- if (success && !ethData.vlanId.empty())
+ if (success && ethData.vlanId)
{
auto callback =
[asyncResp](
@@ -2238,7 +2238,7 @@ inline void requestEthernetInterfacesRoutes(App& app)
const EthernetInterfaceData& ethData,
const boost::container::flat_set<IPv4AddressData>&,
const boost::container::flat_set<IPv6AddressData>&) {
- if (success && !ethData.vlanId.empty())
+ if (success && ethData.vlanId)
{
auto callback =
[asyncResp](