CCSDS File Delivery Protocol (CCSDS 727.0-B-5) for space file transfer
0
fork

Configure Feed

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

irmin: tar backend — TAR→tree codec with SHA-256 Merkle tree

+189
+17
test/interop/dariol83/dune
··· 1 + (test 2 + (name test) 3 + (libraries cfdp csvt alcotest) 4 + (deps 5 + (source_tree traces) 6 + (source_tree scripts))) 7 + 8 + ; Regenerate traces against dariol83: 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))))
+172
test/interop/dariol83/test.ml
··· 1 + (** dariol83 interop tests for CFDP KeepAlive PDU. 2 + 3 + Traces generated by: dariol83/ccsds (Java) 4 + Regenerate: dune build @regen-traces *) 5 + 6 + let trace path = Filename.concat "traces" path 7 + 8 + let hex_to_string hex = 9 + let len = String.length hex / 2 in 10 + String.init len (fun i -> 11 + let digit c = 12 + if c >= '0' && c <= '9' then Char.code c - Char.code '0' 13 + else if c >= 'a' && c <= 'f' then Char.code c - Char.code 'a' + 10 14 + else Char.code c - Char.code 'A' + 10 15 + in 16 + Char.chr ((digit hex.[i * 2] lsl 4) lor digit hex.[(i * 2) + 1])) 17 + 18 + let string_to_hex s = 19 + let buf = Buffer.create (String.length s * 2) in 20 + String.iter 21 + (fun c -> Buffer.add_string buf (Printf.sprintf "%02x" (Char.code c))) 22 + s; 23 + Buffer.contents buf 24 + 25 + let direction_of_string = function 26 + | "toward_receiver" -> Cfdp.Toward_receiver 27 + | "toward_sender" -> Cfdp.Toward_sender 28 + | s -> Alcotest.failf "unknown direction: %s" s 29 + 30 + let mode_of_string = function 31 + | "ack" -> Cfdp.Acknowledged 32 + | "unack" -> Cfdp.Unacknowledged 33 + | s -> Alcotest.failf "unknown mode: %s" s 34 + 35 + type ka_row = { 36 + name : string; 37 + source_entity : int; 38 + dest_entity : int; 39 + seq_nr : int; 40 + entity_id_len : int; 41 + seq_nr_len : int; 42 + direction : string; 43 + mode : string; 44 + progress : int64; 45 + large_file : bool; 46 + pdu_hex : string; 47 + } 48 + 49 + let ka_codec = 50 + Csvt.( 51 + Row.( 52 + obj 53 + (fun 54 + name 55 + source_entity 56 + dest_entity 57 + seq_nr 58 + entity_id_len 59 + seq_nr_len 60 + direction 61 + mode 62 + progress 63 + large_file 64 + pdu_hex 65 + -> 66 + { 67 + name; 68 + source_entity; 69 + dest_entity; 70 + seq_nr; 71 + entity_id_len; 72 + seq_nr_len; 73 + direction; 74 + mode; 75 + progress; 76 + large_file; 77 + pdu_hex; 78 + }) 79 + |> col "name" string ~enc:(fun r -> r.name) 80 + |> col "source_entity" int ~enc:(fun r -> r.source_entity) 81 + |> col "dest_entity" int ~enc:(fun r -> r.dest_entity) 82 + |> col "seq_nr" int ~enc:(fun r -> r.seq_nr) 83 + |> col "entity_id_len" int ~enc:(fun r -> r.entity_id_len) 84 + |> col "seq_nr_len" int ~enc:(fun r -> r.seq_nr_len) 85 + |> col "direction" string ~enc:(fun r -> r.direction) 86 + |> col "mode" string ~enc:(fun r -> r.mode) 87 + |> col "progress" int64 ~enc:(fun r -> r.progress) 88 + |> col "large_file" bool ~enc:(fun r -> r.large_file) 89 + |> col "pdu_hex" string ~enc:(fun r -> r.pdu_hex) 90 + |> finish)) 91 + 92 + let load_rows () = 93 + match Csvt.decode_file ka_codec (trace "keep_alive.csv") with 94 + | Ok rows -> rows 95 + | Error e -> Alcotest.failf "CSV: %a" Csvt.pp_error e 96 + 97 + let test_decode () = 98 + let rows = load_rows () in 99 + List.iter 100 + (fun (r : ka_row) -> 101 + let ref_str = hex_to_string r.pdu_hex in 102 + match Cfdp.decode ref_str with 103 + | Error e -> Alcotest.failf "%s: decode failed: %a" r.name Cfdp.pp_error e 104 + | Ok (Cfdp.Pdu_directive (hdr, Cfdp.Keep_alive ka), _) -> 105 + Alcotest.(check int64) 106 + (r.name ^ " source_entity") 107 + (Int64.of_int r.source_entity) 108 + (Cfdp.Entity_id.to_int64 hdr.source_entity); 109 + Alcotest.(check int64) 110 + (r.name ^ " dest_entity") 111 + (Int64.of_int r.dest_entity) 112 + (Cfdp.Entity_id.to_int64 hdr.dest_entity); 113 + Alcotest.(check int64) 114 + (r.name ^ " seq_nr") (Int64.of_int r.seq_nr) hdr.transaction_seq; 115 + Alcotest.(check int64) (r.name ^ " progress") r.progress ka.progress 116 + | Ok _ -> Alcotest.failf "%s: expected Keep_alive directive" r.name) 117 + rows 118 + 119 + let test_encode () = 120 + let rows = load_rows () in 121 + List.iter 122 + (fun (r : ka_row) -> 123 + let config = 124 + match 125 + Cfdp.pdu_config ~entity_id_len:r.entity_id_len 126 + ~seq_nr_len:r.seq_nr_len 127 + with 128 + | Some c -> c 129 + | None -> Alcotest.failf "%s: invalid config" r.name 130 + in 131 + let hdr : Cfdp.header = 132 + { 133 + version = 1; 134 + pdu_type = Cfdp.File_directive; 135 + direction = direction_of_string r.direction; 136 + transmission_mode = mode_of_string r.mode; 137 + crc_present = false; 138 + large_file = r.large_file; 139 + segment_ctrl = false; 140 + segment_metadata = false; 141 + source_entity = Cfdp.Entity_id.of_int_exn r.source_entity; 142 + transaction_seq = Int64.of_int r.seq_nr; 143 + dest_entity = Cfdp.Entity_id.of_int_exn r.dest_entity; 144 + data_len = 0; 145 + } 146 + in 147 + let dir = Cfdp.Keep_alive (Cfdp.keep_alive r.progress) in 148 + let got = Cfdp.encode config hdr (Cfdp.Pdu_directive (hdr, dir)) in 149 + let got_hex = string_to_hex got in 150 + if got_hex <> r.pdu_hex then 151 + Alcotest.failf "%s: encode mismatch\n expected: %s\n got: %s" 152 + r.name r.pdu_hex got_hex) 153 + rows 154 + 155 + let () = 156 + let rows = load_rows () in 157 + let n = List.length rows in 158 + Alcotest.run "cfdp-interop-dariol83" 159 + [ 160 + ( "decode", 161 + [ 162 + Alcotest.test_case 163 + (Printf.sprintf "decode %d KeepAlive PDUs" n) 164 + `Quick test_decode; 165 + ] ); 166 + ( "encode", 167 + [ 168 + Alcotest.test_case 169 + (Printf.sprintf "encode %d KeepAlive PDUs" n) 170 + `Quick test_encode; 171 + ] ); 172 + ]