5#include <l4/virtio-net-switch/stats.h>
10 Virtio_net_switch::Statistics *_stats;
11 bool _initialized =
false;
13 Switch_statistics() {}
24 Virtio_net_switch::Statistics *stats()
29 throw L4::Runtime_error(-
L4_EAGAIN,
"Statistics not set up.");
32 static Switch_statistics& get_instance()
34 static Switch_statistics instance;
41 +
sizeof(Virtio_net_switch::Port_statistics) * num_max_ports);
42 void *addr = malloc(_size);
45 "Could not allocate statistics memory.");
47 memset(addr, 0, _size);
48 _stats =
reinterpret_cast<Virtio_net_switch::Statistics *
>(addr);
50 _stats->max_ports = num_max_ports;
53 Virtio_net_switch::Port_statistics *
54 allocate_port_statistics(
char const* name)
56 for (
unsigned i = 0; i < _stats->max_ports; ++i)
58 if (!_stats->port_stats[i].in_use)
60 memset(
reinterpret_cast<void*
>(&_stats->port_stats[i]), 0,
61 sizeof(Virtio_net_switch::Port_statistics));
62 _stats->port_stats[i].in_use = 1;
63 size_t len = std::min(strlen(name),
sizeof(_stats->port_stats[i].name) - 1);
64 memcpy(_stats->port_stats[i].name, name, len);
65 _stats->port_stats[i].name[len] =
'\0';
67 return &_stats->port_stats[i];
76 Switch_statistics(Switch_statistics
const&) =
delete;
77 void operator=(Switch_statistics
const &) =
delete;
static Env const * env() noexcept
Returns the initial environment for the current task.
L4::Cap< Rm > rm() const noexcept
Object-capability to the region map.
unsigned int l4_size_t
Unsigned size type.
unsigned long l4_addr_t
Address type.
unsigned long long l4_uint64_t
Unsigned 64bit value.
l4_addr_t l4_round_page(l4_addr_t address) L4_NOTHROW
Round address up to the next page.