SatCat5
igmp_server.h
Go to the documentation of this file.
1 // Copyright 2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
30 
31 #pragma once
32 
33 #include <satcat5/eth_plugin.h>
34 #include <satcat5/ip_core.h>
35 #include <satcat5/polling.h>
36 
37 namespace satcat5 {
38  namespace igmp {
41  struct Group {
42  satcat5::ip::Addr group;
43  SATCAT5_PMASK_TYPE mask_active;
44  SATCAT5_PMASK_TYPE mask_rcvd1;
45  SATCAT5_PMASK_TYPE mask_rcvd2;
46  u16 query_count, query_timer;
47 
48  constexpr Group()
49  : group(satcat5::ip::ADDR_NONE)
50  , mask_active(0), mask_rcvd1(0), mask_rcvd2(0)
51  , query_count(0), query_timer(0) {}
52 
53  void reset(const satcat5::ip::Addr& addr);
54  void rcvd(SATCAT5_PMASK_TYPE mask);
55  void refresh();
56  };
57 
72  class Server
74  , protected satcat5::poll::Timer {
75  public:
90  Server(
92  satcat5::ip::Dispatch* iface,
93  satcat5::igmp::Group* groups,
94  unsigned gcount);
95  ~Server() SATCAT5_OPTIONAL_DTOR;
96 
98  void flush();
99 
102  inline void force_version(u8 version)
103  { m_vmax = version; }
104 
106  SATCAT5_PMASK_TYPE get_mask(const satcat5::ip::Addr& addr) const;
107 
109  bool is_querier() const;
110 
112  void query(satcat5::eth::PluginPacket& pkt) override;
113 
118  inline void set_mdly(u8 fast, u8 slow)
119  { m_mdly_fast = fast; m_mdly_slow = slow; }
120 
122  u8 version() const;
123 
124  protected:
125  void timer_event() override;
126  satcat5::igmp::Group* find_or_create(const satcat5::ip::Addr& group);
127  satcat5::igmp::Group* find_match(const satcat5::ip::Addr& group) const;
128  void rcvd_igmp(satcat5::eth::PluginPacket& pkt);
129  void rcvd_mcast(satcat5::eth::PluginPacket& pkt);
130  void send_query(satcat5::igmp::Group* group, bool first);
131 
132  satcat5::ip::Dispatch* const m_iface;
133  satcat5::igmp::Group* const m_groups;
134  const u16 m_gcount; // Size of working buffer
135  u8 m_status; // Status flag
136  u8 m_mdly_fast; // Single-group query delay
137  u8 m_mdly_slow; // General query delay
138  u8 m_vmin, m_vmax; // Current IGMP version
139  u32 m_query_timer; // Countdown to next outgoing query
140  u32 m_window_timer; // Countdown to end of query window
141  };
142 
144  template <unsigned SIZE>
145  class ServerStatic final : public satcat5::igmp::Server {
146  public:
150  satcat5::ip::Dispatch* iface)
151  : Server(sw, iface, m_buff, SIZE) {}
152 
153  protected:
154  satcat5::igmp::Group m_buff[SIZE];
155  };
156  }
157 }
Ethernet switch plugin API.
Definition: eth_plugin.h:166
A shared-memory Ethernet switch based on the MultiBuffer class.
Definition: eth_switch.h:93
Router/Server for the Internet Group Management Protocol (IGMP).
Definition: igmp_server.h:74
bool is_querier() const
Are we the current querier?
Definition: igmp_server.cc:91
Server(satcat5::eth::SwitchCore *sw, satcat5::ip::Dispatch *iface, satcat5::igmp::Group *groups, unsigned gcount)
Link this plugin to the network switch or router.
Definition: igmp_server.cc:50
void query(satcat5::eth::PluginPacket &pkt) override
Packet-processing callback from PluginCore.
Definition: igmp_server.cc:95
void force_version(u8 version)
Force a specific IGMP version for compatibility or testing.
Definition: igmp_server.h:102
u8 version() const
Current IGMP version for this network.
Definition: igmp_server.cc:103
void set_mdly(u8 fast, u8 slow)
Set the max-delay parameter for outgoing queries.
Definition: igmp_server.h:118
void flush()
Flush all existing routes and reset status.
Definition: igmp_server.cc:75
SATCAT5_PMASK_TYPE get_mask(const satcat5::ip::Addr &addr) const
Get the port-mask for a given multicast IP address.
Definition: igmp_server.cc:81
void timer_event() override
Child class MUST override this method.
Definition: igmp_server.cc:107
Statically-allocated wrapper for ip::IgmpServer.
Definition: igmp_server.h:145
ServerStatic(satcat5::eth::SwitchCore *sw, satcat5::ip::Dispatch *iface)
Link this plugin to the network switch or router.
Definition: igmp_server.h:148
Protocol handler and dispatch unit for Internet Protocol v4 (IPv4).
Definition: ip_dispatch.h:43
Timer objects are polled after a fixed delay or at a regular interval.
Definition: polling.h:213
Plugins for the software-defined Ethernet switch and IPv4 router.
#define SATCAT5_PMASK_TYPE
Set the integer type used to identify source and destination ports.
Definition: eth_switch.h:41
Core event-processing loop for SatCat5 software.
Ephemeral data structure provided to plugin callbacks.
Definition: eth_plugin.h:48
Router state for monitoring IGMP multicast subscriptions.
Definition: igmp_server.h:41
IPv4 address is a 32-bit unsigned integer.
Definition: ip_core.h:15