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