blob: 88200f8ecdbfcef03121aadb52b59f756fb777f7 [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 Gupta1caa2302017-07-10 10:30:13 +05308#include "xyz/openbmc_project/Network/MACAddress/server.hpp"
Ratan Gupta82549cc2017-04-21 08:45:23 +05309#include "xyz/openbmc_project/Network/IP/Create/server.hpp"
Ratan Gupta8c834932017-04-14 16:30:24 +053010
11#include <sdbusplus/bus.hpp>
12#include <sdbusplus/server/object.hpp>
13
14#include <string>
15
16namespace phosphor
17{
18namespace network
19{
Ratan Gupta8c834932017-04-14 16:30:24 +053020
Ratan Gupta82549cc2017-04-21 08:45:23 +053021using Ifaces =
22 sdbusplus::server::object::object<
23 sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface,
Ratan Gupta1caa2302017-07-10 10:30:13 +053024 sdbusplus::xyz::openbmc_project::Network::server::MACAddress,
Ratan Gupta82549cc2017-04-21 08:45:23 +053025 sdbusplus::xyz::openbmc_project::Network::IP::server::Create>;
Ratan Gupta8c834932017-04-14 16:30:24 +053026
Ratan Gupta82549cc2017-04-21 08:45:23 +053027using IP = sdbusplus::xyz::openbmc_project::Network::server::IP;
Ratan Gupta87c13982017-06-15 09:27:27 +053028
29using EthernetInterfaceIntf =
30 sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface;
31
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053032class Manager; // forward declaration of network manager.
Ratan Gupta8c834932017-04-14 16:30:24 +053033
Ratan Gupta47722dc2017-05-26 18:32:23 +053034class TestEthernetInterface;
35
Ratan Gupta8c834932017-04-14 16:30:24 +053036using LinkSpeed = uint16_t;
37using DuplexMode = uint8_t;
38using Autoneg = uint8_t;
39using InterfaceInfo = std::tuple<LinkSpeed, DuplexMode, Autoneg>;
Ratan Gupta29b0e432017-05-25 12:51:40 +053040using AddressMap = std::map<std::string, std::shared_ptr<IPAddress>>;
Ratan Gupta8c834932017-04-14 16:30:24 +053041
42/** @class EthernetInterface
43 * @brief OpenBMC Ethernet Interface implementation.
44 * @details A concrete implementation for the
45 * xyz.openbmc_project.Network.EthernetInterface DBus API.
46 */
Ratan Gupta82549cc2017-04-21 08:45:23 +053047class EthernetInterface : public Ifaces
Ratan Gupta8c834932017-04-14 16:30:24 +053048{
49 public:
50 EthernetInterface() = delete;
51 EthernetInterface(const EthernetInterface&) = delete;
52 EthernetInterface& operator=(const EthernetInterface&) = delete;
53 EthernetInterface(EthernetInterface&&) = delete;
54 EthernetInterface& operator=(EthernetInterface&&) = delete;
55 virtual ~EthernetInterface() = default;
56
57 /** @brief Constructor to put object onto bus at a dbus path.
58 * @param[in] bus - Bus to attach to.
59 * @param[in] objPath - Path to attach at.
Ratan Gupta8c834932017-04-14 16:30:24 +053060 * @param[in] dhcpEnabled - is dhcp enabled(true/false).
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053061 * @param[in] parent - parent object.
Ratan Gupta8c834932017-04-14 16:30:24 +053062 */
63 EthernetInterface(sdbusplus::bus::bus& bus,
Ratan Gupta91a99cc2017-04-14 16:32:09 +053064 const std::string& objPath,
Ratan Gupta4f1c18b2017-05-25 12:59:35 +053065 bool dhcpEnabled,
66 Manager& parent);
Ratan Gupta82549cc2017-04-21 08:45:23 +053067
68 /** @brief Function to create ipaddress dbus object.
69 * @param[in] addressType - Type of ip address.
Ratan Gupta29b0e432017-05-25 12:51:40 +053070 * @param[in] ipaddress- IP address.
Ratan Gupta82549cc2017-04-21 08:45:23 +053071 * @param[in] prefixLength - Length of prefix.
72 * @param[in] gateway - Gateway ip address.
73 */
74
75 void iP(IP::Protocol addressType,
76 std::string ipaddress,
77 uint8_t prefixLength,
78 std::string gateway) override;
Ratan Gupta8c834932017-04-14 16:30:24 +053079
Ratan Gupta29b0e432017-05-25 12:51:40 +053080 /* @brief delete the dbus object of the given ipaddress.
81 * @param[in] ipaddress - IP address.
Ratan Gupta2eff84f2017-04-20 19:19:15 +053082 */
Ratan Gupta2eff84f2017-04-20 19:19:15 +053083 void deleteObject(const std::string& ipaddress);
Ratan Gupta8c834932017-04-14 16:30:24 +053084
Ratan Gupta87c13982017-06-15 09:27:27 +053085 /* @brief creates the dbus object(IPaddres) given in the address list.
Ratan Gupta29b0e432017-05-25 12:51:40 +053086 * @param[in] addrs - address list for which dbus objects needs
87 * to create.
88 */
Ratan Gupta87c13982017-06-15 09:27:27 +053089 void createIPAddressObjects();
Ratan Gupta29b0e432017-05-25 12:51:40 +053090
91 /* @brief Gets all the ip addresses.
92 * @returns the list of ipaddress.
93 */
94 const AddressMap& getAddresses() const { return addrs; }
Ratan Gupta8c834932017-04-14 16:30:24 +053095
Ratan Gupta87c13982017-06-15 09:27:27 +053096 /** Set value of DHCPEnabled */
97 bool dHCPEnabled(bool value) override;
98
99 using EthernetInterfaceIntf::dHCPEnabled;
100
Ratan Gupta8c834932017-04-14 16:30:24 +0530101 private:
102
103 /** @brief get the info of the ethernet interface.
104 * @return tuple having the link speed,autonegotiation,duplexmode .
105 */
106
107 InterfaceInfo getInterfaceInfo() const;
108
109 /** @brief get the mac address of the interface.
110 * @return macaddress on success
111 */
112
113 std::string getMACAddress() const;
114
Ratan Gupta82549cc2017-04-21 08:45:23 +0530115 /** @brief construct the ip address dbus object path.
116 * @param[in] addressType - Type of ip address.
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530117 * @param[in] ipaddress - IP address.
118 * @param[in] prefixLength - Length of prefix.
119 * @param[in] gateway - Gateway addess.
120
Ratan Gupta82549cc2017-04-21 08:45:23 +0530121 * @return path of the address object.
122 */
123
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530124 std::string generateObjectPath(IP::Protocol addressType,
125 const std::string& ipaddress,
126 uint8_t prefixLength,
127 const std::string& gateway) const;
Ratan Gupta82549cc2017-04-21 08:45:23 +0530128
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530129 /** @brief generates the id by doing hash of ipaddress,
130 * prefixlength and the gateway.
131 * @param[in] ipaddress - IP address.
132 * @param[in] prefixLength - Length of prefix.
133 * @param[in] gateway - Gateway addess.
134 * @return hash string.
Ratan Gupta82549cc2017-04-21 08:45:23 +0530135 */
136
Ratan Gupta65e5abe2017-05-23 13:20:44 +0530137 static std::string generateId(const std::string& ipaddress,
138 uint8_t prefixLength,
139 const std::string& gateway);
Ratan Gupta82549cc2017-04-21 08:45:23 +0530140
141 /** @brief Persistent sdbusplus DBus bus connection. */
142 sdbusplus::bus::bus& bus;
143
Ratan Gupta4f1c18b2017-05-25 12:59:35 +0530144 /** @brief Network Manager object. */
145 Manager& manager;
146
Ratan Gupta82549cc2017-04-21 08:45:23 +0530147 /** @brief Persistent map of IPAddress dbus objects and their names */
Ratan Gupta29b0e432017-05-25 12:51:40 +0530148 AddressMap addrs;
Ratan Gupta82549cc2017-04-21 08:45:23 +0530149
Ratan Gupta47722dc2017-05-26 18:32:23 +0530150 /** @brief Dbus object path */
151 std::string objPath;
152
153 friend class TestEthernetInterface;
Ratan Gupta8c834932017-04-14 16:30:24 +0530154};
155
156} // namespace network
157} // namespace phosphor