Bundle Protocol Version 7 (RFC 9171) for Delay-Tolerant Networking
OCaml 95.3%
Dune 1.3%
Other 3.4%
29 1 0

Clone this repository

https://tangled.org/gazagnaire.org/ocaml-bundle https://tangled.org/did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-bundle
git@git.recoil.org:gazagnaire.org/ocaml-bundle git@git.recoil.org:did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-bundle

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

bundle#

Pure OCaml implementation of the IETF Bundle Protocol Version 7 (RFC 9171) for Delay-Tolerant Networking (DTN).

Overview#

Bundle Protocol is a store-and-forward messaging protocol designed for networks with intermittent connectivity, long delays, and high error rates. It's the foundational protocol for Delay-Tolerant Networking (DTN), used in:

  • Deep space communications (NASA missions)
  • Disaster recovery networks
  • Remote sensor networks
  • Challenged terrestrial networks

A "bundle" is a self-contained message that can be stored at intermediate nodes and forwarded when connectivity becomes available.

Features#

  • Full RFC 9171 Bundle Protocol v7 implementation
  • CBOR encoding/decoding using the cbort library
  • Support for all standard block types:
    • Payload block
    • Previous node block
    • Bundle age block
    • Hop count block
    • Extension blocks
  • CRC-16 X.25 and CRC-32C integrity checking
  • Endpoint ID support (dtn: and ipn: schemes)
  • Streaming I/O with bytesrw

Installation#

opam install bundle

Usage#

(* Create a bundle *)
let bundle =
  Bundle.v
    ~source:(Bundle.Ipn (1L, 1L))
    ~destination:(Bundle.Ipn (2L, 1L))
    ~creation_timestamp:{ Bundle.time = 0L; seq = 0L }
    ~payload:"Hello, DTN!"
    ()

(* Encode to bytes *)
let encoded = Bundle.encode bundle

(* Decode from bytes *)
match Bundle.decode encoded with
| Ok decoded -> Printf.printf "Payload: %s\n" (Option.get (Bundle.payload decoded))
| Error e -> Printf.printf "Error: %a\n" Bundle.pp_error e

API#

Types#

  • Bundle.t - A complete bundle
  • Bundle.eid - Endpoint identifier (dtn:none, dtn:URI, ipn:node.service)
  • Bundle.primary_block - Bundle primary block
  • Bundle.canonical_block - Extension/payload blocks
  • Bundle.timestamp - Creation timestamp

Functions#

  • Bundle.v - Create a bundle
  • Bundle.encode / Bundle.decode - Serialize/deserialize
  • Bundle.payload - Extract payload data
  • Bundle.previous_node / Bundle.bundle_age / Bundle.hop_count - Extract extension block data
  • ION - NASA/JPL's production DTN implementation in C
  • µD3TN - Lightweight C implementation for embedded systems
  • DTN7 - Go/Rust implementations of BPv7

This implementation focuses on:

  • Pure OCaml with minimal C dependencies
  • Integration with the OCaml ecosystem (cbort, bytesrw)
  • Type-safe API with comprehensive error handling

References#

Licence#

ISC License. See LICENSE.md for details.