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" |
Ratan Gupta | 8804feb | 2017-05-25 10:49:57 +0530 | [diff] [blame] | 5 | #include "util.hpp" |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 6 | |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 7 | #include "xyz/openbmc_project/Network/EthernetInterface/server.hpp" |
Ratan Gupta | 1caa230 | 2017-07-10 10:30:13 +0530 | [diff] [blame] | 8 | #include "xyz/openbmc_project/Network/MACAddress/server.hpp" |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 9 | #include "xyz/openbmc_project/Network/IP/Create/server.hpp" |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 10 | |
| 11 | #include <sdbusplus/bus.hpp> |
| 12 | #include <sdbusplus/server/object.hpp> |
| 13 | |
| 14 | #include <string> |
| 15 | |
| 16 | namespace phosphor |
| 17 | { |
| 18 | namespace network |
| 19 | { |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 20 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 21 | using Ifaces = |
| 22 | sdbusplus::server::object::object< |
| 23 | sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface, |
Ratan Gupta | 1caa230 | 2017-07-10 10:30:13 +0530 | [diff] [blame] | 24 | sdbusplus::xyz::openbmc_project::Network::server::MACAddress, |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 25 | sdbusplus::xyz::openbmc_project::Network::IP::server::Create>; |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 26 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 27 | using IP = sdbusplus::xyz::openbmc_project::Network::server::IP; |
Ratan Gupta | 87c1398 | 2017-06-15 09:27:27 +0530 | [diff] [blame] | 28 | |
| 29 | using EthernetInterfaceIntf = |
| 30 | sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface; |
| 31 | |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 32 | class Manager; // forward declaration of network manager. |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 33 | |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 34 | class TestEthernetInterface; |
| 35 | |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 36 | using LinkSpeed = uint16_t; |
| 37 | using DuplexMode = uint8_t; |
| 38 | using Autoneg = uint8_t; |
| 39 | using InterfaceInfo = std::tuple<LinkSpeed, DuplexMode, Autoneg>; |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 40 | using AddressMap = std::map<std::string, std::shared_ptr<IPAddress>>; |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 41 | |
| 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 Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 47 | class EthernetInterface : public Ifaces |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 48 | { |
| 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 Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 60 | * @param[in] dhcpEnabled - is dhcp enabled(true/false). |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 61 | * @param[in] parent - parent object. |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 62 | */ |
| 63 | EthernetInterface(sdbusplus::bus::bus& bus, |
Ratan Gupta | 91a99cc | 2017-04-14 16:32:09 +0530 | [diff] [blame] | 64 | const std::string& objPath, |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 65 | bool dhcpEnabled, |
| 66 | Manager& parent); |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 67 | |
| 68 | /** @brief Function to create ipaddress dbus object. |
| 69 | * @param[in] addressType - Type of ip address. |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 70 | * @param[in] ipaddress- IP address. |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 71 | * @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 Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 79 | |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 80 | /* @brief delete the dbus object of the given ipaddress. |
| 81 | * @param[in] ipaddress - IP address. |
Ratan Gupta | 2eff84f | 2017-04-20 19:19:15 +0530 | [diff] [blame] | 82 | */ |
Ratan Gupta | 2eff84f | 2017-04-20 19:19:15 +0530 | [diff] [blame] | 83 | void deleteObject(const std::string& ipaddress); |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 84 | |
Ratan Gupta | 87c1398 | 2017-06-15 09:27:27 +0530 | [diff] [blame] | 85 | /* @brief creates the dbus object(IPaddres) given in the address list. |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 86 | * @param[in] addrs - address list for which dbus objects needs |
| 87 | * to create. |
| 88 | */ |
Ratan Gupta | 87c1398 | 2017-06-15 09:27:27 +0530 | [diff] [blame] | 89 | void createIPAddressObjects(); |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 90 | |
| 91 | /* @brief Gets all the ip addresses. |
| 92 | * @returns the list of ipaddress. |
| 93 | */ |
| 94 | const AddressMap& getAddresses() const { return addrs; } |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 95 | |
Ratan Gupta | 87c1398 | 2017-06-15 09:27:27 +0530 | [diff] [blame] | 96 | /** Set value of DHCPEnabled */ |
| 97 | bool dHCPEnabled(bool value) override; |
| 98 | |
| 99 | using EthernetInterfaceIntf::dHCPEnabled; |
| 100 | |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 101 | 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 Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 115 | /** @brief construct the ip address dbus object path. |
| 116 | * @param[in] addressType - Type of ip address. |
Ratan Gupta | 65e5abe | 2017-05-23 13:20:44 +0530 | [diff] [blame] | 117 | * @param[in] ipaddress - IP address. |
| 118 | * @param[in] prefixLength - Length of prefix. |
| 119 | * @param[in] gateway - Gateway addess. |
| 120 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 121 | * @return path of the address object. |
| 122 | */ |
| 123 | |
Ratan Gupta | 65e5abe | 2017-05-23 13:20:44 +0530 | [diff] [blame] | 124 | std::string generateObjectPath(IP::Protocol addressType, |
| 125 | const std::string& ipaddress, |
| 126 | uint8_t prefixLength, |
| 127 | const std::string& gateway) const; |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 128 | |
Ratan Gupta | 65e5abe | 2017-05-23 13:20:44 +0530 | [diff] [blame] | 129 | /** @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 Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 135 | */ |
| 136 | |
Ratan Gupta | 65e5abe | 2017-05-23 13:20:44 +0530 | [diff] [blame] | 137 | static std::string generateId(const std::string& ipaddress, |
| 138 | uint8_t prefixLength, |
| 139 | const std::string& gateway); |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 140 | |
| 141 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 142 | sdbusplus::bus::bus& bus; |
| 143 | |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 144 | /** @brief Network Manager object. */ |
| 145 | Manager& manager; |
| 146 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 147 | /** @brief Persistent map of IPAddress dbus objects and their names */ |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 148 | AddressMap addrs; |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 149 | |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 150 | /** @brief Dbus object path */ |
| 151 | std::string objPath; |
| 152 | |
| 153 | friend class TestEthernetInterface; |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | } // namespace network |
| 157 | } // namespace phosphor |