blob: ed6dc5be3e3487d0fbbde9a6165e6ad40cc42ab8 [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
Nagaraju Goruganti067ca2d2018-01-17 01:12:00 -060040class TestRtNetlink; //forward declaration
Ratan Gupta8ab17922017-05-25 13:07:05 +053041
Ratan Gupta05eb1092017-04-14 16:33:53 +053042/** @class Manager
43 * @brief OpenBMC network manager implementation.
44 */
45class Manager : public details::VLANCreateIface
46{
47 public:
48 Manager() = delete;
49 Manager(const Manager&) = delete;
50 Manager& operator=(const Manager&) = delete;
51 Manager(Manager&&) = delete;
52 Manager& operator=(Manager&&) = delete;
53 virtual ~Manager() = default;
54
55 /** @brief Constructor to put object onto bus at a dbus path.
56 * @param[in] bus - Bus to attach to.
57 * @param[in] objPath - Path to attach at.
Ratan Gupta255d5142017-08-10 09:02:08 +053058 * @param[in] dir - Network Configuration directory path.
Ratan Gupta05eb1092017-04-14 16:33:53 +053059 */
Ratan Gupta255d5142017-08-10 09:02:08 +053060 Manager(sdbusplus::bus::bus& bus, const char* objPath,
61 const std::string& dir);
Ratan Gupta05eb1092017-04-14 16:33:53 +053062
Ratan Gupta584df832017-07-31 16:21:54 +053063 void vLAN(IntfName interfaceName, uint32_t id) override;
Ratan Gupta05eb1092017-04-14 16:33:53 +053064
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053065 /** @brief write the network conf file with the in-memory objects.
66 */
67 void writeToConfigurationFile();
68
Ratan Gupta29b0e432017-05-25 12:51:40 +053069 /** @brief Fetch the interface and the ipaddress details
70 * from the system and create the ethernet interraces
71 * dbus object.
72 */
73 void createInterfaces();
74
Ratan Guptaef85eb92017-06-15 08:57:54 +053075 /** @brief create child interface object and the system conf object.
Ratan Guptafc2c7242017-05-29 08:46:06 +053076 */
Ratan Guptaef85eb92017-06-15 08:57:54 +053077 void createChildObjects();
78
79 /** @brief sets the network conf directory.
80 * @param[in] dirName - Absolute path of the directory.
81 */
82 void setConfDir(const fs::path& dir);
83
Ratan Gupta255d5142017-08-10 09:02:08 +053084 /** @brief gets the network conf directory.
85 */
86 fs::path getConfDir() { return confDir; }
87
Ratan Gupta2b106532017-07-25 16:05:02 +053088 /** @brief gets the system conf object.
89 *
90 */
91 const SystemConfPtr& getSystemConf() { return systemConf; }
Ratan Gupta05eb1092017-04-14 16:33:53 +053092
Ratan Gupta2b106532017-07-25 16:05:02 +053093 /** @brief gets the dhcp conf object.
94 *
95 */
96 const DHCPConfPtr& getDHCPConf() { return dhcpConf; }
97
Ratan Guptab610caf2017-09-19 09:33:51 +053098 /** @brief create the default network files for each interface
99 * @detail if force param is true then forcefully create the network
100 * files otherwise if network file doesn't exist then
101 * create it.
102 * @param[in] force - forcefully create the file
103 * @return true if network file created else false
104 */
105 bool createDefaultNetworkFiles(bool force);
Ratan Gupta70c7e5b2017-07-12 11:41:55 +0530106
Ratan Gupta16f12882017-09-22 18:26:11 +0530107 /** @brief restart the network timers. */
108 void restartTimers();
Ratan Guptae05083a2017-09-16 07:12:11 +0530109
Ratan Guptab610caf2017-09-19 09:33:51 +0530110 private:
Ratan Gupta29b0e432017-05-25 12:51:40 +0530111 /** @brief Persistent sdbusplus DBus bus connection. */
112 sdbusplus::bus::bus& bus;
113
Ratan Gupta05eb1092017-04-14 16:33:53 +0530114 /** @brief Persistent map of EthernetInterface dbus objects and their names */
Ratan Gupta2b106532017-07-25 16:05:02 +0530115 std::map<IntfName, std::shared_ptr<EthernetInterface>> interfaces;
Ratan Gupta05eb1092017-04-14 16:33:53 +0530116
Michael Tritz29f2fd62017-05-22 15:27:26 -0500117 /** @brief BMC network reset - resets network configuration for BMC. */
118 void reset() override;
119
Ratan Gupta29b0e432017-05-25 12:51:40 +0530120 /** @brief Path of Object. */
121 std::string objectPath;
122
Ratan Guptaef85eb92017-06-15 08:57:54 +0530123 /** @brief pointer to system conf object. */
Ratan Gupta2b106532017-07-25 16:05:02 +0530124 SystemConfPtr systemConf = nullptr;
Ratan Guptaef85eb92017-06-15 08:57:54 +0530125
Ratan Guptad16f88c2017-07-11 17:47:57 +0530126 /** @brief pointer to dhcp conf object. */
Ratan Gupta2b106532017-07-25 16:05:02 +0530127 DHCPConfPtr dhcpConf = nullptr;
Ratan Guptad16f88c2017-07-11 17:47:57 +0530128
Ratan Guptaef85eb92017-06-15 08:57:54 +0530129 /** @brief Network Configuration directory. */
130 fs::path confDir;
131
Ratan Gupta8ab17922017-05-25 13:07:05 +0530132 friend class TestNetworkManager;
Nagaraju Goruganti067ca2d2018-01-17 01:12:00 -0600133 friend class TestRtNetlink;
Ratan Gupta8ab17922017-05-25 13:07:05 +0530134
Ratan Gupta05eb1092017-04-14 16:33:53 +0530135};
136
137} // namespace network
138} // namespace phosphor