Add testcases for hypervisor nw manager
This commit includes three changes:
1. Add testcases for hypervisor nw manager
2. Removal of vmi_if_count support, as it is no longer
available in the bios table
3. Add methods to set default values to bios table
attributes
Tested.
Signed-off-by: Asmitha Karunanithi <asmitk01@in.ibm.com>
Change-Id: I78397f653658c88097e4566632b0ce36c7b3861b
diff --git a/src/ibm/hypervisor-network-mgr-src/hyp_network_manager.cpp b/src/ibm/hypervisor-network-mgr-src/hyp_network_manager.cpp
index ad0b8b4..4923cac 100644
--- a/src/ibm/hypervisor-network-mgr-src/hyp_network_manager.cpp
+++ b/src/ibm/hypervisor-network-mgr-src/hyp_network_manager.cpp
@@ -82,6 +82,19 @@
}
}
+void HypNetworkMgr::setDefaultBIOSTableAttrsOnIntf(const std::string& intf)
+{
+ biosTableAttrs.emplace("vmi_" + intf + "_ipv4_ipaddr", "0.0.0.0");
+ biosTableAttrs.emplace("vmi_" + intf + "_ipv4_gateway", "0.0.0.0");
+ biosTableAttrs.emplace("vmi_" + intf + "_ipv4_prefix_length", 0);
+ biosTableAttrs.emplace("vmi_" + intf + "_ipv4_method", "IPv4Static");
+}
+
+void HypNetworkMgr::setDefaultHostnameInBIOSTableAttrs()
+{
+ biosTableAttrs.emplace("vmi_hostname", "");
+}
+
void HypNetworkMgr::setBIOSTableAttrs()
{
try
@@ -176,10 +189,6 @@
&std::get<biosBaseCurrValue>(item.second));
if (currValue != nullptr)
{
- if (item.first == "vmi_if_count")
- {
- intfCount = *currValue;
- }
biosTableAttrs.emplace(item.first, *currValue);
}
}
@@ -210,11 +219,6 @@
}
}
-uint16_t HypNetworkMgr::getIntfCount()
-{
- return intfCount;
-}
-
biosTableType HypNetworkMgr::getBIOSTableAttrs()
{
return biosTableAttrs;
@@ -224,21 +228,17 @@
{
setBIOSTableAttrs();
- if (intfCount == 1)
+ if ((getBIOSTableAttrs()).size() == 0)
{
- // TODO: create eth0 object
- log<level::INFO>("Create eth0 object");
+ setDefaultHostnameInBIOSTableAttrs();
}
- else if (intfCount == 2)
- {
- // TODO: create eth0 and eth1 objects
- log<level::INFO>("Create eth0 and eth1 objects");
- }
- else
- {
- log<level::ERR>("More than 2 Interfaces");
- return;
- }
+
+ // The hypervisor can support maximum of
+ // 2 ethernet interfaces. Both eth0/1 objects are
+ // created during init time to support the static
+ // network configurations on the both.
+ // create eth0 and eth1 objects
+ log<level::INFO>("Create eth0 and eth1 objects");
}
} // namespace network
diff --git a/src/ibm/hypervisor-network-mgr-src/hyp_network_manager.hpp b/src/ibm/hypervisor-network-mgr-src/hyp_network_manager.hpp
index fa56d96..a1b4d9a 100644
--- a/src/ibm/hypervisor-network-mgr-src/hyp_network_manager.hpp
+++ b/src/ibm/hypervisor-network-mgr-src/hyp_network_manager.hpp
@@ -67,11 +67,7 @@
HypNetworkMgr(sdbusplus::bus::bus& bus, sdeventplus::Event& event,
const char* path) :
bus(bus),
- event(event), objectPath(path)
- {
- // Create the hypervisor eth interface objects
- createIfObjects();
- };
+ event(event), objectPath(path){};
/** @brief Get the BaseBiosTable attributes
*
@@ -91,7 +87,24 @@
std::variant<std::string, int64_t> attrValue,
std::string attrType);
- private:
+ /** @brief Method to set all the interface 0 attributes
+ * to its default value in biosTableAttrs data member
+ */
+ void setDefaultBIOSTableAttrsOnIntf(const std::string& intf);
+
+ /** @brief Method to set the hostname attribute
+ * to its default value in biosTableAttrs
+ * data member
+ */
+ void setDefaultHostnameInBIOSTableAttrs();
+
+ /** @brief Fetch the interface and the ipaddress details
+ * from the Bios table and create the hyp ethernet interfaces
+ * dbus object.
+ */
+ void createIfObjects();
+
+ protected:
/**
* @brief get Dbus Prop
*
@@ -104,18 +117,6 @@
auto getDBusProp(const std::string& objectName,
const std::string& interface, const std::string& kw);
- /** @brief Fetch the interface and the ipaddress details
- * from the Bios table and create the hyp ethernet interfaces
- * dbus object.
- */
- void createIfObjects();
-
- /** @brief Get the hypervisor eth interfaces count
- *
- * @return number of interfaces
- */
- uint16_t getIntfCount();
-
/** @brief Setter method for biosTableAttrs data member
* GET operation on the BIOS table to
* read all the hyp attrbutes (name, value pair)
@@ -137,9 +138,6 @@
*/
std::map<std::string, std::shared_ptr<HypEthInterface>> interfaces;
- /** @brief interface count */
- uint16_t intfCount;
-
/** @brief map of bios table attrs and values */
std::map<biosAttrName, biosAttrCurrValue> biosTableAttrs;
};
diff --git a/src/ibm/hypervisor-network-mgr-src/hyp_network_manager_main.cpp b/src/ibm/hypervisor-network-mgr-src/hyp_network_manager_main.cpp
index ddb515b..d0d7b7d 100644
--- a/src/ibm/hypervisor-network-mgr-src/hyp_network_manager_main.cpp
+++ b/src/ibm/hypervisor-network-mgr-src/hyp_network_manager_main.cpp
@@ -24,6 +24,9 @@
phosphor::network::HypNetworkMgr manager(bus, event,
DEFAULT_HYP_NW_OBJPATH);
+ // Create the hypervisor eth interface objects
+ manager.createIfObjects();
+
bus.request_name(HYP_DEFAULT_NETWORK_BUSNAME);
event.loop();