network_manager: Cleanup map type

We want the map type to be a unique_map that allows and type of strings
for comparsion.

Change-Id: I22158e85d90256fe827a0a2fb389acb68bc909a1
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/network_manager.cpp b/src/network_manager.cpp
index b3b28b4..bba2ca2 100644
--- a/src/network_manager.cpp
+++ b/src/network_manager.cpp
@@ -131,7 +131,7 @@
                 log<level::ERR>(msg.c_str());
                 continue;
             }
-            auto it = interfaces.find(std::string(interfaceName));
+            auto it = interfaces.find(interfaceName);
             if (it == interfaces.end())
             {
                 auto msg = fmt::format("Missing interface({}) for VLAN({}): {}",
@@ -146,7 +146,7 @@
         objPath /= interface;
         config::Parser config(config::pathForIntfConf(confDir, interface));
 
-        auto intf = std::make_shared<phosphor::network::EthernetInterface>(
+        auto intf = std::make_unique<phosphor::network::EthernetInterface>(
             bus, objPath.string(), config, *this);
 
         intf->createIPAddressObjects();
diff --git a/src/network_manager.hpp b/src/network_manager.hpp
index 2d5b255..3002a20 100644
--- a/src/network_manager.hpp
+++ b/src/network_manager.hpp
@@ -1,9 +1,9 @@
 #pragma once
-
 #include "dhcp_configuration.hpp"
 #include "ethernet_interface.hpp"
 #include "routing_table.hpp"
 #include "system_configuration.hpp"
+#include "types.hpp"
 #include "vlan_interface.hpp"
 #include "xyz/openbmc_project/Network/VLAN/Create/server.hpp"
 
@@ -12,7 +12,7 @@
 #include <memory>
 #include <sdbusplus/bus.hpp>
 #include <string>
-#include <utility>
+#include <string_view>
 #include <vector>
 #include <xyz/openbmc_project/Common/FactoryReset/server.hpp>
 
@@ -57,7 +57,7 @@
      */
     Manager(sdbusplus::bus_t& bus, const char* objPath, const std::string& dir);
 
-    ObjectPath vlan(IntfName interfaceName, uint32_t id) override;
+    ObjectPath vlan(std::string interfaceName, uint32_t id) override;
 
     /** @brief write the network conf file with the in-memory objects.
      */
@@ -143,9 +143,9 @@
      * @param[in] intf - the interface name to check.
      * @return true if found, false otherwise.
      */
-    bool hasInterface(const std::string& intf)
+    inline bool hasInterface(std::string_view intf)
     {
-        return (interfaces.find(intf) != interfaces.end());
+        return interfaces.find(intf) != interfaces.end();
     }
 
     /** @brief Get the routing table owned by the manager
@@ -172,7 +172,7 @@
 
     /** @brief Persistent map of EthernetInterface dbus objects and their names
      */
-    std::map<IntfName, std::shared_ptr<EthernetInterface>> interfaces;
+    string_umap<std::unique_ptr<EthernetInterface>> interfaces;
 
     /** @brief BMC network reset - resets network configuration for BMC. */
     void reset() override;
diff --git a/src/types.hpp b/src/types.hpp
index c64407a..5465381 100644
--- a/src/types.hpp
+++ b/src/types.hpp
@@ -9,6 +9,7 @@
 #include <sdeventplus/clock.hpp>
 #include <sdeventplus/utility/timer.hpp>
 #include <string>
+#include <unordered_map>
 #include <unordered_set>
 #include <variant>
 
@@ -26,8 +27,6 @@
 // configuration takes 3-4 sec to reconfigure at most.
 constexpr auto refreshTimeout = 4s;
 
-using IntfName = std::string;
-
 using Addr_t = ifaddrs*;
 
 struct AddrDeleter
@@ -53,9 +52,17 @@
 // Byte representations for common address types in network byte order
 using InAddrAny = std::variant<struct in_addr, struct in6_addr>;
 
-using InterfaceList = std::unordered_set<IntfName>;
+using InterfaceList = std::unordered_set<std::string>;
 
 using Timer = sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>;
 
+struct string_hash : public std::hash<std::string_view>
+{
+    using is_transparent = void;
+};
+template <typename V>
+using string_umap =
+    std::unordered_map<std::string, V, string_hash, std::equal_to<>>;
+
 } // namespace network
 } // namespace phosphor
diff --git a/test/mock_network_manager.hpp b/test/mock_network_manager.hpp
index 337af88..559a667 100644
--- a/test/mock_network_manager.hpp
+++ b/test/mock_network_manager.hpp
@@ -13,12 +13,12 @@
 void initializeTimers();
 void refreshObjects();
 
-class MockManager : public phosphor::network::Manager
+class MockManager : public Manager
 {
   public:
     MockManager(sdbusplus::bus_t& bus, const char* path,
                 const std::string& dir) :
-        phosphor::network::Manager(bus, path, dir)
+        Manager(bus, path, dir)
     {
     }
 
@@ -33,9 +33,8 @@
             // normal ethernet interface
             objPath /= interface;
             config::Parser config(config::pathForIntfConf(confDir, interface));
-            auto intf =
-                std::make_shared<phosphor::network::MockEthernetInterface>(
-                    bus, objPath.string(), config, *this, true);
+            auto intf = std::make_unique<MockEthernetInterface>(
+                bus, objPath.string(), config, *this, true);
             intf->createIPAddressObjects();
             intf->createStaticNeighborObjects();
             intf->loadNameServers(config);