blob: 60b4434119142174d532f7154e8c0eaee22955f5 [file] [log] [blame]
Tom Joseph807c7e82017-02-09 19:49:38 +05301#pragma once
2
Vernon Mauery9e801a22018-10-12 13:20:49 -07003#include "sol/sol_manager.hpp"
4
Tom Joseph807c7e82017-02-09 19:49:38 +05305#include <systemd/sd-event.h>
Vernon Mauery9e801a22018-10-12 13:20:49 -07006
Vernon Mauerycbccb052018-10-24 13:52:22 -07007#include <boost/asio/io_context.hpp>
Tom Joseph807c7e82017-02-09 19:49:38 +05308#include <chrono>
9#include <map>
Vernon Maueryd92bc322019-03-15 15:24:30 -070010#include <sdbusplus/asio/connection.hpp>
Andrew Geissler7408e762020-05-17 08:56:05 -050011#include <string>
Vernon Maueryd92bc322019-03-15 15:24:30 -070012
13namespace ipmi
14{
15namespace rmcpp
16{
17constexpr uint16_t defaultPort = 623;
18} // namespace rmcpp
19} // namespace ipmi
Tom Joseph807c7e82017-02-09 19:49:38 +053020
21namespace eventloop
22{
Alvin Wang8c0bf982019-10-21 10:30:07 +080023using DbusObjectPath = std::string;
24using DbusService = std::string;
25using DbusInterface = std::string;
26using ObjectTree =
27 std::map<DbusObjectPath, std::map<DbusService, std::vector<DbusInterface>>>;
28using Value = std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t,
29 int64_t, uint64_t, double, std::string>;
30// VLANs are a 12-bit value
31constexpr uint16_t VLAN_VALUE_MASK = 0x0fff;
32constexpr auto MAPPER_BUS_NAME = "xyz.openbmc_project.ObjectMapper";
33constexpr auto MAPPER_OBJ = "/xyz/openbmc_project/object_mapper";
34constexpr auto MAPPER_INTF = "xyz.openbmc_project.ObjectMapper";
35constexpr auto PATH_ROOT = "/xyz/openbmc_project/network";
36constexpr auto INTF_VLAN = "xyz.openbmc_project.Network.VLAN";
37constexpr auto INTF_ETHERNET = "xyz.openbmc_project.Network.EthernetInterface";
38constexpr auto METHOD_GET = "Get";
39constexpr auto PROP_INTF = "org.freedesktop.DBus.Properties";
Tom Joseph807c7e82017-02-09 19:49:38 +053040
Tom Joseph807c7e82017-02-09 19:49:38 +053041class EventLoop
42{
Vernon Mauery9e801a22018-10-12 13:20:49 -070043 public:
Vernon Mauerycbccb052018-10-24 13:52:22 -070044 explicit EventLoop(std::shared_ptr<boost::asio::io_context> io) : io(io)
45 {
46 }
47 EventLoop() = delete;
Vernon Mauery9e801a22018-10-12 13:20:49 -070048 ~EventLoop() = default;
49 EventLoop(const EventLoop&) = delete;
50 EventLoop& operator=(const EventLoop&) = delete;
51 EventLoop(EventLoop&&) = delete;
52 EventLoop& operator=(EventLoop&&) = delete;
Tom Joseph807c7e82017-02-09 19:49:38 +053053
Vernon Mauery9e801a22018-10-12 13:20:49 -070054 /** @brief Initialise the event loop and add the handler for incoming
55 * IPMI packets.
Vernon Mauery9e801a22018-10-12 13:20:49 -070056 *
57 * @return EXIT_SUCCESS on success and EXIT_FAILURE on failure.
58 */
Vernon Mauerycbccb052018-10-24 13:52:22 -070059 int startEventLoop();
Tom Joseph807c7e82017-02-09 19:49:38 +053060
Vernon Maueryd92bc322019-03-15 15:24:30 -070061 /** @brief Set up the socket (if systemd has not already) and
62 * make sure that the bus name matches the specified channel
63 */
64 int setupSocket(std::shared_ptr<sdbusplus::asio::connection>& bus,
65 std::string iface,
66 uint16_t reqPort = ipmi::rmcpp::defaultPort);
67
Vernon Mauery9e801a22018-10-12 13:20:49 -070068 private:
Vernon Mauery7a0142c2018-11-09 08:38:16 -080069 /** @brief async handler for incoming udp packets */
70 void handleRmcpPacket();
71
72 /** @brief register the async handler for incoming udp packets */
73 void startRmcpReceive();
74
Alvin Wang8c0bf982019-10-21 10:30:07 +080075 /** @brief get vlanid */
76 int getVLANID(const std::string channel);
77
Vernon Mauerycbccb052018-10-24 13:52:22 -070078 /** @brief boost::asio io context to run with
79 */
80 std::shared_ptr<boost::asio::io_context> io;
81
Vernon Mauery7a0142c2018-11-09 08:38:16 -080082 /** @brief boost::asio udp socket
Vernon Mauery9e801a22018-10-12 13:20:49 -070083 */
Vernon Mauery7a0142c2018-11-09 08:38:16 -080084 std::shared_ptr<boost::asio::ip::udp::socket> udpSocket = nullptr;
Tom Joseph807c7e82017-02-09 19:49:38 +053085};
86
87} // namespace eventloop