Add support for vlan(set lan command)

Resolves openbmc/openbmc#1899

Change-Id: I3c436045676bc96e5d91fd9420509bc991549a13
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
diff --git a/utils.cpp b/utils.cpp
index 11dc2d4..2e6c5e7 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -339,6 +339,32 @@
 
 }
 
+void createVLAN(sdbusplus::bus::bus& bus,
+                const std::string& service,
+                const std::string& objPath,
+                const std::string& interfaceName,
+                uint32_t vlanID)
+{
+    auto busMethod = bus.new_method_call(
+                         service.c_str(),
+                         objPath.c_str(),
+                         VLAN_CREATE_INTERFACE,
+                         "VLAN");
+
+    busMethod.append(interfaceName, vlanID);
+
+    auto reply = bus.call(busMethod);
+
+    if (reply.is_method_error())
+    {
+        log<level::ERR>("Failed to excute method",
+                        entry("METHOD=%s", "VLAN"),
+                        entry("PATH=%s", objPath.c_str()));
+        elog<InternalFailure>();
+    }
+
+}
+
 uint8_t toPrefix(int addressFamily, const std::string& subnetMask)
 {
     if (addressFamily == AF_INET6)
@@ -370,7 +396,34 @@
     }
 }
 
+uint32_t getVLAN(const std::string& path)
+{
+    // Path would be look like
+    // /xyz/openbmc_project/network/eth0_443/ipv4
+
+    uint32_t vlanID = 0;
+    try
+    {
+        auto intfObjectPath = path.substr(0,
+                path.find(IP_TYPE) - 1);
+
+        auto intfName = intfObjectPath.substr(intfObjectPath.rfind("/") + 1);
+
+        auto index = intfName.find("_");
+        if (index != std::string::npos)
+        {
+            auto str = intfName.substr(index + 1);
+            vlanID = std::stoul(str);
+        }
+    }
+    catch (std::exception & e)
+    {
+        log<level::ERR>("Exception occured during getVLAN",
+                        entry("PATH=%s",path.c_str()),
+                        entry("EXCEPTIOn=%s", e.what()));
+    }
+    return vlanID;
+}
+
 } // namespace network
 } // namespace ipmi
-
-