blob: 048751625fdb170948dc5af11ade9810d2277059 [file] [log] [blame]
Sean Condon0e89bda2017-03-21 14:23:19 +00001/*
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.incubator.net.l2monitoring.soam.loss;
17
18import java.util.ArrayList;
19import java.util.Collection;
20
21import org.onosproject.incubator.net.l2monitoring.soam.MilliPct;
22import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
23
24/**
25 * The default implementation of {@link org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementThreshold}.
26 */
27public final class DefaultLmThreshold implements LossMeasurementThreshold {
28
29 private final SoamId thresholdId;
30 private final Collection<ThresholdOption> threshold;
31 private final MilliPct measuredFlrForward;
32 private final MilliPct maxFlrForward;
33 private final MilliPct averageFlrForward;
34 private final MilliPct measuredFlrBackward;
35 private final MilliPct maxFlrBackward;
36 private final MilliPct averageFlrBackward;
37 private final Long forwardHighLoss;
38 private final Long forwardConsecutiveHighLoss;
39 private final Long backwardHighLoss;
40 private final Long backwardConsecutiveHighLoss;
41 private final Long forwardUnavailableCount;
42 private final MilliPct forwardAvailableRatio;
43 private final Long backwardUnavailableCount;
44 private final MilliPct backwardAvailableRatio;
45
46 private DefaultLmThreshold(DefaultLmThresholdBuilder builder) {
47 this.thresholdId = builder.thresholdId;
48 this.threshold = builder.threshold;
49 this.measuredFlrForward = builder.measuredFlrForward;
50 this.maxFlrForward = builder.maxFlrForward;
51 this.averageFlrForward = builder.averageFlrForward;
52 this.measuredFlrBackward = builder.measuredFlrBackward;
53 this.maxFlrBackward = builder.maxFlrBackward;
54 this.averageFlrBackward = builder.averageFlrBackward;
55 this.forwardHighLoss = builder.forwardHighLoss;
56 this.forwardConsecutiveHighLoss = builder.forwardConsecutiveHighLoss;
57 this.backwardHighLoss = builder.backwardHighLoss;
58 this.backwardConsecutiveHighLoss = builder.backwardConsecutiveHighLoss;
59 this.forwardUnavailableCount = builder.forwardUnavailableCount;
60 this.forwardAvailableRatio = builder.forwardAvailableRatio;
61 this.backwardUnavailableCount = builder.backwardUnavailableCount;
62 this.backwardAvailableRatio = builder.backwardAvailableRatio;
63 }
64
65 @Override
66 public SoamId thresholdId() {
67 return thresholdId;
68 }
69
70 @Override
71 public Collection<ThresholdOption> thresholds() {
72 return threshold;
73 }
74
75 @Override
76 public MilliPct measuredFlrForward() {
77 return measuredFlrForward;
78 }
79
80 @Override
81 public MilliPct maxFlrForward() {
82 return maxFlrForward;
83 }
84
85 @Override
86 public MilliPct averageFlrForward() {
87 return averageFlrForward;
88 }
89
90 @Override
91 public MilliPct measuredFlrBackward() {
92 return measuredFlrBackward;
93 }
94
95 @Override
96 public MilliPct maxFlrBackward() {
97 return maxFlrBackward;
98 }
99
100 @Override
101 public MilliPct averageFlrBackward() {
102 return averageFlrBackward;
103 }
104
105 @Override
106 public Long forwardHighLoss() {
107 return forwardHighLoss;
108 }
109
110 @Override
111 public Long forwardConsecutiveHighLoss() {
112 return forwardConsecutiveHighLoss;
113 }
114
115 @Override
116 public Long backwardHighLoss() {
117 return backwardHighLoss;
118 }
119
120 @Override
121 public Long backwardConsecutiveHighLoss() {
122 return backwardConsecutiveHighLoss;
123 }
124
125 @Override
126 public Long forwardUnavailableCount() {
127 return forwardUnavailableCount;
128 }
129
130 @Override
131 public MilliPct forwardAvailableRatio() {
132 return forwardAvailableRatio;
133 }
134
135 @Override
136 public Long backwardUnavailableCount() {
137 return backwardUnavailableCount;
138 }
139
140 @Override
141 public MilliPct backwardAvailableRatio() {
142 return backwardAvailableRatio;
143 }
144
145 public static LmThresholdBuilder builder(SoamId thresholdId) {
146 return new DefaultLmThresholdBuilder(thresholdId);
147 }
148
149 private static final class DefaultLmThresholdBuilder implements LmThresholdBuilder {
150 private final SoamId thresholdId;
151 private Collection<ThresholdOption> threshold;
152 private MilliPct measuredFlrForward;
153 private MilliPct maxFlrForward;
154 private MilliPct averageFlrForward;
155 private MilliPct measuredFlrBackward;
156 private MilliPct maxFlrBackward;
157 private MilliPct averageFlrBackward;
158 private Long forwardHighLoss;
159 private Long forwardConsecutiveHighLoss;
160 private Long backwardHighLoss;
161 private Long backwardConsecutiveHighLoss;
162 private Long forwardUnavailableCount;
163 private MilliPct forwardAvailableRatio;
164 private Long backwardUnavailableCount;
165 private MilliPct backwardAvailableRatio;
166
167 protected DefaultLmThresholdBuilder(SoamId thresholdId) {
168 this.thresholdId = thresholdId;
169 threshold = new ArrayList<>();
170 }
171
172 @Override
173 public LmThresholdBuilder addToThreshold(ThresholdOption threshold) {
174 this.threshold.add(threshold);
175 return this;
176 }
177
178 @Override
179 public LmThresholdBuilder measuredFlrForward(MilliPct measuredFlrForward) {
180 this.measuredFlrForward = measuredFlrForward;
181 return this;
182 }
183
184 @Override
185 public LmThresholdBuilder maxFlrForward(MilliPct maxFlrForward) {
186 this.maxFlrForward = maxFlrForward;
187 return this;
188 }
189
190 @Override
191 public LmThresholdBuilder averageFlrForward(MilliPct averageFlrForward) {
192 this.averageFlrForward = averageFlrForward;
193 return this;
194 }
195
196 @Override
197 public LmThresholdBuilder measuredFlrBackward(
198 MilliPct measuredFlrBackward) {
199 this.measuredFlrBackward = measuredFlrBackward;
200 return this;
201 }
202
203 @Override
204 public LmThresholdBuilder maxFlrBackward(MilliPct maxFlrBackward) {
205 this.maxFlrBackward = maxFlrBackward;
206 return this;
207 }
208
209 @Override
210 public LmThresholdBuilder averageFlrBackward(MilliPct averageFlrBackward) {
211 this.averageFlrBackward = averageFlrBackward;
212 return this;
213 }
214
215 @Override
216 public LmThresholdBuilder forwardHighLoss(Long forwardHighLoss) {
217 this.forwardHighLoss = forwardHighLoss;
218 return this;
219 }
220
221 @Override
222 public LmThresholdBuilder forwardConsecutiveHighLoss(
223 Long forwardConsecutiveHighLoss) {
224 this.forwardConsecutiveHighLoss = forwardConsecutiveHighLoss;
225 return this;
226 }
227
228 @Override
229 public LmThresholdBuilder backwardHighLoss(Long backwardHighLoss) {
230 this.backwardHighLoss = backwardHighLoss;
231 return this;
232 }
233
234 @Override
235 public LmThresholdBuilder backwardConsecutiveHighLoss(
236 Long backwardConsecutiveHighLoss) {
237 this.backwardConsecutiveHighLoss = backwardConsecutiveHighLoss;
238 return this;
239 }
240
241 @Override
242 public LmThresholdBuilder forwardUnavailableCount(
243 Long forwardUnavailableCount) {
244 this.forwardUnavailableCount = forwardUnavailableCount;
245 return this;
246 }
247
248 @Override
249 public LmThresholdBuilder forwardAvailableRatio(
250 MilliPct forwardAvailableRatio) {
251 this.forwardAvailableRatio = forwardAvailableRatio;
252 return this;
253 }
254
255 @Override
256 public LmThresholdBuilder backwardUnavailableCount(
257 Long backwardUnavailableCount) {
258 this.backwardUnavailableCount = backwardUnavailableCount;
259 return this;
260 }
261
262 @Override
263 public LmThresholdBuilder backwardAvailableRatio(
264 MilliPct backwardAvailableRatio) {
265 this.backwardAvailableRatio = backwardAvailableRatio;
266 return this;
267 }
268
269 @Override
270 public LossMeasurementThreshold build() {
271 return new DefaultLmThreshold(this);
272 }
273 }
274}