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.drivers.microsemi; |
| 17 | |
| 18 | import static org.junit.Assert.assertEquals; |
| 19 | import static org.junit.Assert.assertNotNull; |
| 20 | import static org.junit.Assert.assertTrue; |
| 21 | import static org.junit.Assert.fail; |
| 22 | |
| 23 | import java.time.Duration; |
| 24 | import java.util.ArrayList; |
| 25 | import java.util.BitSet; |
| 26 | import java.util.Collection; |
| 27 | |
| 28 | import org.junit.Before; |
| 29 | import org.junit.Test; |
| 30 | import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority; |
| 31 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdCharStr; |
| 32 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort; |
| 33 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId; |
| 34 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdCharStr; |
| 35 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId; |
| 36 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException; |
| 37 | import org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException; |
| 38 | import org.onosproject.incubator.net.l2monitoring.soam.SoamId; |
| 39 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementCreate; |
| 40 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.DmCreateBuilder; |
| 41 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.DmType; |
| 42 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.MeasurementOption; |
| 43 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.Version; |
| 44 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry; |
| 45 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry.SessionStatus; |
| 46 | |
| 47 | public class EA1000SoamDmProgrammableTest { |
| 48 | |
| 49 | EA1000SoamDmProgrammable dmProgrammable; |
| 50 | MdId mdId1 = MdIdCharStr.asMdId("md-1"); |
| 51 | MaIdShort maId11 = MaIdCharStr.asMaId("ma-1-1"); |
| 52 | MepId mep111 = MepId.valueOf((short) 1); |
| 53 | |
| 54 | @Before |
| 55 | public void setUp() throws Exception { |
| 56 | dmProgrammable = new EA1000SoamDmProgrammable(); |
| 57 | dmProgrammable.setHandler(new MockEa1000DriverHandler()); |
| 58 | assertNotNull(dmProgrammable.handler().data().deviceId()); |
| 59 | } |
| 60 | |
| 61 | //TODO Implement all these tests |
| 62 | // @Test |
| 63 | // public void testEA1000SoamDmProgrammable() { |
| 64 | // fail("Not yet implemented"); |
| 65 | // } |
| 66 | // |
| 67 | // @Test |
| 68 | // public void testGetAllDms() { |
| 69 | // fail("Not yet implemented"); |
| 70 | // } |
| 71 | |
| 72 | /** |
| 73 | * From SAMPLE_MSEACFM_DELAY_MEASUREMENT_FULL_REPLY. |
| 74 | * @throws CfmConfigException |
| 75 | * @throws SoamConfigException |
| 76 | */ |
| 77 | @Test |
| 78 | public void testGetDm() throws CfmConfigException, SoamConfigException { |
| 79 | DelayMeasurementEntry dmEntry = |
| 80 | dmProgrammable.getDm(mdId1, maId11, mep111, SoamId.valueOf(1)); |
| 81 | assertEquals(1, dmEntry.dmId().id().intValue()); |
| 82 | assertEquals(2, dmEntry.measurementsEnabled().size()); |
| 83 | assertEquals(SessionStatus.ACTIVE.name(), dmEntry.sessionStatus().name()); |
| 84 | assertEquals(100, dmEntry.frameDelayTwoWay().toNanos() / 1000); |
| 85 | assertEquals(101, dmEntry.interFrameDelayVariationTwoWay().toNanos() / 1000); |
| 86 | } |
| 87 | |
| 88 | @Test |
| 89 | public void testCreateDm() throws CfmConfigException, SoamConfigException { |
| 90 | DmCreateBuilder dmBuilder = (DmCreateBuilder) DefaultDelayMeasurementCreate |
| 91 | .builder(DmType.DMDMM, Version.Y17312011, |
| 92 | MepId.valueOf((short) 10), Priority.PRIO3) |
| 93 | .frameSize((short) 1200); |
| 94 | |
| 95 | dmProgrammable.createDm(mdId1, maId11, mep111, dmBuilder.build()); |
| 96 | } |
| 97 | |
| 98 | @Test |
| 99 | public void testCreateDmWrongMsgPeriod() |
| 100 | throws CfmConfigException, SoamConfigException { |
| 101 | DmCreateBuilder dmBuilder = (DmCreateBuilder) DefaultDelayMeasurementCreate |
| 102 | .builder(DmType.DMDMM, Version.Y17312011, |
| 103 | MepId.valueOf((short) 10), Priority.PRIO3) |
| 104 | .messagePeriod(Duration.ofMillis(1234)); |
| 105 | |
| 106 | try { |
| 107 | dmProgrammable.createDm(mdId1, maId11, mep111, dmBuilder.build()); |
| 108 | fail("Expecting to get an exception"); |
| 109 | } catch (SoamConfigException e) { |
| 110 | assertTrue(e.getMessage() |
| 111 | .contains("EA1000 supports only Message Periods")); |
| 112 | } |
| 113 | |
| 114 | } |
| 115 | |
| 116 | // @Test |
| 117 | // public void testGetDmCurrentStat() { |
| 118 | // fail("Not yet implemented"); |
| 119 | // } |
| 120 | // |
| 121 | // @Test |
| 122 | // public void testGetDmHistoricalStats() { |
| 123 | // fail("Not yet implemented"); |
| 124 | // } |
| 125 | // |
| 126 | // @Test |
| 127 | // public void testAbortDmMdIdMaIdShortMepIdSoamId() { |
| 128 | // fail("Not yet implemented"); |
| 129 | // } |
| 130 | // |
| 131 | // @Test |
| 132 | // public void testBuildApiDmFromYangDm() { |
| 133 | // fail("Not yet implemented"); |
| 134 | // } |
| 135 | // |
| 136 | // @Test |
| 137 | // public void testAbortDmMdIdMaIdShortMepId() { |
| 138 | // fail("Not yet implemented"); |
| 139 | // } |
| 140 | // |
| 141 | // @Test |
| 142 | // public void testClearDelayHistoryStatsMdIdMaIdShortMepId() { |
| 143 | // fail("Not yet implemented"); |
| 144 | // } |
| 145 | // |
| 146 | // @Test |
| 147 | // public void testClearDelayHistoryStatsMdIdMaIdShortMepIdSoamId() { |
| 148 | // fail("Not yet implemented"); |
| 149 | // } |
| 150 | // |
| 151 | // @Test |
| 152 | // public void testGetAllLms() { |
| 153 | // fail("Not yet implemented"); |
| 154 | // } |
| 155 | // |
| 156 | // @Test |
| 157 | // public void testGetLm() { |
| 158 | // fail("Not yet implemented"); |
| 159 | // } |
| 160 | // |
| 161 | // @Test |
| 162 | // public void testGetLmCurrentStat() { |
| 163 | // fail("Not yet implemented"); |
| 164 | // } |
| 165 | // |
| 166 | // @Test |
| 167 | // public void testGetLmHistoricalStats() { |
| 168 | // fail("Not yet implemented"); |
| 169 | // } |
| 170 | // |
| 171 | // @Test |
| 172 | // public void testCreateLm() { |
| 173 | // fail("Not yet implemented"); |
| 174 | // } |
| 175 | // |
| 176 | // @Test |
| 177 | // public void testAbortLmMdIdMaIdShortMepId() { |
| 178 | // fail("Not yet implemented"); |
| 179 | // } |
| 180 | // |
| 181 | // @Test |
| 182 | // public void testAbortLmMdIdMaIdShortMepIdSoamId() { |
| 183 | // fail("Not yet implemented"); |
| 184 | // } |
| 185 | // |
| 186 | // @Test |
| 187 | // public void testClearLossHistoryStatsMdIdMaIdShortMepId() { |
| 188 | // fail("Not yet implemented"); |
| 189 | // } |
| 190 | // |
| 191 | // @Test |
| 192 | // public void testClearLossHistoryStatsMdIdMaIdShortMepIdSoamId() { |
| 193 | // fail("Not yet implemented"); |
| 194 | // } |
| 195 | |
| 196 | @Test |
| 197 | public void testCreateTestSignal() { |
| 198 | try { |
| 199 | dmProgrammable.createTestSignal(mdId1, maId11, mep111, null); |
| 200 | fail("Expected an exception"); |
| 201 | } catch (UnsupportedOperationException e) { |
| 202 | assertEquals("Not supported by EA1000", e.getMessage()); |
| 203 | } catch (CfmConfigException e) { |
| 204 | fail("CfmConfigException was not expected"); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | @Test |
| 209 | public void testAbortTestSignal() { |
| 210 | try { |
| 211 | dmProgrammable.abortTestSignal(mdId1, maId11, mep111); |
| 212 | fail("Expected an exception"); |
| 213 | } catch (UnsupportedOperationException e) { |
| 214 | assertEquals("Not supported by EA1000", e.getMessage()); |
| 215 | } catch (CfmConfigException e) { |
| 216 | fail("CfmConfigException was not expected"); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | @Test |
| 221 | public void testMeasurementEnableCollectionOfMeasurementOption() { |
| 222 | BitSet meBs = BitSet.valueOf(new byte[]{0x05}); |
| 223 | Collection<MeasurementOption> moSet = |
| 224 | EA1000SoamDmProgrammable.getMeasurementOptions(meBs); |
| 225 | assertTrue(moSet.contains(MeasurementOption.SOAM_PDUS_RECEIVED)); |
| 226 | assertTrue(moSet.contains(MeasurementOption.FRAME_DELAY_TWO_WAY_MIN)); |
| 227 | } |
| 228 | |
| 229 | @Test |
| 230 | public void testMeasurementEnableBitSetEmpty() { |
| 231 | Collection<MeasurementOption> moSet = new ArrayList<>(); |
| 232 | try { |
| 233 | BitSet bitSet = EA1000SoamDmProgrammable.getMeasurementEnabledSet(moSet); |
| 234 | assertEquals("{}", bitSet.toString()); |
| 235 | } catch (SoamConfigException e) { |
| 236 | fail("Was not expecting exception here"); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | @Test |
| 241 | public void testMeasurementEnableBitSetInvalid() { |
| 242 | Collection<MeasurementOption> moSet = new ArrayList<>(); |
| 243 | moSet.add(MeasurementOption.FRAME_DELAY_BACKWARD_BINS); |
| 244 | moSet.add(MeasurementOption.FRAME_DELAY_RANGE_BACKWARD_AVERAGE); |
| 245 | try { |
| 246 | EA1000SoamDmProgrammable.getMeasurementEnabledSet(moSet); |
| 247 | fail("Was expecting an exception"); |
| 248 | } catch (SoamConfigException e) { |
| 249 | assertTrue(e.getMessage() |
| 250 | .contains("Measurement Option is not supported on EA1000")); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | @Test |
| 255 | public void testMeasurementEnableBitSet2Good() { |
| 256 | Collection<MeasurementOption> moSet = new ArrayList<>(); |
| 257 | moSet.add(MeasurementOption.FRAME_DELAY_TWO_WAY_BINS); |
| 258 | moSet.add(MeasurementOption.FRAME_DELAY_TWO_WAY_AVERAGE); |
| 259 | try { |
| 260 | BitSet bitSet = EA1000SoamDmProgrammable.getMeasurementEnabledSet(moSet); |
| 261 | assertEquals("{1, 4}", bitSet.toString()); |
| 262 | } catch (SoamConfigException e) { |
| 263 | fail("Was not expecting exception here"); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | } |