blob: 8f545a7c55db07259e57294015424411aa409742 [file] [log] [blame]
chengfan2fff70f2015-08-24 18:20:19 -05001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
chengfan2fff70f2015-08-24 18:20:19 -05003 *
Thomas Vachuska58de4162015-09-10 16:15:33 -07004 * 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
chengfan2fff70f2015-08-24 18:20:19 -05007 *
Thomas Vachuska58de4162015-09-10 16:15:33 -07008 * 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.
chengfan2fff70f2015-08-24 18:20:19 -050015 */
16
17package org.onosproject.incubator.net.tunnel;
18
Thomas Vachuska4c571ae2015-09-10 16:31:59 -070019import com.google.common.annotations.Beta;
20
chengfan2fff70f2015-08-24 18:20:19 -050021import java.time.Duration;
22import java.util.List;
23
24/**
25 * Default implementation of immutable tunnel statistics.
26 */
Thomas Vachuska4c571ae2015-09-10 16:31:59 -070027@Beta
chengfan2fff70f2015-08-24 18:20:19 -050028public final class DefaultTunnelStatistics implements TunnelStatistics {
29 private final TunnelId tunnelId;
30 private final double bwUtilization;
31 private final double packetLossRatio;
32 private final Duration flowDelay;
33 private final List<String> alarms;
34
35 private DefaultTunnelStatistics(TunnelId tunnelId,
36 double bwUtilization,
37 double packetLossRatio,
38 Duration flowDelay,
39 List<String> alarms) {
40 this.tunnelId = tunnelId;
41 this.bwUtilization = bwUtilization;
42 this.packetLossRatio = packetLossRatio;
43 this.flowDelay = flowDelay;
44 this.alarms = alarms;
45 }
46
47 private DefaultTunnelStatistics() {
48 this.tunnelId = null;
49 this.bwUtilization = 0;
50 this.packetLossRatio = 0;
51 this.flowDelay = null;
52 this.alarms = null;
53 }
54
55
56 @Override
57 public TunnelId id() {
58 return this.tunnelId;
59 }
60
61 @Override
62 public double bandwidthUtilization() {
63 return this.bwUtilization;
64 }
65
66 @Override
67 public double packetLossRate() {
68 return this.packetLossRatio;
69 }
70
71 @Override
72 public Duration flowDelay() {
73 return this.flowDelay;
74 }
75
76
77 @Override
78 public List<String> alarms() {
79 return this.alarms;
80 }
81
82 /**
83 * Builder for tunnelStatistics.
84 */
85 public static final class Builder {
86 TunnelId tunnelId;
87 double bwUtilization;
88 double packetLossRatio;
89 Duration flowDelay;
90 List<String> alarms;
91
92 public Builder() {
93
94 }
95
96 /**
97 * Set tunnel id.
98 *
99 * @param tunnelId tunnel id
100 * @return builder object
101 */
102 public Builder setTunnelId(TunnelId tunnelId) {
103 this.tunnelId = tunnelId;
104
105 return this;
106 }
107
108 /**
109 * set bandwidth utilization.
110 *
111 * @param bwUtilization bandwidth utilization
112 * @return builder object
113 */
114 public Builder setBwUtilization(double bwUtilization) {
115 this.bwUtilization = bwUtilization;
116
117 return this;
118 }
119
120 /**
121 * Set packet loss ratio.
122 *
123 * @param packetLossRatio packet loss ratio
124 * @return builder object
125 */
126 public Builder setPacketLossRatio(double packetLossRatio) {
127 this.packetLossRatio = packetLossRatio;
128
129 return this;
130 }
131
132 /**
133 * Set flow delay.
134 *
135 * @param flowDelay flow delay
136 * @return builder object
137 */
138 public Builder setFlowDelay(Duration flowDelay) {
139 this.flowDelay = flowDelay;
140
141 return this;
142 }
143
144 /**
145 * Set alarms.
146 *
147 * @param alarms alarms of a tunnel
148 * @return builder object
149 */
150 public Builder setAlarms(List<String> alarms) {
151 this.alarms = alarms;
152
153 return this;
154 }
155
156 /**
157 * Creates a TunnelStatistics object.
158 *
159 * @return DefaultTunnelStatistics
160 */
161 public DefaultTunnelStatistics build() {
162 return new DefaultTunnelStatistics(tunnelId,
163 bwUtilization,
164 packetLossRatio,
165 flowDelay,
166 alarms);
167 }
168 }
169}