blob: ab5fbd140baf5a54e790e4a533d5b0e1249bba5c [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
Ratan Gupta8ab17922017-05-25 13:07:05 +053038class TestNetworkManager; //forward declaration
Nagaraju Goruganti067ca2d2018-01-17 01:12:00 -060039class 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{
46 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;
53
54 /** @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.
Ratan Gupta255d5142017-08-10 09:02:08 +053057 * @param[in] dir - Network Configuration directory path.
Ratan Gupta05eb1092017-04-14 16:33:53 +053058 */
Ratan Gupta255d5142017-08-10 09:02:08 +053059 Manager(sdbusplus::bus::bus& bus, const char* objPath,
60 const std::string& dir);
Ratan Gupta05eb1092017-04-14 16:33:53 +053061
Ratan Gupta584df832017-07-31 16:21:54 +053062 void vLAN(IntfName interfaceName, uint32_t id) override;
Ratan Gupta05eb1092017-04-14 16:33:53 +053063
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053064 /** @brief write the network conf file with the in-memory objects.
65 */
66 void writeToConfigurationFile();
67
Ratan Gupta29b0e432017-05-25 12:51:40 +053068 /** @brief Fetch the interface and the ipaddress details
69 * from the system and create the ethernet interraces
70 * dbus object.
71 */
72 void createInterfaces();
73
Ratan Guptaef85eb92017-06-15 08:57:54 +053074 /** @brief create child interface object and the system conf object.
Ratan Guptafc2c7242017-05-29 08:46:06 +053075 */
Ratan Guptaef85eb92017-06-15 08:57:54 +053076 void createChildObjects();
77
78 /** @brief sets the network conf directory.
79 * @param[in] dirName - Absolute path of the directory.
80 */
81 void setConfDir(const fs::path& dir);
82
Ratan Gupta255d5142017-08-10 09:02:08 +053083 /** @brief gets the network conf directory.
84 */
85 fs::path getConfDir() { return confDir; }
86
Ratan Gupta2b106532017-07-25 16:05:02 +053087 /** @brief gets the system conf object.
88 *
89 */
90 const SystemConfPtr& getSystemConf() { return systemConf; }
Ratan Gupta05eb1092017-04-14 16:33:53 +053091
Ratan Gupta2b106532017-07-25 16:05:02 +053092 /** @brief gets the dhcp conf object.
93 *
94 */
95 const DHCPConfPtr& getDHCPConf() { return dhcpConf; }
96
Ratan Guptab610caf2017-09-19 09:33:51 +053097 /** @brief create the default network files for each interface
98 * @detail if force param is true then forcefully create the network
99 * files otherwise if network file doesn't exist then
100 * create it.
101 * @param[in] force - forcefully create the file
102 * @return true if network file created else false
103 */
104 bool createDefaultNetworkFiles(bool force);
Ratan Gupta70c7e5b2017-07-12 11:41:55 +0530105
Ratan Gupta16f12882017-09-22 18:26:11 +0530106 /** @brief restart the network timers. */
107 void restartTimers();
Ratan Guptae05083a2017-09-16 07:12:11 +0530108
Ratan Guptab610caf2017-09-19 09:33:51 +0530109 private:
Ratan Gupta29b0e432017-05-25 12:51:40 +0530110 /** @brief Persistent sdbusplus DBus bus connection. */
111 sdbusplus::bus::bus& bus;
112
Ratan Gupta05eb1092017-04-14 16:33:53 +0530113 /** @brief Persistent map of EthernetInterface dbus objects and their names */
Ratan Gupta2b106532017-07-25 16:05:02 +0530114 std::map<IntfName, std::shared_ptr<EthernetInterface>> interfaces;
Ratan Gupta05eb1092017-04-14 16:33:53 +0530115
Michael Tritz29f2fd62017-05-22 15:27:26 -0500116 /** @brief BMC network reset - resets network configuration for BMC. */
117 void reset() override;
118
Ratan Gupta29b0e432017-05-25 12:51:40 +0530119 /** @brief Path of Object. */
120 std::string objectPath;
121
Ratan Guptaef85eb92017-06-15 08:57:54 +0530122 /** @brief pointer to system conf object. */
Ratan Gupta2b106532017-07-25 16:05:02 +0530123 SystemConfPtr systemConf = nullptr;
Ratan Guptaef85eb92017-06-15 08:57:54 +0530124
Ratan Guptad16f88c2017-07-11 17:47:57 +0530125 /** @brief pointer to dhcp conf object. */
Ratan Gupta2b106532017-07-25 16:05:02 +0530126 DHCPConfPtr dhcpConf = nullptr;
Ratan Guptad16f88c2017-07-11 17:47:57 +0530127
Ratan Guptaef85eb92017-06-15 08:57:54 +0530128 /** @brief Network Configuration directory. */
129 fs::path confDir;
130
Ratan Gupta8ab17922017-05-25 13:07:05 +0530131 friend class TestNetworkManager;
Nagaraju Goruganti067ca2d2018-01-17 01:12:00 -0600132 friend class TestRtNetlink;
Ratan Gupta8ab17922017-05-25 13:07:05 +0530133
Ratan Gupta05eb1092017-04-14 16:33:53 +0530134};
135
136} // namespace network
137} // namespace phosphor