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 | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame^] | 62 | * @param[in] emitSignal - true if the object added signal needs to be |
| 63 | * send. |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 64 | */ |
| 65 | EthernetInterface(sdbusplus::bus::bus& bus, |
Ratan Gupta | 91a99cc | 2017-04-14 16:32:09 +0530 | [diff] [blame] | 66 | const std::string& objPath, |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 67 | bool dhcpEnabled, |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame^] | 68 | Manager& parent, |
| 69 | bool emitSignal = true); |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 70 | |
| 71 | /** @brief Function to create ipaddress dbus object. |
| 72 | * @param[in] addressType - Type of ip address. |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 73 | * @param[in] ipaddress- IP address. |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 74 | * @param[in] prefixLength - Length of prefix. |
| 75 | * @param[in] gateway - Gateway ip address. |
| 76 | */ |
| 77 | |
| 78 | void iP(IP::Protocol addressType, |
| 79 | std::string ipaddress, |
| 80 | uint8_t prefixLength, |
| 81 | std::string gateway) override; |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 82 | |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 83 | /* @brief delete the dbus object of the given ipaddress. |
| 84 | * @param[in] ipaddress - IP address. |
Ratan Gupta | 2eff84f | 2017-04-20 19:19:15 +0530 | [diff] [blame] | 85 | */ |
Ratan Gupta | 2eff84f | 2017-04-20 19:19:15 +0530 | [diff] [blame] | 86 | void deleteObject(const std::string& ipaddress); |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 87 | |
Ratan Gupta | 87c1398 | 2017-06-15 09:27:27 +0530 | [diff] [blame] | 88 | /* @brief creates the dbus object(IPaddres) given in the address list. |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 89 | * @param[in] addrs - address list for which dbus objects needs |
| 90 | * to create. |
| 91 | */ |
Ratan Gupta | 87c1398 | 2017-06-15 09:27:27 +0530 | [diff] [blame] | 92 | void createIPAddressObjects(); |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 93 | |
| 94 | /* @brief Gets all the ip addresses. |
| 95 | * @returns the list of ipaddress. |
| 96 | */ |
| 97 | const AddressMap& getAddresses() const { return addrs; } |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 98 | |
Ratan Gupta | 87c1398 | 2017-06-15 09:27:27 +0530 | [diff] [blame] | 99 | /** Set value of DHCPEnabled */ |
| 100 | bool dHCPEnabled(bool value) override; |
| 101 | |
| 102 | using EthernetInterfaceIntf::dHCPEnabled; |
| 103 | |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame^] | 104 | protected: |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 105 | |
| 106 | /** @brief get the info of the ethernet interface. |
| 107 | * @return tuple having the link speed,autonegotiation,duplexmode . |
| 108 | */ |
| 109 | |
| 110 | InterfaceInfo getInterfaceInfo() const; |
| 111 | |
| 112 | /** @brief get the mac address of the interface. |
| 113 | * @return macaddress on success |
| 114 | */ |
| 115 | |
| 116 | std::string getMACAddress() const; |
| 117 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 118 | /** @brief construct the ip address dbus object path. |
| 119 | * @param[in] addressType - Type of ip address. |
Ratan Gupta | 65e5abe | 2017-05-23 13:20:44 +0530 | [diff] [blame] | 120 | * @param[in] ipaddress - IP address. |
| 121 | * @param[in] prefixLength - Length of prefix. |
| 122 | * @param[in] gateway - Gateway addess. |
| 123 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 124 | * @return path of the address object. |
| 125 | */ |
| 126 | |
Ratan Gupta | 65e5abe | 2017-05-23 13:20:44 +0530 | [diff] [blame] | 127 | std::string generateObjectPath(IP::Protocol addressType, |
| 128 | const std::string& ipaddress, |
| 129 | uint8_t prefixLength, |
| 130 | const std::string& gateway) const; |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 131 | |
Ratan Gupta | 65e5abe | 2017-05-23 13:20:44 +0530 | [diff] [blame] | 132 | /** @brief generates the id by doing hash of ipaddress, |
| 133 | * prefixlength and the gateway. |
| 134 | * @param[in] ipaddress - IP address. |
| 135 | * @param[in] prefixLength - Length of prefix. |
| 136 | * @param[in] gateway - Gateway addess. |
| 137 | * @return hash string. |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 138 | */ |
| 139 | |
Ratan Gupta | 65e5abe | 2017-05-23 13:20:44 +0530 | [diff] [blame] | 140 | static std::string generateId(const std::string& ipaddress, |
| 141 | uint8_t prefixLength, |
| 142 | const std::string& gateway); |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 143 | |
| 144 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 145 | sdbusplus::bus::bus& bus; |
| 146 | |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 147 | /** @brief Network Manager object. */ |
| 148 | Manager& manager; |
| 149 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 150 | /** @brief Persistent map of IPAddress dbus objects and their names */ |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 151 | AddressMap addrs; |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 152 | |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 153 | /** @brief Dbus object path */ |
| 154 | std::string objPath; |
| 155 | |
| 156 | friend class TestEthernetInterface; |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | } // namespace network |
| 160 | } // namespace phosphor |