tof_control/helper/
switch_type.rs

1#[derive(Debug)]
2pub struct AllSwitchData {
3    pub switch1: Option<SwitchData>,
4    pub switch2: Option<SwitchData>,
5    pub switch3: Option<SwitchData>,
6}
7
8#[derive(Debug)]
9pub struct SwitchData {
10    pub info: SwitchInfo,
11    pub port: SwitchPort,
12}
13
14#[derive(Debug)]
15pub struct SwitchInfo {
16    pub hostname: String,
17    pub uptime: String, // VTSSDisplayString (OCTET STRING) (SIZE(0..10)). Hint: 255a
18    pub mac_address: String,
19    pub cpu_load: [u8; 3], // [100ms, 1s, 10s]
20    // Need to Check!
21    pub ps_status: [u8; 2], // vtssSysutilStatusPowerSupplyState (INTEGER), VTSSSysutilPowerSupplyStateType (INTEGER) {active(0), standby(1), notPresent(2) }, The state of power supply.
22}
23
24#[derive(Debug)]
25pub struct SwitchPort {
26    pub link: [u8; 16], // TruthValue (INTEGER) {true(1), false(2) }
27    pub speed: [u8; 16], // VTSSPortStatusSpeed (INTEGER) {undefined(0), speed10M(1), speed100M(2), speed1G(3), speed2G5(4), speed5G(5), speed10G(6), speed12G(7) }
28    pub full_duplex: [u8; 16], // TruthValue (INTEGER) {true(1), false(2) }
29    pub rx_bytes: [u64; 16], // vtssPortStatisticsRmonStatisticsRxOctets (COUNTER64), Shows the number of received (good and bad) bytes. Includes FCS, but excludes framing bits.
30    pub rx_pkts: [u64; 16], // vtssPortStatisticsRmonStatisticsRxPkts (COUNTER64), Shows the number of received (good and bad) packets.
31    pub rx_drop_evts: [u64; 16], // vtssPortStatisticsRmonStatisticsRxDropEvents (COUNTER64), Shows the number of frames discarded due to ingress congestion.
32    pub rx_broadcast_pkts: [u64; 16], // vtssPortStatisticsRmonStatisticsRxBroadcastPkts (COUNTER64), Shows the number of received (good and bad) broadcast packets.
33    pub rx_multicast_pkts: [u64; 16], // vtssPortStatisticsRmonStatisticsRxMulticastPkts (COUNTER64), Shows the number of received (good and bad) multicast packets.
34    pub rx_crc_align_err_pkts: [u64; 16], // vtssPortStatisticsRmonStatisticsRxCrcAlignErrPkts (COUNTER64), Shows the number of frames received with CRC or alignment errors.
35    pub tx_bytes: [u64; 16], //  vtssPortStatisticsRmonStatisticsTxOctets (COUNTER64), Shows the number of transmitted (good and bad) bytes. Includes FCS, but excludes framing bits.
36    pub tx_pkts: [u64; 16], // vtssPortStatisticsRmonStatisticsTxPkts (COUNTER64), Shows the number of transmitted (good and bad) packets.
37    pub tx_drop_evts: [u64; 16], // vtssPortStatisticsRmonStatisticsTxDropEvents (COUNTER64), Shows the number of frames discarded due to egress congestion.
38    pub tx_broadcast_pkts: [u64; 16], // vtssPortStatisticsRmonStatisticsTxBroadcastPkts (COUNTER64), Shows the number of transmitted (good and bad) broadcast packets.
39    pub tx_multicast_pkts: [u64; 16], // vtssPortStatisticsRmonStatisticsTxMulticastPkts (COUNTER64), Shows the number of transmitted (good and bad) multicast packets.
40}
41
42/// Switch Error Type
43#[derive(Debug)]
44pub enum SwitchError {
45    SNMP(snmp::SnmpError),
46    ParseInt(std::num::ParseIntError),
47    IO(std::io::Error),
48    Address,
49}
50
51impl From<snmp::SnmpError> for SwitchError {
52    fn from(e: snmp::SnmpError) -> Self {
53        SwitchError::SNMP(e)
54    }
55}
56
57impl From<std::num::ParseIntError> for SwitchError {
58    fn from(e: std::num::ParseIntError) -> Self {
59        SwitchError::ParseInt(e)
60    }
61}
62
63impl From<std::io::Error> for SwitchError {
64    fn from(e: std::io::Error) -> Self {
65        SwitchError::IO(e)
66    }
67}