Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 3 | #include "ipaddress.hpp" |
| 4 | #include "types.hpp" |
| 5 | |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 6 | #include "xyz/openbmc_project/Network/EthernetInterface/server.hpp" |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 7 | #include "xyz/openbmc_project/Network/IP/Create/server.hpp" |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 8 | |
| 9 | #include <sdbusplus/bus.hpp> |
| 10 | #include <sdbusplus/server/object.hpp> |
| 11 | |
| 12 | #include <string> |
| 13 | |
| 14 | namespace phosphor |
| 15 | { |
| 16 | namespace network |
| 17 | { |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 18 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 19 | using Ifaces = |
| 20 | sdbusplus::server::object::object< |
| 21 | sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface, |
| 22 | sdbusplus::xyz::openbmc_project::Network::IP::server::Create>; |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 23 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 24 | using IP = sdbusplus::xyz::openbmc_project::Network::server::IP; |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 25 | |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 26 | |
| 27 | using LinkSpeed = uint16_t; |
| 28 | using DuplexMode = uint8_t; |
| 29 | using Autoneg = uint8_t; |
| 30 | using 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 Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 38 | class EthernetInterface : public Ifaces |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 39 | { |
| 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 Gupta | 91a99cc | 2017-04-14 16:32:09 +0530 | [diff] [blame] | 55 | const std::string& objPath, |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 56 | 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 Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 70 | |
Ratan Gupta | 2eff84f | 2017-04-20 19:19:15 +0530 | [diff] [blame] | 71 | /** @brief delete the dbus object of the given ipaddress. |
| 72 | */ |
| 73 | |
| 74 | void deleteObject(const std::string& ipaddress); |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 75 | |
| 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 Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 91 | /** @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 Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | } // namespace network |
| 116 | } // namespace phosphor |