blob: e5ca96b8027823f38840465ddd5c42b6dc6cc88d [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 Guptad16f88c2017-07-11 17:47:57 +05305#include "dhcp_configuration.hpp"
6#include <xyz/openbmc_project/Network/VLAN/Create/server.hpp>
Michael Tritz29f2fd62017-05-22 15:27:26 -05007#include <xyz/openbmc_project/Common/FactoryReset/server.hpp>
Ratan Gupta05eb1092017-04-14 16:33:53 +05308#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 Gupta70c7e5b2017-07-12 11:41:55 +053078 /** @brief write the dhcp section **/
79 void writeDHCPSection(std::fstream& stream);
80
Ratan Gupta29b0e432017-05-25 12:51:40 +053081 /** @brief Persistent sdbusplus DBus bus connection. */
82 sdbusplus::bus::bus& bus;
83
Ratan Gupta05eb1092017-04-14 16:33:53 +053084 /** @brief Persistent map of EthernetInterface dbus objects and their names */
Ratan Gupta82549cc2017-04-21 08:45:23 +053085 std::map<IntfName, std::unique_ptr<EthernetInterface>> interfaces;
Ratan Gupta05eb1092017-04-14 16:33:53 +053086
Michael Tritz29f2fd62017-05-22 15:27:26 -050087 /** @brief BMC network reset - resets network configuration for BMC. */
88 void reset() override;
89
Ratan Gupta34f96d62017-06-15 09:16:22 +053090 /** @brief read the DHCP value from the configuration file
91 * @param[in] intf - Interface name.
92 */
93 bool getDHCPValue(const std::string& intf);
94
Ratan Gupta29b0e432017-05-25 12:51:40 +053095 /** @brief Path of Object. */
96 std::string objectPath;
97
Ratan Guptaef85eb92017-06-15 08:57:54 +053098 /** @brief pointer to system conf object. */
99 std::unique_ptr<SystemConfiguration> systemConf = nullptr;
100
Ratan Guptad16f88c2017-07-11 17:47:57 +0530101 /** @brief pointer to dhcp conf object. */
102 std::unique_ptr<dhcp::Configuration> dhcpConf = nullptr;
103
Ratan Guptaef85eb92017-06-15 08:57:54 +0530104 /** @brief Network Configuration directory. */
105 fs::path confDir;
106
Ratan Gupta8ab17922017-05-25 13:07:05 +0530107 friend class TestNetworkManager;
108
Ratan Gupta05eb1092017-04-14 16:33:53 +0530109};
110
111} // namespace network
112} // namespace phosphor