6 #include <satcat5/ip_dispatch.h>
7 #include <satcat5/router2_deferfwd.h>
8 #include <satcat5/router2_dispatch.h>
17 static constexpr
unsigned DEBUG_VERBOSE = 0;
20 #ifndef SATCAT5_R2_RETRY_MAX
21 #define SATCAT5_R2_RETRY_MAX 4
24 #ifndef SATCAT5_R2_RETRY_MSEC
25 #define SATCAT5_R2_RETRY_MSEC 10
38 , m_tref(SATCAT5_CLOCK->now())
43 for (
unsigned a = 0 ; a < bcount ; ++a) {
44 m_empty.
add(buff + a);
51 #if SATCAT5_ALLOW_DELETION
52 DeferFwd::~DeferFwd() {
54 if (m_arp) m_arp->
remove(
this);
61 if (!m_parent->iface())
return false;
63 m_arp = m_parent->iface()->arp();
65 m_tref = SATCAT5_CLOCK->now();
89 pkt = (pkt->
dst_ip == ip) ? request_fwd(pkt, mac) : m_active.
next(pkt);
104 if (pkt->
trem < elapsed) {
105 pkt = request_arp(pkt);
107 pkt->
trem -= elapsed;
108 pkt = m_active.
next(pkt);
118 if (pkt->
sent <= SATCAT5_R2_RETRY_MAX) {
120 pkt->
trem = u16(SATCAT5_R2_RETRY_MSEC) << (pkt->
sent++);
128 m_parent->icmp_reply(satcat5::ip::ICMP_UNREACHABLE_HOST, 0, meta);
148 m_parent->adjust_mac(dst, meta);
149 auto debug = m_parent->m_debug;
150 if (DEBUG_VERBOSE > 0 && debug) meta.
pkt->
copy_to(debug);
151 count = m_parent->deliver_offload(meta)
bool send_query(const satcat5::ip::Addr &target, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE)
Send a query for a given IP address.
void add(satcat5::eth::ArpListener *evt)
Register an event-listener.
void remove(satcat5::eth::ArpListener *evt)
Unregister an event-listener.
unsigned deliver_switch(const satcat5::eth::PluginPacket &pkt)
Internal event-handlers called from deliver(...).
void free_packet(satcat5::io::MultiPacket *packet)
Immediately free memory associated with this packet.
void timer_every(unsigned msec)
Configure a repeating notification every X milliseconds.
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.
Packet-processing pipeline for the IPv4 router.
T * next(const T *item) const
Fetch pointer to the next item.
void add(T *item)
Add new item to front or back, whichever is simpler.
T * pop_front()
Remove the item at the head of the list.
void remove(T *item)
Remove the designated item from the list.
An Ethernet MAC address (with serializable interface).
Ephemeral data structure provided to plugin callbacks.
satcat5::io::MultiPacket * pkt
Complete packet contents.
satcat5::ip::Header ip
Copy of additional header fields, if present.
SATCAT5_PMASK_TYPE dst_mask
Destination mask for which port(s) receive this packet.
bool read_from(satcat5::io::MultiPacket *packet)
Read metadata from a packet object.
bool copy_to(satcat5::io::Writeable *wr) const
Copy the packet contents to the specified destination.
IPv4 address is a 32-bit unsigned integer.
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.
unsigned increment_msec()
Measure elapsed time in milliseconds, then increment by the returned quantized value.