SatCat5
eth_address.cc
1 // Copyright 2023-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 
6 #include <satcat5/eth_address.h>
7 
9 
10 Address::Address(satcat5::eth::Dispatch* iface)
11  : m_iface(iface)
12  , m_addr(satcat5::eth::MACADDR_NONE)
13  , m_type(satcat5::eth::ETYPE_NONE)
14  , m_vtag(satcat5::eth::VTAG_NONE)
15 {
16  // Nothing else to initialize.
17 }
18 
20  const satcat5::eth::MacAddr& addr,
21  const satcat5::eth::MacType& type,
22  const satcat5::eth::VlanTag& vtag)
23 {
24  m_addr = addr;
25  m_type = type;
26  m_vtag = vtag;
27 }
28 
30  return m_iface;
31 }
32 
34  return m_iface->open_write(m_addr, m_type, m_vtag);
35 }
36 
38  m_addr = satcat5::eth::MACADDR_NONE;
39  m_type = satcat5::eth::ETYPE_NONE;
40  m_vtag = satcat5::eth::VTAG_NONE;
41 }
42 
43 bool Address::ready() const {
44  return !(m_addr == satcat5::eth::MACADDR_NONE)
45  && !(m_type == satcat5::eth::ETYPE_NONE);
46 }
47 
48 bool Address::is_multicast() const {
49  return m_addr.is_multicast();
50 }
51 
53  bool dst_match = m_addr.is_multicast() || m_addr == m_iface->reply_mac();
54  bool vid_match = m_iface->reply_vtag().vid() == m_vtag.vid();
55  return dst_match && vid_match;
56 }
57 
59  return m_iface->reply_is_multicast();
60 }
61 
63  m_addr = m_iface->reply_mac();
64  m_type = m_iface->reply_type();
65  m_vtag = m_iface->reply_vtag();
66 }
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
Implemention of "net::Dispatch" for Ethernet frames.
Definition: eth_dispatch.h:21
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
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
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 vid() const
Accessors for each individual field.
Definition: eth_header.h:135