blob: 1f8763424e946e6f9e756aefb86c7167016ce43d [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 junit.framework.TestCase.fail;
19import static org.junit.Assert.assertEquals;
20import static org.junit.Assert.assertFalse;
21import static org.junit.Assert.assertNotNull;
22import static org.junit.Assert.assertTrue;
Sean Condon96b896d2017-12-11 12:44:29 -080023import static org.onosproject.drivers.microsemi.yang.utils.MdNameUtil.getYangMdNameFromApiMdId;
Sean Condon0e89bda2017-03-21 14:23:19 +000024
25import org.junit.Before;
26import org.junit.Ignore;
27import org.junit.Test;
28import org.onosproject.drivers.microsemi.yang.utils.MaNameUtil;
Sean Condon96b896d2017-12-11 12:44:29 -080029import org.onosproject.drivers.microsemi.yang.utils.MdNameUtil;
Sean Condon0e89bda2017-03-21 14:23:19 +000030import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepLbCreate;
31import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority;
32import org.onosproject.incubator.net.l2monitoring.cfm.MepEntry;
33import org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate;
34import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.InterfaceStatusTlvType;
35import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.PortStatusTlvType;
36import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.RemoteMepState;
37import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdCharStr;
38import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort;
39import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId;
40import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdCharStr;
41import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
42import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
Sean Condon96b896d2017-12-11 12:44:29 -080043import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepProgrammable;
Sean Condon0e89bda2017-03-21 14:23:19 +000044import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.MdNameAndTypeCombo;
45import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.MaNameAndTypeCombo;
46
Sean Condon1dbcd712017-10-19 12:09:21 +010047import java.util.BitSet;
Sean Condon96b896d2017-12-11 12:44:29 -080048import java.util.Optional;
Sean Condon1dbcd712017-10-19 12:09:21 +010049
Sean Condon0e89bda2017-03-21 14:23:19 +000050/**
51 * Test of the CFM implementation on EA1000 through the incubator/net/l2monitoring interface.
52 */
53public class EA1000CfmMepProgrammableTest {
Sean Condon1dbcd712017-10-19 12:09:21 +010054 public static final MdId MD_ID_1 = MdIdCharStr.asMdId("md-1");
55 public static final MaIdShort MA_ID_11 = MaIdCharStr.asMaId("ma-1-1");
56 public static final MepId MEP_111 = MepId.valueOf((short) 1);
57 public static final MepId MEP_112 = MepId.valueOf((short) 2);
Sean Condon0e89bda2017-03-21 14:23:19 +000058
Sean Condon96b896d2017-12-11 12:44:29 -080059 private CfmMepProgrammable cfmProgrammable;
60
Sean Condon0e89bda2017-03-21 14:23:19 +000061 @Before
62 public void setUp() throws Exception {
63 cfmProgrammable = new EA1000CfmMepProgrammable();
64 cfmProgrammable.setHandler(new MockEa1000DriverHandler());
65 assertNotNull(cfmProgrammable.handler().data().deviceId());
66 }
67
68
69 @Ignore
70 @Test
71 public void testCreateMep() {
72 fail("Not yet implemented");
73 }
74
Sean Condon0e89bda2017-03-21 14:23:19 +000075 @Test
76 public void testGetMep() throws CfmConfigException {
Sean Condon1dbcd712017-10-19 12:09:21 +010077 MepEntry mepEntry = cfmProgrammable.getMep(MD_ID_1, MA_ID_11, MEP_111);
Sean Condon0e89bda2017-03-21 14:23:19 +000078
79 //Result will come from MockNetconfSessionEa1000.SAMPLE_MSEACFM_MD_MA_MEP_FULL_REPLY
80 assertNotNull(mepEntry);
81 assertTrue(mepEntry.administrativeState());
82 assertTrue(mepEntry.cciEnabled());
83 assertEquals(Priority.PRIO5.name(), mepEntry.ccmLtmPriority().name());
84
Sean Condon1dbcd712017-10-19 12:09:21 +010085 assertTrue("Expecting remote-mac-error", mepEntry.activeMacStatusDefect()); //remote-mac-error
86 assertTrue("Expecting remote-rdi", mepEntry.activeRdiCcmDefect()); //remote-rdi
Sean Condon0e89bda2017-03-21 14:23:19 +000087
88 assertNotNull(mepEntry.activeRemoteMepList());
89
Sean Condon1dbcd712017-10-19 12:09:21 +010090//FIXME Waiting on patch https://gerrit.onosproject.org/#/c/15778/
91// assertEquals("Expecting 2 Remote Meps", 2, mepEntry.activeRemoteMepList().size());
92 mepEntry.activeRemoteMepList().forEach(rmep -> {
93 if (rmep.remoteMepId().value() == 1) {
94 assertEquals(RemoteMepState.RMEP_FAILED.name(),
95 rmep.state().toString());
96 assertEquals(54654654L, rmep.failedOrOkTime().toMillis());
97 assertEquals("aa:bb:cc:dd:ee:ff".toUpperCase(), rmep.macAddress().toString());
98 assertFalse(rmep.rdi());
99 assertEquals(PortStatusTlvType.PS_NO_STATUS_TLV.name(),
100 rmep.portStatusTlvType().toString());
101 assertEquals(InterfaceStatusTlvType.IS_DORMANT.name(),
102 rmep.interfaceStatusTlvType().toString());
103 }
104 });
105
106 }
107
108 @Test
109 public void testGetMep2() throws CfmConfigException {
110 MepEntry mepEntry = cfmProgrammable.getMep(MD_ID_1, MA_ID_11, MEP_112);
111
112 //Result will come from MockNetconfSessionEa1000.SAMPLE_MSEACFM_MD_MA_MEP_FULL_REPLY
113 assertNotNull(mepEntry);
114 assertTrue(mepEntry.administrativeState());
115 assertTrue(mepEntry.cciEnabled());
116 assertEquals(Priority.PRIO4.name(), mepEntry.ccmLtmPriority().name());
117
118 assertNotNull(mepEntry.activeRemoteMepList());
119 BitSet bs1 = new BitSet();
120 bs1.clear();
121//FIXME Waiting on patch https://gerrit.onosproject.org/#/c/15778/
Sean Condon0e89bda2017-03-21 14:23:19 +0000122// assertEquals("Expecting 2 Remote Meps", 2, mepEntry.activeRemoteMepList().size());
123 mepEntry.activeRemoteMepList().forEach(rmep -> {
124 if (rmep.remoteMepId().value() == 1) {
125 assertEquals(RemoteMepState.RMEP_FAILED.name(),
126 rmep.state().toString());
127 assertEquals(54654654L, rmep.failedOrOkTime().toMillis());
128 assertEquals("aa:bb:cc:dd:ee:ff".toUpperCase(), rmep.macAddress().toString());
129 assertFalse(rmep.rdi());
130 assertEquals(PortStatusTlvType.PS_NO_STATUS_TLV.name(),
131 rmep.portStatusTlvType().toString());
132 assertEquals(InterfaceStatusTlvType.IS_DORMANT.name(),
133 rmep.interfaceStatusTlvType().toString());
134 }
135 });
136
137 }
138
139 /**
140 * For sampleXmlRegexDeleteMseaCfmMep.
141 * @throws CfmConfigException If an error occurs
142 */
143 @Test
144 public void testDeleteMep() throws CfmConfigException {
Sean Condon96b896d2017-12-11 12:44:29 -0800145 assertTrue(cfmProgrammable.deleteMep(MD_ID_1, MA_ID_11, MEP_111, Optional.empty()));
146 }
147
148 /**
149 * Create the MD md-1 on the device.
150 * This will retrieve the MD from the MockCfmMdService and will create it
151 * and its MA on the device
152 * Depends on sampleXmlRegexCreateMseaCfmMa
153 */
154 @Test
155 public void testCreateMaintenanceDomainOnDevice() throws CfmConfigException {
156 boolean success =
157 cfmProgrammable.createMdOnDevice(MdIdCharStr.asMdId("md-1"));
158 assertTrue(success);
159 }
160
161 /**
162 * Create the MD md-2 on the device.
163 * This will retrieve the MD from the MockCfmMdService and will create it on
164 * the device. This MD has no MA
165 * Depends on sampleXmlRegexCreateMseaCfmMa
166 */
167 @Test
168 public void testCreateMaintenanceDomainOnDevice2() throws CfmConfigException {
169 boolean success =
170 cfmProgrammable.createMdOnDevice(MdIdCharStr.asMdId("md-2"));
171 assertTrue(success);
172 }
173
174 /**
175 * Delete the MD md-1 on the device.
176 * This will retrieve the MD from the MockCfmMdService and will delete it on
177 * the device.
178 * Depends on sampleXmlRegexCreateMseaCfmMa
179 */
180 @Test
181 public void testDeleteMaintenanceDomainOnDevice() throws CfmConfigException {
182 boolean success =
183 cfmProgrammable.deleteMdOnDevice(MdIdCharStr.asMdId("md-1"), Optional.empty());
184 assertTrue(success);
185 }
186
187
188 /**
189 * Create the MA ma-1-1 on the device.
190 * This will retrieve the MA from the MockCfmMdService and will create it
191 * on the device under md-1
192 * Depends on sampleXmlRegexCreateMseaCfmMa
193 */
194 @Test
195 public void testCreateMaintenanceAssociationOnDevice() throws CfmConfigException {
196 boolean success =
197 cfmProgrammable.createMaOnDevice(
198 MdIdCharStr.asMdId("md-1"), MaIdCharStr.asMaId("ma-1-1"));
199 assertTrue(success);
200 }
201
202 /**
203 * Delete the MD md-1 on the device.
204 * This will retrieve the MD from the MockCfmMdService and will delete it on
205 * the device.
206 * Depends on sampleXmlRegexCreateMseaCfmMa
207 */
208 @Test
209 public void testDeleteMaintenanceAssociationOnDevice() throws CfmConfigException {
210 boolean success =
211 cfmProgrammable.deleteMaOnDevice(
212 MdIdCharStr.asMdId("md-1"),
213 MaIdCharStr.asMaId("ma-1-1"),
214 Optional.empty());
215 assertTrue(success);
216 }
217
218 /**
219 * Create the Remote Mep 10001 in ma-1-1 on the device.
220 * This will retrieve the MA from the MockCfmMdService and will create the
221 * new remote mep under it on the device
222 * Depends on sampleXmlRegexCreateMseaCfmMa
223 */
224 @Test
225 public void testCreateRemoteMepOnDevice() throws CfmConfigException {
226 boolean success =
227 cfmProgrammable.createMaRemoteMepOnDevice(
228 MdIdCharStr.asMdId("md-1"), MaIdCharStr.asMaId("ma-1-1"),
229 MepId.valueOf((short) 1001));
230 assertTrue(success);
231 }
232
233 /**
234 * Delete the Remote Mep 1002 in ma-1-1 on the device.
235 * This will retrieve the MA from the MockCfmMdService and will delete the
236 * existing remote mep under it on the device
237 * Depends on sampleXmlRegexCreateMseaCfmMa
238 */
239 @Test
240 public void testDeleteRemoteMepOnDevice() throws CfmConfigException {
241 boolean success =
242 cfmProgrammable.deleteMaRemoteMepOnDevice(
243 MdIdCharStr.asMdId("md-1"), MaIdCharStr.asMaId("ma-1-1"),
244 MepId.valueOf((short) 1001));
245 assertTrue(success);
Sean Condon0e89bda2017-03-21 14:23:19 +0000246 }
247
248 /**
249 * For sampleXmlRegexTransmitLoopback.
250 * @throws CfmConfigException If an error occurs
251 */
252 @Test
253 public void testTransmitLoopback() throws CfmConfigException {
254 MepLbCreate.MepLbCreateBuilder lbCreate =
255 DefaultMepLbCreate.builder(MepId.valueOf((short) 12));
256 lbCreate.numberMessages(5);
257// lbCreate.dataTlvHex("AA:BB:CC:DD:EE");
258 lbCreate.vlanPriority(Priority.PRIO3);
259 lbCreate.vlanDropEligible(true);
260
Sean Condon1dbcd712017-10-19 12:09:21 +0100261 cfmProgrammable.transmitLoopback(MD_ID_1, MA_ID_11, MEP_111, lbCreate.build());
Sean Condon0e89bda2017-03-21 14:23:19 +0000262 }
263
264 @Test
265 public void testAbortLoopback() throws CfmConfigException {
Sean Condon1dbcd712017-10-19 12:09:21 +0100266 cfmProgrammable.abortLoopback(MD_ID_1, MA_ID_11, MEP_111);
Sean Condon0e89bda2017-03-21 14:23:19 +0000267 }
268
Sean Condon96b896d2017-12-11 12:44:29 -0800269 @Ignore
270 @Test
271 public void testTransmitLinktrace() {
272 fail("Not yet implemented");
273 }
Sean Condon0e89bda2017-03-21 14:23:19 +0000274
275 @Test
276 public void testGetYangMdNameFromApiMdId() throws CfmConfigException {
Sean Condon96b896d2017-12-11 12:44:29 -0800277 MdNameAndTypeCombo name = getYangMdNameFromApiMdId(MdIdCharStr.asMdId("md-1"));
Sean Condon0e89bda2017-03-21 14:23:19 +0000278
279 assertEquals(org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm
280 .maintenancedomain.mdnameandtypecombo
281 .DefaultNameCharacterString.class, name.getClass());
282
Sean Condon96b896d2017-12-11 12:44:29 -0800283 assertEquals("md-1", MdNameUtil.cast(name).name().string());
Sean Condon0e89bda2017-03-21 14:23:19 +0000284 }
285
286 @Test
287 public void testGetYangMaNameFromApiMaId() throws CfmConfigException {
288 MaNameAndTypeCombo name = MaNameUtil
289 .getYangMaNameFromApiMaId(MaIdCharStr.asMaId("ma-1-1"));
290 assertEquals(org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm
291 .maintenancedomain.maintenanceassociation.manameandtypecombo
292 .DefaultNameCharacterString.class, name.getClass());
293
Sean Condon96b896d2017-12-11 12:44:29 -0800294 assertEquals("ma-1-1", MaNameUtil.cast(name).name().string());
Sean Condon0e89bda2017-03-21 14:23:19 +0000295 }
Sean Condon0e89bda2017-03-21 14:23:19 +0000296}