1 #pragma once
2 
3 #include "hyp_sys_config.hpp"
4 #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 
11 namespace phosphor
12 {
13 namespace network
14 {
15 
16 class HypEthInterface;
17 class HypSysConfig;
18 
19 using biosAttrName = std::string;
20 using biosAttrType = std::string;
21 using biosAttrIsReadOnly = bool;
22 using biosAttrDispName = std::string;
23 using biosAttrHelpText = std::string;
24 using biosAttrMenuPath = std::string;
25 using biosAttrCurrValue = std::variant<int64_t, std::string>;
26 using biosAttrDefaultValue = std::variant<int64_t, std::string>;
27 using biosAttrOptions =
28     std::tuple<std::string, std::variant<int64_t, std::string>>;
29 
30 using biosTableType = std::map<biosAttrName, biosAttrCurrValue>;
31 using BiosBaseTableItemType =
32     std::pair<biosAttrName,
33               std::tuple<biosAttrType, biosAttrIsReadOnly, biosAttrDispName,
34                          biosAttrHelpText, biosAttrMenuPath, biosAttrCurrValue,
35                          biosAttrDefaultValue, std::vector<biosAttrOptions>>>;
36 using BiosBaseTableType = std::vector<BiosBaseTableItemType>;
37 
38 enum BiosBaseTableIndex
39 {
40     biosBaseAttrType = 0,
41     biosBaseReadonlyStatus,
42     biosBaseDisplayName,
43     biosBaseDescription,
44     biosBaseMenuPath,
45     biosBaseCurrValue,
46     biosBaseDefaultValue,
47     biosBaseOptions
48 };
49 
50 using SystemConfPtr = std::unique_ptr<HypSysConfig>;
51 
52 /** @class Manager
53  *  @brief Implementation for the
54  *         xyz.openbmc_project.Network.Hypervisor DBus API.
55  */
56 class 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      */
71     HypNetworkMgr(sdbusplus::bus_t& bus, sdeventplus::Event& event,
72                   const char* path) :
73         bus(bus),
74         event(event), objectPath(path){};
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     /** @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 
111     /** @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 
123   protected:
124     /**
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 
136     /** @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. */
144     sdbusplus::bus_t& bus;
145 
146     /**  sdevent Event handle. */
147     sdeventplus::Event& event;
148 
149     /** @brief object path */
150     std::string objectPath;
151 
152     /** @brief pointer to system conf object. */
153     SystemConfPtr systemConf = nullptr;
154 
155     /** @brief Persistent map of EthernetInterface dbus
156      *         objects and their names
157      */
158     std::map<std::string, std::shared_ptr<HypEthInterface>> interfaces;
159 
160     /** @brief map of bios table attrs and values */
161     std::map<biosAttrName, biosAttrCurrValue> biosTableAttrs;
162 };
163 
164 } // namespace network
165 } // namespace phosphor
166