Asmitha Karunanithi | be2bdec | 2021-05-13 02:54:29 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "types.hpp" |
| 4 | #include "util.hpp" |
| 5 | |
| 6 | #include <sdbusplus/bus.hpp> |
| 7 | #include <sdbusplus/server/object.hpp> |
| 8 | #include <sdeventplus/source/event.hpp> |
| 9 | |
| 10 | namespace phosphor |
| 11 | { |
| 12 | namespace network |
| 13 | { |
| 14 | |
| 15 | class HypEthInterface; |
| 16 | |
| 17 | using biosAttrName = std::string; |
| 18 | using biosAttrType = std::string; |
| 19 | using biosAttrIsReadOnly = bool; |
| 20 | using biosAttrDispName = std::string; |
| 21 | using biosAttrHelpText = std::string; |
| 22 | using biosAttrMenuPath = std::string; |
| 23 | using biosAttrCurrValue = std::variant<int64_t, std::string>; |
| 24 | using biosAttrDefaultValue = std::variant<int64_t, std::string>; |
| 25 | using biosAttrOptions = |
| 26 | std::tuple<std::string, std::variant<int64_t, std::string>>; |
| 27 | |
| 28 | using biosTableType = std::map<biosAttrName, biosAttrCurrValue>; |
| 29 | using BiosBaseTableItemType = |
| 30 | std::pair<biosAttrName, |
| 31 | std::tuple<biosAttrType, biosAttrIsReadOnly, biosAttrDispName, |
| 32 | biosAttrHelpText, biosAttrMenuPath, biosAttrCurrValue, |
| 33 | biosAttrDefaultValue, std::vector<biosAttrOptions>>>; |
| 34 | using BiosBaseTableType = std::vector<BiosBaseTableItemType>; |
| 35 | |
| 36 | enum BiosBaseTableIndex |
| 37 | { |
| 38 | biosBaseAttrType = 0, |
| 39 | biosBaseReadonlyStatus, |
| 40 | biosBaseDisplayName, |
| 41 | biosBaseDescription, |
| 42 | biosBaseMenuPath, |
| 43 | biosBaseCurrValue, |
| 44 | biosBaseDefaultValue, |
| 45 | biosBaseOptions |
| 46 | }; |
| 47 | |
| 48 | /** @class Manager |
| 49 | * @brief Implementation for the |
| 50 | * xyz.openbmc_project.Network.Hypervisor DBus API. |
| 51 | */ |
| 52 | class HypNetworkMgr |
| 53 | { |
| 54 | public: |
| 55 | HypNetworkMgr() = delete; |
| 56 | HypNetworkMgr(const HypNetworkMgr&) = delete; |
| 57 | HypNetworkMgr& operator=(const HypNetworkMgr&) = delete; |
| 58 | HypNetworkMgr(HypNetworkMgr&&) = delete; |
| 59 | HypNetworkMgr& operator=(HypNetworkMgr&&) = delete; |
| 60 | virtual ~HypNetworkMgr() = default; |
| 61 | |
| 62 | /** @brief Constructor to put object onto bus at a dbus path. |
| 63 | * @param[in] bus - Bus to attach to. |
| 64 | * @param[in] event - event. |
| 65 | * @param[in] path - Path to attach at. |
| 66 | */ |
| 67 | HypNetworkMgr(sdbusplus::bus::bus& bus, sdeventplus::Event& event, |
| 68 | const char* path) : |
| 69 | bus(bus), |
| 70 | event(event), objectPath(path) |
| 71 | { |
| 72 | // Create the hypervisor eth interface objects |
| 73 | createIfObjects(); |
| 74 | }; |
| 75 | |
| 76 | /** @brief Get the BaseBiosTable attributes |
| 77 | * |
| 78 | * @return attributes list |
| 79 | */ |
| 80 | biosTableType getBIOSTableAttrs(); |
| 81 | |
| 82 | /** @brief Set specific attribute and its value to |
| 83 | * the biosTableAttrs data member |
| 84 | * |
| 85 | * @param[in] attrName - attribute name in biosTableAttrs |
| 86 | * @param[in] attrValue - attribute value |
| 87 | * @param[in] attrType - attribute type |
| 88 | * |
| 89 | */ |
| 90 | void setBIOSTableAttr(std::string attrName, |
| 91 | std::variant<std::string, int64_t> attrValue, |
| 92 | std::string attrType); |
| 93 | |
| 94 | private: |
| 95 | /** |
| 96 | * @brief get Dbus Prop |
| 97 | * |
| 98 | * @param[in] objectName - dbus Object |
| 99 | * @param[in] interface - dbus Interface |
| 100 | * @param[in] kw - keyword under the interface |
| 101 | * |
| 102 | * @return dbus call response |
| 103 | */ |
| 104 | auto getDBusProp(const std::string& objectName, |
| 105 | const std::string& interface, const std::string& kw); |
| 106 | |
| 107 | /** @brief Fetch the interface and the ipaddress details |
| 108 | * from the Bios table and create the hyp ethernet interfaces |
| 109 | * dbus object. |
| 110 | */ |
| 111 | void createIfObjects(); |
| 112 | |
| 113 | /** @brief Get the hypervisor eth interfaces count |
| 114 | * |
| 115 | * @return number of interfaces |
| 116 | */ |
| 117 | uint16_t getIntfCount(); |
| 118 | |
| 119 | /** @brief Setter method for biosTableAttrs data member |
| 120 | * GET operation on the BIOS table to |
| 121 | * read all the hyp attrbutes (name, value pair) |
| 122 | * and push them to biosTableAttrs data member |
| 123 | */ |
| 124 | void setBIOSTableAttrs(); |
| 125 | |
| 126 | /** @brief sdbusplus DBus bus connection. */ |
| 127 | sdbusplus::bus::bus& bus; |
| 128 | |
| 129 | /** sdevent Event handle. */ |
| 130 | sdeventplus::Event& event; |
| 131 | |
| 132 | /** @brief object path */ |
| 133 | std::string objectPath; |
| 134 | |
| 135 | /** @brief Persistent map of EthernetInterface dbus |
| 136 | * objects and their names |
| 137 | */ |
| 138 | std::map<std::string, std::shared_ptr<HypEthInterface>> interfaces; |
| 139 | |
| 140 | /** @brief interface count */ |
| 141 | uint16_t intfCount; |
| 142 | |
| 143 | /** @brief map of bios table attrs and values */ |
| 144 | std::map<biosAttrName, biosAttrCurrValue> biosTableAttrs; |
| 145 | }; |
| 146 | |
| 147 | } // namespace network |
| 148 | } // namespace phosphor |