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 | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 5 | #include "types.hpp" |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 6 | #include "xyz/openbmc_project/Network/VLAN/Create/server.hpp" |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 7 | #include <xyz/openbmc_project/Common/FactoryReset/server.hpp> |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 8 | |
| 9 | #include <sdbusplus/bus.hpp> |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 10 | #include <ifaddrs.h> |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 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 | |
| 34 | using IntfName = std::string; |
| 35 | |
Ratan Gupta | 738a67f | 2017-04-21 10:38:05 +0530 | [diff] [blame] | 36 | struct AddrInfo |
| 37 | { |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 38 | short addrType; |
| 39 | std::string ipaddress; |
| 40 | }; |
| 41 | |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 42 | using Addr_t = ifaddrs*; |
| 43 | |
| 44 | struct AddrDeleter |
| 45 | { |
| 46 | void operator()(Addr_t ptr) const |
| 47 | { |
| 48 | freeifaddrs(ptr); |
| 49 | } |
| 50 | }; |
| 51 | |
| 52 | using AddrPtr = std::unique_ptr<ifaddrs, AddrDeleter>; |
| 53 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 54 | using AddrList = std::list<AddrInfo>; |
| 55 | using IntfAddrMap = std::map<IntfName, AddrList>; |
| 56 | |
| 57 | } // namespace details |
| 58 | |
Ratan Gupta | 8ab1792 | 2017-05-25 13:07:05 +0530 | [diff] [blame] | 59 | class TestNetworkManager; //forward declaration |
| 60 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 61 | /** @class Manager |
| 62 | * @brief OpenBMC network manager implementation. |
| 63 | */ |
| 64 | class Manager : public details::VLANCreateIface |
| 65 | { |
| 66 | public: |
| 67 | Manager() = delete; |
| 68 | Manager(const Manager&) = delete; |
| 69 | Manager& operator=(const Manager&) = delete; |
| 70 | Manager(Manager&&) = delete; |
| 71 | Manager& operator=(Manager&&) = delete; |
| 72 | virtual ~Manager() = default; |
| 73 | |
| 74 | /** @brief Constructor to put object onto bus at a dbus path. |
| 75 | * @param[in] bus - Bus to attach to. |
| 76 | * @param[in] objPath - Path to attach at. |
| 77 | */ |
| 78 | Manager(sdbusplus::bus::bus& bus, const char* objPath); |
| 79 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 80 | void vLAN(IntfName interfaceName, uint16_t id) override; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 81 | |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 82 | /** @brief write the network conf file with the in-memory objects. |
| 83 | */ |
| 84 | void writeToConfigurationFile(); |
| 85 | |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 86 | /** @brief Fetch the interface and the ipaddress details |
| 87 | * from the system and create the ethernet interraces |
| 88 | * dbus object. |
| 89 | */ |
| 90 | void createInterfaces(); |
| 91 | |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 92 | /** @brief create child interface object and the system conf object. |
Ratan Gupta | fc2c724 | 2017-05-29 08:46:06 +0530 | [diff] [blame] | 93 | */ |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 94 | void createChildObjects(); |
| 95 | |
| 96 | /** @brief sets the network conf directory. |
| 97 | * @param[in] dirName - Absolute path of the directory. |
| 98 | */ |
| 99 | void setConfDir(const fs::path& dir); |
| 100 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 101 | private: |
| 102 | /** @brief Get all the interfaces from the system. |
| 103 | * @returns list of interface names. |
| 104 | */ |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 105 | IntfAddrMap getInterfaceAddrs() const; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 106 | |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 107 | /** @brief Restart the systemd networkd |
| 108 | */ |
| 109 | void restartSystemdNetworkd(); |
| 110 | |
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 | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 115 | std::map<IntfName, std::unique_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 | 34f96d6 | 2017-06-15 09:16:22 +0530 | [diff] [blame^] | 120 | /** @brief read the DHCP value from the configuration file |
| 121 | * @param[in] intf - Interface name. |
| 122 | */ |
| 123 | bool getDHCPValue(const std::string& intf); |
| 124 | |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 125 | /** @brief Path of Object. */ |
| 126 | std::string objectPath; |
| 127 | |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 128 | /** @brief pointer to system conf object. */ |
| 129 | std::unique_ptr<SystemConfiguration> systemConf = nullptr; |
| 130 | |
| 131 | /** @brief Network Configuration directory. */ |
| 132 | fs::path confDir; |
| 133 | |
Ratan Gupta | 8ab1792 | 2017-05-25 13:07:05 +0530 | [diff] [blame] | 134 | friend class TestNetworkManager; |
| 135 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | } // namespace network |
| 139 | } // namespace phosphor |