blob: 805c2acfe17c0626c54c93cebbcdcead7ce47f99 [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 Gupta82549cc2017-04-21 08:45:23 +05308#include "xyz/openbmc_project/Network/IP/Create/server.hpp"
Ratan Gupta8c834932017-04-14 16:30:24 +05309
10#include <sdbusplus/bus.hpp>
11#include <sdbusplus/server/object.hpp>
12
13#include <string>
14
15namespace phosphor
16{
17namespace network
18{
Ratan Gupta8c834932017-04-14 16:30:24 +053019
Ratan Gupta82549cc2017-04-21 08:45:23 +053020using Ifaces =
21 sdbusplus::server::object::object<
22 sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface,
23 sdbusplus::xyz::openbmc_project::Network::IP::server::Create>;
Ratan Gupta8c834932017-04-14 16:30:24 +053024
Ratan Gupta82549cc2017-04-21 08:45:23 +053025using IP = sdbusplus::xyz::openbmc_project::Network::server::IP;
Ratan Gupta87c13982017-06-15 09:27:27 +053026
27using EthernetInterfaceIntf =
28 sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface;
29
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053030class Manager; // forward declaration of network manager.
Ratan Gupta8c834932017-04-14 16:30:24 +053031
Ratan Gupta47722dc2017-05-26 18:32:23 +053032class TestEthernetInterface;
33
Ratan Gupta8c834932017-04-14 16:30:24 +053034using LinkSpeed = uint16_t;
35using DuplexMode = uint8_t;
36using Autoneg = uint8_t;
37using InterfaceInfo = std::tuple<LinkSpeed, DuplexMode, Autoneg>;
Ratan Gupta29b0e432017-05-25 12:51:40 +053038using AddressMap = std::map<std::string, std::shared_ptr<IPAddress>>;
Ratan Gupta8c834932017-04-14 16:30:24 +053039
40/** @class EthernetInterface
41 * @brief OpenBMC Ethernet Interface implementation.
42 * @details A concrete implementation for the
43 * xyz.openbmc_project.Network.EthernetInterface DBus API.
44 */
Ratan Gupta82549cc2017-04-21 08:45:23 +053045class EthernetInterface : public Ifaces
Ratan Gupta8c834932017-04-14 16:30:24 +053046{
47 public:
48 EthernetInterface() = delete;
49 EthernetInterface(const EthernetInterface&) = delete;
50 EthernetInterface& operator=(const EthernetInterface&) = delete;
51 EthernetInterface(EthernetInterface&&) = delete;
52 EthernetInterface& operator=(EthernetInterface&&) = delete;
53 virtual ~EthernetInterface() = default;
54
55 /** @brief Constructor to put object onto bus at a dbus path.
56 * @param[in] bus - Bus to attach to.
57 * @param[in] objPath - Path to attach at.
Ratan Gupta8c834932017-04-14 16:30:24 +053058 * @param[in] dhcpEnabled - is dhcp enabled(true/false).
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053059 * @param[in] parent - parent object.
Ratan Gupta8c834932017-04-14 16:30:24 +053060 */
61 EthernetInterface(sdbusplus::bus::bus& bus,
Ratan Gupta91a99cc2017-04-14 16:32:09 +053062 const std::string& objPath,
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053063 bool dhcpEnabled,
64 Manager& parent);
Ratan Gupta82549cc2017-04-21 08:45:23 +053065
66 /** @brief Function to create ipaddress dbus object.
67 * @param[in] addressType - Type of ip address.
Ratan Gupta29b0e432017-05-25 12:51:40 +053068 * @param[in] ipaddress- IP address.
Ratan Gupta82549cc2017-04-21 08:45:23 +053069 * @param[in] prefixLength - Length of prefix.
70 * @param[in] gateway - Gateway ip address.
71 */
72
73 void iP(IP::Protocol addressType,
74 std::string ipaddress,
75 uint8_t prefixLength,
76 std::string gateway) override;
Ratan Gupta8c834932017-04-14 16:30:24 +053077
Ratan Gupta29b0e432017-05-25 12:51:40 +053078 /* @brief delete the dbus object of the given ipaddress.
79 * @param[in] ipaddress - IP address.
Ratan Gupta2eff84f2017-04-20 19:19:15 +053080 */
Ratan Gupta2eff84f2017-04-20 19:19:15 +053081 void deleteObject(const std::string& ipaddress);
Ratan Gupta8c834932017-04-14 16:30:24 +053082
Ratan Gupta87c13982017-06-15 09:27:27 +053083 /* @brief creates the dbus object(IPaddres) given in the address list.
Ratan Gupta29b0e432017-05-25 12:51:40 +053084 * @param[in] addrs - address list for which dbus objects needs
85 * to create.
86 */
Ratan Gupta87c13982017-06-15 09:27:27 +053087 void createIPAddressObjects();
Ratan Gupta29b0e432017-05-25 12:51:40 +053088
89 /* @brief Gets all the ip addresses.
90 * @returns the list of ipaddress.
91 */
92 const AddressMap& getAddresses() const { return addrs; }
Ratan Gupta8c834932017-04-14 16:30:24 +053093
Ratan Gupta87c13982017-06-15 09:27:27 +053094 /** Set value of DHCPEnabled */
95 bool dHCPEnabled(bool value) override;
96
97 using EthernetInterfaceIntf::dHCPEnabled;
98
Ratan Gupta8c834932017-04-14 16:30:24 +053099 private:
100
101 /** @brief get the info of the ethernet interface.
102 * @return tuple having the link speed,autonegotiation,duplexmode .
103 */
104
105 InterfaceInfo getInterfaceInfo() const;
106
107 /** @brief get the mac address of the interface.
108 * @return macaddress on success
109 */
110
111 std::string getMACAddress() const;
112
Ratan Gupta82549cc2017-04-21 08:45:23 +0530113 /** @brief construct the ip address dbus object path.
114 * @param[in] addressType - Type of ip address.
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530115 * @param[in] ipaddress - IP address.
116 * @param[in] prefixLength - Length of prefix.
117 * @param[in] gateway - Gateway addess.
118
Ratan Gupta82549cc2017-04-21 08:45:23 +0530119 * @return path of the address object.
120 */
121
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530122 std::string generateObjectPath(IP::Protocol addressType,
123 const std::string& ipaddress,
124 uint8_t prefixLength,
125 const std::string& gateway) const;
Ratan Gupta82549cc2017-04-21 08:45:23 +0530126
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530127 /** @brief generates the id by doing hash of ipaddress,
128 * prefixlength and the gateway.
129 * @param[in] ipaddress - IP address.
130 * @param[in] prefixLength - Length of prefix.
131 * @param[in] gateway - Gateway addess.
132 * @return hash string.
Ratan Gupta82549cc2017-04-21 08:45:23 +0530133 */
134
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530135 static std::string generateId(const std::string& ipaddress,
136 uint8_t prefixLength,
137 const std::string& gateway);
Ratan Gupta82549cc2017-04-21 08:45:23 +0530138
139 /** @brief Persistent sdbusplus DBus bus connection. */
140 sdbusplus::bus::bus& bus;
141
Ratan Gupta4f1c18b2017-05-25 12:59:35 +0530142 /** @brief Network Manager object. */
143 Manager& manager;
144
Ratan Gupta82549cc2017-04-21 08:45:23 +0530145 /** @brief Persistent map of IPAddress dbus objects and their names */
Ratan Gupta29b0e432017-05-25 12:51:40 +0530146 AddressMap addrs;
Ratan Gupta82549cc2017-04-21 08:45:23 +0530147
Ratan Gupta47722dc2017-05-26 18:32:23 +0530148 /** @brief Dbus object path */
149 std::string objPath;
150
151 friend class TestEthernetInterface;
Ratan Gupta8c834932017-04-14 16:30:24 +0530152};
153
154} // namespace network
155} // namespace phosphor