2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mikrotik.internal.model;
15 import static org.openhab.binding.mikrotik.internal.model.RouterosDevice.PROP_ID_KEY;
17 import java.math.BigInteger;
18 import java.time.LocalDateTime;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.mikrotik.internal.util.Converter;
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.
29 * @author Oleg Vivtash - Initial contribution
32 public abstract class RouterosInterfaceBase extends RouterosBaseData {
33 protected @Nullable RouterosInterfaceType type;
35 public RouterosInterfaceBase(Map<String, String> props) {
37 this.type = RouterosInterfaceType.resolve(getType());
40 public @Nullable String getProperty(String propName) {
41 return getProp(propName);
44 public abstract RouterosInterfaceType getDesignedType();
46 public abstract boolean hasDetailedReport();
48 public abstract boolean hasMonitor();
50 public String getApiType() {
51 return getDesignedType().toString();
54 public boolean validate() {
55 return getDesignedType() == this.type;
58 public @Nullable String getId() {
59 return getProp(PROP_ID_KEY);
62 public @Nullable String getType() {
63 return getProp("type");
66 public @Nullable String getName() {
67 return getProp("name");
70 public @Nullable String getComment() {
71 return getProp("comment");
74 public @Nullable String getMacAddress() {
75 return getProp("mac-address");
78 public boolean isEnabled() {
79 return "false".equals(getProp("disabled", ""));
82 public boolean isConnected() {
83 return "true".equals(getProp("running", ""));
86 public @Nullable Integer getLinkDowns() {
87 return getIntProp("link-downs");
90 public @Nullable LocalDateTime getLastLinkDownTime() {
91 return Converter.fromRouterosTime(getProp("last-link-down-time"));
94 public @Nullable LocalDateTime getLastLinkUpTime() {
95 return Converter.fromRouterosTime(getProp("last-link-up-time"));
98 public @Nullable BigInteger getTxBytes() {
99 return getBigIntProp("tx-byte");
102 public @Nullable BigInteger getRxBytes() {
103 return getBigIntProp("rx-byte");
106 public @Nullable BigInteger getTxPackets() {
107 return getBigIntProp("tx-packet");
110 public @Nullable BigInteger getRxPackets() {
111 return getBigIntProp("rx-packet");
114 public @Nullable BigInteger getTxDrops() {
115 return getBigIntProp("tx-drop");
118 public @Nullable BigInteger getRxDrops() {
119 return getBigIntProp("rx-drop");
122 public @Nullable BigInteger getTxErrors() {
123 return getBigIntProp("tx-error");
126 public @Nullable BigInteger getRxErrors() {
127 return getBigIntProp("rx-error");