blob: 9729078db277eb10f96b61246e9a48dbadd1833f [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>
11
12namespace ipmi
13{
14namespace rmcpp
15{
16constexpr uint16_t defaultPort = 623;
17} // namespace rmcpp
18} // namespace ipmi
Tom Joseph807c7e82017-02-09 19:49:38 +053019
20namespace eventloop
21{
Alvin Wang8c0bf982019-10-21 10:30:07 +080022using DbusObjectPath = std::string;
23using DbusService = std::string;
24using DbusInterface = std::string;
25using ObjectTree =
26 std::map<DbusObjectPath, std::map<DbusService, std::vector<DbusInterface>>>;
27using Value = std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t,
28 int64_t, uint64_t, double, std::string>;
29// VLANs are a 12-bit value
30constexpr uint16_t VLAN_VALUE_MASK = 0x0fff;
31constexpr auto MAPPER_BUS_NAME = "xyz.openbmc_project.ObjectMapper";
32constexpr auto MAPPER_OBJ = "/xyz/openbmc_project/object_mapper";
33constexpr auto MAPPER_INTF = "xyz.openbmc_project.ObjectMapper";
34constexpr auto PATH_ROOT = "/xyz/openbmc_project/network";
35constexpr auto INTF_VLAN = "xyz.openbmc_project.Network.VLAN";
36constexpr auto INTF_ETHERNET = "xyz.openbmc_project.Network.EthernetInterface";
37constexpr auto METHOD_GET = "Get";
38constexpr auto PROP_INTF = "org.freedesktop.DBus.Properties";
Tom Joseph807c7e82017-02-09 19:49:38 +053039
Tom Joseph807c7e82017-02-09 19:49:38 +053040class EventLoop
41{
Vernon Mauery9e801a22018-10-12 13:20:49 -070042 public:
Vernon Mauerycbccb052018-10-24 13:52:22 -070043 explicit EventLoop(std::shared_ptr<boost::asio::io_context> io) : io(io)
44 {
45 }
46 EventLoop() = delete;
Vernon Mauery9e801a22018-10-12 13:20:49 -070047 ~EventLoop() = default;
48 EventLoop(const EventLoop&) = delete;
49 EventLoop& operator=(const EventLoop&) = delete;
50 EventLoop(EventLoop&&) = delete;
51 EventLoop& operator=(EventLoop&&) = delete;
Tom Joseph807c7e82017-02-09 19:49:38 +053052
Vernon Mauery9e801a22018-10-12 13:20:49 -070053 /** @brief Initialise the event loop and add the handler for incoming
54 * IPMI packets.
Vernon Mauery9e801a22018-10-12 13:20:49 -070055 *
56 * @return EXIT_SUCCESS on success and EXIT_FAILURE on failure.
57 */
Vernon Mauerycbccb052018-10-24 13:52:22 -070058 int startEventLoop();
Tom Joseph807c7e82017-02-09 19:49:38 +053059
Vernon Maueryd92bc322019-03-15 15:24:30 -070060 /** @brief Set up the socket (if systemd has not already) and
61 * make sure that the bus name matches the specified channel
62 */
63 int setupSocket(std::shared_ptr<sdbusplus::asio::connection>& bus,
64 std::string iface,
65 uint16_t reqPort = ipmi::rmcpp::defaultPort);
66
Vernon Mauery9e801a22018-10-12 13:20:49 -070067 private:
Vernon Mauery7a0142c2018-11-09 08:38:16 -080068 /** @brief async handler for incoming udp packets */
69 void handleRmcpPacket();
70
71 /** @brief register the async handler for incoming udp packets */
72 void startRmcpReceive();
73
Alvin Wang8c0bf982019-10-21 10:30:07 +080074 /** @brief get vlanid */
75 int getVLANID(const std::string channel);
76
Vernon Mauerycbccb052018-10-24 13:52:22 -070077 /** @brief boost::asio io context to run with
78 */
79 std::shared_ptr<boost::asio::io_context> io;
80
Vernon Mauery7a0142c2018-11-09 08:38:16 -080081 /** @brief boost::asio udp socket
Vernon Mauery9e801a22018-10-12 13:20:49 -070082 */
Vernon Mauery7a0142c2018-11-09 08:38:16 -080083 std::shared_ptr<boost::asio::ip::udp::socket> udpSocket = nullptr;
Tom Joseph807c7e82017-02-09 19:49:38 +053084};
85
86} // namespace eventloop