blob: 6ef1ec93047a141bf93216e518ae9a22501cef4d [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 +053027
28using LinkSpeed = uint16_t;
29using DuplexMode = uint8_t;
30using Autoneg = uint8_t;
31using InterfaceInfo = std::tuple<LinkSpeed, DuplexMode, Autoneg>;
32
33
34/** @class EthernetInterface
35 * @brief OpenBMC Ethernet Interface implementation.
36 * @details A concrete implementation for the
37 * xyz.openbmc_project.Network.EthernetInterface DBus API.
38 */
Ratan Gupta82549cc2017-04-21 08:45:23 +053039class EthernetInterface : public Ifaces
Ratan Gupta8c834932017-04-14 16:30:24 +053040{
41 public:
42 EthernetInterface() = delete;
43 EthernetInterface(const EthernetInterface&) = delete;
44 EthernetInterface& operator=(const EthernetInterface&) = delete;
45 EthernetInterface(EthernetInterface&&) = delete;
46 EthernetInterface& operator=(EthernetInterface&&) = delete;
47 virtual ~EthernetInterface() = default;
48
49 /** @brief Constructor to put object onto bus at a dbus path.
50 * @param[in] bus - Bus to attach to.
51 * @param[in] objPath - Path to attach at.
52 * @param[in] intfName - name of the ethernet interface.
53 * @param[in] dhcpEnabled - is dhcp enabled(true/false).
54 */
55 EthernetInterface(sdbusplus::bus::bus& bus,
Ratan Gupta91a99cc2017-04-14 16:32:09 +053056 const std::string& objPath,
Ratan Gupta82549cc2017-04-21 08:45:23 +053057 bool dhcpEnabled,
58 const AddrList& addrs);
59
60 /** @brief Function to create ipaddress dbus object.
61 * @param[in] addressType - Type of ip address.
62 * @param[in] ipaddress- IP adress.
63 * @param[in] prefixLength - Length of prefix.
64 * @param[in] gateway - Gateway ip address.
65 */
66
67 void iP(IP::Protocol addressType,
68 std::string ipaddress,
69 uint8_t prefixLength,
70 std::string gateway) override;
Ratan Gupta8c834932017-04-14 16:30:24 +053071
Ratan Gupta2eff84f2017-04-20 19:19:15 +053072 /** @brief delete the dbus object of the given ipaddress.
73 */
74
75 void deleteObject(const std::string& ipaddress);
Ratan Gupta8c834932017-04-14 16:30:24 +053076
77
78 private:
79
80 /** @brief get the info of the ethernet interface.
81 * @return tuple having the link speed,autonegotiation,duplexmode .
82 */
83
84 InterfaceInfo getInterfaceInfo() const;
85
86 /** @brief get the mac address of the interface.
87 * @return macaddress on success
88 */
89
90 std::string getMACAddress() const;
91
Ratan Gupta82549cc2017-04-21 08:45:23 +053092 /** @brief construct the ip address dbus object path.
93 * @param[in] addressType - Type of ip address.
Ratan Gupta65e5abe2017-05-23 13:20:44 +053094 * @param[in] ipaddress - IP address.
95 * @param[in] prefixLength - Length of prefix.
96 * @param[in] gateway - Gateway addess.
97
Ratan Gupta82549cc2017-04-21 08:45:23 +053098 * @return path of the address object.
99 */
100
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530101 std::string generateObjectPath(IP::Protocol addressType,
102 const std::string& ipaddress,
103 uint8_t prefixLength,
104 const std::string& gateway) const;
Ratan Gupta82549cc2017-04-21 08:45:23 +0530105
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530106 /** @brief generates the id by doing hash of ipaddress,
107 * prefixlength and the gateway.
108 * @param[in] ipaddress - IP address.
109 * @param[in] prefixLength - Length of prefix.
110 * @param[in] gateway - Gateway addess.
111 * @return hash string.
Ratan Gupta82549cc2017-04-21 08:45:23 +0530112 */
113
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530114 static std::string generateId(const std::string& ipaddress,
115 uint8_t prefixLength,
116 const std::string& gateway);
Ratan Gupta82549cc2017-04-21 08:45:23 +0530117
118 /** @brief Persistent sdbusplus DBus bus connection. */
119 sdbusplus::bus::bus& bus;
120
121 /** @brief Persistent map of IPAddress dbus objects and their names */
122 std::map<std::string, std::unique_ptr<IPAddress>> addrs;
123
124
Ratan Gupta8c834932017-04-14 16:30:24 +0530125};
126
127} // namespace network
128} // namespace phosphor