blob: ce61737b6cdcb920bdb3ec80ed1a2d28dac8d6e1 [file] [log] [blame]
Ratan Gupta05eb1092017-04-14 16:33:53 +05301#pragma once
2
3#include "ethernet_interface.hpp"
Ratan Guptaef85eb92017-06-15 08:57:54 +05304#include "system_configuration.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>
9
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>
Ratan Guptaef85eb92017-06-15 08:57:54 +053014#include <experimental/filesystem>
Ratan Gupta05eb1092017-04-14 16:33:53 +053015
16namespace phosphor
17{
18namespace network
19{
20
Ratan Guptaef85eb92017-06-15 08:57:54 +053021namespace fs = std::experimental::filesystem;
Ratan Gupta05eb1092017-04-14 16:33:53 +053022namespace details
23{
24
Michael Tritz29f2fd62017-05-22 15:27:26 -050025template <typename T, typename U>
26using ServerObject = typename sdbusplus::server::object::object<T, U>;
Ratan Gupta05eb1092017-04-14 16:33:53 +053027
Michael Tritz29f2fd62017-05-22 15:27:26 -050028using VLANCreateIface = details::ServerObject<
29 sdbusplus::xyz::openbmc_project::Network::VLAN::server::Create,
30 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
Ratan Gupta05eb1092017-04-14 16:33:53 +053031
Ratan Gupta05eb1092017-04-14 16:33:53 +053032} // namespace details
33
Ratan Gupta8ab17922017-05-25 13:07:05 +053034class TestNetworkManager; //forward declaration
35
Ratan Gupta05eb1092017-04-14 16:33:53 +053036/** @class Manager
37 * @brief OpenBMC network manager implementation.
38 */
39class Manager : public details::VLANCreateIface
40{
41 public:
42 Manager() = delete;
43 Manager(const Manager&) = delete;
44 Manager& operator=(const Manager&) = delete;
45 Manager(Manager&&) = delete;
46 Manager& operator=(Manager&&) = delete;
47 virtual ~Manager() = default;
48
49 /** @brief Constructor to put object onto bus at a dbus path.
50 * @param[in] bus - Bus to attach to.
51 * @param[in] objPath - Path to attach at.
52 */
53 Manager(sdbusplus::bus::bus& bus, const char* objPath);
54
Ratan Gupta82549cc2017-04-21 08:45:23 +053055 void vLAN(IntfName interfaceName, uint16_t id) override;
Ratan Gupta05eb1092017-04-14 16:33:53 +053056
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053057 /** @brief write the network conf file with the in-memory objects.
58 */
59 void writeToConfigurationFile();
60
Ratan Gupta29b0e432017-05-25 12:51:40 +053061 /** @brief Fetch the interface and the ipaddress details
62 * from the system and create the ethernet interraces
63 * dbus object.
64 */
65 void createInterfaces();
66
Ratan Guptaef85eb92017-06-15 08:57:54 +053067 /** @brief create child interface object and the system conf object.
Ratan Guptafc2c7242017-05-29 08:46:06 +053068 */
Ratan Guptaef85eb92017-06-15 08:57:54 +053069 void createChildObjects();
70
71 /** @brief sets the network conf directory.
72 * @param[in] dirName - Absolute path of the directory.
73 */
74 void setConfDir(const fs::path& dir);
75
Ratan Gupta05eb1092017-04-14 16:33:53 +053076 private:
Ratan Gupta05eb1092017-04-14 16:33:53 +053077
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053078 /** @brief Restart the systemd networkd
79 */
80 void restartSystemdNetworkd();
81
Ratan Gupta29b0e432017-05-25 12:51:40 +053082 /** @brief Persistent sdbusplus DBus bus connection. */
83 sdbusplus::bus::bus& bus;
84
Ratan Gupta05eb1092017-04-14 16:33:53 +053085 /** @brief Persistent map of EthernetInterface dbus objects and their names */
Ratan Gupta82549cc2017-04-21 08:45:23 +053086 std::map<IntfName, std::unique_ptr<EthernetInterface>> interfaces;
Ratan Gupta05eb1092017-04-14 16:33:53 +053087
Michael Tritz29f2fd62017-05-22 15:27:26 -050088 /** @brief BMC network reset - resets network configuration for BMC. */
89 void reset() override;
90
Ratan Gupta34f96d62017-06-15 09:16:22 +053091 /** @brief read the DHCP value from the configuration file
92 * @param[in] intf - Interface name.
93 */
94 bool getDHCPValue(const std::string& intf);
95
Ratan Gupta29b0e432017-05-25 12:51:40 +053096 /** @brief Path of Object. */
97 std::string objectPath;
98
Ratan Guptaef85eb92017-06-15 08:57:54 +053099 /** @brief pointer to system conf object. */
100 std::unique_ptr<SystemConfiguration> systemConf = nullptr;
101
102 /** @brief Network Configuration directory. */
103 fs::path confDir;
104
Ratan Gupta8ab17922017-05-25 13:07:05 +0530105 friend class TestNetworkManager;
106
Ratan Gupta05eb1092017-04-14 16:33:53 +0530107};
108
109} // namespace network
110} // namespace phosphor