27 Virtio_net_switch::Port_statistics *_stats;
30 Port_iface(
char const *name)
32 strncpy(_name, name,
sizeof(_name));
33 _name[
sizeof(_name) - 1] =
'\0';
34#ifdef CONFIG_VNS_STATS
35 _stats = Switch_statistics::get_instance().allocate_port_statistics(name);
38 "Could not allocate port statistics.\n");
44#ifdef CONFIG_VNS_STATS
45 _stats->in_use =
false;
50 Port_iface(Port_iface
const &) =
delete;
51 Port_iface &operator = (Port_iface
const &) =
delete;
53 char const *get_name()
const
59 inline bool is_trunk()
const
60 {
return _vlan_id == VLAN_ID_TRUNK; }
62 inline bool is_native()
const
63 {
return _vlan_id == VLAN_ID_NATIVE; }
65 inline bool is_access()
const
66 {
return !is_trunk() && !is_native(); }
77 assert(vlan_valid_id(
id));
79 _vlan_bloom_filter = 0;
92 void set_vlan_trunk(
const std::vector<l4_uint16_t> &ids)
98 for (
const auto id : ids)
100 assert(vlan_valid_id(
id));
101 filter |= vlan_bloom_hash(
id);
102 _vlan_ids.insert(
id);
105 _vlan_id = VLAN_ID_TRUNK;
106 _vlan_bloom_filter = filter;
112 void set_vlan_trunk_all()
115 _vlan_id = VLAN_ID_TRUNK;
116 _vlan_bloom_filter = -1;
127 _vlan_id = VLAN_ID_TRUNK;
128 _vlan_bloom_filter = 0;
139 bool match_vlan(uint16_t
id)
150 if ((_vlan_bloom_filter & vlan_bloom_hash(
id)) == 0)
153 return _vlan_ids.find(
id) != _vlan_ids.end();
178 if (!src_port->is_trunk() && !src_port->is_native())
186 if (src_port->is_trunk())
192 virtual void rx_notify_disable_and_remember() = 0;
193 virtual void rx_notify_emit_and_enable() = 0;
195 virtual bool is_gone()
const = 0;
202 Delivered, Exception, Dropped,
220 virtual Result handle_request(Port_iface *src_port,
224 void reschedule_pending_tx()
225 { _pending_tx_reschedule->trigger(); }
239 std::set<l4_uint16_t> _vlan_ids;
243 {
return 1UL << (vid & 31U); }
254#ifdef CONFIG_VNS_STATS
255 inline void stat_inc_tx_num()
256 { _stats->tx_num++; }
257 inline void stat_inc_tx_dropped()
258 { _stats->tx_dropped++; }
260 { _stats->tx_bytes += bytes; }
261 inline void stat_inc_rx_num()
262 { _stats->rx_num++; }
263 inline void stat_inc_rx_dropped()
264 { _stats->rx_dropped++; }
266 { _stats->rx_bytes += bytes; }
268 inline void stat_inc_tx_num()
270 inline void stat_inc_tx_dropped()
274 inline void stat_inc_rx_num()
276 inline void stat_inc_rx_dropped()
C++ interface for capabilities.
Exception for an abstract runtime error.
A wrapper class around the value of a MAC address.
A network request to only a single destination.
Class for VLAN packet rewriting.
static constexpr Virtio_vlan_mangle remove()
Construct an object that removes the VLAN tag.
static constexpr Virtio_vlan_mangle add(l4_uint16_t tci)
Construct an object that adds a VLAN tag.
unsigned int l4_uint32_t
Unsigned 32bit value.
unsigned short int l4_uint16_t
Unsigned 16bit value.
unsigned long long l4_uint64_t
Unsigned 64bit value.