6 #include <satcat5/cfgbus_stats.h>
8 #include <satcat5/switch_telemetry.h>
11 #if SATCAT5_CBOR_ENABLE
19 static void copy_mactbl_array(QCBOREncodeContext* cbor,
SwitchConfig* cfg) {
25 QCBOREncode_OpenArray(cbor);
26 for (
unsigned tbl_idx = 0 ; tbl_idx < table_size ; ++tbl_idx) {
27 if (cfg->
mactbl_read(tbl_idx, port_idx, mac_addr)) {
29 QCBOREncode_OpenArray(cbor);
30 QCBOREncode_AddBytes(cbor, {mac_addr.
addr, 6});
31 QCBOREncode_AddUInt64(cbor, port_idx);
32 QCBOREncode_CloseArray(cbor);
35 QCBOREncode_CloseArray(cbor);
38 static void copy_traffic_array(QCBOREncodeContext* cbor,
unsigned port_count,
NetworkStats* stats) {
40 QCBOREncode_OpenArray(cbor);
41 for (
unsigned a = 0 ; a < port_count ; ++a) {
44 QCBOREncode_OpenMap(cbor);
45 QCBOREncode_AddUInt64ToMap(cbor,
"rxb", data.
rcvd_bytes);
46 QCBOREncode_AddUInt64ToMap(cbor,
"rxf", data.
rcvd_frames);
47 QCBOREncode_AddUInt64ToMap(cbor,
"txb", data.
sent_bytes);
48 QCBOREncode_AddUInt64ToMap(cbor,
"txf", data.
sent_frames);
55 QCBOREncode_CloseMap(cbor);
57 QCBOREncode_CloseArray(cbor);
60 SwitchTelemetry::SwitchTelemetry(
66 , m_tier1(tlm, this, 1, 30000)
67 , m_tier2(tlm, this, 2, 1000)
77 if (pmask) cbor.
add_item(
"pmask", pmask);
79 QCBOREncode_AddSZString(cbor.
cbor,
"mactbl");
80 copy_mactbl_array(cbor.
cbor, m_cfg);
84 if (filter) cbor.
add_item(
"traffic_etype_filter", filter);
89 QCBOREncode_AddSZString(cbor.
cbor,
"traffic_by_port");
QCBOREncodeContext *const cbor
QCBOR context pointer.
void add_item(KEYTYPE key, s8 value) const
Write a scalar value to the Map.
Traffic statistics polling.
satcat5::cfg::TrafficStats get_port(unsigned idx)
Read most recent statistics for the Nth port.
void refresh_now()
Immediately refresh statistics for every port.
Management functions for a SatCat5 Ethernet switch.
u32 get_miss_mask()
Identify which ports are currently in "miss-as-broadcast" mode.
unsigned mactbl_size()
Read the maximum size of the MAC-address table.
u32 get_promiscuous_mask()
Identify which ports are currently promiscuous.
u16 get_traffic_filter() const
Query the current traffic filter setting.
u32 get_traffic_count()
Report matching frames since last call to get_traffic_count().
u32 port_count()
Number of ports on this switch.
bool mactbl_read(unsigned tbl_idx, unsigned &port_idx, satcat5::eth::MacAddr &mac_addr)
Read the Nth entry from the MAC-address table.
Diagnostic telemetry for a SatCat5 switch.
void telem_event(u32 tier_id, satcat5::net::TelemetryCbor &cbor) override
User method for writing each telemetry message.
Protocol-agnostic handler for one or more TelemetryTier objects.
Legacy ephemeral wrapper class for the CBOR encoder.
Data structure for reading per-port traffic statistics.
u8 errct_ovr_rx
Rx-FIFO overflow (rare)
u32 sent_frames
Total frames sent from switch to device.
u8 errct_ptp_tx
TX PTP packets with bad tstamps.
u8 errct_mac
MAC/PHY errors.
u8 errct_ovr_tx
Tx-FIFO overflow (common)
u8 errct_pkt
Packet errors (bad checksum, length, etc.)
u32 rcvd_bytes
Total bytes received from device.
u32 sent_bytes
Total bytes sent from switch to device.
u32 rcvd_frames
Total frames received from device.
u8 errct_ptp_rx
RX PTP packets with bad tstamps.
An Ethernet MAC address (with serializable interface).
u8 addr[6]
Byte array in network order (Index 0 = MSB)
Configuration for a managed SatCat5 switch.