blob: edbe643fb0175633ffb5d8c8db1a7bdfefc3f843 [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.cfm;
17
18import java.util.ArrayList;
19import java.util.Collection;
20import java.util.List;
21
22import org.onlab.packet.MacAddress;
23import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort;
24import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId;
25import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
26import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
27import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry;
28import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry;
29import org.onosproject.net.DeviceId;
30import org.onosproject.net.PortNumber;
31
32import com.google.common.base.MoreObjects;
33import com.google.common.collect.Lists;
34
35/**
Sean Condon3a1efef2018-02-24 13:16:03 +000036 * The default implementation of {@link MepEntry}.
Sean Condon0e89bda2017-03-21 14:23:19 +000037 */
38public final class DefaultMepEntry extends DefaultMep implements MepEntry {
39
40 private final MacAddress macAddress;
41 private final FngState fngState;
42 private final FaultDefectType highestPriorityDefect;
43 private final boolean activeRdiCcmDefect;
44 private final boolean activeMacStatusDefect;
45 private final boolean activeRemoteCcmDefect;
46 private final boolean activeErrorCcmDefect;
47 private final boolean activeXconCcmDefect;
48 private final byte[] lastErrorCcm;
49 private final byte[] lastXconCcm;
50 private final int ccmSequenceErrorCount;
51 private final int totalCcmsTransmitted;
52 private final MepLbEntry loopbackAttributes;
53 private final MepLtEntry linktraceAttributes;
54 private final Collection<RemoteMepEntry> activeRemoteMepList;
55 private final Collection<DelayMeasurementEntry> delayMeasurementList;
56 private final Collection<LossMeasurementEntry> lossMeasurementList;
57
58 private DefaultMepEntry(DefaultMepEntryBuilder mepEntryBuilder) throws CfmConfigException {
59 super((DefaultMepBuilder) DefaultMep.builder(
60 mepEntryBuilder.mepId,
61 mepEntryBuilder.deviceId,
62 mepEntryBuilder.port,
63 mepEntryBuilder.direction,
64 mepEntryBuilder.mdId,
65 mepEntryBuilder.maId)
66 .administrativeState(mepEntryBuilder.administrativeState)
67 .cciEnabled(mepEntryBuilder.cciEnabled)
68 .ccmLtmPriority(mepEntryBuilder.ccmLtmPriority));
69
70 this.macAddress = mepEntryBuilder.macAddress;
71 this.fngState = mepEntryBuilder.fngState;
72 this.highestPriorityDefect = mepEntryBuilder.highestPriorityDefect;
73 this.activeRdiCcmDefect = mepEntryBuilder.activeRdiCcmDefect;
74 this.activeMacStatusDefect = mepEntryBuilder.activeMacStatusDefect;
75 this.activeRemoteCcmDefect = mepEntryBuilder.activeRemoteCcmDefect;
76 this.activeErrorCcmDefect = mepEntryBuilder.activeErrorCcmDefect;
77 this.activeXconCcmDefect = mepEntryBuilder.activeXconCcmDefect;
78 this.lastErrorCcm = mepEntryBuilder.lastErrorCcm;
79 this.lastXconCcm = mepEntryBuilder.lastXconCcm;
80 this.ccmSequenceErrorCount = mepEntryBuilder.ccmSequenceErrorCount;
81 this.totalCcmsTransmitted = mepEntryBuilder.totalCcmsTransmitted;
82 this.loopbackAttributes = mepEntryBuilder.loopbackAttributes;
83 this.linktraceAttributes = mepEntryBuilder.linktraceAttributes;
84 this.activeRemoteMepList = mepEntryBuilder.activeRemoteMepList;
85 this.delayMeasurementList = mepEntryBuilder.delayMeasurementList;
86 this.lossMeasurementList = mepEntryBuilder.lossMeasurementList;
87 }
88
89 @Override
90 public MacAddress macAddress() {
91 return macAddress;
92 }
93
94 @Override
95 public FngState fngState() {
96 return fngState;
97 }
98
99 @Override
100 public FaultDefectType getHighestPriorityDefect() {
101 return highestPriorityDefect;
102 }
103
104 @Override
105 public boolean activeRdiCcmDefect() {
106 return activeRdiCcmDefect;
107 }
108
109 @Override
110 public boolean activeMacStatusDefect() {
111 return activeMacStatusDefect;
112 }
113
114 @Override
115 public boolean activeRemoteCcmDefect() {
116 return activeRemoteCcmDefect;
117 }
118
119 @Override
120 public boolean activeErrorCcmDefect() {
121 return activeErrorCcmDefect;
122 }
123
124 @Override
125 public boolean activeXconCcmDefect() {
126 return activeXconCcmDefect;
127 }
128
129 @Override
130 public byte[] lastErrorCcm() {
131 return lastErrorCcm;
132 }
133
134 @Override
135 public byte[] lastXconCcm() {
136 return lastXconCcm;
137 }
138
139 @Override
140 public int ccmSequenceErrorCount() {
141 return ccmSequenceErrorCount;
142 }
143
144 @Override
145 public int totalCcmsTransmitted() {
146 return totalCcmsTransmitted;
147 }
148
149 @Override
150 public MepLbEntry loopbackAttributes() {
151 return loopbackAttributes;
152 }
153
154 @Override
155 public MepLtEntry linktraceAttributes() {
156 return linktraceAttributes;
157 }
158
159 @Override
160 public List<RemoteMepEntry> activeRemoteMepList() {
161 if (activeRemoteMepList == null) {
162 return null;
163 } else {
164 return Lists.newArrayList(activeRemoteMepList);
165 }
166 }
167
168 @Override
169 public Collection<DelayMeasurementEntry> delayMeasurementList() {
170 return delayMeasurementList;
171 }
172
173 @Override
174 public Collection<LossMeasurementEntry> lossMeasurementList() {
175 return lossMeasurementList;
176 }
177
178 @Override
179 public int hashCode() {
180 final int prime = 31;
181 int result = 1;
182 result = prime * result + mepId.value();
183 return result;
184 }
185
186 @Override
187 public boolean equals(Object obj) {
188 if (this == obj) {
189 return true;
190 }
191 if (obj == null) {
192 return false;
193 }
194 if (getClass() != obj.getClass()) {
195 return false;
196 }
197 DefaultMepEntry other = (DefaultMepEntry) obj;
198 if (mepId != other.mepId) {
199 return false;
200 }
201 return true;
202 }
203
204 @Override
205 public String toString() {
206 return MoreObjects.toStringHelper(getClass()).add("id", mepId).toString();
207 }
208
209 public static MepEntryBuilder builder(
210 MepId mepId,
211 DeviceId deviceId,
212 PortNumber port,
213 MepDirection direction,
214 MdId mdName,
215 MaIdShort maName)
216 throws CfmConfigException {
217 return new DefaultMepEntryBuilder(mepId, deviceId, port, direction, mdName, maName);
218 }
219
220 public static MepEntryBuilder builder(Mep mep) throws CfmConfigException {
221 return new DefaultMepEntryBuilder(mep);
222 }
223
224 private static final class DefaultMepEntryBuilder
225 extends DefaultMep.DefaultMepBuilder implements MepEntry.MepEntryBuilder {
226 private MacAddress macAddress;
227 private FngState fngState;
228 private FaultDefectType highestPriorityDefect;
229 private boolean activeRdiCcmDefect;
230 private boolean activeMacStatusDefect;
231 private boolean activeRemoteCcmDefect;
232 private boolean activeErrorCcmDefect;
233 private boolean activeXconCcmDefect;
234 private byte[] lastErrorCcm;
235 private byte[] lastXconCcm;
236 private int ccmSequenceErrorCount;
237 private int totalCcmsTransmitted;
238 private MepLbEntry loopbackAttributes;
239 private MepLtEntry linktraceAttributes;
240 private Collection<RemoteMepEntry> activeRemoteMepList;
241 private Collection<DelayMeasurementEntry> delayMeasurementList;
242 private Collection<LossMeasurementEntry> lossMeasurementList;
243
244 private DefaultMepEntryBuilder(MepId mepId, DeviceId deviceId, PortNumber port, MepDirection direction,
245 MdId mdName, MaIdShort maName)
246 throws CfmConfigException {
247 super(mepId, deviceId, port, direction, mdName, maName);
248
249 activeRemoteMepList = new ArrayList<>();
250 delayMeasurementList = new ArrayList<>();
251 lossMeasurementList = new ArrayList<>();
252 }
253
254 private DefaultMepEntryBuilder(MepEntry mepEntry) throws CfmConfigException {
255 super(mepEntry.mepId(), mepEntry.deviceId(),
256 mepEntry.port(), mepEntry.direction(), mepEntry.mdId(), mepEntry.maId());
257 this.macAddress = mepEntry.macAddress();
258 this.fngState = mepEntry.fngState();
259 this.highestPriorityDefect = mepEntry.getHighestPriorityDefect();
260 this.activeRdiCcmDefect = mepEntry.activeRdiCcmDefect();
261 this.activeMacStatusDefect = mepEntry.activeMacStatusDefect();
262 this.activeRemoteCcmDefect = mepEntry.activeRemoteCcmDefect();
263 this.activeErrorCcmDefect = mepEntry.activeErrorCcmDefect();
264 this.activeXconCcmDefect = mepEntry.activeXconCcmDefect();
265 this.lastErrorCcm = mepEntry.lastErrorCcm();
266 this.lastXconCcm = mepEntry.lastXconCcm();
267 this.ccmSequenceErrorCount = mepEntry.ccmSequenceErrorCount();
268 this.totalCcmsTransmitted = mepEntry.totalCcmsTransmitted();
269 this.loopbackAttributes = mepEntry.loopbackAttributes();
270 this.linktraceAttributes = mepEntry.linktraceAttributes();
271 this.activeRemoteMepList = Lists.newArrayList(mepEntry.activeRemoteMepList());
272 this.delayMeasurementList = Lists.newArrayList(mepEntry.delayMeasurementList());
273 this.lossMeasurementList = Lists.newArrayList(mepEntry.lossMeasurementList());
274 }
275
276 private DefaultMepEntryBuilder(Mep mep) throws CfmConfigException {
277 super(mep.mepId(), mep.deviceId(),
278 mep.port(), mep.direction(),
279 mep.mdId(), mep.maId());
280 }
281
282 @Override
283 public MepEntryBuilder macAddress(MacAddress macAddress) {
284 this.macAddress = macAddress;
285 return this;
286 }
287
288 @Override
289 public MepEntryBuilder fngState(FngState fngState) {
290 this.fngState = fngState;
291 return this;
292 }
293
294 @Override
295 public MepEntryBuilder highestPriorityDefect(FaultDefectType highestPriorityDefect) {
296 this.highestPriorityDefect = highestPriorityDefect;
297 return this;
298 }
299
300 @Override
301 public MepEntryBuilder activeRdiCcmDefect(boolean activeRdiCcmDefect) {
302 this.activeRdiCcmDefect = activeRdiCcmDefect;
303 return this;
304 }
305
306 @Override
307 public MepEntryBuilder activeMacStatusDefect(boolean activeMacStatusDefect) {
308 this.activeMacStatusDefect = activeMacStatusDefect;
309 return this;
310 }
311
312 @Override
313 public MepEntryBuilder activeRemoteCcmDefect(boolean activeRemoteCcmDefect) {
314 this.activeRemoteCcmDefect = activeRemoteCcmDefect;
315 return this;
316 }
317
318 @Override
319 public MepEntryBuilder activeErrorCcmDefect(boolean activeErrorCcmDefect) {
320 this.activeErrorCcmDefect = activeErrorCcmDefect;
321 return this;
322 }
323
324 @Override
325 public MepEntryBuilder activeXconCcmDefect(boolean activeXconCcmDefect) {
326 this.activeXconCcmDefect = activeXconCcmDefect;
327 return this;
328 }
329
330 @Override
331 public MepEntryBuilder lastErrorCcm(byte[] lastErrorCcm) {
332 this.lastErrorCcm = lastErrorCcm;
333 return this;
334 }
335
336 @Override
337 public MepEntryBuilder lastXconCcm(byte[] lastXconCcm) {
338 this.lastXconCcm = lastXconCcm;
339 return this;
340 }
341
342 @Override
343 public MepEntryBuilder ccmSequenceErrorCount(int ccmSequenceErrorCount) {
344 this.ccmSequenceErrorCount = ccmSequenceErrorCount;
345 return this;
346 }
347
348 @Override
349 public MepEntryBuilder totalCcmsTransmitted(int totalCcmsTransmitted) {
350 this.totalCcmsTransmitted = totalCcmsTransmitted;
351 return this;
352 }
353
354 @Override
355 public MepEntryBuilder loopbackAttributes(MepLbEntry loopbackAttributes) {
356 this.loopbackAttributes = loopbackAttributes;
357 return this;
358 }
359
360 @Override
361 public MepEntryBuilder linktraceAttributes(MepLtEntry linktraceAttributes) {
362 this.linktraceAttributes = linktraceAttributes;
363 return this;
364 }
365
366 @Override
367 public MepEntryBuilder addToActiveRemoteMepList(
368 RemoteMepEntry activeRemoteMep) {
369 this.activeRemoteMepList.add(activeRemoteMep);
370 return this;
371 }
372
373 @Override
374 public MepEntryBuilder addToDelayMeasurementList(
375 DelayMeasurementEntry delayMeasurement) {
376 this.delayMeasurementList.add(delayMeasurement);
377 return this;
378 }
379
380 @Override
381 public MepEntryBuilder addToLossMeasurementList(
382 LossMeasurementEntry lossMeasurement) {
383 this.lossMeasurementList.add(lossMeasurement);
384 return this;
385 }
386
387 @Override
388 public MepEntry buildEntry() throws CfmConfigException {
389 return new DefaultMepEntry(this);
390 }
391 }
392}