blob: 88cbf1eee1968562e08fc37471c42db84bbfe771 [file] [log] [blame]
Ratan Gupta8c834932017-04-14 16:30:24 +05301#pragma once
2
Ratan Gupta82549cc2017-04-21 08:45:23 +05303#include "ipaddress.hpp"
4#include "types.hpp"
Ratan Gupta8804feb2017-05-25 10:49:57 +05305#include "util.hpp"
Ratan Gupta82549cc2017-04-21 08:45:23 +05306
Ratan Gupta8c834932017-04-14 16:30:24 +05307#include "xyz/openbmc_project/Network/EthernetInterface/server.hpp"
Ratan Gupta1caa2302017-07-10 10:30:13 +05308#include "xyz/openbmc_project/Network/MACAddress/server.hpp"
Ratan Gupta82549cc2017-04-21 08:45:23 +05309#include "xyz/openbmc_project/Network/IP/Create/server.hpp"
Ratan Gupta8c834932017-04-14 16:30:24 +053010
11#include <sdbusplus/bus.hpp>
12#include <sdbusplus/server/object.hpp>
13
14#include <string>
15
16namespace phosphor
17{
18namespace network
19{
Ratan Gupta8c834932017-04-14 16:30:24 +053020
Ratan Gupta82549cc2017-04-21 08:45:23 +053021using Ifaces =
22 sdbusplus::server::object::object<
23 sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface,
Ratan Gupta1caa2302017-07-10 10:30:13 +053024 sdbusplus::xyz::openbmc_project::Network::server::MACAddress,
Ratan Gupta82549cc2017-04-21 08:45:23 +053025 sdbusplus::xyz::openbmc_project::Network::IP::server::Create>;
Ratan Gupta8c834932017-04-14 16:30:24 +053026
Ratan Gupta82549cc2017-04-21 08:45:23 +053027using IP = sdbusplus::xyz::openbmc_project::Network::server::IP;
Ratan Gupta87c13982017-06-15 09:27:27 +053028
29using EthernetInterfaceIntf =
30 sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface;
31
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053032class Manager; // forward declaration of network manager.
Ratan Gupta8c834932017-04-14 16:30:24 +053033
Ratan Gupta47722dc2017-05-26 18:32:23 +053034class TestEthernetInterface;
35
Ratan Gupta8c834932017-04-14 16:30:24 +053036using LinkSpeed = uint16_t;
37using DuplexMode = uint8_t;
38using Autoneg = uint8_t;
39using InterfaceInfo = std::tuple<LinkSpeed, DuplexMode, Autoneg>;
Ratan Gupta29b0e432017-05-25 12:51:40 +053040using AddressMap = std::map<std::string, std::shared_ptr<IPAddress>>;
Ratan Gupta8c834932017-04-14 16:30:24 +053041
42/** @class EthernetInterface
43 * @brief OpenBMC Ethernet Interface implementation.
44 * @details A concrete implementation for the
45 * xyz.openbmc_project.Network.EthernetInterface DBus API.
46 */
Ratan Gupta82549cc2017-04-21 08:45:23 +053047class EthernetInterface : public Ifaces
Ratan Gupta8c834932017-04-14 16:30:24 +053048{
49 public:
50 EthernetInterface() = delete;
51 EthernetInterface(const EthernetInterface&) = delete;
52 EthernetInterface& operator=(const EthernetInterface&) = delete;
53 EthernetInterface(EthernetInterface&&) = delete;
54 EthernetInterface& operator=(EthernetInterface&&) = delete;
55 virtual ~EthernetInterface() = default;
56
57 /** @brief Constructor to put object onto bus at a dbus path.
58 * @param[in] bus - Bus to attach to.
59 * @param[in] objPath - Path to attach at.
Ratan Gupta8c834932017-04-14 16:30:24 +053060 * @param[in] dhcpEnabled - is dhcp enabled(true/false).
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053061 * @param[in] parent - parent object.
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053062 * @param[in] emitSignal - true if the object added signal needs to be
63 * send.
Ratan Gupta8c834932017-04-14 16:30:24 +053064 */
65 EthernetInterface(sdbusplus::bus::bus& bus,
Ratan Gupta91a99cc2017-04-14 16:32:09 +053066 const std::string& objPath,
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053067 bool dhcpEnabled,
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +053068 Manager& parent,
69 bool emitSignal = true);
Ratan Gupta82549cc2017-04-21 08:45:23 +053070
71 /** @brief Function to create ipaddress dbus object.
72 * @param[in] addressType - Type of ip address.
Ratan Gupta29b0e432017-05-25 12:51:40 +053073 * @param[in] ipaddress- IP address.
Ratan Gupta82549cc2017-04-21 08:45:23 +053074 * @param[in] prefixLength - Length of prefix.
75 * @param[in] gateway - Gateway ip address.
76 */
77
78 void iP(IP::Protocol addressType,
79 std::string ipaddress,
80 uint8_t prefixLength,
81 std::string gateway) override;
Ratan Gupta8c834932017-04-14 16:30:24 +053082
Ratan Gupta29b0e432017-05-25 12:51:40 +053083 /* @brief delete the dbus object of the given ipaddress.
84 * @param[in] ipaddress - IP address.
Ratan Gupta2eff84f2017-04-20 19:19:15 +053085 */
Ratan Gupta2eff84f2017-04-20 19:19:15 +053086 void deleteObject(const std::string& ipaddress);
Ratan Gupta8c834932017-04-14 16:30:24 +053087
Ratan Gupta87c13982017-06-15 09:27:27 +053088 /* @brief creates the dbus object(IPaddres) given in the address list.
Ratan Gupta29b0e432017-05-25 12:51:40 +053089 * @param[in] addrs - address list for which dbus objects needs
90 * to create.
91 */
Ratan Gupta87c13982017-06-15 09:27:27 +053092 void createIPAddressObjects();
Ratan Gupta29b0e432017-05-25 12:51:40 +053093
94 /* @brief Gets all the ip addresses.
95 * @returns the list of ipaddress.
96 */
97 const AddressMap& getAddresses() const { return addrs; }
Ratan Gupta8c834932017-04-14 16:30:24 +053098
Ratan Gupta87c13982017-06-15 09:27:27 +053099 /** Set value of DHCPEnabled */
100 bool dHCPEnabled(bool value) override;
101
102 using EthernetInterfaceIntf::dHCPEnabled;
103
Ratan Gupta3d3e4fc2017-07-25 13:38:19 +0530104 protected:
Ratan Gupta8c834932017-04-14 16:30:24 +0530105
106 /** @brief get the info of the ethernet interface.
107 * @return tuple having the link speed,autonegotiation,duplexmode .
108 */
109
110 InterfaceInfo getInterfaceInfo() const;
111
112 /** @brief get the mac address of the interface.
113 * @return macaddress on success
114 */
115
116 std::string getMACAddress() const;
117
Ratan Gupta82549cc2017-04-21 08:45:23 +0530118 /** @brief construct the ip address dbus object path.
119 * @param[in] addressType - Type of ip address.
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530120 * @param[in] ipaddress - IP address.
121 * @param[in] prefixLength - Length of prefix.
122 * @param[in] gateway - Gateway addess.
123
Ratan Gupta82549cc2017-04-21 08:45:23 +0530124 * @return path of the address object.
125 */
126
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530127 std::string generateObjectPath(IP::Protocol addressType,
128 const std::string& ipaddress,
129 uint8_t prefixLength,
130 const std::string& gateway) const;
Ratan Gupta82549cc2017-04-21 08:45:23 +0530131
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530132 /** @brief generates the id by doing hash of ipaddress,
133 * prefixlength and the gateway.
134 * @param[in] ipaddress - IP address.
135 * @param[in] prefixLength - Length of prefix.
136 * @param[in] gateway - Gateway addess.
137 * @return hash string.
Ratan Gupta82549cc2017-04-21 08:45:23 +0530138 */
139
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530140 static std::string generateId(const std::string& ipaddress,
141 uint8_t prefixLength,
142 const std::string& gateway);
Ratan Gupta82549cc2017-04-21 08:45:23 +0530143
144 /** @brief Persistent sdbusplus DBus bus connection. */
145 sdbusplus::bus::bus& bus;
146
Ratan Gupta4f1c18b2017-05-25 12:59:35 +0530147 /** @brief Network Manager object. */
148 Manager& manager;
149
Ratan Gupta82549cc2017-04-21 08:45:23 +0530150 /** @brief Persistent map of IPAddress dbus objects and their names */
Ratan Gupta29b0e432017-05-25 12:51:40 +0530151 AddressMap addrs;
Ratan Gupta82549cc2017-04-21 08:45:23 +0530152
Ratan Gupta47722dc2017-05-26 18:32:23 +0530153 /** @brief Dbus object path */
154 std::string objPath;
155
156 friend class TestEthernetInterface;
Ratan Gupta8c834932017-04-14 16:30:24 +0530157};
158
159} // namespace network
160} // namespace phosphor