6 #include <satcat5/cfgbus_stats.h>
10 #include <satcat5/udp_dispatch.h>
25 constexpr u8 SwitchLogMessage::REASON_KEEP;
26 constexpr u8 SwitchLogMessage::DROP_OVERFLOW;
27 constexpr u8 SwitchLogMessage::DROP_BADFCS;
28 constexpr u8 SwitchLogMessage::DROP_BADFRM;
29 constexpr u8 SwitchLogMessage::DROP_MCTRL;
30 constexpr u8 SwitchLogMessage::DROP_VLAN;
31 constexpr u8 SwitchLogMessage::DROP_VRATE;
32 constexpr u8 SwitchLogMessage::DROP_PTPERR;
33 constexpr u8 SwitchLogMessage::DROP_NO_ROUTE;
34 constexpr u8 SwitchLogMessage::DROP_DISABLED;
35 constexpr u8 SwitchLogMessage::DROP_UNKNOWN;
37 u8 SwitchLogMessage::reason()
const {
57 default:
return "Unknown";
64 return u16(
meta >> 16);
70 return u16(
meta & 0xFFFF);
91 meta = (u32(_drop) << 16) | u32(_keep);
96 wr.
wr_str(
"\r\n Delivered to: 0x");
100 wr.
wr_str(
"\r\n Dropped: ");
104 wr.
wr_str(
"\r\n Summary: ");
106 wr.
wr_str(
" delivered, ");
130 meta = rd->read_u32();
144 static constexpr u32 DATA_VALID = (1u << 31);
145 static constexpr u32 DATA_FINAL = (1u << 30);
149 while (reg & DATA_VALID) {
151 m_buff.write_u24(reg);
152 if (reg & DATA_FINAL) {
169 bool skip_mode = m_skip_drop || m_skip_keep;
172 if (can_write && !skip_mode) {
207 for (
unsigned a = 0 ; a <
m_size ; ++a)
212 if (idx >=
m_size)
return STATS_ZERO;
221 if (src >=
m_size)
return;
229 for (
unsigned dst = 0 ; dst <
m_size ; ++dst) {
230 if ((msg.
dstmask() >> dst) & 1)
257 if (m_iface) m_iface->
add(
this);
260 #if SATCAT5_ALLOW_DELETION
261 SwitchLogReader::~SwitchLogReader() {
262 if (m_iface) m_iface->
remove(
this);
325 , m_dst_port(dst->get_switch(), dst->get_egress())
326 , m_dst_raw(&m_dst_port)
327 , m_eth(iface->eth())
339 , m_dst_port(nullptr, nullptr)
341 , m_eth(iface->eth())
354 m_eth.
connect(addr, type, vtag);
363 m_udp.
connect(addr, port, satcat5::udp::PORT_NONE, vtag);
369 if (!
ready())
return;
382 unsigned total_bytes = (1 + more_pkt) * BYTES_PER_MSG;
383 m_dst_raw->
write_obj(m_udp.eth_header());
384 m_dst_raw->
write_obj(m_udp.ip_header(total_bytes));
385 m_dst_raw->
write_obj(m_udp.udp_header(total_bytes));
Pointer-like wrapper for one or more ConfigBus registers.
u32 uptime_usec() const
Get elapsed time since startup, in microseconds.
bool ready() const override
Is this address object ready for use? Child MUST override this method.
void close() override
Close any open connections and revert to idle.
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.
Implemention of "net::Dispatch" for Ethernet frames.
Accept incoming Ethernet packets by EtherType.
Define the API for packet-logging callbacks from eth::SwitchCore.
virtual void log_packet(const satcat5::eth::SwitchLogMessage &msg)=0
This method is called exactly once for each incoming packet.
Poll a hardware switch or router for log data.
void timer_event() override
Child class MUST override this method.
SwitchLogHardware(satcat5::eth::SwitchLogHandler *dst, satcat5::cfg::Register src)
Link this object to a log-writer and a data source.
Read packet-logs from an input stream or network interface.
virtual void log_event(const satcat5::eth::SwitchLogMessage &msg)=0
The child class MUST override this method.
void set_polling_interval(unsigned msec)
Set polling interval, in milliseconds.
void frame_rcvd(satcat5::io::LimitedRead &src) override
Dispatch calls frame_rcvd(...) for each incoming frame with with a matching net::Type value.
void data_unlink(satcat5::io::Readable *src) override
Unlink this EventListener from the designated source, because the designated Readable object is being...
void data_rcvd(satcat5::io::Readable *src) override
The data_rcvd() callback is polled whenever data is available.
void timer_event() override
Child class MUST override this method.
SwitchLogReader(satcat5::io::Readable *src)
Constructor for buffered mode.
Record packet statistics based on switch log events.
TrafficStats get_port(unsigned idx)
Read most recent statistics for the Nth port.
const unsigned m_size
Buffer size.
TrafficStats *const m_stats
Working counters.
SwitchLogStats(TrafficStats *buff, unsigned size)
Constructor accepts a pointer to the working buffer.
void log_packet(const satcat5::eth::SwitchLogMessage &msg) override
Process each packet event.
Forward binary packet logs to a network interface.
SwitchLogToPort(satcat5::io::Readable *src, satcat5::eth::SwitchPort *dst, satcat5::udp::Dispatch *iface)
Bind this object to a software egress port.
bool ready() const
Is this connection currently active?
void log_event(const satcat5::eth::SwitchLogMessage &msg) override
Implement the SwitchLogReader callback.
void connect(const satcat5::eth::MacAddr &addr, const satcat5::eth::MacType &type=satcat5::eth::ETYPE_SWITCH_LOG, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE)
Connect to a designated raw-Ethernet address.
Record rate-limited packet-logs for a switch or router.
void timer_event() override
Child class MUST override this method.
void log_packet(const satcat5::eth::SwitchLogMessage &msg) override
Process each packet event.
Generic packetized I/O interface for use with SwitchCore.
Ephemeral Readable interface for a simple array.
unsigned written_len() const
Report total length after write_finalize() is called.
bool write_finalize() override
Mark end of frame and release temporary working data.
const u8 * buffer() const
Read-only access to the working buffer.
Limited read of next N bytes.
Abstract API for reading byte-streams and packets.
u8 read_u8()
One of many functions for reading integer/floating point values, see details.
virtual void read_finalize()
Consume any remaining bytes in this frame, if applicable.
virtual void set_callback(satcat5::io::EventListener *callback)
Update registered callback for data_rcvd() events.
virtual unsigned get_read_ready() const =0
How many bytes can be read without blocking?
Abstract API for writing byte-streams and packets.
virtual unsigned get_write_space() const =0
How many bytes can be written without blocking?
void write_u8(u8 data)
One of many functions for writing integer/floating point values, see details.
virtual bool write_finalize()
Mark end of frame and release temporary working data.
void write_obj(const T &obj)
Templated wrapper for any object with the following method: void write_to(satcat5::io::Writeable* wr)...
Internal buffer used by the Log class.
void wr_h32(u32 val, unsigned nhex=8)
Write an integer (u32) in hexadecimal format.
void wr_str(const char *str)
Write a null-terminated UTF-8 string.
void wr_d32(u32 val, unsigned zpad=0)
Write an unsigned integer (u32) in decimal format.
The Log class creates and formats one log message.
Log & write_obj(const T &obj)
Templated wrapper for custom output formatting.
The "Dispatch" is a generic interface that knows how to read a designated protocol layer and sort inc...
void add(satcat5::net::Protocol *proto)
Register a Protocol object.
void remove(satcat5::net::Protocol *proto)
Unregister a Protocol object.
void timer_stop()
Stop all future notifications.
void timer_every(unsigned msec)
Configure a repeating notification every X milliseconds.
void connect(const satcat5::udp::Addr &dstaddr, const satcat5::eth::MacAddr &dstmac, const satcat5::udp::Port &dstport, const satcat5::udp::Port &srcport=satcat5::udp::PORT_NONE, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE)
Manual address resolution (user supplies IP + MAC).
void close() override
Close any open connections and revert to idle.
Dispatcher sorts incoming UDP messages by port index.
Real-time clock conversion functions.
Diagnostic logging system for the Ethernet switch.
Diagnostic logging to UART and/or Ethernet ports.
An Ethernet MAC address (with serializable interface).
void write_to(satcat5::io::Writeable *wr) const
Write this field to a byte-stream.
bool read_from(satcat5::io::Readable *rd)
Read this field from a byte-stream.
bool is_broadcast() const
Broadcast (FF:FF:FF:FF:FF:FF)
EtherType field (uint16) is used a protocol-ID [1536..65535].
void write_to(satcat5::io::Writeable *wr) const
Write this field to a byte-stream.
bool read_from(satcat5::io::Readable *rd)
Read this field from a byte-stream.
A single 24-byte packet-log message.
void init_keep(const satcat5::eth::Header &hdr, u8 src, u32 dst)
Initialize a KEEP message.
static constexpr u8 DROP_UNKNOWN
Other unspecified error.
satcat5::eth::Header hdr
Ethernet packet header.
static constexpr u8 DROP_VLAN
Virtual-LAN policy.
static constexpr u8 DROP_MCTRL
Link-local control packet.
bool read_from(satcat5::io::Readable *rd)
Read descriptor from the designated stream.
static constexpr unsigned LEN_BYTES
Message length, in bytes.
static constexpr u8 DROP_BADFRM
Frame length, source MAC, etc.
void init_drop(const satcat5::eth::Header &hdr, u8 src, u8 why)
Initialize a DROP message.
u16 count_keep() const
Count delivered packets.
static constexpr u8 DROP_PTPERR
PTP error (no timestamp)
static constexpr u8 DROP_BADFCS
Invalid frame check sequence.
static constexpr u8 TYPE_SKIP
Message type: SKIP (summary)
u16 count_drop() const
Count dropped packets.
static constexpr u8 DROP_DISABLED
Ingress or egress port disabled.
u8 type_src
Type and source port.
void init_skip(u16 drop, u16 keep)
Initialize a SKIP message.
const char * reason_str() const
Human-readable reason for a dropped packet, if applicable.
static constexpr u8 DROP_NO_ROUTE
No destination or null route.
static constexpr u8 REASON_KEEP
Packet accepted / not dropped.
static constexpr u8 DROP_VRATE
Virtual-LAN rate limits.
u8 reason() const
Coded reason for a dropped packet, if applicable.
u32 meta
Additional metadata.
void log_to(satcat5::log::LogBuffer &wr) const
Format this field as a human-readable string.
u8 type() const
< Message type.
static constexpr u8 TYPE_DROP
Message type: DROP (dropped)
static constexpr u8 DROP_OVERFLOW
FIFO overflow (Rx or Tx)
u32 tstamp
Timestamp in microseconds.
static constexpr u8 TYPE_KEEP
Message type: KEEP (delivered)
static constexpr u8 SRC_MASK
Mask for source index.
void write_to(satcat5::io::Writeable *wr) const
Write descriptor to the designated stream.
SATCAT5_PMASK_TYPE dstmask() const
Destination mask (KEEP messages only).
u8 srcport() const
< Source port index.
Data structure for reporting per-port traffic statistics.
u32 bcast_frames
Broadcast frames received from device.
u32 errct_total
Total packet errors, all types.
u32 errct_ovr
Frames dropped due to FIFO overflow.
u32 sent_frames
Total frames sent from switch to device.
u32 rcvd_frames
Total frames received from device.
u32 errct_pkt
Invalid packets (bad checksum, etc.)
Header contents for an 802.1Q Virtual-LAN tag.
bool read_from(satcat5::io::Readable *rd)
Read this field from a byte-stream.
void write_to(satcat5::io::Writeable *wr) const
Write this field to a byte-stream.
IPv4 address is a 32-bit unsigned integer.
UDP and TCP ports are both 16-bit unsigned integers.
Multipurpose filter for matching fields in network packets.