Load the VLAN interfaces from the system

At start up Network Manager creates all the interfaces
by reading it from the system.This commit creates the
vlan interface after reading it from the system.

Change-Id: I38e6f3b776f834e33d17e4e88f700b4f52af4048
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
diff --git a/ethernet_interface.cpp b/ethernet_interface.cpp
index 3b50d4e..30927f6 100644
--- a/ethernet_interface.cpp
+++ b/ethernet_interface.cpp
@@ -303,10 +303,35 @@
     {
         writeConfigurationFile();
         createIPAddressObjects();
+
     }
+
     return value;
 }
 
+void EthernetInterface::loadVLAN(VlanId id)
+{
+    std::string vlanInterfaceName = interfaceName() + "." +
+                                    std::to_string(id);
+    std::string path = objPath;
+    path += "_" + std::to_string(id);
+
+    auto vlanIntf = std::make_unique<phosphor::network::VlanInterface>(
+                        bus,
+                        path.c_str(),
+                        EthernetInterfaceIntf::dHCPEnabled(),
+                        id,
+                        *this,
+                        manager);
+
+   // Fetch the ip address from the system
+   // and create the dbus object.
+    vlanIntf->createIPAddressObjects();
+
+    this->vlanInterfaces.emplace(std::move(vlanInterfaceName),
+                                 std::move(vlanIntf));
+}
+
 void EthernetInterface::createVLAN(VlanId id)
 {
     std::string vlanInterfaceName = interfaceName() + "." +
diff --git a/ethernet_interface.hpp b/ethernet_interface.hpp
index 4617f56..36669d6 100644
--- a/ethernet_interface.hpp
+++ b/ethernet_interface.hpp
@@ -113,11 +113,16 @@
          */
         void createVLAN(VlanId id);
 
+        /** @brief load the vlan info from the system
+         *         and creates the ip address dbus objects.
+         *  @param[in] vlanID- VLAN identifier.
+         */
+        void loadVLAN(VlanId vlanID);
+
         /** @brief write the network conf file with the in-memory objects.
          */
         void writeConfigurationFile();
 
-
         using EthernetInterfaceIntf::dHCPEnabled;
         using EthernetInterfaceIntf::interfaceName;
 
diff --git a/network_manager.cpp b/network_manager.cpp
index cac4d93..6ae3bfb 100644
--- a/network_manager.cpp
+++ b/network_manager.cpp
@@ -64,18 +64,38 @@
     for (const auto& intfInfo : interfaceInfoList)
     {
         fs::path objPath = objectPath;
+        auto index = intfInfo.first.find(".");
+
+        // interface can be of vlan type or normal ethernet interface.
+        // vlan interface looks like "interface.vlanid",so here by looking
+        // at the interface name we decide that we need
+        // to create the vlaninterface or normal physical interface.
+        if (index != std::string::npos)
+        {
+            //it is vlan interface
+            auto interface = intfInfo.first.substr(0, index);
+            auto vlanid = intfInfo.first.substr(index + 1);
+            uint32_t vlanInt = std::stoul(vlanid);
+
+            interfaces[interface]->loadVLAN(vlanInt);
+            return;
+        }
+        // normal ethernet inetrface
         objPath /= intfInfo.first;
 
         auto dhcp = getDHCPValue(intfInfo.first);
 
+        auto intf =  std::make_shared<phosphor::network::EthernetInterface>(
+                         bus,
+                         objPath.string(),
+                         dhcp,
+                         *this);
+
+
+        intf->createIPAddressObjects();
+
         this->interfaces.emplace(std::make_pair(
-                                     intfInfo.first,
-                                     std::make_unique<
-                                     phosphor::network::EthernetInterface>
-                                     (bus,
-                                      objPath.string(),
-                                      dhcp,
-                                      *this)));
+                                     intfInfo.first, std::move(intf)));
 
     }