blob: 2e90b230ed45e9a8f457590406cd3e78a01fa9ef [file] [log] [blame]
Ratan Gupta05eb1092017-04-14 16:33:53 +05301#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 Gupta6811f822017-04-14 16:34:56 +05307#include <ifaddrs.h>
Ratan Gupta05eb1092017-04-14 16:33:53 +05308
9#include <list>
Ratan Gupta6811f822017-04-14 16:34:56 +053010#include <memory>
Ratan Gupta05eb1092017-04-14 16:33:53 +053011#include <string>
12#include <vector>
13
14namespace phosphor
15{
16namespace network
17{
18
19namespace details
20{
21
22template <typename T>
23using ServerObject = typename sdbusplus::server::object::object<T>;
24
25using VLANCreateIface =
26 details::ServerObject<sdbusplus::xyz::openbmc_project::
27 Network::VLAN::server::Create>;
28
29using IntfName = std::string;
30
31struct AddrInfo {
32 short addrType;
33 std::string ipaddress;
34};
35
Ratan Gupta6811f822017-04-14 16:34:56 +053036using Addr_t = ifaddrs*;
37
38struct AddrDeleter
39{
40 void operator()(Addr_t ptr) const
41 {
42 freeifaddrs(ptr);
43 }
44};
45
46using AddrPtr = std::unique_ptr<ifaddrs, AddrDeleter>;
47
Ratan Gupta05eb1092017-04-14 16:33:53 +053048using AddrList = std::list<AddrInfo>;
49using IntfAddrMap = std::map<IntfName, AddrList>;
50
51} // namespace details
52
53/** @class Manager
54 * @brief OpenBMC network manager implementation.
55 */
56class 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