SatCat5
udp_dispatch.h
1 // Copyright 2021-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 // UDP Dispatcher sorts incoming messages by port index
6 
7 #pragma once
8 
9 #include <satcat5/ip_dispatch.h>
10 #include <satcat5/udp_core.h>
11 
12 namespace satcat5 {
13  namespace udp {
17  class Dispatch final
18  : public satcat5::net::Protocol
19  , public satcat5::net::Dispatch
20  {
21  public:
24  ~Dispatch() SATCAT5_OPTIONAL_DTOR;
25 
30  const satcat5::net::Type& type, unsigned nbytes) override;
31 
35  satcat5::ip::Address& addr, // Destination IP+MAC
36  const satcat5::udp::Port& src, // Source port
37  const satcat5::udp::Port& dst, // Destination port
38  unsigned len); // Length after UDP header
39 
40  // Other accessors.
41  inline satcat5::eth::ProtoArp* arp() const
42  { return m_iface->arp(); }
43  inline satcat5::eth::Dispatch* eth() const
44  { return m_iface->iface(); }
45  inline satcat5::ip::Dispatch* iface() const
46  { return m_iface; }
47  inline satcat5::ip::Addr ipaddr() const
48  { return m_iface->ipaddr(); }
49  inline satcat5::eth::MacAddr macaddr() const
50  { return m_iface->macaddr(); }
51  inline satcat5::eth::VlanTag reply_vtag() const
52  { return m_iface->reply_vtag(); }
53  inline satcat5::eth::MacAddr reply_mac() const
54  { return m_iface->reply_mac(); }
55  inline bool reply_is_multicast() const
56  { return m_iface->reply_is_multicast(); }
57  inline satcat5::ip::Addr reply_ip() const
58  { return m_iface->reply_ip(); }
59  inline satcat5::udp::Port reply_src() const
60  { return m_reply_src; }
61  inline satcat5::udp::Port reply_dst() const
62  { return m_reply_dst; }
63 
66 
67  protected:
68  // Event handler for incoming IPv4 frames.
69  void frame_rcvd(satcat5::io::LimitedRead& src) override;
70 
71  // Pointer to the parent interface.
72  satcat5::ip::Dispatch* const m_iface;
73 
74  // Next dynamically assigned port.
75  u16 m_next_port;
76 
77  // The current reply parameters.
78  satcat5::udp::Port m_reply_src;
79  satcat5::udp::Port m_reply_dst;
80  };
81  }
82 }
Implemention of "net::Dispatch" for Ethernet frames.
Definition: eth_dispatch.h:21
Protocol handler for Ethernet-to-IPv4 ARP queries and replies.
Definition: eth_arp.h:68
Limited read of next N bytes.
Definition: io_readable.h:255
Abstract API for writing byte-streams and packets.
Definition: io_writeable.h:24
Connection metadata for an IPv4 address.
Definition: ip_address.h:38
Protocol handler and dispatch unit for Internet Protocol v4 (IPv4).
Definition: ip_dispatch.h:43
The "Dispatch" is a generic interface that knows how to read a designated protocol layer and sort inc...
Definition: net_dispatch.h:36
Dispatch()
Constructor and destructor access restricted to children.
Definition: net_dispatch.h:68
A net::Protocol is the counterpart to net::Dispatch that handles a particular data stream,...
Definition: net_protocol.h:28
Dispatcher sorts incoming UDP messages by port index.
Definition: udp_dispatch.h:20
satcat5::io::Writeable * open_write(satcat5::ip::Address &addr, const satcat5::udp::Port &src, const satcat5::udp::Port &dst, unsigned len)
Send a datagram to the designated UDP address and port.
Definition: udp_dispatch.cc:84
satcat5::io::Writeable * open_reply(const satcat5::net::Type &type, unsigned nbytes) override
Reply to the sender of the most recent received message.
Definition: udp_dispatch.cc:69
void frame_rcvd(satcat5::io::LimitedRead &src) override
Dispatch calls frame_rcvd(...) for each incoming frame with with a matching net::Type value.
satcat5::udp::Port next_free_port()
Get the next unclaimed dynamically-allocated port index.
Definition: udp_dispatch.cc:48
An Ethernet MAC address (with serializable interface).
Definition: eth_header.h:29
Header contents for an 802.1Q Virtual-LAN tag.
Definition: eth_header.h:124
IPv4 address is a 32-bit unsigned integer.
Definition: ip_core.h:15
UDP and TCP ports are both 16-bit unsigned integers.
Definition: ip_core.h:119
Multipurpose filter for matching fields in network packets.
Definition: net_type.h:38