blob: fbfbb136d30d7207363d606c3ec27c2b155d504b [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;
Yuta HIGUCHI8dee1452018-05-02 19:09:04 -070026import org.junit.BeforeClass;
Sean Condon0e89bda2017-03-21 14:23:19 +000027import org.junit.Ignore;
28import org.junit.Test;
29import org.onosproject.drivers.microsemi.yang.utils.MaNameUtil;
Sean Condon96b896d2017-12-11 12:44:29 -080030import org.onosproject.drivers.microsemi.yang.utils.MdNameUtil;
Sean Condon0e89bda2017-03-21 14:23:19 +000031import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepLbCreate;
32import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority;
33import org.onosproject.incubator.net.l2monitoring.cfm.MepEntry;
34import org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate;
35import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.InterfaceStatusTlvType;
36import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.PortStatusTlvType;
37import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.RemoteMepState;
38import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdCharStr;
39import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort;
40import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId;
41import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdCharStr;
42import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
43import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
Sean Condon96b896d2017-12-11 12:44:29 -080044import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepProgrammable;
Sean Condon0e89bda2017-03-21 14:23:19 +000045import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.MdNameAndTypeCombo;
46import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.MaNameAndTypeCombo;
47
Sean Condon1dbcd712017-10-19 12:09:21 +010048import java.util.BitSet;
Sean Condon96b896d2017-12-11 12:44:29 -080049import java.util.Optional;
Sean Condon1dbcd712017-10-19 12:09:21 +010050
Sean Condon0e89bda2017-03-21 14:23:19 +000051/**
52 * Test of the CFM implementation on EA1000 through the incubator/net/l2monitoring interface.
53 */
54public class EA1000CfmMepProgrammableTest {
Sean Condon1dbcd712017-10-19 12:09:21 +010055 public static final MdId MD_ID_1 = MdIdCharStr.asMdId("md-1");
56 public static final MaIdShort MA_ID_11 = MaIdCharStr.asMaId("ma-1-1");
57 public static final MepId MEP_111 = MepId.valueOf((short) 1);
58 public static final MepId MEP_112 = MepId.valueOf((short) 2);
Sean Condon0e89bda2017-03-21 14:23:19 +000059
Sean Condon96b896d2017-12-11 12:44:29 -080060 private CfmMepProgrammable cfmProgrammable;
61
Yuta HIGUCHI8dee1452018-05-02 19:09:04 -070062 private static MockEa1000DriverHandler mockHandler;
63
64 @BeforeClass
65 public static void setUpBeforeClass() throws Exception {
66 mockHandler = new MockEa1000DriverHandler();
67 }
68
Sean Condon0e89bda2017-03-21 14:23:19 +000069 @Before
70 public void setUp() throws Exception {
71 cfmProgrammable = new EA1000CfmMepProgrammable();
Yuta HIGUCHI8dee1452018-05-02 19:09:04 -070072 cfmProgrammable.setHandler(mockHandler);
Sean Condon0e89bda2017-03-21 14:23:19 +000073 assertNotNull(cfmProgrammable.handler().data().deviceId());
74 }
75
76
77 @Ignore
78 @Test
79 public void testCreateMep() {
80 fail("Not yet implemented");
81 }
82
Sean Condon0e89bda2017-03-21 14:23:19 +000083 @Test
84 public void testGetMep() throws CfmConfigException {
Sean Condon1dbcd712017-10-19 12:09:21 +010085 MepEntry mepEntry = cfmProgrammable.getMep(MD_ID_1, MA_ID_11, MEP_111);
Sean Condon0e89bda2017-03-21 14:23:19 +000086
87 //Result will come from MockNetconfSessionEa1000.SAMPLE_MSEACFM_MD_MA_MEP_FULL_REPLY
88 assertNotNull(mepEntry);
89 assertTrue(mepEntry.administrativeState());
90 assertTrue(mepEntry.cciEnabled());
91 assertEquals(Priority.PRIO5.name(), mepEntry.ccmLtmPriority().name());
92
Sean Condon1dbcd712017-10-19 12:09:21 +010093 assertTrue("Expecting remote-mac-error", mepEntry.activeMacStatusDefect()); //remote-mac-error
94 assertTrue("Expecting remote-rdi", mepEntry.activeRdiCcmDefect()); //remote-rdi
Sean Condon0e89bda2017-03-21 14:23:19 +000095
96 assertNotNull(mepEntry.activeRemoteMepList());
97
Sean Condon1dbcd712017-10-19 12:09:21 +010098//FIXME Waiting on patch https://gerrit.onosproject.org/#/c/15778/
99// assertEquals("Expecting 2 Remote Meps", 2, mepEntry.activeRemoteMepList().size());
100 mepEntry.activeRemoteMepList().forEach(rmep -> {
101 if (rmep.remoteMepId().value() == 1) {
102 assertEquals(RemoteMepState.RMEP_FAILED.name(),
103 rmep.state().toString());
104 assertEquals(54654654L, rmep.failedOrOkTime().toMillis());
105 assertEquals("aa:bb:cc:dd:ee:ff".toUpperCase(), rmep.macAddress().toString());
106 assertFalse(rmep.rdi());
107 assertEquals(PortStatusTlvType.PS_NO_STATUS_TLV.name(),
108 rmep.portStatusTlvType().toString());
109 assertEquals(InterfaceStatusTlvType.IS_DORMANT.name(),
110 rmep.interfaceStatusTlvType().toString());
111 }
112 });
113
114 }
115
116 @Test
117 public void testGetMep2() throws CfmConfigException {
118 MepEntry mepEntry = cfmProgrammable.getMep(MD_ID_1, MA_ID_11, MEP_112);
119
120 //Result will come from MockNetconfSessionEa1000.SAMPLE_MSEACFM_MD_MA_MEP_FULL_REPLY
121 assertNotNull(mepEntry);
122 assertTrue(mepEntry.administrativeState());
123 assertTrue(mepEntry.cciEnabled());
124 assertEquals(Priority.PRIO4.name(), mepEntry.ccmLtmPriority().name());
125
126 assertNotNull(mepEntry.activeRemoteMepList());
127 BitSet bs1 = new BitSet();
128 bs1.clear();
Yuta HIGUCHI8dee1452018-05-02 19:09:04 -0700129 assertEquals("Expecting 2 Remote Meps", 2, mepEntry.activeRemoteMepList().size());
Sean Condon0e89bda2017-03-21 14:23:19 +0000130 mepEntry.activeRemoteMepList().forEach(rmep -> {
131 if (rmep.remoteMepId().value() == 1) {
132 assertEquals(RemoteMepState.RMEP_FAILED.name(),
133 rmep.state().toString());
134 assertEquals(54654654L, rmep.failedOrOkTime().toMillis());
135 assertEquals("aa:bb:cc:dd:ee:ff".toUpperCase(), rmep.macAddress().toString());
136 assertFalse(rmep.rdi());
137 assertEquals(PortStatusTlvType.PS_NO_STATUS_TLV.name(),
138 rmep.portStatusTlvType().toString());
139 assertEquals(InterfaceStatusTlvType.IS_DORMANT.name(),
140 rmep.interfaceStatusTlvType().toString());
141 }
142 });
143
144 }
145
146 /**
147 * For sampleXmlRegexDeleteMseaCfmMep.
148 * @throws CfmConfigException If an error occurs
149 */
150 @Test
151 public void testDeleteMep() throws CfmConfigException {
Sean Condon96b896d2017-12-11 12:44:29 -0800152 assertTrue(cfmProgrammable.deleteMep(MD_ID_1, MA_ID_11, MEP_111, Optional.empty()));
153 }
154
155 /**
156 * Create the MD md-1 on the device.
157 * This will retrieve the MD from the MockCfmMdService and will create it
158 * and its MA on the device
159 * Depends on sampleXmlRegexCreateMseaCfmMa
160 */
161 @Test
162 public void testCreateMaintenanceDomainOnDevice() throws CfmConfigException {
163 boolean success =
164 cfmProgrammable.createMdOnDevice(MdIdCharStr.asMdId("md-1"));
165 assertTrue(success);
166 }
167
168 /**
169 * Create the MD md-2 on the device.
170 * This will retrieve the MD from the MockCfmMdService and will create it on
171 * the device. This MD has no MA
172 * Depends on sampleXmlRegexCreateMseaCfmMa
173 */
174 @Test
175 public void testCreateMaintenanceDomainOnDevice2() throws CfmConfigException {
176 boolean success =
177 cfmProgrammable.createMdOnDevice(MdIdCharStr.asMdId("md-2"));
178 assertTrue(success);
179 }
180
181 /**
182 * Delete the MD md-1 on the device.
183 * This will retrieve the MD from the MockCfmMdService and will delete it on
184 * the device.
185 * Depends on sampleXmlRegexCreateMseaCfmMa
186 */
187 @Test
188 public void testDeleteMaintenanceDomainOnDevice() throws CfmConfigException {
189 boolean success =
190 cfmProgrammable.deleteMdOnDevice(MdIdCharStr.asMdId("md-1"), Optional.empty());
191 assertTrue(success);
192 }
193
194
195 /**
196 * Create the MA ma-1-1 on the device.
197 * This will retrieve the MA from the MockCfmMdService and will create it
198 * on the device under md-1
199 * Depends on sampleXmlRegexCreateMseaCfmMa
200 */
201 @Test
202 public void testCreateMaintenanceAssociationOnDevice() throws CfmConfigException {
203 boolean success =
204 cfmProgrammable.createMaOnDevice(
205 MdIdCharStr.asMdId("md-1"), MaIdCharStr.asMaId("ma-1-1"));
206 assertTrue(success);
207 }
208
209 /**
210 * Delete the MD md-1 on the device.
211 * This will retrieve the MD from the MockCfmMdService and will delete it on
212 * the device.
213 * Depends on sampleXmlRegexCreateMseaCfmMa
214 */
215 @Test
216 public void testDeleteMaintenanceAssociationOnDevice() throws CfmConfigException {
217 boolean success =
218 cfmProgrammable.deleteMaOnDevice(
219 MdIdCharStr.asMdId("md-1"),
220 MaIdCharStr.asMaId("ma-1-1"),
221 Optional.empty());
222 assertTrue(success);
223 }
224
225 /**
226 * Create the Remote Mep 10001 in ma-1-1 on the device.
227 * This will retrieve the MA from the MockCfmMdService and will create the
228 * new remote mep under it on the device
229 * Depends on sampleXmlRegexCreateMseaCfmMa
230 */
231 @Test
232 public void testCreateRemoteMepOnDevice() throws CfmConfigException {
233 boolean success =
234 cfmProgrammable.createMaRemoteMepOnDevice(
235 MdIdCharStr.asMdId("md-1"), MaIdCharStr.asMaId("ma-1-1"),
236 MepId.valueOf((short) 1001));
237 assertTrue(success);
238 }
239
240 /**
241 * Delete the Remote Mep 1002 in ma-1-1 on the device.
242 * This will retrieve the MA from the MockCfmMdService and will delete the
243 * existing remote mep under it on the device
244 * Depends on sampleXmlRegexCreateMseaCfmMa
245 */
246 @Test
247 public void testDeleteRemoteMepOnDevice() throws CfmConfigException {
248 boolean success =
249 cfmProgrammable.deleteMaRemoteMepOnDevice(
250 MdIdCharStr.asMdId("md-1"), MaIdCharStr.asMaId("ma-1-1"),
251 MepId.valueOf((short) 1001));
252 assertTrue(success);
Sean Condon0e89bda2017-03-21 14:23:19 +0000253 }
254
255 /**
256 * For sampleXmlRegexTransmitLoopback.
257 * @throws CfmConfigException If an error occurs
258 */
259 @Test
260 public void testTransmitLoopback() throws CfmConfigException {
261 MepLbCreate.MepLbCreateBuilder lbCreate =
262 DefaultMepLbCreate.builder(MepId.valueOf((short) 12));
263 lbCreate.numberMessages(5);
264// lbCreate.dataTlvHex("AA:BB:CC:DD:EE");
265 lbCreate.vlanPriority(Priority.PRIO3);
266 lbCreate.vlanDropEligible(true);
267
Sean Condon1dbcd712017-10-19 12:09:21 +0100268 cfmProgrammable.transmitLoopback(MD_ID_1, MA_ID_11, MEP_111, lbCreate.build());
Sean Condon0e89bda2017-03-21 14:23:19 +0000269 }
270
271 @Test
272 public void testAbortLoopback() throws CfmConfigException {
Sean Condon1dbcd712017-10-19 12:09:21 +0100273 cfmProgrammable.abortLoopback(MD_ID_1, MA_ID_11, MEP_111);
Sean Condon0e89bda2017-03-21 14:23:19 +0000274 }
275
Sean Condon96b896d2017-12-11 12:44:29 -0800276 @Ignore
277 @Test
278 public void testTransmitLinktrace() {
279 fail("Not yet implemented");
280 }
Sean Condon0e89bda2017-03-21 14:23:19 +0000281
282 @Test
283 public void testGetYangMdNameFromApiMdId() throws CfmConfigException {
Sean Condon96b896d2017-12-11 12:44:29 -0800284 MdNameAndTypeCombo name = getYangMdNameFromApiMdId(MdIdCharStr.asMdId("md-1"));
Sean Condon0e89bda2017-03-21 14:23:19 +0000285
286 assertEquals(org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm
287 .maintenancedomain.mdnameandtypecombo
288 .DefaultNameCharacterString.class, name.getClass());
289
Sean Condon96b896d2017-12-11 12:44:29 -0800290 assertEquals("md-1", MdNameUtil.cast(name).name().string());
Sean Condon0e89bda2017-03-21 14:23:19 +0000291 }
292
293 @Test
294 public void testGetYangMaNameFromApiMaId() throws CfmConfigException {
295 MaNameAndTypeCombo name = MaNameUtil
296 .getYangMaNameFromApiMaId(MaIdCharStr.asMaId("ma-1-1"));
297 assertEquals(org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm
298 .maintenancedomain.maintenanceassociation.manameandtypecombo
299 .DefaultNameCharacterString.class, name.getClass());
300
Sean Condon96b896d2017-12-11 12:44:29 -0800301 assertEquals("ma-1-1", MaNameUtil.cast(name).name().string());
Sean Condon0e89bda2017-03-21 14:23:19 +0000302 }
Sean Condon0e89bda2017-03-21 14:23:19 +0000303}