1 #pragma once
2 
3 #include "hyp_ethernet_interface.hpp"
4 #include "hyp_sys_config.hpp"
5 
6 #include <sdbusplus/bus.hpp>
7 #include <sdbusplus/server/object.hpp>
8 #include <stdplus/str/maps.hpp>
9 
10 namespace phosphor
11 {
12 namespace network
13 {
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 using ethIntfMapType = stdplus::string_umap<std::unique_ptr<HypEthInterface>>;
48 
49 /** @class Manager
50  *  @brief Implementation for the
51  *         xyz.openbmc_project.Network.Hypervisor DBus API.
52  */
53 class HypNetworkMgr
54 {
55   public:
56     HypNetworkMgr() = delete;
57     HypNetworkMgr(const HypNetworkMgr&) = delete;
58     HypNetworkMgr& operator=(const HypNetworkMgr&) = delete;
59     HypNetworkMgr(HypNetworkMgr&&) = delete;
60     HypNetworkMgr& operator=(HypNetworkMgr&&) = delete;
61     virtual ~HypNetworkMgr() = default;
62 
63     /** @brief Constructor to put object onto bus at a dbus path.
64      *  @param[in] bus - Bus to attach to.
65      *  @param[in] path - Path to attach at.
66      */
HypNetworkMgr(sdbusplus::bus_t & bus,const char * path)67     HypNetworkMgr(sdbusplus::bus_t& bus, const char* path) :
68         bus(bus), objectPath(path) {};
69 
70     /** @brief Get the BaseBiosTable attributes
71      *
72      * @return attributes list
73      */
getBIOSTableAttrs()74     inline biosTableType getBIOSTableAttrs()
75     {
76         return biosTableAttrs;
77     }
78 
79     /** @brief Set specific attribute and its value to
80      *         the biosTableAttrs data member
81      *
82      * @param[in] attrName  - attribute name in biosTableAttrs
83      * @param[in] attrValue - attribute value
84      * @param[in] attrType  - attribute type
85      *
86      */
87     void setBIOSTableAttr(std::string attrName,
88                           std::variant<std::string, int64_t> attrValue,
89                           std::string attrType);
90 
91     /** @brief Get the ethernet interfaces list data member
92      *
93      * @return ethernet interfaces list
94      */
getEthIntfList()95     inline const auto& getEthIntfList()
96     {
97         return interfaces;
98     }
99 
100     /** @brief Method to set all the interface 0 attributes
101      *         to its default value in biosTableAttrs data member
102      */
103     void setDefaultBIOSTableAttrsOnIntf(const std::string& intf);
104 
105     /** @brief Method to set the hostname attribute
106      *         to its default value in biosTableAttrs
107      *         data member
108      */
109     void setDefaultHostnameInBIOSTableAttrs();
110 
111     /** @brief Fetch the interface and the ipaddress details
112      *         from the Bios table and create the hyp ethernet interfaces
113      *         dbus object.
114      */
115     void createIfObjects();
116 
117     /** @brief Creates system config object
118      */
119     void createSysConfObj();
120 
121     /** @brief gets the system conf object.
122      *
123      */
getSystemConf()124     const SystemConfPtr& getSystemConf()
125     {
126         return systemConf;
127     }
128 
129   protected:
130     /**
131      * @brief get Dbus Prop
132      *
133      * @param[in] objectName - dbus Object
134      * @param[in] interface - dbus Interface
135      * @param[in] kw - keyword under the interface
136      *
137      * @return dbus call response
138      */
139     auto getDBusProp(const std::string& objectName,
140                      const std::string& interface, const std::string& kw);
141 
142     /** @brief Setter method for biosTableAttrs data member
143      *         GET operation on the BIOS table to
144      *         read all the hyp attributes (name, value pair)
145      *         and push them to biosTableAttrs data member
146      */
147     void setBIOSTableAttrs();
148 
149     /** @brief sdbusplus DBus bus connection. */
150     sdbusplus::bus_t& bus;
151 
152     /** @brief object path */
153     std::string objectPath;
154 
155     /** @brief pointer to system conf object. */
156     SystemConfPtr systemConf = nullptr;
157 
158     /** @brief Persistent map of EthernetInterface dbus
159      *         objects and their names
160      */
161     ethIntfMapType interfaces;
162 
163     /** @brief map of bios table attrs and values */
164     std::map<biosAttrName, biosAttrCurrValue> biosTableAttrs;
165 };
166 
167 } // namespace network
168 } // namespace phosphor
169