40 #ifndef SATCAT5_PMASK_TYPE
41 #define SATCAT5_PMASK_TYPE u32
120 { m_pktlogs.
add(log); }
122 { m_pktlogs.
remove(log); }
130 { m_prom_mask = mask; }
133 {
return m_prom_mask; }
139 {
return m_stats_filter; }
202 template <
unsigned BSIZE = 65536>
329 void data_rcvd(satcat5::io::Readable* src) override;
357 friend satcat5::util::ListCore;
Ethernet switch plugin API.
Ethernet port plugin API.
A shared-memory Ethernet switch based on the MultiBuffer class.
satcat5::util::List< satcat5::eth::SwitchPort > m_ports
Linked list of attached Ethernet ports.
unsigned deliver(satcat5::io::MultiPacket *packet) override
Override the MultiBuffer::deliver() method.
unsigned deliver_switch(const satcat5::eth::PluginPacket &pkt)
Internal event-handlers called from deliver(...).
SwitchCore(u8 *buff, unsigned nbytes)
Configure this object and link to the provided working buffer.
satcat5::util::optional< unsigned > process_plugins(satcat5::eth::PluginPacket &pkt)
Internal event-handlers called from deliver(...).
satcat5::util::List< satcat5::eth::PluginCore > m_plugins
Linked list of attached plugins.
satcat5::util::optional< unsigned > pkt_has_dropped(satcat5::eth::PluginPacket &pkt, unsigned mask)
Internal event-handlers called from deliver(...).
void set_promiscuous(unsigned port_idx, bool enable)
Enable or disable "promiscuous" flag on the specified port index.
u32 get_traffic_count()
Query traffic statistics Count received frames that match the current traffic filter,...
satcat5::eth::SwitchPort * get_port(unsigned idx)
Fetch a SwitchPort object by port-index.
void process_stats(const satcat5::eth::PluginPacket &pkt)
Internal event-handlers called from deliver(...).
SATCAT5_PMASK_TYPE next_port_mask()
Get next available bit-mask for new SwitchPort objects.
void debug_log(const satcat5::io::MultiPacket *pkt, u8 reason, SATCAT5_PMASK_TYPE dst=0) const
If logging is enabled, record the outcome for this packet.
void set_debug(satcat5::io::Writeable *debug)
Optional debug interface gets a carbon copy of each packet.
void add_log(satcat5::eth::SwitchLogHandler *log)
Optional logging interface records a summary of every packet.
void set_promiscuous_mask(SATCAT5_PMASK_TYPE mask)
Enable or disable "promiscuous" flag for all ports at once.
u16 get_traffic_filter() const
Return the current filter configuration. (0 = Any type)
SATCAT5_PMASK_TYPE get_promiscuous_mask() const
Return a bit-mask identifying all "promiscuous" ports.
void debug_if(const satcat5::eth::PluginPacket &pkt, unsigned mask) const
Carbon-copy a packet to the debug port, if it is enabled.
void set_traffic_filter(u16 etype=0)
Configure EtherType filter for traffic reporting. (0 = Any type)
u32 port_count() const
Get the number of attached ports.
Wrapper for SwitchCore with a statically-allocated working buffer.
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.
constexpr SwitchLogHandler()
Constructor is accessible only to children.
Generic packetized I/O interface for use with SwitchCore.
const unsigned m_port_index
Define this port's connection to the switch.
void plugin_ingress(satcat5::eth::PluginPacket &pkt)
Issue notifications to all attached plugins.
bool write_finalize() override
Override write_finalize() to store metadata.
SATCAT5_PMASK_TYPE m_port_mask
Define this port's connection to the switch.
void port_flush()
Discard all pending ingress and egress data.
void write_abort() override
Override write_abort() to allow additional error handling.
satcat5::io::MultiReaderPriority * get_egress()
Source for data leaving the switch through this port.
void data_rcvd(satcat5::io::Readable *src) override
The data_rcvd() callback is polled whenever data is available.
bool port_enabled() const
Is this port currently enabled?
SATCAT5_PMASK_TYPE port_mask() const
Bit-mask for all port(s) associated with this interface.
void plugin_remove(satcat5::eth::PluginPort *plugin)
Plugin management.
void port_enable(bool enable)
Enable or disable this port, pausing data-flow.
bool m_eg_hdr
Frame header copied?
satcat5::eth::VtagPolicy m_vlan_cfg
Metadata required for VLAN functionality.
void set_callback(satcat5::io::EventListener *cb)
Set egress data callback, mainly used for unit testing.
bool consistency() const
Internal consistency check, mainly used for unit testing.
satcat5::eth::SwitchCore *const m_switch
Pointer to the associated switch.
satcat5::eth::SwitchCore * get_switch()
Pointer to the parent SwitchCore object.
satcat5::util::List< satcat5::eth::PluginPort > m_plugins
Linked list of attached plugins.
unsigned port_index() const
Port number for attachment to the parent SwitchCore.
void vlan_config(const VtagPolicy &cfg)
Set this port's VLAN configuration.
satcat5::eth::VtagPolicy vlan_config() const
Return this port's VLAN configuration.
satcat5::io::Writeable *const m_eg_dst
Egress destination.
SwitchPort(satcat5::eth::SwitchCore *sw, satcat5::io::Writeable *dst)
Link this port to the designated switch.
void plugin_add(satcat5::eth::PluginPort *plugin)
Plugin management.
satcat5::io::MultiReaderPriority m_egress
Egress data source.
void plugin_egress(satcat5::eth::PluginPacket &pkt)
Issue notifications to all attached plugins.
bool accept(SATCAT5_PMASK_TYPE dst_mask, satcat5::io::MultiPacket *packet)
Accept delivery of a given packet?
Event-handler interface for newly received data.
A multi-source, multi-sink packet buffer.
void set_port_enable(bool enable)
Enable or disable this port.
void flush()
Discard all queued packets.
bool get_port_enable() const
Is this port currently enabled?
A variant of MultiReader that follows priority ordering.
bool consistency() const
Internal consistency self-test (Optional).
A port for writing to a MultiBuffer object.
virtual void set_callback(satcat5::io::EventListener *callback)
Update registered callback for data_rcvd() events.
Abstract API for writing byte-streams and packets.
constexpr Writeable()
Only children should create or destroy the base class.
Helper functions for manipulating singly-linked lists.
unsigned len() const
Traverse the linked list to count its length.
T * get_index(unsigned idx)
Fetch the Nth item from the linked list.
void add(T *item)
Add new item to front or back, whichever is simpler.
void remove(T *item)
Remove the designated item from the list.
#define SATCAT5_PMASK_TYPE
Set the integer type used to identify source and destination ports.
constexpr SATCAT5_PMASK_TYPE idx2mask(unsigned idx)
Macro converting port-index to a bit-mask.
constexpr SATCAT5_PMASK_TYPE PMASK_NONE(0)
Global port-mask indicating no ports (i.e., drop).
constexpr unsigned PMASK_SIZE()
Maximum number of switch ports, based on SATCAT5_PMASK_TYPE.
constexpr SATCAT5_PMASK_TYPE PMASK_ALL(-1)
Global port-mask indicating every port (i.e., broadcast).
Templated functions for manipulating singly-linked lists.
Multi-source, multi-sink packet buffer.
Ephemeral data structure provided to plugin callbacks.
A single 24-byte packet-log message.
Data structure for configuring VLAN tagging policy of each port.
A packet is a linked-list of memory blocks, plus metadata.
An optional field that may be filled or empty.
Configuration for a managed SatCat5 switch.
Basic type aliases and prototypes used throughout SatCat5.