Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.incubator.net.l2monitoring.soam; |
| 17 | |
| 18 | import java.time.Duration; |
| 19 | import java.time.Instant; |
| 20 | |
| 21 | import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority; |
| 22 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId; |
| 23 | import org.onosproject.incubator.net.l2monitoring.soam.StartTime.StartTimeOption; |
| 24 | import org.onosproject.incubator.net.l2monitoring.soam.StopTime.StopTimeOption; |
| 25 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.DataPattern; |
| 26 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.TestTlvPattern; |
| 27 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.Version; |
| 28 | |
| 29 | /** |
Sean Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 30 | * Abstract implementation of {@link MeasurementCreateBase}. |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 31 | */ |
| 32 | public abstract class DefaultMeasurementCreateBase |
| 33 | implements MeasurementCreateBase { |
| 34 | protected final Version version; |
| 35 | |
| 36 | protected final MepId remoteMepId; |
| 37 | protected final Duration messagePeriod; |
| 38 | protected final Priority priority; |
| 39 | protected final Short frameSize; |
| 40 | protected final DataPattern dataPattern; |
| 41 | protected final boolean testTlvIncluded; |
| 42 | protected final TestTlvPattern testTlvPattern; |
| 43 | protected final Duration measurementInterval; |
| 44 | protected final Short numberIntervalsStored; |
| 45 | protected final boolean alignMeasurementIntervals; |
| 46 | protected final Duration alignMeasurementOffset; |
| 47 | protected final SessionType sessionType; |
| 48 | protected final StartTime startTime; |
| 49 | protected final StopTime stopTime; |
| 50 | |
| 51 | protected DefaultMeasurementCreateBase(DefaultMeasCreateBaseBuilder builder) { |
| 52 | this.version = builder.version; |
| 53 | |
| 54 | this.remoteMepId = builder.remoteMepId; |
| 55 | this.messagePeriod = builder.messagePeriod; |
| 56 | this.priority = builder.priority; |
| 57 | this.frameSize = builder.frameSize; |
| 58 | this.dataPattern = builder.dataPattern; |
| 59 | this.testTlvIncluded = builder.testTlvIncluded; |
| 60 | this.testTlvPattern = builder.testTlvPattern; |
| 61 | this.measurementInterval = builder.measurementInterval; |
| 62 | this.numberIntervalsStored = builder.numberIntervalsStored; |
| 63 | this.alignMeasurementIntervals = builder.alignMeasurementIntervals; |
| 64 | this.alignMeasurementOffset = builder.alignMeasurementOffset; |
| 65 | this.sessionType = builder.sessionType; |
| 66 | this.startTime = builder.startTime; |
| 67 | this.stopTime = builder.stopTime; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public Version version() { |
| 72 | return version; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public MepId remoteMepId() { |
| 77 | return remoteMepId; |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public Duration messagePeriod() { |
| 82 | return messagePeriod; |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public Priority priority() { |
| 87 | return priority; |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public Short frameSize() { |
| 92 | return frameSize; |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public DataPattern dataPattern() { |
| 97 | return dataPattern; |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public boolean testTlvIncluded() { |
| 102 | return testTlvIncluded; |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public TestTlvPattern testTlvPattern() { |
| 107 | return testTlvPattern; |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public Duration measurementInterval() { |
| 112 | return measurementInterval; |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | public Short numberIntervalsStored() { |
| 117 | return numberIntervalsStored; |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public boolean alignMeasurementIntervals() { |
| 122 | return alignMeasurementIntervals; |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public Duration alignMeasurementOffset() { |
| 127 | return alignMeasurementOffset; |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | public SessionType sessionType() { |
| 132 | return sessionType; |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public StartTime startTime() { |
| 137 | return startTime; |
| 138 | } |
| 139 | |
| 140 | @Override |
| 141 | public StopTime stopTime() { |
| 142 | return stopTime; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Abstract Builder class for building. |
Sean Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 147 | * {@link MeasurementCreateBase}. |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 148 | */ |
| 149 | protected abstract static class DefaultMeasCreateBaseBuilder implements MeasCreateBaseBuilder { |
| 150 | protected final Version version; |
| 151 | protected final MepId remoteMepId; |
| 152 | protected final Priority priority; |
| 153 | |
| 154 | protected Duration messagePeriod; |
| 155 | protected Short frameSize; |
| 156 | protected DataPattern dataPattern; |
| 157 | protected boolean testTlvIncluded; |
| 158 | protected TestTlvPattern testTlvPattern; |
| 159 | protected Duration measurementInterval; |
| 160 | protected Short numberIntervalsStored; |
| 161 | protected boolean alignMeasurementIntervals; |
| 162 | protected Duration alignMeasurementOffset; |
| 163 | protected SessionType sessionType; |
| 164 | protected StartTime startTime; |
| 165 | protected StopTime stopTime; |
| 166 | |
| 167 | protected DefaultMeasCreateBaseBuilder(Version version, |
| 168 | MepId remoteMepId, Priority priority) |
| 169 | throws SoamConfigException { |
| 170 | super(); |
| 171 | if (remoteMepId == null) { |
| 172 | throw new SoamConfigException("RemoteMepId is null"); |
| 173 | } |
| 174 | this.remoteMepId = remoteMepId; |
| 175 | this.version = version; |
| 176 | this.priority = priority; |
| 177 | } |
| 178 | |
| 179 | @Override |
| 180 | public MeasCreateBaseBuilder messagePeriod(Duration messagePeriod) throws SoamConfigException { |
| 181 | if (messagePeriod.toMillis() < 3 || messagePeriod.toMillis() > 3600000) { |
| 182 | throw new SoamConfigException("Message Period must be between 3-3600000ms. Rejecting: " |
| 183 | + messagePeriod); |
| 184 | } |
| 185 | this.messagePeriod = messagePeriod; |
| 186 | return this; |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public MeasCreateBaseBuilder frameSize(Short frameSize) throws SoamConfigException { |
| 191 | if (frameSize < 64 || frameSize > 9600) { |
| 192 | throw new SoamConfigException("Frame Size must be between 64-9600 bytes." |
| 193 | + " Rejecting: " + frameSize); |
| 194 | } |
| 195 | this.frameSize = frameSize; |
| 196 | return this; |
| 197 | } |
| 198 | |
| 199 | @Override |
| 200 | public MeasCreateBaseBuilder dataPattern(DataPattern dataPattern) { |
| 201 | this.dataPattern = dataPattern; |
| 202 | return this; |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | public MeasCreateBaseBuilder testTlvIncluded(boolean testTlvIncluded) { |
| 207 | this.testTlvIncluded = testTlvIncluded; |
| 208 | return this; |
| 209 | } |
| 210 | |
| 211 | @Override |
| 212 | public MeasCreateBaseBuilder testTlvPattern(TestTlvPattern testTlvPattern) { |
| 213 | this.testTlvPattern = testTlvPattern; |
| 214 | return this; |
| 215 | } |
| 216 | |
| 217 | @Override |
| 218 | public MeasCreateBaseBuilder measurementInterval(Duration measurementInterval) throws SoamConfigException { |
| 219 | if (measurementInterval.toMinutes() < 1 || measurementInterval.toMinutes() > 525600) { |
| 220 | throw new SoamConfigException( |
| 221 | "Measurement Interval must be between 1..525600 minutes. Rejecting: " + measurementInterval); |
| 222 | } |
| 223 | this.measurementInterval = measurementInterval; |
| 224 | return this; |
| 225 | } |
| 226 | |
| 227 | @Override |
| 228 | public MeasCreateBaseBuilder numberIntervalsStored(Short numberIntervalsStored) |
| 229 | throws SoamConfigException { |
| 230 | if (numberIntervalsStored < 2 || numberIntervalsStored > 1000) { |
| 231 | throw new SoamConfigException( |
| 232 | "Number Intervals Stored must be between 2-1000. " |
| 233 | + "Rejecting: " + numberIntervalsStored); |
| 234 | } |
| 235 | this.numberIntervalsStored = numberIntervalsStored; |
| 236 | return this; |
| 237 | } |
| 238 | |
| 239 | @Override |
| 240 | public MeasCreateBaseBuilder alignMeasurementIntervals(boolean alignMeasurementIntervals) { |
| 241 | this.alignMeasurementIntervals = alignMeasurementIntervals; |
| 242 | return this; |
| 243 | } |
| 244 | |
| 245 | @Override |
| 246 | public MeasCreateBaseBuilder alignMeasurementOffset( |
| 247 | Duration alignMeasurementOffset) throws SoamConfigException { |
| 248 | if (alignMeasurementOffset.toMinutes() < 0 || alignMeasurementOffset.toMinutes() > 525600) { |
| 249 | throw new SoamConfigException( |
| 250 | "Align Measurement Offset must be between 0..525600 minutes. Rejecting: " + |
| 251 | alignMeasurementOffset); |
| 252 | } |
| 253 | this.alignMeasurementOffset = alignMeasurementOffset; |
| 254 | return this; |
| 255 | } |
| 256 | |
| 257 | @Override |
| 258 | public MeasCreateBaseBuilder sessionType(SessionType sessionType) { |
| 259 | this.sessionType = sessionType; |
| 260 | return this; |
| 261 | } |
| 262 | |
| 263 | @Override |
| 264 | public MeasCreateBaseBuilder startTime(StartTime startTime) throws SoamConfigException { |
| 265 | if (startTime.option() == StartTimeOption.ABSOLUTE && |
| 266 | startTime.absoluteTime().isBefore(Instant.now())) { |
| 267 | throw new SoamConfigException( |
| 268 | "Start Time must be not be in the past. Rejecting: " + startTime); |
| 269 | } |
| 270 | this.startTime = startTime; |
| 271 | return this; |
| 272 | } |
| 273 | |
| 274 | @Override |
| 275 | public MeasCreateBaseBuilder stopTime(StopTime stopTime) throws SoamConfigException { |
| 276 | if (stopTime.option() == StopTimeOption.ABSOLUTE && |
| 277 | stopTime.absoluteTime().isBefore(Instant.now())) { |
| 278 | throw new SoamConfigException( |
| 279 | "Stop Time must be not be in the past. Rejecting: " + stopTime); |
| 280 | } |
| 281 | this.stopTime = stopTime; |
| 282 | return this; |
| 283 | } |
| 284 | |
| 285 | |
| 286 | } |
| 287 | } |