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 / net.om

722 lines · 13511 bytes Raw Blame History
1note Packet stack behavior; concatenate after base.om, net.om, tests/check.om.
2note Frames are built here from RFC791/768/826/2131/1035/9293 layouts with an
3note independent checksum; outgoing frames are checked against the same rules.
4note Host-only protocol fixtures: no live network, firmware or peer qualification.
5global Vnow ulong 1
6global Vpeer uchar 6
7global Vip ulong 1
8global Vxid ulong 1
9global Vport ulong 1
10global Viss ulong 1
11global Vdport ulong 1
12global Vdid ulong 1
13text Vq "apigithubcom"
14text Vqmix "ApIgithubCOM"
15text Vget "GEThello"
16fn nvip4 a ulong b ulong c ulong d ulong to ulong
17ret add add shl a 24 shl b 16 add shl c 8 d
18end
19fn nvsrv to ulong
20ret nvip4 10 9 8 1
21end
22fn nvdns to ulong
23ret nvip4 10 9 8 53
24end
25fn nvgh to ulong
26ret nvip4 140 82 112 6
27end
28fn nvsseq to ulong
29ret 3000000000
30end
31fn nvw16 p ulong v ulong to void
32put Nrx p uchar and shr v 8 255
33put Nrx add p 1 uchar and v 255
34end
35fn nvw32 p ulong v ulong to void
36nvw16 p shr v 16
37nvw16 add p 2 and v 65535
38end
39fn nvt16 p ulong to ulong
40ret add shl ulong get Ntx p 8 ulong get Ntx add p 1
41end
42fn nvt32 p ulong to ulong
43ret add shl nvt16 p 16 nvt16 add p 2
44end
45note Independent one's-complement sum: byte pairs, odd tail as high octet.
46fn nvsum tx bool p ulong n ulong to ulong
47s = ulong 0
48for i ulong n
49v = ulong 0
50if tx
51v = ulong get Ntx add p i
52else
53v = ulong get Nrx add p i
54end
55if eq rem i 2 0
56s = add s shl v 8
57else
58s = add s v
59end
60end
61ret s
62end
63fn nvcpl s ulong to ulong
64while gt s 65535 bound 8
65s = add shr s 16 and s 65535
66end
67ret xor s 65535
68end
69fn nvpseudo a ulong b ulong pr ulong n ulong to ulong
70s = add add shr a 16 and a 65535 add shr b 16 and b 65535
71ret add s add pr n
72end
73fn nvsetmac p ulong last ulong to void
74for i ulong 5
75put Vpeer i uchar 0
76end
77put Vpeer 0 uchar 2
78put Vpeer 5 uchar last
79put Vpeer 4 uchar p
80end
81fn nvclr to void
82for i ulong 2048
83put Nrx i uchar 0
84end
85end
86fn nveth typ ulong to void
87for i ulong 6
88put Nrx i get Nmac i
89put Nrx add i 6 get Vpeer i
90end
91nvw16 12 typ
92end
93fn nvip src ulong dst ulong pr ulong l4 ulong to void
94nveth 2048
95put Nrx 14 uchar 69
96nvw16 16 add l4 20
97nvw16 20 16384
98put Nrx 22 uchar 64
99put Nrx 23 uchar pr
100nvw32 26 src
101nvw32 30 dst
102nvw16 24 0
103nvw16 24 nvcpl nvsum false 14 20
104end
105fn nvudp src ulong dst ulong sp ulong dp ulong n ulong to ulong
106nvw16 34 sp
107nvw16 36 dp
108nvw16 38 add n 8
109s = nvpseudo src dst 17 add n 8
110c = nvcpl add s nvsum false 34 add n 8
111if eq c 0
112c = 65535
113end
114nvw16 40 c
115nvip src dst 17 add n 8
116ret add 42 n
117end
118fn nvtcp src ulong seq ulong ack ulong fl ulong hl ulong dl ulong to ulong
119nvw16 34 443
120nvw16 36 get Vport 0
121nvw32 38 seq
122nvw32 42 ack
123put Nrx 46 uchar mul div hl 4 16
124put Nrx 47 uchar fl
125nvw16 48 65535
126nvw16 50 0
127s = nvpseudo src get Vip 0 6 add hl dl
128nvw16 50 nvcpl add s nvsum false 34 add hl dl
129nvip src get Vip 0 6 add hl dl
130ret add 34 add hl dl
131end
132fn nvin n ulong to void
133if lt n 60
134n = 60
135end
136netinput n get Vnow 0
137end
138note Each outgoing IPv4 frame: header checksum, UDP/TCP pseudo-header checksum.
139fn nvtxok to bool
140if ne nvt16 12 2048
141ret false
142end
143if ne nvcpl nvsum true 14 20 0
144ret false
145end
146n = sub nvt16 16 20
147if gt add n 34 get Ntxlen 0
148ret false
149end
150s = nvpseudo nvt32 26 nvt32 30 ulong get Ntx 23 n
151ret eq nvcpl add s nvsum true 34 n 0
152end
153fn nvnext to bool
154for i ulong 400
155netstep get Vnow 0
156if ne get Ntxlen 0 0
157ret true
158end
159put Vnow 0 add get Vnow 0 250
160end
161ret false
162end
163fn nvsent to void
164netsent true get Vnow 0
165end
166fn nvstart to bool
167put Vnow 0 5000
168put Nmac 0 uchar 2
169for i ulong 4
170put Nmac add i 1 uchar 0
171end
172put Nmac 5 uchar 1
173netinit get Vnow 0
174for i ulong 32
175put Nrand i uchar add i 1
176end
177put Vip 0 nvip4 10 9 8 20
178netconnect get Vnow 0
179for i ulong 32
180if ne get Nrand i 0
181ret false
182end
183end
184ret eq get Tcpstate 0 1
185end
186fn nvdisc to bool
187if not nvnext
188ret false
189end
190for i ulong 6
191if ne get Ntx i 255
192ret false
193end
194end
195if or ne nvt16 34 68 ne nvt16 36 67
196ret false
197end
198if or ne get Ntx 42 1 ne nvt32 278 1669485411
199ret false
200end
201put Vxid 0 nvt32 46
202if ne get Vxid 0 nvip4 1 2 3 4
203ret false
204end
205if or ne get Ntx 282 53 ne get Ntx 284 1
206ret false
207end
208ret nvtxok
209end
210fn nvopt p ulong code ulong v ulong to void
211put Nrx p uchar code
212put Nrx add p 1 uchar 4
213nvw32 add p 2 v
214end
215fn nvdhcp typ ulong xid ulong to ulong
216nvclr
217nvsetmac 0 170
218put Nrx 42 uchar 2
219put Nrx 43 uchar 1
220put Nrx 44 uchar 6
221nvw32 46 xid
222nvw32 58 get Vip 0
223for i ulong 6
224put Nrx add i 70 get Nmac i
225end
226nvw32 278 1669485411
227put Nrx 282 uchar 53
228put Nrx 283 uchar 1
229put Nrx 284 uchar typ
230nvopt 285 54 nvsrv
231nvopt 291 1 nvip4 255 255 255 0
232nvopt 297 3 nvsrv
233nvopt 303 6 nvdns
234nvopt 309 51 3600
235put Nrx 315 uchar 255
236ret nvudp nvsrv 4294967295 67 68 274
237end
238fn nvreq to bool
239if not nvnext
240ret false
241end
242if or ne get Ntx 284 3 ne get Ntx 285 50
243ret false
244end
245if or ne nvt32 287 get Vip 0 ne nvt32 293 nvsrv
246ret false
247end
248if ne nvt32 46 get Vxid 0
249ret false
250end
251ret nvtxok
252end
253fn nvarpq spa ulong tpa ulong to bool
254if not nvnext
255ret false
256end
257if or ne nvt16 12 2054 ne nvt16 20 1
258ret false
259end
260for i ulong 6
261if or ne get Ntx add i 6 get Nmac i ne get Ntx add i 22 get Nmac i
262ret false
263end
264end
265ret and eq nvt32 28 spa eq nvt32 38 tpa
266end
267fn nvarp op ulong spa ulong tpa ulong to ulong
268nvclr
269nveth 2054
270nvw16 14 1
271nvw16 16 2048
272put Nrx 18 uchar 6
273put Nrx 19 uchar 4
274nvw16 20 op
275for i ulong 6
276put Nrx add i 22 get Vpeer i
277put Nrx add i 32 get Nmac i
278end
279nvw32 28 spa
280nvw32 38 tpa
281ret 60
282end
283fn nvdnsq to bool
284if not nvnext
285ret false
286end
287for i ulong 6
288if ne get Ntx i get Vpeer i
289ret false
290end
291end
292if or ne nvt32 30 nvdns ne nvt16 36 53
293ret false
294end
295put Vdport 0 nvt16 34
296put Vdid 0 nvt16 42
297if ne get Vdport 0 add 49152 rem nvip4 9 10 11 12 16384
298ret false
299end
300if or ne get Vdid 0 and nvip4 5 6 7 8 65535 ne nvt16 44 256
301ret false
302end
303if or ne get Ntx 54 3 ne get Ntx 58 6
304ret false
305end
306if or ne get Ntx 65 3 ne get Ntx 69 0
307ret false
308end
309for i ulong 3
310if or ne get Ntx add i 55 get Vq i ne get Ntx add i 66 get Vq add i 9
311ret false
312end
313end
314for i ulong 6
315if ne get Ntx add i 59 get Vq add i 3
316ret false
317end
318end
319if or ne nvt16 70 1 ne nvt16 72 1
320ret false
321end
322ret nvtxok
323end
324fn nvboot to bool
325if not nvstart
326ret false
327end
328if not nvdisc
329ret false
330end
331nvsent
332nvin nvdhcp 2 add get Vxid 0 1
333netstep get Vnow 0
334if ne get Ntxlen 0 0
335ret false
336end
337n = nvdhcp 2 get Vxid 0
338put Nrx 100 uchar 1
339nvin n
340netstep get Vnow 0
341if ne get Ntxlen 0 0
342ret false
343end
344nvin nvdhcp 2 get Vxid 0
345if not nvreq
346ret false
347end
348nvsent
349nvin nvdhcp 5 get Vxid 0
350for k ulong 3
351if not nvarpq 0 get Vip 0
352ret false
353end
354nvsent
355end
356for k ulong 2
357if not nvarpq get Vip 0 get Vip 0
358ret false
359end
360nvsent
361end
362if not nvarpq get Vip 0 nvdns
363ret false
364end
365nvsent
366if ne get Tcpstate 0 2
367ret false
368end
369nvsetmac 0 187
370nvin nvarp 2 nvdns get Vip 0
371if not nvdnsq
372ret false
373end
374nvsent
375ret true
376end
377note DNS question in mixed case; CNAME via compression to the question, A via
378note compression to the CNAME rdata. mode 1 forward pointer, 2 TC, 3 wrong id.
379fn nvqname p ulong to void
380put Nrx p uchar 3
381put Nrx add p 4 uchar 6
382put Nrx add p 11 uchar 3
383for i ulong 3
384put Nrx add add p 1 i get Vqmix i
385put Nrx add add p 12 i get Vqmix add i 9
386end
387for i ulong 6
388put Nrx add add p 5 i get Vqmix add i 3
389end
390end
391fn nvrr p ulong name ulong typ ulong n ulong to void
392nvw16 p name
393nvw16 add p 2 typ
394nvw16 add p 4 1
395nvw32 add p 6 60
396nvw16 add p 10 n
397end
398fn nvdnsr mode ulong to ulong
399nvclr
400nvsetmac 0 187
401id = get Vdid 0
402if eq mode 3
403id = xor id 1
404end
405nvw16 42 id
406if eq mode 2
407nvw16 44 33664
408else
409nvw16 44 33152
410end
411nvw16 46 1
412nvw16 48 2
413nvqname 54
414nvw16 70 1
415nvw16 72 1
416nvrr 74 49164 5 7
417put Nrx 86 uchar 4
418put Nrx 87 uchar 101
419put Nrx 88 uchar 100
420put Nrx 89 uchar 103
421put Nrx 90 uchar 101
422nvw16 91 49168
423if eq mode 1
424nvrr 93 49232 1 4
425else
426nvrr 93 49196 1 4
427end
428nvw32 105 nvgh
429src = nvdns
430if eq mode 6
431src = add src 1
432end
433dp = get Vdport 0
434if eq mode 4
435dp = add dp 1
436end
437n = nvudp src get Vip 0 53 dp 67
438if eq mode 5
439put Nrx 108 xor get Nrx 108 1
440end
441ret n
442end
443fn nvsyn to bool
444if not nvnext
445ret false
446end
447for i ulong 6
448if ne get Ntx i get Vpeer i
449ret false
450end
451end
452if or ne nvt32 30 nvgh ne get Ntx 23 6
453ret false
454end
455if or ne get Ntx 47 2 ne get Ntx 46 96
456ret false
457end
458if or ne nvt16 54 516 ne nvt16 56 1460
459ret false
460end
461put Viss 0 nvt32 38
462put Vport 0 nvt16 34
463if ne get Viss 0 nvip4 13 14 15 16
464ret false
465end
466if ne get Vport 0 add 49152 rem nvip4 17 18 19 20 16384
467ret false
468end
469if ne nvt16 36 443
470ret false
471end
472ret nvtxok
473end
474fn nvsynack bad ulong to ulong
475nvclr
476nvsetmac 0 170
477put Nrx 54 uchar 2
478put Nrx 55 uchar 4
479nvw16 56 1400
480src = nvgh
481ack = nadd get Viss 0 1
482if eq bad 2
483ack = nadd ack 1
484end
485if eq bad 3
486src = add src 1
487end
488n = nvtcp src nvsseq ack 18 24 0
489if eq bad 1
490put Nrx 51 xor get Nrx 51 1
491end
492ret n
493end
494fn nvisack seq ulong ack ulong fl ulong dl ulong to bool
495if not nvtxok
496ret false
497end
498if or ne nvt32 38 seq ne nvt32 42 ack
499ret false
500end
501if or ne get Ntx 47 uchar fl ne nvt16 16 add 40 dl
502ret false
503end
504ret and eq nvt16 34 get Vport 0 eq nvt16 36 443
505end
506fn nvopen hard bool to bool
507if not nvboot
508ret false
509end
510if hard
511for m ulong 4
512nvin nvdnsr add m 3
513end
514if ne get Tcpstate 0 2
515ret false
516end
517end
518nvin nvdnsr 0
519if or ne get Tcpstate 0 3 ne get Tcpstate 2 nvgh
520ret false
521end
522if not nvarpq get Vip 0 nvsrv
523ret false
524end
525nvsent
526nvsetmac 0 170
527nvin nvarp 2 nvsrv get Vip 0
528if not nvsyn
529ret false
530end
531nvsent
532if hard
533for b ulong 3
534nvin nvsynack add b 1
535if ne get Tcpstate 0 3
536ret false
537end
538end
539end
540nvin nvsynack 0
541if ne get Tcpstate 0 4
542ret false
543end
544if not nvnext
545ret false
546end
547if not nvisack nadd get Viss 0 1 nadd nvsseq 1 16 0
548ret false
549end
550nvsent
551ret true
552end
553fn nvinj off ulong n ulong fl ulong src ulong ack ulong to ulong
554note Inject a TCP segment at a stream offset with a repeated payload byte; no golden bytes needed.
555nvclr
556nvsetmac 0 170
557for i ulong n
558put Nrx add 54 i uchar and i 255
559end
560ret nvtcp src nadd nvsseq add 1 off ack fl 20 n
561end
562fn nvdata off ulong n ulong fl ulong src ulong ack ulong dat ulong to ulong
563nvclr
564nvsetmac 0 170
565for i ulong n
566put Nrx add 54 i get Vget add dat i
567end
568ret nvtcp src nadd nvsseq add 1 off ack fl 20 n
569end
570fn nvwire to void
571note RFC1071/791 header example with known checksum b861.
572for i ulong 20
573put Ntx i uchar 0
574end
575put Ntx 0 uchar 69
576put Ntx 3 uchar 115
577put Ntx 6 uchar 64
578put Ntx 8 uchar 64
579put Ntx 9 uchar 17
580put Ntx 12 uchar 192
581put Ntx 13 uchar 168
582put Ntx 15 uchar 1
583put Ntx 16 uchar 192
584put Ntx 17 uchar 168
585put Ntx 19 uchar 199
586check eq nfold ntsum 0 20 47201 1
587check eq nvcpl nvsum true 0 20 47201 2
588put Nrx 0 uchar 1
589put Nrx 1 uchar 2
590put Nrx 2 uchar 3
591check eq nrsum 0 3 1026 3
592check nlt 4294967295 0 4
593check not nlt 0 4294967295 5
594check eq nadd 4294967295 2 1 6
595check eq ndiff 1 4294967295 2 7
596end
597fn nvfail code ulong id ulong to void
598check eq get Tcpstate 0 6 id
599check eq get Tcpstate 1 code add id 1
600check eq get Ntxlen 0 0 add id 2
601end
602fn main to int
603nvwire
604check nvopen true 10
605put Tcpout 0 uchar 71
606put Tcpout 1 uchar 69
607put Tcpout 2 uchar 84
608check netwrite 3 get Vnow 0 11
609check not netwrite 1 get Vnow 0 12
610check nvnext 13
611a = nadd nvsseq 1
612check nvisack nadd get Viss 0 1 a 24 3 14
613check eq get Ntx 54 71 15
614netstep get Vnow 0
615check eq get Ntx 54 71 16
616netsent false get Vnow 0
617check ne get Ntxlen 0 0 17
618nvsent
619check nvnext 18
620check nvisack nadd get Viss 0 1 a 24 3 19
621nvsent
622s = nadd get Viss 0 4
623nvin nvdata 3 2 24 nvgh s 6
624check eq get Tcpn 0 0 20
625nvin nvdata 0 3 24 nvgh s 3
626check eq get Tcpn 0 5 21
627for i ulong 5
628check eq get Tcpin i get Vget add i 3 add 22 i
629end
630check netwrite 1 get Vnow 0 27
631nvin nvdata 0 3 24 nvgh s 3
632check eq get Tcpn 0 5 28
633nvin nvdata 5 1 24 add nvgh 1 s 3
634check eq get Tcpn 0 5 29
635nvin nvdata 5 0 17 nvgh s 3
636check eq get Tcpstate 0 5 30
637check eq get Tcpn 0 5 31
638netconsume 5
639check eq get Tcpn 0 0 32
640netconsume 1
641nvfail 17 33
642check nvopen false 40
643nvin nvtcp nvgh nadd nvsseq 101 nadd get Viss 0 1 4 20 0
644check eq get Tcpstate 0 4 41
645check nvnext 42
646nvin nvtcp nvgh nadd nvsseq 1 nadd get Viss 0 1 4 20 0
647nvfail 12 43
648check nvopen false 50
649s = nadd get Viss 0 1
650nvin nvdata 10 2 24 nvgh s 3
651check eq get Tcpn 0 0 51
652nvin nvdata 10 2 24 nvgh s 5
653nvfail 13 52
654check nvopen false 60
655check not netwrite 65537 get Vnow 0 61
656nvfail 17 62
657check nvboot 70
658nvin nvdnsr 1
659nvfail 10 71
660check nvboot 80
661nvin nvdnsr 2
662nvfail 9 81
663check nvstart 90
664netstep 1
665nvfail 1 91
666put Vnow 0 5000
667netinit get Vnow 0
668netconnect get Vnow 0
669nvfail 2 92
670check nvstart 100
671check nvdisc 101
672nvsent
673nvin nvdhcp 2 get Vxid 0
674check nvreq 102
675nvsent
676nvin nvdhcp 5 get Vxid 0
677check nvarpq 0 get Vip 0 103
678nvsent
679nvsetmac 0 204
680nvin nvarp 1 get Vip 0 nvsrv
681check nvnext 104
682check eq get Ntx 284 4 105
683nvsent
684nvfail 6 106
685note aienux#454: three in-order 1440-byte segments after the app consumed the previous record.
686check nvopen false 200
687ok = netwrite 3 get Vnow 0
688ok = nvnext
689nvsent
690a = nadd nvsseq 4
691b = nadd nvsseq 1
692put Ndrop 0 0
693nvin nvinj 0 1440 24 nvgh a
694nvin nvinj 1440 1440 24 nvgh a
695nvin nvinj 2880 1440 24 nvgh a
696check eq get Tcpn 0 4320 201
697check eq ndiff get Nct 2 b 4320 202
698check eq get Ndrop 0 0 203
699netconsume 4320
700note aienux#454: a long transfer must not die on the mode-3 idle cap while frames keep arriving.
701put Ncfg 1 3
702put Ncfg 9 5000
703t = get Vnow 0
704put Vnow 0 add t 4000
705nvin nvinj 4320 0 16 nvgh a
706put Vnow 0 add t 6000
707netstep get Vnow 0
708check ne get Tcpstate 0 6 204
709put Ncfg 1 2
710note aienux#454: an in-order peer FIN completes the stream instead of being ignored.
711check nvopen false 205
712ok = netwrite 3 get Vnow 0
713ok = nvnext
714nvsent
715c = nadd nvsseq 4
716nvin nvinj 0 3 24 nvgh c
717netconsume 3
718nvin nvinj 3 0 17 nvgh c
719check eq get Tcpstate 0 5 206
720check eq get Tcpn 0 0 207
721ret int get Fails 0
722end