Create the system conf Dbus Object

Also put extra checks while writing the gateway
and the destination to the conf file.

Change-Id: I8f24b3f293e6f978b655f061a198a32690dd44f3
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
diff --git a/network_manager.cpp b/network_manager.cpp
index a635952..aff86a0 100644
--- a/network_manager.cpp
+++ b/network_manager.cpp
@@ -8,7 +8,6 @@
 
 #include <algorithm>
 #include <bitset>
-#include <experimental/filesystem>
 #include <map>
 #include <fstream>
 
@@ -24,17 +23,25 @@
 {
 
 using namespace phosphor::logging;
-namespace fs = std::experimental::filesystem;
+using namespace sdbusplus::xyz::openbmc_project::Common::Error;
 
 Manager::Manager(sdbusplus::bus::bus& bus, const char* objPath):
     details::VLANCreateIface(bus, objPath, true),
     bus(bus),
     objectPath(objPath)
 {
+    confDir = NETWORK_CONF_DIR;
+}
+
+void Manager::setConfDir(const fs::path& dir)
+{
+    confDir = dir;
 }
 
 void Manager::createInterfaces()
 {
+    //clear all the interfaces first
+    interfaces.clear();
 
     auto interfaceInfoList = getInterfaceAddrs();
 
@@ -56,6 +63,18 @@
     }
 }
 
+void Manager::createChildObjects()
+{
+    // creates the ethernet interface dbus object.
+    createInterfaces();
+    // create the system conf object.
+    fs::path objPath = objectPath;
+    objPath /= "config";
+    systemConf = std::make_unique<phosphor::network::SystemConfiguration>(
+                        bus, objPath.string(), *this);
+
+}
+
 void Manager::vLAN(IntfName interfaceName, uint16_t id)
 {
 }
@@ -216,7 +235,7 @@
     for (const auto& intf : interfaces)
     {
 
-        fs::path confPath {NETWORK_CONF_DIR};
+        fs::path confPath = confDir;
         std::string fileName = "00-bmc-"s + intf.first + ".network"s;
         confPath /= fileName;
         std::fstream stream;
@@ -238,12 +257,16 @@
                                           addr.second->prefixLength());
 
                 stream << "Address=" << address << "\n";
-                stream << "Gateway=" << addr.second->gateway() << "\n";
+                if (addr.second->gateway() != "0.0.0.0" &&
+                    addr.second->gateway() != "")
+                {
+                    stream << "Gateway=" << addr.second->gateway() << "\n";
+                }
 
             }
         }
-
-        stream << "Gateway=" << this->defaultGateway << "\n";
+        stream << "Gateway=" << systemConf->defaultGateway() << "\n";
+        // write the route section
         stream << "[" << "Route" << "]\n";
         for(const auto& addr : addrs)
         {
@@ -255,8 +278,10 @@
                                             addr.second->address(),
                                             addr.second->prefixLength());
 
-                if (addr.second->gateway() != "0.0.0.0" ||
-                    addr.second->gateway() != "")
+                if (addr.second->gateway() != "0.0.0.0" &&
+                    addr.second->gateway() != "" &&
+                    destination != "0.0.0.0" &&
+                    destination != "")
                 {
 
                     stream << "Gateway=" << addr.second->gateway() << "\n";