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