blob: bdee88976d572c779c2d96aecabaae53c89a3c48 [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"
Michael Tritz29f2fd62017-05-22 15:27:26 -05006#include <xyz/openbmc_project/Common/FactoryReset/server.hpp>
Ratan Gupta05eb1092017-04-14 16:33:53 +05307
8#include <sdbusplus/bus.hpp>
Ratan Gupta6811f822017-04-14 16:34:56 +05309#include <ifaddrs.h>
Ratan Gupta05eb1092017-04-14 16:33:53 +053010
11#include <list>
Ratan Gupta6811f822017-04-14 16:34:56 +053012#include <memory>
Ratan Gupta05eb1092017-04-14 16:33:53 +053013#include <string>
14#include <vector>
15
16namespace phosphor
17{
18namespace network
19{
20
21namespace details
22{
23
Michael Tritz29f2fd62017-05-22 15:27:26 -050024template <typename T, typename U>
25using ServerObject = typename sdbusplus::server::object::object<T, U>;
Ratan Gupta05eb1092017-04-14 16:33:53 +053026
Michael Tritz29f2fd62017-05-22 15:27:26 -050027using VLANCreateIface = details::ServerObject<
28 sdbusplus::xyz::openbmc_project::Network::VLAN::server::Create,
29 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
Ratan Gupta05eb1092017-04-14 16:33:53 +053030
31using IntfName = std::string;
32
Ratan Gupta738a67f2017-04-21 10:38:05 +053033struct AddrInfo
34{
Ratan Gupta05eb1092017-04-14 16:33:53 +053035 short addrType;
36 std::string ipaddress;
37};
38
Ratan Gupta6811f822017-04-14 16:34:56 +053039using Addr_t = ifaddrs*;
40
41struct AddrDeleter
42{
43 void operator()(Addr_t ptr) const
44 {
45 freeifaddrs(ptr);
46 }
47};
48
49using AddrPtr = std::unique_ptr<ifaddrs, AddrDeleter>;
50
Ratan Gupta05eb1092017-04-14 16:33:53 +053051using AddrList = std::list<AddrInfo>;
52using IntfAddrMap = std::map<IntfName, AddrList>;
53
54} // namespace details
55
Ratan Gupta8ab17922017-05-25 13:07:05 +053056class TestNetworkManager; //forward declaration
57
Ratan Gupta05eb1092017-04-14 16:33:53 +053058/** @class Manager
59 * @brief OpenBMC network manager implementation.
60 */
61class 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 Gupta82549cc2017-04-21 08:45:23 +053077 void vLAN(IntfName interfaceName, uint16_t id) override;
Ratan Gupta05eb1092017-04-14 16:33:53 +053078
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053079 /** @brief write the network conf file with the in-memory objects.
80 */
81 void writeToConfigurationFile();
82
Ratan Gupta29b0e432017-05-25 12:51:40 +053083 /** @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 Gupta05eb1092017-04-14 16:33:53 +053090 private:
91 /** @brief Get all the interfaces from the system.
92 * @returns list of interface names.
93 */
Ratan Gupta82549cc2017-04-21 08:45:23 +053094 IntfAddrMap getInterfaceAddrs() const;
Ratan Gupta05eb1092017-04-14 16:33:53 +053095
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053096 /** @brief Restart the systemd networkd
97 */
98 void restartSystemdNetworkd();
99
Ratan Gupta29b0e432017-05-25 12:51:40 +0530100 /** @brief Persistent sdbusplus DBus bus connection. */
101 sdbusplus::bus::bus& bus;
102
Ratan Gupta05eb1092017-04-14 16:33:53 +0530103 /** @brief Persistent map of EthernetInterface dbus objects and their names */
Ratan Gupta82549cc2017-04-21 08:45:23 +0530104 std::map<IntfName, std::unique_ptr<EthernetInterface>> interfaces;
Ratan Gupta05eb1092017-04-14 16:33:53 +0530105
Michael Tritz29f2fd62017-05-22 15:27:26 -0500106 /** @brief BMC network reset - resets network configuration for BMC. */
107 void reset() override;
108
Ratan Gupta29b0e432017-05-25 12:51:40 +0530109 /** @brief Path of Object. */
110 std::string objectPath;
111
Ratan Gupta8ab17922017-05-25 13:07:05 +0530112 friend class TestNetworkManager;
113
Ratan Gupta05eb1092017-04-14 16:33:53 +0530114};
115
116} // namespace network
117} // namespace phosphor