blob: 856f8745a5f56740affa1f9332826ef9cb33fff5 [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 Manager; // forward declaration of network manager.
29class TestEthernetInterface;
30
Ratan Gupta8c834932017-04-14 16:30:24 +053031using LinkSpeed = uint16_t;
32using DuplexMode = uint8_t;
33using Autoneg = uint8_t;
34using InterfaceInfo = std::tuple<LinkSpeed, DuplexMode, Autoneg>;
Ratan Gupta29b0e432017-05-25 12:51:40 +053035using AddressMap = std::map<std::string, std::shared_ptr<IPAddress>>;
Ratan Gupta8c834932017-04-14 16:30:24 +053036
37/** @class EthernetInterface
38 * @brief OpenBMC Ethernet Interface implementation.
39 * @details A concrete implementation for the
40 * xyz.openbmc_project.Network.EthernetInterface DBus API.
41 */
Ratan Gupta82549cc2017-04-21 08:45:23 +053042class EthernetInterface : public Ifaces
Ratan Gupta8c834932017-04-14 16:30:24 +053043{
44 public:
45 EthernetInterface() = delete;
46 EthernetInterface(const EthernetInterface&) = delete;
47 EthernetInterface& operator=(const EthernetInterface&) = delete;
48 EthernetInterface(EthernetInterface&&) = delete;
49 EthernetInterface& operator=(EthernetInterface&&) = delete;
50 virtual ~EthernetInterface() = default;
51
52 /** @brief Constructor to put object onto bus at a dbus path.
53 * @param[in] bus - Bus to attach to.
54 * @param[in] objPath - Path to attach at.
Ratan Gupta8c834932017-04-14 16:30:24 +053055 * @param[in] dhcpEnabled - is dhcp enabled(true/false).
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053056 * @param[in] parent - parent object.
Ratan Gupta8c834932017-04-14 16:30:24 +053057 */
58 EthernetInterface(sdbusplus::bus::bus& bus,
Ratan Gupta91a99cc2017-04-14 16:32:09 +053059 const std::string& objPath,
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053060 bool dhcpEnabled,
61 Manager& parent);
Ratan Gupta82549cc2017-04-21 08:45:23 +053062
63 /** @brief Function to create ipaddress dbus object.
64 * @param[in] addressType - Type of ip address.
Ratan Gupta29b0e432017-05-25 12:51:40 +053065 * @param[in] ipaddress- IP address.
Ratan Gupta82549cc2017-04-21 08:45:23 +053066 * @param[in] prefixLength - Length of prefix.
67 * @param[in] gateway - Gateway ip address.
68 */
69
70 void iP(IP::Protocol addressType,
71 std::string ipaddress,
72 uint8_t prefixLength,
73 std::string gateway) override;
Ratan Gupta8c834932017-04-14 16:30:24 +053074
Ratan Gupta29b0e432017-05-25 12:51:40 +053075 /* @brief delete the dbus object of the given ipaddress.
76 * @param[in] ipaddress - IP address.
Ratan Gupta2eff84f2017-04-20 19:19:15 +053077 */
Ratan Gupta2eff84f2017-04-20 19:19:15 +053078 void deleteObject(const std::string& ipaddress);
Ratan Gupta8c834932017-04-14 16:30:24 +053079
Ratan Gupta29b0e432017-05-25 12:51:40 +053080 /* @brief creates the dbus object given in the address list.
81 * @param[in] addrs - address list for which dbus objects needs
82 * to create.
83 */
84 void setAddressList(const AddrList& addrs);
85
86 /* @brief Gets all the ip addresses.
87 * @returns the list of ipaddress.
88 */
89 const AddressMap& getAddresses() const { return addrs; }
Ratan Gupta8c834932017-04-14 16:30:24 +053090
91 private:
92
93 /** @brief get the info of the ethernet interface.
94 * @return tuple having the link speed,autonegotiation,duplexmode .
95 */
96
97 InterfaceInfo getInterfaceInfo() const;
98
99 /** @brief get the mac address of the interface.
100 * @return macaddress on success
101 */
102
103 std::string getMACAddress() const;
104
Ratan Gupta82549cc2017-04-21 08:45:23 +0530105 /** @brief construct the ip address dbus object path.
106 * @param[in] addressType - Type of ip address.
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530107 * @param[in] ipaddress - IP address.
108 * @param[in] prefixLength - Length of prefix.
109 * @param[in] gateway - Gateway addess.
110
Ratan Gupta82549cc2017-04-21 08:45:23 +0530111 * @return path of the address object.
112 */
113
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530114 std::string generateObjectPath(IP::Protocol addressType,
115 const std::string& ipaddress,
116 uint8_t prefixLength,
117 const std::string& gateway) const;
Ratan Gupta82549cc2017-04-21 08:45:23 +0530118
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530119 /** @brief generates the id by doing hash of ipaddress,
120 * prefixlength and the gateway.
121 * @param[in] ipaddress - IP address.
122 * @param[in] prefixLength - Length of prefix.
123 * @param[in] gateway - Gateway addess.
124 * @return hash string.
Ratan Gupta82549cc2017-04-21 08:45:23 +0530125 */
126
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530127 static std::string generateId(const std::string& ipaddress,
128 uint8_t prefixLength,
129 const std::string& gateway);
Ratan Gupta82549cc2017-04-21 08:45:23 +0530130
131 /** @brief Persistent sdbusplus DBus bus connection. */
132 sdbusplus::bus::bus& bus;
133
Ratan Gupta4f1c18b2017-05-25 12:59:35 +0530134 /** @brief Network Manager object. */
135 Manager& manager;
136
Ratan Gupta82549cc2017-04-21 08:45:23 +0530137 /** @brief Persistent map of IPAddress dbus objects and their names */
Ratan Gupta29b0e432017-05-25 12:51:40 +0530138 AddressMap addrs;
Ratan Gupta82549cc2017-04-21 08:45:23 +0530139
Ratan Gupta47722dc2017-05-26 18:32:23 +0530140 /** @brief Dbus object path */
141 std::string objPath;
142
143 friend class TestEthernetInterface;
Ratan Gupta8c834932017-04-14 16:30:24 +0530144};
145
146} // namespace network
147} // namespace phosphor