SatCat5
satcat5::eth::SwitchCore Class Reference

Detailed Description

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).

See also
eth_plugin.h.

Typically a SwitchCore is instantiated along side SwitchCache:

satcat5::eth::SwitchCache<64> cache(&my_sw_switch);
A shared-memory Ethernet switch based on the MultiBuffer class.
Definition: eth_switch.h:93

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>

Inheritance diagram for satcat5::eth::SwitchCore:
[legend]
Collaboration diagram for satcat5::eth::SwitchCore:
[legend]

Public Member Functions

 SwitchCore (u8 *buff, unsigned nbytes)
 Configure this object and link to the provided working buffer.
 
satcat5::eth::SwitchPortget_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::MultiPacketdequeue ()
 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::MultiChunknew_chunk ()
 Memory allocation.
 
satcat5::io::MultiPacketnew_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::PluginCorem_plugins
 Linked list of attached plugins.
 
satcat5::util::List< satcat5::eth::SwitchPortm_ports
 Linked list of attached Ethernet ports.
 
satcat5::io::Writeablem_debug
 
satcat5::util::List< satcat5::eth::SwitchLogHandlerm_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::MultiChunkm_free_chunks
 
satcat5::util::List< satcat5::io::MultiReaderm_read_ports
 
satcat5::util::List< satcat5::io::MultiPacketm_rcvd_packets
 

Private Attributes

satcat5::poll::OnDemandm_next
 
bool m_idle
 

Member Function Documentation

◆ add_log()

void satcat5::eth::SwitchCore::add_log ( satcat5::eth::SwitchLogHandler log)
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.

◆ debug_if()

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.

◆ enqueue()

bool MultiBuffer::enqueue ( satcat5::io::MultiPacket packet)
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.

◆ free_packet()

void MultiBuffer::free_packet ( satcat5::io::MultiPacket packet)
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.

◆ get_port()

satcat5::eth::SwitchPort* satcat5::eth::SwitchCore::get_port ( unsigned  idx)
inline

Fetch a SwitchPort object by port-index.

Ports are numbered in the order they are created.

See also
port_add. The maximum number of ports is given by eth::PMASK_SIZE.

Definition at line 101 of file eth_switch.h.

◆ get_traffic_count()

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().

Returns
the number of matching frames.

Definition at line 104 of file eth_switch.cc.

◆ next_port_mask()

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.

◆ poll_demand()

void MultiBuffer::poll_demand ( )
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.

◆ request_poll()

void satcat5::poll::OnDemand::request_poll ( )
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.

◆ set_promiscuous()

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.


The documentation for this class was generated from the following files: