blob: 313a0b9b40e8b1aca3b2148bcef3c6ac6821f52d [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 Gupta4f1c18b2017-05-25 12:59:35 +053026class Manager; // forward declaration of network manager.
Ratan Gupta8c834932017-04-14 16:30:24 +053027
Ratan Gupta47722dc2017-05-26 18:32:23 +053028class TestEthernetInterface;
29
Ratan Gupta8c834932017-04-14 16:30:24 +053030using LinkSpeed = uint16_t;
31using DuplexMode = uint8_t;
32using Autoneg = uint8_t;
33using InterfaceInfo = std::tuple<LinkSpeed, DuplexMode, Autoneg>;
Ratan Gupta29b0e432017-05-25 12:51:40 +053034using AddressMap = std::map<std::string, std::shared_ptr<IPAddress>>;
Ratan Gupta8c834932017-04-14 16:30:24 +053035
36/** @class EthernetInterface
37 * @brief OpenBMC Ethernet Interface implementation.
38 * @details A concrete implementation for the
39 * xyz.openbmc_project.Network.EthernetInterface DBus API.
40 */
Ratan Gupta82549cc2017-04-21 08:45:23 +053041class EthernetInterface : public Ifaces
Ratan Gupta8c834932017-04-14 16:30:24 +053042{
43 public:
44 EthernetInterface() = delete;
45 EthernetInterface(const EthernetInterface&) = delete;
46 EthernetInterface& operator=(const EthernetInterface&) = delete;
47 EthernetInterface(EthernetInterface&&) = delete;
48 EthernetInterface& operator=(EthernetInterface&&) = delete;
49 virtual ~EthernetInterface() = default;
50
51 /** @brief Constructor to put object onto bus at a dbus path.
52 * @param[in] bus - Bus to attach to.
53 * @param[in] objPath - Path to attach at.
Ratan Gupta8c834932017-04-14 16:30:24 +053054 * @param[in] dhcpEnabled - is dhcp enabled(true/false).
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053055 * @param[in] parent - parent object.
Ratan Gupta8c834932017-04-14 16:30:24 +053056 */
57 EthernetInterface(sdbusplus::bus::bus& bus,
Ratan Gupta91a99cc2017-04-14 16:32:09 +053058 const std::string& objPath,
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053059 bool dhcpEnabled,
60 Manager& parent);
Ratan Gupta82549cc2017-04-21 08:45:23 +053061
62 /** @brief Function to create ipaddress dbus object.
63 * @param[in] addressType - Type of ip address.
Ratan Gupta29b0e432017-05-25 12:51:40 +053064 * @param[in] ipaddress- IP address.
Ratan Gupta82549cc2017-04-21 08:45:23 +053065 * @param[in] prefixLength - Length of prefix.
66 * @param[in] gateway - Gateway ip address.
67 */
68
69 void iP(IP::Protocol addressType,
70 std::string ipaddress,
71 uint8_t prefixLength,
72 std::string gateway) override;
Ratan Gupta8c834932017-04-14 16:30:24 +053073
Ratan Gupta29b0e432017-05-25 12:51:40 +053074 /* @brief delete the dbus object of the given ipaddress.
75 * @param[in] ipaddress - IP address.
Ratan Gupta2eff84f2017-04-20 19:19:15 +053076 */
Ratan Gupta2eff84f2017-04-20 19:19:15 +053077 void deleteObject(const std::string& ipaddress);
Ratan Gupta8c834932017-04-14 16:30:24 +053078
Ratan Gupta29b0e432017-05-25 12:51:40 +053079 /* @brief creates the dbus object given in the address list.
80 * @param[in] addrs - address list for which dbus objects needs
81 * to create.
82 */
83 void setAddressList(const AddrList& addrs);
84
85 /* @brief Gets all the ip addresses.
86 * @returns the list of ipaddress.
87 */
88 const AddressMap& getAddresses() const { return addrs; }
Ratan Gupta8c834932017-04-14 16:30:24 +053089
90 private:
91
92 /** @brief get the info of the ethernet interface.
93 * @return tuple having the link speed,autonegotiation,duplexmode .
94 */
95
96 InterfaceInfo getInterfaceInfo() const;
97
98 /** @brief get the mac address of the interface.
99 * @return macaddress on success
100 */
101
102 std::string getMACAddress() const;
103
Ratan Gupta82549cc2017-04-21 08:45:23 +0530104 /** @brief construct the ip address dbus object path.
105 * @param[in] addressType - Type of ip address.
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530106 * @param[in] ipaddress - IP address.
107 * @param[in] prefixLength - Length of prefix.
108 * @param[in] gateway - Gateway addess.
109
Ratan Gupta82549cc2017-04-21 08:45:23 +0530110 * @return path of the address object.
111 */
112
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530113 std::string generateObjectPath(IP::Protocol addressType,
114 const std::string& ipaddress,
115 uint8_t prefixLength,
116 const std::string& gateway) const;
Ratan Gupta82549cc2017-04-21 08:45:23 +0530117
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530118 /** @brief generates the id by doing hash of ipaddress,
119 * prefixlength and the gateway.
120 * @param[in] ipaddress - IP address.
121 * @param[in] prefixLength - Length of prefix.
122 * @param[in] gateway - Gateway addess.
123 * @return hash string.
Ratan Gupta82549cc2017-04-21 08:45:23 +0530124 */
125
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530126 static std::string generateId(const std::string& ipaddress,
127 uint8_t prefixLength,
128 const std::string& gateway);
Ratan Gupta82549cc2017-04-21 08:45:23 +0530129
130 /** @brief Persistent sdbusplus DBus bus connection. */
131 sdbusplus::bus::bus& bus;
132
Ratan Gupta4f1c18b2017-05-25 12:59:35 +0530133 /** @brief Network Manager object. */
134 Manager& manager;
135
Ratan Gupta82549cc2017-04-21 08:45:23 +0530136 /** @brief Persistent map of IPAddress dbus objects and their names */
Ratan Gupta29b0e432017-05-25 12:51:40 +0530137 AddressMap addrs;
Ratan Gupta82549cc2017-04-21 08:45:23 +0530138
Ratan Gupta47722dc2017-05-26 18:32:23 +0530139 /** @brief Dbus object path */
140 std::string objPath;
141
142 friend class TestEthernetInterface;
Ratan Gupta8c834932017-04-14 16:30:24 +0530143};
144
145} // namespace network
146} // namespace phosphor