SatCat5
eth_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 // Implemention of "net::Dispatch" for Ethernet frames.
6 
7 #pragma once
8 
9 #include <satcat5/eth_header.h>
10 #include <satcat5/net_core.h>
11 
12 namespace satcat5 {
13  namespace eth {
18  class Dispatch final
19  : public satcat5::net::Dispatch
21  {
22  public:
26  Dispatch(
27  const satcat5::eth::MacAddr& addr,
30  ~Dispatch() SATCAT5_OPTIONAL_DTOR;
31 
35  const satcat5::net::Type& type, unsigned len) override;
36 
40  const satcat5::eth::MacAddr& dst,
41  const satcat5::eth::MacType& type,
42  satcat5::eth::VlanTag vtag = satcat5::eth::VTAG_NONE);
43 
45  void set_macaddr(const satcat5::eth::MacAddr& macaddr);
46 
47  // Other accessors:
48  inline satcat5::eth::MacAddr macaddr() const
49  { return m_addr; }
50  inline satcat5::eth::MacAddr reply_mac() const
51  { return m_reply_srcaddr; }
52  inline satcat5::eth::MacType reply_type() const
53  { return m_reply_type; }
54  inline satcat5::eth::VlanTag reply_vtag() const
55  { return m_reply_vtag; }
56  inline bool reply_is_multicast() const
57  { return m_reply_dstaddr.is_multicast(); }
58  inline void set_default_vid(const satcat5::eth::VlanTag& vtag)
59  { m_default_vid.value = vtag.vid(); }
60 
61  protected:
62  // Event handler for incoming Ethernet frames.
63  void data_rcvd(satcat5::io::Readable* src) override;
64  void data_unlink(satcat5::io::Readable* src) override;
65 
66  // MAC address for this interface.
67  satcat5::eth::MacAddr m_addr;
68 
69  // Sink and source objects for the Ethernet interface.
70  satcat5::io::Writeable* const m_dst;
71  satcat5::io::Readable* m_src;
72 
73  // Other internal state:
74  satcat5::eth::MacAddr m_reply_dstaddr; // Reply destination MAC
75  satcat5::eth::MacAddr m_reply_srcaddr; // Reply source MAC
76  satcat5::eth::MacType m_reply_type; // Reply EtherType
77  satcat5::eth::VlanTag m_reply_vtag; // Reply VLAN
78  satcat5::eth::VlanTag m_default_vid; // Default VID (optional)
79  };
80  }
81 }
Implemention of "net::Dispatch" for Ethernet frames.
Definition: eth_dispatch.h:21
void data_rcvd(satcat5::io::Readable *src) override
The data_rcvd() callback is polled whenever data is available.
void set_macaddr(const satcat5::eth::MacAddr &macaddr)
Set the local MAC-address.
void data_unlink(satcat5::io::Readable *src) override
Unlink this EventListener from the designated source, because the designated Readable object is being...
satcat5::io::Writeable * open_reply(const satcat5::net::Type &type, unsigned len) override
Send a reply to the most recent received frame.
Definition: eth_dispatch.cc:45
satcat5::io::Writeable * open_write(const satcat5::eth::MacAddr &dst, const satcat5::eth::MacType &type, satcat5::eth::VlanTag vtag=satcat5::eth::VTAG_NONE)
Send a frame to the designated Ethernet address/VLAN.
Definition: eth_dispatch.cc:74
Event-handler interface for newly received data.
Definition: io_readable.h:43
Abstract API for reading byte-streams and packets.
Definition: io_readable.h:68
Abstract API for writing byte-streams and packets.
Definition: io_writeable.h:24
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
Type definitions for Ethernet frames and protocol handlers.
Generic network Dispatch API.
An Ethernet MAC address (with serializable interface).
Definition: eth_header.h:29
bool is_multicast() const
Broadcast, L2 multicast, or L3 multicast.
Definition: eth_header.cc:57
EtherType field (uint16) is used a protocol-ID [1536..65535].
Definition: eth_header.h:96
Header contents for an 802.1Q Virtual-LAN tag.
Definition: eth_header.h:124
u16 value
The 16-bit value holds VID, DEI, and PCP fields.
Definition: eth_header.h:126
u16 vid() const
Accessors for each individual field.
Definition: eth_header.h:135
Multipurpose filter for matching fields in network packets.
Definition: net_type.h:38