blob: ab69a785d5e847af7013b4a071732a01a47e2a95 [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.
93 * @return path of the address object.
94 */
95
96 std::string getAddressObjectPath(IP::Protocol addressType) const;
97
98 /** @brief get the ipadress count for a specific type on this interface.
99 * @param[in] addressType - Type of ip address.
100 * @return count of ipaddreses for the incoming type.
101 */
102
103 size_t getAddressCount(IP::Protocol addressType) const;
104
105
106 /** @brief Persistent sdbusplus DBus bus connection. */
107 sdbusplus::bus::bus& bus;
108
109 /** @brief Persistent map of IPAddress dbus objects and their names */
110 std::map<std::string, std::unique_ptr<IPAddress>> addrs;
111
112
Ratan Gupta8c834932017-04-14 16:30:24 +0530113};
114
115} // namespace network
116} // namespace phosphor