blob: 7a98f9a17fb4c0a2a90eb458c059490e7db2bf4e [file] [log] [blame]
Ratan Gupta05eb1092017-04-14 16:33:53 +05301#pragma once
2
Patrick Venture189d44e2018-07-09 12:30:59 -07003#include "dhcp_configuration.hpp"
Ratan Gupta05eb1092017-04-14 16:33:53 +05304#include "ethernet_interface.hpp"
Ratan Guptaef85eb92017-06-15 08:57:54 +05305#include "system_configuration.hpp"
Ratan Gupta5978dd12017-07-25 13:47:13 +05306#include "vlan_interface.hpp"
Patrick Venture189d44e2018-07-09 12:30:59 -07007#include "xyz/openbmc_project/Network/VLAN/Create/server.hpp"
Ratan Gupta5978dd12017-07-25 13:47:13 +05308
Patrick Venture189d44e2018-07-09 12:30:59 -07009#include <experimental/filesystem>
Ratan Gupta05eb1092017-04-14 16:33:53 +053010#include <list>
Ratan Gupta6811f822017-04-14 16:34:56 +053011#include <memory>
Patrick Venture189d44e2018-07-09 12:30:59 -070012#include <sdbusplus/bus.hpp>
Ratan Gupta05eb1092017-04-14 16:33:53 +053013#include <string>
14#include <vector>
Patrick Venture189d44e2018-07-09 12:30:59 -070015#include <xyz/openbmc_project/Common/FactoryReset/server.hpp>
Ratan Gupta05eb1092017-04-14 16:33:53 +053016
17namespace phosphor
18{
19namespace network
20{
21
Ratan Gupta2b106532017-07-25 16:05:02 +053022using SystemConfPtr = std::unique_ptr<SystemConfiguration>;
23using DHCPConfPtr = std::unique_ptr<dhcp::Configuration>;
24
Ratan Guptaef85eb92017-06-15 08:57:54 +053025namespace fs = std::experimental::filesystem;
Ratan Gupta05eb1092017-04-14 16:33:53 +053026namespace details
27{
28
Michael Tritz29f2fd62017-05-22 15:27:26 -050029template <typename T, typename U>
30using ServerObject = typename sdbusplus::server::object::object<T, U>;
Ratan Gupta05eb1092017-04-14 16:33:53 +053031
Michael Tritz29f2fd62017-05-22 15:27:26 -050032using VLANCreateIface = details::ServerObject<
33 sdbusplus::xyz::openbmc_project::Network::VLAN::server::Create,
34 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
Ratan Gupta05eb1092017-04-14 16:33:53 +053035
Ratan Gupta05eb1092017-04-14 16:33:53 +053036} // namespace details
37
Gunnar Mills57d9c502018-09-14 14:42:34 -050038class TestNetworkManager; // forward declaration
39class TestRtNetlink; // forward declaration
Ratan Gupta8ab17922017-05-25 13:07:05 +053040
Ratan Gupta05eb1092017-04-14 16:33:53 +053041/** @class Manager
42 * @brief OpenBMC network manager implementation.
43 */
44class Manager : public details::VLANCreateIface
45{
Gunnar Mills57d9c502018-09-14 14:42:34 -050046 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;
Ratan Gupta05eb1092017-04-14 16:33:53 +053053
Gunnar Mills57d9c502018-09-14 14:42:34 -050054 /** @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.
57 * @param[in] dir - Network Configuration directory path.
58 */
59 Manager(sdbusplus::bus::bus& bus, const char* objPath,
60 const std::string& dir);
Ratan Gupta05eb1092017-04-14 16:33:53 +053061
Gunnar Mills57d9c502018-09-14 14:42:34 -050062 void vLAN(IntfName interfaceName, uint32_t id) override;
Ratan Gupta05eb1092017-04-14 16:33:53 +053063
Gunnar Mills57d9c502018-09-14 14:42:34 -050064 /** @brief write the network conf file with the in-memory objects.
65 */
66 void writeToConfigurationFile();
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053067
Gunnar Mills57d9c502018-09-14 14:42:34 -050068 /** @brief Fetch the interface and the ipaddress details
69 * from the system and create the ethernet interraces
70 * dbus object.
71 */
72 void createInterfaces();
Ratan Gupta29b0e432017-05-25 12:51:40 +053073
Gunnar Mills57d9c502018-09-14 14:42:34 -050074 /** @brief create child interface object and the system conf object.
75 */
76 void createChildObjects();
Ratan Guptaef85eb92017-06-15 08:57:54 +053077
Gunnar Mills57d9c502018-09-14 14:42:34 -050078 /** @brief sets the network conf directory.
79 * @param[in] dirName - Absolute path of the directory.
80 */
81 void setConfDir(const fs::path& dir);
Ratan Guptaef85eb92017-06-15 08:57:54 +053082
Gunnar Mills57d9c502018-09-14 14:42:34 -050083 /** @brief gets the network conf directory.
84 */
85 fs::path getConfDir()
86 {
87 return confDir;
88 }
Ratan Gupta255d5142017-08-10 09:02:08 +053089
Gunnar Mills57d9c502018-09-14 14:42:34 -050090 /** @brief gets the system conf object.
91 *
92 */
93 const SystemConfPtr& getSystemConf()
94 {
95 return systemConf;
96 }
Ratan Gupta05eb1092017-04-14 16:33:53 +053097
Gunnar Mills57d9c502018-09-14 14:42:34 -050098 /** @brief gets the dhcp conf object.
99 *
100 */
101 const DHCPConfPtr& getDHCPConf()
102 {
103 return dhcpConf;
104 }
Ratan Gupta2b106532017-07-25 16:05:02 +0530105
Gunnar Mills57d9c502018-09-14 14:42:34 -0500106 /** @brief create the default network files for each interface
107 * @detail if force param is true then forcefully create the network
108 * files otherwise if network file doesn't exist then
109 * create it.
110 * @param[in] force - forcefully create the file
111 * @return true if network file created else false
112 */
113 bool createDefaultNetworkFiles(bool force);
Ratan Gupta70c7e5b2017-07-12 11:41:55 +0530114
Gunnar Mills57d9c502018-09-14 14:42:34 -0500115 /** @brief restart the network timers. */
116 void restartTimers();
Ratan Guptae05083a2017-09-16 07:12:11 +0530117
Ratan Gupta895f9e52018-11-26 20:57:34 +0530118 /** @brief Restart the systemd unit
119 * @param[in] unit - systemd unit name which needs to be
120 * restarted.
121 */
122 inline void restartSystemdUnit(const std::string& unit)
123 {
124 auto bus = sdbusplus::bus::new_default();
125 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
126 SYSTEMD_INTERFACE, "RestartUnit");
127
128 method.append(unit, "replace");
129 bus.call_noreply(method);
130 }
131
Gunnar Mills57d9c502018-09-14 14:42:34 -0500132 private:
133 /** @brief Persistent sdbusplus DBus bus connection. */
134 sdbusplus::bus::bus& bus;
Ratan Gupta29b0e432017-05-25 12:51:40 +0530135
Gunnar Mills57d9c502018-09-14 14:42:34 -0500136 /** @brief Persistent map of EthernetInterface dbus objects and their names
137 */
138 std::map<IntfName, std::shared_ptr<EthernetInterface>> interfaces;
Ratan Gupta05eb1092017-04-14 16:33:53 +0530139
Gunnar Mills57d9c502018-09-14 14:42:34 -0500140 /** @brief BMC network reset - resets network configuration for BMC. */
141 void reset() override;
Michael Tritz29f2fd62017-05-22 15:27:26 -0500142
Gunnar Mills57d9c502018-09-14 14:42:34 -0500143 /** @brief Path of Object. */
144 std::string objectPath;
Ratan Gupta29b0e432017-05-25 12:51:40 +0530145
Gunnar Mills57d9c502018-09-14 14:42:34 -0500146 /** @brief pointer to system conf object. */
147 SystemConfPtr systemConf = nullptr;
Ratan Guptaef85eb92017-06-15 08:57:54 +0530148
Gunnar Mills57d9c502018-09-14 14:42:34 -0500149 /** @brief pointer to dhcp conf object. */
150 DHCPConfPtr dhcpConf = nullptr;
Ratan Guptad16f88c2017-07-11 17:47:57 +0530151
Gunnar Mills57d9c502018-09-14 14:42:34 -0500152 /** @brief Network Configuration directory. */
153 fs::path confDir;
Ratan Guptaef85eb92017-06-15 08:57:54 +0530154
Gunnar Mills57d9c502018-09-14 14:42:34 -0500155 friend class TestNetworkManager;
156 friend class TestRtNetlink;
Ratan Gupta05eb1092017-04-14 16:33:53 +0530157};
158
159} // namespace network
160} // namespace phosphor