6 #include <satcat5/ip_dispatch.h>
7 #include <satcat5/ptp_client.h>
8 #include <satcat5/ptp_dispatch.h>
9 #include <satcat5/ptp_interface.h>
15 using satcat5::ptp::DispatchTo;
25 , m_reply_mac(satcat5::eth::MACADDR_NONE)
26 , m_stored_mac(satcat5::eth::MACADDR_NONE)
27 , m_reply_vtag(satcat5::eth::VTAG_NONE)
28 , m_stored_vtag(satcat5::eth::VTAG_NONE)
29 , m_reply_ip(satcat5::ip::ADDR_NONE)
30 , m_stored_ip(satcat5::ip::ADDR_NONE)
35 #if SATCAT5_ALLOW_DELETION
36 Dispatch::~Dispatch() {
42 DispatchTo addr,
unsigned num_bytes, u8 ptp_msg_type)
45 unsigned max_bytes = num_bytes + 34;
56 if (eth_header.
type == satcat5::eth::ETYPE_IPV4) {
60 unsigned udp_bytes = num_bytes + satcat5::udp::HEADER_BYTES;
62 m_ip->
next_header(satcat5::ip::PROTO_UDP, dst_ip, udp_bytes);
78 m_stored_mac = m_reply_mac;
79 m_stored_vtag = m_reply_vtag;
80 m_stored_ip = m_reply_ip;
97 m_reply_mac = eth_header.
src;
98 m_reply_vtag = eth_header.
vtag;
101 if (eth_header.
type == satcat5::eth::ETYPE_IPV4) {
105 m_reply_ip = ip_header.
src();
111 m_reply_ip = satcat5::ip::ADDR_NONE;
125 return (addr == satcat5::ip::ADDR_NONE)
126 ? satcat5::eth::ETYPE_PTP : satcat5::eth::ETYPE_IPV4;
132 case DispatchTo::BROADCAST_L2:
134 satcat5::eth::MACADDR_BROADCAST, m_ip->macaddr(),
135 satcat5::eth::ETYPE_PTP, satcat5::eth::VTAG_NONE};
136 case DispatchTo::BROADCAST_L3:
138 satcat5::eth::MACADDR_BROADCAST, m_ip->macaddr(),
139 satcat5::eth::ETYPE_IPV4, satcat5::eth::VTAG_NONE};
140 case DispatchTo::REPLY:
142 m_reply_mac, m_ip->macaddr(),
143 infer_etype(m_reply_ip), m_reply_vtag};
146 m_stored_mac, m_ip->macaddr(),
147 infer_etype(m_stored_ip), m_stored_vtag};
153 ptp_msg_type == satcat5::ptp::Header::TYPE_DELAY_REQ ||
154 ptp_msg_type == satcat5::ptp::Header::TYPE_PDELAY_REQ ||
155 ptp_msg_type == satcat5::ptp::Header::TYPE_PDELAY_RESP) {
156 return satcat5::udp::PORT_PTP_EVENT;
158 return satcat5::udp::PORT_PTP_GENERAL;
164 case DispatchTo::REPLY:
return m_reply_ip;
165 case DispatchTo::STORED:
return m_stored_ip;
166 default:
return (ptp_msg_type == satcat5::ptp::Header::TYPE_PDELAY_REQ)
167 ? satcat5::ip::ADDR_PTP_PDELAY : satcat5::ip::ADDR_PTP_PRIMARY;
Limited read of next N bytes.
Abstract API for reading byte-streams and packets.
virtual void read_finalize()
Consume any remaining bytes in this frame, if applicable.
Abstract API for writing byte-streams and packets.
virtual unsigned get_write_space() const =0
How many bytes can be written without blocking?
Protocol handler and dispatch unit for Internet Protocol v4 (IPv4).
satcat5::ip::Header next_header(u8 protocol, const satcat5::ip::Addr &dst, unsigned inner_bytes, u8 ttl=SATCAT5_IP_TTL)
Create a basic IPv4 header with the specified information.
void ptp_rcvd(satcat5::io::LimitedRead &rd)
Dispatch calls this method for each incoming packet.
Dispatch and formatting for L2 and L3 PTP messages.
void store_addr(const satcat5::eth::MacAddr &mac, const satcat5::ip::Addr &ip=satcat5::ip::ADDR_NONE, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE)
Set the address for use with DispatchTo::STORED.
void store_reply_addr()
Set the address for use with DispatchTo::STORED.
satcat5::io::Writeable * ptp_send(satcat5::ptp::DispatchTo where, unsigned num_bytes, u8 ptp_msg_type)
Send a PTP message to the designated address(es).
void poll_demand() override
Deferred event handler, called after request().
Generic API for network ports that support PTP.
virtual satcat5::io::Writeable * ptp_tx_write()=0
Return an object suitable for writing the next PTP frame.
void ptp_callback(satcat5::poll::OnDemand *obj)
Set callback object for PTP-related packet handling.
virtual satcat5::io::Readable * ptp_rx_read()=0
Return an object suitable for reading the next PTP frame.
An Ethernet MAC address (with serializable interface).
EtherType field (uint16) is used a protocol-ID [1536..65535].
Header contents for an 802.1Q Virtual-LAN tag.
IPv4 address is a 32-bit unsigned integer.
UDP and TCP ports are both 16-bit unsigned integers.
Struct used for sourcePortIdentity and requestingPortIdentity.