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 junit.framework.TestCase.fail; |
| 19 | import static org.junit.Assert.assertEquals; |
| 20 | import static org.junit.Assert.assertFalse; |
| 21 | import static org.junit.Assert.assertNotNull; |
| 22 | import static org.junit.Assert.assertTrue; |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 23 | import static org.onosproject.drivers.microsemi.yang.utils.MdNameUtil.getYangMdNameFromApiMdId; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 24 | |
| 25 | import org.junit.Before; |
| 26 | import org.junit.Ignore; |
| 27 | import org.junit.Test; |
| 28 | import org.onosproject.drivers.microsemi.yang.utils.MaNameUtil; |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 29 | import org.onosproject.drivers.microsemi.yang.utils.MdNameUtil; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 30 | import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepLbCreate; |
| 31 | import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority; |
| 32 | import org.onosproject.incubator.net.l2monitoring.cfm.MepEntry; |
| 33 | import org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate; |
| 34 | import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.InterfaceStatusTlvType; |
| 35 | import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.PortStatusTlvType; |
| 36 | import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.RemoteMepState; |
| 37 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdCharStr; |
| 38 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort; |
| 39 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId; |
| 40 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdCharStr; |
| 41 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId; |
| 42 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException; |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 43 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepProgrammable; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 44 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.MdNameAndTypeCombo; |
| 45 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.MaNameAndTypeCombo; |
| 46 | |
Sean Condon | 1dbcd71 | 2017-10-19 12:09:21 +0100 | [diff] [blame] | 47 | import java.util.BitSet; |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 48 | import java.util.Optional; |
Sean Condon | 1dbcd71 | 2017-10-19 12:09:21 +0100 | [diff] [blame] | 49 | |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 50 | /** |
| 51 | * Test of the CFM implementation on EA1000 through the incubator/net/l2monitoring interface. |
| 52 | */ |
| 53 | public class EA1000CfmMepProgrammableTest { |
Sean Condon | 1dbcd71 | 2017-10-19 12:09:21 +0100 | [diff] [blame] | 54 | 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 Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 58 | |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 59 | private CfmMepProgrammable cfmProgrammable; |
| 60 | |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 61 | @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 Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 75 | @Test |
| 76 | public void testGetMep() throws CfmConfigException { |
Sean Condon | 1dbcd71 | 2017-10-19 12:09:21 +0100 | [diff] [blame] | 77 | MepEntry mepEntry = cfmProgrammable.getMep(MD_ID_1, MA_ID_11, MEP_111); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 78 | |
| 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 Condon | 1dbcd71 | 2017-10-19 12:09:21 +0100 | [diff] [blame] | 85 | assertTrue("Expecting remote-mac-error", mepEntry.activeMacStatusDefect()); //remote-mac-error |
| 86 | assertTrue("Expecting remote-rdi", mepEntry.activeRdiCcmDefect()); //remote-rdi |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 87 | |
| 88 | assertNotNull(mepEntry.activeRemoteMepList()); |
| 89 | |
Sean Condon | 1dbcd71 | 2017-10-19 12:09:21 +0100 | [diff] [blame] | 90 | //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 Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 122 | // 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 Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 145 | 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 Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 246 | } |
| 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 Condon | 1dbcd71 | 2017-10-19 12:09:21 +0100 | [diff] [blame] | 261 | cfmProgrammable.transmitLoopback(MD_ID_1, MA_ID_11, MEP_111, lbCreate.build()); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | @Test |
| 265 | public void testAbortLoopback() throws CfmConfigException { |
Sean Condon | 1dbcd71 | 2017-10-19 12:09:21 +0100 | [diff] [blame] | 266 | cfmProgrammable.abortLoopback(MD_ID_1, MA_ID_11, MEP_111); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 269 | @Ignore |
| 270 | @Test |
| 271 | public void testTransmitLinktrace() { |
| 272 | fail("Not yet implemented"); |
| 273 | } |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 274 | |
| 275 | @Test |
| 276 | public void testGetYangMdNameFromApiMdId() throws CfmConfigException { |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 277 | MdNameAndTypeCombo name = getYangMdNameFromApiMdId(MdIdCharStr.asMdId("md-1")); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 278 | |
| 279 | assertEquals(org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm |
| 280 | .maintenancedomain.mdnameandtypecombo |
| 281 | .DefaultNameCharacterString.class, name.getClass()); |
| 282 | |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 283 | assertEquals("md-1", MdNameUtil.cast(name).name().string()); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 284 | } |
| 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 Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 294 | assertEquals("ma-1-1", MaNameUtil.cast(name).name().string()); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 295 | } |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 296 | } |