Skip to main content

rustflexstack/
lib.rs

1// SPDX-License-Identifier: AGPL-3.0-only
2// Copyright (C) 2024 Fundació Privada Internet i Innovació Digital a Catalunya (i2CAT)
3
4//! # rustflexstack
5//!
6//! ETSI C-ITS protocol stack implemented in Rust: GeoNetworking (TS 103 836-4-1),
7//! BTP (EN 302 636-5-1), security (TS 103 097, IEEE 1609.2) and the PKI client
8//! (TS 102 941), CA / DEN / VRU basic services, LDM and DCC.
9//!
10//! ## Architecture
11//!
12//! The stack is built around an actor model where each layer runs in its own
13//! background thread and communicates via [`std::sync::mpsc`] channels.  The
14//! caller interacts with the routers through lightweight handle types that wrap
15//! a [`std::sync::mpsc::Sender`].
16//!
17//! ## Typical usage
18//!
19//! An unsecured station on a raw Ethernet interface (ITS-G5 over `eth0`):
20//! GeoNetworking and BTP routers wired to the link layer. With security, pass
21//! a `SignService`, an `EcdsaBackend` and a `CertificateLibrary` to
22//! [`geonet::router::Router::spawn`]; the facilities (CA, DEN, VRU services)
23//! take the BTP handle. `examples/v2x_cli.rs` is a complete station.
24//!
25//! ```no_run
26//! use rustflexstack::btp::router::Router as BTPRouter;
27//! use rustflexstack::geonet::gn_address::{GNAddress, M, MID, ST};
28//! use rustflexstack::geonet::mib::{GnIfType, Mib};
29//! use rustflexstack::geonet::router::Router as GNRouter;
30//! use rustflexstack::link_layer::raw_link_layer::RawLinkLayer;
31//! use std::sync::mpsc;
32//! use std::thread;
33//!
34//! // Over ITS-G5 the GN address MID is the interface MAC address.
35//! let mac = [0x02, 0x00, 0x00, 0x00, 0x00, 0x01];
36//! let mut mib = Mib::new();
37//! mib.itsGnLocalGnAddr = GNAddress::new(M::GnMulticast, ST::PassengerCar, MID::new(mac));
38//! mib.itsGnIfType = GnIfType::ItsG5;
39//!
40//! // Routers (no sign / verify services: unsecured).
41//! let (gn_handle, gn_to_ll_rx, gn_to_btp_rx) = GNRouter::spawn(mib, None, None, None);
42//! let (btp_handle, btp_to_gn_rx) = BTPRouter::spawn(mib);
43//!
44//! // Raw Ethernet link layer (EtherType 0x8947).
45//! let (ll_to_gn_tx, ll_to_gn_rx) = mpsc::channel::<Vec<u8>>();
46//! let link_layer = RawLinkLayer::new(ll_to_gn_tx, gn_to_ll_rx, "eth0", mac);
47//! link_layer.start();
48//!
49//! // Link layer -> GN, GN -> BTP, BTP -> GN.
50//! let gn = gn_handle.clone();
51//! thread::spawn(move || {
52//!     while let Ok(packet) = ll_to_gn_rx.recv() {
53//!         gn.send_incoming_packet(packet);
54//!     }
55//! });
56//! let btp = btp_handle.clone();
57//! thread::spawn(move || {
58//!     while let Ok(indication) = gn_to_btp_rx.recv() {
59//!         btp.send_gn_data_indication(indication);
60//!     }
61//! });
62//! let gn = gn_handle.clone();
63//! thread::spawn(move || {
64//!     while let Ok(request) = btp_to_gn_rx.recv() {
65//!         gn.send_gn_data_request(request);
66//!     }
67//! });
68//! ```
69
70pub mod btp;
71pub mod facilities;
72pub mod geonet;
73pub mod link_layer;
74pub mod management;
75pub mod security;