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 "types.hpp" |
Ratan Gupta | 8804feb | 2017-05-25 10:49:57 +0530 | [diff] [blame] | 4 | #include "util.hpp" |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 5 | |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 6 | #include "xyz/openbmc_project/Network/EthernetInterface/server.hpp" |
Ratan Gupta | 1caa230 | 2017-07-10 10:30:13 +0530 | [diff] [blame] | 7 | #include "xyz/openbmc_project/Network/MACAddress/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> |
Ratan Gupta | 5978dd1 | 2017-07-25 13:47:13 +0530 | [diff] [blame] | 14 | #include <experimental/filesystem> |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 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 | 5978dd1 | 2017-07-25 13:47:13 +0530 | [diff] [blame] | 32 | namespace fs = std::experimental::filesystem; |
| 33 | |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 34 | class Manager; // forward declaration of network manager. |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 35 | |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 36 | class TestEthernetInterface; |
| 37 | |
Ratan Gupta | 5978dd1 | 2017-07-25 13:47:13 +0530 | [diff] [blame] | 38 | class VlanInterface; |
| 39 | |
| 40 | class IPAddress; |
| 41 | |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 42 | using LinkSpeed = uint16_t; |
| 43 | using DuplexMode = uint8_t; |
| 44 | using Autoneg = uint8_t; |
Ratan Gupta | 5978dd1 | 2017-07-25 13:47:13 +0530 | [diff] [blame] | 45 | using VlanId = uint32_t; |
| 46 | using InterfaceName = std::string; |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 47 | using InterfaceInfo = std::tuple<LinkSpeed, DuplexMode, Autoneg>; |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 48 | using AddressMap = std::map<std::string, std::shared_ptr<IPAddress>>; |
Ratan Gupta | 5978dd1 | 2017-07-25 13:47:13 +0530 | [diff] [blame] | 49 | using VlanInterfaceMap = std::map<InterfaceName, std::unique_ptr<VlanInterface>>; |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 50 | |
| 51 | /** @class EthernetInterface |
| 52 | * @brief OpenBMC Ethernet Interface implementation. |
| 53 | * @details A concrete implementation for the |
| 54 | * xyz.openbmc_project.Network.EthernetInterface DBus API. |
| 55 | */ |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 56 | class EthernetInterface : public Ifaces |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 57 | { |
| 58 | public: |
| 59 | EthernetInterface() = delete; |
| 60 | EthernetInterface(const EthernetInterface&) = delete; |
| 61 | EthernetInterface& operator=(const EthernetInterface&) = delete; |
| 62 | EthernetInterface(EthernetInterface&&) = delete; |
| 63 | EthernetInterface& operator=(EthernetInterface&&) = delete; |
| 64 | virtual ~EthernetInterface() = default; |
| 65 | |
| 66 | /** @brief Constructor to put object onto bus at a dbus path. |
| 67 | * @param[in] bus - Bus to attach to. |
| 68 | * @param[in] objPath - Path to attach at. |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 69 | * @param[in] dhcpEnabled - is dhcp enabled(true/false). |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 70 | * @param[in] parent - parent object. |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 71 | * @param[in] emitSignal - true if the object added signal needs to be |
| 72 | * send. |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 73 | */ |
| 74 | EthernetInterface(sdbusplus::bus::bus& bus, |
Ratan Gupta | 91a99cc | 2017-04-14 16:32:09 +0530 | [diff] [blame] | 75 | const std::string& objPath, |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 76 | bool dhcpEnabled, |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 77 | Manager& parent, |
| 78 | bool emitSignal = true); |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 79 | |
| 80 | /** @brief Function to create ipaddress dbus object. |
| 81 | * @param[in] addressType - Type of ip address. |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 82 | * @param[in] ipaddress- IP address. |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 83 | * @param[in] prefixLength - Length of prefix. |
| 84 | * @param[in] gateway - Gateway ip address. |
| 85 | */ |
| 86 | |
| 87 | void iP(IP::Protocol addressType, |
| 88 | std::string ipaddress, |
| 89 | uint8_t prefixLength, |
| 90 | std::string gateway) override; |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 91 | |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 92 | /* @brief delete the dbus object of the given ipaddress. |
| 93 | * @param[in] ipaddress - IP address. |
Ratan Gupta | 2eff84f | 2017-04-20 19:19:15 +0530 | [diff] [blame] | 94 | */ |
Ratan Gupta | 2eff84f | 2017-04-20 19:19:15 +0530 | [diff] [blame] | 95 | void deleteObject(const std::string& ipaddress); |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 96 | |
Ratan Gupta | 87c1398 | 2017-06-15 09:27:27 +0530 | [diff] [blame] | 97 | /* @brief creates the dbus object(IPaddres) given in the address list. |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 98 | * @param[in] addrs - address list for which dbus objects needs |
| 99 | * to create. |
| 100 | */ |
Ratan Gupta | 87c1398 | 2017-06-15 09:27:27 +0530 | [diff] [blame] | 101 | void createIPAddressObjects(); |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 102 | |
| 103 | /* @brief Gets all the ip addresses. |
| 104 | * @returns the list of ipaddress. |
| 105 | */ |
| 106 | const AddressMap& getAddresses() const { return addrs; } |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 107 | |
Ratan Gupta | 87c1398 | 2017-06-15 09:27:27 +0530 | [diff] [blame] | 108 | /** Set value of DHCPEnabled */ |
| 109 | bool dHCPEnabled(bool value) override; |
| 110 | |
Ratan Gupta | 5978dd1 | 2017-07-25 13:47:13 +0530 | [diff] [blame] | 111 | /** @brief create Vlan interface. |
| 112 | * @param[in] id- VLAN identifier. |
| 113 | */ |
| 114 | void createVLAN(VlanId id); |
| 115 | |
Ratan Gupta | 92bc2fe | 2017-07-26 22:40:21 +0530 | [diff] [blame^] | 116 | /** @brief load the vlan info from the system |
| 117 | * and creates the ip address dbus objects. |
| 118 | * @param[in] vlanID- VLAN identifier. |
| 119 | */ |
| 120 | void loadVLAN(VlanId vlanID); |
| 121 | |
Ratan Gupta | 2b10653 | 2017-07-25 16:05:02 +0530 | [diff] [blame] | 122 | /** @brief write the network conf file with the in-memory objects. |
| 123 | */ |
| 124 | void writeConfigurationFile(); |
| 125 | |
Ratan Gupta | 87c1398 | 2017-06-15 09:27:27 +0530 | [diff] [blame] | 126 | using EthernetInterfaceIntf::dHCPEnabled; |
Ratan Gupta | 5978dd1 | 2017-07-25 13:47:13 +0530 | [diff] [blame] | 127 | using EthernetInterfaceIntf::interfaceName; |
| 128 | |
Ratan Gupta | 3d3e4fc | 2017-07-25 13:38:19 +0530 | [diff] [blame] | 129 | protected: |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 130 | |
| 131 | /** @brief get the info of the ethernet interface. |
| 132 | * @return tuple having the link speed,autonegotiation,duplexmode . |
| 133 | */ |
| 134 | |
| 135 | InterfaceInfo getInterfaceInfo() const; |
| 136 | |
| 137 | /** @brief get the mac address of the interface. |
| 138 | * @return macaddress on success |
| 139 | */ |
| 140 | |
| 141 | std::string getMACAddress() const; |
| 142 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 143 | /** @brief construct the ip address dbus object path. |
| 144 | * @param[in] addressType - Type of ip address. |
Ratan Gupta | 65e5abe | 2017-05-23 13:20:44 +0530 | [diff] [blame] | 145 | * @param[in] ipaddress - IP address. |
| 146 | * @param[in] prefixLength - Length of prefix. |
| 147 | * @param[in] gateway - Gateway addess. |
| 148 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 149 | * @return path of the address object. |
| 150 | */ |
| 151 | |
Ratan Gupta | 65e5abe | 2017-05-23 13:20:44 +0530 | [diff] [blame] | 152 | std::string generateObjectPath(IP::Protocol addressType, |
| 153 | const std::string& ipaddress, |
| 154 | uint8_t prefixLength, |
| 155 | const std::string& gateway) const; |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 156 | |
Ratan Gupta | 65e5abe | 2017-05-23 13:20:44 +0530 | [diff] [blame] | 157 | /** @brief generates the id by doing hash of ipaddress, |
| 158 | * prefixlength and the gateway. |
| 159 | * @param[in] ipaddress - IP address. |
| 160 | * @param[in] prefixLength - Length of prefix. |
| 161 | * @param[in] gateway - Gateway addess. |
| 162 | * @return hash string. |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 163 | */ |
| 164 | |
Ratan Gupta | 65e5abe | 2017-05-23 13:20:44 +0530 | [diff] [blame] | 165 | static std::string generateId(const std::string& ipaddress, |
| 166 | uint8_t prefixLength, |
| 167 | const std::string& gateway); |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 168 | |
Ratan Gupta | 2b10653 | 2017-07-25 16:05:02 +0530 | [diff] [blame] | 169 | /** @brief write the dhcp section **/ |
| 170 | void writeDHCPSection(std::fstream& stream);; |
| 171 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 172 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 173 | sdbusplus::bus::bus& bus; |
| 174 | |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 175 | /** @brief Network Manager object. */ |
| 176 | Manager& manager; |
| 177 | |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 178 | /** @brief Persistent map of IPAddress dbus objects and their names */ |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 179 | AddressMap addrs; |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 180 | |
Ratan Gupta | 5978dd1 | 2017-07-25 13:47:13 +0530 | [diff] [blame] | 181 | /** @brief Persistent map of VLAN interface dbus objects and their names */ |
| 182 | VlanInterfaceMap vlanInterfaces; |
| 183 | |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 184 | /** @brief Dbus object path */ |
| 185 | std::string objPath; |
| 186 | |
| 187 | friend class TestEthernetInterface; |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | } // namespace network |
| 191 | } // namespace phosphor |