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.loss; |
| 17 | |
| 18 | import static org.junit.Assert.assertEquals; |
| 19 | |
| 20 | import java.util.ArrayList; |
| 21 | |
| 22 | import org.junit.Before; |
| 23 | import org.junit.Test; |
| 24 | import org.onosproject.incubator.net.l2monitoring.soam.MilliPct; |
| 25 | import org.onosproject.incubator.net.l2monitoring.soam.SoamId; |
| 26 | import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementThreshold.ThresholdOption; |
| 27 | |
| 28 | public class LossMeasurementThresholdOptionTest { |
| 29 | |
| 30 | LossMeasurementThreshold lmt1; |
| 31 | |
| 32 | @Before |
| 33 | public void setUp() throws Exception { |
| 34 | lmt1 = DefaultLmThreshold |
| 35 | .builder(SoamId.valueOf(4)) |
| 36 | .addToThreshold(ThresholdOption.BACKWARD_CONSECUTIVE_HIGH_LOSS) |
| 37 | .addToThreshold(ThresholdOption.MAX_FLR_BACKWARD) |
| 38 | .averageFlrBackward(MilliPct.ofMilliPct(301)) |
| 39 | .averageFlrForward(MilliPct.ofMilliPct(302)) |
| 40 | .backwardAvailableRatio(MilliPct.ofMilliPct(303)) |
| 41 | .backwardConsecutiveHighLoss(123451L) |
| 42 | .backwardHighLoss(123452L) |
| 43 | .backwardUnavailableCount(123453L) |
| 44 | .forwardAvailableRatio(MilliPct.ofMilliPct(304)) |
| 45 | .forwardConsecutiveHighLoss(123454L) |
| 46 | .forwardHighLoss(123455L) |
| 47 | .forwardUnavailableCount(123456L) |
| 48 | .maxFlrBackward(MilliPct.ofMilliPct(305)) |
| 49 | .maxFlrForward(MilliPct.ofMilliPct(306)) |
| 50 | .measuredFlrBackward(MilliPct.ofMilliPct(307)) |
| 51 | .measuredFlrForward(MilliPct.ofMilliPct(308)) |
| 52 | .build(); |
| 53 | } |
| 54 | |
| 55 | @Test |
| 56 | public void testThresholdId() { |
| 57 | assertEquals(4, lmt1.thresholdId().id().intValue()); |
| 58 | } |
| 59 | |
| 60 | @Test |
| 61 | public void testThreshold() { |
| 62 | assertEquals(2, lmt1.thresholds().size()); |
| 63 | ArrayList<ThresholdOption> list = new ArrayList<>(); |
| 64 | lmt1.thresholds().forEach(list::add); |
| 65 | assertEquals(ThresholdOption.BACKWARD_CONSECUTIVE_HIGH_LOSS, list.get(0)); |
| 66 | assertEquals(ThresholdOption.MAX_FLR_BACKWARD, list.get(1)); |
| 67 | } |
| 68 | |
| 69 | @Test |
| 70 | public void testMeasuredFlrForward() { |
| 71 | assertEquals(308, lmt1.measuredFlrForward().intValue()); |
| 72 | } |
| 73 | |
| 74 | @Test |
| 75 | public void testMaxFlrForward() { |
| 76 | assertEquals(306, lmt1.maxFlrForward().intValue()); |
| 77 | } |
| 78 | |
| 79 | @Test |
| 80 | public void testAverageFlrForward() { |
| 81 | assertEquals(302, lmt1.averageFlrForward().intValue()); |
| 82 | } |
| 83 | |
| 84 | @Test |
| 85 | public void testMeasuredFlrBackward() { |
| 86 | assertEquals(307, lmt1.measuredFlrBackward().intValue()); |
| 87 | } |
| 88 | |
| 89 | @Test |
| 90 | public void testMaxFlrBackward() { |
| 91 | assertEquals(305, lmt1.maxFlrBackward().intValue()); |
| 92 | } |
| 93 | |
| 94 | @Test |
| 95 | public void testAverageFlrBackward() { |
| 96 | assertEquals(301, lmt1.averageFlrBackward().intValue()); |
| 97 | } |
| 98 | |
| 99 | @Test |
| 100 | public void testForwardHighLoss() { |
| 101 | assertEquals(123455L, lmt1.forwardHighLoss().longValue()); |
| 102 | } |
| 103 | |
| 104 | @Test |
| 105 | public void testForwardConsecutiveHighLoss() { |
| 106 | assertEquals(123454L, lmt1.forwardConsecutiveHighLoss().longValue()); |
| 107 | } |
| 108 | |
| 109 | @Test |
| 110 | public void testBackwardHighLoss() { |
| 111 | assertEquals(123452L, lmt1.backwardHighLoss().longValue()); |
| 112 | } |
| 113 | |
| 114 | @Test |
| 115 | public void testBackwardConsecutiveHighLoss() { |
| 116 | assertEquals(123451L, lmt1.backwardConsecutiveHighLoss().longValue()); |
| 117 | } |
| 118 | |
| 119 | @Test |
| 120 | public void testForwardUnavailableCount() { |
| 121 | assertEquals(123456L, lmt1.forwardUnavailableCount().longValue()); |
| 122 | } |
| 123 | |
| 124 | @Test |
| 125 | public void testForwardAvailableRatio() { |
| 126 | assertEquals(304, lmt1.forwardAvailableRatio().intValue()); |
| 127 | } |
| 128 | |
| 129 | @Test |
| 130 | public void testBackwardUnavailableCount() { |
| 131 | assertEquals(123453L, lmt1.backwardUnavailableCount().longValue()); |
| 132 | } |
| 133 | |
| 134 | @Test |
| 135 | public void testBackwardAvailableRatio() { |
| 136 | assertEquals(303, lmt1.backwardAvailableRatio().intValue()); |
| 137 | } |
| 138 | } |