SatCat5
router2_stack.h
Go to the documentation of this file.
1 // Copyright 2024-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
29 
30 #pragma once
31 
32 #include <satcat5/igmp_server.h>
33 #include <satcat5/ip_stack.h>
34 #include <satcat5/router2_deferfwd.h>
35 #include <satcat5/router2_dispatch.h>
36 #include <satcat5/router2_offload.h>
37 #include <satcat5/router2_table.h>
38 
39 namespace satcat5 {
40  namespace router2 {
47  class StackCommon {
48  public:
49  // Enable or disable specific ports.
50  inline void port_enable(const SATCAT5_PMASK_TYPE& mask)
51  { m_dispatch.port_enable(mask); }
52  inline void port_disable(const SATCAT5_PMASK_TYPE& mask)
53  { m_dispatch.port_disable(mask); }
54 
55  // Other accessors.
56  inline satcat5::eth::Dispatch* eth()
57  { return &m_eth; }
58  inline satcat5::ip::Dispatch* ip()
59  { return &m_ip; }
60  inline satcat5::ip::Addr ipaddr() const
61  { return m_ip.ipaddr(); }
62  inline satcat5::eth::MacAddr macaddr() const
63  { return m_eth.macaddr(); }
64  inline satcat5::router2::Dispatch* router()
65  { return &m_dispatch; }
66  inline satcat5::ip::Table* table()
67  { return m_ip.table(); }
68  inline satcat5::udp::Dispatch* udp()
69  { return &m_udp; }
70  inline void set_ipaddr(const satcat5::ip::Addr& addr)
71  { return m_dispatch.set_ipaddr(addr); }
72 
73  protected:
76  const satcat5::eth::MacAddr& local_mac, // Local MAC address
77  const satcat5::ip::Addr& local_ip, // Local IP address
78  satcat5::ip::Table* table, // Routing table
79  u8* buff, unsigned nbytes) // Internal working buffer
80  : m_dispatch(buff, nbytes)
81  , m_fwd(&m_dispatch)
82  , m_eth(local_mac, m_dispatch.get_local_wr(), m_dispatch.get_local_rd())
83  , m_ip(local_ip, &m_eth, table)
84  , m_udp(&m_ip)
85  {
86  m_dispatch.set_defer_fwd(&m_fwd);
87  m_dispatch.set_local_iface(&m_ip);
88  }
89 
92 
93  // Router logic.
94  satcat5::router2::Dispatch m_dispatch; // Incoming packet processing
95  satcat5::router2::DeferFwdStatic<> m_fwd; // Deferred-fowarding buffer
96 
97  // Internal IP stack.
98  satcat5::eth::Dispatch m_eth; // Ethernet layer
99  satcat5::ip::Dispatch m_ip; // IPv4 and ICMP layer
100  satcat5::udp::Dispatch m_udp; // UDP layer
101  };
102 
112  template <unsigned BSIZE = 8192>
114  public:
116  const satcat5::eth::MacAddr& local_mac, // Local MAC address
117  const satcat5::ip::Addr& local_ip, // Local IP address
118  satcat5::cfg::ConfigBusMmap* cfg, // ConfigBus interface
119  unsigned devaddr, // ConfigBus address
120  unsigned hw_ports) // Number of hardware ports
121  : StackCommon(local_mac, local_ip, &m_table, m_buff, BSIZE)
122  , m_offload(cfg, devaddr, &m_dispatch, hw_ports)
123  , m_table(cfg, devaddr)
124  {
125  m_dispatch.set_offload(&m_offload);
126  }
127 
128  // Additional accessors.
129  inline satcat5::router2::Offload* offload()
130  { return &m_offload; }
131 
132  protected:
133  // Internal variables.
134  satcat5::router2::Offload m_offload;
135  satcat5::router2::Table m_table;
136  u8 m_buff[BSIZE];
137  };
138 
147  template <unsigned BSIZE = 16384>
149  public:
151  const satcat5::eth::MacAddr& local_mac, // Local MAC address
152  const satcat5::ip::Addr& local_ip) // Local IP address
153  : StackCommon(local_mac, local_ip, &m_table, m_buff, BSIZE)
154  , m_igmp(&m_dispatch, &m_ip)
155  , m_table()
156  {} // Nothing else to initialize.
157 
158  inline satcat5::igmp::Server* igmp()
159  { return &m_igmp; }
160 
161  protected:
162  // Internal variables.
164  satcat5::ip::Table m_table;
165  u8 m_buff[BSIZE];
166  };
167  }
168 }
Memory-mapped local ConfigBus.
Definition: cfgbus_core.h:199
Implemention of "net::Dispatch" for Ethernet frames.
Definition: eth_dispatch.h:21
Router/Server for the Internet Group Management Protocol (IGMP).
Definition: igmp_server.h:74
Protocol handler and dispatch unit for Internet Protocol v4 (IPv4).
Definition: ip_dispatch.h:43
IPv4 forwarding table.
Definition: ip_table.h:144
Implement DeferFwd with static memory allocation.
Packet-processing pipeline for the IPv4 router.
void port_enable(const SATCAT5_PMASK_TYPE &mask)
Enable or disable specific port(s).
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).
Offload port for gateware-accelerated IPv4 routers.
Common parent for StackGateware and StackSoftware.
Definition: router2_stack.h:47
StackCommon(const satcat5::eth::MacAddr &local_mac, const satcat5::ip::Addr &local_ip, satcat5::ip::Table *table, u8 *buff, unsigned nbytes)
Constructor should only be called by the child class.
Definition: router2_stack.h:75
~StackCommon()
Destructor should only be called by the child class.
Definition: router2_stack.h:91
Router implementation where some or all ports are gateware.
Router implementation where all ports are software-defined.
IPv4 forwarding table with hardware mirroring.
Definition: router2_table.h:22
Dispatcher sorts incoming UDP messages by port index.
Definition: udp_dispatch.h:20
#define SATCAT5_PMASK_TYPE
Set the integer type used to identify source and destination ports.
Definition: eth_switch.h:41
Router-side implementation of the Internet Group Management Protocol (IGMP)
An Ethernet MAC address (with serializable interface).
Definition: eth_header.h:29
IPv4 address is a 32-bit unsigned integer.
Definition: ip_core.h:15