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