6 #include <satcat5/ip_ping.h>
7 #include <satcat5/ip_dispatch.h>
12 namespace log = satcat5::log;
16 , m_addr(iface, satcat5::ip::PROTO_ICMP)
17 , m_arp_tref(SATCAT5_CLOCK->now())
25 #if SATCAT5_ALLOW_DELETION
35 m_addr.
connect(dstaddr, satcat5::eth::MACADDR_NONE);
39 m_iface->arp()->
add(
this);
52 m_iface->icmp()->
add(
this);
64 m_iface->arp()->
remove(
this);
65 m_iface->icmp()->
remove(
this);
72 if (ip == m_addr.dstaddr()) {
81 if (from == m_addr.dstaddr()) {
88 void Ping::send_arping() {
91 m_arp_tref = SATCAT5_CLOCK->now();
98 void Ping::send_ping() {
101 m_reply_rcvd =
false;
102 m_arp_tref = SATCAT5_CLOCK->now();
107 }
else if (m_arp_remct > 0) {
113 log::Log(log::INFO,
"Ping: Gateway unreachable").
write(m_addr.gateway());
119 if (m_icmp_remct && m_arp_remct && m_addr.
ready()) {
121 }
else if (!m_reply_rcvd) {
122 log::Log(log::INFO,
"Ping: Request timed out.");
127 }
else if (m_arp_remct) {
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.
bool ready() const override
Is this address object ready for use? Child MUST override this method.
void connect(const satcat5::ip::Addr &dstaddr, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE)
Automatic address resolution using routing table + ARP.
void retry() override
If this Address is not in the ready() state, reattempt any steps required to do so,...
Protocol handler and dispatch unit for Internet Protocol v4 (IPv4).
Automatic "ping" functionality using an ICMP dispatch object A simplified wrapper for basic "ping" fu...
void arping(const satcat5::ip::Addr &dstaddr, unsigned qty=satcat5::ip::Ping::UNLIMITED)
Begin sending ARPING queries (ARP query).
void timer_event() override
Child class MUST override this method.
void ping_event(const satcat5::ip::Addr &from, u32 elapsed_usec) override
Callback method when a ping response is received.
static constexpr unsigned UNLIMITED
All requests can send N queries or until told to stop.
void arp_event(const satcat5::eth::MacAddr &mac, const satcat5::ip::Addr &ip) override
Callback for any announced MAC/IP address pair.
void stop()
Stop any ongoing activities.
void ping(const satcat5::ip::Addr &dstaddr, unsigned qty=satcat5::ip::Ping::UNLIMITED)
Begin sending PING queries (ICMP echo request).
void remove(satcat5::ip::PingListener *cb)
Add/remove callback handlers for Ping responses.
void add(satcat5::ip::PingListener *cb)
Add/remove callback handlers for Ping responses.
bool send_ping(satcat5::ip::Address &dst)
Initiate a ping (Echo request = Type 8.0).
The Log class creates and formats one log message.
Log & write10(s32 val)
Print integer as a decimal value with no leading zeros.
Log & write(const char *str)
Formatting methods for various data types.
void timer_stop()
Stop all future notifications.
void timer_every(unsigned msec)
Configure a repeating notification every X milliseconds.
Diagnostic logging to UART and/or Ethernet ports.
An Ethernet MAC address (with serializable interface).
IPv4 address is a 32-bit unsigned integer.
unsigned elapsed_usec() const
Elapsed time in microseconds.
TimeRef and TimeVal define the API for monotonic timers.