DTN controller and policy language for satellite networks
at main 62 lines 1.9 kB view raw
1(*--------------------------------------------------------------------------- 2 Copyright (c) 2025 Thomas Gazagnaire. All rights reserved. 3 SPDX-License-Identifier: ISC 4 ---------------------------------------------------------------------------*) 5 6open Crowbar 7 8let gen_eid = 9 choose 10 [ 11 const Bundle.Dtn_none; 12 map [ bytes ] (fun s -> Bundle.Dtn s); 13 map [ int64; int64 ] (fun n s -> Bundle.Ipn (n, s)); 14 ] 15 16let gen_status = 17 map 18 [ 19 gen_eid; float; range 1000; range 1000; range 1000; range 1000; range 100; 20 ] 21 (fun node_id uptime_secs stored fwd del drop contacts -> 22 Admin.Status_report 23 { 24 node_id; 25 uptime_secs; 26 bundles_stored = stored; 27 bundles_forwarded = fwd; 28 bundles_delivered = del; 29 bundles_dropped = drop; 30 active_contacts = contacts; 31 }) 32 33let gen_query = 34 choose 35 [ 36 const (Admin.Query Admin.Query_status); 37 const (Admin.Query Admin.Query_contacts); 38 const (Admin.Query Admin.Query_policy); 39 map 40 [ option bytes ] 41 (fun filter -> Admin.Query (Admin.Query_bundles { filter })); 42 ] 43 44let gen_contact = 45 map [ bytes; bytes; float; float; float; float ] 46 (fun from_node to_node start_time stop_time rate_bps owlt_secs -> 47 { Admin.from_node; to_node; start_time; stop_time; rate_bps; owlt_secs }) 48 49let gen_contact_plan = 50 map [ list gen_contact ] (fun contacts -> Admin.Contact_update { contacts }) 51 52let gen_record = choose [ gen_status; gen_query; gen_contact_plan ] 53 54let test_roundtrip record = 55 let encoded = Admin.encode record in 56 match Admin.decode encoded with 57 | Error _ -> () 58 | Ok decoded -> 59 let re_encoded = Admin.encode decoded in 60 check_eq ~pp:Fmt.string encoded re_encoded 61 62let () = add_test ~name:"admin roundtrip" [ gen_record ] test_roundtrip