blob: 7685ba81a54866fd3d729b24c0866a3edd7d0882 [file] [log] [blame]
Ratan Gupta05eb1092017-04-14 16:33:53 +05301#pragma once
2
3#include "ethernet_interface.hpp"
Ratan Guptaef85eb92017-06-15 08:57:54 +05304#include "system_configuration.hpp"
Ratan Guptad16f88c2017-07-11 17:47:57 +05305#include "dhcp_configuration.hpp"
Ratan Gupta5978dd12017-07-25 13:47:13 +05306#include "vlan_interface.hpp"
7
Ratan Guptad16f88c2017-07-11 17:47:57 +05308#include <xyz/openbmc_project/Network/VLAN/Create/server.hpp>
Michael Tritz29f2fd62017-05-22 15:27:26 -05009#include <xyz/openbmc_project/Common/FactoryReset/server.hpp>
Ratan Gupta05eb1092017-04-14 16:33:53 +053010#include <sdbusplus/bus.hpp>
11
12#include <list>
Ratan Gupta6811f822017-04-14 16:34:56 +053013#include <memory>
Ratan Gupta05eb1092017-04-14 16:33:53 +053014#include <string>
15#include <vector>
Ratan Guptaef85eb92017-06-15 08:57:54 +053016#include <experimental/filesystem>
Ratan Gupta05eb1092017-04-14 16:33:53 +053017
18namespace phosphor
19{
20namespace network
21{
22
Ratan Gupta2b106532017-07-25 16:05:02 +053023using SystemConfPtr = std::unique_ptr<SystemConfiguration>;
24using DHCPConfPtr = std::unique_ptr<dhcp::Configuration>;
25
Ratan Guptaef85eb92017-06-15 08:57:54 +053026namespace fs = std::experimental::filesystem;
Ratan Gupta05eb1092017-04-14 16:33:53 +053027namespace details
28{
29
Michael Tritz29f2fd62017-05-22 15:27:26 -050030template <typename T, typename U>
31using ServerObject = typename sdbusplus::server::object::object<T, U>;
Ratan Gupta05eb1092017-04-14 16:33:53 +053032
Michael Tritz29f2fd62017-05-22 15:27:26 -050033using VLANCreateIface = details::ServerObject<
34 sdbusplus::xyz::openbmc_project::Network::VLAN::server::Create,
35 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
Ratan Gupta05eb1092017-04-14 16:33:53 +053036
Ratan Gupta05eb1092017-04-14 16:33:53 +053037} // namespace details
38
Ratan Gupta8ab17922017-05-25 13:07:05 +053039class TestNetworkManager; //forward declaration
40
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;
132
Ratan Gupta05eb1092017-04-14 16:33:53 +0530133};
134
135} // namespace network
136} // namespace phosphor