Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 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.yang; |
| 17 | |
| 18 | import static org.junit.Assert.assertEquals; |
| 19 | import static org.junit.Assert.assertNotNull; |
| 20 | import static org.junit.Assert.assertTrue; |
| 21 | import static org.junit.Assert.fail; |
| 22 | |
| 23 | import java.io.UncheckedIOException; |
| 24 | |
| 25 | import org.junit.After; |
| 26 | import org.junit.Before; |
| 27 | import org.junit.Test; |
| 28 | import org.onlab.packet.Ip4Address; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame^] | 29 | import org.onosproject.drivers.microsemi.yang.MseaCfmNetconfService.DmEntryParts; |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 30 | import org.onosproject.drivers.microsemi.yang.impl.MseaCfmManager; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame^] | 31 | import org.onosproject.drivers.microsemi.yang.utils.MepIdUtil; |
| 32 | import org.onosproject.drivers.microsemi.yang.utils.MepIdUtil2; |
| 33 | import org.onosproject.drivers.microsemi.yang.utils.MepIdUtil3; |
| 34 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdCharStr; |
| 35 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdCharStr; |
| 36 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId; |
| 37 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException; |
| 38 | import org.onosproject.incubator.net.l2monitoring.soam.SoamId; |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 39 | import org.onosproject.netconf.NetconfDeviceInfo; |
| 40 | import org.onosproject.netconf.NetconfException; |
| 41 | import org.onosproject.netconf.NetconfSession; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame^] | 42 | import org.onosproject.yang.gen.v1.ietfyangtypes.rev20130715.ietfyangtypes.MacAddress; |
Sean Condon | 06613e9 | 2017-06-09 15:14:01 +0100 | [diff] [blame] | 43 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.MseaCfm; |
| 44 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.DefaultMefCfm; |
| 45 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.MefCfm; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame^] | 46 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.abortloopback.AbortLoopbackInput; |
| 47 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.abortloopback.DefaultAbortLoopbackInput; |
Sean Condon | 06613e9 | 2017-06-09 15:14:01 +0100 | [diff] [blame] | 48 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.DefaultMaintenanceDomain; |
| 49 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.MaintenanceDomain; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame^] | 50 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.MaintenanceAssociationEndPoint; |
Sean Condon | 06613e9 | 2017-06-09 15:14:01 +0100 | [diff] [blame] | 51 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.DefaultNameCharacterString; |
| 52 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.NameCharacterString; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame^] | 53 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.targetaddressgroup.AddressType; |
| 54 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.targetaddressgroup.addresstype.DefaultMacAddress; |
| 55 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.targetaddressgroup.addresstype.DefaultMepId; |
| 56 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.transmitloopback.DefaultTransmitLoopbackInput; |
| 57 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.transmitloopback.TransmitLoopbackInput; |
| 58 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.transmitloopback.transmitloopbackinput.DefaultTargetAddress; |
| 59 | import org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.augmentedmseacfmmaintenanceassociationendpoint.delaymeasurements.DelayMeasurement; |
| 60 | import org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.augmentedmseacfmmaintenanceassociationendpoint.lossmeasurements.lossmeasurement.MessagePeriodEnum; |
| 61 | import org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.sessionstatustype.SessionStatusTypeEnum; |
Sean Condon | 06613e9 | 2017-06-09 15:14:01 +0100 | [diff] [blame] | 62 | import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.Identifier45; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame^] | 63 | import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.MepIdType; |
| 64 | import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.PriorityType; |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 65 | |
| 66 | public class MseaCfmManagerTest { |
| 67 | |
| 68 | MseaCfmManager mseaCfmService; |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 69 | NetconfSession session; |
| 70 | |
| 71 | @Before |
| 72 | public void setUp() throws Exception { |
| 73 | try { |
| 74 | mseaCfmService = new MockMseaCfmManager(); |
| 75 | mseaCfmService.activate(); |
| 76 | } catch (UncheckedIOException e) { |
| 77 | fail(e.getMessage()); |
| 78 | } |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame^] | 79 | NetconfDeviceInfo deviceInfo = new NetconfDeviceInfo("netconf", "netconf", |
| 80 | Ip4Address.valueOf("1.2.3.4"), 830); |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 81 | session = new MockNetconfSessionEa1000(deviceInfo); |
| 82 | } |
| 83 | |
| 84 | @After |
| 85 | public void tearDown() throws Exception { |
| 86 | } |
| 87 | |
| 88 | @Test |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame^] | 89 | public void testGetConfigMseaCfmEssentials() |
| 90 | throws NetconfException, CfmConfigException { |
| 91 | MseaCfm mseaCfm = mseaCfmService.getMepEssentials( |
| 92 | MdIdCharStr.asMdId("md-1"), |
| 93 | MaIdCharStr.asMaId("ma-1-1"), |
| 94 | MepId.valueOf((short) 1), session); |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 95 | assertNotNull(mseaCfm); |
| 96 | |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame^] | 97 | //See SAMPLE_MSEACFM_MD_MA_MEP_ESSENTIALS_REPLY in MockNetconfSessionEa1000 |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 98 | assertEquals(1, mseaCfm.mefCfm().maintenanceDomain().size()); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame^] | 99 | } |
| 100 | |
| 101 | @Test |
| 102 | public void testGetConfigMseaCfmFull() |
| 103 | throws NetconfException, CfmConfigException { |
| 104 | MseaCfm mseaCfm = mseaCfmService.getMepFull( |
| 105 | MdIdCharStr.asMdId("md-1"), |
| 106 | MaIdCharStr.asMaId("ma-1-1"), |
| 107 | MepId.valueOf((short) 1), session); |
| 108 | assertNotNull(mseaCfm); |
| 109 | |
| 110 | //See SAMPLE_MSEACFM_MD_MA_MEP_FULL_REPLY in MockNetconfSessionEa1000 |
| 111 | assertEquals(1, mseaCfm.mefCfm().maintenanceDomain().size()); |
| 112 | MaintenanceAssociationEndPoint mep = mseaCfm.mefCfm() |
| 113 | .maintenanceDomain().get(0) |
| 114 | .maintenanceAssociation().get(0) |
| 115 | .maintenanceAssociationEndPoint().get(0); |
| 116 | assertTrue(mep.administrativeState()); |
| 117 | assertEquals("00:b0:ae:03:ff:31", mep.macAddress().toString()); |
| 118 | |
| 119 | org.onosproject.yang.gen.v1.mseasoamfm.rev20160229.mseasoamfm.mefcfm.maintenancedomain |
| 120 | .maintenanceassociation.maintenanceassociationendpoint |
| 121 | .AugmentedMseaCfmMaintenanceAssociationEndPoint augmentedMep = |
| 122 | MepIdUtil2.convertFmAugmentedMep(mep); |
| 123 | |
| 124 | assertEquals("partially-active", augmentedMep.connectivityStatus().toString()); |
| 125 | assertEquals("up", augmentedMep.interfaceStatus().enumeration().toString()); |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Driven by SAMPLE_MSEACFM_DELAY_MEASUREMENT_FULL_REPLY. |
| 130 | * @throws NetconfException If there's a problem |
| 131 | */ |
| 132 | @Test |
| 133 | public void testGetSoamDm() throws NetconfException { |
| 134 | MseaCfm mseaCfmWithDm = mseaCfmService.getSoamDm( |
| 135 | MdIdCharStr.asMdId("md-1"), |
| 136 | MaIdCharStr.asMaId("ma-1-1"), |
| 137 | MepId.valueOf((short) 1), |
| 138 | SoamId.valueOf(1), |
| 139 | DmEntryParts.ALL_PARTS, session); |
| 140 | |
| 141 | assertNotNull(mseaCfmWithDm); |
| 142 | MaintenanceAssociationEndPoint mep = mseaCfmWithDm.mefCfm() |
| 143 | .maintenanceDomain().get(0) |
| 144 | .maintenanceAssociation().get(0) |
| 145 | .maintenanceAssociationEndPoint().get(0); |
| 146 | |
| 147 | //Because of a checkstyle problem with typecasts including really long |
| 148 | //package names, this has to be handed off to a different class |
| 149 | org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.mefcfm.maintenancedomain |
| 150 | .maintenanceassociation.maintenanceassociationendpoint |
| 151 | .AugmentedMseaCfmMaintenanceAssociationEndPoint augmentedMep = |
| 152 | MepIdUtil.convertPmAugmentedMep(mep); |
| 153 | |
| 154 | DelayMeasurement dm = augmentedMep.delayMeasurements().delayMeasurement().get(0); |
| 155 | assertEquals(true, dm.administrativeState()); |
| 156 | assertTrue(dm.measurementEnable().get(3)); //frame-delay-two-way-bins |
| 157 | assertTrue(dm.measurementEnable().get(1)); //frame-delay-two-way-max |
| 158 | |
| 159 | assertEquals(MessagePeriodEnum.YANGAUTOPREFIX3MS.name(), dm.messagePeriod().name()); |
| 160 | assertEquals(6, dm.priority().uint8()); |
| 161 | assertEquals(1000, dm.frameSize()); |
| 162 | assertEquals(15, dm.measurementInterval()); |
| 163 | assertEquals(32, dm.numberIntervalsStored()); |
| 164 | assertEquals(SessionStatusTypeEnum.ACTIVE.name(), |
| 165 | dm.sessionStatus().enumeration().name()); |
| 166 | assertEquals(100, dm.frameDelayTwoWay().uint32()); |
| 167 | assertEquals(101, dm.interFrameDelayVariationTwoWay().uint32()); |
| 168 | |
| 169 | //The remoteMep of the DM is a choice, which for mepId is a leafref object |
| 170 | org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.remotemepgroup.remotemep |
| 171 | .DefaultMepId remoteMepId = MepIdUtil3.convertPmRemoteMepToMepId(dm.remoteMep()); |
| 172 | assertNotNull(remoteMepId); |
| 173 | assertEquals(10, ((MepIdType) remoteMepId.mepId()).uint16()); |
| 174 | |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Create the Maintenance Domain "md-1". |
| 179 | * @throws NetconfException |
| 180 | */ |
| 181 | @Test |
| 182 | public void testSetMseaCfm() throws NetconfException { |
Sean Condon | 06613e9 | 2017-06-09 15:14:01 +0100 | [diff] [blame] | 183 | NameCharacterString mdName = new DefaultNameCharacterString(); |
| 184 | mdName.name(Identifier45.fromString("md-1")); |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 185 | |
Sean Condon | 06613e9 | 2017-06-09 15:14:01 +0100 | [diff] [blame] | 186 | MaintenanceDomain yangMd = new DefaultMaintenanceDomain(); |
| 187 | yangMd.id((short) 1); |
| 188 | yangMd.mdNameAndTypeCombo(mdName); |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 189 | |
Sean Condon | 06613e9 | 2017-06-09 15:14:01 +0100 | [diff] [blame] | 190 | MefCfm mefCfm = new DefaultMefCfm(); |
| 191 | mefCfm.addToMaintenanceDomain(yangMd); |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 192 | //FIXME implement this |
| 193 | // MseaCfmOpParam mseaCfmOpParam = (MseaCfmOpParam) MseaCfmOpParam.builder().mefCfm(mefCfm).build(); |
| 194 | // mseaCfmService.setMseaCfm(mseaCfmOpParam, session, NcDsType.running); |
| 195 | } |
| 196 | |
| 197 | @Test |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame^] | 198 | /** |
| 199 | * Using Remote remote MEP ID and all arguments. |
| 200 | */ |
| 201 | public void testTransmitLoopback1() { |
| 202 | TransmitLoopbackInput lbTr1 = new DefaultTransmitLoopbackInput(); |
| 203 | lbTr1.maintenanceDomain(Short.valueOf((short) 1)); |
| 204 | lbTr1.maintenanceAssociation(Short.valueOf((short) 2)); |
| 205 | lbTr1.maintenanceAssociationEndPoint(Short.valueOf((short) 3)); |
| 206 | |
| 207 | DefaultTargetAddress ta = new DefaultTargetAddress(); |
| 208 | DefaultMepId mepId = new DefaultMepId(); |
| 209 | mepId.mepId(MepIdType.of(4)); |
| 210 | ta.addressType((AddressType) mepId); |
| 211 | lbTr1.targetAddress(ta); |
| 212 | |
| 213 | // lbTr1.dataTlv(new byte[]{0x01, 0x02, 0x03}); Not supported in onos-yang-tools just yet |
| 214 | lbTr1.numberOfMessages(10); |
| 215 | lbTr1.vlanDropEligible(true); |
| 216 | lbTr1.vlanPriority(PriorityType.of((short) 1)); |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 217 | try { |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame^] | 218 | mseaCfmService.transmitLoopback(lbTr1, session); |
| 219 | } catch (NetconfException e) { |
| 220 | fail("Calling of TransmitLoopback failed: " + e.getMessage()); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | @Test |
| 225 | /** |
| 226 | * Using Remote Mac address in place of remote MEP ID and fewer arguments. |
| 227 | */ |
| 228 | public void testTransmitLoopback2() { |
| 229 | TransmitLoopbackInput lbTr2 = new DefaultTransmitLoopbackInput(); |
| 230 | |
| 231 | lbTr2.maintenanceDomain(Short.valueOf((short) 63)); |
| 232 | lbTr2.maintenanceAssociation(Short.valueOf((short) 62)); |
| 233 | lbTr2.maintenanceAssociationEndPoint(Short.valueOf((short) 61)); |
| 234 | |
| 235 | DefaultTargetAddress ta = new DefaultTargetAddress(); |
| 236 | DefaultMacAddress macAddr = new DefaultMacAddress(); |
| 237 | macAddr.macAddress(MacAddress.of("FF:EE:DD:CC:BB:AA")); |
| 238 | ta.addressType(macAddr); |
| 239 | lbTr2.targetAddress(ta); |
| 240 | try { |
| 241 | mseaCfmService.transmitLoopback(lbTr2, session); |
| 242 | } catch (NetconfException e) { |
| 243 | fail("Calling of TransmitLoopback failed: " + e.getMessage()); |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
| 247 | @Test |
| 248 | public void testAbortLoopback() throws NetconfException { |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame^] | 249 | AbortLoopbackInput lbAbort = new DefaultAbortLoopbackInput(); |
| 250 | |
| 251 | lbAbort.maintenanceDomain((short) 70); |
| 252 | lbAbort.maintenanceAssociation((short) 71); |
| 253 | lbAbort.maintenanceAssociationEndPoint((short) 72); |
| 254 | |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 255 | try { |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame^] | 256 | mseaCfmService.abortLoopback(lbAbort, session); |
| 257 | } catch (NetconfException e) { |
| 258 | fail("Calling of AbortLoopback failed: " + e.getMessage()); |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | |
| 262 | @Test |
| 263 | public void testTransmitLinktrace() throws NetconfException { |
| 264 | try { |
| 265 | mseaCfmService.transmitLinktrace(null, session); |
| 266 | } catch (UnsupportedOperationException e) { |
| 267 | assertTrue(e.getMessage().contains("Not yet implemented")); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | } |