Sponge
CS144's user-space TCP library
Public Member Functions | Private Attributes | List of all members
AsyncNetworkInterface Class Reference

A wrapper for NetworkInterface that makes the host-side interface asynchronous: instead of returning received datagrams immediately (from the recv_frame method), it stores them for later retrieval. Otherwise, behaves identically to the underlying implementation of NetworkInterface. More...

#include <router.hh>

Inheritance diagram for AsyncNetworkInterface:
Inheritance graph
[legend]

Public Member Functions

 AsyncNetworkInterface (NetworkInterface &&interface)
 Construct from a NetworkInterface. More...
 
std::queue< InternetDatagram > & datagrams_out ()
 Access queue of Internet datagrams that have been received. More...
 
 NetworkInterface (const EthernetAddress &ethernet_address, const Address &ip_address)
 Construct a network interface with given Ethernet (network-access-layer) and IP (internet-layer) addresses. More...
 
void recv_frame (const EthernetFrame &frame)
 Receives and Ethernet frame and responds appropriately. More...
 
- Public Member Functions inherited from NetworkInterface
 NetworkInterface (const EthernetAddress &ethernet_address, const Address &ip_address)
 Construct a network interface with given Ethernet (network-access-layer) and IP (internet-layer) addresses. More...
 
std::queue< EthernetFrame > & frames_out ()
 Access queue of Ethernet frames awaiting transmission. More...
 
std::optional< InternetDatagramrecv_frame (const EthernetFrame &frame)
 Receives an Ethernet frame and responds appropriately. More...
 
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 address). More...
 
void tick (const size_t ms_since_last_tick)
 Called periodically when time elapses. More...
 

Private Attributes

std::queue< InternetDatagram_datagrams_out {}
 

Detailed Description

A wrapper for NetworkInterface that makes the host-side interface asynchronous: instead of returning received datagrams immediately (from the recv_frame method), it stores them for later retrieval. Otherwise, behaves identically to the underlying implementation of NetworkInterface.

Definition at line 14 of file router.hh.

Constructor & Destructor Documentation

◆ AsyncNetworkInterface()

AsyncNetworkInterface::AsyncNetworkInterface ( NetworkInterface &&  interface)
inline

Construct from a NetworkInterface.

Definition at line 21 of file router.hh.

Member Function Documentation

◆ datagrams_out()

std::queue<InternetDatagram>& AsyncNetworkInterface::datagrams_out ( )
inline

Access queue of Internet datagrams that have been received.

Definition at line 38 of file router.hh.

◆ NetworkInterface()

NetworkInterface::NetworkInterface

Construct a network interface with given Ethernet (network-access-layer) and IP (internet-layer) addresses.

Parameters
[in]ethernet_addressEthernet (what ARP calls "hardware") address of the interface
[in]ip_addressIP (what ARP calls "protocol") address of the interface

Definition at line 23 of file network_interface.cc.

◆ recv_frame()

void AsyncNetworkInterface::recv_frame ( const EthernetFrame frame)
inline

Receives and Ethernet frame and responds appropriately.

  • If type is IPv4, pushes to the datagrams_out queue for later retrieval by the owner.
  • If type is ARP request, learn a mapping from the "sender" fields, and send an ARP reply.
  • If type is ARP reply, learn a mapping from the "target" fields.
Parameters
[in]framethe incoming Ethernet frame

Definition at line 30 of file router.hh.

Member Data Documentation

◆ _datagrams_out

std::queue<InternetDatagram> AsyncNetworkInterface::_datagrams_out {}
private

Definition at line 15 of file router.hh.


The documentation for this class was generated from the following file: