L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
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
18#include <vector>
19
36{
37private:
38 std::vector<Port_iface *> _ports;
39 Port_iface *_monitor = nullptr;
40
41 unsigned _max_ports;
42 Mac_table<> _mac_table;
43
44 // Limits the number of consecutive TX requests a port can process before
45 // being interrupted to ensure fairness to other ports.
46 static constexpr unsigned Tx_burst = 128;
47
57 template<typename REQ>
58 void handle_tx_request(Port_iface *port, REQ const &request);
59
60 template<typename PORT>
61 void handle_tx_requests(PORT *port, unsigned &num_reqs_handled);
62
63
64 void all_rx_notify_emit_and_enable()
65 {
66 for (auto *port : _ports)
67 port->rx_notify_emit_and_enable();
68 }
69
70 void all_rx_notify_disable_and_remember()
71 {
72 for (auto *port: _ports)
73 port->rx_notify_disable_and_remember();
74 }
75
76public:
83 explicit Virtio_switch(unsigned max_ports);
84
93 bool add_port(Port_iface *port);
94
103 bool add_monitor_port(Port_iface *port);
104
112 void check_ports();
113
124
125#if CONFIG_VNS_IXL
135 bool handle_ixl_port_tx(Ixl_port *port);
136#endif
137
146 bool port_available(bool monitor)
147 {
148 if (monitor)
149 return _monitor == 0;
150
151 return _ports.size() < _max_ports;
152 }
153};
154
A Port on the Virtio Net Switch.
Mac_table manages a 1:n association between ports and MAC addresses.
Definition mac_table.h:41
bool port_available(bool monitor)
Is there still a free port on this switch available?
Definition switch.h:146
void check_ports()
Check validity of ports.
Definition switch.cc:56
Virtio_switch(unsigned max_ports)
Create a switch with n ports.
Definition switch.cc:12
bool add_monitor_port(Port_iface *port)
Add a monitor port to the switch.
Definition switch.cc:41
bool handle_l4virtio_port_tx(L4virtio_port *port)
Handle TX queue of the given port.
Definition switch.cc:180
bool add_port(Port_iface *port)
Add a port to the switch.
Definition switch.cc:17