summaryrefslogtreecommitdiffstats
path: root/network_manager.hpp
blob: 0d15fc630b0b5e35582ebcf3ba3faf93e756500f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#pragma once

#include "ethernet_interface.hpp"
#include "system_configuration.hpp"
#include "dhcp_configuration.hpp"
#include "vlan_interface.hpp"

#include <xyz/openbmc_project/Network/VLAN/Create/server.hpp>
#include <xyz/openbmc_project/Common/FactoryReset/server.hpp>
#include <sdbusplus/bus.hpp>

#include <list>
#include <memory>
#include <string>
#include <vector>
#include <experimental/filesystem>

namespace phosphor
{
namespace network
{

using SystemConfPtr = std::unique_ptr<SystemConfiguration>;
using DHCPConfPtr = std::unique_ptr<dhcp::Configuration>;

namespace fs = std::experimental::filesystem;
namespace details
{

template <typename T, typename U>
using ServerObject = typename sdbusplus::server::object::object<T, U>;

using VLANCreateIface = details::ServerObject<
    sdbusplus::xyz::openbmc_project::Network::VLAN::server::Create,
    sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;

} // namespace details

class TestNetworkManager; //forward declaration

/** @class Manager
 *  @brief OpenBMC network manager implementation.
 */
class Manager : public details::VLANCreateIface
{
    public:
        Manager() = delete;
        Manager(const Manager&) = delete;
        Manager& operator=(const Manager&) = delete;
        Manager(Manager&&) = delete;
        Manager& operator=(Manager&&) = delete;
        virtual ~Manager() = default;

        /** @brief Constructor to put object onto bus at a dbus path.
         *  @param[in] bus - Bus to attach to.
         *  @param[in] objPath - Path to attach at.
         *  @param[in] dir - Network Configuration directory path.
         */
        Manager(sdbusplus::bus::bus& bus, const char* objPath,
                const std::string& dir);

        void vLAN(IntfName interfaceName, uint32_t id) override;

        /** @brief write the network conf file with the in-memory objects.
         */
        void writeToConfigurationFile();

        /** @brief Fetch the interface and the ipaddress details
         *         from the system and create the ethernet interraces
         *         dbus object.
         */
        void createInterfaces();

        /** @brief create child interface object and the system conf object.
         */
        void createChildObjects();

        /** @brief sets the network conf directory.
         *  @param[in] dirName - Absolute path of the directory.
         */
        void setConfDir(const fs::path& dir);

        /** @brief gets the network conf directory.
         */
        fs::path getConfDir() { return confDir; }

        /** @brief gets the system conf object.
         *
         */
        const SystemConfPtr& getSystemConf() { return systemConf; }

        /** @brief gets the dhcp conf object.
         *
         */
        const DHCPConfPtr& getDHCPConf() { return dhcpConf; }

    private:

        /** @brief restart the systemd networkd. */
        void restartNetwork();

        /** @brief Persistent sdbusplus DBus bus connection. */
        sdbusplus::bus::bus& bus;

        /** @brief Persistent map of EthernetInterface dbus objects and their names */
        std::map<IntfName, std::shared_ptr<EthernetInterface>> interfaces;

        /** @brief BMC network reset - resets network configuration for BMC. */
        void reset() override;

        /** @brief Path of Object. */
        std::string objectPath;

        /** @brief pointer to system conf object. */
        SystemConfPtr systemConf = nullptr;

        /** @brief pointer to dhcp conf object. */
        DHCPConfPtr dhcpConf = nullptr;

        /** @brief Network Configuration directory. */
        fs::path confDir;

        friend class TestNetworkManager;

};

} // namespace network
} // namespace phosphor
OpenPOWER on IntegriCloud