blob: f9bd895d19171c40ec0d2e70d21e7a7c7c3b3c75 [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"
5
Ratan Gupta8c834932017-04-14 16:30:24 +05306#include "xyz/openbmc_project/Network/EthernetInterface/server.hpp"
Ratan Gupta82549cc2017-04-21 08:45:23 +05307#include "xyz/openbmc_project/Network/IP/Create/server.hpp"
Ratan Gupta8c834932017-04-14 16:30:24 +05308
9#include <sdbusplus/bus.hpp>
10#include <sdbusplus/server/object.hpp>
11
12#include <string>
13
14namespace phosphor
15{
16namespace network
17{
Ratan Gupta8c834932017-04-14 16:30:24 +053018
Ratan Gupta82549cc2017-04-21 08:45:23 +053019using Ifaces =
20 sdbusplus::server::object::object<
21 sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface,
22 sdbusplus::xyz::openbmc_project::Network::IP::server::Create>;
Ratan Gupta8c834932017-04-14 16:30:24 +053023
Ratan Gupta82549cc2017-04-21 08:45:23 +053024using IP = sdbusplus::xyz::openbmc_project::Network::server::IP;
Ratan Gupta8c834932017-04-14 16:30:24 +053025
Ratan Gupta8c834932017-04-14 16:30:24 +053026
27using LinkSpeed = uint16_t;
28using DuplexMode = uint8_t;
29using Autoneg = uint8_t;
30using InterfaceInfo = std::tuple<LinkSpeed, DuplexMode, Autoneg>;
31
32
33/** @class EthernetInterface
34 * @brief OpenBMC Ethernet Interface implementation.
35 * @details A concrete implementation for the
36 * xyz.openbmc_project.Network.EthernetInterface DBus API.
37 */
Ratan Gupta82549cc2017-04-21 08:45:23 +053038class EthernetInterface : public Ifaces
Ratan Gupta8c834932017-04-14 16:30:24 +053039{
40 public:
41 EthernetInterface() = delete;
42 EthernetInterface(const EthernetInterface&) = delete;
43 EthernetInterface& operator=(const EthernetInterface&) = delete;
44 EthernetInterface(EthernetInterface&&) = delete;
45 EthernetInterface& operator=(EthernetInterface&&) = delete;
46 virtual ~EthernetInterface() = default;
47
48 /** @brief Constructor to put object onto bus at a dbus path.
49 * @param[in] bus - Bus to attach to.
50 * @param[in] objPath - Path to attach at.
51 * @param[in] intfName - name of the ethernet interface.
52 * @param[in] dhcpEnabled - is dhcp enabled(true/false).
53 */
54 EthernetInterface(sdbusplus::bus::bus& bus,
Ratan Gupta91a99cc2017-04-14 16:32:09 +053055 const std::string& objPath,
Ratan Gupta82549cc2017-04-21 08:45:23 +053056 bool dhcpEnabled,
57 const AddrList& addrs);
58
59 /** @brief Function to create ipaddress dbus object.
60 * @param[in] addressType - Type of ip address.
61 * @param[in] ipaddress- IP adress.
62 * @param[in] prefixLength - Length of prefix.
63 * @param[in] gateway - Gateway ip address.
64 */
65
66 void iP(IP::Protocol addressType,
67 std::string ipaddress,
68 uint8_t prefixLength,
69 std::string gateway) override;
Ratan Gupta8c834932017-04-14 16:30:24 +053070
Ratan Gupta2eff84f2017-04-20 19:19:15 +053071 /** @brief delete the dbus object of the given ipaddress.
72 */
73
74 void deleteObject(const std::string& ipaddress);
Ratan Gupta8c834932017-04-14 16:30:24 +053075
76
77 private:
78
79 /** @brief get the info of the ethernet interface.
80 * @return tuple having the link speed,autonegotiation,duplexmode .
81 */
82
83 InterfaceInfo getInterfaceInfo() const;
84
85 /** @brief get the mac address of the interface.
86 * @return macaddress on success
87 */
88
89 std::string getMACAddress() const;
90
Ratan Gupta82549cc2017-04-21 08:45:23 +053091 /** @brief construct the ip address dbus object path.
92 * @param[in] addressType - Type of ip address.
Ratan Gupta65e5abe2017-05-23 13:20:44 +053093 * @param[in] ipaddress - IP address.
94 * @param[in] prefixLength - Length of prefix.
95 * @param[in] gateway - Gateway addess.
96
Ratan Gupta82549cc2017-04-21 08:45:23 +053097 * @return path of the address object.
98 */
99
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530100 std::string generateObjectPath(IP::Protocol addressType,
101 const std::string& ipaddress,
102 uint8_t prefixLength,
103 const std::string& gateway) const;
Ratan Gupta82549cc2017-04-21 08:45:23 +0530104
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530105 /** @brief generates the id by doing hash of ipaddress,
106 * prefixlength and the gateway.
107 * @param[in] ipaddress - IP address.
108 * @param[in] prefixLength - Length of prefix.
109 * @param[in] gateway - Gateway addess.
110 * @return hash string.
Ratan Gupta82549cc2017-04-21 08:45:23 +0530111 */
112
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530113 static std::string generateId(const std::string& ipaddress,
114 uint8_t prefixLength,
115 const std::string& gateway);
Ratan Gupta82549cc2017-04-21 08:45:23 +0530116
117 /** @brief Persistent sdbusplus DBus bus connection. */
118 sdbusplus::bus::bus& bus;
119
120 /** @brief Persistent map of IPAddress dbus objects and their names */
121 std::map<std::string, std::unique_ptr<IPAddress>> addrs;
122
123
Ratan Gupta8c834932017-04-14 16:30:24 +0530124};
125
126} // namespace network
127} // namespace phosphor