SatCat5
eth_address.h
1 // Copyright 2023-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 // Send packets to a specific Ethernet address.
6 
7 #pragma once
8 
9 #include <satcat5/eth_dispatch.h>
10 #include <satcat5/eth_header.h>
11 #include <satcat5/net_address.h>
12 
13 namespace satcat5 {
14  namespace eth {
17  class Address : public satcat5::net::Address {
18  public:
21 
23  void connect(
24  const satcat5::eth::MacAddr& addr,
25  const satcat5::eth::MacType& type,
26  const satcat5::eth::VlanTag& vtag = satcat5::eth::VTAG_NONE);
27 
28  // Required overrides from net::Address:
29  satcat5::net::Dispatch* iface() const override;
30  satcat5::io::Writeable* open_write(unsigned len) override;
31  void close() override;
32  bool ready() const override;
33  bool is_multicast() const override;
34  bool matches_reply_address() const override;
35  bool reply_is_multicast() const override;
36  void save_reply_address() override;
37 
38  // Other accessors.
39  inline satcat5::eth::MacAddr dstmac() const
40  { return m_addr; }
41  inline satcat5::eth::MacAddr srcmac() const
42  { return m_iface->macaddr(); }
43  inline satcat5::eth::MacType etype() const
44  { return m_type; }
45  inline satcat5::eth::VlanTag vtag() const
46  { return m_vtag; }
47  inline satcat5::eth::Header header() const
48  { return {m_addr, srcmac(), m_type, m_vtag}; }
49 
50  protected:
51  satcat5::eth::Dispatch* const m_iface;
52  satcat5::eth::MacAddr m_addr;
53  satcat5::eth::MacType m_type;
54  satcat5::eth::VlanTag m_vtag;
55  };
56 
61  protected:
63  : m_addr(iface) {}
64  ~AddressContainer() {}
65  satcat5::eth::Address m_addr;
66  };
67  }
68 }
Inheritable container for a eth::Address.
Definition: eth_address.h:60
Send packets to a specific Ethernet address.
Definition: eth_address.h:17
bool ready() const override
Is this address object ready for use? Child MUST override this method.
Definition: eth_address.cc:43
void close() override
Close any open connections and revert to idle.
Definition: eth_address.cc:37
void save_reply_address() override
Bind this Address object to the parent interface's current reply address, as provided in net::Dispatc...
Definition: eth_address.cc:62
bool reply_is_multicast() const override
Was the parent interface's incoming message sent to a multicast address? (i.e., Could that message ha...
Definition: eth_address.cc:58
satcat5::net::Dispatch * iface() const override
Fetch a pointer to the underlying interface.
Definition: eth_address.cc:29
void connect(const satcat5::eth::MacAddr &addr, const satcat5::eth::MacType &type, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE)
Connect to the designated address.
Definition: eth_address.cc:19
satcat5::io::Writeable * open_write(unsigned len) override
Open a new frame to the designated address and type.
Definition: eth_address.cc:33
bool matches_reply_address() const override
Does this Address object match the parent interface's current reply address? Multicast destinations s...
Definition: eth_address.cc:52
bool is_multicast() const override
Is the destination a broadcast or multicast address? Child MUST override these method.
Definition: eth_address.cc:48
Address(satcat5::eth::Dispatch *iface)
Link this object to a network interface.
Definition: eth_address.cc:10
Implemention of "net::Dispatch" for Ethernet frames.
Definition: eth_dispatch.h:21
Abstract API for writing byte-streams and packets.
Definition: io_writeable.h:24
Defines a generic API for sending data to a specific destination, such as a MAC address,...
Definition: net_address.h:30
The "Dispatch" is a generic interface that knows how to read a designated protocol layer and sort inc...
Definition: net_dispatch.h:36
Type definitions for Ethernet frames and protocol handlers.
Generic network Address API.
An Ethernet frame header.
Definition: eth_header.h:167
An Ethernet MAC address (with serializable interface).
Definition: eth_header.h:29
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