Skip to main content

batman_robin/model/
gateway.rs

1use macaddr::MacAddr6;
2
3/// Represents a gateway in the batman-adv mesh.
4///
5/// This struct contains information about a gateway node, including its MAC address,
6/// the router it is associated with, interface used, bandwidth, throughput, and
7/// quality metrics.
8#[derive(Debug, Clone)]
9pub struct Gateway {
10    /// MAC address of the gateway (BATADV_ATTR_ORIG_ADDRESS).
11    pub mac_addr: MacAddr6,
12
13    /// MAC address of the associated router (BATADV_ATTR_ROUTER).
14    pub router: MacAddr6,
15
16    /// Outgoing interface used to reach this gateway.
17    /// Usually from BATADV_ATTR_HARD_IFNAME; if not available, falls back to interface index.
18    pub outgoing_if: String,
19
20    /// Optional downstream bandwidth in kbps (BATADV_ATTR_BANDWIDTH_DOWN).
21    pub bandwidth_down: Option<u32>,
22
23    /// Optional upstream bandwidth in kbps (BATADV_ATTR_BANDWIDTH_UP).
24    pub bandwidth_up: Option<u32>,
25
26    /// Optional throughput in kbps (BATADV_ATTR_THROUGHPUT).
27    pub throughput: Option<u32>,
28
29    /// Optional transmission quality (TQ) of the gateway (BATADV_ATTR_TQ).
30    pub tq: Option<u8>,
31
32    /// Whether this gateway is considered the best among alternatives (BATADV_ATTR_FLAG_BEST).
33    pub is_best: bool,
34}
35
36/// Contains configuration information about a mesh gateway.
37///
38/// This struct is used when querying or setting the gateway mode and associated parameters.
39#[derive(Debug)]
40pub struct GatewayInfo {
41    /// Current gateway mode (BATADV_ATTR_GW_MODE).
42    pub mode: GwMode,
43
44    /// Selection class for the gateway (BATADV_ATTR_GW_SEL_CLASS).
45    pub sel_class: u32,
46
47    /// Downstream bandwidth in kbps (BATADV_ATTR_GW_BANDWIDTH_DOWN).
48    pub bandwidth_down: u32,
49
50    /// Upstream bandwidth in kbps (BATADV_ATTR_GW_BANDWIDTH_UP).
51    pub bandwidth_up: u32,
52
53    /// Routing algorithm in use (BATADV_ATTR_ALGO_NAME).
54    pub algo: String,
55}
56
57/// Represents the mode of a batman-adv gateway.
58#[derive(Debug, Copy, Clone)]
59pub enum GwMode {
60    /// Gateway mode is turned off.
61    Off,
62
63    /// Node is operating as a gateway client.
64    Client,
65
66    /// Node is operating as a gateway server.
67    Server,
68
69    /// Unknown or unsupported mode.
70    Unknown,
71}