]> git.basschouten.com Git - openhab-addons.git/blob
c97a4ded70786c0722a6e91abf34b56565918096
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.mikrotik.internal.model;
14
15 import static org.openhab.binding.mikrotik.internal.model.RouterosDevice.PROP_ID_KEY;
16
17 import java.math.BigInteger;
18 import java.time.LocalDateTime;
19 import java.util.Map;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.mikrotik.internal.util.Converter;
24
25 /**
26  * The {@link RouterosInterfaceBase} is a base model class for network interface models having casting accessors for
27  * data that is same for all interface types.
28  *
29  * @author Oleg Vivtash - Initial contribution
30  */
31 @NonNullByDefault
32 public abstract class RouterosInterfaceBase extends RouterosBaseData {
33     protected @Nullable RouterosInterfaceType type;
34
35     public RouterosInterfaceBase(Map<String, String> props) {
36         super(props);
37         this.type = RouterosInterfaceType.resolve(getType());
38     }
39
40     public @Nullable String getProperty(String propName) {
41         return getProp(propName);
42     }
43
44     public abstract RouterosInterfaceType getDesignedType();
45
46     public abstract boolean hasDetailedReport();
47
48     public abstract boolean hasMonitor();
49
50     public String getApiType() {
51         return getDesignedType().toString();
52     };
53
54     public boolean validate() {
55         return getDesignedType() == this.type;
56     }
57
58     public @Nullable String getId() {
59         return getProp(PROP_ID_KEY);
60     }
61
62     public @Nullable String getType() {
63         return getProp("type");
64     }
65
66     public @Nullable String getName() {
67         return getProp("name");
68     }
69
70     public @Nullable String getComment() {
71         return getProp("comment");
72     }
73
74     public @Nullable String getMacAddress() {
75         return getProp("mac-address");
76     }
77
78     public boolean isEnabled() {
79         return "false".equals(getProp("disabled", ""));
80     }
81
82     public boolean isConnected() {
83         return "true".equals(getProp("running", ""));
84     }
85
86     public @Nullable Integer getLinkDowns() {
87         return getIntProp("link-downs");
88     }
89
90     public @Nullable LocalDateTime getLastLinkDownTime() {
91         return Converter.fromRouterosTime(getProp("last-link-down-time"));
92     }
93
94     public @Nullable LocalDateTime getLastLinkUpTime() {
95         return Converter.fromRouterosTime(getProp("last-link-up-time"));
96     }
97
98     public @Nullable BigInteger getTxBytes() {
99         return getBigIntProp("tx-byte");
100     }
101
102     public @Nullable BigInteger getRxBytes() {
103         return getBigIntProp("rx-byte");
104     }
105
106     public @Nullable BigInteger getTxPackets() {
107         return getBigIntProp("tx-packet");
108     }
109
110     public @Nullable BigInteger getRxPackets() {
111         return getBigIntProp("rx-packet");
112     }
113
114     public @Nullable BigInteger getTxDrops() {
115         return getBigIntProp("tx-drop");
116     }
117
118     public @Nullable BigInteger getRxDrops() {
119         return getBigIntProp("rx-drop");
120     }
121
122     public @Nullable BigInteger getTxErrors() {
123         return getBigIntProp("tx-error");
124     }
125
126     public @Nullable BigInteger getRxErrors() {
127         return getBigIntProp("rx-error");
128     }
129 }