blob: df98104fa8136697525fbb127687a8c25e74f43f [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 Guptaef85eb92017-06-15 08:57:54 +053023namespace fs = std::experimental::filesystem;
Ratan Gupta05eb1092017-04-14 16:33:53 +053024namespace details
25{
26
Michael Tritz29f2fd62017-05-22 15:27:26 -050027template <typename T, typename U>
28using ServerObject = typename sdbusplus::server::object::object<T, U>;
Ratan Gupta05eb1092017-04-14 16:33:53 +053029
Michael Tritz29f2fd62017-05-22 15:27:26 -050030using VLANCreateIface = details::ServerObject<
31 sdbusplus::xyz::openbmc_project::Network::VLAN::server::Create,
32 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
Ratan Gupta05eb1092017-04-14 16:33:53 +053033
Ratan Gupta05eb1092017-04-14 16:33:53 +053034} // namespace details
35
Ratan Gupta8ab17922017-05-25 13:07:05 +053036class TestNetworkManager; //forward declaration
37
Ratan Gupta05eb1092017-04-14 16:33:53 +053038/** @class Manager
39 * @brief OpenBMC network manager implementation.
40 */
41class Manager : public details::VLANCreateIface
42{
43 public:
44 Manager() = delete;
45 Manager(const Manager&) = delete;
46 Manager& operator=(const Manager&) = delete;
47 Manager(Manager&&) = delete;
48 Manager& operator=(Manager&&) = delete;
49 virtual ~Manager() = default;
50
51 /** @brief Constructor to put object onto bus at a dbus path.
52 * @param[in] bus - Bus to attach to.
53 * @param[in] objPath - Path to attach at.
Ratan Gupta255d5142017-08-10 09:02:08 +053054 * @param[in] dir - Network Configuration directory path.
Ratan Gupta05eb1092017-04-14 16:33:53 +053055 */
Ratan Gupta255d5142017-08-10 09:02:08 +053056 Manager(sdbusplus::bus::bus& bus, const char* objPath,
57 const std::string& dir);
Ratan Gupta05eb1092017-04-14 16:33:53 +053058
Ratan Gupta584df832017-07-31 16:21:54 +053059 void vLAN(IntfName interfaceName, uint32_t id) override;
Ratan Gupta05eb1092017-04-14 16:33:53 +053060
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053061 /** @brief write the network conf file with the in-memory objects.
62 */
63 void writeToConfigurationFile();
64
Ratan Gupta29b0e432017-05-25 12:51:40 +053065 /** @brief Fetch the interface and the ipaddress details
66 * from the system and create the ethernet interraces
67 * dbus object.
68 */
69 void createInterfaces();
70
Ratan Guptaef85eb92017-06-15 08:57:54 +053071 /** @brief create child interface object and the system conf object.
Ratan Guptafc2c7242017-05-29 08:46:06 +053072 */
Ratan Guptaef85eb92017-06-15 08:57:54 +053073 void createChildObjects();
74
75 /** @brief sets the network conf directory.
76 * @param[in] dirName - Absolute path of the directory.
77 */
78 void setConfDir(const fs::path& dir);
79
Ratan Gupta255d5142017-08-10 09:02:08 +053080 /** @brief gets the network conf directory.
81 */
82 fs::path getConfDir() { return confDir; }
83
Ratan Gupta05eb1092017-04-14 16:33:53 +053084 private:
Ratan Gupta05eb1092017-04-14 16:33:53 +053085
Ratan Gupta70c7e5b2017-07-12 11:41:55 +053086 /** @brief write the dhcp section **/
87 void writeDHCPSection(std::fstream& stream);
88
Ratan Gupta29b0e432017-05-25 12:51:40 +053089 /** @brief Persistent sdbusplus DBus bus connection. */
90 sdbusplus::bus::bus& bus;
91
Ratan Gupta05eb1092017-04-14 16:33:53 +053092 /** @brief Persistent map of EthernetInterface dbus objects and their names */
Ratan Gupta82549cc2017-04-21 08:45:23 +053093 std::map<IntfName, std::unique_ptr<EthernetInterface>> interfaces;
Ratan Gupta05eb1092017-04-14 16:33:53 +053094
Michael Tritz29f2fd62017-05-22 15:27:26 -050095 /** @brief BMC network reset - resets network configuration for BMC. */
96 void reset() override;
97
Ratan Gupta34f96d62017-06-15 09:16:22 +053098 /** @brief read the DHCP value from the configuration file
99 * @param[in] intf - Interface name.
100 */
101 bool getDHCPValue(const std::string& intf);
102
Ratan Gupta29b0e432017-05-25 12:51:40 +0530103 /** @brief Path of Object. */
104 std::string objectPath;
105
Ratan Guptaef85eb92017-06-15 08:57:54 +0530106 /** @brief pointer to system conf object. */
107 std::unique_ptr<SystemConfiguration> systemConf = nullptr;
108
Ratan Guptad16f88c2017-07-11 17:47:57 +0530109 /** @brief pointer to dhcp conf object. */
110 std::unique_ptr<dhcp::Configuration> dhcpConf = nullptr;
111
Ratan Guptaef85eb92017-06-15 08:57:54 +0530112 /** @brief Network Configuration directory. */
113 fs::path confDir;
114
Ratan Gupta8ab17922017-05-25 13:07:05 +0530115 friend class TestNetworkManager;
116
Ratan Gupta05eb1092017-04-14 16:33:53 +0530117};
118
119} // namespace network
120} // namespace phosphor