blob: 4849faf6767f08a4d403b8a2e469a4e5c9775724 [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"
Ratan Gupta5978dd12017-07-25 13:47:13 +05306#include "vlan_interface.hpp"
7
Ratan Guptad16f88c2017-07-11 17:47:57 +05308#include <xyz/openbmc_project/Network/VLAN/Create/server.hpp>
Michael Tritz29f2fd62017-05-22 15:27:26 -05009#include <xyz/openbmc_project/Common/FactoryReset/server.hpp>
Ratan Gupta05eb1092017-04-14 16:33:53 +053010#include <sdbusplus/bus.hpp>
11
12#include <list>
Ratan Gupta6811f822017-04-14 16:34:56 +053013#include <memory>
Ratan Gupta05eb1092017-04-14 16:33:53 +053014#include <string>
15#include <vector>
Ratan Guptaef85eb92017-06-15 08:57:54 +053016#include <experimental/filesystem>
Ratan Gupta05eb1092017-04-14 16:33:53 +053017
18namespace phosphor
19{
20namespace network
21{
22
Ratan Gupta2b106532017-07-25 16:05:02 +053023using SystemConfPtr = std::unique_ptr<SystemConfiguration>;
24using DHCPConfPtr = std::unique_ptr<dhcp::Configuration>;
25
Ratan Guptaef85eb92017-06-15 08:57:54 +053026namespace fs = std::experimental::filesystem;
Ratan Gupta05eb1092017-04-14 16:33:53 +053027namespace details
28{
29
Michael Tritz29f2fd62017-05-22 15:27:26 -050030template <typename T, typename U>
31using ServerObject = typename sdbusplus::server::object::object<T, U>;
Ratan Gupta05eb1092017-04-14 16:33:53 +053032
Michael Tritz29f2fd62017-05-22 15:27:26 -050033using VLANCreateIface = details::ServerObject<
34 sdbusplus::xyz::openbmc_project::Network::VLAN::server::Create,
35 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
Ratan Gupta05eb1092017-04-14 16:33:53 +053036
Ratan Gupta05eb1092017-04-14 16:33:53 +053037} // namespace details
38
Ratan Gupta8ab17922017-05-25 13:07:05 +053039class TestNetworkManager; //forward declaration
40
Ratan Gupta05eb1092017-04-14 16:33:53 +053041/** @class Manager
42 * @brief OpenBMC network manager implementation.
43 */
44class Manager : public details::VLANCreateIface
45{
46 public:
47 Manager() = delete;
48 Manager(const Manager&) = delete;
49 Manager& operator=(const Manager&) = delete;
50 Manager(Manager&&) = delete;
51 Manager& operator=(Manager&&) = delete;
52 virtual ~Manager() = default;
53
54 /** @brief Constructor to put object onto bus at a dbus path.
55 * @param[in] bus - Bus to attach to.
56 * @param[in] objPath - Path to attach at.
Ratan Gupta255d5142017-08-10 09:02:08 +053057 * @param[in] dir - Network Configuration directory path.
Ratan Gupta05eb1092017-04-14 16:33:53 +053058 */
Ratan Gupta255d5142017-08-10 09:02:08 +053059 Manager(sdbusplus::bus::bus& bus, const char* objPath,
60 const std::string& dir);
Ratan Gupta05eb1092017-04-14 16:33:53 +053061
Ratan Gupta584df832017-07-31 16:21:54 +053062 void vLAN(IntfName interfaceName, uint32_t id) override;
Ratan Gupta05eb1092017-04-14 16:33:53 +053063
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053064 /** @brief write the network conf file with the in-memory objects.
65 */
66 void writeToConfigurationFile();
67
Ratan Gupta29b0e432017-05-25 12:51:40 +053068 /** @brief Fetch the interface and the ipaddress details
69 * from the system and create the ethernet interraces
70 * dbus object.
71 */
72 void createInterfaces();
73
Ratan Guptaef85eb92017-06-15 08:57:54 +053074 /** @brief create child interface object and the system conf object.
Ratan Guptafc2c7242017-05-29 08:46:06 +053075 */
Ratan Guptaef85eb92017-06-15 08:57:54 +053076 void createChildObjects();
77
78 /** @brief sets the network conf directory.
79 * @param[in] dirName - Absolute path of the directory.
80 */
81 void setConfDir(const fs::path& dir);
82
Ratan Gupta255d5142017-08-10 09:02:08 +053083 /** @brief gets the network conf directory.
84 */
85 fs::path getConfDir() { return confDir; }
86
Ratan Gupta2b106532017-07-25 16:05:02 +053087 /** @brief gets the system conf object.
88 *
89 */
90 const SystemConfPtr& getSystemConf() { return systemConf; }
Ratan Gupta05eb1092017-04-14 16:33:53 +053091
Ratan Gupta2b106532017-07-25 16:05:02 +053092 /** @brief gets the dhcp conf object.
93 *
94 */
95 const DHCPConfPtr& getDHCPConf() { return dhcpConf; }
96
97 private:
Ratan Gupta70c7e5b2017-07-12 11:41:55 +053098
Ratan Gupta29b0e432017-05-25 12:51:40 +053099 /** @brief Persistent sdbusplus DBus bus connection. */
100 sdbusplus::bus::bus& bus;
101
Ratan Gupta05eb1092017-04-14 16:33:53 +0530102 /** @brief Persistent map of EthernetInterface dbus objects and their names */
Ratan Gupta2b106532017-07-25 16:05:02 +0530103 std::map<IntfName, std::shared_ptr<EthernetInterface>> interfaces;
Ratan Gupta05eb1092017-04-14 16:33:53 +0530104
Michael Tritz29f2fd62017-05-22 15:27:26 -0500105 /** @brief BMC network reset - resets network configuration for BMC. */
106 void reset() override;
107
Ratan Gupta34f96d62017-06-15 09:16:22 +0530108 /** @brief read the DHCP value from the configuration file
109 * @param[in] intf - Interface name.
110 */
111 bool getDHCPValue(const std::string& intf);
112
Ratan Gupta29b0e432017-05-25 12:51:40 +0530113 /** @brief Path of Object. */
114 std::string objectPath;
115
Ratan Guptaef85eb92017-06-15 08:57:54 +0530116 /** @brief pointer to system conf object. */
Ratan Gupta2b106532017-07-25 16:05:02 +0530117 SystemConfPtr systemConf = nullptr;
Ratan Guptaef85eb92017-06-15 08:57:54 +0530118
Ratan Guptad16f88c2017-07-11 17:47:57 +0530119 /** @brief pointer to dhcp conf object. */
Ratan Gupta2b106532017-07-25 16:05:02 +0530120 DHCPConfPtr dhcpConf = nullptr;
Ratan Guptad16f88c2017-07-11 17:47:57 +0530121
Ratan Guptaef85eb92017-06-15 08:57:54 +0530122 /** @brief Network Configuration directory. */
123 fs::path confDir;
124
Ratan Gupta8ab17922017-05-25 13:07:05 +0530125 friend class TestNetworkManager;
126
Ratan Gupta05eb1092017-04-14 16:33:53 +0530127};
128
129} // namespace network
130} // namespace phosphor