L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
switch.h
1/*
2 * Copyright (C) 2016-2017, 2020, 2022-2024 Kernkonzept GmbH.
3 * Author(s): Jean Wolter <jean.wolter@kernkonzept.com>
4 * Alexander Warg <warg@os.inf.tu-dresden.de>
5 *
6 * License: see LICENSE.spdx (in this directory or the directories above)
7 */
8#pragma once
9
10#include "port.h"
11#include "port_l4virtio.h"
12#include "mac_table.h"
13
14#if CONFIG_VNS_IXL
15#include "port_ixl.h"
16#endif
17
34{
35private:
36 Port_iface **_ports;
37 Port_iface *_monitor;
39 unsigned _max_ports;
40 unsigned _max_used;
41 Mac_table<> _mac_table;
42
43 // Limits the number of consecutive TX requests a port can process before
44 // being interrupted to ensure fairness to other ports.
45 static constexpr unsigned Tx_burst = 128;
46
47 int lookup_free_slot();
48
58 template<typename REQ>
59 void handle_tx_request(Port_iface *port, REQ const &request);
60
61 template<typename PORT>
62 void handle_tx_requests(PORT *port, unsigned &num_reqs_handled);
63
64
65 void all_rx_notify_emit_and_enable()
66 {
67 for (unsigned idx = 0; idx < _max_ports; ++idx)
68 if (_ports[idx])
69 _ports[idx]->rx_notify_emit_and_enable();
70 }
71
72 void all_rx_notify_disable_and_remember()
73 {
74 for (unsigned idx = 0; idx < _max_ports; ++idx)
75 if (_ports[idx])
76 _ports[idx]->rx_notify_disable_and_remember();
77 }
78
79public:
85 explicit Virtio_switch(unsigned max_ports);
86
95 bool add_port(Port_iface *port);
96
105 bool add_monitor_port(Port_iface *port);
106
114 void check_ports();
115
126
127#if CONFIG_VNS_IXL
137 bool handle_ixl_port_tx(Ixl_port *port);
138#endif
139
148 int port_available(bool monitor)
149 {
150 if (monitor)
151 return !_monitor ? 0 : -1;
152
153 return lookup_free_slot();
154 }
155};
A Port on the Virtio Net Switch.
Mac_table manages a 1:n association between ports and MAC addresses.
Definition mac_table.h:41
The Virtio switch contains all ports and processes network requests.
Definition switch.h:34
void check_ports()
Check validity of ports.
Definition switch.cc:70
bool add_monitor_port(Port_iface *port)
Add a monitor port to the switch.
Definition switch.cc:55
bool handle_l4virtio_port_tx(L4virtio_port *port)
Handle TX queue of the given port.
Definition switch.cc:195
int port_available(bool monitor)
Is there still a free port on this switch available?
Definition switch.h:148
bool add_port(Port_iface *port)
Add a port to the switch.
Definition switch.cc:30