Loading...
Searching...
No Matches
switch.h
/*
* Copyright (C) 2016-2017, 2020, 2022-2024 Kernkonzept GmbH.
* Author(s): Jean Wolter <jean.wolter@kernkonzept.com>
* Alexander Warg <warg@os.inf.tu-dresden.de>
*
* License: see LICENSE.spdx (in this directory or the directories above)
*/
#pragma once
#include "port.h"
#include "port_l4virtio.h"
#include "mac_table.h"
#if CONFIG_VNS_IXL
#include "port_ixl.h"
#endif
class Virtio_switch
{
private:
Port_iface **_ports;
Port_iface *_monitor = nullptr;
unsigned _max_ports;
unsigned _max_used = 0;
Mac_table<> _mac_table;
// Limits the number of consecutive TX requests a port can process before
// being interrupted to ensure fairness to other ports.
static constexpr unsigned Tx_burst = 128;
int lookup_free_slot();
template<typename REQ>
void handle_tx_request(Port_iface *port, REQ const &request);
template<typename PORT>
void handle_tx_requests(PORT *port, unsigned &num_reqs_handled);
void all_rx_notify_emit_and_enable()
{
for (unsigned idx = 0; idx < _max_ports; ++idx)
if (_ports[idx])
_ports[idx]->rx_notify_emit_and_enable();
}
void all_rx_notify_disable_and_remember()
{
for (unsigned idx = 0; idx < _max_ports; ++idx)
if (_ports[idx])
_ports[idx]->rx_notify_disable_and_remember();
}
public:
explicit Virtio_switch(unsigned max_ports);
bool add_port(Port_iface *port);
bool add_monitor_port(Port_iface *port);
void check_ports();
bool handle_l4virtio_port_tx(L4virtio_port *port);
#if CONFIG_VNS_IXL
bool handle_ixl_port_tx(Ixl_port *port);
#endif
int port_available(bool monitor)
{
if (monitor)
return !_monitor ? 0 : -1;
return lookup_free_slot();
}
};
L4virtio_port
A Port on the Virtio Net Switch.
Definition port_l4virtio.h:37
Mac_table
Mac_table manages a 1:n association between ports and MAC addresses.
Definition mac_table.h:41
Virtio_switch::check_ports
void check_ports()
Check validity of ports.
Definition switch.cc:69
Virtio_switch::Virtio_switch
Virtio_switch(unsigned max_ports)
Create a switch with n ports.
Definition switch.cc:12
Virtio_switch::add_monitor_port
bool add_monitor_port(Port_iface *port)
Add a monitor port to the switch.
Definition switch.cc:54
Virtio_switch::handle_l4virtio_port_tx
bool handle_l4virtio_port_tx(L4virtio_port *port)
Handle TX queue of the given port.
Definition switch.cc:194
Virtio_switch::port_available
int port_available(bool monitor)
Is there still a free port on this switch available?
Definition switch.h:148
Virtio_switch::add_port
bool add_port(Port_iface *port)
Add a port to the switch.
Definition switch.cc:29