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 | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 8 | #include "xyz/openbmc_project/Network/IP/Create/server.hpp" |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 9 | |
| 10 | #include <sdbusplus/bus.hpp> |
| 11 | #include <sdbusplus/server/object.hpp> |
| 12 | |
| 13 | #include <string> |
| 14 | |
| 15 | namespace phosphor |
| 16 | { |
| 17 | namespace network |
| 18 | { |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 19 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 20 | using Ifaces = |
| 21 | sdbusplus::server::object::object< |
| 22 | sdbusplus::xyz::openbmc_project::Network::server::EthernetInterface, |
| 23 | sdbusplus::xyz::openbmc_project::Network::IP::server::Create>; |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 24 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 25 | using IP = sdbusplus::xyz::openbmc_project::Network::server::IP; |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 26 | class Manager; // forward declaration of network manager. |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 27 | |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 28 | using LinkSpeed = uint16_t; |
| 29 | using DuplexMode = uint8_t; |
| 30 | using Autoneg = uint8_t; |
| 31 | using InterfaceInfo = std::tuple<LinkSpeed, DuplexMode, Autoneg>; |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 32 | using AddressMap = std::map<std::string, std::shared_ptr<IPAddress>>; |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 33 | |
| 34 | /** @class EthernetInterface |
| 35 | * @brief OpenBMC Ethernet Interface implementation. |
| 36 | * @details A concrete implementation for the |
| 37 | * xyz.openbmc_project.Network.EthernetInterface DBus API. |
| 38 | */ |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 39 | class EthernetInterface : public Ifaces |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 40 | { |
| 41 | public: |
| 42 | EthernetInterface() = delete; |
| 43 | EthernetInterface(const EthernetInterface&) = delete; |
| 44 | EthernetInterface& operator=(const EthernetInterface&) = delete; |
| 45 | EthernetInterface(EthernetInterface&&) = delete; |
| 46 | EthernetInterface& operator=(EthernetInterface&&) = delete; |
| 47 | virtual ~EthernetInterface() = default; |
| 48 | |
| 49 | /** @brief Constructor to put object onto bus at a dbus path. |
| 50 | * @param[in] bus - Bus to attach to. |
| 51 | * @param[in] objPath - Path to attach at. |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 52 | * @param[in] dhcpEnabled - is dhcp enabled(true/false). |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 53 | * @param[in] parent - parent object. |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 54 | */ |
| 55 | EthernetInterface(sdbusplus::bus::bus& bus, |
Ratan Gupta | 91a99cc | 2017-04-14 16:32:09 +0530 | [diff] [blame] | 56 | const std::string& objPath, |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 57 | bool dhcpEnabled, |
| 58 | Manager& parent); |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 59 | |
| 60 | /** @brief Function to create ipaddress dbus object. |
| 61 | * @param[in] addressType - Type of ip address. |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 62 | * @param[in] ipaddress- IP address. |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 63 | * @param[in] prefixLength - Length of prefix. |
| 64 | * @param[in] gateway - Gateway ip address. |
| 65 | */ |
| 66 | |
| 67 | void iP(IP::Protocol addressType, |
| 68 | std::string ipaddress, |
| 69 | uint8_t prefixLength, |
| 70 | std::string gateway) override; |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 71 | |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 72 | /* @brief delete the dbus object of the given ipaddress. |
| 73 | * @param[in] ipaddress - IP address. |
Ratan Gupta | 2eff84f | 2017-04-20 19:19:15 +0530 | [diff] [blame] | 74 | */ |
Ratan Gupta | 2eff84f | 2017-04-20 19:19:15 +0530 | [diff] [blame] | 75 | void deleteObject(const std::string& ipaddress); |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 76 | |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 77 | /* @brief creates the dbus object given in the address list. |
| 78 | * @param[in] addrs - address list for which dbus objects needs |
| 79 | * to create. |
| 80 | */ |
| 81 | void setAddressList(const AddrList& addrs); |
| 82 | |
| 83 | /* @brief Gets all the ip addresses. |
| 84 | * @returns the list of ipaddress. |
| 85 | */ |
| 86 | const AddressMap& getAddresses() const { return addrs; } |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 87 | |
| 88 | private: |
| 89 | |
| 90 | /** @brief get the info of the ethernet interface. |
| 91 | * @return tuple having the link speed,autonegotiation,duplexmode . |
| 92 | */ |
| 93 | |
| 94 | InterfaceInfo getInterfaceInfo() const; |
| 95 | |
| 96 | /** @brief get the mac address of the interface. |
| 97 | * @return macaddress on success |
| 98 | */ |
| 99 | |
| 100 | std::string getMACAddress() const; |
| 101 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 102 | /** @brief construct the ip address dbus object path. |
| 103 | * @param[in] addressType - Type of ip address. |
Ratan Gupta | 65e5abe | 2017-05-23 13:20:44 +0530 | [diff] [blame] | 104 | * @param[in] ipaddress - IP address. |
| 105 | * @param[in] prefixLength - Length of prefix. |
| 106 | * @param[in] gateway - Gateway addess. |
| 107 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 108 | * @return path of the address object. |
| 109 | */ |
| 110 | |
Ratan Gupta | 65e5abe | 2017-05-23 13:20:44 +0530 | [diff] [blame] | 111 | std::string generateObjectPath(IP::Protocol addressType, |
| 112 | const std::string& ipaddress, |
| 113 | uint8_t prefixLength, |
| 114 | const std::string& gateway) const; |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 115 | |
Ratan Gupta | 65e5abe | 2017-05-23 13:20:44 +0530 | [diff] [blame] | 116 | /** @brief generates the id by doing hash of ipaddress, |
| 117 | * prefixlength and the gateway. |
| 118 | * @param[in] ipaddress - IP address. |
| 119 | * @param[in] prefixLength - Length of prefix. |
| 120 | * @param[in] gateway - Gateway addess. |
| 121 | * @return hash string. |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 122 | */ |
| 123 | |
Ratan Gupta | 65e5abe | 2017-05-23 13:20:44 +0530 | [diff] [blame] | 124 | static std::string generateId(const std::string& ipaddress, |
| 125 | uint8_t prefixLength, |
| 126 | const std::string& gateway); |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 127 | |
| 128 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 129 | sdbusplus::bus::bus& bus; |
| 130 | |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 131 | /** @brief Network Manager object. */ |
| 132 | Manager& manager; |
| 133 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 134 | /** @brief Persistent map of IPAddress dbus objects and their names */ |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 135 | AddressMap addrs; |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 136 | |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | } // namespace network |
| 140 | } // namespace phosphor |