blob: 1c3d1c28bd299db19af4753ab61cd725e45a7ce6 [file] [log] [blame]
Tom Joseph807c7e82017-02-09 19:49:38 +05301#pragma once
2
Vernon Mauery2085ae02021-06-10 11:51:00 -07003#include "main.hpp"
Vernon Mauery9e801a22018-10-12 13:20:49 -07004#include "sol/sol_manager.hpp"
5
Tom Joseph807c7e82017-02-09 19:49:38 +05306#include <systemd/sd-event.h>
Vernon Mauery9e801a22018-10-12 13:20:49 -07007
Vernon Mauerycbccb052018-10-24 13:52:22 -07008#include <boost/asio/io_context.hpp>
Tom Joseph807c7e82017-02-09 19:49:38 +05309#include <chrono>
10#include <map>
Vernon Maueryd92bc322019-03-15 15:24:30 -070011#include <sdbusplus/asio/connection.hpp>
Andrew Geissler7408e762020-05-17 08:56:05 -050012#include <string>
Vernon Maueryd92bc322019-03-15 15:24:30 -070013
14namespace ipmi
15{
16namespace rmcpp
17{
18constexpr uint16_t defaultPort = 623;
19} // namespace rmcpp
20} // namespace ipmi
Tom Joseph807c7e82017-02-09 19:49:38 +053021
22namespace eventloop
23{
Alvin Wang8c0bf982019-10-21 10:30:07 +080024using DbusObjectPath = std::string;
25using DbusService = std::string;
26using DbusInterface = std::string;
27using ObjectTree =
28 std::map<DbusObjectPath, std::map<DbusService, std::vector<DbusInterface>>>;
29using Value = std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t,
30 int64_t, uint64_t, double, std::string>;
31// VLANs are a 12-bit value
32constexpr uint16_t VLAN_VALUE_MASK = 0x0fff;
33constexpr auto MAPPER_BUS_NAME = "xyz.openbmc_project.ObjectMapper";
34constexpr auto MAPPER_OBJ = "/xyz/openbmc_project/object_mapper";
35constexpr auto MAPPER_INTF = "xyz.openbmc_project.ObjectMapper";
36constexpr auto PATH_ROOT = "/xyz/openbmc_project/network";
37constexpr auto INTF_VLAN = "xyz.openbmc_project.Network.VLAN";
38constexpr auto INTF_ETHERNET = "xyz.openbmc_project.Network.EthernetInterface";
39constexpr auto METHOD_GET = "Get";
40constexpr auto PROP_INTF = "org.freedesktop.DBus.Properties";
Tom Joseph807c7e82017-02-09 19:49:38 +053041
Tom Joseph807c7e82017-02-09 19:49:38 +053042class EventLoop
43{
Vernon Mauery2085ae02021-06-10 11:51:00 -070044 private:
45 struct Private
46 {
47 };
48
Vernon Mauery9e801a22018-10-12 13:20:49 -070049 public:
Vernon Mauery2085ae02021-06-10 11:51:00 -070050 EventLoop(std::shared_ptr<boost::asio::io_context>& io, const Private&) :
51 io(io)
Vernon Mauerycbccb052018-10-24 13:52:22 -070052 {
53 }
54 EventLoop() = delete;
Vernon Mauery9e801a22018-10-12 13:20:49 -070055 ~EventLoop() = default;
56 EventLoop(const EventLoop&) = delete;
57 EventLoop& operator=(const EventLoop&) = delete;
58 EventLoop(EventLoop&&) = delete;
59 EventLoop& operator=(EventLoop&&) = delete;
Tom Joseph807c7e82017-02-09 19:49:38 +053060
Vernon Mauery2085ae02021-06-10 11:51:00 -070061 /**
62 * @brief Get a reference to the singleton EventLoop
63 *
64 * @return EventLoop reference
65 */
66 static EventLoop& get()
67 {
68 static std::shared_ptr<EventLoop> ptr = nullptr;
69 if (!ptr)
70 {
71 std::shared_ptr<boost::asio::io_context> io = getIo();
72 ptr = std::make_shared<EventLoop>(io, Private());
73 }
74 return *ptr;
75 }
76
Vernon Mauery9e801a22018-10-12 13:20:49 -070077 /** @brief Initialise the event loop and add the handler for incoming
78 * IPMI packets.
Vernon Mauery9e801a22018-10-12 13:20:49 -070079 *
80 * @return EXIT_SUCCESS on success and EXIT_FAILURE on failure.
81 */
Vernon Mauerycbccb052018-10-24 13:52:22 -070082 int startEventLoop();
Tom Joseph807c7e82017-02-09 19:49:38 +053083
Vernon Maueryd92bc322019-03-15 15:24:30 -070084 /** @brief Set up the socket (if systemd has not already) and
85 * make sure that the bus name matches the specified channel
86 */
87 int setupSocket(std::shared_ptr<sdbusplus::asio::connection>& bus,
88 std::string iface,
89 uint16_t reqPort = ipmi::rmcpp::defaultPort);
90
Vernon Mauery9e801a22018-10-12 13:20:49 -070091 private:
Vernon Mauery7a0142c2018-11-09 08:38:16 -080092 /** @brief async handler for incoming udp packets */
93 void handleRmcpPacket();
94
95 /** @brief register the async handler for incoming udp packets */
96 void startRmcpReceive();
97
Alvin Wang8c0bf982019-10-21 10:30:07 +080098 /** @brief get vlanid */
99 int getVLANID(const std::string channel);
100
Vernon Mauerycbccb052018-10-24 13:52:22 -0700101 /** @brief boost::asio io context to run with
102 */
103 std::shared_ptr<boost::asio::io_context> io;
104
Vernon Mauery7a0142c2018-11-09 08:38:16 -0800105 /** @brief boost::asio udp socket
Vernon Mauery9e801a22018-10-12 13:20:49 -0700106 */
Vernon Mauery7a0142c2018-11-09 08:38:16 -0800107 std::shared_ptr<boost::asio::ip::udp::socket> udpSocket = nullptr;
Tom Joseph807c7e82017-02-09 19:49:38 +0530108};
109
110} // namespace eventloop