blob: a1b4d9a96a64598b9ebdfa3773968d1f87a2a4f0 [file] [log] [blame]
Asmitha Karunanithibe2bdec2021-05-13 02:54:29 -05001#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
10namespace phosphor
11{
12namespace network
13{
14
15class HypEthInterface;
16
17using biosAttrName = std::string;
18using biosAttrType = std::string;
19using biosAttrIsReadOnly = bool;
20using biosAttrDispName = std::string;
21using biosAttrHelpText = std::string;
22using biosAttrMenuPath = std::string;
23using biosAttrCurrValue = std::variant<int64_t, std::string>;
24using biosAttrDefaultValue = std::variant<int64_t, std::string>;
25using biosAttrOptions =
26 std::tuple<std::string, std::variant<int64_t, std::string>>;
27
28using biosTableType = std::map<biosAttrName, biosAttrCurrValue>;
29using BiosBaseTableItemType =
30 std::pair<biosAttrName,
31 std::tuple<biosAttrType, biosAttrIsReadOnly, biosAttrDispName,
32 biosAttrHelpText, biosAttrMenuPath, biosAttrCurrValue,
33 biosAttrDefaultValue, std::vector<biosAttrOptions>>>;
34using BiosBaseTableType = std::vector<BiosBaseTableItemType>;
35
36enum 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 */
52class 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),
Asmitha Karunanithia6c07572022-05-05 03:19:45 -050070 event(event), objectPath(path){};
Asmitha Karunanithibe2bdec2021-05-13 02:54:29 -050071
72 /** @brief Get the BaseBiosTable attributes
73 *
74 * @return attributes list
75 */
76 biosTableType getBIOSTableAttrs();
77
78 /** @brief Set specific attribute and its value to
79 * the biosTableAttrs data member
80 *
81 * @param[in] attrName - attribute name in biosTableAttrs
82 * @param[in] attrValue - attribute value
83 * @param[in] attrType - attribute type
84 *
85 */
86 void setBIOSTableAttr(std::string attrName,
87 std::variant<std::string, int64_t> attrValue,
88 std::string attrType);
89
Asmitha Karunanithia6c07572022-05-05 03:19:45 -050090 /** @brief Method to set all the interface 0 attributes
91 * to its default value in biosTableAttrs data member
92 */
93 void setDefaultBIOSTableAttrsOnIntf(const std::string& intf);
94
95 /** @brief Method to set the hostname attribute
96 * to its default value in biosTableAttrs
97 * data member
98 */
99 void setDefaultHostnameInBIOSTableAttrs();
100
101 /** @brief Fetch the interface and the ipaddress details
102 * from the Bios table and create the hyp ethernet interfaces
103 * dbus object.
104 */
105 void createIfObjects();
106
107 protected:
Asmitha Karunanithibe2bdec2021-05-13 02:54:29 -0500108 /**
109 * @brief get Dbus Prop
110 *
111 * @param[in] objectName - dbus Object
112 * @param[in] interface - dbus Interface
113 * @param[in] kw - keyword under the interface
114 *
115 * @return dbus call response
116 */
117 auto getDBusProp(const std::string& objectName,
118 const std::string& interface, const std::string& kw);
119
Asmitha Karunanithibe2bdec2021-05-13 02:54:29 -0500120 /** @brief Setter method for biosTableAttrs data member
121 * GET operation on the BIOS table to
122 * read all the hyp attrbutes (name, value pair)
123 * and push them to biosTableAttrs data member
124 */
125 void setBIOSTableAttrs();
126
127 /** @brief sdbusplus DBus bus connection. */
128 sdbusplus::bus::bus& bus;
129
130 /** sdevent Event handle. */
131 sdeventplus::Event& event;
132
133 /** @brief object path */
134 std::string objectPath;
135
136 /** @brief Persistent map of EthernetInterface dbus
137 * objects and their names
138 */
139 std::map<std::string, std::shared_ptr<HypEthInterface>> interfaces;
140
Asmitha Karunanithibe2bdec2021-05-13 02:54:29 -0500141 /** @brief map of bios table attrs and values */
142 std::map<biosAttrName, biosAttrCurrValue> biosTableAttrs;
143};
144
145} // namespace network
146} // namespace phosphor