1 #pragma once
2 #include "hyp_sys_config.hpp"
3 
4 #include <sdbusplus/bus.hpp>
5 #include <sdbusplus/server/object.hpp>
6 
7 namespace phosphor
8 {
9 namespace network
10 {
11 
12 class HypEthInterface;
13 class HypSysConfig;
14 
15 using biosAttrName = std::string;
16 using biosAttrType = std::string;
17 using biosAttrIsReadOnly = bool;
18 using biosAttrDispName = std::string;
19 using biosAttrHelpText = std::string;
20 using biosAttrMenuPath = std::string;
21 using biosAttrCurrValue = std::variant<int64_t, std::string>;
22 using biosAttrDefaultValue = std::variant<int64_t, std::string>;
23 using biosAttrOptions =
24     std::tuple<std::string, std::variant<int64_t, std::string>>;
25 
26 using biosTableType = std::map<biosAttrName, biosAttrCurrValue>;
27 using BiosBaseTableItemType =
28     std::pair<biosAttrName,
29               std::tuple<biosAttrType, biosAttrIsReadOnly, biosAttrDispName,
30                          biosAttrHelpText, biosAttrMenuPath, biosAttrCurrValue,
31                          biosAttrDefaultValue, std::vector<biosAttrOptions>>>;
32 using BiosBaseTableType = std::vector<BiosBaseTableItemType>;
33 
34 enum BiosBaseTableIndex
35 {
36     biosBaseAttrType = 0,
37     biosBaseReadonlyStatus,
38     biosBaseDisplayName,
39     biosBaseDescription,
40     biosBaseMenuPath,
41     biosBaseCurrValue,
42     biosBaseDefaultValue,
43     biosBaseOptions
44 };
45 
46 using SystemConfPtr = std::unique_ptr<HypSysConfig>;
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] path - Path to attach at.
65      */
66     HypNetworkMgr(sdbusplus::bus_t& bus, const char* path) :
67         bus(bus), objectPath(path){};
68 
69     /** @brief Get the BaseBiosTable attributes
70      *
71      * @return attributes list
72      */
73     biosTableType getBIOSTableAttrs();
74 
75     /** @brief Set specific attribute and its value to
76      *         the biosTableAttrs data member
77      *
78      * @param[in] attrName  - attribute name in biosTableAttrs
79      * @param[in] attrValue - attribute value
80      * @param[in] attrType  - attribute type
81      *
82      */
83     void setBIOSTableAttr(std::string attrName,
84                           std::variant<std::string, int64_t> attrValue,
85                           std::string attrType);
86 
87     /** @brief Method to set all the interface 0 attributes
88      *         to its default value in biosTableAttrs data member
89      */
90     void setDefaultBIOSTableAttrsOnIntf(const std::string& intf);
91 
92     /** @brief Method to set the hostname attribute
93      *         to its default value in biosTableAttrs
94      *         data member
95      */
96     void setDefaultHostnameInBIOSTableAttrs();
97 
98     /** @brief Fetch the interface and the ipaddress details
99      *         from the Bios table and create the hyp ethernet interfaces
100      *         dbus object.
101      */
102     void createIfObjects();
103 
104     /** @brief Creates system config object
105      */
106     void createSysConfObj();
107 
108     /** @brief gets the system conf object.
109      *
110      */
111     const SystemConfPtr& getSystemConf()
112     {
113         return systemConf;
114     }
115 
116   protected:
117     /**
118      * @brief get Dbus Prop
119      *
120      * @param[in] objectName - dbus Object
121      * @param[in] interface - dbus Interface
122      * @param[in] kw - keyword under the interface
123      *
124      * @return dbus call response
125      */
126     auto getDBusProp(const std::string& objectName,
127                      const std::string& interface, const std::string& kw);
128 
129     /** @brief Setter method for biosTableAttrs data member
130      *         GET operation on the BIOS table to
131      *         read all the hyp attrbutes (name, value pair)
132      *         and push them to biosTableAttrs data member
133      */
134     void setBIOSTableAttrs();
135 
136     /** @brief sdbusplus DBus bus connection. */
137     sdbusplus::bus_t& bus;
138 
139     /** @brief object path */
140     std::string objectPath;
141 
142     /** @brief pointer to system conf object. */
143     SystemConfPtr systemConf = nullptr;
144 
145     /** @brief Persistent map of EthernetInterface dbus
146      *         objects and their names
147      */
148     std::map<std::string, std::shared_ptr<HypEthInterface>> interfaces;
149 
150     /** @brief map of bios table attrs and values */
151     std::map<biosAttrName, biosAttrCurrValue> biosTableAttrs;
152 };
153 
154 } // namespace network
155 } // namespace phosphor
156