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 class HypEthInterface;
16 class HypSysConfig;
17 
18 using biosAttrName = std::string;
19 using biosAttrType = std::string;
20 using biosAttrIsReadOnly = bool;
21 using biosAttrDispName = std::string;
22 using biosAttrHelpText = std::string;
23 using biosAttrMenuPath = std::string;
24 using biosAttrCurrValue = std::variant<int64_t, std::string>;
25 using biosAttrDefaultValue = std::variant<int64_t, std::string>;
26 using biosAttrOptions =
27     std::tuple<std::string, std::variant<int64_t, std::string>>;
28 
29 using biosTableType = std::map<biosAttrName, biosAttrCurrValue>;
30 using BiosBaseTableItemType =
31     std::pair<biosAttrName,
32               std::tuple<biosAttrType, biosAttrIsReadOnly, biosAttrDispName,
33                          biosAttrHelpText, biosAttrMenuPath, biosAttrCurrValue,
34                          biosAttrDefaultValue, std::vector<biosAttrOptions>>>;
35 using BiosBaseTableType = std::vector<BiosBaseTableItemType>;
36 
37 enum BiosBaseTableIndex
38 {
39     biosBaseAttrType = 0,
40     biosBaseReadonlyStatus,
41     biosBaseDisplayName,
42     biosBaseDescription,
43     biosBaseMenuPath,
44     biosBaseCurrValue,
45     biosBaseDefaultValue,
46     biosBaseOptions
47 };
48 
49 using SystemConfPtr = std::unique_ptr<HypSysConfig>;
50 using ethIntfMapType = stdplus::string_umap<std::unique_ptr<HypEthInterface>>;
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] path - Path to attach at.
69      */
HypNetworkMgr(sdbusplus::bus_t & bus,const char * path)70     HypNetworkMgr(sdbusplus::bus_t& bus, const char* path) :
71         bus(bus), objectPath(path){};
72 
73     /** @brief Get the BaseBiosTable attributes
74      *
75      * @return attributes list
76      */
getBIOSTableAttrs()77     inline biosTableType getBIOSTableAttrs()
78     {
79         return biosTableAttrs;
80     }
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 Get the ethernet interfaces list data member
95      *
96      * @return ethernet interfaces list
97      */
getEthIntfList()98     inline const auto& getEthIntfList()
99     {
100         return interfaces;
101     }
102 
103     /** @brief Method to set all the interface 0 attributes
104      *         to its default value in biosTableAttrs data member
105      */
106     void setDefaultBIOSTableAttrsOnIntf(const std::string& intf);
107 
108     /** @brief Method to set the hostname attribute
109      *         to its default value in biosTableAttrs
110      *         data member
111      */
112     void setDefaultHostnameInBIOSTableAttrs();
113 
114     /** @brief Fetch the interface and the ipaddress details
115      *         from the Bios table and create the hyp ethernet interfaces
116      *         dbus object.
117      */
118     void createIfObjects();
119 
120     /** @brief Creates system config object
121      */
122     void createSysConfObj();
123 
124     /** @brief gets the system conf object.
125      *
126      */
getSystemConf()127     const SystemConfPtr& getSystemConf()
128     {
129         return systemConf;
130     }
131 
132   protected:
133     /**
134      * @brief get Dbus Prop
135      *
136      * @param[in] objectName - dbus Object
137      * @param[in] interface - dbus Interface
138      * @param[in] kw - keyword under the interface
139      *
140      * @return dbus call response
141      */
142     auto getDBusProp(const std::string& objectName,
143                      const std::string& interface, const std::string& kw);
144 
145     /** @brief Setter method for biosTableAttrs data member
146      *         GET operation on the BIOS table to
147      *         read all the hyp attributes (name, value pair)
148      *         and push them to biosTableAttrs data member
149      */
150     void setBIOSTableAttrs();
151 
152     /** @brief sdbusplus DBus bus connection. */
153     sdbusplus::bus_t& bus;
154 
155     /** @brief object path */
156     std::string objectPath;
157 
158     /** @brief pointer to system conf object. */
159     SystemConfPtr systemConf = nullptr;
160 
161     /** @brief Persistent map of EthernetInterface dbus
162      *         objects and their names
163      */
164     ethIntfMapType interfaces;
165 
166     /** @brief map of bios table attrs and values */
167     std::map<biosAttrName, biosAttrCurrValue> biosTableAttrs;
168 };
169 
170 } // namespace network
171 } // namespace phosphor
172