|
Sponge
CS144's user-space TCP library
|
Go to the documentation of this file. 1 #ifndef SPONGE_LIBSPONGE_TUNFD_ADAPTER_HH
2 #define SPONGE_LIBSPONGE_TUNFD_ADAPTER_HH
9 #include <unordered_map>
22 std::optional<TCPSegment>
read() {
61 std::optional<TCPSegment>
read();
67 void tick(
const size_t ms_since_last_tick);
76 #endif // SPONGE_LIBSPONGE_TUNFD_ADAPTER_HH
std::optional< TCPSegment > read()
Attempts to read and parse an Ethernet frame containing an IPv4 datagram that contains a TCP segment.
size_t write(const char *str, const bool write_all=true)
Write a string, possibly blocking until all is written.
void write(TCPSegment &seg)
Creates an IPv4 datagram from a TCP segment and writes it to the TUN device.
void tick(const size_t ms_since_last_tick)
Called periodically when time elapses.
NetworkInterface _interface
NIC abstraction.
TapFD _tap
Raw Ethernet connection.
std::string read(const size_t limit=std::numeric_limits< size_t >::max())
Read up to limit bytes.
Wrapper around IPv4 addresses and DNS operations.
InternetDatagram wrap_tcp_in_ip(TCPSegment &seg)
A "network interface" that connects IP (the internet layer, or network layer) with Ethernet (the netw...
TCPOverIPv4OverEthernetAdapter(TapFD &&tap, const EthernetAddress ð_address, const Address &ip_address, const Address &next_hop)
Construct from a TapFD.
std::optional< TCPSegment > read()
Attempts to read and parse an IPv4 datagram containing a TCP segment related to the current connectio...
A FD adapter for IPv4 datagrams read from and written to a TAP device.
ParseResult parse(const Buffer buffer)
Parse the segment from a string.
An adapter class that adds random dropping behavior to an FD adapter.
void send_pending()
Sends any pending Ethernet frames.
A FD adapter for IPv4 datagrams read from and written to a TUN device.
Address _next_hop
IP address of the next hop.
void write(TCPSegment &seg)
Sends a TCP segment (in an IPv4 datagram, in an Ethernet frame).
TCPOverIPv4OverTunFdAdapter(TunFD &&tun)
Construct from a TunFD.
A FileDescriptor to a Linux TAP device.
A converter from TCP segments to serialized IPv4 datagrams.
A FileDescriptor to a Linux TUN device.
std::optional< TCPSegment > unwrap_tcp_in_ip(const InternetDatagram &ip_dgram)