SatCat5
router2_deferfwd.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 // Deferred packet forwarding for the IPv4 router
6 
7 #pragma once
8 
9 #include <satcat5/eth_arp.h>
10 #include <satcat5/eth_switch.h>
11 #include <satcat5/ip_core.h>
12 #include <satcat5/list.h>
13 #include <satcat5/timeref.h>
14 
15 namespace satcat5 {
16  namespace router2 {
19  struct DeferPkt {
20  public:
21  // All data and metadata are public variables:
25  u16 sent;
26  u16 trem;
27 
28  // Explicitly declare default constructor and assignment methods.
29  DeferPkt() = default;
30  DeferPkt(const DeferPkt& t) = delete;
31  DeferPkt& operator=(const DeferPkt& t) = delete;
32 
35 
36  private:
37  // Linked list to the next packet object.
40  };
41 
55  class DeferFwd
57  , public satcat5::poll::Timer
58  {
59  public:
61  bool accept(const satcat5::eth::PluginPacket& meta);
62 
63  protected:
66  DeferFwd(
69  unsigned bcount);
70  ~DeferFwd() SATCAT5_OPTIONAL_DTOR;
71 
72  // Event handler callbacks.
73  void arp_event(
74  const satcat5::eth::MacAddr& mac,
75  const satcat5::ip::Addr& ip) override;
76  void timer_event() override;
77 
78  // Packet handlers may mutate the active list,
79  // so they return the next item to be processed.
80  satcat5::router2::DeferPkt* request_arp(
82  satcat5::router2::DeferPkt* request_fwd(
84 
85  // Pointers to upstream interface objects.
86  satcat5::router2::Dispatch* const m_parent;
88 
89  // Reference for measuring elapsed time.
91 
92  // Lists for empty and active packets.
95  };
96 
99  template <unsigned SIZE = SATCAT5_MBUFF_RXPKT>
101  public:
104  : DeferFwd(parent, m_buff, SIZE), m_buff{} {}
105 
106  protected:
107  // Backing array for parent (i.e., m_active and m_empty).
108  satcat5::router2::DeferPkt m_buff[SIZE];
109  };
110  }
111 }
Callback interface for responding to ARP and ICMP events.
Definition: eth_arp.h:46
Protocol handler for Ethernet-to-IPv4 ARP queries and replies.
Definition: eth_arp.h:68
Timer objects are polled after a fixed delay or at a regular interval.
Definition: polling.h:213
Deferred packet-forwarding system for the IPv4 router.
void timer_event() override
Child class MUST override this method.
DeferFwd(satcat5::router2::Dispatch *parent, satcat5::router2::DeferPkt *buff, unsigned bcount)
Constructor should only be accessed by children, and requires a backing array of empty DeferPkt objec...
bool accept(const satcat5::eth::PluginPacket &meta)
Accept this packet into the queue?
void arp_event(const satcat5::eth::MacAddr &mac, const satcat5::ip::Addr &ip) override
Callback for any announced MAC/IP address pair.
Implement DeferFwd with static memory allocation.
DeferFwdStatic(satcat5::router2::Dispatch *parent)
Constructor links the parent interface and the backing array.
Packet-processing pipeline for the IPv4 router.
Helper functions for manipulating singly-linked lists.
Definition: list.h:52
Protocol handler for the Address Resolution Protocol (ARP)
Software-defined Ethernet switch.
#define SATCAT5_PMASK_TYPE
Set the integer type used to identify source and destination ports.
Definition: eth_switch.h:41
Templated functions for manipulating singly-linked lists.
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
State information for a single deferred packet.
satcat5::ip::Addr dst_ip
Destination address.
satcat5::io::MultiPacket * pkt
Packet object.
SATCAT5_PMASK_TYPE dst_mask
Destination port-mask.
u16 trem
Remaining time in msec.
bool read_meta(satcat5::eth::PluginPacket &meta)
Reconstitute switch PacketMeta from this object.
u16 sent
Number of attempts so far.
Timestamp for measuring elapsed time.
Definition: timeref.h:48
TimeRef and TimeVal define the API for monotonic timers.