blob: 227955c6e5cd04a4f9f3d19dacef13595feecd41 [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
Manojkiran Edaa879baa2020-06-13 14:39:08 +05309#include <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
Patrick Williams8173e022021-05-01 06:39:41 -050017#ifndef SDBUSPP_NEW_CAMELCASE
18#define vlan vLAN
19#endif
20
Ratan Gupta05eb1092017-04-14 16:33:53 +053021namespace phosphor
22{
23namespace network
24{
25
Ratan Gupta2b106532017-07-25 16:05:02 +053026using SystemConfPtr = std::unique_ptr<SystemConfiguration>;
27using DHCPConfPtr = std::unique_ptr<dhcp::Configuration>;
28
Manojkiran Edaa879baa2020-06-13 14:39:08 +053029namespace fs = std::filesystem;
Ratan Gupta05eb1092017-04-14 16:33:53 +053030namespace details
31{
32
Michael Tritz29f2fd62017-05-22 15:27:26 -050033template <typename T, typename U>
34using ServerObject = typename sdbusplus::server::object::object<T, U>;
Ratan Gupta05eb1092017-04-14 16:33:53 +053035
Michael Tritz29f2fd62017-05-22 15:27:26 -050036using VLANCreateIface = details::ServerObject<
37 sdbusplus::xyz::openbmc_project::Network::VLAN::server::Create,
38 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
Ratan Gupta05eb1092017-04-14 16:33:53 +053039
Ratan Gupta05eb1092017-04-14 16:33:53 +053040} // namespace details
41
42/** @class Manager
43 * @brief OpenBMC network manager implementation.
44 */
45class Manager : public details::VLANCreateIface
46{
Gunnar Mills57d9c502018-09-14 14:42:34 -050047 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;
Ratan Gupta05eb1092017-04-14 16:33:53 +053054
Gunnar Mills57d9c502018-09-14 14:42:34 -050055 /** @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.
58 * @param[in] dir - Network Configuration directory path.
59 */
60 Manager(sdbusplus::bus::bus& bus, const char* objPath,
61 const std::string& dir);
Ratan Gupta05eb1092017-04-14 16:33:53 +053062
Patrick Williams8173e022021-05-01 06:39:41 -050063 ObjectPath vlan(IntfName interfaceName, uint32_t id) override;
Ratan Gupta05eb1092017-04-14 16:33:53 +053064
Gunnar Mills57d9c502018-09-14 14:42:34 -050065 /** @brief write the network conf file with the in-memory objects.
66 */
67 void writeToConfigurationFile();
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053068
Gunnar Mills57d9c502018-09-14 14:42:34 -050069 /** @brief Fetch the interface and the ipaddress details
70 * from the system and create the ethernet interraces
71 * dbus object.
72 */
Manojkiran Edaacd6dd52019-10-15 15:00:51 +053073 virtual void createInterfaces();
Ratan Gupta29b0e432017-05-25 12:51:40 +053074
Gunnar Mills57d9c502018-09-14 14:42:34 -050075 /** @brief create child interface object and the system conf object.
76 */
77 void createChildObjects();
Ratan Guptaef85eb92017-06-15 08:57:54 +053078
Gunnar Mills57d9c502018-09-14 14:42:34 -050079 /** @brief sets the network conf directory.
80 * @param[in] dirName - Absolute path of the directory.
81 */
82 void setConfDir(const fs::path& dir);
Ratan Guptaef85eb92017-06-15 08:57:54 +053083
Gunnar Mills57d9c502018-09-14 14:42:34 -050084 /** @brief gets the network conf directory.
85 */
86 fs::path getConfDir()
87 {
88 return confDir;
89 }
Ratan Gupta255d5142017-08-10 09:02:08 +053090
Gunnar Mills57d9c502018-09-14 14:42:34 -050091 /** @brief gets the system conf object.
92 *
93 */
94 const SystemConfPtr& getSystemConf()
95 {
96 return systemConf;
97 }
Ratan Gupta05eb1092017-04-14 16:33:53 +053098
Gunnar Mills57d9c502018-09-14 14:42:34 -050099 /** @brief gets the dhcp conf object.
100 *
101 */
102 const DHCPConfPtr& getDHCPConf()
103 {
104 return dhcpConf;
105 }
Ratan Gupta2b106532017-07-25 16:05:02 +0530106
Gunnar Mills57d9c502018-09-14 14:42:34 -0500107 /** @brief create the default network files for each interface
108 * @detail if force param is true then forcefully create the network
109 * files otherwise if network file doesn't exist then
110 * create it.
111 * @param[in] force - forcefully create the file
112 * @return true if network file created else false
113 */
114 bool createDefaultNetworkFiles(bool force);
Ratan Gupta70c7e5b2017-07-12 11:41:55 +0530115
Gunnar Mills57d9c502018-09-14 14:42:34 -0500116 /** @brief restart the network timers. */
117 void restartTimers();
Ratan Guptae05083a2017-09-16 07:12:11 +0530118
Manojkiran Edacc099a82020-05-11 14:25:16 +0530119 /** @brief This function gets the MAC address from the VPD and
120 * sets it on the corresponding ethernet interface during first
121 * Boot, once it sets the MAC from VPD, it creates a file named
122 * firstBoot under /var/lib to make sure we dont run this function
123 * again.
124 *
125 * @param[in] ethPair - Its a pair of ethernet interface name & the
126 * corresponding MAC Address from the VPD
127 *
128 * return - NULL
129 */
130 void setFistBootMACOnInterface(
131 const std::pair<std::string, std::string>& ethPair);
132
Ratan Gupta895f9e52018-11-26 20:57:34 +0530133 /** @brief Restart the systemd unit
134 * @param[in] unit - systemd unit name which needs to be
135 * restarted.
136 */
Ratan Gupta35297172018-11-28 18:40:16 +0530137 virtual void restartSystemdUnit(const std::string& unit);
Ratan Gupta895f9e52018-11-26 20:57:34 +0530138
Patrick Ventured94d23e2019-01-07 13:05:23 -0800139 /** @brief Returns the number of interfaces under this manager.
140 *
141 * @return the number of interfaces managed by this manager.
142 */
143 int getInterfaceCount()
144 {
145 return interfaces.size();
146 }
147
148 /** @brief Does the requested interface exist under this manager?
149 *
150 * @param[in] intf - the interface name to check.
151 * @return true if found, false otherwise.
152 */
153 bool hasInterface(const std::string& intf)
154 {
155 return (interfaces.find(intf) != interfaces.end());
156 }
157
Ratan Gupta35297172018-11-28 18:40:16 +0530158 protected:
Gunnar Mills57d9c502018-09-14 14:42:34 -0500159 /** @brief Persistent sdbusplus DBus bus connection. */
160 sdbusplus::bus::bus& bus;
Ratan Gupta29b0e432017-05-25 12:51:40 +0530161
Gunnar Mills57d9c502018-09-14 14:42:34 -0500162 /** @brief Persistent map of EthernetInterface dbus objects and their names
163 */
164 std::map<IntfName, std::shared_ptr<EthernetInterface>> interfaces;
Ratan Gupta05eb1092017-04-14 16:33:53 +0530165
Gunnar Mills57d9c502018-09-14 14:42:34 -0500166 /** @brief BMC network reset - resets network configuration for BMC. */
167 void reset() override;
Michael Tritz29f2fd62017-05-22 15:27:26 -0500168
Gunnar Mills57d9c502018-09-14 14:42:34 -0500169 /** @brief Path of Object. */
170 std::string objectPath;
Ratan Gupta29b0e432017-05-25 12:51:40 +0530171
Gunnar Mills57d9c502018-09-14 14:42:34 -0500172 /** @brief pointer to system conf object. */
173 SystemConfPtr systemConf = nullptr;
Ratan Guptaef85eb92017-06-15 08:57:54 +0530174
Gunnar Mills57d9c502018-09-14 14:42:34 -0500175 /** @brief pointer to dhcp conf object. */
176 DHCPConfPtr dhcpConf = nullptr;
Ratan Guptad16f88c2017-07-11 17:47:57 +0530177
Gunnar Mills57d9c502018-09-14 14:42:34 -0500178 /** @brief Network Configuration directory. */
179 fs::path confDir;
Ratan Gupta05eb1092017-04-14 16:33:53 +0530180};
181
182} // namespace network
183} // namespace phosphor