blob: 738131438eec5a3090f55ec04fd970eb2a565fb6 [file] [log] [blame]
Ratan Gupta1dc91782018-04-19 16:47:12 +05301#pragma once
2
3#include "snmp_client.hpp"
4
5#include <xyz/openbmc_project/Network/Client/Create/server.hpp>
6#include <sdbusplus/bus.hpp>
7
Ratan Gupta212f53e2018-04-30 17:28:05 +05308#include <experimental/filesystem>
Ratan Gupta1dc91782018-04-19 16:47:12 +05309#include <string>
10
11namespace phosphor
12{
13namespace network
14{
15namespace snmp
16{
Ratan Gupta212f53e2018-04-30 17:28:05 +053017
Ratan Gupta1dc91782018-04-19 16:47:12 +053018using IPAddress = std::string;
19using ClientList = std::map<IPAddress, std::unique_ptr<Client>>;
Ratan Gupta212f53e2018-04-30 17:28:05 +053020namespace fs = std::experimental::filesystem;
Ratan Gupta1dc91782018-04-19 16:47:12 +053021
22namespace details
23{
24
25using CreateIface = sdbusplus::server::object::object<
26 sdbusplus::xyz::openbmc_project::Network::Client::server::Create>;
27
28} // namespace details
29
30class TestSNMPConfManager;
31/** @class Manager
32 * @brief OpenBMC SNMP config implementation.
33 */
34class ConfManager : public details::CreateIface
35{
36 public:
37 ConfManager() = delete;
38 ConfManager(const ConfManager&) = delete;
39 ConfManager& operator=(const ConfManager&) = delete;
40 ConfManager(ConfManager&&) = delete;
41 ConfManager& operator=(ConfManager&&) = delete;
42 virtual ~ConfManager() = default;
43
Ratan Gupta212f53e2018-04-30 17:28:05 +053044 /** @brief Constructor to put object onto bus at a D-Bus path.
Ratan Gupta1dc91782018-04-19 16:47:12 +053045 * @param[in] bus - Bus to attach to.
46 * @param[in] objPath - Path to attach at.
47 */
48 ConfManager(sdbusplus::bus::bus& bus, const char* objPath);
49
50 /** @brief Function to create snmp manager details D-Bus object.
51 * @param[in] address- IP address/Hostname.
52 * @param[in] port - network port.
Ratan Guptad84e3272018-09-06 16:52:52 +053053 * @returns D-Bus object path
Ratan Gupta1dc91782018-04-19 16:47:12 +053054 */
Ratan Guptad84e3272018-09-06 16:52:52 +053055 std::string client(std::string address, uint16_t port) override;
Ratan Gupta1dc91782018-04-19 16:47:12 +053056
Ratan Gupta212f53e2018-04-30 17:28:05 +053057 /* @brief delete the D-Bus object of the given ipaddress.
Ratan Gupta1dc91782018-04-19 16:47:12 +053058 * @param[in] address - IP address/Hostname.
59 */
60 void deleteSNMPClient(const std::string& address);
61
Ratan Gupta212f53e2018-04-30 17:28:05 +053062 /** @brief Construct manager/client D-Bus objects from their persisted
63 * representations.
64 */
65 void restoreClients();
66
67 /** @brief location of the persisted D-Bus object.*/
68 fs::path dbusPersistentLocation;
69
Ratan Gupta1dc91782018-04-19 16:47:12 +053070 protected:
71 /** @brief generates the id by doing hash of ipaddress, port
72 * @param[in] address - IP address/Hostname.
73 * @param[in] port - network port.
74 * @return hash string.
75 */
76 static std::string generateId(const std::string& address, uint16_t port);
77
78 private:
79 /** @brief sdbusplus DBus bus object. */
80 sdbusplus::bus::bus& bus;
81
82 /** @brief Path of Object. */
83 std::string objectPath;
84
85 /** @brief map of IPAddress dbus objects and their names */
86 ClientList clients;
87
88 friend class TestSNMPConfManager;
89};
90
91} // namespace snmp
92} // namespace network
93} // namespace phosphor