blob: 3d745cec1e64482677884ed46d37aba52d510fc2 [file] [log] [blame]
Ratan Gupta05eb1092017-04-14 16:33:53 +05301#pragma once
2
3#include "ethernet_interface.hpp"
Ratan Gupta82549cc2017-04-21 08:45:23 +05304#include "types.hpp"
Ratan Gupta05eb1092017-04-14 16:33:53 +05305#include "xyz/openbmc_project/Network/VLAN/Create/server.hpp"
6
7#include <sdbusplus/bus.hpp>
Ratan Gupta6811f822017-04-14 16:34:56 +05308#include <ifaddrs.h>
Ratan Gupta05eb1092017-04-14 16:33:53 +05309
10#include <list>
Ratan Gupta6811f822017-04-14 16:34:56 +053011#include <memory>
Ratan Gupta05eb1092017-04-14 16:33:53 +053012#include <string>
13#include <vector>
14
15namespace phosphor
16{
17namespace network
18{
19
20namespace details
21{
22
23template <typename T>
24using ServerObject = typename sdbusplus::server::object::object<T>;
25
26using VLANCreateIface =
27 details::ServerObject<sdbusplus::xyz::openbmc_project::
28 Network::VLAN::server::Create>;
29
30using IntfName = std::string;
31
32struct AddrInfo {
33 short addrType;
34 std::string ipaddress;
35};
36
Ratan Gupta6811f822017-04-14 16:34:56 +053037using Addr_t = ifaddrs*;
38
39struct AddrDeleter
40{
41 void operator()(Addr_t ptr) const
42 {
43 freeifaddrs(ptr);
44 }
45};
46
47using AddrPtr = std::unique_ptr<ifaddrs, AddrDeleter>;
48
Ratan Gupta05eb1092017-04-14 16:33:53 +053049using AddrList = std::list<AddrInfo>;
50using IntfAddrMap = std::map<IntfName, AddrList>;
51
52} // namespace details
53
54/** @class Manager
55 * @brief OpenBMC network manager implementation.
56 */
57class 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 Gupta82549cc2017-04-21 08:45:23 +053073 void vLAN(IntfName interfaceName, uint16_t id) override;
Ratan Gupta05eb1092017-04-14 16:33:53 +053074
75 private:
76 /** @brief Get all the interfaces from the system.
77 * @returns list of interface names.
78 */
Ratan Gupta82549cc2017-04-21 08:45:23 +053079 IntfAddrMap getInterfaceAddrs() const;
Ratan Gupta05eb1092017-04-14 16:33:53 +053080
81 /** @brief Persistent map of EthernetInterface dbus objects and their names */
Ratan Gupta82549cc2017-04-21 08:45:23 +053082 std::map<IntfName, std::unique_ptr<EthernetInterface>> interfaces;
Ratan Gupta05eb1092017-04-14 16:33:53 +053083
84};
85
86} // namespace network
87} // namespace phosphor