Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 3 | #include "dhcp_configuration.hpp" |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 4 | #include "ethernet_interface.hpp" |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 5 | #include "system_configuration.hpp" |
Ratan Gupta | 5978dd1 | 2017-07-25 13:47:13 +0530 | [diff] [blame] | 6 | #include "vlan_interface.hpp" |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 7 | #include "xyz/openbmc_project/Network/VLAN/Create/server.hpp" |
Ratan Gupta | 5978dd1 | 2017-07-25 13:47:13 +0530 | [diff] [blame] | 8 | |
Manojkiran Eda | a879baa | 2020-06-13 14:39:08 +0530 | [diff] [blame] | 9 | #include <filesystem> |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 10 | #include <list> |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 11 | #include <memory> |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 12 | #include <sdbusplus/bus.hpp> |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 13 | #include <string> |
| 14 | #include <vector> |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 15 | #include <xyz/openbmc_project/Common/FactoryReset/server.hpp> |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 16 | |
| 17 | namespace phosphor |
| 18 | { |
| 19 | namespace network |
| 20 | { |
| 21 | |
Ratan Gupta | 2b10653 | 2017-07-25 16:05:02 +0530 | [diff] [blame] | 22 | using SystemConfPtr = std::unique_ptr<SystemConfiguration>; |
| 23 | using DHCPConfPtr = std::unique_ptr<dhcp::Configuration>; |
| 24 | |
Manojkiran Eda | a879baa | 2020-06-13 14:39:08 +0530 | [diff] [blame] | 25 | namespace fs = std::filesystem; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 26 | namespace details |
| 27 | { |
| 28 | |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 29 | template <typename T, typename U> |
| 30 | using ServerObject = typename sdbusplus::server::object::object<T, U>; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 31 | |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 32 | using VLANCreateIface = details::ServerObject< |
| 33 | sdbusplus::xyz::openbmc_project::Network::VLAN::server::Create, |
| 34 | sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 35 | |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 36 | } // namespace details |
| 37 | |
| 38 | /** @class Manager |
| 39 | * @brief OpenBMC network manager implementation. |
| 40 | */ |
| 41 | class Manager : public details::VLANCreateIface |
| 42 | { |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 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; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 50 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 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. |
| 54 | * @param[in] dir - Network Configuration directory path. |
| 55 | */ |
| 56 | Manager(sdbusplus::bus::bus& bus, const char* objPath, |
| 57 | const std::string& dir); |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 58 | |
William A. Kennington III | f4b4ff8 | 2019-04-09 19:06:52 -0700 | [diff] [blame] | 59 | ObjectPath vLAN(IntfName interfaceName, uint32_t id) override; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 60 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 61 | /** @brief write the network conf file with the in-memory objects. |
| 62 | */ |
| 63 | void writeToConfigurationFile(); |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 64 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 65 | /** @brief Fetch the interface and the ipaddress details |
| 66 | * from the system and create the ethernet interraces |
| 67 | * dbus object. |
| 68 | */ |
Manojkiran Eda | acd6dd5 | 2019-10-15 15:00:51 +0530 | [diff] [blame] | 69 | virtual void createInterfaces(); |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 70 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 71 | /** @brief create child interface object and the system conf object. |
| 72 | */ |
| 73 | void createChildObjects(); |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 74 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 75 | /** @brief sets the network conf directory. |
| 76 | * @param[in] dirName - Absolute path of the directory. |
| 77 | */ |
| 78 | void setConfDir(const fs::path& dir); |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 79 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 80 | /** @brief gets the network conf directory. |
| 81 | */ |
| 82 | fs::path getConfDir() |
| 83 | { |
| 84 | return confDir; |
| 85 | } |
Ratan Gupta | 255d514 | 2017-08-10 09:02:08 +0530 | [diff] [blame] | 86 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 87 | /** @brief gets the system conf object. |
| 88 | * |
| 89 | */ |
| 90 | const SystemConfPtr& getSystemConf() |
| 91 | { |
| 92 | return systemConf; |
| 93 | } |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 94 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 95 | /** @brief gets the dhcp conf object. |
| 96 | * |
| 97 | */ |
| 98 | const DHCPConfPtr& getDHCPConf() |
| 99 | { |
| 100 | return dhcpConf; |
| 101 | } |
Ratan Gupta | 2b10653 | 2017-07-25 16:05:02 +0530 | [diff] [blame] | 102 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 103 | /** @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 Gupta | 70c7e5b | 2017-07-12 11:41:55 +0530 | [diff] [blame] | 111 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 112 | /** @brief restart the network timers. */ |
| 113 | void restartTimers(); |
Ratan Gupta | e05083a | 2017-09-16 07:12:11 +0530 | [diff] [blame] | 114 | |
Manojkiran Eda | cc099a8 | 2020-05-11 14:25:16 +0530 | [diff] [blame] | 115 | /** @brief This function gets the MAC address from the VPD and |
| 116 | * sets it on the corresponding ethernet interface during first |
| 117 | * Boot, once it sets the MAC from VPD, it creates a file named |
| 118 | * firstBoot under /var/lib to make sure we dont run this function |
| 119 | * again. |
| 120 | * |
| 121 | * @param[in] ethPair - Its a pair of ethernet interface name & the |
| 122 | * corresponding MAC Address from the VPD |
| 123 | * |
| 124 | * return - NULL |
| 125 | */ |
| 126 | void setFistBootMACOnInterface( |
| 127 | const std::pair<std::string, std::string>& ethPair); |
| 128 | |
Ratan Gupta | 895f9e5 | 2018-11-26 20:57:34 +0530 | [diff] [blame] | 129 | /** @brief Restart the systemd unit |
| 130 | * @param[in] unit - systemd unit name which needs to be |
| 131 | * restarted. |
| 132 | */ |
Ratan Gupta | 3529717 | 2018-11-28 18:40:16 +0530 | [diff] [blame] | 133 | virtual void restartSystemdUnit(const std::string& unit); |
Ratan Gupta | 895f9e5 | 2018-11-26 20:57:34 +0530 | [diff] [blame] | 134 | |
Patrick Venture | d94d23e | 2019-01-07 13:05:23 -0800 | [diff] [blame] | 135 | /** @brief Returns the number of interfaces under this manager. |
| 136 | * |
| 137 | * @return the number of interfaces managed by this manager. |
| 138 | */ |
| 139 | int getInterfaceCount() |
| 140 | { |
| 141 | return interfaces.size(); |
| 142 | } |
| 143 | |
| 144 | /** @brief Does the requested interface exist under this manager? |
| 145 | * |
| 146 | * @param[in] intf - the interface name to check. |
| 147 | * @return true if found, false otherwise. |
| 148 | */ |
| 149 | bool hasInterface(const std::string& intf) |
| 150 | { |
| 151 | return (interfaces.find(intf) != interfaces.end()); |
| 152 | } |
| 153 | |
Ratan Gupta | 3529717 | 2018-11-28 18:40:16 +0530 | [diff] [blame] | 154 | protected: |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 155 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 156 | sdbusplus::bus::bus& bus; |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 157 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 158 | /** @brief Persistent map of EthernetInterface dbus objects and their names |
| 159 | */ |
| 160 | std::map<IntfName, std::shared_ptr<EthernetInterface>> interfaces; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 161 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 162 | /** @brief BMC network reset - resets network configuration for BMC. */ |
| 163 | void reset() override; |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 164 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 165 | /** @brief Path of Object. */ |
| 166 | std::string objectPath; |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 167 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 168 | /** @brief pointer to system conf object. */ |
| 169 | SystemConfPtr systemConf = nullptr; |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 170 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 171 | /** @brief pointer to dhcp conf object. */ |
| 172 | DHCPConfPtr dhcpConf = nullptr; |
Ratan Gupta | d16f88c | 2017-07-11 17:47:57 +0530 | [diff] [blame] | 173 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 174 | /** @brief Network Configuration directory. */ |
| 175 | fs::path confDir; |
Ratan Gupta | 05eb109 | 2017-04-14 16:33:53 +0530 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | } // namespace network |
| 179 | } // namespace phosphor |