Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "ethernet_interface.hpp" |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 4 | #include "system_configuration.hpp" |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 5 | #include "xyz/openbmc_project/Network/VLAN/Create/server.hpp" |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 6 | #include <xyz/openbmc_project/Common/FactoryReset/server.hpp> |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 7 | |
| 8 | #include <sdbusplus/bus.hpp> |
| 9 | |
| 10 | #include <list> |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 11 | #include <memory> |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 12 | #include <string> |
| 13 | #include <vector> |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 14 | #include <experimental/filesystem> |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 15 | |
| 16 | namespace phosphor |
| 17 | { |
| 18 | namespace network |
| 19 | { |
| 20 | |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 21 | namespace fs = std::experimental::filesystem; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 22 | namespace details |
| 23 | { |
| 24 | |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 25 | template <typename T, typename U> |
| 26 | using ServerObject = typename sdbusplus::server::object::object<T, U>; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 27 | |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 28 | using VLANCreateIface = details::ServerObject< |
| 29 | sdbusplus::xyz::openbmc_project::Network::VLAN::server::Create, |
| 30 | sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 31 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 32 | } // namespace details |
| 33 | |
Ratan Gupta | 8ab1792 | 2017-05-25 13:07:05 +0530 | [diff] [blame] | 34 | class TestNetworkManager; //forward declaration |
| 35 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 36 | /** @class Manager |
| 37 | * @brief OpenBMC network manager implementation. |
| 38 | */ |
| 39 | class Manager : public details::VLANCreateIface |
| 40 | { |
| 41 | public: |
| 42 | Manager() = delete; |
| 43 | Manager(const Manager&) = delete; |
| 44 | Manager& operator=(const Manager&) = delete; |
| 45 | Manager(Manager&&) = delete; |
| 46 | Manager& operator=(Manager&&) = delete; |
| 47 | virtual ~Manager() = default; |
| 48 | |
| 49 | /** @brief Constructor to put object onto bus at a dbus path. |
| 50 | * @param[in] bus - Bus to attach to. |
| 51 | * @param[in] objPath - Path to attach at. |
| 52 | */ |
| 53 | Manager(sdbusplus::bus::bus& bus, const char* objPath); |
| 54 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 55 | void vLAN(IntfName interfaceName, uint16_t id) override; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 56 | |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 57 | /** @brief write the network conf file with the in-memory objects. |
| 58 | */ |
| 59 | void writeToConfigurationFile(); |
| 60 | |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 61 | /** @brief Fetch the interface and the ipaddress details |
| 62 | * from the system and create the ethernet interraces |
| 63 | * dbus object. |
| 64 | */ |
| 65 | void createInterfaces(); |
| 66 | |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 67 | /** @brief create child interface object and the system conf object. |
Ratan Gupta | fc2c724 | 2017-05-29 08:46:06 +0530 | [diff] [blame] | 68 | */ |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 69 | void createChildObjects(); |
| 70 | |
| 71 | /** @brief sets the network conf directory. |
| 72 | * @param[in] dirName - Absolute path of the directory. |
| 73 | */ |
| 74 | void setConfDir(const fs::path& dir); |
| 75 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 76 | private: |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 77 | |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 78 | /** @brief Restart the systemd networkd |
| 79 | */ |
| 80 | void restartSystemdNetworkd(); |
| 81 | |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 82 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 83 | sdbusplus::bus::bus& bus; |
| 84 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 85 | /** @brief Persistent map of EthernetInterface dbus objects and their names */ |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 86 | std::map<IntfName, std::unique_ptr<EthernetInterface>> interfaces; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 87 | |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 88 | /** @brief BMC network reset - resets network configuration for BMC. */ |
| 89 | void reset() override; |
| 90 | |
Ratan Gupta | 34f96d6 | 2017-06-15 09:16:22 +0530 | [diff] [blame] | 91 | /** @brief read the DHCP value from the configuration file |
| 92 | * @param[in] intf - Interface name. |
| 93 | */ |
| 94 | bool getDHCPValue(const std::string& intf); |
| 95 | |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 96 | /** @brief Path of Object. */ |
| 97 | std::string objectPath; |
| 98 | |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 99 | /** @brief pointer to system conf object. */ |
| 100 | std::unique_ptr<SystemConfiguration> systemConf = nullptr; |
| 101 | |
| 102 | /** @brief Network Configuration directory. */ |
| 103 | fs::path confDir; |
| 104 | |
Ratan Gupta | 8ab1792 | 2017-05-25 13:07:05 +0530 | [diff] [blame] | 105 | friend class TestNetworkManager; |
| 106 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | } // namespace network |
| 110 | } // namespace phosphor |