SatCat5
port_recovery.cc
1 // Copyright 2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 
6 #include <satcat5/log.h>
7 #include <satcat5/port_recovery.h>
8 
15 using satcat5::log::Log;
16 
17 // Set Verbosity level for debugging (0/1/2)
18 static constexpr unsigned DEBUG_VERBOSE = 0;
19 
20 RecoveryIngress::RecoveryIngress(SwitchCore* sw)
21  : PluginCore(sw)
22  , m_recov_in_buff(m_raw_buff_in, SATCAT5_RECOVERY_SWITCH_BUFFER_SIZE)
23 {
24  // Nothing else to initialize.
25 }
26 
28  // If this is a recovery packet: copy the data onto the buffer, call
29  // free_packet, and let the parent know we've consumed the packet.
30  if (packet.hdr.type == satcat5::eth::ETYPE_RECOVERY) {
31  // Discard frame header and note remaining length.
33  rd.read_consume(packet.hlen);
34  unsigned length = rd.get_read_ready();
35 
36  // If there is enough space, copy the rest of the packet.
37  if (m_recov_in_buff.get_write_space() >= length) {
38  rd.copy_to(&m_recov_in_buff);
39  m_recov_in_buff.write_finalize();
40  } else if (DEBUG_VERBOSE > 1) {
41  Log(DEBUG, "RecoveryIngress::query: Overflow.");
42  }
43 
44  // Signal to the parent that we've consumed this packet.
45  m_switch->free_packet(packet.pkt);
46  packet.divert();
47  }
48 }
49 
51  : MultiWriterBypass(port->get_switch(), port->get_egress(), 9999)
52 {
53  // Nothing else to initialize.
54 }
satcat5::eth::SwitchCore *const m_switch
Pointer to the associated SwitchCore object.
Definition: eth_plugin.h:183
A shared-memory Ethernet switch based on the MultiBuffer class.
Definition: eth_switch.h:93
Generic packetized I/O interface for use with SwitchCore.
Definition: eth_switch.h:245
void free_packet(satcat5::io::MultiPacket *packet)
Immediately free memory associated with this packet.
Barebones class for reading data from a MultiPacket.
Definition: multi_buffer.h:129
unsigned get_read_ready() const override
How many bytes can be read without blocking?
Definition: multi_buffer.cc:63
bool read_consume(unsigned nbytes) override
Read and discard 0 or more bytes.
Definition: multi_buffer.cc:88
bool write_finalize() override
Mark end of frame and release temporary working data.
Definition: pkt_buffer.cc:105
unsigned get_write_space() const override
How many bytes can be written without blocking?
Definition: pkt_buffer.cc:52
unsigned copy_to(satcat5::io::Writeable *dst)
Copy data to a Writeable object, without finalizing.
Definition: io_readable.cc:214
The Log class creates and formats one log message.
Definition: log.h:195
MultiWriter that slips packets written to it into the port's egress buffer.
Definition: port_recovery.h:44
RecoveryEgress(satcat5::eth::SwitchPort *port)
Egress interface attaches to an Ethernet port.
Intercepts all packets with the ETYPE_RECOVERY_IN ethertype and puts them into a buffer that can be r...
Definition: port_recovery.h:26
void query(satcat5::eth::PluginPacket &packet) override
Packet-received callback.
Diagnostic logging to UART and/or Ethernet ports.
constexpr s8 DEBUG
Define basic priority codes for log messages.
Definition: log.h:109
satcat5::eth::MacType type
Ethernet header fields.
Definition: eth_header.h:172
Ephemeral data structure provided to plugin callbacks.
Definition: eth_plugin.h:48
satcat5::io::MultiPacket * pkt
Complete packet contents.
Definition: eth_plugin.h:51
u16 hlen
Original header length.
Definition: eth_plugin.h:78
void divert()
Divert this frame for deferred processing.
Definition: eth_plugin.h:114
satcat5::eth::Header hdr
Copy of Ethernet header fields.
Definition: eth_plugin.h:55