diff options
author | Ratan Gupta <ratagupt@in.ibm.com> | 2017-09-16 07:12:11 +0530 |
---|---|---|
committer | Ratan Gupta <ratagupt@in.ibm.com> | 2017-10-03 10:04:46 +0530 |
commit | e05083ad3082e61388567c0c36c68dc08436188d (patch) | |
tree | fd4ea818178da8720fbdc563264cfbe20168675b | |
parent | fd4b0f018b7d34292766cf9d871c391fa96ce8aa (diff) | |
download | phosphor-networkd-e05083ad3082e61388567c0c36c68dc08436188d.tar.gz phosphor-networkd-e05083ad3082e61388567c0c36c68dc08436188d.zip |
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>
-rw-r--r-- | ethernet_interface.cpp | 27 | ||||
-rw-r--r-- | network_manager.cpp | 24 | ||||
-rw-r--r-- | network_manager.hpp | 3 | ||||
-rw-r--r-- | rtnetlink_server.cpp | 3 | ||||
-rw-r--r-- | test/Makefile.am | 1 | ||||
-rw-r--r-- | test/test_network_manager.cpp | 2 | ||||
-rw-r--r-- | timer.cpp | 1 | ||||
-rw-r--r-- | types.hpp | 5 |
8 files changed, 50 insertions, 16 deletions
diff --git a/ethernet_interface.cpp b/ethernet_interface.cpp index bcb8f6c..7c4e8bb 100644 --- a/ethernet_interface.cpp +++ b/ethernet_interface.cpp @@ -134,7 +134,7 @@ void EthernetInterface::iP(IP::Protocol protType, prefixLength, gateway)); - writeConfigurationFile(); + manager.writeToConfigurationFile(); } @@ -246,7 +246,7 @@ void EthernetInterface::deleteObject(const std::string& ipaddress) return; } this->addrs.erase(it); - writeConfigurationFile(); + manager.writeToConfigurationFile(); } void EthernetInterface::deleteVLANObject(const std::string& interface) @@ -282,9 +282,6 @@ void EthernetInterface::deleteVLANObject(const std::string& interface) } // delete the interface vlanInterfaces.erase(it); - // restart the systemd-networkd - - restartSystemdUnit("systemd-networkd.service"); // TODO systemd doesn't delete the virtual network interface // even after deleting all the related configuartion. @@ -297,6 +294,8 @@ void EthernetInterface::deleteVLANObject(const std::string& interface) { commit<InternalFailure>(); } + + manager.writeToConfigurationFile(); } std::string EthernetInterface::generateObjectPath(IP::Protocol addressType, @@ -323,7 +322,7 @@ bool EthernetInterface::dHCPEnabled(bool value) } EthernetInterfaceIntf::dHCPEnabled(value); - writeConfigurationFile(); + manager.writeToConfigurationFile(); return value; } @@ -364,19 +363,18 @@ void EthernetInterface::createVLAN(VlanId id) auto vlanIntf = std::make_unique<phosphor::network::VlanInterface>( bus, path.c_str(), - EthernetInterfaceIntf::dHCPEnabled(), + false, id, *this, manager); // write the device file for the vlan interface. vlanIntf->writeDeviceFile(); - vlanIntf->writeConfigurationFile(); this->vlanInterfaces.emplace(vlanInterfaceName, std::move(vlanIntf)); // write the new vlan device entry to the configuration(network) file. - writeConfigurationFile(); + manager.writeToConfigurationFile(); } // Need to merge the below function with the code which writes the @@ -391,6 +389,15 @@ void EthernetInterface::writeConfigurationFile() using AddressOrigin = sdbusplus::xyz::openbmc_project::Network::server::IP::AddressOrigin; namespace fs = std::experimental::filesystem; + + // if there is vlan interafce then write the configuration file + // for vlan also. + + for (const auto& intf: vlanInterfaces) + { + intf.second->writeConfigurationFile(); + } + fs::path confPath = manager.getConfDir(); std::string fileName = systemd::config::networkFilePrefix + interfaceName() + @@ -429,7 +436,6 @@ void EthernetInterface::writeConfigurationFile() // configured as dhcp. writeDHCPSection(stream); stream.close(); - restartSystemdUnit("systemd-networkd.service"); return; } @@ -475,7 +481,6 @@ void EthernetInterface::writeConfigurationFile() } stream.close(); - restartSystemdUnit("systemd-networkd.service"); } void EthernetInterface::writeDHCPSection(std::fstream& stream) 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 phosphor 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 @@ void Manager::createChildObjects() { // 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::reset() 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 diff --git a/network_manager.hpp b/network_manager.hpp index 1890565..0d15fc6 100644 --- a/network_manager.hpp +++ b/network_manager.hpp @@ -96,6 +96,9 @@ class Manager : public details::VLANCreateIface private: + /** @brief restart the systemd networkd. */ + void restartNetwork(); + /** @brief Persistent sdbusplus DBus bus connection. */ sdbusplus::bus::bus& bus; diff --git a/rtnetlink_server.cpp b/rtnetlink_server.cpp index 8e636a1..91e9947 100644 --- a/rtnetlink_server.cpp +++ b/rtnetlink_server.cpp @@ -26,9 +26,6 @@ extern std::unique_ptr<phosphor::network::Timer> refreshTimer; namespace rtnetlink { -using namespace std::chrono_literals; -constexpr auto networkChangeTimeout = 1s; //seconds - /* Call Back for the sd event loop */ static int eventHandler(sd_event_source* es, int fd, uint32_t revents, void* userdata) diff --git a/test/Makefile.am b/test/Makefile.am index f1d11d4..024fa25 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -33,6 +33,7 @@ test_LDADD = $(top_builddir)/ethernet_interface.o \ $(top_builddir)/ipaddress.o \ $(top_builddir)/routing_table.o \ $(top_builddir)/util.o \ + $(top_builddir)/timer.o \ $(top_builddir)/system_configuration.o \ $(top_builddir)/dhcp_configuration.o \ $(top_builddir)/config_parser.o \ diff --git a/test/test_network_manager.cpp b/test/test_network_manager.cpp index 3e1f0e3..6281081 100644 --- a/test/test_network_manager.cpp +++ b/test/test_network_manager.cpp @@ -3,6 +3,7 @@ #include "xyz/openbmc_project/Common/error.hpp" #include <phosphor-logging/elog-errors.hpp> +#include "timer.hpp" #include <gtest/gtest.h> #include <sdbusplus/bus.hpp> @@ -20,6 +21,7 @@ namespace phosphor namespace network { +std::unique_ptr<phosphor::network::Timer> refreshTimer = nullptr; namespace fs = std::experimental::filesystem; class TestNetworkManager : public testing::Test @@ -73,6 +73,7 @@ int Timer::timeoutHandler(sd_event_source* eventSource, } log<level::INFO>("Timer expired"); + sd_event_source_set_enabled(eventSource, SD_EVENT_OFF); return 0; } @@ -8,12 +8,17 @@ #include <map> #include <memory> #include <set> +#include <chrono> #include <systemd/sd-event.h> namespace phosphor { namespace network { + +using namespace std::chrono_literals; +constexpr auto networkChangeTimeout = 1s; + namespace systemd { namespace config |