netconf-rust
Warning: This library is EXTREMELY experimental and under active development. The API is subject to change without notice. Use in production at your own risk.
An async Rust NETCONF client implementing RFC 6241, RFC 6242, and RFC 4742 with pipelining and zero-copy XML parsing.
Features
- Async -- Built on tokio with split read/write architecture
- Pipelining -- Send multiple RPCs without waiting for replies, correlated by message-id
- Streaming -- Stream large responses chunk-by-chunk via
AsyncRead, avoiding unbounded memory usage - Zero-copy parsing --
DataPayloadreferences the codec buffer directly, avoiding copies for large responses - RFC 6242 chunked framing -- Automatically negotiated during the hello exchange
- RFC 4742 EOM framing -- Fallback for NETCONF 1.0-only devices
- Keyboard-interactive auth -- Fallback for devices (Cisco, Nokia) that require it
Usage
use ;
async
Subtree filtering
let interfaces = session.get_config.await?;
Edit config with candidate commit
session.lock.await?;
session.edit_config.await?;
session.commit.await?;
session.unlock.await?;
Pipelining
let fut1 = session.rpc_send.await?;
let fut2 = session.rpc_send.await?;
let fut3 = session.rpc_send.await?;
let reply1 = fut1.response.await?;
let reply2 = fut2.response.await?;
let reply3 = fut3.response.await?;
Zero-copy DataPayload
let payload = session.get_config_payload.await?;
println!;
// Zero-copy &str view
let s: &str = payload.as_str;
// Stream XML events directly from the payload's bytes
let mut reader = payload.reader;
Streaming
use AsyncReadExt;
let mut stream = session.get_config_stream.await?;
let mut buf = ;
loop
Raw RPC
let reply = session.rpc_raw.await?;
Built with
- russh -- Async SSH implementation used for the transport layer
- quick-xml -- Fast, zero-allocation XML parser powering our event-based parsing and span extraction
- bytes -- Reference-counted byte buffers enabling zero-copy message handling
RFCs
- RFC 6241 -- NETCONF Configuration Protocol
- RFC 6242 -- Using NETCONF over SSH (chunked framing)
- RFC 4742 -- Using NETCONF over SSH (EOM framing)
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.