blob: c755f06e5799d3e2a157c40ef4db6056d990de40 [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 Gupta8c834932017-04-14 16:30:24 +053026
Ratan Gupta8c834932017-04-14 16:30:24 +053027using LinkSpeed = uint16_t;
28using DuplexMode = uint8_t;
29using Autoneg = uint8_t;
30using InterfaceInfo = std::tuple<LinkSpeed, DuplexMode, Autoneg>;
Ratan Gupta29b0e432017-05-25 12:51:40 +053031using AddressMap = std::map<std::string, std::shared_ptr<IPAddress>>;
Ratan Gupta8c834932017-04-14 16:30:24 +053032
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.
Ratan Gupta8c834932017-04-14 16:30:24 +053051 * @param[in] dhcpEnabled - is dhcp enabled(true/false).
52 */
53 EthernetInterface(sdbusplus::bus::bus& bus,
Ratan Gupta91a99cc2017-04-14 16:32:09 +053054 const std::string& objPath,
Ratan Gupta29b0e432017-05-25 12:51:40 +053055 bool dhcpEnabled);
Ratan Gupta82549cc2017-04-21 08:45:23 +053056
57 /** @brief Function to create ipaddress dbus object.
58 * @param[in] addressType - Type of ip address.
Ratan Gupta29b0e432017-05-25 12:51:40 +053059 * @param[in] ipaddress- IP address.
Ratan Gupta82549cc2017-04-21 08:45:23 +053060 * @param[in] prefixLength - Length of prefix.
61 * @param[in] gateway - Gateway ip address.
62 */
63
64 void iP(IP::Protocol addressType,
65 std::string ipaddress,
66 uint8_t prefixLength,
67 std::string gateway) override;
Ratan Gupta8c834932017-04-14 16:30:24 +053068
Ratan Gupta29b0e432017-05-25 12:51:40 +053069 /* @brief delete the dbus object of the given ipaddress.
70 * @param[in] ipaddress - IP address.
Ratan Gupta2eff84f2017-04-20 19:19:15 +053071 */
Ratan Gupta2eff84f2017-04-20 19:19:15 +053072 void deleteObject(const std::string& ipaddress);
Ratan Gupta8c834932017-04-14 16:30:24 +053073
Ratan Gupta29b0e432017-05-25 12:51:40 +053074 /* @brief creates the dbus object given in the address list.
75 * @param[in] addrs - address list for which dbus objects needs
76 * to create.
77 */
78 void setAddressList(const AddrList& addrs);
79
80 /* @brief Gets all the ip addresses.
81 * @returns the list of ipaddress.
82 */
83 const AddressMap& getAddresses() const { return addrs; }
Ratan Gupta8c834932017-04-14 16:30:24 +053084
85 private:
86
87 /** @brief get the info of the ethernet interface.
88 * @return tuple having the link speed,autonegotiation,duplexmode .
89 */
90
91 InterfaceInfo getInterfaceInfo() const;
92
93 /** @brief get the mac address of the interface.
94 * @return macaddress on success
95 */
96
97 std::string getMACAddress() const;
98
Ratan Gupta82549cc2017-04-21 08:45:23 +053099 /** @brief construct the ip address dbus object path.
100 * @param[in] addressType - Type of ip address.
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530101 * @param[in] ipaddress - IP address.
102 * @param[in] prefixLength - Length of prefix.
103 * @param[in] gateway - Gateway addess.
104
Ratan Gupta82549cc2017-04-21 08:45:23 +0530105 * @return path of the address object.
106 */
107
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530108 std::string generateObjectPath(IP::Protocol addressType,
109 const std::string& ipaddress,
110 uint8_t prefixLength,
111 const std::string& gateway) const;
Ratan Gupta82549cc2017-04-21 08:45:23 +0530112
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530113 /** @brief generates the id by doing hash of ipaddress,
114 * prefixlength and the gateway.
115 * @param[in] ipaddress - IP address.
116 * @param[in] prefixLength - Length of prefix.
117 * @param[in] gateway - Gateway addess.
118 * @return hash string.
Ratan Gupta82549cc2017-04-21 08:45:23 +0530119 */
120
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530121 static std::string generateId(const std::string& ipaddress,
122 uint8_t prefixLength,
123 const std::string& gateway);
Ratan Gupta82549cc2017-04-21 08:45:23 +0530124
125 /** @brief Persistent sdbusplus DBus bus connection. */
126 sdbusplus::bus::bus& bus;
127
128 /** @brief Persistent map of IPAddress dbus objects and their names */
Ratan Gupta29b0e432017-05-25 12:51:40 +0530129 AddressMap addrs;
Ratan Gupta82549cc2017-04-21 08:45:23 +0530130
Ratan Gupta8c834932017-04-14 16:30:24 +0530131};
132
133} // namespace network
134} // namespace phosphor