SatCat5
satcat5::router2::Dispatch Class Reference

Detailed Description

Packet-processing pipeline for the IPv4 router.

The router2::Dispatch class is the core of the IPv4 router, parsing each incoming packet, then deciding the appropriate action.

The Dispatch class supports up to 32 ports in total. It may operate with a mixture of software-controlled ports and hardware-accelerated ports. Software-controlled ports use the Dispatch class for all packet processing and are attached using any of the port::Adapter classes (see port_adapter.h), using the same API as eth::SwitchCore. Hardware-accelerated ports use HDL for routine routing, but offload rare-but-complex operations to to this class through router2::Offload.

The implementation uses eth::SwitchCore as a parent class for buffer and I/O handling, allowing use of many of the same plugin and port interface objects. However, it completely replaces the packet delivery logic to implement the IPv4 router functionality.

For an all-in-one turnkey solution that instantiates router2::Dispatch along with all required helper objects, see "router2_stack.h".

Definition at line 35 of file router2_dispatch.h.

#include <router2_dispatch.h>

Inheritance diagram for satcat5::router2::Dispatch:
[legend]
Collaboration diagram for satcat5::router2::Dispatch:
[legend]

Public Member Functions

 Dispatch (u8 *buff, unsigned nbytes)
 Configure this object and link to the working buffer.
 
satcat5::ip::Dispatchiface () const
 
satcat5::ip::Addr ipaddr () const
 
satcat5::eth::MacAddr macaddr () const
 
void set_ipaddr (const satcat5::ip::Addr &addr)
 
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...
 
satcat5::io::Readableget_local_rd ()
 Link this dispatch unit to other parts of the IP/UDP stack. More...
 
satcat5::io::Writeableget_local_wr ()
 Link this dispatch unit to other parts of the IP/UDP stack. More...
 
void set_defer_fwd (satcat5::router2::DeferFwd *fwd)
 Link this dispatch unit to other parts of the IP/UDP stack. More...
 
void set_local_iface (satcat5::ip::Dispatch *iface)
 Link this dispatch unit to other parts of the IP/UDP stack. More...
 
void set_offload (satcat5::router2::Offload *iface)
 Link this dispatch unit to other parts of the IP/UDP stack. More...
 
void port_enable (const SATCAT5_PMASK_TYPE &mask)
 Enable or disable specific port(s).
 
void port_disable (const SATCAT5_PMASK_TYPE &mask)
 Enable or disable specific port(s).
 

Protected Member Functions

unsigned deliver (satcat5::io::MultiPacket *packet) override
 Override the MultiBuffer::deliver() method.
 
unsigned deliver_pkt (satcat5::eth::PluginPacket &meta)
 
void adjust_mac (const satcat5::eth::MacAddr &dst, satcat5::eth::PluginPacket &meta)
 
bool decrement_ttl (satcat5::eth::PluginPacket &meta)
 
unsigned process_gateway (satcat5::eth::PluginPacket &meta)
 
unsigned deliver_arp (satcat5::eth::PluginPacket &meta)
 
unsigned deliver_defer (const satcat5::eth::PluginPacket &meta)
 
unsigned deliver_local (const satcat5::eth::PluginPacket &meta)
 
unsigned deliver_offload (const satcat5::eth::PluginPacket &meta)
 
bool icmp_reply (u16 errtyp, u32 arg, const satcat5::eth::PluginPacket &meta)
 
bool is_from_offload (const satcat5::eth::PluginPacket &meta)
 
SATCAT5_PMASK_TYPE link_up_mask ()
 
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::router2::DeferFwdm_defer_fwd
 
satcat5::port::NullAdapter m_local_port
 
satcat5::ip::Dispatchm_local_iface
 
satcat5::router2::Offloadm_offload
 
SATCAT5_PMASK_TYPE m_port_shdn
 
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)
inlineinherited

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
inherited

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.

◆ decrement_ttl()

bool Dispatch::decrement_ttl ( satcat5::eth::PluginPacket meta)
protected

Calculate byte offsets for IPv4 header fields of interest.

Definition at line 252 of file router2_dispatch.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_local_rd()

satcat5::io::Readable* satcat5::router2::Dispatch::get_local_rd ( )
inline

Link this dispatch unit to other parts of the IP/UDP stack.

These methods must be called after the constructor, to break the chicken-and-egg problem for various helper objects.

Definition at line 44 of file router2_dispatch.h.

◆ get_local_wr()

satcat5::io::Writeable* satcat5::router2::Dispatch::get_local_wr ( )
inline

Link this dispatch unit to other parts of the IP/UDP stack.

These methods must be called after the constructor, to break the chicken-and-egg problem for various helper objects.

Definition at line 46 of file router2_dispatch.h.

◆ get_port()

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

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

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

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

void satcat5::router2::Dispatch::set_defer_fwd ( satcat5::router2::DeferFwd fwd)
inline

Link this dispatch unit to other parts of the IP/UDP stack.

These methods must be called after the constructor, to break the chicken-and-egg problem for various helper objects.

Definition at line 48 of file router2_dispatch.h.

◆ set_local_iface()

void satcat5::router2::Dispatch::set_local_iface ( satcat5::ip::Dispatch iface)
inline

Link this dispatch unit to other parts of the IP/UDP stack.

These methods must be called after the constructor, to break the chicken-and-egg problem for various helper objects.

Definition at line 50 of file router2_dispatch.h.

◆ set_offload()

void satcat5::router2::Dispatch::set_offload ( satcat5::router2::Offload iface)
inline

Link this dispatch unit to other parts of the IP/UDP stack.

These methods must be called after the constructor, to break the chicken-and-egg problem for various helper objects.

Definition at line 52 of file router2_dispatch.h.

◆ set_promiscuous()

void SwitchCore::set_promiscuous ( unsigned  port_idx,
bool  enable 
)
inherited

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: