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; |
Yuta HIGUCHI | 8dee145 | 2018-05-02 19:09:04 -0700 | [diff] [blame^] | 26 | import org.junit.BeforeClass; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 27 | import org.junit.Ignore; |
| 28 | import org.junit.Test; |
| 29 | import org.onosproject.drivers.microsemi.yang.utils.MaNameUtil; |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 30 | import org.onosproject.drivers.microsemi.yang.utils.MdNameUtil; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 31 | import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepLbCreate; |
| 32 | import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority; |
| 33 | import org.onosproject.incubator.net.l2monitoring.cfm.MepEntry; |
| 34 | import org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate; |
| 35 | import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.InterfaceStatusTlvType; |
| 36 | import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.PortStatusTlvType; |
| 37 | import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.RemoteMepState; |
| 38 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdCharStr; |
| 39 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort; |
| 40 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId; |
| 41 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdCharStr; |
| 42 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId; |
| 43 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException; |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 44 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepProgrammable; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 45 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.MdNameAndTypeCombo; |
| 46 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.MaNameAndTypeCombo; |
| 47 | |
Sean Condon | 1dbcd71 | 2017-10-19 12:09:21 +0100 | [diff] [blame] | 48 | import java.util.BitSet; |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 49 | import java.util.Optional; |
Sean Condon | 1dbcd71 | 2017-10-19 12:09:21 +0100 | [diff] [blame] | 50 | |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 51 | /** |
| 52 | * Test of the CFM implementation on EA1000 through the incubator/net/l2monitoring interface. |
| 53 | */ |
| 54 | public class EA1000CfmMepProgrammableTest { |
Sean Condon | 1dbcd71 | 2017-10-19 12:09:21 +0100 | [diff] [blame] | 55 | 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 Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 59 | |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 60 | private CfmMepProgrammable cfmProgrammable; |
| 61 | |
Yuta HIGUCHI | 8dee145 | 2018-05-02 19:09:04 -0700 | [diff] [blame^] | 62 | private static MockEa1000DriverHandler mockHandler; |
| 63 | |
| 64 | @BeforeClass |
| 65 | public static void setUpBeforeClass() throws Exception { |
| 66 | mockHandler = new MockEa1000DriverHandler(); |
| 67 | } |
| 68 | |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 69 | @Before |
| 70 | public void setUp() throws Exception { |
| 71 | cfmProgrammable = new EA1000CfmMepProgrammable(); |
Yuta HIGUCHI | 8dee145 | 2018-05-02 19:09:04 -0700 | [diff] [blame^] | 72 | cfmProgrammable.setHandler(mockHandler); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 73 | assertNotNull(cfmProgrammable.handler().data().deviceId()); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | @Ignore |
| 78 | @Test |
| 79 | public void testCreateMep() { |
| 80 | fail("Not yet implemented"); |
| 81 | } |
| 82 | |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 83 | @Test |
| 84 | public void testGetMep() throws CfmConfigException { |
Sean Condon | 1dbcd71 | 2017-10-19 12:09:21 +0100 | [diff] [blame] | 85 | MepEntry mepEntry = cfmProgrammable.getMep(MD_ID_1, MA_ID_11, MEP_111); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 86 | |
| 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 Condon | 1dbcd71 | 2017-10-19 12:09:21 +0100 | [diff] [blame] | 93 | assertTrue("Expecting remote-mac-error", mepEntry.activeMacStatusDefect()); //remote-mac-error |
| 94 | assertTrue("Expecting remote-rdi", mepEntry.activeRdiCcmDefect()); //remote-rdi |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 95 | |
| 96 | assertNotNull(mepEntry.activeRemoteMepList()); |
| 97 | |
Sean Condon | 1dbcd71 | 2017-10-19 12:09:21 +0100 | [diff] [blame] | 98 | //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 HIGUCHI | 8dee145 | 2018-05-02 19:09:04 -0700 | [diff] [blame^] | 129 | assertEquals("Expecting 2 Remote Meps", 2, mepEntry.activeRemoteMepList().size()); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 130 | 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 Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 152 | 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 Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 253 | } |
| 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 Condon | 1dbcd71 | 2017-10-19 12:09:21 +0100 | [diff] [blame] | 268 | cfmProgrammable.transmitLoopback(MD_ID_1, MA_ID_11, MEP_111, lbCreate.build()); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | @Test |
| 272 | public void testAbortLoopback() throws CfmConfigException { |
Sean Condon | 1dbcd71 | 2017-10-19 12:09:21 +0100 | [diff] [blame] | 273 | cfmProgrammable.abortLoopback(MD_ID_1, MA_ID_11, MEP_111); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 276 | @Ignore |
| 277 | @Test |
| 278 | public void testTransmitLinktrace() { |
| 279 | fail("Not yet implemented"); |
| 280 | } |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 281 | |
| 282 | @Test |
| 283 | public void testGetYangMdNameFromApiMdId() throws CfmConfigException { |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 284 | MdNameAndTypeCombo name = getYangMdNameFromApiMdId(MdIdCharStr.asMdId("md-1")); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 285 | |
| 286 | assertEquals(org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm |
| 287 | .maintenancedomain.mdnameandtypecombo |
| 288 | .DefaultNameCharacterString.class, name.getClass()); |
| 289 | |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 290 | assertEquals("md-1", MdNameUtil.cast(name).name().string()); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 291 | } |
| 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 Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 301 | assertEquals("ma-1-1", MaNameUtil.cast(name).name().string()); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 302 | } |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 303 | } |