blob: 0528a692f595eaeae1e350707b24671b517dec1e [file] [log] [blame]
Georgios Katsikasfda66742018-07-31 20:18:14 +02001/*
2 * Copyright 2017-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.drivers.server.stats;
17
18import java.util.Map;
19import java.util.HashMap;
20
21/**
22 * Representation of a monitoring unit.
23 */
24public interface MonitoringUnit {
25
26 /**
27 * Throughput-related monitoring units.
28 */
29 public enum ThroughputUnit implements MonitoringUnit {
30
31 BPS("bps"),
32 KBPS("kbps"),
33 MBPS("mbps"),
34 GBPS("gbps");
35
36 private String throughputUnit;
37
38 // Statically maps throughput monitoring units to enum types
39 private static final Map<String, MonitoringUnit> MAP =
40 new HashMap<String, MonitoringUnit>();
41 static {
42 for (ThroughputUnit tu : ThroughputUnit.values()) {
43 MAP.put(tu.toString().toLowerCase(), (MonitoringUnit) tu);
44 }
45 }
46
47 private ThroughputUnit(String throughputUnit) {
48 this.throughputUnit = throughputUnit;
49 }
50
51 public static MonitoringUnit getByName(String tu) {
52 tu = tu.toLowerCase();
53 return MAP.get(tu);
54 }
55
56 @Override
57 public String toString() {
58 return this.throughputUnit;
59 }
60
61 };
62
63 /**
64 * Latency-related monitoring units.
65 */
66 public enum LatencyUnit implements MonitoringUnit {
67
68 NANO_SECOND("ns"),
69 MICRO_SECOND("us"),
70 MILLI_SECOND("ms"),
71 SECOND("s");
72
73 private String latencyUnit;
74
75 // Statically maps latency monitoring units to enum types
76 private static final Map<String, MonitoringUnit> MAP =
77 new HashMap<String, MonitoringUnit>();
78 static {
79 for (LatencyUnit lu : LatencyUnit.values()) {
80 MAP.put(lu.toString().toLowerCase(), (MonitoringUnit) lu);
81 }
82 }
83
84 private LatencyUnit(String latencyUnit) {
85 this.latencyUnit = latencyUnit;
86 }
87
88 public static MonitoringUnit getByName(String lu) {
89 lu = lu.toLowerCase();
90 return MAP.get(lu);
91 }
92
93 @Override
94 public String toString() {
95 return this.latencyUnit;
96 }
97
98 };
99
100 String toString();
101
102}