SatCat5
eth_socket.h
1 // Copyright 2021-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 // BufferedIO wrapper for two-way Ethernet communication.
6 
7 #pragma once
8 
9 #include <satcat5/ethernet.h>
10 #include <satcat5/net_socket.h>
11 
12 // Default size parameters for the fixed-size buffer.
13 // Override with a larger buffer size to support jumbo Ethernet frames.
14 // (i.e., Add gcc argument "-DSATCAT5_ESOCK_BUFFSIZE=16384" etc.)
15 #ifndef SATCAT5_ESOCK_BUFFSIZE
16 #define SATCAT5_ESOCK_BUFFSIZE 1600 // One full-size Ethernet frame
17 #endif
18 
19 #ifndef SATCAT5_ESOCK_PACKETS
20 #define SATCAT5_ESOCK_PACKETS 32 // ...or many smaller frames
21 #endif
22 
23 namespace satcat5 {
24  namespace eth {
27  class SocketCore
30  {
31  public:
33  void bind(
34  const satcat5::eth::MacType& lcltype,
35  const satcat5::eth::VlanTag& vtag = satcat5::eth::VTAG_NONE);
36 
38  void connect(
39  const satcat5::eth::MacAddr& dstmac,
40  const satcat5::eth::MacType& dsttype,
41  const satcat5::eth::MacType& lcltype = satcat5::eth::ETYPE_NONE,
42  const satcat5::eth::VlanTag& vtag = satcat5::eth::VTAG_NONE);
43 
44  // Useful inherited methods from net::SocketCore:
45  // close(), ready_rx(), ready_tx()
46 
47  protected:
49  SocketCore(
51  u8* txbuff, unsigned txbytes, unsigned txpkt,
52  u8* rxbuff, unsigned rxbytes, unsigned rxpkt);
53  ~SocketCore() {}
54  };
55 
57  class Socket final : public satcat5::eth::SocketCore {
58  public:
61  ~Socket() {}
62 
63  // Useful inherited methods from eth::SocketCore:
64  // bind(...), connect(...), close(), ready_rx(), ready_tx()
65 
66  private:
67  u8 m_txbuff[SATCAT5_ESOCK_BUFFSIZE];
68  u8 m_rxbuff[SATCAT5_ESOCK_BUFFSIZE];
69  };
70 
72  class SocketRx final : public satcat5::eth::SocketCore {
73  public:
75  explicit SocketRx(satcat5::eth::Dispatch* iface);
76  ~SocketRx() {}
77 
78  // Useful inherited methods from eth::SocketCore:
79  // bind(...), connect(...), close(), ready_rx(), ready_tx()
80 
81  private:
82  u8 m_rxbuff[SATCAT5_ESOCK_BUFFSIZE];
83  };
84 
86  class SocketTx final : public satcat5::eth::SocketCore {
87  public:
89  explicit SocketTx(satcat5::eth::Dispatch* iface);
90  ~SocketTx() {}
91 
92  // Useful inherited methods from eth::SocketCore:
93  // bind(...), connect(...), close(), ready_rx(), ready_tx()
94 
95  private:
96  u8 m_txbuff[SATCAT5_ESOCK_BUFFSIZE];
97  };
98  }
99 }
Inheritable container for a eth::Address.
Definition: eth_address.h:60
Implemention of "net::Dispatch" for Ethernet frames.
Definition: eth_dispatch.h:21
BufferedIO wrapper for two-way Ethernet communication.
Definition: eth_socket.h:30
SocketCore(satcat5::eth::Dispatch *iface, u8 *txbuff, unsigned txbytes, unsigned txpkt, u8 *rxbuff, unsigned rxbytes, unsigned rxpkt)
Child must provide transmit and receive working buffers.
Definition: eth_socket.cc:35
void bind(const satcat5::eth::MacType &lcltype, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE)
Listening mode only (no remote address).
Definition: eth_socket.cc:47
void connect(const satcat5::eth::MacAddr &dstmac, const satcat5::eth::MacType &dsttype, const satcat5::eth::MacType &lcltype=satcat5::eth::ETYPE_NONE, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE)
Two-way connection.
Definition: eth_socket.cc:55
SocketCore with fixed-size transmit and receive buffers.
Definition: eth_socket.h:57
Socket(satcat5::eth::Dispatch *iface)
Link this socket to a network interface.
Definition: eth_socket.cc:11
SocketCore with fixed-size receive buffer only.
Definition: eth_socket.h:72
SocketRx(satcat5::eth::Dispatch *iface)
Connect this Socket to a network interface.
Definition: eth_socket.cc:19
SocketCore with fixed-size transmit buffer only.
Definition: eth_socket.h:86
SocketTx(satcat5::eth::Dispatch *iface)
Connect this Socket to a network interface.
Definition: eth_socket.cc:27
Buffered I/O for sending and receiving messages over a network.
Definition: net_socket.h:24
Buffered wrappers for generic network communication.
An Ethernet MAC address (with serializable interface).
Definition: eth_header.h:29
EtherType field (uint16) is used a protocol-ID [1536..65535].
Definition: eth_header.h:96
Header contents for an 802.1Q Virtual-LAN tag.
Definition: eth_header.h:124