1#include "port_dispatcher.hpp"
2#include "data_indication.hpp"
3#include <vanetza/geonet/data_indication.hpp>
12boost::optional<DataIndication> parse_btp_header(
const geonet::DataIndication& gn_ind, PacketVariant& packet)
14 boost::optional<DataIndication> indication;
16 switch (gn_ind.upper_protocol) {
17 case geonet::UpperProtocol::BTP_A: {
18 HeaderA hdr = parse_btp_a(packet);
19 indication = DataIndication(gn_ind, hdr);
22 case geonet::UpperProtocol::BTP_B: {
23 HeaderB hdr = parse_btp_b(packet);
24 indication = DataIndication(gn_ind, hdr);
37 if (hook !=
nullptr) {
38 auto it = std::find(m_promiscuous_hooks.begin(), m_promiscuous_hooks.end(), hook);
39 if (it == m_promiscuous_hooks.end()) {
40 m_promiscuous_hooks.push_back(hook);
47 m_promiscuous_hooks.remove(hook);
54 m_interactive_handlers[port] = handler;
61 m_non_interactive_handlers[port] = handler;
64void PortDispatcher::indicate(
66 std::unique_ptr<UpPacket> packet)
69 boost::optional<DataIndication> btp_ind = parse_btp_header(gn_ind, *packet);
73 if (btp_ind->source_port) {
74 handler = m_interactive_handlers[btp_ind->destination_port];
76 handler = m_non_interactive_handlers[btp_ind->destination_port];
79 for (PromiscuousHook* hook : m_promiscuous_hooks) {
80 hook->tap_packet(*btp_ind, *packet);
84 handler->indicate(*btp_ind, std::move(packet));
void add_promiscuous_hook(PromiscuousHook *hook)
void remove_promiscuous_hook(PromiscuousHook *)
void set_interactive_handler(port_type, IndicationInterface *)
Hook< const geonet::DataIndication &, const btp::DataIndication * > hook_undispatched
void set_non_interactive_handler(port_type, IndicationInterface *)