Rust Basic Transport Protocol (BTP)
The rustflexstack::btp module implements ETSI EN 302 636-5-1 V2.2.1 (Basic Transport Protocol). It routes payloads between the GeoNetworking router and the Facilities services by port number.
Supported Variants
BTP-A (
CommonNH::BtpA): destination and source port, for interactive services.BTP-B (
CommonNH::BtpB): destination port and destination port info, used by CAM (port 2001), DENM (port 2002) and VAM (port 2018).
Spawning the BTP Router
BTPRouter::spawn(mib) starts the router thread and returns its handle and the receiver of the GeoNetworking requests it produces, which the application forwards to the GeoNetworking router:
use std::sync::mpsc;
use std::thread;
use rustflexstack::btp::router::Router as BTPRouter;
use rustflexstack::btp::service_access_point::{BTPDataIndication, BTPDataRequest};
use rustflexstack::geonet::mib::Mib;
use rustflexstack::geonet::router::Router as GNRouter;
use rustflexstack::geonet::service_access_point::CommonNH;
let mib = Mib::new();
let (gn_handle, _gn_to_ll_rx, gn_to_btp_rx) = GNRouter::spawn(mib, None, None, None);
let (btp_handle, btp_to_gn_rx) = BTPRouter::spawn(mib);
// BTP -> GeoNetworking requests, GeoNetworking -> BTP indications
let gn = gn_handle.clone();
thread::spawn(move || {
while let Ok(request) = btp_to_gn_rx.recv() {
gn.send_gn_data_request(request);
}
});
let btp = btp_handle.clone();
thread::spawn(move || {
while let Ok(indication) = gn_to_btp_rx.recv() {
btp.send_gn_data_indication(indication);
}
});
Registering Port Listeners
A service receives the packets of a port through an mpsc::Sender<BTPDataIndication>:
let (port_tx, port_rx) = mpsc::channel::<BTPDataIndication>();
btp_handle.register_port(4000, port_tx);
thread::spawn(move || {
while let Ok(indication) = port_rx.recv() {
println!("Port {}: {} bytes", indication.destination_port, indication.data.len());
}
});
With itsGnSecurity enabled, unsecured packets are delivered only to ports registered with register_port_accepting_unsecured.
Sending BTP Data Requests
BTPDataRequest implements Default (BTP-B, single-hop broadcast); set the fields you need:
let payload = b"application payload".to_vec();
let request = BTPDataRequest {
btp_type: CommonNH::BtpB,
destination_port: 4000,
length: payload.len() as u16,
data: payload,
..Default::default()
};
btp_handle.send_btp_data_request(request);