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 / omega / allen / tests / look-chat.om

313 lines · 7537 bytes Raw Blame History
1note Courier over UDP 47033 on net.om: concatenate after platform.om, the gate.sh
2note core list, net.om, look-chat.om and tests/check.om. Host-only fixtures: HI,
3note ACK and LINE datagrams are built by courier.om's own serializer in the live
4note relay's form (allen-courier main.rs datagram(): HI/ACK part=0/0 bytes=0,
5note LINE part=i/0 bytes=<body length>), wrapped in Ethernet/IPv4/UDP frames with
6note an independent checksum, and fed through netinput; outgoing frames are
7note checked against the same rules. The first HELLO frame is written raw to
8note fd 2 for an outside checksum check. check prints through Outb, so every
9note fixture is delivered before its packet result is checked.
10text Cvline " 1/1 Model answer."
11text Cvsay "SAY "
12text Cvask "hello"
13global Cvdst ulong 1
14fn cvw16 p ulong v ulong to void
15put Nrx p uchar and shr v 8 255
16put Nrx add p 1 uchar and v 255
17end
18fn cvw32 p ulong v ulong to void
19cvw16 p shr v 16
20cvw16 add p 2 and v 65535
21end
22fn cvt16 p ulong to ulong
23ret add shl ulong get Ntx p 8 ulong get Ntx add p 1
24end
25fn cvt32 p ulong to ulong
26ret add shl cvt16 p 16 cvt16 add p 2
27end
28note Independent one's-complement sum over Nrx (tx false) or Ntx (tx true).
29fn cvsum tx bool p ulong n ulong to ulong
30s = ulong 0
31for i ulong n
32v = ulong 0
33if tx
34v = ulong get Ntx add p i
35else
36v = ulong get Nrx add p i
37end
38if eq rem i 2 0
39s = add s shl v 8
40else
41s = add s v
42end
43end
44ret s
45end
46fn cvcpl s ulong to ulong
47while gt s 65535 bound 8
48s = add shr s 16 and s 65535
49end
50ret xor s 65535
51end
52fn cvpseudo a ulong b ulong n ulong to ulong
53s = add add shr a 16 and a 65535 add shr b 16 and b 65535
54ret add s add 17 n
55end
56fn cvip4 a ulong b ulong c ulong d ulong to ulong
57ret add add shl a 24 shl b 16 add shl c 8 d
58end
59note Wrap Outb[0..Outlen) in a frame from 192.168.1.10:sp to Cvdst:dp and feed it in.
60fn cvdeliver sp ulong dp ulong now ulong to void
61n = get Outlen 0
62for i ulong 2048
63put Nrx i uchar 0
64end
65for i ulong 6
66put Nrx i uchar 255
67put Nrx add i 6 uchar 0
68end
69put Nrx 6 uchar 2
70put Nrx 11 uchar 170
71cvw16 12 2048
72put Nrx 14 uchar 69
73cvw16 16 add n 28
74cvw16 20 16384
75put Nrx 22 uchar 64
76put Nrx 23 uchar 17
77src = cvip4 192 168 1 10
78cvw32 26 src
79cvw32 30 get Cvdst 0
80cvw16 24 cvcpl cvsum false 14 20
81cvw16 34 sp
82cvw16 36 dp
83cvw16 38 add n 8
84for i ulong n
85put Nrx add 42 i get Outb i
86end
87c = cvcpl add cvpseudo src get Cvdst 0 add n 8 cvsum false 34 add n 8
88if eq c 0
89c = 65535
90end
91cvw16 40 c
92if lt n 18
93n = 18
94end
95netinput add 42 n now
96end
97note A 20-byte TCP segment from 192.168.1.10:443 to Cvdst:Ncfg21 (session port).
98fn cvtcp now ulong to void
99for i ulong 2048
100put Nrx i uchar 0
101end
102for i ulong 6
103put Nrx i uchar 255
104put Nrx add i 6 uchar 0
105end
106put Nrx 6 uchar 2
107put Nrx 11 uchar 170
108cvw16 12 2048
109put Nrx 14 uchar 69
110cvw16 16 40
111cvw16 20 16384
112put Nrx 22 uchar 64
113put Nrx 23 uchar 6
114cvw32 26 cvip4 192 168 1 10
115cvw32 30 get Cvdst 0
116cvw16 24 cvcpl cvsum false 14 20
117cvw16 34 443
118cvw16 36 get Ncfg 21
119put Nrx 46 uchar 80
120netinput 54 now
121end
122note Outgoing courier frame: broadcast, IPv4/UDP 47033 both ways, valid checksums.
123fn cvtxok to bool
124if eq get Ntxlen 0 0
125ret false
126end
127for i ulong 6
128if ne get Ntx i 255
129ret false
130end
131end
132if or ne cvt16 12 2048 ne get Ntx 23 17
133ret false
134end
135if ne cvcpl cvsum true 14 20 0
136ret false
137end
138if or ne cvt16 34 47033 ne cvt16 36 47033
139ret false
140end
141n = sub cvt16 16 20
142if or ne n cvt16 38 gt add n 34 get Ntxlen 0
143ret false
144end
145if ne cvt32 30 4294967295
146ret false
147end
148s = cvpseudo cvt32 26 cvt32 30 n
149ret eq cvcpl add s cvsum true 34 n 0
150end
151fn cvkind c uchar to bool
152note The kind field starts at offset 22+16+6 of the head (ALLEN-COURIER v=1 run=<16> kind=).
153ret eq ulong get Ntx 86 ulong c
154end
155fn cvbody seq ulong to void
156outreset
157for i ulong len Cvsay
158emitb get Cvsay i
159end
160emitn seq
161for i ulong len Cvline
162emitb get Cvline i
163end
164put Inlen 0 get Outlen 0
165for i ulong get Outlen 0
166put In i get Outb i
167end
168end
169fn main to int
170put Cvdst 0 4294967295
171put Nmac 0 uchar 2
172for i ulong 4
173put Nmac add i 1 uchar 0
174end
175put Nmac 5 uchar 1
176netinit 5000
177netsent true 5000
178check eq get Ntxlen 0 0 7
179check not chbusy 1
180check chinit 5000 0 2
181check ne get Q 0 0 3
182check eq get Q 0 chrun 5000 4
183check not chinit 5000 0 5
184check eq get Ncfg 2 0 6
185chstep 5000 true
186check cvtxok 10
187check eq cvt32 26 0 11
188check cvkind 72 12
189check eq get Ch 2 1 13
190check not netudpsend 10 14
191w = write 2 Ntx 0 get Ntxlen 0
192netsent true 5000
193check eq get Ntxlen 0 0 15
194put Inlen 0 0
195ok = packet 6 0 0 0 0
196n = get Outlen 0
197cvdeliver 47033 47033 5001
198check ok 16
199check eq get Chrxn 0 n 17
200chstep 5001 true
201check eq get Chrxn 0 0 18
202check eq get T 1 1 19
203check eq get Ch 3 1 20
204check eq get Ntxlen 0 0 21
205put Dprmn 0 len Cvask
206for i ulong len Cvask
207put Dprm i get Cvask i
208end
209check chask 5002 30
210check chbusy 31
211check not chask 5003 32
212chstep 5003 true
213check cvtxok 33
214check cvkind 74 34
215netsent true 5003
216put Inlen 0 0
217ok = packet 4 get Q 1 0 0 0
218cvdeliver 47033 47033 5004
219check ok 35
220chstep 5004 true
221check eq get T 6 1 36
222check eq get Ntxlen 0 0 37
223note Negative control: a LINE whose bytes= is neither 0 nor the body length is refused.
224cvbody get Q 1
225ok = packet 2 get Q 1 1 0 add get Inlen 0 1
226cvdeliver 47033 47033 5005
227chstep 5005 true
228check and ok and eq get Chevent 0 0 eq get Ntxlen 0 0 39
229cvbody get Q 1
230ok = packet 2 get Q 1 1 0 get Inlen 0
231cvdeliver 47033 47033 5005
232n = get Chdrop 0
233cvdeliver 47033 47033 5005
234check ok 40
235check eq n 0 41
236check eq get Chdrop 0 1 42
237chstep 5005 true
238check eq get Chevent 0 1 43
239check eq get Chsayn 0 13 44
240check eq get Chsay 0 77 45
241check eq get Ch 5 1 46
242check cvtxok 47
243check cvkind 71 48
244check not chbusy 49
245netsent true 5005
246note Like the C kernel, ours by Ethernet destination and port alone: other ports
247note never reach the courier slot; any IPv4 destination does, so the relay's
248note --udp-answer 192.168.1.255 is heard without a lease.
249cvdeliver 47033 47034 5006
250check eq get Chrxn 0 0 50
251cvdeliver 1234 47033 5006
252check ne get Chrxn 0 0 51
253put Chrxn 0 0
254put Cvdst 0 cvip4 192 168 1 255
255cvdeliver 47033 47033 5007
256check ne get Chrxn 0 0 52
257put Chrxn 0 0
258put Ncfg 2 cvip4 192 168 1 20
259put Ncfg 3 cvip4 255 255 255 0
260put Cvdst 0 cvip4 192 168 1 20
261cvdeliver 47033 47033 5007
262check ne get Chrxn 0 0 53
263put Chrxn 0 0
264put Cvdst 0 cvip4 192 168 1 21
265cvdeliver 47033 47033 5007
266check ne get Chrxn 0 0 54
267put Chrxn 0 0
268put Chevent 0 1
269chcancel
270check eq get Chevent 0 0 55
271check not chbusy 56
272note With a lease the frame leaves from our address and the relay's subnet
273note broadcast answer (--udp-answer 192.168.1.255) is still heard.
274put Dprmn 0 len Cvask
275check chask 5008 60
276chstep 5008 true
277check cvtxok 61
278check eq cvt32 26 cvip4 192 168 1 20 62
279netsent true 5008
280put Cvdst 0 cvip4 192 168 1 255
281put Inlen 0 0
282ok = packet 4 get Q 1 0 0 0
283cvdeliver 47033 47033 5009
284chstep 5009 true
285check and ok eq get T 6 1 63
286note Error state 6 after a failed repository session: the courier still hears a
287note LINE and sends its GOT, while a TCP segment for the dead session is frozen
288note (Ndrop 12 is ntcpin's first verdict for a segment from the wrong peer).
289put Tcpstate 0 6
290cvbody get Q 1
291ok = packet 2 get Q 1 1 0 get Inlen 0
292cvdeliver 47033 47033 5010
293check and ok ne get Chrxn 0 0 64
294r = get Ch 4
295chstep 5010 true
296check eq get Chevent 0 1 65
297check and cvtxok cvkind 71 66
298check eq get Ch 4 r 67
299netsent true 5010
300put Cvdst 0 cvip4 192 168 1 20
301put Ncfg 1 4
302put Ncfg 21 40000
303put Tcpstate 2 cvip4 10 0 0 1
304put Tcpstate 0 5
305put Ndrop 0 0
306cvtcp 5011
307check eq get Ndrop 0 12 68
308put Ndrop 0 0
309put Tcpstate 0 6
310cvtcp 5011
311check eq get Ndrop 0 0 69
312ret int get Fails 0
313end