blob: 1854364be4431be2a0266f553d5a677c0c90623b [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 Gupta29b0e432017-05-25 12:51:40 +053078 /** @brief Persistent sdbusplus DBus bus connection. */
79 sdbusplus::bus::bus& bus;
80
Ratan Gupta05eb1092017-04-14 16:33:53 +053081 /** @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
Michael Tritz29f2fd62017-05-22 15:27:26 -050084 /** @brief BMC network reset - resets network configuration for BMC. */
85 void reset() override;
86
Ratan Gupta34f96d62017-06-15 09:16:22 +053087 /** @brief read the DHCP value from the configuration file
88 * @param[in] intf - Interface name.
89 */
90 bool getDHCPValue(const std::string& intf);
91
Ratan Gupta29b0e432017-05-25 12:51:40 +053092 /** @brief Path of Object. */
93 std::string objectPath;
94
Ratan Guptaef85eb92017-06-15 08:57:54 +053095 /** @brief pointer to system conf object. */
96 std::unique_ptr<SystemConfiguration> systemConf = nullptr;
97
98 /** @brief Network Configuration directory. */
99 fs::path confDir;
100
Ratan Gupta8ab17922017-05-25 13:07:05 +0530101 friend class TestNetworkManager;
102
Ratan Gupta05eb1092017-04-14 16:33:53 +0530103};
104
105} // namespace network
106} // namespace phosphor