Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "ethernet_interface.hpp" |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 4 | #include "types.hpp" |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 5 | #include "xyz/openbmc_project/Network/VLAN/Create/server.hpp" |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 6 | #include <xyz/openbmc_project/Common/FactoryReset/server.hpp> |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 7 | |
| 8 | #include <sdbusplus/bus.hpp> |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 9 | #include <ifaddrs.h> |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 10 | |
| 11 | #include <list> |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 12 | #include <memory> |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 13 | #include <string> |
| 14 | #include <vector> |
| 15 | |
| 16 | namespace phosphor |
| 17 | { |
| 18 | namespace network |
| 19 | { |
| 20 | |
| 21 | namespace details |
| 22 | { |
| 23 | |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 24 | template <typename T, typename U> |
| 25 | using ServerObject = typename sdbusplus::server::object::object<T, U>; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 26 | |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 27 | using VLANCreateIface = details::ServerObject< |
| 28 | sdbusplus::xyz::openbmc_project::Network::VLAN::server::Create, |
| 29 | sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 30 | |
| 31 | using IntfName = std::string; |
| 32 | |
Ratan Gupta | 738a67f | 2017-04-21 10:38:05 +0530 | [diff] [blame] | 33 | struct AddrInfo |
| 34 | { |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 35 | short addrType; |
| 36 | std::string ipaddress; |
| 37 | }; |
| 38 | |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 39 | using Addr_t = ifaddrs*; |
| 40 | |
| 41 | struct AddrDeleter |
| 42 | { |
| 43 | void operator()(Addr_t ptr) const |
| 44 | { |
| 45 | freeifaddrs(ptr); |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | using AddrPtr = std::unique_ptr<ifaddrs, AddrDeleter>; |
| 50 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 51 | using AddrList = std::list<AddrInfo>; |
| 52 | using IntfAddrMap = std::map<IntfName, AddrList>; |
| 53 | |
| 54 | } // namespace details |
| 55 | |
Ratan Gupta | 8ab1792 | 2017-05-25 13:07:05 +0530 | [diff] [blame] | 56 | class TestNetworkManager; //forward declaration |
| 57 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 58 | /** @class Manager |
| 59 | * @brief OpenBMC network manager implementation. |
| 60 | */ |
| 61 | class Manager : public details::VLANCreateIface |
| 62 | { |
| 63 | public: |
| 64 | Manager() = delete; |
| 65 | Manager(const Manager&) = delete; |
| 66 | Manager& operator=(const Manager&) = delete; |
| 67 | Manager(Manager&&) = delete; |
| 68 | Manager& operator=(Manager&&) = delete; |
| 69 | virtual ~Manager() = default; |
| 70 | |
| 71 | /** @brief Constructor to put object onto bus at a dbus path. |
| 72 | * @param[in] bus - Bus to attach to. |
| 73 | * @param[in] objPath - Path to attach at. |
| 74 | */ |
| 75 | Manager(sdbusplus::bus::bus& bus, const char* objPath); |
| 76 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 77 | void vLAN(IntfName interfaceName, uint16_t id) override; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 78 | |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 79 | /** @brief write the network conf file with the in-memory objects. |
| 80 | */ |
| 81 | void writeToConfigurationFile(); |
| 82 | |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 83 | /** @brief Fetch the interface and the ipaddress details |
| 84 | * from the system and create the ethernet interraces |
| 85 | * dbus object. |
| 86 | */ |
| 87 | void createInterfaces(); |
| 88 | |
| 89 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 90 | private: |
| 91 | /** @brief Get all the interfaces from the system. |
| 92 | * @returns list of interface names. |
| 93 | */ |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 94 | IntfAddrMap getInterfaceAddrs() const; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 95 | |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 96 | /** @brief Restart the systemd networkd |
| 97 | */ |
| 98 | void restartSystemdNetworkd(); |
| 99 | |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 100 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 101 | sdbusplus::bus::bus& bus; |
| 102 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 103 | /** @brief Persistent map of EthernetInterface dbus objects and their names */ |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 104 | std::map<IntfName, std::unique_ptr<EthernetInterface>> interfaces; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 105 | |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 106 | /** @brief BMC network reset - resets network configuration for BMC. */ |
| 107 | void reset() override; |
| 108 | |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 109 | /** @brief Path of Object. */ |
| 110 | std::string objectPath; |
| 111 | |
Ratan Gupta | 8ab1792 | 2017-05-25 13:07:05 +0530 | [diff] [blame] | 112 | friend class TestNetworkManager; |
| 113 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | } // namespace network |
| 117 | } // namespace phosphor |