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

A router that has multiple network interfaces and performs longest-prefix-match routing between them. More...

#include <router.hh>

Public Member Functions

size_t add_interface (AsyncNetworkInterface &&interface)
 
void add_route (const uint32_t route_prefix, const uint8_t prefix_length, const std::optional< Address > next_hop, const size_t interface_num)
 Add a route (a forwarding rule) More...
 
AsyncNetworkInterfaceinterface (const size_t N)
 Access an interface by index. More...
 
void route ()
 Route packets between the interfaces. More...
 

Private Member Functions

void route_one_datagram (InternetDatagram &dgram)
 

Private Attributes

std::vector< AsyncNetworkInterface_interfaces {}
 The router's collection of network interfaces. More...
 

Detailed Description

A router that has multiple network interfaces and performs longest-prefix-match routing between them.

Definition at line 43 of file router.hh.

Member Function Documentation

◆ add_interface()

size_t Router::add_interface ( AsyncNetworkInterface &&  interface)
inline

Add an interface to the router

Parameters
[in]interfacean already-constructed network interface
Returns
The index of the interface after it has been added to the router

Definition at line 56 of file router.hh.

◆ add_route()

void Router::add_route ( const uint32_t  route_prefix,
const uint8_t  prefix_length,
const std::optional< Address next_hop,
const size_t  interface_num 
)

Add a route (a forwarding rule)

Parameters
[in]route_prefixThe "up-to-32-bit" IPv4 address prefix to match the datagram's destination address against
[in]prefix_lengthFor this route to be applicable, how many high-order (most-significant) bits of the route_prefix will need to match the corresponding bits of the datagram's destination address?
[in]next_hopThe IP address of the next hop. Will be empty if the network is directly attached to the router (in which case, the next hop address should be the datagram's final destination).
[in]interface_numThe index of the interface to send the datagram out on.

Definition at line 25 of file router.cc.

◆ interface()

AsyncNetworkInterface& Router::interface ( const size_t  N)
inline

Access an interface by index.

Definition at line 62 of file router.hh.

◆ route()

void Router::route ( )

Route packets between the interfaces.

Definition at line 42 of file router.cc.

◆ route_one_datagram()

void Router::route_one_datagram ( InternetDatagram dgram)
private

Send a single datagram from the appropriate outbound interface to the next hop, as specified by the route with the longest prefix_length that matches the datagram's destination address.

Parameters
[in]dgramThe datagram to be routed

Definition at line 37 of file router.cc.

Member Data Documentation

◆ _interfaces

std::vector<AsyncNetworkInterface> Router::_interfaces {}
private

The router's collection of network interfaces.

Definition at line 45 of file router.hh.


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