SatCat5
router2_dispatch.h
1 // Copyright 2024-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 // Incoming packet dispatch for the IPv4 router
6 
7 #pragma once
8 
9 #include <satcat5/eth_switch.h>
10 #include <satcat5/ip_core.h>
11 #include <satcat5/port_adapter.h>
12 
13 namespace satcat5 {
14  namespace router2 {
36  public:
38  Dispatch(u8* buff, unsigned nbytes);
39 
45  { return &m_local_port; }
47  { return &m_local_port; }
49  { m_defer_fwd = fwd; }
51  { m_local_iface = iface; }
53  { m_offload = iface; }
55 
58  inline void port_enable(const SATCAT5_PMASK_TYPE& mask)
59  { m_port_shdn &= ~mask; }
60  inline void port_disable(const SATCAT5_PMASK_TYPE& mask)
61  { m_port_shdn |= mask; }
63 
64  // Other accessors.
65  inline satcat5::ip::Dispatch* iface() const
66  { return m_local_iface; }
67  satcat5::ip::Addr ipaddr() const;
68  satcat5::eth::MacAddr macaddr() const;
69  void set_ipaddr(const satcat5::ip::Addr& addr);
70 
71  protected:
72  // Deferred forwarding needs privileged access.
74 
75  // Override the SwitchCore::deliver() method.
76  unsigned deliver(satcat5::io::MultiPacket* packet) override;
77  unsigned deliver_pkt(satcat5::eth::PluginPacket& meta);
78 
79  // Internal event-handlers called from deliver(...).
80  void adjust_mac(
81  const satcat5::eth::MacAddr& dst,
83  bool decrement_ttl(
85  unsigned process_gateway(
87  unsigned deliver_arp(
89  unsigned deliver_defer(
90  const satcat5::eth::PluginPacket& meta);
91  unsigned deliver_local(
92  const satcat5::eth::PluginPacket& meta);
93  unsigned deliver_offload(
94  const satcat5::eth::PluginPacket& meta);
95  bool icmp_reply(
96  u16 errtyp, u32 arg,
97  const satcat5::eth::PluginPacket& meta);
98  bool is_from_offload(
99  const satcat5::eth::PluginPacket& meta);
100  SATCAT5_PMASK_TYPE link_up_mask();
101 
102  // Internal state:
103  satcat5::router2::DeferFwd* m_defer_fwd;
104  satcat5::port::NullAdapter m_local_port;
105  satcat5::ip::Dispatch* m_local_iface;
106  satcat5::router2::Offload* m_offload;
107  SATCAT5_PMASK_TYPE m_port_shdn;
108  };
109  }
110 }
A shared-memory Ethernet switch based on the MultiBuffer class.
Definition: eth_switch.h:93
Abstract API for reading byte-streams and packets.
Definition: io_readable.h:68
Abstract API for writing byte-streams and packets.
Definition: io_writeable.h:24
Protocol handler and dispatch unit for Internet Protocol v4 (IPv4).
Definition: ip_dispatch.h:43
Minimalist port adapter with no VLAN conversion.
Definition: port_adapter.h:148
Deferred packet-forwarding system for the IPv4 router.
Packet-processing pipeline for the IPv4 router.
void port_enable(const SATCAT5_PMASK_TYPE &mask)
Enable or disable specific port(s).
unsigned deliver(satcat5::io::MultiPacket *packet) override
Override the MultiBuffer::deliver() method.
satcat5::io::Readable * get_local_rd()
Link this dispatch unit to other parts of the IP/UDP stack.
void set_local_iface(satcat5::ip::Dispatch *iface)
Link this dispatch unit to other parts of the IP/UDP stack.
void set_offload(satcat5::router2::Offload *iface)
Link this dispatch unit to other parts of the IP/UDP stack.
void set_defer_fwd(satcat5::router2::DeferFwd *fwd)
Link this dispatch unit to other parts of the IP/UDP stack.
void port_disable(const SATCAT5_PMASK_TYPE &mask)
Enable or disable specific port(s).
satcat5::io::Writeable * get_local_wr()
Link this dispatch unit to other parts of the IP/UDP stack.
Dispatch(u8 *buff, unsigned nbytes)
Configure this object and link to the working buffer.
bool decrement_ttl(satcat5::eth::PluginPacket &meta)
Offload port for gateware-accelerated IPv4 routers.
Software-defined Ethernet switch.
#define SATCAT5_PMASK_TYPE
Set the integer type used to identify source and destination ports.
Definition: eth_switch.h:41
Adapter definitions for using generic I/O objects with eth::SwitchCore.
An Ethernet MAC address (with serializable interface).
Definition: eth_header.h:29
Ephemeral data structure provided to plugin callbacks.
Definition: eth_plugin.h:48
A packet is a linked-list of memory blocks, plus metadata.
Definition: multi_buffer.h:91
IPv4 address is a 32-bit unsigned integer.
Definition: ip_core.h:15