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 |
| 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 | |
| 97 | private: |
Ratan Gupta | 70c7e5b | 2017-07-12 11:41:55 +0530 | [diff] [blame] | 98 | |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 99 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 100 | sdbusplus::bus::bus& bus; |
| 101 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 102 | /** @brief Persistent map of EthernetInterface dbus objects and their names */ |
Ratan Gupta | 2b10653 | 2017-07-25 16:05:02 +0530 | [diff] [blame] | 103 | std::map<IntfName, std::shared_ptr<EthernetInterface>> interfaces; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 104 | |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 105 | /** @brief BMC network reset - resets network configuration for BMC. */ |
| 106 | void reset() override; |
| 107 | |
Ratan Gupta | 34f96d6 | 2017-06-15 09:16:22 +0530 | [diff] [blame] | 108 | /** @brief read the DHCP value from the configuration file |
| 109 | * @param[in] intf - Interface name. |
| 110 | */ |
| 111 | bool getDHCPValue(const std::string& intf); |
| 112 | |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 113 | /** @brief Path of Object. */ |
| 114 | std::string objectPath; |
| 115 | |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 116 | /** @brief pointer to system conf object. */ |
Ratan Gupta | 2b10653 | 2017-07-25 16:05:02 +0530 | [diff] [blame] | 117 | SystemConfPtr systemConf = nullptr; |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 118 | |
Ratan Gupta | d16f88c | 2017-07-11 17:47:57 +0530 | [diff] [blame] | 119 | /** @brief pointer to dhcp conf object. */ |
Ratan Gupta | 2b10653 | 2017-07-25 16:05:02 +0530 | [diff] [blame] | 120 | DHCPConfPtr dhcpConf = nullptr; |
Ratan Gupta | d16f88c | 2017-07-11 17:47:57 +0530 | [diff] [blame] | 121 | |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 122 | /** @brief Network Configuration directory. */ |
| 123 | fs::path confDir; |
| 124 | |
Ratan Gupta | 8ab1792 | 2017-05-25 13:07:05 +0530 | [diff] [blame] | 125 | friend class TestNetworkManager; |
| 126 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | } // namespace network |
| 130 | } // namespace phosphor |