1/* @ajax/mesh-abi-host-links: Peer link records (L_*) and the frame kinds they count.
2 *
3 * Part of alpha-c-mesh, a C port of alpha-rust-mesh (README.md says from where). */
4#ifndef MESH_ABI_HOST_LINKS_H
5#define MESH_ABI_HOST_LINKS_H
67#include <stdbool.h>
8#include <stddef.h>
9#include <stdint.h>
10#include "mesh/abi/peer_frames.h"
11#include "mesh/abi/fields.h"
1213/* One link record (L_*) per member k, at link(k): the bytes and frames of
14 * this meshd's peer link to system k, summed over every link to it since
15 * start (its own record stays zero). */
16#define MESH_S_LINKS 0x700
17#define MESH_LINK_BYTES 0x80
18#define MESH_L_RX_BYTES 0x00 /* u64 frame bytes read (type byte included; TCP/IP headers not) */
19#define MESH_L_TX_BYTES 0x08 /* u64 frame bytes written */
20#define MESH_L_RX_FRAMES 0x10 /* u64 x NET_KINDS frames read, by frame_kind */
21#define MESH_L_TX_FRAMES 0x30 /* u64 x NET_KINDS frames written */
22#define MESH_L_LOCAL 0x50 /* 32 bytes: the link's local address (ip:port), NUL padded */
23#define MESH_L_IFACE 0x70 /* 16 bytes: the interface that address is on */
24/* Frame kinds counted per link: a lockstep group's frames (F_ROUND, F_HELLO),
25 * placement (F_FRAME, F_INPUT, F_PLACE), the desired state (F_STATE,
26 * F_STATE_ACK, F_COMMIT, F_CTL, F_CTL_REPLY, F_IMAGE_REQ, F_IMAGE, F_VIEW_REQ,
27 * F_VIEW: "state"), control and liveness (F_JOIN, F_BEAT, F_VOTE_REQ, F_VOTE,
28 * F_LOADREP, F_PERF); the jobs' frames and their blobs count as "state". */
29#define MESH_NET_KINDS 4
30#define MESH_KIND_ROUND 0
31#define MESH_KIND_PLACE 1
32#define MESH_KIND_LOAD 2
33#define MESH_KIND_CTL 3
34#define MESH_KIND_NAMES_LEN MESH_NET_KINDS
35extern const char *const MESH_KIND_NAMES[MESH_NET_KINDS];
36#define MESH_LINK_FIELDS_LEN 6
37extern const mesh_field MESH_LINK_FIELDS[6];
3839/* The link record of member k. */
40static inline size_t mesh_link(uint32_t k) { return MESH_S_LINKS + MESH_LINK_BYTES * (size_t)k; }
41/* The kind (KIND_*) a frame type is counted under. */
42static inline size_t mesh_frame_kind(uint8_t ty) {
43 switch (ty) {
44 case MESH_F_ROUND: case MESH_F_HELLO: return MESH_KIND_ROUND;
45 case MESH_F_FRAME: case MESH_F_INPUT: case MESH_F_PLACE: return MESH_KIND_PLACE;
46 case MESH_F_STATE: case MESH_F_STATE_ACK: case MESH_F_COMMIT: case MESH_F_CTL: case MESH_F_CTL_REPLY:
47 case MESH_F_IMAGE_REQ: case MESH_F_IMAGE: case MESH_F_VIEW_REQ: case MESH_F_VIEW: return MESH_KIND_LOAD;
48 default: return ty >= MESH_F_JOB_AVAIL && ty <= MESH_F_BLOB ? MESH_KIND_LOAD : MESH_KIND_CTL;
49 }
50}
5152/* The Rust const asserts that only involve this package. */
53_Static_assert((MESH_S_LINKS % 8 == 0), "S_LINKS.is_multiple_of(8)");
54_Static_assert((MESH_LINK_BYTES % 8 == 0), "LINK_BYTES.is_multiple_of(8)");
55_Static_assert(MESH_L_RX_FRAMES + 8 * MESH_NET_KINDS == MESH_L_TX_FRAMES, "L_RX_FRAMES + 8 * NET_KINDS == L_TX_FRAMES");
56_Static_assert(MESH_L_TX_FRAMES + 8 * MESH_NET_KINDS <= MESH_L_LOCAL, "L_TX_FRAMES + 8 * NET_KINDS <= L_LOCAL");
5758#endif