blob: 23eaacb93c284b5cd71f85b93a8430ba7b802d8b [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
Gunnar Mills57d9c502018-09-14 14:42:34 -0500118 private:
119 /** @brief Persistent sdbusplus DBus bus connection. */
120 sdbusplus::bus::bus& bus;
Ratan Gupta29b0e432017-05-25 12:51:40 +0530121
Gunnar Mills57d9c502018-09-14 14:42:34 -0500122 /** @brief Persistent map of EthernetInterface dbus objects and their names
123 */
124 std::map<IntfName, std::shared_ptr<EthernetInterface>> interfaces;
Ratan Gupta05eb1092017-04-14 16:33:53 +0530125
Gunnar Mills57d9c502018-09-14 14:42:34 -0500126 /** @brief BMC network reset - resets network configuration for BMC. */
127 void reset() override;
Michael Tritz29f2fd62017-05-22 15:27:26 -0500128
Gunnar Mills57d9c502018-09-14 14:42:34 -0500129 /** @brief Path of Object. */
130 std::string objectPath;
Ratan Gupta29b0e432017-05-25 12:51:40 +0530131
Gunnar Mills57d9c502018-09-14 14:42:34 -0500132 /** @brief pointer to system conf object. */
133 SystemConfPtr systemConf = nullptr;
Ratan Guptaef85eb92017-06-15 08:57:54 +0530134
Gunnar Mills57d9c502018-09-14 14:42:34 -0500135 /** @brief pointer to dhcp conf object. */
136 DHCPConfPtr dhcpConf = nullptr;
Ratan Guptad16f88c2017-07-11 17:47:57 +0530137
Gunnar Mills57d9c502018-09-14 14:42:34 -0500138 /** @brief Network Configuration directory. */
139 fs::path confDir;
Ratan Guptaef85eb92017-06-15 08:57:54 +0530140
Gunnar Mills57d9c502018-09-14 14:42:34 -0500141 friend class TestNetworkManager;
142 friend class TestRtNetlink;
Ratan Gupta05eb1092017-04-14 16:33:53 +0530143};
144
145} // namespace network
146} // namespace phosphor