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