Restart the network through networkManager

Extend the refresh timer once we get the Dbus request which
requires network restart.

Detaching the network restart from the writeConfiguration func.
Write the configuration file for the vlan interface in
writeConfiguration func.

During creation of vlan,vlan interface should come up with
dhcp as false.

Change-Id: Iadc7b44554aca412d211d13e9569cc601ad04074
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
diff --git a/network_manager.cpp b/network_manager.cpp
index ae0cbaf..4525e34 100644
--- a/network_manager.cpp
+++ b/network_manager.cpp
@@ -3,6 +3,7 @@
 #include "network_manager.hpp"
 #include "network_config.hpp"
 #include "ipaddress.hpp"
+#include "timer.hpp"
 #include "xyz/openbmc_project/Common/error.hpp"
 
 #include <phosphor-logging/log.hpp>
@@ -24,6 +25,7 @@
 namespace network
 {
 
+extern std::unique_ptr<phosphor::network::Timer> refreshTimer;
 using namespace phosphor::logging;
 using namespace sdbusplus::xyz::openbmc_project::Common::Error;
 
@@ -104,9 +106,14 @@
 {
     // creates the ethernet interface dbus object.
     createInterfaces();
-    // create the system conf object.
+
+    systemConf.reset(nullptr);
+    dhcpConf.reset(nullptr);
+
     fs::path objPath = objectPath;
     objPath /= "config";
+
+    // create the system conf object.
     systemConf = std::make_unique<phosphor::network::SystemConfiguration>(
                         bus, objPath.string(), *this);
     // create the dhcp conf object.
@@ -170,12 +177,25 @@
 void Manager::writeToConfigurationFile()
 {
     // write all the static ip address in the systemd-network conf file
-
     for (const auto& intf : interfaces)
     {
         intf.second->writeConfigurationFile();
 
     }
+    restartNetwork();
+}
+
+void Manager::restartNetwork()
+{
+    using namespace std::chrono;
+
+    if (refreshTimer && !refreshTimer->isExpired())
+    {
+        auto time =  duration_cast<microseconds>(
+                        phosphor::network::networkChangeTimeout);
+        refreshTimer->startTimer(time);
+    }
+    restartSystemdUnit("systemd-networkd.service");
 }
 
 }//namespace network