Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "ethernet_interface.hpp" |
| 4 | #include "xyz/openbmc_project/Network/VLAN/Create/server.hpp" |
| 5 | |
| 6 | #include <sdbusplus/bus.hpp> |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 7 | #include <ifaddrs.h> |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 8 | |
| 9 | #include <list> |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 10 | #include <memory> |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 11 | #include <string> |
| 12 | #include <vector> |
| 13 | |
| 14 | namespace phosphor |
| 15 | { |
| 16 | namespace network |
| 17 | { |
| 18 | |
| 19 | namespace details |
| 20 | { |
| 21 | |
| 22 | template <typename T> |
| 23 | using ServerObject = typename sdbusplus::server::object::object<T>; |
| 24 | |
| 25 | using VLANCreateIface = |
| 26 | details::ServerObject<sdbusplus::xyz::openbmc_project:: |
| 27 | Network::VLAN::server::Create>; |
| 28 | |
| 29 | using IntfName = std::string; |
| 30 | |
| 31 | struct AddrInfo { |
| 32 | short addrType; |
| 33 | std::string ipaddress; |
| 34 | }; |
| 35 | |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 36 | using Addr_t = ifaddrs*; |
| 37 | |
| 38 | struct AddrDeleter |
| 39 | { |
| 40 | void operator()(Addr_t ptr) const |
| 41 | { |
| 42 | freeifaddrs(ptr); |
| 43 | } |
| 44 | }; |
| 45 | |
| 46 | using AddrPtr = std::unique_ptr<ifaddrs, AddrDeleter>; |
| 47 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 48 | using AddrList = std::list<AddrInfo>; |
| 49 | using IntfAddrMap = std::map<IntfName, AddrList>; |
| 50 | |
| 51 | } // namespace details |
| 52 | |
| 53 | /** @class Manager |
| 54 | * @brief OpenBMC network manager implementation. |
| 55 | */ |
| 56 | class Manager : public details::VLANCreateIface |
| 57 | { |
| 58 | public: |
| 59 | Manager() = delete; |
| 60 | Manager(const Manager&) = delete; |
| 61 | Manager& operator=(const Manager&) = delete; |
| 62 | Manager(Manager&&) = delete; |
| 63 | Manager& operator=(Manager&&) = delete; |
| 64 | virtual ~Manager() = default; |
| 65 | |
| 66 | /** @brief Constructor to put object onto bus at a dbus path. |
| 67 | * @param[in] bus - Bus to attach to. |
| 68 | * @param[in] objPath - Path to attach at. |
| 69 | */ |
| 70 | Manager(sdbusplus::bus::bus& bus, const char* objPath); |
| 71 | |
| 72 | void vLAN(details::IntfName interfaceName, uint16_t id) override; |
| 73 | |
| 74 | private: |
| 75 | /** @brief Get all the interfaces from the system. |
| 76 | * @returns list of interface names. |
| 77 | */ |
| 78 | details::IntfAddrMap getInterfaceAndaddrs() const; |
| 79 | |
| 80 | /** @brief Persistent map of EthernetInterface dbus objects and their names */ |
| 81 | std::map<details::IntfName, std::unique_ptr<EthernetInterface>> interfaces; |
| 82 | |
| 83 | }; |
| 84 | |
| 85 | } // namespace network |
| 86 | } // namespace phosphor |