Sponge
CS144's user-space TCP library
network_interface.hh
Go to the documentation of this file.
1 #ifndef SPONGE_LIBSPONGE_NETWORK_INTERFACE_HH
2 #define SPONGE_LIBSPONGE_NETWORK_INTERFACE_HH
3 
4 #include "ethernet_frame.hh"
5 #include "tcp_over_ip.hh"
6 #include "tun.hh"
7 
8 #include <optional>
9 #include <queue>
10 
13 
20 
33  private:
36 
39 
42 
43  public:
45  NetworkInterface(const EthernetAddress &ethernet_address, const Address &ip_address);
46 
49 
51 
54  void send_datagram(const InternetDatagram &dgram, const Address &next_hop);
55 
57 
61  std::optional<InternetDatagram> recv_frame(const EthernetFrame &frame);
62 
64  void tick(const size_t ms_since_last_tick);
65 };
66 
67 #endif // SPONGE_LIBSPONGE_NETWORK_INTERFACE_HH
NetworkInterface::recv_frame
std::optional< InternetDatagram > recv_frame(const EthernetFrame &frame)
Receives an Ethernet frame and responds appropriately.
Definition: network_interface.cc:40
NetworkInterface::frames_out
std::queue< EthernetFrame > & frames_out()
Access queue of Ethernet frames awaiting transmission.
Definition: network_interface.hh:48
tcp_over_ip.hh
EthernetFrame
Ethernet frame.
Definition: ethernet_frame.hh:8
std::queue< EthernetFrame >
NetworkInterface::_ethernet_address
EthernetAddress _ethernet_address
Ethernet (known as hardware, network-access-layer, or link-layer) address of the interface.
Definition: network_interface.hh:35
IPv4Datagram
IPv4 Internet datagram
Definition: ipv4_datagram.hh:8
NetworkInterface::_frames_out
std::queue< EthernetFrame > _frames_out
outbound queue of Ethernet frames that the NetworkInterface wants sent
Definition: network_interface.hh:41
Address
Wrapper around IPv4 addresses and DNS operations.
Definition: address.hh:13
NetworkInterface::send_datagram
void send_datagram(const InternetDatagram &dgram, const Address &next_hop)
Sends an IPv4 datagram, encapsulated in an Ethernet frame (if it knows the Ethernet destination addre...
Definition: network_interface.cc:32
NetworkInterface
A "network interface" that connects IP (the internet layer, or network layer) with Ethernet (the netw...
Definition: network_interface.hh:32
tun.hh
std::array
NetworkInterface::_ip_address
Address _ip_address
IP (known as internet-layer or network-layer) address of the interface.
Definition: network_interface.hh:38
NetworkInterface::tick
void tick(const size_t ms_since_last_tick)
Called periodically when time elapses.
Definition: network_interface.cc:46
NetworkInterface::NetworkInterface
NetworkInterface(const EthernetAddress &ethernet_address, const Address &ip_address)
Construct a network interface with given Ethernet (network-access-layer) and IP (internet-layer) addr...
Definition: network_interface.cc:23
ethernet_frame.hh