- OCaml 100%
udpcl #
A delay-tolerant network moves bundles (RFC 9171) between nodes over whatever
link is available, and a convergence layer maps bundles onto one transport.
Over UDP the mapping is simple, because a datagram is already a message, and
RFC 7122 defines it: each datagram carries exactly one bundle, or four zero
octets as a keep-alive. udpcl implements that convergence layer in OCaml,
with an Eio transport in udpcl-eio.
A bundle that fits the MTU is the datagram itself, with no header. A longer
bundle travels as a Transfer, the convergence-layer segmentation of
draft-sipos-dtn-udpcl-02 (Sections 2.5 and 3.5.2): each datagram carries one
CBOR Extension Map {2: [transfer-id, total-length, segment-offset, segment-data]}, and the receiver reassembles the segments one source sent
under one Transfer ID, discarding overlapping or inconsistent segments and
any reassembly idle for longer than the transfer timeout (Section 3.6.2). A
receiver tells the messages of a datagram apart by their first octet
(Section 3.4): a CBOR array is a BPv7 bundle, a CBOR map an Extension Map,
and a zero octet starts the padding.
The package speaks BPv7 only. It implements no DTLS (draft Section 3.8) and no extension item other than Transfer; a BPv6 bundle or a DTLS record is reported and dropped, and the other extension items are ignored, as the draft requires of an unknown one.
Installation #
Install with opam:
$ opam install udpcl
If opam cannot find the package, it may not yet be released in the public
opam-repository. Add the overlay repository, then install it:
$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install udpcl
Usage #
let bundle =
Bundle.encode
(Bundle.v ~source:(Bundle.Ipn (1L, 1L)) ~destination:(Bundle.Ipn (2L, 1L))
~creation_timestamp:{ Bundle.time = 0L; seq = 0L }
~payload:(String.make 3000 'x') ())
(* Over a 1400-octet MTU the bundle is a Transfer of several segments. *)
let _, packets = Udpcl.Sender.outgoing (Udpcl.Sender.v ()) bundle
let received =
let now = Mtime.of_uint64_ns 0L in
List.fold_left
(fun (r, got) p ->
let r, events = Udpcl.Receiver.incoming r ~now ~src:"peer" p in
(r, got @ events))
(Udpcl.Receiver.v (), []) packets
|> snd
let () = assert (received = [ Udpcl.Receiver.Bundle bundle ])
References #
- RFC 7122: Datagram Convergence Layers for the DTN Bundle Protocol and LTP, Section 3.2
- draft-sipos-dtn-udpcl-02: DTN Bundle Protocol UDP Convergence Layer, Sections 2.5 and 3
- RFC 9171: Bundle Protocol Version 7
Licence #
ISC License. See LICENSE.md for details.