interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / kernel / x86 / courier_udp.h

57 lines · 3479 bytes Raw Blame History
1/* courier_udp.h -- Allen's courier over Ethernet (x86/courier_udp_x86.c):
2 * the same lines as the serial courier (svc/courier.h), carried to the far-off
3 * worker on the Spark in UDP datagrams, the way the test computer's netboot
4 * loader and lab report already talk to it: Ethernet broadcast frames, source
5 * address 0.0.0.0 (this kernel has no address of its own and asks for none),
6 * destination 255.255.255.255, one port both ways. No ARP, no DHCP, no
7 * floating point. Lab image only (make imac-kernel CK_X86_REPORT=1): the
8 * default image has no way to send or receive a frame.
9 *
10 * Every datagram is a text head and a body:
11 * "ALLEN-COURIER v=1 run=<16 hex> kind=<K> seq=<n> part=<i>/<n> bytes=<total>\n<body>"
12 * run names this boot (the kernel's clock at start mixed with its MAC); the
13 * far side echoes it and the kernel ignores any other. Kinds:
14 * HELLO kernel -> far side, every 2 s until HI, then every 10 s (a keepalive)
15 * HI far side -> kernel; ready() is 1 while one came within 30 s
16 * JOB kernel -> far side, the job line cut into parts of 1000 bytes,
17 * the whole set sent again every 2 s until ACK or the first LINE
18 * ACK far side -> kernel: the job arrived whole
19 * LINE far side -> kernel: one answer line ("SAY ..." or "WAIT ...") per
20 * datagram, part = its number within the job's answer (from 1)
21 * GOT kernel -> far side for every LINE taken: the far side sends a line
22 * again until it hears GOT, so no part is lost; a line out of order
23 * is dropped and comes again in its turn
24 * Lines taken through take() are the LINE bodies, in order, never twice.
25 * The frame device is handed in (ck_netio), so the same code runs on the
26 * host against a real relay (x86/tests/courier_udp_test.c): the kernel binds
27 * it to the Broadcom chip (tg3_x86.c) and its clock. */
28#ifndef AIENOS_COURIER_UDP_H
29#define AIENOS_COURIER_UDP_H
30#include <stddef.h>
31#include <stdint.h>
32#include "../svc/courier.h"
33
34#define CK_COURIER_PORT 47033u /* both ends (the relay and the scripts read this line) */
35#define CK_COURIER_PART 1000u /* body bytes per JOB datagram */
36#define CK_COURIER_JOB_MAX 4096u /* the longest job line */
37#define CK_COURIER_LINE_MAX 320u /* the longest answer line taken */
38
39typedef struct ck_netio {
40 void *ctx;
41 int (*send)(void *ctx, const uint8_t *frame, size_t n); /* a whole Ethernet frame: 0, or -1 */
42 size_t (*recv)(void *ctx, uint8_t *frame, size_t cap); /* the next frame waiting, bytes; 0: none */
43 int (*link)(void *ctx); /* 1 while frames can go */
44 uint64_t (*now)(void *ctx); /* a clock counting hz per second */
45} ck_netio;
46
47/* Sets the courier up on io (kept by reference) with this machine's MAC,
48 * its source address (0.0.0.0 when none) and the far side's (broadcast by
49 * default), and calls HELLO. Returns the courier; never NULL. One instance. */
50const ck_courier *ck_courier_udp_init(const ck_netio *io, const uint8_t mac[6], const uint8_t ip[4],
51 const uint8_t peer_ip[4], uint16_t port, uint64_t hz);
52/* Counters for the lab report (no words): datagrams in, out, lines taken,
53 * job resends, dropped frames. */
54void ck_courier_udp_stats(unsigned *in, unsigned *out, unsigned *lines, unsigned *resends, unsigned *dropped);
55/* The run id of this instance (0 before init). */
56uint64_t ck_courier_udp_run(void);
57#endif