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 | d16f88c | 2017-07-11 17:47:57 +0530 | [diff] [blame] | 5 | #include "dhcp_configuration.hpp" |
Ratan Gupta | 5978dd1 | 2017-07-25 13:47:13 +0530 | [diff] [blame] | 6 | #include "vlan_interface.hpp" |
| 7 | |
Ratan Gupta | d16f88c | 2017-07-11 17:47:57 +0530 | [diff] [blame] | 8 | #include <xyz/openbmc_project/Network/VLAN/Create/server.hpp> |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 9 | #include <xyz/openbmc_project/Common/FactoryReset/server.hpp> |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 10 | #include <sdbusplus/bus.hpp> |
| 11 | |
| 12 | #include <list> |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 13 | #include <memory> |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 14 | #include <string> |
| 15 | #include <vector> |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 16 | #include <experimental/filesystem> |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 17 | |
| 18 | namespace phosphor |
| 19 | { |
| 20 | namespace network |
| 21 | { |
| 22 | |
Ratan Gupta | 2b10653 | 2017-07-25 16:05:02 +0530 | [diff] [blame] | 23 | using SystemConfPtr = std::unique_ptr<SystemConfiguration>; |
| 24 | using DHCPConfPtr = std::unique_ptr<dhcp::Configuration>; |
| 25 | |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 26 | namespace fs = std::experimental::filesystem; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 27 | namespace details |
| 28 | { |
| 29 | |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 30 | template <typename T, typename U> |
| 31 | using ServerObject = typename sdbusplus::server::object::object<T, U>; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 32 | |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 33 | using VLANCreateIface = details::ServerObject< |
| 34 | sdbusplus::xyz::openbmc_project::Network::VLAN::server::Create, |
| 35 | sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 36 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 37 | } // namespace details |
| 38 | |
Ratan Gupta | 8ab1792 | 2017-05-25 13:07:05 +0530 | [diff] [blame] | 39 | class TestNetworkManager; //forward declaration |
Nagaraju Goruganti | 067ca2d | 2018-01-17 01:12:00 -0600 | [diff] [blame] | 40 | class TestRtNetlink; //forward declaration |
Ratan Gupta | 8ab1792 | 2017-05-25 13:07:05 +0530 | [diff] [blame] | 41 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 42 | /** @class Manager |
| 43 | * @brief OpenBMC network manager implementation. |
| 44 | */ |
| 45 | class Manager : public details::VLANCreateIface |
| 46 | { |
| 47 | public: |
| 48 | Manager() = delete; |
| 49 | Manager(const Manager&) = delete; |
| 50 | Manager& operator=(const Manager&) = delete; |
| 51 | Manager(Manager&&) = delete; |
| 52 | Manager& operator=(Manager&&) = delete; |
| 53 | virtual ~Manager() = default; |
| 54 | |
| 55 | /** @brief Constructor to put object onto bus at a dbus path. |
| 56 | * @param[in] bus - Bus to attach to. |
| 57 | * @param[in] objPath - Path to attach at. |
Ratan Gupta | 255d514 | 2017-08-10 09:02:08 +0530 | [diff] [blame] | 58 | * @param[in] dir - Network Configuration directory path. |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 59 | */ |
Ratan Gupta | 255d514 | 2017-08-10 09:02:08 +0530 | [diff] [blame] | 60 | Manager(sdbusplus::bus::bus& bus, const char* objPath, |
| 61 | const std::string& dir); |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 62 | |
Ratan Gupta | 584df83 | 2017-07-31 16:21:54 +0530 | [diff] [blame] | 63 | void vLAN(IntfName interfaceName, uint32_t id) override; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 64 | |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 65 | /** @brief write the network conf file with the in-memory objects. |
| 66 | */ |
| 67 | void writeToConfigurationFile(); |
| 68 | |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 69 | /** @brief Fetch the interface and the ipaddress details |
| 70 | * from the system and create the ethernet interraces |
| 71 | * dbus object. |
| 72 | */ |
| 73 | void createInterfaces(); |
| 74 | |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 75 | /** @brief create child interface object and the system conf object. |
Ratan Gupta | fc2c724 | 2017-05-29 08:46:06 +0530 | [diff] [blame] | 76 | */ |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 77 | void createChildObjects(); |
| 78 | |
| 79 | /** @brief sets the network conf directory. |
| 80 | * @param[in] dirName - Absolute path of the directory. |
| 81 | */ |
| 82 | void setConfDir(const fs::path& dir); |
| 83 | |
Ratan Gupta | 255d514 | 2017-08-10 09:02:08 +0530 | [diff] [blame] | 84 | /** @brief gets the network conf directory. |
| 85 | */ |
| 86 | fs::path getConfDir() { return confDir; } |
| 87 | |
Ratan Gupta | 2b10653 | 2017-07-25 16:05:02 +0530 | [diff] [blame] | 88 | /** @brief gets the system conf object. |
| 89 | * |
| 90 | */ |
| 91 | const SystemConfPtr& getSystemConf() { return systemConf; } |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 92 | |
Ratan Gupta | 2b10653 | 2017-07-25 16:05:02 +0530 | [diff] [blame] | 93 | /** @brief gets the dhcp conf object. |
| 94 | * |
| 95 | */ |
| 96 | const DHCPConfPtr& getDHCPConf() { return dhcpConf; } |
| 97 | |
Ratan Gupta | b610caf | 2017-09-19 09:33:51 +0530 | [diff] [blame] | 98 | /** @brief create the default network files for each interface |
| 99 | * @detail if force param is true then forcefully create the network |
| 100 | * files otherwise if network file doesn't exist then |
| 101 | * create it. |
| 102 | * @param[in] force - forcefully create the file |
| 103 | * @return true if network file created else false |
| 104 | */ |
| 105 | bool createDefaultNetworkFiles(bool force); |
Ratan Gupta | 70c7e5b | 2017-07-12 11:41:55 +0530 | [diff] [blame] | 106 | |
Ratan Gupta | 16f1288 | 2017-09-22 18:26:11 +0530 | [diff] [blame] | 107 | /** @brief restart the network timers. */ |
| 108 | void restartTimers(); |
Ratan Gupta | e05083a | 2017-09-16 07:12:11 +0530 | [diff] [blame] | 109 | |
Ratan Gupta | b610caf | 2017-09-19 09:33:51 +0530 | [diff] [blame] | 110 | private: |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 111 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 112 | sdbusplus::bus::bus& bus; |
| 113 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 114 | /** @brief Persistent map of EthernetInterface dbus objects and their names */ |
Ratan Gupta | 2b10653 | 2017-07-25 16:05:02 +0530 | [diff] [blame] | 115 | std::map<IntfName, std::shared_ptr<EthernetInterface>> interfaces; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 116 | |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 117 | /** @brief BMC network reset - resets network configuration for BMC. */ |
| 118 | void reset() override; |
| 119 | |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 120 | /** @brief Path of Object. */ |
| 121 | std::string objectPath; |
| 122 | |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 123 | /** @brief pointer to system conf object. */ |
Ratan Gupta | 2b10653 | 2017-07-25 16:05:02 +0530 | [diff] [blame] | 124 | SystemConfPtr systemConf = nullptr; |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 125 | |
Ratan Gupta | d16f88c | 2017-07-11 17:47:57 +0530 | [diff] [blame] | 126 | /** @brief pointer to dhcp conf object. */ |
Ratan Gupta | 2b10653 | 2017-07-25 16:05:02 +0530 | [diff] [blame] | 127 | DHCPConfPtr dhcpConf = nullptr; |
Ratan Gupta | d16f88c | 2017-07-11 17:47:57 +0530 | [diff] [blame] | 128 | |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 129 | /** @brief Network Configuration directory. */ |
| 130 | fs::path confDir; |
| 131 | |
Ratan Gupta | 8ab1792 | 2017-05-25 13:07:05 +0530 | [diff] [blame] | 132 | friend class TestNetworkManager; |
Nagaraju Goruganti | 067ca2d | 2018-01-17 01:12:00 -0600 | [diff] [blame] | 133 | friend class TestRtNetlink; |
Ratan Gupta | 8ab1792 | 2017-05-25 13:07:05 +0530 | [diff] [blame] | 134 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | } // namespace network |
| 138 | } // namespace phosphor |