pub struct Client;Expand description
High-level client for interacting with the BATMAN-adv mesh network.
Client provides asynchronous methods to query and configure BATMAN-adv
interfaces and settings via netlink.
Mesh-targeted methods take a model::MeshSelector by value. You can build
selectors explicitly with model::MeshSelector::with_name or
model::MeshSelector::with_ifindex.
§Example
use batman_robin::{Client, MeshSelector};
let client = Client::new();
let selector = MeshSelector::with_name("bat0");
let neighbors = client.neighbors(selector.clone()).await?;
println!("{} neighbor entries", neighbors.len());Implementations§
Source§impl Client
impl Client
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new instance of Client.
§Example
use batman_robin::Client;
let client = Client::new();
let _ = client;Sourcepub async fn originators(
&self,
selector: MeshSelector,
) -> Result<Vec<Originator>, Error>
pub async fn originators( &self, selector: MeshSelector, ) -> Result<Vec<Originator>, Error>
Sourcepub async fn gateways(
&self,
selector: Option<MeshSelector>,
) -> Result<Vec<Gateway>, Error>
pub async fn gateways( &self, selector: Option<MeshSelector>, ) -> Result<Vec<Gateway>, Error>
Retrieves the list of gateways for the selected mesh interface.
§Arguments
selector- Mesh selector.
§Example
use batman_robin::{Client, MeshSelector};
let client = Client::new();
let gateways = client.gateways(Some(MeshSelector::with_name("bat0"))).await?;
println!("{} gateways", gateways.len());
// Pass None to query gateways across all mesh interfaces:
let all = client.gateways(None).await?;Sourcepub async fn subscribe_gateway_events(
&self,
selector: Option<MeshSelector>,
) -> Result<BoxStream<'static, Result<GatewayEvent, Error>>, Error>
pub async fn subscribe_gateway_events( &self, selector: Option<MeshSelector>, ) -> Result<BoxStream<'static, Result<GatewayEvent, Error>>, Error>
Subscribes to gateway change events for the selected mesh interface.
§Arguments
selector- Mesh selector.
§Example
use batman_robin::{Client, MeshSelector};
use futures::StreamExt;
let client = Client::new();
let mut events = client
.subscribe_gateway_events(Some(MeshSelector::with_name("bat0")))
.await?;
while let Some(event) = events.next().await {
println!("{:?}", event?);
}Sourcepub async fn get_gw_mode(
&self,
selector: MeshSelector,
) -> Result<GatewayInfo, Error>
pub async fn get_gw_mode( &self, selector: MeshSelector, ) -> Result<GatewayInfo, Error>
Gets current gateway mode and related configuration for the selected mesh interface.
§Arguments
selector- Mesh selector.
§Example
use batman_robin::{Client, MeshSelector};
let client = Client::new();
let gw = client.get_gw_mode(MeshSelector::with_name("bat0")).await?;
println!("mode={:?}", gw.mode);Sourcepub async fn set_gw_mode(
&self,
selector: MeshSelector,
mode: GwMode,
down: Option<u32>,
up: Option<u32>,
sel_class: Option<u32>,
) -> Result<(), Error>
pub async fn set_gw_mode( &self, selector: MeshSelector, mode: GwMode, down: Option<u32>, up: Option<u32>, sel_class: Option<u32>, ) -> Result<(), Error>
Sets gateway mode and optional parameters for the selected mesh interface.
§Arguments
selector- Mesh selector.mode- Gateway mode to apply.down- Optional downstream bandwidth parameter.up- Optional upstream bandwidth parameter.sel_class- Optional gateway selection class.
§Errors
Returns Error if selector validation, selector resolution, or netlink write fails.
§Example
use batman_robin::{Client, GwMode, MeshSelector};
let client = Client::new();
client
.set_gw_mode(
MeshSelector::with_name("bat0"),
GwMode::Client,
None,
None,
Some(20),
)
.await?;Sourcepub async fn transglobal(
&self,
selector: MeshSelector,
) -> Result<Vec<TransglobalEntry>, Error>
pub async fn transglobal( &self, selector: MeshSelector, ) -> Result<Vec<TransglobalEntry>, Error>
Retrieves global translation table entries for the selected mesh interface.
§Arguments
selector- Mesh selector.
§Example
use batman_robin::{Client, MeshSelector};
let client = Client::new();
let tg = client.transglobal(MeshSelector::with_name("bat0")).await?;
println!("{} global entries", tg.len());Sourcepub async fn translocal(
&self,
selector: MeshSelector,
) -> Result<Vec<TranslocalEntry>, Error>
pub async fn translocal( &self, selector: MeshSelector, ) -> Result<Vec<TranslocalEntry>, Error>
Sourcepub async fn interface_list(
&self,
selector: MeshSelector,
) -> Result<Vec<Interface>, Error>
pub async fn interface_list( &self, selector: MeshSelector, ) -> Result<Vec<Interface>, Error>
Retrieves the list of physical interfaces attached to the selected mesh interface.
§Arguments
selector- Mesh selector.
§Example
use batman_robin::{Client, MeshSelector};
let client = Client::new();
let ifaces = client.interface_list(MeshSelector::with_name("bat0")).await?;
println!("{} attached interfaces", ifaces.len());Sourcepub async fn interface_add(
&self,
selector: MeshSelector,
interface_selector: InterfaceSelector,
) -> Result<(), Error>
pub async fn interface_add( &self, selector: MeshSelector, interface_selector: InterfaceSelector, ) -> Result<(), Error>
Adds a physical interface to a selected mesh interface.
§Arguments
selector- Mesh selector identifying the target mesh interface.interface_selector- Interface selector for the physical interface to add.
§Example
use batman_robin::{Client, InterfaceSelector, MeshSelector};
let client = Client::new();
client
.interface_add(
MeshSelector::with_name("bat0"),
InterfaceSelector::with_name("wlan0"),
)
.await?;Sourcepub async fn interface_remove(
&self,
interface_selector: InterfaceSelector,
) -> Result<(), Error>
pub async fn interface_remove( &self, interface_selector: InterfaceSelector, ) -> Result<(), Error>
Sourcepub async fn mesh_create(
&self,
mesh_if: &str,
routing_algo: Option<&str>,
mac_addr: Option<MacAddr6>,
) -> Result<(), Error>
pub async fn mesh_create( &self, mesh_if: &str, routing_algo: Option<&str>, mac_addr: Option<MacAddr6>, ) -> Result<(), Error>
Creates a new BATMAN-adv mesh interface with an optional routing algorithm and MAC address.
§Arguments
mesh_if- Name of the interface to create.routing_algo- Optional routing algorithm string.mac_addr- Optional hardware address. A random locally-administered address is generated ifNoneto avoid conflicts with other devices on the network.
§Example
use batman_robin::Client;
let client = Client::new();
client.mesh_create("bat0", Some("BATMAN_V"), None).await?;Sourcepub async fn mesh_list(&self) -> Result<Vec<String>, Error>
pub async fn mesh_list(&self) -> Result<Vec<String>, Error>
Lists BATMAN-adv mesh interfaces available on the host.
This method returns interfaces whose kernel link kind is batadv.
It is useful to discover existing mesh interfaces before selecting one
for operations like neighbors, gateways, or interface management.
§Returns
Returns a vector of mesh interface names for every detected BATMAN-adv mesh interface.
§Example
use batman_robin::Client;
let client = Client::new();
let meshes = client.mesh_list().await?;
for mesh in meshes {
println!("mesh={}", mesh);
}Sourcepub async fn mesh_delete(&self, selector: MeshSelector) -> Result<(), Error>
pub async fn mesh_delete(&self, selector: MeshSelector) -> Result<(), Error>
Sourcepub async fn interfaces_count(
&self,
selector: MeshSelector,
) -> Result<u32, Error>
pub async fn interfaces_count( &self, selector: MeshSelector, ) -> Result<u32, Error>
Sourcepub async fn get_aggregation(
&self,
selector: MeshSelector,
) -> Result<bool, Error>
pub async fn get_aggregation( &self, selector: MeshSelector, ) -> Result<bool, Error>
Sourcepub async fn set_aggregation(
&self,
selector: MeshSelector,
val: bool,
) -> Result<(), Error>
pub async fn set_aggregation( &self, selector: MeshSelector, val: bool, ) -> Result<(), Error>
Sourcepub async fn get_ap_isolation(
&self,
selector: MeshSelector,
) -> Result<bool, Error>
pub async fn get_ap_isolation( &self, selector: MeshSelector, ) -> Result<bool, Error>
Sourcepub async fn set_ap_isolation(
&self,
selector: MeshSelector,
val: bool,
) -> Result<(), Error>
pub async fn set_ap_isolation( &self, selector: MeshSelector, val: bool, ) -> Result<(), Error>
Sourcepub async fn get_bridge_loop_avoidance(
&self,
selector: MeshSelector,
) -> Result<bool, Error>
pub async fn get_bridge_loop_avoidance( &self, selector: MeshSelector, ) -> Result<bool, Error>
Gets whether bridge loop avoidance is enabled on the selected mesh interface.
§Arguments
selector- Mesh selector.
§Example
use batman_robin::{Client, MeshSelector};
let client = Client::new();
let enabled = client
.get_bridge_loop_avoidance(MeshSelector::with_name("bat0"))
.await?;
println!("{enabled}");Sourcepub async fn set_bridge_loop_avoidance(
&self,
selector: MeshSelector,
val: bool,
) -> Result<(), Error>
pub async fn set_bridge_loop_avoidance( &self, selector: MeshSelector, val: bool, ) -> Result<(), Error>
Enables or disables bridge loop avoidance on the selected mesh interface.
§Arguments
selector- Mesh selector.val-trueto enable,falseto disable.
§Example
use batman_robin::{Client, MeshSelector};
let client = Client::new();
client
.set_bridge_loop_avoidance(MeshSelector::with_name("bat0"), true)
.await?;Sourcepub async fn get_default_routing_algo(&self) -> Result<String, Error>
pub async fn get_default_routing_algo(&self) -> Result<String, Error>
Sourcepub async fn get_active_routing_algos(
&self,
) -> Result<Vec<(String, String)>, Error>
pub async fn get_active_routing_algos( &self, ) -> Result<Vec<(String, String)>, Error>
Retrieves all active routing algorithms currently in use and their interfaces.
Returns a vector of (interface_name, algorithm_name).
§Example
use batman_robin::Client;
let client = Client::new();
let active = client.get_active_routing_algos().await?;
for (iface, algo) in active {
println!("{iface}: {algo}");
}Sourcepub async fn get_available_routing_algos(&self) -> Result<Vec<String>, Error>
pub async fn get_available_routing_algos(&self) -> Result<Vec<String>, Error>
Retrieves all routing algorithms available on the system.
§Example
use batman_robin::Client;
let client = Client::new();
let available = client.get_available_routing_algos().await?;
println!("{} available algos", available.len());