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