1/* @ajax/mesh-net-counters: meshd's live network counters (mesh-abi "Network I/O").
2 *
3 * Per peer link, the bytes and frames by kind meshd reads and writes; the
4 * control port's and the HTTP relay's bytes and requests. Every counter is a
5 * cumulative u64 since meshd started, a relaxed atomic bumped once per frame
6 * or request by the thread that moved it; `fill` copies them into a host
7 * status block at snapshot time (viewers derive rates). */
8#ifndef MESH_NET_COUNTERS_H
9#define MESH_NET_COUNTERS_H
1011#include "mesh/abi/base.h"
12#include "mesh/abi/host_links.h"
1314#include <stdatomic.h>
15#include <stddef.h>
16#include <stdint.h>
1718typedef struct {
19 _Atomic uint64_t rx_bytes, tx_bytes;
20 _Atomic uint64_t rx[MESH_NET_KINDS], tx[MESH_NET_KINDS];
21} mesh_link_counters;
2223typedef struct {
24 mesh_link_counters links[MESH_MAX_SYSTEMS];
25 _Atomic uint64_t ctl[3]; /* bytes read, bytes written, requests */
26 _Atomic uint64_t http[3]; /* head bytes read, response bytes written, connections */
27} mesh_net_counters;
2829void mesh_net_counters_init(mesh_net_counters *c);
30/* A frame of type `ty`, `bytes` long (type byte included), read from system k. */
31void mesh_net_counters_rx(mesh_net_counters *c, uint32_t k, uint8_t ty, size_t bytes);
32/* A frame written to system k (`f` starts with its type byte). */
33void mesh_net_counters_tx(mesh_net_counters *c, uint32_t k, const uint8_t *f, size_t len);
34/* A control request: its line (and body) read, its reply written. */
35void mesh_net_counters_ctl(mesh_net_counters *c, size_t rx, size_t tx);
36/* An HTTP connection: its head read, its response written. */
37void mesh_net_counters_http(mesh_net_counters *c, size_t rx, size_t tx);
38/* Writes the live counters into a host status block (SNAP_HOST bytes). */
39void mesh_net_counters_fill(mesh_net_counters *c, uint8_t *block);
4041#endif