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; |
| 23 | |
| 24 | import org.junit.Before; |
| 25 | import org.junit.Ignore; |
| 26 | import org.junit.Test; |
| 27 | import org.onosproject.drivers.microsemi.yang.utils.MaNameUtil; |
| 28 | import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepLbCreate; |
| 29 | import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority; |
| 30 | import org.onosproject.incubator.net.l2monitoring.cfm.MepEntry; |
| 31 | import org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate; |
| 32 | import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.InterfaceStatusTlvType; |
| 33 | import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.PortStatusTlvType; |
| 34 | import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.RemoteMepState; |
| 35 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdCharStr; |
| 36 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort; |
| 37 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId; |
| 38 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdCharStr; |
| 39 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId; |
| 40 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException; |
| 41 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.MdNameAndTypeCombo; |
| 42 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.MaNameAndTypeCombo; |
| 43 | |
| 44 | /** |
| 45 | * Test of the CFM implementation on EA1000 through the incubator/net/l2monitoring interface. |
| 46 | */ |
| 47 | public class EA1000CfmMepProgrammableTest { |
| 48 | EA1000CfmMepProgrammable cfmProgrammable; |
| 49 | MdId mdId1 = MdIdCharStr.asMdId("md-1"); |
| 50 | MaIdShort maId11 = MaIdCharStr.asMaId("ma-1-1"); |
| 51 | MepId mep111 = MepId.valueOf((short) 1); |
| 52 | |
| 53 | @Before |
| 54 | public void setUp() throws Exception { |
| 55 | cfmProgrammable = new EA1000CfmMepProgrammable(); |
| 56 | cfmProgrammable.setHandler(new MockEa1000DriverHandler()); |
| 57 | assertNotNull(cfmProgrammable.handler().data().deviceId()); |
| 58 | } |
| 59 | |
| 60 | |
| 61 | @Ignore |
| 62 | @Test |
| 63 | public void testCreateMep() { |
| 64 | fail("Not yet implemented"); |
| 65 | } |
| 66 | |
| 67 | @Ignore |
| 68 | @Test |
| 69 | public void testGetAllMeps() { |
| 70 | fail("Not yet implemented"); |
| 71 | } |
| 72 | |
| 73 | @Test |
| 74 | public void testGetMep() throws CfmConfigException { |
| 75 | MepEntry mepEntry = cfmProgrammable.getMep(mdId1, maId11, mep111); |
| 76 | |
| 77 | //Result will come from MockNetconfSessionEa1000.SAMPLE_MSEACFM_MD_MA_MEP_FULL_REPLY |
| 78 | assertNotNull(mepEntry); |
| 79 | assertTrue(mepEntry.administrativeState()); |
| 80 | assertTrue(mepEntry.cciEnabled()); |
| 81 | assertEquals(Priority.PRIO5.name(), mepEntry.ccmLtmPriority().name()); |
| 82 | |
| 83 | assertTrue(mepEntry.activeMacStatusDefect()); //remote-mac-error |
| 84 | assertTrue(mepEntry.activeRdiCcmDefect()); //remote-rdi |
| 85 | |
| 86 | assertNotNull(mepEntry.activeRemoteMepList()); |
| 87 | |
| 88 | //TODO Comment back in this test - this is a serious issue with onos-yang-tools that only 1 is found |
| 89 | // See https://gerrit.onosproject.org/#/c/15164/ |
| 90 | // assertEquals("Expecting 2 Remote Meps", 2, mepEntry.activeRemoteMepList().size()); |
| 91 | mepEntry.activeRemoteMepList().forEach(rmep -> { |
| 92 | if (rmep.remoteMepId().value() == 1) { |
| 93 | assertEquals(RemoteMepState.RMEP_FAILED.name(), |
| 94 | rmep.state().toString()); |
| 95 | assertEquals(54654654L, rmep.failedOrOkTime().toMillis()); |
| 96 | assertEquals("aa:bb:cc:dd:ee:ff".toUpperCase(), rmep.macAddress().toString()); |
| 97 | assertFalse(rmep.rdi()); |
| 98 | assertEquals(PortStatusTlvType.PS_NO_STATUS_TLV.name(), |
| 99 | rmep.portStatusTlvType().toString()); |
| 100 | assertEquals(InterfaceStatusTlvType.IS_DORMANT.name(), |
| 101 | rmep.interfaceStatusTlvType().toString()); |
| 102 | } |
| 103 | }); |
| 104 | |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * For sampleXmlRegexDeleteMseaCfmMep. |
| 109 | * @throws CfmConfigException If an error occurs |
| 110 | */ |
| 111 | @Test |
| 112 | public void testDeleteMep() throws CfmConfigException { |
| 113 | assertTrue(cfmProgrammable.deleteMep(mdId1, maId11, mep111)); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * For sampleXmlRegexTransmitLoopback. |
| 118 | * @throws CfmConfigException If an error occurs |
| 119 | */ |
| 120 | @Test |
| 121 | public void testTransmitLoopback() throws CfmConfigException { |
| 122 | MepLbCreate.MepLbCreateBuilder lbCreate = |
| 123 | DefaultMepLbCreate.builder(MepId.valueOf((short) 12)); |
| 124 | lbCreate.numberMessages(5); |
| 125 | // lbCreate.dataTlvHex("AA:BB:CC:DD:EE"); |
| 126 | lbCreate.vlanPriority(Priority.PRIO3); |
| 127 | lbCreate.vlanDropEligible(true); |
| 128 | |
| 129 | cfmProgrammable.transmitLoopback(mdId1, maId11, mep111, lbCreate.build()); |
| 130 | } |
| 131 | |
| 132 | @Test |
| 133 | public void testAbortLoopback() throws CfmConfigException { |
| 134 | cfmProgrammable.abortLoopback(mdId1, maId11, mep111); |
| 135 | } |
| 136 | |
| 137 | // @Test |
| 138 | // public void testTransmitLinktrace() { |
| 139 | // fail("Not yet implemented"); |
| 140 | // } |
| 141 | |
| 142 | @Test |
| 143 | public void testGetYangMdNameFromApiMdId() throws CfmConfigException { |
| 144 | MdNameAndTypeCombo name = EA1000CfmMepProgrammable |
| 145 | .getYangMdNameFromApiMdId(MdIdCharStr.asMdId("md-1")); |
| 146 | |
| 147 | assertEquals(org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm |
| 148 | .maintenancedomain.mdnameandtypecombo |
| 149 | .DefaultNameCharacterString.class, name.getClass()); |
| 150 | |
| 151 | //There's a problem with checkstyle for typecast on really long paths |
| 152 | // assertEquals("md-1", ((org.onosproject.yang.gen.v1.http.www.microsemi.com |
| 153 | // .microsemi.edge.assure.msea.cfm.rev20160229.mseacfm.mefcfm |
| 154 | // .maintenancedomain.mdnameandtypecombo |
| 155 | // .DefaultNameCharacterString) name).name().string()); |
| 156 | } |
| 157 | |
| 158 | @Test |
| 159 | public void testGetYangMaNameFromApiMaId() throws CfmConfigException { |
| 160 | MaNameAndTypeCombo name = MaNameUtil |
| 161 | .getYangMaNameFromApiMaId(MaIdCharStr.asMaId("ma-1-1")); |
| 162 | assertEquals(org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm |
| 163 | .maintenancedomain.maintenanceassociation.manameandtypecombo |
| 164 | .DefaultNameCharacterString.class, name.getClass()); |
| 165 | |
| 166 | //There's a problem with checkstyle for typecast on really long paths |
| 167 | // assertEquals("ma-1-1", ((org.onosproject.yang.gen.v1.http.www.microsemi.com |
| 168 | // .microsemi.edge.assure.msea.cfm.rev20160229.mseacfm.mefcfm |
| 169 | // .maintenancedomain.maintenanceassociation.manameandtypecombo |
| 170 | // .DefaultNameCharacterString) name).name().string()); |
| 171 | } |
| 172 | |
| 173 | } |