Licklider Transmission Protocol (CCSDS 734.1-B) for reliable DTN links
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ltp: ION interop — SDNV encoding verified against NASA JPL ION 4.1.4

15 SDNV vectors including RFC 6256 test cases, generated by ION's
encodeSdnv (C). Byte-identical output for all values 0 through 2^63-1.

+131 -1
+17
test/interop/ion/dune
··· 1 + (test 2 + (name test) 3 + (libraries ltp csvt alcotest) 4 + (deps 5 + (source_tree traces) 6 + (source_tree scripts))) 7 + 8 + ; Regenerate traces against ION: dune build @regen-traces 9 + 10 + (rule 11 + (alias regen-traces) 12 + (deps 13 + (source_tree scripts)) 14 + (action 15 + (chdir 16 + scripts 17 + (run bash ./generate.sh))))
test/interop/ion/scripts/generate

This is a binary file and will not be displayed.

+8 -1
test/interop/ion/scripts/generate.c
··· 3 3 Build & run via generate.sh (or: dune build @regen-traces). 4 4 Output: one CSV per test group into ../traces/. 5 5 6 - ION's encodeSdnv is pure computation -- no ION runtime needed. */ 6 + ION's encodeSdnv is pure computation -- no ION runtime needed. 7 + 8 + On newer macOS SDKs sys/param.h defines __DARWIN_MAXPATHLEN but not 9 + MAXPATHLEN, which ION's platform.h requires. Define it here. */ 7 10 11 + #include <sys/param.h> 12 + #ifndef MAXPATHLEN 13 + #define MAXPATHLEN 1024 14 + #endif 8 15 #include "platform.h" 9 16 #include <stdio.h> 10 17 #include <stdlib.h>
+90
test/interop/ion/test.ml
··· 1 + (** ION (NASA JPL) interop tests for LTP SDNV encoding. 2 + 3 + Tests [Ltp.encode_sdnv] and [Ltp.decode_sdnv] against NASA JPL ION's 4 + [encodeSdnv], an independent implementation of Self-Delimiting Numeric 5 + Values (RFC 5326 Section 3.1, RFC 6256). 6 + 7 + Traces generated by: ION 4.x via generate.c 8 + Regenerate: REGEN_TRACES=1 dune build @regen-traces *) 9 + 10 + let trace path = Filename.concat "traces" path 11 + 12 + let hex_of_string s = 13 + let buf = Buffer.create (String.length s * 2) in 14 + String.iter 15 + (fun c -> Buffer.add_string buf (Printf.sprintf "%02x" (Char.code c))) 16 + s; 17 + Buffer.contents buf 18 + 19 + let string_of_hex hex = 20 + let len = String.length hex / 2 in 21 + String.init len (fun i -> 22 + Char.chr (int_of_string ("0x" ^ String.sub hex (i * 2) 2))) 23 + 24 + (* --- CSV row type and codec --- *) 25 + 26 + type vector = { name : string; value : int64; encoded_hex : string } 27 + 28 + let vector_codec = 29 + Csvt.( 30 + Row.( 31 + obj (fun name value encoded_hex -> { name; value; encoded_hex }) 32 + |> col "name" string ~enc:(fun v -> v.name) 33 + |> col "value" int64 ~enc:(fun v -> v.value) 34 + |> col "encoded_hex" string ~enc:(fun v -> v.encoded_hex) 35 + |> finish)) 36 + 37 + let parse_vectors () = 38 + match Csvt.decode_file vector_codec (trace "sdnv.csv") with 39 + | Ok vs -> vs 40 + | Error e -> Alcotest.failf "failed to parse sdnv.csv: %a" Csvt.pp_error e 41 + 42 + (* --- Test: encode matches ION --- *) 43 + 44 + let test_encode vec () = 45 + let got_hex = hex_of_string (Ltp.encode_sdnv vec.value) in 46 + if got_hex <> vec.encoded_hex then 47 + Alcotest.failf "%s: encode mismatch\n expected: %s\n got: %s" 48 + vec.name vec.encoded_hex got_hex 49 + 50 + (* --- Test: decode ION bytes recovers value --- *) 51 + 52 + let test_decode vec () = 53 + let bytes = string_of_hex vec.encoded_hex in 54 + match Ltp.decode_sdnv bytes 0 with 55 + | Error e -> Alcotest.failf "%s: decode failed: %s" vec.name e 56 + | Ok (v, off) -> 57 + Alcotest.(check int64) (vec.name ^ ": value") vec.value v; 58 + Alcotest.(check int) 59 + (vec.name ^ ": consumed all bytes") 60 + (String.length bytes) off 61 + 62 + (* --- Test: roundtrip encode -> decode --- *) 63 + 64 + let test_roundtrip vec () = 65 + let encoded = Ltp.encode_sdnv vec.value in 66 + match Ltp.decode_sdnv encoded 0 with 67 + | Error e -> Alcotest.failf "%s: roundtrip decode failed: %s" vec.name e 68 + | Ok (v, off) -> 69 + Alcotest.(check int64) (vec.name ^ ": value") vec.value v; 70 + Alcotest.(check int) 71 + (vec.name ^ ": consumed all bytes") 72 + (String.length encoded) off 73 + 74 + let () = 75 + let vectors = parse_vectors () in 76 + Alcotest.run "ltp-interop-ion" 77 + [ 78 + ( "encode", 79 + List.map 80 + (fun v -> Alcotest.test_case v.name `Quick (test_encode v)) 81 + vectors ); 82 + ( "decode", 83 + List.map 84 + (fun v -> Alcotest.test_case v.name `Quick (test_decode v)) 85 + vectors ); 86 + ( "roundtrip", 87 + List.map 88 + (fun v -> Alcotest.test_case v.name `Quick (test_roundtrip v)) 89 + vectors ); 90 + ]
+16
test/interop/ion/traces/sdnv.csv
··· 1 + name,value,encoded_hex 2 + zero,0,00 3 + one,1,01 4 + v_127,127,7f 5 + v_128,128,8100 6 + v_255,255,817f 7 + v_256,256,8200 8 + v_16383,16383,ff7f 9 + v_16384,16384,818000 10 + rfc_0x7f,127,7f 11 + rfc_0xabc,2748,953c 12 + rfc_0x1234,4660,a434 13 + rfc_0x4234,16948,818434 14 + v_0xffff,65535,83ff7f 15 + v_0xffffffff,4294967295,8fffffff7f 16 + v_0x7fffffffffffffff,9223372036854775807,ffffffffffffffff7f