|
SatCat5
|
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>
Public Member Functions | |
| Dispatch (u8 *buff, unsigned nbytes) | |
| Configure this object and link to the working buffer. | |
| satcat5::ip::Dispatch * | iface () const |
| satcat5::ip::Addr | ipaddr () const |
| satcat5::eth::MacAddr | macaddr () const |
| void | set_ipaddr (const satcat5::ip::Addr &addr) |
| 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... | |
| satcat5::io::Readable * | get_local_rd () |
| Link this dispatch unit to other parts of the IP/UDP stack. More... | |
| satcat5::io::Writeable * | get_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::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::router2::DeferFwd * | m_defer_fwd |
| satcat5::port::NullAdapter | m_local_port |
| satcat5::ip::Dispatch * | m_local_iface |
| satcat5::router2::Offload * | m_offload |
| SATCAT5_PMASK_TYPE | m_port_shdn |
| 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 |
|
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.
|
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.
|
protected |
Calculate byte offsets for IPv4 header fields of interest.
Definition at line 252 of file router2_dispatch.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 |
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.
|
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.
|
inlineinherited |
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.
|
inherited |
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.