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