Implement the Client create interface

This commit also implement the D-Bus service which would be
used for snmp client configuration and would add the
snmp manager/trap receiver D-Bus objects under
namespace /xyz/openbmc_project/network/snmp/manager/

It implements the delete interface for SNMP client D-Bus Object.

Resolves openbmc/openbmc#3057

Change-Id: I0df7b1475f81325b9ac497c1fb350c3f62329686
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
diff --git a/test/Makefile.am.include b/test/Makefile.am.include
index 9c5435a..7926d09 100644
--- a/test/Makefile.am.include
+++ b/test/Makefile.am.include
@@ -2,17 +2,37 @@
 	-I${top_srcdir} \
 	-I${top_builddir} \
 	-Igtest \
-	$(GTEST_CPPFLAGS) \
-	$(CODE_COVERAGE_CPPFLAGS)
+	$(GTEST_CPPFLAGS)
 
-AM_LDFLAGS = -lgtest_main -lgtest -lstdc++fs \
+AM_CFLAGS = \
+	$(PTHREAD_CFLAGS) \
+	$(CODE_COVERAGE_CFLAGS) \
+	$(SDBUSPLUS_CFLAGS) \
+	$(PHOSPHOR_LOGGING_CFLAGS) \
+	$(PHOSPHOR_DBUS_INTERFACES_CFLAGS)
+
+AM_CXXFLAGS = \
+	$(PTHREAD_CXXFLAGS) \
+	$(CODE_COVERAGE_CXXFLAGS) \
+	$(SDBUSPLUS_CXXFLAGS) \
+	$(PHOSPHOR_LOGGING_CXXFLAGS) \
+	$(PHOSPHOR_DBUS_INTERFACES_CXXFLAGS)
+
+AM_LDFLAGS = \
+	-lgtest_main -lgtest -lstdc++fs \
+	$(PTHREAD_CFLAGS) \
+	$(SDBUSPLUS_LIBS) \
+	$(PHOSPHOR_LOGGING_LIBS) \
+	$(PHOSPHOR_DBUS_INTERFACES_LIBS) \
 	$(OESDK_TESTCASE_FLAGS) \
 	$(CODE_COVERAGE_LIBS)
 
-AM_CXXFLAGS = $(PTHREAD_CFLAGS) \
-	$(CODE_COVERAGE_CXXFLAGS)
-
 test_notification_SOURCES = \
-	%reldir%/test_error_notification.cpp
+	%reldir%/test_error_notification.cpp \
+	%reldir%/test_snmp_conf_manager.cpp
+
+test_notification_LDADD = $(top_builddir)/phosphor_network_snmpconf-snmp_conf_manager.o \
+	$(top_builddir)/phosphor_network_snmpconf-snmp_client.o \
+	$(top_builddir)/xyz/openbmc_project/Network/Client/Create/phosphor_network_snmpconf-server.o
 
 check_PROGRAMS += %reldir%/notification
diff --git a/test/test_snmp_conf_manager.cpp b/test/test_snmp_conf_manager.cpp
new file mode 100644
index 0000000..ab29215
--- /dev/null
+++ b/test/test_snmp_conf_manager.cpp
@@ -0,0 +1,91 @@
+#include "snmp_conf_manager.hpp"
+
+#include "xyz/openbmc_project/Common/error.hpp"
+
+#include <gtest/gtest.h>
+#include <sdbusplus/bus.hpp>
+
+namespace phosphor
+{
+namespace network
+{
+namespace snmp
+{
+
+class TestSNMPConfManager : public testing::Test
+{
+  public:
+    sdbusplus::bus::bus bus;
+    ConfManager manager;
+    std::string confDir;
+    TestSNMPConfManager() :
+        bus(sdbusplus::bus::new_default()), manager(bus, ""){};
+
+    ~TestSNMPConfManager()
+    {
+    }
+
+    void createSNMPClient(std::string ipaddress, uint16_t port)
+    {
+        manager.client(ipaddress, port);
+    }
+
+    ClientList &getSNMPClients()
+    {
+        return manager.clients;
+    }
+
+    void deleteSNMPClient(std::string ipaddress)
+    {
+        if (manager.clients.find(ipaddress) != manager.clients.end())
+        {
+            auto &it = manager.clients[ipaddress];
+            it->delete_();
+        }
+    }
+};
+
+// Add single SNMP client
+TEST_F(TestSNMPConfManager, AddSNMPClient)
+{
+    using namespace sdbusplus::xyz::openbmc_project::Common::Error;
+
+    createSNMPClient("192.168.1.1", 24);
+
+    auto &clients = getSNMPClients();
+    EXPECT_EQ(1, clients.size());
+    EXPECT_EQ(true, clients.find("192.168.1.1") != clients.end());
+}
+
+// Add multiple SNMP client
+TEST_F(TestSNMPConfManager, AddMultipleSNMPClient)
+{
+    using namespace sdbusplus::xyz::openbmc_project::Common::Error;
+
+    createSNMPClient("192.168.1.1", 24);
+    createSNMPClient("192.168.1.2", 24);
+
+    auto &clients = getSNMPClients();
+    EXPECT_EQ(2, clients.size());
+    EXPECT_EQ(true, clients.find("192.168.1.1") != clients.end());
+    EXPECT_EQ(true, clients.find("192.168.1.2") != clients.end());
+}
+
+// Delete SNMP client
+TEST_F(TestSNMPConfManager, DeleteSNMPClient)
+{
+    using namespace sdbusplus::xyz::openbmc_project::Common::Error;
+
+    createSNMPClient("192.168.1.1", 24);
+    createSNMPClient("192.168.1.2", 24);
+
+    auto &clients = getSNMPClients();
+    EXPECT_EQ(2, clients.size());
+    deleteSNMPClient("192.168.1.1");
+    EXPECT_EQ(1, clients.size());
+    EXPECT_EQ(true, clients.find("192.168.1.2") != clients.end());
+}
+
+} // namespace snmp
+} // namespce network
+} // namespace phosphor