blob: edb341f896a11512a3a1675a6c351c9cf1557a2d [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
38/** @class Manager
39 * @brief OpenBMC network manager implementation.
40 */
41class Manager : public details::VLANCreateIface
42{
Gunnar Mills57d9c502018-09-14 14:42:34 -050043 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;
Ratan Gupta05eb1092017-04-14 16:33:53 +053050
Gunnar Mills57d9c502018-09-14 14:42:34 -050051 /** @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.
54 * @param[in] dir - Network Configuration directory path.
55 */
56 Manager(sdbusplus::bus::bus& bus, const char* objPath,
57 const std::string& dir);
Ratan Gupta05eb1092017-04-14 16:33:53 +053058
William A. Kennington IIIf4b4ff82019-04-09 19:06:52 -070059 ObjectPath vLAN(IntfName interfaceName, uint32_t id) override;
Ratan Gupta05eb1092017-04-14 16:33:53 +053060
Gunnar Mills57d9c502018-09-14 14:42:34 -050061 /** @brief write the network conf file with the in-memory objects.
62 */
63 void writeToConfigurationFile();
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053064
Gunnar Mills57d9c502018-09-14 14:42:34 -050065 /** @brief Fetch the interface and the ipaddress details
66 * from the system and create the ethernet interraces
67 * dbus object.
68 */
69 void createInterfaces();
Ratan Gupta29b0e432017-05-25 12:51:40 +053070
Gunnar Mills57d9c502018-09-14 14:42:34 -050071 /** @brief create child interface object and the system conf object.
72 */
73 void createChildObjects();
Ratan Guptaef85eb92017-06-15 08:57:54 +053074
Gunnar Mills57d9c502018-09-14 14:42:34 -050075 /** @brief sets the network conf directory.
76 * @param[in] dirName - Absolute path of the directory.
77 */
78 void setConfDir(const fs::path& dir);
Ratan Guptaef85eb92017-06-15 08:57:54 +053079
Gunnar Mills57d9c502018-09-14 14:42:34 -050080 /** @brief gets the network conf directory.
81 */
82 fs::path getConfDir()
83 {
84 return confDir;
85 }
Ratan Gupta255d5142017-08-10 09:02:08 +053086
Gunnar Mills57d9c502018-09-14 14:42:34 -050087 /** @brief gets the system conf object.
88 *
89 */
90 const SystemConfPtr& getSystemConf()
91 {
92 return systemConf;
93 }
Ratan Gupta05eb1092017-04-14 16:33:53 +053094
Gunnar Mills57d9c502018-09-14 14:42:34 -050095 /** @brief gets the dhcp conf object.
96 *
97 */
98 const DHCPConfPtr& getDHCPConf()
99 {
100 return dhcpConf;
101 }
Ratan Gupta2b106532017-07-25 16:05:02 +0530102
Gunnar Mills57d9c502018-09-14 14:42:34 -0500103 /** @brief create the default network files for each interface
104 * @detail if force param is true then forcefully create the network
105 * files otherwise if network file doesn't exist then
106 * create it.
107 * @param[in] force - forcefully create the file
108 * @return true if network file created else false
109 */
110 bool createDefaultNetworkFiles(bool force);
Ratan Gupta70c7e5b2017-07-12 11:41:55 +0530111
Gunnar Mills57d9c502018-09-14 14:42:34 -0500112 /** @brief restart the network timers. */
113 void restartTimers();
Ratan Guptae05083a2017-09-16 07:12:11 +0530114
Ratan Gupta895f9e52018-11-26 20:57:34 +0530115 /** @brief Restart the systemd unit
116 * @param[in] unit - systemd unit name which needs to be
117 * restarted.
118 */
Ratan Gupta35297172018-11-28 18:40:16 +0530119 virtual void restartSystemdUnit(const std::string& unit);
Ratan Gupta895f9e52018-11-26 20:57:34 +0530120
Patrick Ventured94d23e2019-01-07 13:05:23 -0800121 /** @brief Returns the number of interfaces under this manager.
122 *
123 * @return the number of interfaces managed by this manager.
124 */
125 int getInterfaceCount()
126 {
127 return interfaces.size();
128 }
129
130 /** @brief Does the requested interface exist under this manager?
131 *
132 * @param[in] intf - the interface name to check.
133 * @return true if found, false otherwise.
134 */
135 bool hasInterface(const std::string& intf)
136 {
137 return (interfaces.find(intf) != interfaces.end());
138 }
139
Ratan Gupta35297172018-11-28 18:40:16 +0530140 protected:
Gunnar Mills57d9c502018-09-14 14:42:34 -0500141 /** @brief Persistent sdbusplus DBus bus connection. */
142 sdbusplus::bus::bus& bus;
Ratan Gupta29b0e432017-05-25 12:51:40 +0530143
Gunnar Mills57d9c502018-09-14 14:42:34 -0500144 /** @brief Persistent map of EthernetInterface dbus objects and their names
145 */
146 std::map<IntfName, std::shared_ptr<EthernetInterface>> interfaces;
Ratan Gupta05eb1092017-04-14 16:33:53 +0530147
Gunnar Mills57d9c502018-09-14 14:42:34 -0500148 /** @brief BMC network reset - resets network configuration for BMC. */
149 void reset() override;
Michael Tritz29f2fd62017-05-22 15:27:26 -0500150
Gunnar Mills57d9c502018-09-14 14:42:34 -0500151 /** @brief Path of Object. */
152 std::string objectPath;
Ratan Gupta29b0e432017-05-25 12:51:40 +0530153
Gunnar Mills57d9c502018-09-14 14:42:34 -0500154 /** @brief pointer to system conf object. */
155 SystemConfPtr systemConf = nullptr;
Ratan Guptaef85eb92017-06-15 08:57:54 +0530156
Gunnar Mills57d9c502018-09-14 14:42:34 -0500157 /** @brief pointer to dhcp conf object. */
158 DHCPConfPtr dhcpConf = nullptr;
Ratan Guptad16f88c2017-07-11 17:47:57 +0530159
Gunnar Mills57d9c502018-09-14 14:42:34 -0500160 /** @brief Network Configuration directory. */
161 fs::path confDir;
Ratan Gupta05eb1092017-04-14 16:33:53 +0530162};
163
164} // namespace network
165} // namespace phosphor