blob: c53c63bc74c20cf5e6a7eb2ff375fdd027205653 [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.delay;
17
18import java.time.Duration;
19import java.util.ArrayList;
20import java.util.Collection;
21
22import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority;
23import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
24import org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException;
25import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
26
27import com.google.common.collect.Lists;
28
29/**
30 * The default implementation of {@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry}.
31 */
32public final class DefaultDelayMeasurementEntry
33 extends DefaultDelayMeasurementCreate implements DelayMeasurementEntry {
34
35 private final SoamId dmId;
36 private final SessionStatus sessionStatus;
37 private final Duration frameDelayTwoWay;
38 private final Duration frameDelayForward;
39 private final Duration frameDelayBackward;
40 private final Duration interFrameDelayVariationTwoWay;
41 private final Duration interFrameDelayVariationForward;
42 private final Duration interFrameDelayVariationBackward;
43 private final DelayMeasurementStatCurrent currentResult;
44 private final Collection<DelayMeasurementStatHistory> historicalResults;
45
46 private DefaultDelayMeasurementEntry(DefaultDmEntryBuilder builder) {
47 super(builder);
48 this.dmId = builder.dmId;
49 this.currentResult = builder.currentResult;
50 this.historicalResults = builder.historicalResults;
51
52 this.sessionStatus = builder.sessionStatus;
53 this.frameDelayTwoWay = builder.frameDelayTwoWay;
54 this.frameDelayForward = builder.frameDelayForward;
55 this.frameDelayBackward = builder.frameDelayBackward;
56 this.interFrameDelayVariationTwoWay = builder.interFrameDelayVariationTwoWay;
57 this.interFrameDelayVariationForward = builder.interFrameDelayVariationForward;
58 this.interFrameDelayVariationBackward = builder.interFrameDelayVariationBackward;
59 }
60
61 @Override
62 public SoamId dmId() {
63 return dmId;
64 }
65
66 @Override
67 public SessionStatus sessionStatus() {
68 return sessionStatus;
69 }
70
71 @Override
72 public Duration frameDelayTwoWay() {
73 return frameDelayTwoWay;
74 }
75
76 @Override
77 public Duration frameDelayForward() {
78 return frameDelayForward;
79 }
80
81 @Override
82 public Duration frameDelayBackward() {
83 return frameDelayBackward;
84 }
85
86 @Override
87 public Duration interFrameDelayVariationTwoWay() {
88 return interFrameDelayVariationTwoWay;
89 }
90
91 @Override
92 public Duration interFrameDelayVariationForward() {
93 return interFrameDelayVariationForward;
94 }
95
96 @Override
97 public Duration interFrameDelayVariationBackward() {
98 return interFrameDelayVariationBackward;
99 }
100
101 @Override
102 public DelayMeasurementStatCurrent currentResult() {
103 return currentResult;
104 }
105
106 @Override
107 public Collection<DelayMeasurementStatHistory> historicalResults() {
108 if (historicalResults != null) {
109 return Lists.newArrayList(historicalResults);
110 }
111 return null;
112 }
113
114 public static DmEntryBuilder builder(SoamId dmId, DmType dmCfgType,
115 Version version, MepId remoteMepId, Priority priority)
116 throws SoamConfigException {
117 return new DefaultDmEntryBuilder(dmId, dmCfgType, version,
118 remoteMepId, priority);
119 }
120
121 /**
122 * Builder for {@link org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry}.
123 */
124 private static final class DefaultDmEntryBuilder extends DefaultDmCreateBuilder
125 implements DmEntryBuilder {
126 private final SoamId dmId;
127 private SessionStatus sessionStatus;
128 private Duration frameDelayTwoWay;
129 private Duration frameDelayForward;
130 private Duration frameDelayBackward;
131 private Duration interFrameDelayVariationTwoWay;
132 private Duration interFrameDelayVariationForward;
133 private Duration interFrameDelayVariationBackward;
134 private DelayMeasurementStatCurrent currentResult;
135 private Collection<DelayMeasurementStatHistory> historicalResults;
136
137 private DefaultDmEntryBuilder(SoamId dmId, DmType dmCfgType,
138 Version version, MepId remoteMepId, Priority priority)
139 throws SoamConfigException {
140 super(dmCfgType, version, remoteMepId, priority);
141 if (dmId == null) {
142 throw new SoamConfigException("DmId is null");
143 }
144 this.dmId = dmId;
145 historicalResults = new ArrayList<>();
146 }
147
148 @Override
149 public DmEntryBuilder sessionStatus(SessionStatus sessionStatus) {
150 this.sessionStatus = sessionStatus;
151 return this;
152 }
153
154 @Override
155 public DmEntryBuilder frameDelayTwoWay(Duration frameDelayTwoWay) {
156 this.frameDelayTwoWay = frameDelayTwoWay;
157 return this;
158 }
159
160 @Override
161 public DmEntryBuilder frameDelayForward(Duration frameDelayForward) {
162 this.frameDelayForward = frameDelayForward;
163 return this;
164 }
165
166 @Override
167 public DmEntryBuilder frameDelayBackward(Duration frameDelayBackward) {
168 this.frameDelayBackward = frameDelayBackward;
169 return this;
170 }
171
172 @Override
173 public DmEntryBuilder interFrameDelayVariationTwoWay(
174 Duration interFrameDelayVariationTwoWay) {
175 this.interFrameDelayVariationTwoWay = interFrameDelayVariationTwoWay;
176 return this;
177 }
178
179 @Override
180 public DmEntryBuilder interFrameDelayVariationForward(
181 Duration interFrameDelayVariationForward) {
182 this.interFrameDelayVariationForward = interFrameDelayVariationForward;
183 return this;
184 }
185
186 @Override
187 public DmEntryBuilder interFrameDelayVariationBackward(
188 Duration interFrameDelayVariationBackward) {
189 this.interFrameDelayVariationBackward = interFrameDelayVariationBackward;
190 return this;
191 }
192
193 @Override
194 public DmEntryBuilder currentResult(DelayMeasurementStatCurrent currentResult) {
195 this.currentResult = currentResult;
196 return this;
197 }
198
199 @Override
200 public DmEntryBuilder addToHistoricalResults(
201 DelayMeasurementStatHistory historicalResult) {
202 this.historicalResults.add(historicalResult);
203 return this;
204 }
205
206 @Override
207 public DelayMeasurementEntry build() {
208 return new DefaultDelayMeasurementEntry(this);
209 }
210 }
211}