agvtf/
stats.rs

1use std::net::Ipv4Addr;
2
3use crate::errors;
4
5#[derive(Debug)]
6pub enum Protocol {
7    PPPoE,
8    PPPoA,
9}
10
11impl std::convert::TryFrom<String> for Protocol {
12    type Error = errors::Error;
13
14    fn try_from(value: String) -> Result<Self, Self::Error> {
15        match value.as_ref() {
16            "PPPoE" => Ok(Self::PPPoE),
17            "PPPoA" => Ok(Self::PPPoA),
18            _ => Err(errors::Error::InvalidValue(value)),
19        }
20    }
21}
22#[derive(Debug)]
23pub struct GatewayInfo {
24    pub model: String,
25    pub serial_number: String,
26    pub hardware_version: String,
27    pub software_version: String,
28}
29#[derive(Debug)]
30pub struct ConnectionInfo {
31    //pub profilo_tariffario: String,
32    //pub mode: String,
33    pub protocol: Protocol,
34    //pub connection_mode: String,
35    pub ip_address: Ipv4Addr,
36    //telegestione
37    //connessione automatica da modem
38    pub primary_dns: Option<Ipv4Addr>,
39    pub secondary_dns: Option<Ipv4Addr>,
40    pub other_dns: Vec<Ipv4Addr>,
41}
42
43#[derive(Debug)]
44pub enum Encapsulation {
45    ATM,
46    PTM,
47}
48
49impl std::convert::TryFrom<&str> for Encapsulation {
50    type Error = errors::Error;
51
52    fn try_from(v: &str) -> Result<Self, Self::Error> {
53        match v {
54            "ATM" => Ok(Self::ATM),
55            "PTM" => Ok(Self::PTM),
56            _ => Err(Self::Error::InvalidValue(v.to_owned())),
57        }
58    }
59}
60
61#[derive(Debug)]
62pub struct TxRx<T>
63where
64    T: std::ops::Add,
65{
66    pub tx: T,
67    pub rx: T,
68}
69
70#[derive(Debug)]
71pub struct LineInfo {
72    pub max_speed: TxRx<u32>,
73    pub dsl_driver_version: String,
74    pub encapsulation: Encapsulation,
75    pub power: TxRx<f64>,
76    pub snr: TxRx<f64>,
77    pub speed: TxRx<u32>,
78    pub ses: u64,
79    pub es: Option<u64>,
80    pub fec: Option<u64>,
81    pub crc: Option<u64>,
82    pub uptime: u64,
83    pub inp: u16,
84    pub attenuation: TxRx<f64>,
85}