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.delay; |
| 17 | |
| 18 | import static org.junit.Assert.assertEquals; |
| 19 | import static org.junit.Assert.assertTrue; |
| 20 | import static org.junit.Assert.fail; |
| 21 | |
| 22 | import java.time.Duration; |
| 23 | import java.time.OffsetDateTime; |
| 24 | |
| 25 | import org.junit.Before; |
| 26 | import org.junit.Test; |
| 27 | import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority; |
| 28 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId; |
| 29 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException; |
| 30 | import org.onosproject.incubator.net.l2monitoring.soam.MeasurementCreateBase.SessionType; |
| 31 | import org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException; |
| 32 | import org.onosproject.incubator.net.l2monitoring.soam.SoamId; |
| 33 | import org.onosproject.incubator.net.l2monitoring.soam.StartTime; |
| 34 | import org.onosproject.incubator.net.l2monitoring.soam.StartTime.StartTimeOption; |
| 35 | import org.onosproject.incubator.net.l2monitoring.soam.StopTime; |
| 36 | import org.onosproject.incubator.net.l2monitoring.soam.StopTime.StopTimeOption; |
| 37 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementCreate.DefaultDmCreateBuilder; |
| 38 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.DataPattern; |
| 39 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.DmType; |
| 40 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.MeasurementOption; |
| 41 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.TestTlvPattern; |
| 42 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.Version; |
| 43 | |
| 44 | public class DelayMeasurementCreateTest { |
| 45 | |
| 46 | DelayMeasurementCreate dm1; |
| 47 | |
| 48 | @Before |
| 49 | public void setUp() throws Exception, CfmConfigException, SoamConfigException { |
| 50 | |
| 51 | DelayMeasurementThreshold dmT1 = DefaultDelayMeasurementThreshold |
| 52 | .builder(SoamId.valueOf(1)) |
| 53 | .averageFrameDelayBackward(Duration.ofMillis(123)) |
| 54 | .averageInterFrameDelayVariationForward(Duration.ofMillis(321)) |
| 55 | .build(); |
| 56 | |
| 57 | DelayMeasurementThreshold dmT2 = DefaultDelayMeasurementThreshold |
| 58 | .builder(SoamId.valueOf(2)) |
| 59 | .averageFrameDelayBackward(Duration.ofMillis(456)) |
| 60 | .averageInterFrameDelayVariationForward(Duration.ofMillis(654)) |
| 61 | .build(); |
| 62 | |
| 63 | try { |
| 64 | DefaultDmCreateBuilder builder = (DefaultDmCreateBuilder) |
| 65 | DefaultDelayMeasurementCreate.builder( |
| 66 | DmType.DMDMM, Version.Y17312011, MepId.valueOf((short) 12), Priority.PRIO6) |
| 67 | .addToMeasurementsEnabled(MeasurementOption.FRAME_DELAY_FORWARD_MIN) |
| 68 | .addToMeasurementsEnabled(MeasurementOption.FRAME_DELAY_FORWARD_AVERAGE) |
| 69 | .addToMeasurementsEnabled(MeasurementOption.FRAME_DELAY_FORWARD_MAX) |
| 70 | .addToMeasurementsEnabled(MeasurementOption.FRAME_DELAY_FORWARD_BINS) |
| 71 | .binsPerFdInterval((short) 8) |
| 72 | .binsPerIfdvInterval((short) 9) |
| 73 | .ifdvSelectionOffset((short) 10) |
| 74 | .binsPerFdrInterval((short) 12) |
| 75 | .addToThresholds(dmT1) |
| 76 | .addToThresholds(dmT2) |
| 77 | .messagePeriod(Duration.ofMillis(100L)) |
| 78 | .frameSize((short) 64) |
| 79 | .dataPattern(DataPattern.ONES) |
| 80 | .testTlvIncluded(true) |
| 81 | .testTlvPattern(TestTlvPattern.NULL_SIGNAL_WITHOUT_CRC_32) |
| 82 | .measurementInterval(Duration.ofMinutes(15)) |
| 83 | .numberIntervalsStored((short) 32) |
| 84 | .alignMeasurementIntervals(true) |
| 85 | .alignMeasurementOffset(Duration.ofMinutes(4)) |
| 86 | .sessionType(SessionType.ONDEMAND) |
| 87 | .startTime(StartTime.relative(Duration.ofMinutes(7))) |
| 88 | .stopTime(StopTime.relative(Duration.ofMinutes(8))); |
| 89 | dm1 = builder.build(); |
| 90 | } catch (SoamConfigException e) { |
| 91 | throw new Exception(e); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | @Test |
| 96 | public void testInvalidMessagePeriod() throws CfmConfigException { |
| 97 | try { |
| 98 | DefaultDelayMeasurementCreate.builder( |
| 99 | DmType.DMDMM, Version.Y17312011, MepId.valueOf((short) 20), |
| 100 | Priority.PRIO6) |
| 101 | .messagePeriod(Duration.ofMinutes(61)); |
| 102 | fail("Expected an exception to be thrown for invalid messagePeriod: " + 3660000); |
| 103 | } catch (SoamConfigException e) { |
| 104 | assertEquals(SoamConfigException.class, e.getClass()); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | @Test |
| 109 | public void testInvalidFrameSize() throws CfmConfigException { |
| 110 | try { |
| 111 | DefaultDelayMeasurementCreate.builder( |
| 112 | DmType.DMDMM, Version.Y17312011, MepId.valueOf((short) 20), |
| 113 | Priority.PRIO6) |
| 114 | .frameSize((short) 11111); |
| 115 | fail("Expected an exception to be thrown for frame size: " + 11111); |
| 116 | } catch (SoamConfigException e) { |
| 117 | assertEquals(SoamConfigException.class, e.getClass()); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | @Test |
| 122 | public void testInvalidMeasurementInterval() throws CfmConfigException { |
| 123 | try { |
| 124 | DefaultDelayMeasurementCreate.builder( |
| 125 | DmType.DMDMM, Version.Y17312011, MepId.valueOf((short) 20), |
| 126 | Priority.PRIO6) |
| 127 | .measurementInterval(Duration.ofMinutes(0)); |
| 128 | fail("Expected an exception to be thrown for invalid measurementInterval: " + 0); |
| 129 | } catch (SoamConfigException e) { |
| 130 | assertEquals(SoamConfigException.class, e.getClass()); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | @Test |
| 135 | public void testInvalidNumberIntervalsStored() throws CfmConfigException { |
| 136 | try { |
| 137 | DefaultDelayMeasurementCreate.builder( |
| 138 | DmType.DMDMM, Version.Y17312011, MepId.valueOf((short) 20), |
| 139 | Priority.PRIO6) |
| 140 | .numberIntervalsStored((short) 1001); |
| 141 | fail("Expected an exception to be thrown for number intervals stored: " + 1001); |
| 142 | } catch (SoamConfigException e) { |
| 143 | assertEquals(SoamConfigException.class, e.getClass()); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | @Test |
| 148 | public void testInvalidAlignMeasurementOffset() throws CfmConfigException { |
| 149 | try { |
| 150 | DefaultDelayMeasurementCreate.builder( |
| 151 | DmType.DMDMM, Version.Y17312011, MepId.valueOf((short) 20), |
| 152 | Priority.PRIO6) |
| 153 | .alignMeasurementOffset(Duration.ofMinutes(525601)); |
| 154 | fail("Expected an exception to be thrown for align Measurement Offset: " + 525601); |
| 155 | } catch (SoamConfigException e) { |
| 156 | assertEquals(SoamConfigException.class, e.getClass()); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | @Test |
| 161 | public void testInvalidStartTime() throws CfmConfigException { |
| 162 | OffsetDateTime oneMinuteAgo = OffsetDateTime.now().minusMinutes(1); |
| 163 | try { |
| 164 | DefaultDelayMeasurementCreate.builder( |
| 165 | DmType.DMDMM, Version.Y17312011, MepId.valueOf((short) 20), |
| 166 | Priority.PRIO6) |
| 167 | .startTime(StartTime.absolute(oneMinuteAgo.toInstant())); |
| 168 | fail("Expected an exception to be thrown for align Start Time: " + oneMinuteAgo); |
| 169 | } catch (SoamConfigException e) { |
| 170 | assertEquals(SoamConfigException.class, e.getClass()); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | @Test |
| 175 | public void testInvalidStopTime() throws CfmConfigException { |
| 176 | OffsetDateTime oneMinuteAgo = OffsetDateTime.now().minusMinutes(1); |
| 177 | try { |
| 178 | DefaultDelayMeasurementCreate.builder( |
| 179 | DmType.DMDMM, Version.Y17312011, MepId.valueOf((short) 20), |
| 180 | Priority.PRIO6) |
| 181 | .stopTime(StopTime.absolute(oneMinuteAgo.toInstant())); |
| 182 | fail("Expected an exception to be thrown for align Stop Time: " + oneMinuteAgo); |
| 183 | } catch (SoamConfigException e) { |
| 184 | assertEquals(SoamConfigException.class, e.getClass()); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | @Test |
| 189 | public void testDmCfgType() { |
| 190 | assertEquals(DmType.DMDMM, dm1.dmCfgType()); |
| 191 | } |
| 192 | |
| 193 | @Test |
| 194 | public void testVersion() { |
| 195 | assertEquals(Version.Y17312011, dm1.version()); |
| 196 | } |
| 197 | |
| 198 | @Test |
| 199 | public void testRemoteMepId() { |
| 200 | assertEquals(12, dm1.remoteMepId().value()); |
| 201 | } |
| 202 | |
| 203 | @Test |
| 204 | public void testMeasurementsEnabled() { |
| 205 | assertEquals(4, dm1.measurementsEnabled().size()); |
| 206 | } |
| 207 | |
| 208 | @Test |
| 209 | public void testMessagePeriod() { |
| 210 | assertEquals(100, dm1.messagePeriod().toMillis()); |
| 211 | } |
| 212 | |
| 213 | @Test |
| 214 | public void testPriority() { |
| 215 | assertEquals(Priority.PRIO6.name(), dm1.priority().name()); |
| 216 | } |
| 217 | |
| 218 | @Test |
| 219 | public void testFrameSize() { |
| 220 | assertEquals(64, dm1.frameSize().shortValue()); |
| 221 | } |
| 222 | |
| 223 | @Test |
| 224 | public void testDataPattern() { |
| 225 | assertEquals(DataPattern.ONES, dm1.dataPattern()); |
| 226 | } |
| 227 | |
| 228 | @Test |
| 229 | public void testTestTlvIncluded() { |
| 230 | assertTrue(dm1.testTlvIncluded()); |
| 231 | } |
| 232 | |
| 233 | @Test |
| 234 | public void testTestTlvPattern() { |
| 235 | assertEquals(TestTlvPattern.NULL_SIGNAL_WITHOUT_CRC_32, dm1.testTlvPattern()); |
| 236 | } |
| 237 | |
| 238 | @Test |
| 239 | public void testMeasurementInterval() { |
| 240 | assertEquals(15, dm1.measurementInterval().toMinutes()); |
| 241 | } |
| 242 | |
| 243 | @Test |
| 244 | public void testNumberIntervalsStored() { |
| 245 | assertEquals(32, dm1.numberIntervalsStored().shortValue()); |
| 246 | } |
| 247 | |
| 248 | @Test |
| 249 | public void testAlignMeasurementIntervals() { |
| 250 | assertTrue(dm1.alignMeasurementIntervals()); |
| 251 | } |
| 252 | |
| 253 | @Test |
| 254 | public void testAlignMeasurementOffset() { |
| 255 | assertEquals(4, dm1.alignMeasurementOffset().toMinutes()); |
| 256 | } |
| 257 | |
| 258 | @Test |
| 259 | public void testBinsPerFdInterval() { |
| 260 | assertEquals(8, dm1.binsPerFdInterval().shortValue()); |
| 261 | } |
| 262 | |
| 263 | @Test |
| 264 | public void testBinsPerIfdvInterval() { |
| 265 | assertEquals(9, dm1.binsPerIfdvInterval().shortValue()); |
| 266 | } |
| 267 | |
| 268 | @Test |
| 269 | public void testIfdvSelectionOffset() { |
| 270 | assertEquals(10, dm1.ifdvSelectionOffset().shortValue()); |
| 271 | } |
| 272 | |
| 273 | @Test |
| 274 | public void testBinsPerFdrInterval() { |
| 275 | assertEquals(12, dm1.binsPerFdrInterval().shortValue()); |
| 276 | } |
| 277 | |
| 278 | @Test |
| 279 | public void testSessionType() { |
| 280 | assertEquals(SessionType.ONDEMAND, dm1.sessionType()); |
| 281 | } |
| 282 | |
| 283 | @Test |
| 284 | public void testStartTime() { |
| 285 | assertEquals(StartTimeOption.RELATIVE, dm1.startTime().option()); |
| 286 | assertEquals(7, dm1.startTime().relativeTime().toMinutes()); |
| 287 | } |
| 288 | |
| 289 | @Test |
| 290 | public void testStopTime() { |
| 291 | assertEquals(StopTimeOption.RELATIVE, dm1.stopTime().option()); |
| 292 | assertEquals(8, dm1.stopTime().relativeTime().toMinutes()); |
| 293 | } |
| 294 | |
| 295 | @Test |
| 296 | public void testThresholds() { |
| 297 | DelayMeasurementThreshold[] thresholds = |
| 298 | dm1.thresholds().toArray( |
| 299 | new DelayMeasurementThreshold[dm1.thresholds().size()]); |
| 300 | |
| 301 | assertEquals(1, thresholds[0].threshId().id().intValue()); |
| 302 | assertEquals(123, thresholds[0].averageFrameDelayBackward().toMillis()); |
| 303 | } |
| 304 | } |