blob: ca21ece5b2b88c30a72bc4ccd705cbaba5e70a15 [file] [log] [blame]
Asmitha Karunanithibe2bdec2021-05-13 02:54:29 -05001#pragma once
2
Asmitha Karunanithieb40f082021-07-22 06:13:04 -05003#include "hyp_sys_config.hpp"
Asmitha Karunanithibe2bdec2021-05-13 02:54:29 -05004#include "types.hpp"
5#include "util.hpp"
6
7#include <sdbusplus/bus.hpp>
8#include <sdbusplus/server/object.hpp>
9#include <sdeventplus/source/event.hpp>
10
11namespace phosphor
12{
13namespace network
14{
15
16class HypEthInterface;
Asmitha Karunanithieb40f082021-07-22 06:13:04 -050017class HypSysConfig;
Asmitha Karunanithibe2bdec2021-05-13 02:54:29 -050018
19using biosAttrName = std::string;
20using biosAttrType = std::string;
21using biosAttrIsReadOnly = bool;
22using biosAttrDispName = std::string;
23using biosAttrHelpText = std::string;
24using biosAttrMenuPath = std::string;
25using biosAttrCurrValue = std::variant<int64_t, std::string>;
26using biosAttrDefaultValue = std::variant<int64_t, std::string>;
27using biosAttrOptions =
28 std::tuple<std::string, std::variant<int64_t, std::string>>;
29
30using biosTableType = std::map<biosAttrName, biosAttrCurrValue>;
31using BiosBaseTableItemType =
32 std::pair<biosAttrName,
33 std::tuple<biosAttrType, biosAttrIsReadOnly, biosAttrDispName,
34 biosAttrHelpText, biosAttrMenuPath, biosAttrCurrValue,
35 biosAttrDefaultValue, std::vector<biosAttrOptions>>>;
36using BiosBaseTableType = std::vector<BiosBaseTableItemType>;
37
38enum BiosBaseTableIndex
39{
40 biosBaseAttrType = 0,
41 biosBaseReadonlyStatus,
42 biosBaseDisplayName,
43 biosBaseDescription,
44 biosBaseMenuPath,
45 biosBaseCurrValue,
46 biosBaseDefaultValue,
47 biosBaseOptions
48};
49
Asmitha Karunanithieb40f082021-07-22 06:13:04 -050050using SystemConfPtr = std::unique_ptr<HypSysConfig>;
51
Asmitha Karunanithibe2bdec2021-05-13 02:54:29 -050052/** @class Manager
53 * @brief Implementation for the
54 * xyz.openbmc_project.Network.Hypervisor DBus API.
55 */
56class HypNetworkMgr
57{
58 public:
59 HypNetworkMgr() = delete;
60 HypNetworkMgr(const HypNetworkMgr&) = delete;
61 HypNetworkMgr& operator=(const HypNetworkMgr&) = delete;
62 HypNetworkMgr(HypNetworkMgr&&) = delete;
63 HypNetworkMgr& operator=(HypNetworkMgr&&) = delete;
64 virtual ~HypNetworkMgr() = 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] event - event.
69 * @param[in] path - Path to attach at.
70 */
Patrick Williamsc38b0712022-07-22 19:26:54 -050071 HypNetworkMgr(sdbusplus::bus_t& bus, sdeventplus::Event& event,
Asmitha Karunanithibe2bdec2021-05-13 02:54:29 -050072 const char* path) :
73 bus(bus),
Asmitha Karunanithia6c07572022-05-05 03:19:45 -050074 event(event), objectPath(path){};
Asmitha Karunanithibe2bdec2021-05-13 02:54:29 -050075
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
Asmitha Karunanithia6c07572022-05-05 03:19:45 -050094 /** @brief Method to set all the interface 0 attributes
95 * to its default value in biosTableAttrs data member
96 */
97 void setDefaultBIOSTableAttrsOnIntf(const std::string& intf);
98
99 /** @brief Method to set the hostname attribute
100 * to its default value in biosTableAttrs
101 * data member
102 */
103 void setDefaultHostnameInBIOSTableAttrs();
104
105 /** @brief Fetch the interface and the ipaddress details
106 * from the Bios table and create the hyp ethernet interfaces
107 * dbus object.
108 */
109 void createIfObjects();
110
Asmitha Karunanithieb40f082021-07-22 06:13:04 -0500111 /** @brief Creates system config object
112 */
113 void createSysConfObj();
114
115 /** @brief gets the system conf object.
116 *
117 */
118 const SystemConfPtr& getSystemConf()
119 {
120 return systemConf;
121 }
122
Asmitha Karunanithia6c07572022-05-05 03:19:45 -0500123 protected:
Asmitha Karunanithibe2bdec2021-05-13 02:54:29 -0500124 /**
125 * @brief get Dbus Prop
126 *
127 * @param[in] objectName - dbus Object
128 * @param[in] interface - dbus Interface
129 * @param[in] kw - keyword under the interface
130 *
131 * @return dbus call response
132 */
133 auto getDBusProp(const std::string& objectName,
134 const std::string& interface, const std::string& kw);
135
Asmitha Karunanithibe2bdec2021-05-13 02:54:29 -0500136 /** @brief Setter method for biosTableAttrs data member
137 * GET operation on the BIOS table to
138 * read all the hyp attrbutes (name, value pair)
139 * and push them to biosTableAttrs data member
140 */
141 void setBIOSTableAttrs();
142
143 /** @brief sdbusplus DBus bus connection. */
Patrick Williamsc38b0712022-07-22 19:26:54 -0500144 sdbusplus::bus_t& bus;
Asmitha Karunanithibe2bdec2021-05-13 02:54:29 -0500145
146 /** sdevent Event handle. */
147 sdeventplus::Event& event;
148
149 /** @brief object path */
150 std::string objectPath;
151
Asmitha Karunanithieb40f082021-07-22 06:13:04 -0500152 /** @brief pointer to system conf object. */
153 SystemConfPtr systemConf = nullptr;
154
Asmitha Karunanithibe2bdec2021-05-13 02:54:29 -0500155 /** @brief Persistent map of EthernetInterface dbus
156 * objects and their names
157 */
158 std::map<std::string, std::shared_ptr<HypEthInterface>> interfaces;
159
Asmitha Karunanithibe2bdec2021-05-13 02:54:29 -0500160 /** @brief map of bios table attrs and values */
161 std::map<biosAttrName, biosAttrCurrValue> biosTableAttrs;
162};
163
164} // namespace network
165} // namespace phosphor