|
SatCat5
|
A shared-memory Ethernet switch based on the MultiBuffer class.
Software-defined Ethernet switch. This file defines a layer-2 Ethernet switch, using a shared-memory architecture defined by the MultiBuffer class (multi_buffer.h). The SwitchCore class supports a maximum of 32 ports by default.
Connected ports implement the "eth::SwitchPort" API, defined below. For examples suitable for use with various SatCat5 I/O objects, see the classes defined in "port_adapter.h".
An extensible plugin system directs packets to the appropriate destination(s).
Typically a SwitchCore is instantiated along side SwitchCache:
If the SwitchCore be instantiated by itself, it will act like a hub.
Precision Time Protocol (PTP) is not currently supported.
This class implements packet delivery using plugins. At minimum, users should add "eth::SwitchCache" or a similar plugin to provide automatic MAC-address association with each port. Other plugins such as "eth::SwitchVlan" add optional features.
Use this class directly to define custom memory allocation; otherwise users should use the "SwitchCoreStatic" class.
Configuration methods mimic the eth::SwitchConfig API.
Definition at line 93 of file eth_switch.h.
#include <eth_switch.h>
Public Member Functions | |
| SwitchCore (u8 *buff, unsigned nbytes) | |
| Configure this object and link to the provided working buffer. | |
| satcat5::eth::SwitchPort * | get_port (unsigned idx) |
| Fetch a SwitchPort object by port-index. More... | |
| SATCAT5_PMASK_TYPE | next_port_mask () |
| Get next available bit-mask for new SwitchPort objects. More... | |
| u32 | port_count () const |
| Get the number of attached ports. | |
| 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. More... | |
| void | remove_log (satcat5::eth::SwitchLogHandler *log) |
| void | set_promiscuous (unsigned port_idx, bool enable) |
| Enable or disable "promiscuous" flag on the specified port index. More... | |
| void | set_promiscuous_mask (SATCAT5_PMASK_TYPE mask) |
| Enable or disable "promiscuous" flag for all ports at once. | |
| SATCAT5_PMASK_TYPE | get_promiscuous_mask () const |
| Return a bit-mask identifying all "promiscuous" ports. | |
| void | set_traffic_filter (u16 etype=0) |
| Configure EtherType filter for traffic reporting. (0 = Any type) | |
| u16 | get_traffic_filter () const |
| Return the current filter configuration. (0 = Any type) | |
| u32 | get_traffic_count () |
| Query traffic statistics Count received frames that match the current traffic filter, starting from the previous call to get_traffic_count(). More... | |
| void | debug_if (const satcat5::eth::PluginPacket &pkt, unsigned mask) const |
| Carbon-copy a packet to the debug port, if it is enabled. More... | |
| 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. | |
| bool | consistency () const |
| Internal consistency self-test (Optional). | |
| unsigned | get_free_bytes () const |
| Query remaining buffer capacity. | |
| u16 | get_pcount () |
| Current value of the packet counter. | |
| bool | enqueue (satcat5::io::MultiPacket *packet) |
| Queue an incoming packet for deferred processing. More... | |
| void | free_packet (satcat5::io::MultiPacket *packet) |
| Immediately free memory associated with this packet. More... | |
Protected Member Functions | |
| unsigned | deliver (satcat5::io::MultiPacket *packet) override |
| Override the MultiBuffer::deliver() method. | |
| satcat5::io::MultiPacket * | dequeue () |
| Event handler for deferred packet delivery. | |
| void | poll_demand () override |
| Deferred event handler, called after request(). More... | |
| void | request_poll () |
| Call this method to request polling at a later time. More... | |
| void | request_cancel () |
| Call this method to cancel a previous request_poll(). | |
| void | process_stats (const satcat5::eth::PluginPacket &pkt) |
| Internal event-handlers called from deliver(...). | |
| satcat5::util::optional< unsigned > | process_plugins (satcat5::eth::PluginPacket &pkt) |
| Internal event-handlers called from deliver(...). | |
| satcat5::util::optional< unsigned > | pkt_has_dropped (satcat5::eth::PluginPacket &pkt, unsigned mask) |
| Internal event-handlers called from deliver(...). | |
| unsigned | deliver_switch (const satcat5::eth::PluginPacket &pkt) |
| Internal event-handlers called from deliver(...). | |
| void | plugin_add (satcat5::eth::PluginCore *plugin) |
| void | plugin_remove (satcat5::eth::PluginCore *plugin) |
| void | port_add (satcat5::eth::SwitchPort *port) |
| void | port_remove (satcat5::eth::SwitchPort *port) |
| void | port_remove (const SATCAT5_PMASK_TYPE &mask) |
| satcat5::io::MultiChunk * | new_chunk () |
| Memory allocation. | |
| satcat5::io::MultiPacket * | new_packet () |
| Memory allocation. | |
Static Protected Member Functions | |
| static unsigned | count_ondemand () |
| Count queued objects of this type (i.e., non-idle). | |
Protected Attributes | |
| satcat5::util::List< satcat5::eth::PluginCore > | m_plugins |
| Linked list of attached plugins. | |
| satcat5::util::List< satcat5::eth::SwitchPort > | m_ports |
| Linked list of attached Ethernet ports. | |
| satcat5::io::Writeable * | m_debug |
| satcat5::util::List< satcat5::eth::SwitchLogHandler > | m_pktlogs |
| SATCAT5_PMASK_TYPE | m_free_pmask |
| SATCAT5_PMASK_TYPE | m_prom_mask |
| u16 | m_stats_filter |
| u32 | m_stats_count |
| unsigned | m_free_bytes |
| u16 | m_pcount |
| satcat5::util::List< satcat5::io::MultiChunk > | m_free_chunks |
| satcat5::util::List< satcat5::io::MultiReader > | m_read_ports |
| satcat5::util::List< satcat5::io::MultiPacket > | m_rcvd_packets |
Private Attributes | |
| satcat5::poll::OnDemand * | m_next |
| bool | m_idle |
|
inline |
Optional logging interface records a summary of every packet.
Function and formatting are the same as "mac_log_core.vhd".
Definition at line 119 of file eth_switch.h.
| void SwitchCore::debug_if | ( | const satcat5::eth::PluginPacket & | pkt, |
| unsigned | mask | ||
| ) | const |
Carbon-copy a packet to the debug port, if it is enabled.
Reserved for use by SwitchCore, SwitchPort, or their children.
Definition at line 135 of file eth_switch.cc.
|
inherited |
Queue an incoming packet for deferred processing.
Note: This method SHOULD only be called from MultiWriter or its children. This method is public only for to allow flexibility in mutual "friend" inheritance rules.
Definition at line 176 of file multi_buffer.cc.
|
inherited |
Immediately free memory associated with this packet.
This is usually called by MultiReader::read_finalize().
Definition at line 243 of file multi_buffer.cc.
|
inline |
Fetch a SwitchPort object by port-index.
Ports are numbered in the order they are created.
Definition at line 101 of file eth_switch.h.
| u32 SwitchCore::get_traffic_count | ( | ) |
Query traffic statistics Count received frames that match the current traffic filter, starting from the previous call to get_traffic_count().
Definition at line 104 of file eth_switch.cc.
| SATCAT5_PMASK_TYPE SwitchCore::next_port_mask | ( | ) |
Get next available bit-mask for new SwitchPort objects.
Most SwitchPort objects are one-to-one, but some represent multiple; call "next_port_mask()" once for each logical port.
Definition at line 66 of file eth_switch.cc.
|
overrideprotectedvirtualinherited |
Deferred event handler, called after request().
Child class MUST override this method. (Call "request_poll" to enqueue a callback to this method.)
Implements satcat5::poll::OnDemand.
Definition at line 195 of file multi_buffer.cc.
|
inherited |
Call this method to request polling at a later time.
Safe to stack requests, but only one call to poll().
Definition at line 208 of file polling.cc.
| void SwitchCore::set_promiscuous | ( | unsigned | port_idx, |
| bool | enable | ||
| ) |
Enable or disable "promiscuous" flag on the specified port index.
For as long as the flag is set, those port(s) will receive ALL switch traffic regardless of the destination address, etc.
Definition at line 94 of file eth_switch.cc.