From 5ec31f19f7a74a884e2bef8e5238fdd4cfa2c4c2 Mon Sep 17 00:00:00 2001 From: Jan Srnicek Date: Tue, 14 Mar 2017 09:29:12 +0100 Subject: HC2VPP-7 - Split vpp state/Cli RPC to separate module Introduces VppManageModule containing - Vpp state attributes - CLI RPC support - Keep-alive Change-Id: I8907e57132cc9e57840aa3b9607fa131a77f767d Signed-off-by: Jan Srnicek --- .../java/io/fd/hc2vpp/v3po/V3poModuleTest.java | 10 +- .../l2/ArpTerminationTableEntryCustomizerTest.java | 192 ++++++++++++ .../hc2vpp/v3po/l2/BridgeDomainCustomizerTest.java | 338 +++++++++++++++++++++ .../hc2vpp/v3po/l2/L2FibEntryCustomizerTest.java | 283 +++++++++++++++++ .../v3po/l2state/BridgeDomainCustomizerTest.java | 48 +++ .../v3po/l2state/L2FibEntryCustomizerTest.java | 125 ++++++++ .../io/fd/hc2vpp/v3po/l2state/L2StateTest.java | 216 +++++++++++++ .../fd/hc2vpp/v3po/rpc/CliInbandServiceTest.java | 52 ---- .../ArpTerminationTableEntryCustomizerTest.java | 192 ------------ .../v3po/vpp/BridgeDomainCustomizerTest.java | 338 --------------------- .../hc2vpp/v3po/vpp/L2FibEntryCustomizerTest.java | 283 ----------------- .../v3po/vppstate/BridgeDomainCustomizerTest.java | 47 --- .../v3po/vppstate/L2FibEntryCustomizerTest.java | 124 -------- .../v3po/vppstate/VersionCustomizerTest.java | 60 ---- .../io/fd/hc2vpp/v3po/vppstate/VppStateTest.java | 326 -------------------- v3po/v3po2vpp/src/test/resources/v3po.json | 3 - 16 files changed, 1203 insertions(+), 1434 deletions(-) create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/ArpTerminationTableEntryCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/BridgeDomainCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/L2FibEntryCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/BridgeDomainCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/L2StateTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/rpc/CliInbandServiceTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/ArpTerminationTableEntryCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/BridgeDomainCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/L2FibEntryCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/BridgeDomainCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/L2FibEntryCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/VersionCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/VppStateTest.java delete mode 100644 v3po/v3po2vpp/src/test/resources/v3po.json (limited to 'v3po/v3po2vpp/src/test') diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/V3poModuleTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/V3poModuleTest.java index 66231b2ff..9d799d850 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/V3poModuleTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/V3poModuleTest.java @@ -19,7 +19,6 @@ package io.fd.hc2vpp.v3po; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.mockito.MockitoAnnotations.initMocks; @@ -29,7 +28,6 @@ import com.google.inject.Inject; import com.google.inject.name.Named; import com.google.inject.testing.fieldbinder.Bind; import com.google.inject.testing.fieldbinder.BoundFieldModule; -import io.fd.hc2vpp.v3po.cfgattrs.V3poConfiguration; import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.impl.read.registry.CompositeReaderRegistryBuilder; import io.fd.honeycomb.translate.impl.write.registry.FlatWriterRegistryBuilder; @@ -70,9 +68,6 @@ public class V3poModuleTest { @Inject private Set writerFactories = new HashSet<>(); - @Inject - private V3poConfiguration configuration; - @Before public void setUp() { initMocks(this); @@ -99,8 +94,5 @@ public class V3poModuleTest { assertNotNull(registryBuilder.build()); } - @Test - public void testConfiguration() { - assertEquals(30, configuration.getKeepaliveDelay()); - } + } \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/ArpTerminationTableEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/ArpTerminationTableEntryCustomizerTest.java new file mode 100644 index 000000000..29caf068b --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/ArpTerminationTableEntryCustomizerTest.java @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.l2; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.VppBaseCallException; +import io.fd.vpp.jvpp.VppInvocationException; +import io.fd.vpp.jvpp.core.dto.BdIpMacAddDel; +import io.fd.vpp.jvpp.core.dto.BdIpMacAddDelReply; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.BridgeDomains; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.ArpTerminationTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.arp.termination.table.ArpTerminationTableEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.arp.termination.table.ArpTerminationTableEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.arp.termination.table.ArpTerminationTableEntryKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomainKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class ArpTerminationTableEntryCustomizerTest extends WriterCustomizerTest { + private static final String BD_CTX_NAME = "bd-test-instance"; + private static final String IFC_CTX_NAME = "ifc-test-instance"; + + private static final String BD_NAME = "testBD0"; + private static final int BD_ID = 111; + private static final String IFACE_NAME = "eth0"; + private static final int IFACE_ID = 123; + private ArpTerminationTableEntryCustomizer customizer; + private byte[] ipAddressRaw; + private byte[] ip6AddressRaw; + private byte[] physAddressRaw; + private PhysAddress physAddress; + private IpAddress ipAddress; + private IpAddress ip6Address; + private ArpTerminationTableEntry entry; + private ArpTerminationTableEntry ip6entry; + private InstanceIdentifier id; + + private static InstanceIdentifier getArpEntryId(final IpAddress ipAddress, + final PhysAddress physAddress) { + return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(BD_NAME)) + .child(ArpTerminationTable.class) + .child(ArpTerminationTableEntry.class, new ArpTerminationTableEntryKey(ipAddress, physAddress)); + } + + @Override + public void setUpTest() throws Exception { + customizer = new ArpTerminationTableEntryCustomizer(api, new NamingContext("generatedBdName", BD_CTX_NAME)); + + ipAddressRaw = new byte[]{1, 2, 3, 4}; + ip6AddressRaw = new byte[]{32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1}; + physAddressRaw = new byte[]{1, 2, 3, 4, 5, 6}; + physAddress = new PhysAddress("01:02:03:04:05:06"); + + ipAddress = new IpAddress(Ipv4AddressNoZone.getDefaultInstance("1.2.3.4")); + ip6Address = new IpAddress(Ipv6AddressNoZone.getDefaultInstance("2001:0db8:0a0b:12f0:0000:0000:0000:0001")); + entry = generateArpEntry(ipAddress, physAddress); + ip6entry = generateArpEntry(ip6Address, physAddress); + id = getArpEntryId(ipAddress, physAddress); + + defineMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + } + + private void whenBdIpMacAddDelThenSuccess() { + doReturn(future(new BdIpMacAddDelReply())).when(api).bdIpMacAddDel(any(BdIpMacAddDel.class)); + } + + private void whenBdIpMacAddDelThenFailure() { + doReturn(failedFuture()).when(api).bdIpMacAddDel(any(BdIpMacAddDel.class)); + } + + private BdIpMacAddDel generateBdIpMacAddDelRequest(final byte[] ipAddress, final byte[] macAddress, + final byte isAdd) { + final BdIpMacAddDel request = new BdIpMacAddDel(); + request.ipAddress = ipAddress; + request.macAddress = macAddress; + request.bdId = BD_ID; + request.isAdd = isAdd; + return request; + } + + private ArpTerminationTableEntry generateArpEntry(final IpAddress ipAddress, final PhysAddress physAddress) { + final ArpTerminationTableEntryBuilder entry = new ArpTerminationTableEntryBuilder(); + entry.setKey(new ArpTerminationTableEntryKey(ipAddress, physAddress)); + entry.setPhysAddress(physAddress); + entry.setIpAddress(ipAddress); + return entry.build(); + } + + private void verifyBdIpMacAddDelWasInvoked(final BdIpMacAddDel expected) throws + VppInvocationException { + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(BdIpMacAddDel.class); + verify(api).bdIpMacAddDel(argumentCaptor.capture()); + final BdIpMacAddDel actual = argumentCaptor.getValue(); + assertArrayEquals(expected.macAddress, actual.macAddress); + assertArrayEquals(expected.ipAddress, actual.ipAddress); + assertEquals(expected.bdId, actual.bdId); + assertEquals(expected.isAdd, actual.isAdd); + } + + @Test + public void testCreate() throws Exception { + whenBdIpMacAddDelThenSuccess(); + customizer.writeCurrentAttributes(id, entry, writeContext); + verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ipAddressRaw, physAddressRaw, (byte) 1)); + } + + @Test + public void testCreateIpv6() throws Exception { + whenBdIpMacAddDelThenSuccess(); + customizer.writeCurrentAttributes(id, ip6entry, writeContext); + verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ip6AddressRaw, physAddressRaw, (byte) 1)); + } + + @Test + public void testCreateFailed() throws Exception { + whenBdIpMacAddDelThenFailure(); + try { + customizer.writeCurrentAttributes(id, entry, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ipAddressRaw, physAddressRaw, (byte) 1)); + return; + } + fail("WriteFailedException.CreateFailedException was expected"); + } + + @Test(expected = UnsupportedOperationException.class) + public void testUpdate() throws Exception { + customizer.updateCurrentAttributes(InstanceIdentifier.create(ArpTerminationTableEntry.class), + mock(ArpTerminationTableEntry.class), + mock(ArpTerminationTableEntry.class), writeContext); + } + + @Test + public void testDelete() throws Exception { + whenBdIpMacAddDelThenSuccess(); + customizer.deleteCurrentAttributes(id, entry, writeContext); + verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ipAddressRaw, physAddressRaw, (byte) 0)); + } + + @Test + public void testDeleteIpv6() throws Exception { + whenBdIpMacAddDelThenSuccess(); + customizer.deleteCurrentAttributes(id, ip6entry, writeContext); + verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ip6AddressRaw, physAddressRaw, (byte) 0)); + } + + @Test + public void testDeleteFailed() throws Exception { + whenBdIpMacAddDelThenFailure(); + try { + customizer.deleteCurrentAttributes(id, entry, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ipAddressRaw, physAddressRaw, (byte) 0)); + return; + } + fail("WriteFailedException.DeleteFailedException was expected"); + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/BridgeDomainCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/BridgeDomainCustomizerTest.java new file mode 100644 index 000000000..8bf7007fe --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/BridgeDomainCustomizerTest.java @@ -0,0 +1,338 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.l2; + +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.google.common.base.Optional; +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.VppInvocationException; +import io.fd.vpp.jvpp.core.dto.BridgeDomainAddDel; +import io.fd.vpp.jvpp.core.dto.BridgeDomainAddDelReply; +import java.util.Arrays; +import javax.annotation.Nullable; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.BridgeDomains; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomainBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomainKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.L2Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.base.attributes.interconnection.BridgeBasedBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; + +public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator { + + private static final String BD_CTX_NAME = "bd-test-instance"; + private static final byte ADD_OR_UPDATE_BD = (byte) 1; + private BridgeDomainCustomizer customizer; + + @Nullable + private static Boolean intToBoolean(final int value) { + if (value == 0) { + return Boolean.FALSE; + } + if (value == 1) { + return Boolean.TRUE; + } + return null; + } + + private static KeyedInstanceIdentifier bdIdentifierForName( + final String bdName) { + return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(bdName)); + } + + @Override + public void setUpTest() throws Exception { + customizer = new BridgeDomainCustomizer(api, new NamingContext("generatedBDName", BD_CTX_NAME)); + } + + private BridgeDomain generateBridgeDomain(final String bdName) { + final byte arpTerm = 0; + final byte flood = 1; + final byte forward = 0; + final byte learn = 1; + final byte uuf = 0; + return generateBridgeDomain(bdName, arpTerm, flood, forward, learn, uuf); + } + + private BridgeDomain generateBridgeDomain(final String bdName, final int arpTerm, final int flood, + final int forward, final int learn, final int uuf) { + return new BridgeDomainBuilder() + .setName(bdName) + .setArpTermination(intToBoolean(arpTerm)) + .setFlood(intToBoolean(flood)) + .setForward(intToBoolean(forward)) + .setLearn(intToBoolean(learn)) + .setUnknownUnicastFlood(intToBoolean(uuf)) + .build(); + } + + private void verifyBridgeDomainAddOrUpdateWasInvoked(final BridgeDomain bd, final int bdId) + throws VppInvocationException { + final BridgeDomainAddDel expected = new BridgeDomainAddDel(); + expected.arpTerm = booleanToByte(bd.isArpTermination()); + expected.flood = booleanToByte(bd.isFlood()); + expected.forward = booleanToByte(bd.isForward()); + expected.learn = booleanToByte(bd.isLearn()); + expected.uuFlood = booleanToByte(bd.isUnknownUnicastFlood()); + expected.isAdd = ADD_OR_UPDATE_BD; + expected.bdId = bdId; + verify(api).bridgeDomainAddDel(expected); + } + + private void verifyBridgeDomainDeleteWasInvoked(final int bdId) throws VppInvocationException { + final BridgeDomainAddDel expected = new BridgeDomainAddDel(); + expected.bdId = bdId; + verify(api).bridgeDomainAddDel(expected); + } + + private void whenBridgeDomainAddDelThenSuccess() { + when(api.bridgeDomainAddDel(any(BridgeDomainAddDel.class))).thenReturn(future(new BridgeDomainAddDelReply())); + } + + private void whenBridgeDomainAddDelThenFailure() { + doReturn(failedFuture()).when(api).bridgeDomainAddDel(any(BridgeDomainAddDel.class)); + } + + @Test + public void testAddBridgeDomain() throws Exception { + final int bdId = 1; + final String bdName = "bd1"; + final BridgeDomain bd = generateBridgeDomain(bdName); + noMappingDefined(mappingContext, bdName, BD_CTX_NAME); + + whenBridgeDomainAddDelThenSuccess(); + + customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); + + verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId); + verify(mappingContext).put(mappingIid(bdName, BD_CTX_NAME), mapping(bdName, bdId).get()); + } + + @Test + public void testAddBridgeDomainPresentInBdContext() throws Exception { + final int bdId = 1; + final String bdName = "bd1"; + final BridgeDomain bd = generateBridgeDomain(bdName); + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + + whenBridgeDomainAddDelThenSuccess(); + + customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); + + verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId); + verify(mappingContext).put(mappingIid(bdName, BD_CTX_NAME), mapping(bdName, bdId).get()); + } + + @Test + public void testAddBridgeDomainFailed() throws Exception { + final int bdId = 1; + final String bdName = "bd1"; + final BridgeDomain bd = generateBridgeDomain(bdName); + noMappingDefined(mappingContext, bdName, BD_CTX_NAME); + + whenBridgeDomainAddDelThenFailure(); + + try { + customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); + } catch (WriteFailedException e) { + verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId); + return; + } + fail("WriteFailedException.CreateFailedException was expected"); + } + + @Test + public void testDeleteBridgeDomain() throws Exception { + final int bdId = 1; + final String bdName = "bd1"; + final BridgeDomain bd = generateBridgeDomain(bdName); + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent()); + + whenBridgeDomainAddDelThenSuccess(); + + customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); + + verifyBridgeDomainDeleteWasInvoked(bdId); + } + + @Test + public void testDeleteReferencedBridgeDomain() throws Exception { + final int bdId = 1; + final String bdName = "bd1"; + final BridgeDomain bd = generateBridgeDomain(bdName); + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.of( + new InterfacesBuilder().setInterface(Arrays.asList(l2ReferenceToBd("bd1"), l2ReferenceToBd("other-bd"))) + .build() + )); + + try { + customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); + } catch (IllegalStateException e) { + verify(api, never()).bridgeDomainAddDel(any(BridgeDomainAddDel.class)); + return; + } + fail("IllegalStateException was expected"); + } + + @Test + public void testDeleteReferencedPartialData() throws Exception { + final int bdId = 1; + final String bdName = "bd1"; + final BridgeDomain bd = generateBridgeDomain(bdName); + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + whenBridgeDomainAddDelThenSuccess(); + when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.of( + new InterfacesBuilder().setInterface(Arrays.asList(new InterfaceBuilder() + .addAugmentation(VppInterfaceAugmentation.class, new VppInterfaceAugmentationBuilder().build()) + .build())).build() + )); + + customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); + verifyBridgeDomainDeleteWasInvoked(bdId); + } + + private static Interface l2ReferenceToBd(final String bridgeDomain) { + return new InterfaceBuilder() + .addAugmentation(VppInterfaceAugmentation.class, new VppInterfaceAugmentationBuilder() + .setL2(new L2Builder() + .setInterconnection(new BridgeBasedBuilder() + .setBridgeDomain(bridgeDomain) + .build()) + .build()) + .build()) + .build(); + } + + @Test + public void testDeleteUnknownBridgeDomain() throws Exception { + final String bdName = "bd1"; + final BridgeDomain bd = generateBridgeDomain("bd1"); + noMappingDefined(mappingContext, bdName, BD_CTX_NAME); + when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent()); + + try { + customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); + } catch (IllegalArgumentException e) { + verify(api, never()).bridgeDomainAddDel(any(BridgeDomainAddDel.class)); + return; + } + fail("IllegalArgumentException was expected"); + } + + @Test + public void testDeleteBridgeDomainFailed() throws Exception { + final int bdId = 1; + final String bdName = "bd1"; + final BridgeDomain bd = generateBridgeDomain(bdName); + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent()); + + whenBridgeDomainAddDelThenFailure(); + + try { + customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); + } catch (WriteFailedException e) { + verifyBridgeDomainDeleteWasInvoked(bdId); + return; + } + + fail("WriteFailedException.DeleteFailedException was expected"); + } + + @Test + public void testUpdateBridgeDomain() throws Exception { + final int bdId = 1; + final String bdName = "bd1"; + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + + final byte arpTermBefore = 1; + final byte floodBefore = 1; + final byte forwardBefore = 0; + final byte learnBefore = 1; + final byte uufBefore = 0; + + final BridgeDomain dataBefore = + generateBridgeDomain(bdName, arpTermBefore, floodBefore, forwardBefore, learnBefore, uufBefore); + final BridgeDomain dataAfter = + generateBridgeDomain(bdName, arpTermBefore ^ 1, floodBefore ^ 1, forwardBefore ^ 1, learnBefore ^ 1, + uufBefore ^ 1); + + whenBridgeDomainAddDelThenSuccess(); + + customizer + .updateCurrentAttributes(bdIdentifierForName(bdName), dataBefore, dataAfter, + writeContext); + verifyBridgeDomainAddOrUpdateWasInvoked(dataAfter, bdId); + } + + @Test + public void testUpdateUnknownBridgeDomain() throws Exception { + final String bdName = "bd1"; + final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0, 1, 0); + final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0, 1, 0); + noMappingDefined(mappingContext, bdName, BD_CTX_NAME); + + try { + customizer + .updateCurrentAttributes(bdIdentifierForName(bdName), bdBefore, bdAfter, + writeContext); + } catch (IllegalArgumentException e) { + verify(api, never()).bridgeDomainAddDel(any(BridgeDomainAddDel.class)); + return; + } + fail("IllegalArgumentException was expected"); + } + + @Test + public void testUpdateBridgeDomainFailed() throws Exception { + final int bdId = 1; + final String bdName = "bd1"; + final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0, 1, 0); + final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0, 1, 0); + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + + whenBridgeDomainAddDelThenFailure(); + + try { + customizer.updateCurrentAttributes(bdIdentifierForName(bdName), bdBefore, bdAfter, writeContext); + } catch (WriteFailedException e) { + verifyBridgeDomainAddOrUpdateWasInvoked(bdAfter, bdId); + return; + } + fail("IllegalStateException was expected"); + } + +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/L2FibEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/L2FibEntryCustomizerTest.java new file mode 100644 index 000000000..b00e9e7e2 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/L2FibEntryCustomizerTest.java @@ -0,0 +1,283 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.l2; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.VppBaseCallException; +import io.fd.vpp.jvpp.VppInvocationException; +import io.fd.vpp.jvpp.core.dto.L2FibAddDel; +import io.fd.vpp.jvpp.core.dto.L2FibAddDelReply; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.BridgeDomains; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.L2FibFilter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.L2FibForward; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomainKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class L2FibEntryCustomizerTest extends WriterCustomizerTest { + private static final String BD_CTX_NAME = "bd-test-instance"; + private static final String IFC_CTX_NAME = "ifc-test-instance"; + + private static final String BD_NAME = "testBD0"; + private static final int BD_ID = 111; + private static final String IFACE_NAME = "eth0"; + private static final int IFACE_ID = 123; + private static final int NO_INTERFACE = -1; + + private L2FibEntryCustomizer customizer; + + private static InstanceIdentifier getL2FibEntryId(final PhysAddress address) { + return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(BD_NAME)) + .child(L2FibTable.class).child(L2FibEntry.class, new L2FibEntryKey(address)); + } + + @Override + public void setUpTest() throws Exception { + defineMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + + customizer = new L2FibEntryCustomizer( + api, + new NamingContext("generatedBdName", BD_CTX_NAME), + new NamingContext("generatedIfaceName", IFC_CTX_NAME)); + } + + private void whenL2FibAddDelThenSuccess() { + doReturn(future(new L2FibAddDelReply())).when(api).l2FibAddDel(any(L2FibAddDel.class)); + } + + private void whenL2FibAddDelThenFailure() { + doReturn(failedFuture()).when(api).l2FibAddDel(any(L2FibAddDel.class)); + } + + private L2FibAddDel generateL2FibAddDelFilterRequest(final long mac, final byte isAdd, final int ifaceIndex) { + final L2FibAddDel request = new L2FibAddDel(); + request.mac = mac; + request.bdId = BD_ID; + request.swIfIndex = ifaceIndex; + request.isAdd = isAdd; + if (isAdd == 1) { + request.staticMac = 1; + request.filterMac = 1; + } + return request; + } + + private L2FibAddDel generateL2FibAddDelForwardRequest(final long mac, final byte isAdd, final int ifaceIndex) { + final L2FibAddDel request = new L2FibAddDel(); + request.mac = mac; + request.bdId = BD_ID; + request.swIfIndex = ifaceIndex; + request.isAdd = isAdd; + if (isAdd == 1) { + request.staticMac = 1; + request.filterMac = 0; + } + return request; + } + + private L2FibEntry generateL2FibFilterEntry(final PhysAddress address) { + final L2FibEntryBuilder entry = new L2FibEntryBuilder(); + entry.setKey(new L2FibEntryKey(address)); + entry.setPhysAddress(address); + entry.setStaticConfig(true); + entry.setBridgedVirtualInterface(false); + entry.setAction(L2FibFilter.class); + return entry.build(); + } + + private L2FibEntry generateL2FibForwardEntry(final PhysAddress address) { + final L2FibEntryBuilder entry = new L2FibEntryBuilder(); + entry.setKey(new L2FibEntryKey(address)); + entry.setPhysAddress(address); + entry.setStaticConfig(true); + entry.setBridgedVirtualInterface(false); + entry.setAction(L2FibForward.class); + entry.setOutgoingInterface(IFACE_NAME); + return entry.build(); + } + + + private void verifyL2FibAddDelWasInvoked(final L2FibAddDel expected) throws + VppInvocationException { + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(L2FibAddDel.class); + verify(api).l2FibAddDel(argumentCaptor.capture()); + final L2FibAddDel actual = argumentCaptor.getValue(); + assertEquals(expected.mac, actual.mac); + assertEquals(expected.bdId, actual.bdId); + assertEquals(expected.swIfIndex, actual.swIfIndex); + assertEquals(expected.isAdd, actual.isAdd); + assertEquals(expected.staticMac, actual.staticMac); + assertEquals(expected.filterMac, actual.filterMac); + } + + @Test + public void testCreateFilter() throws Exception { + final long address_vpp = 0x0102030405060000L; + final PhysAddress address = new PhysAddress("01:02:03:04:05:06"); + final L2FibEntry entry = generateL2FibFilterEntry(address); + final InstanceIdentifier id = getL2FibEntryId(address); + + whenL2FibAddDelThenSuccess(); + + customizer.writeCurrentAttributes(id, entry, writeContext); + + verifyL2FibAddDelWasInvoked(generateL2FibAddDelFilterRequest(address_vpp, (byte) 1, NO_INTERFACE)); + } + + @Test + public void testCreateForward() throws Exception { + final long address_vpp = 0x0102030405060000L; + final PhysAddress address = new PhysAddress("01:02:03:04:05:06"); + final L2FibEntry entry = generateL2FibForwardEntry(address); + final InstanceIdentifier id = getL2FibEntryId(address); + + whenL2FibAddDelThenSuccess(); + + customizer.writeCurrentAttributes(id, entry, writeContext); + + verifyL2FibAddDelWasInvoked(generateL2FibAddDelForwardRequest(address_vpp, (byte) 1, IFACE_ID)); + } + + @Test + public void testCreateFilterFailed() throws Exception { + final long address_vpp = 0x1122334455660000L; + final PhysAddress address = new PhysAddress("11:22:33:44:55:66"); + final L2FibEntry entry = generateL2FibFilterEntry(address); + final InstanceIdentifier id = getL2FibEntryId(address); + + whenL2FibAddDelThenFailure(); + + try { + customizer.writeCurrentAttributes(id, entry, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verifyL2FibAddDelWasInvoked(generateL2FibAddDelFilterRequest(address_vpp, (byte) 1, NO_INTERFACE)); + return; + } + fail("WriteFailedException.CreateFailedException was expected"); + } + + @Test + public void testCreateForwardFailed() throws Exception { + final long address_vpp = 0x1122334455660000L; + final PhysAddress address = new PhysAddress("11:22:33:44:55:66"); + final L2FibEntry entry = generateL2FibForwardEntry(address); + final InstanceIdentifier id = getL2FibEntryId(address); + + whenL2FibAddDelThenFailure(); + + try { + customizer.writeCurrentAttributes(id, entry, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verifyL2FibAddDelWasInvoked(generateL2FibAddDelForwardRequest(address_vpp, (byte) 1, IFACE_ID)); + return; + } + fail("WriteFailedException.CreateFailedException was expected"); + } + + @Test(expected = UnsupportedOperationException.class) + public void testUpdate() throws Exception { + customizer.updateCurrentAttributes(InstanceIdentifier.create(L2FibEntry.class), mock(L2FibEntry.class), + mock(L2FibEntry.class), writeContext); + } + + @Test + public void testDeleteFilter() throws Exception { + final long address_vpp = 0x1122334455660000L; + final PhysAddress address = new PhysAddress("11:22:33:44:55:66"); + final L2FibEntry entry = generateL2FibFilterEntry(address); + final InstanceIdentifier id = getL2FibEntryId(address); + + whenL2FibAddDelThenSuccess(); + + customizer.deleteCurrentAttributes(id, entry, writeContext); + + verifyL2FibAddDelWasInvoked(generateL2FibAddDelFilterRequest(address_vpp, (byte) 0, NO_INTERFACE)); + } + + @Test + public void testDeleteForward() throws Exception { + final long address_vpp = 0x1122334455660000L; + final PhysAddress address = new PhysAddress("11:22:33:44:55:66"); + final L2FibEntry entry = generateL2FibForwardEntry(address); + final InstanceIdentifier id = getL2FibEntryId(address); + + whenL2FibAddDelThenSuccess(); + + customizer.deleteCurrentAttributes(id, entry, writeContext); + + verifyL2FibAddDelWasInvoked(generateL2FibAddDelForwardRequest(address_vpp, (byte) 0, IFACE_ID)); + } + + + @Test + public void testDeleteFilterFailed() throws Exception { + final long address_vpp = 0x0102030405060000L; + final PhysAddress address = new PhysAddress("01:02:03:04:05:06"); + final L2FibEntry entry = generateL2FibFilterEntry(address); + final InstanceIdentifier id = getL2FibEntryId(address); + + whenL2FibAddDelThenFailure(); + + try { + customizer.deleteCurrentAttributes(id, entry, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verifyL2FibAddDelWasInvoked(generateL2FibAddDelFilterRequest(address_vpp, (byte) 0, NO_INTERFACE)); + return; + } + fail("WriteFailedException.DeleteFailedException was expected"); + } + + @Test + public void testDeleteForwardFailed() throws Exception { + final long address_vpp = 0x0102030405060000L; + final PhysAddress address = new PhysAddress("01:02:03:04:05:06"); + final L2FibEntry entry = generateL2FibForwardEntry(address); + final InstanceIdentifier id = getL2FibEntryId(address); + + whenL2FibAddDelThenFailure(); + + try { + customizer.deleteCurrentAttributes(id, entry, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verifyL2FibAddDelWasInvoked(generateL2FibAddDelForwardRequest(address_vpp, (byte) 0, IFACE_ID)); + return; + } + fail("WriteFailedException.DeleteFailedException was expected"); + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/BridgeDomainCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/BridgeDomainCustomizerTest.java new file mode 100644 index 000000000..98e0cde08 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/BridgeDomainCustomizerTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.l2state; + +import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.BridgeDomainsStateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomainBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomainKey; + + +public class BridgeDomainCustomizerTest + extends ListReaderCustomizerTest { + + private NamingContext bdContext; + private NamingContext interfacesContext; + + public BridgeDomainCustomizerTest() { + super(BridgeDomain.class, BridgeDomainsStateBuilder.class); + } + + @Override + public void setUp() { + bdContext = new NamingContext("generatedBdName", "bd-test-instance"); + interfacesContext = new NamingContext("generatedIfaceName", "ifc-test-instance"); + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new BridgeDomainCustomizer(api, bdContext); + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizerTest.java new file mode 100644 index 000000000..836653b28 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizerTest.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.l2state; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.ExecutionException; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.BridgeDomains; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.BridgeDomainsState; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.L2FibForward; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomainKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import io.fd.vpp.jvpp.VppInvocationException; +import io.fd.vpp.jvpp.core.dto.L2FibTableDump; +import io.fd.vpp.jvpp.core.dto.L2FibTableEntry; +import io.fd.vpp.jvpp.core.dto.L2FibTableEntryReplyDump; + +public class L2FibEntryCustomizerTest extends ListReaderCustomizerTest { + + private static final String BD_NAME = "testBD0"; + private static final int BD_ID = 111; + private static final String IFACE_NAME = "eth0"; + private static final int IFACE_ID = 123; + private static final String BD_CTX_NAME = "bd-test-instance"; + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private NamingContext bdContext; + private NamingContext interfacesContext; + + public L2FibEntryCustomizerTest() { + super(L2FibEntry.class, L2FibTableBuilder.class); + } + + @Override + public void setUp() { + bdContext = new NamingContext("generatedBdName", BD_CTX_NAME); + defineMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME); + interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new L2FibEntryCustomizer(api, bdContext, interfacesContext); + } + + private static InstanceIdentifier getL2FibEntryId(final String bdName, final PhysAddress address) { + return InstanceIdentifier.create(BridgeDomainsState.class).child(BridgeDomain.class, new BridgeDomainKey(bdName)) + .child(L2FibTable.class).child(L2FibEntry.class, new L2FibEntryKey(address)); + } + + private void whenL2FibTableDumpThenReturn(final List l2FibTableEntryList) + throws ExecutionException, InterruptedException, VppInvocationException { + final L2FibTableEntryReplyDump reply = new L2FibTableEntryReplyDump(); + reply.l2FibTableEntry = l2FibTableEntryList; + when(api.l2FibTableDump(any(L2FibTableDump.class))).thenReturn(future(reply)); + } + + @Test + public void testRead() throws Exception { + final long address_vpp = 0x0000010203040506L; + final PhysAddress address = new PhysAddress("01:02:03:04:05:06"); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + + whenL2FibTableDumpThenReturn(Collections.singletonList(generateL2FibEntry(address_vpp))); + + final L2FibEntryBuilder builder = mock(L2FibEntryBuilder.class); + getCustomizer().readCurrentAttributes(getL2FibEntryId(BD_NAME, address), builder, ctx); + + verify(builder).setAction(L2FibForward.class); + verify(builder).setBridgedVirtualInterface(false); + verify(builder).setOutgoingInterface(IFACE_NAME); + verify(builder).setStaticConfig(false); + verify(builder).setPhysAddress(address); + verify(builder).setKey(new L2FibEntryKey(address)); + } + + private L2FibTableEntry generateL2FibEntry(final long mac) { + final L2FibTableEntry entry = new L2FibTableEntry(); + entry.mac = mac; + entry.swIfIndex = IFACE_ID; + return entry; + } + + @Test + public void testGetAllIds() throws Exception { + final long address_vpp = 0x0000112233445566L; + final PhysAddress address = new PhysAddress("11:22:33:44:55:66"); + + whenL2FibTableDumpThenReturn(Collections.singletonList(generateL2FibEntry(address_vpp))); + + final List ids = getCustomizer().getAllIds(getL2FibEntryId(BD_NAME, address), ctx); + assertEquals(1, ids.size()); + assertEquals(address, ids.get(0).getPhysAddress()); + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/L2StateTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/L2StateTest.java new file mode 100644 index 000000000..9a0d0e4c8 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/L2StateTest.java @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.l2state; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import com.google.common.base.Optional; +import com.google.common.collect.Iterables; +import com.google.common.collect.Multimap; +import io.fd.hc2vpp.common.test.util.FutureProducer; +import io.fd.hc2vpp.common.test.util.NamingContextHelper; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.MappingContext; +import io.fd.honeycomb.translate.ModificationCache; +import io.fd.honeycomb.translate.impl.read.GenericListReader; +import io.fd.honeycomb.translate.impl.read.registry.CompositeReaderRegistryBuilder; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.read.registry.ReaderRegistry; +import io.fd.vpp.jvpp.core.dto.BridgeDomainDetails; +import io.fd.vpp.jvpp.core.dto.BridgeDomainDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.BridgeDomainDump; +import io.fd.vpp.jvpp.core.dto.L2FibTableDump; +import io.fd.vpp.jvpp.core.dto.L2FibTableEntry; +import io.fd.vpp.jvpp.core.dto.L2FibTableEntryReplyDump; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import javax.annotation.Nonnull; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.BridgeDomainsState; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.BridgeDomainsStateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomainBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomainKey; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class L2StateTest implements FutureProducer, NamingContextHelper { + + private static final String BD_CTX_NAME = "bd-test-instance"; + @Mock + private FutureJVppCore api; + @Mock + private ReadContext ctx; + @Mock + private MappingContext mappingContext; + + private NamingContext bdContext; + + private ReaderRegistry readerRegistry; + + private static InstanceIdentifier bridgeDomainsId; + + /** + * Create root VppState reader with all its children wired. + */ + private static ReaderRegistry getVppStateReader(@Nonnull final FutureJVppCore jVpp, + @Nonnull final NamingContext bdContext) { + final CompositeReaderRegistryBuilder registry = new CompositeReaderRegistryBuilder(); + + // BridgeDomains(Structural) + bridgeDomainsId = InstanceIdentifier.create(BridgeDomainsState.class); + registry.addStructuralReader(bridgeDomainsId, BridgeDomainsStateBuilder.class); + // BridgeDomain + registry.add(getBridgeDomainReader(jVpp, bdContext)); + return registry.build(); + } + + private static GenericListReader getBridgeDomainReader( + final @Nonnull FutureJVppCore jVpp, final @Nonnull NamingContext bdContext) { + final InstanceIdentifier bridgeDomainId = bridgeDomainsId.child(BridgeDomain.class); + return new GenericListReader<>(bridgeDomainId, new BridgeDomainCustomizer(jVpp, bdContext)); + } + + @Before + public void setUp() throws Exception { + initMocks(this); + final ModificationCache cache = new ModificationCache(); + doReturn(cache).when(ctx).getModificationCache(); + doReturn(mappingContext).when(ctx).getMappingContext(); + + bdContext = new NamingContext("generatedBdName", BD_CTX_NAME); + readerRegistry = getVppStateReader(api, bdContext); + } + + private void whenL2FibTableDumpThenReturn(final List entryList) { + final L2FibTableEntryReplyDump reply = new L2FibTableEntryReplyDump(); + reply.l2FibTableEntry = entryList; + when(api.l2FibTableDump(any(L2FibTableDump.class))).thenReturn(future(reply)); + } + + private void whenBridgeDomainDumpThenReturn(final List bdList) { + final BridgeDomainDetailsReplyDump reply = new BridgeDomainDetailsReplyDump(); + reply.bridgeDomainDetails = bdList; + + doAnswer(invocation -> { + BridgeDomainDump request = (BridgeDomainDump) invocation.getArguments()[0]; + if (request.bdId == -1) { + reply.bridgeDomainDetails = bdList; + } else { + reply.bridgeDomainDetails = Collections.singletonList(bdList.get(request.bdId)); + } + return future(reply); + }).when(api).bridgeDomainDump(any(BridgeDomainDump.class)); + } + + @Test + public void testReadAll() throws Exception { + final BridgeDomainDetails bridgeDomainDetails = new BridgeDomainDetails(); + final BridgeDomainDetails bridgeDomainDetails2 = new BridgeDomainDetails(); + bridgeDomainDetails2.bdId = 1; + + final List bdList = Arrays.asList(bridgeDomainDetails, bridgeDomainDetails2); + mockBdMapping(bridgeDomainDetails, "bd1"); + mockBdMapping(bridgeDomainDetails2, "bd2"); + + whenBridgeDomainDumpThenReturn(bdList); + + final Multimap, ? extends DataObject> dataObjects = + readerRegistry.readAll(ctx); + assertEquals(dataObjects.size(), 1); + final BridgeDomainsState dataObject = + (BridgeDomainsState) Iterables.getOnlyElement(dataObjects.get(Iterables.getOnlyElement(dataObjects.keySet()))); + assertEquals(2, dataObject.getBridgeDomain().size()); + } + + @Test + public void testReadBridgeDomains() throws Exception { + final BridgeDomainDetails details = new BridgeDomainDetails(); + whenBridgeDomainDumpThenReturn(Collections.singletonList(details)); + + mockBdMapping(details, "bdn1"); + BridgeDomainsState readRoot = (BridgeDomainsState) readerRegistry.read(InstanceIdentifier.create(BridgeDomainsState.class), ctx).get(); + + Optional read = + readerRegistry.read(InstanceIdentifier.create(BridgeDomainsState.class), ctx); + assertTrue(read.isPresent()); + assertEquals(readRoot.getBridgeDomain(), BridgeDomainsState.class.cast(read.get()).getBridgeDomain()); + } + + private void mockBdMapping(final BridgeDomainDetails bd, final String bdName) { + defineMapping(mappingContext, bdName, bd.bdId, BD_CTX_NAME); + } + + @Test + public void testReadBridgeDomainAll() throws Exception { + final BridgeDomainDetails details = new BridgeDomainDetails(); + whenBridgeDomainDumpThenReturn(Collections.singletonList(details)); + mockBdMapping(details, "bd2"); + + BridgeDomainsState readRoot = (BridgeDomainsState) readerRegistry.read(InstanceIdentifier.create(BridgeDomainsState.class), ctx).get(); + + final GenericListReader bridgeDomainReader = + getBridgeDomainReader(api, bdContext); + + final List read = + bridgeDomainReader.readList(InstanceIdentifier.create(BridgeDomainsState.class).child( + BridgeDomain.class), ctx); + + assertEquals(readRoot.getBridgeDomain(), read); + } + + @Test + public void testReadBridgeDomain() throws Exception { + final BridgeDomainDetails bd = new BridgeDomainDetails(); + bd.bdId = 0; + final String bdName = "bdn1"; + mockBdMapping(bd, bdName); + + whenBridgeDomainDumpThenReturn(Collections.singletonList(bd)); + + BridgeDomainsState readRoot = (BridgeDomainsState) readerRegistry.read(InstanceIdentifier.create(BridgeDomainsState.class), ctx).get(); + + final Optional read = + readerRegistry.read(InstanceIdentifier.create(BridgeDomainsState.class).child( + BridgeDomain.class, new BridgeDomainKey(bdName)), ctx); + + assertTrue(read.isPresent()); + assertEquals(readRoot.getBridgeDomain().stream().filter( + input -> input.getKey().getName().equals(bdName)).findFirst().get(), + read.get()); + } + + @Test(expected = ReadFailedException.class) + public void testReadBridgeDomainNotExisting() throws Exception { + final String nonExistingBdName = "NOT EXISTING"; + noMappingDefined(mappingContext, nonExistingBdName, BD_CTX_NAME); + + readerRegistry.read(InstanceIdentifier.create(BridgeDomainsState.class).child( + BridgeDomain.class, new BridgeDomainKey(nonExistingBdName)), ctx); + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/rpc/CliInbandServiceTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/rpc/CliInbandServiceTest.java deleted file mode 100644 index baedba6fc..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/rpc/CliInbandServiceTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.rpc; - -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -import io.fd.hc2vpp.common.test.util.FutureProducer; -import io.fd.vpp.jvpp.core.dto.CliInbandReply; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.CliInbandInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.CliInbandInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.CliInbandOutput; - -public class CliInbandServiceTest implements FutureProducer { - - @Mock - private FutureJVppCore api; - - @Test - public void testInvoke() throws Exception { - initMocks(this); - final String replyString = "CLI output"; - - final CliInbandService service = new CliInbandService(api); - final CliInbandReply reply = new CliInbandReply(); - reply.reply = replyString.getBytes(); - when(api.cliInband(any())).thenReturn(future(reply)); - - final CliInbandInput request = new CliInbandInputBuilder().setCmd("cmd").build(); - final CliInbandOutput response = service.invoke(request).toCompletableFuture().get(); - assertEquals(replyString, response.getReply()); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/ArpTerminationTableEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/ArpTerminationTableEntryCustomizerTest.java deleted file mode 100644 index c1dd5b170..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/ArpTerminationTableEntryCustomizerTest.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.vpp; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.vpp.jvpp.VppBaseCallException; -import io.fd.vpp.jvpp.VppInvocationException; -import io.fd.vpp.jvpp.core.dto.BdIpMacAddDel; -import io.fd.vpp.jvpp.core.dto.BdIpMacAddDelReply; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.ArpTerminationTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.arp.termination.table.ArpTerminationTableEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.arp.termination.table.ArpTerminationTableEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.arp.termination.table.ArpTerminationTableEntryKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.BridgeDomains; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomain; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomainKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class ArpTerminationTableEntryCustomizerTest extends WriterCustomizerTest { - private static final String BD_CTX_NAME = "bd-test-instance"; - private static final String IFC_CTX_NAME = "ifc-test-instance"; - - private static final String BD_NAME = "testBD0"; - private static final int BD_ID = 111; - private static final String IFACE_NAME = "eth0"; - private static final int IFACE_ID = 123; - private ArpTerminationTableEntryCustomizer customizer; - private byte[] ipAddressRaw; - private byte[] ip6AddressRaw; - private byte[] physAddressRaw; - private PhysAddress physAddress; - private IpAddress ipAddress; - private IpAddress ip6Address; - private ArpTerminationTableEntry entry; - private ArpTerminationTableEntry ip6entry; - private InstanceIdentifier id; - - private static InstanceIdentifier getArpEntryId(final IpAddress ipAddress, - final PhysAddress physAddress) { - return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(BD_NAME)) - .child(ArpTerminationTable.class) - .child(ArpTerminationTableEntry.class, new ArpTerminationTableEntryKey(ipAddress, physAddress)); - } - - @Override - public void setUpTest() throws Exception { - customizer = new ArpTerminationTableEntryCustomizer(api, new NamingContext("generatedBdName", BD_CTX_NAME)); - - ipAddressRaw = new byte[]{1, 2, 3, 4}; - ip6AddressRaw = new byte[]{32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1}; - physAddressRaw = new byte[]{1, 2, 3, 4, 5, 6}; - physAddress = new PhysAddress("01:02:03:04:05:06"); - - ipAddress = new IpAddress(Ipv4AddressNoZone.getDefaultInstance("1.2.3.4")); - ip6Address = new IpAddress(Ipv6AddressNoZone.getDefaultInstance("2001:0db8:0a0b:12f0:0000:0000:0000:0001")); - entry = generateArpEntry(ipAddress, physAddress); - ip6entry = generateArpEntry(ip6Address, physAddress); - id = getArpEntryId(ipAddress, physAddress); - - defineMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME); - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - } - - private void whenBdIpMacAddDelThenSuccess() { - doReturn(future(new BdIpMacAddDelReply())).when(api).bdIpMacAddDel(any(BdIpMacAddDel.class)); - } - - private void whenBdIpMacAddDelThenFailure() { - doReturn(failedFuture()).when(api).bdIpMacAddDel(any(BdIpMacAddDel.class)); - } - - private BdIpMacAddDel generateBdIpMacAddDelRequest(final byte[] ipAddress, final byte[] macAddress, - final byte isAdd) { - final BdIpMacAddDel request = new BdIpMacAddDel(); - request.ipAddress = ipAddress; - request.macAddress = macAddress; - request.bdId = BD_ID; - request.isAdd = isAdd; - return request; - } - - private ArpTerminationTableEntry generateArpEntry(final IpAddress ipAddress, final PhysAddress physAddress) { - final ArpTerminationTableEntryBuilder entry = new ArpTerminationTableEntryBuilder(); - entry.setKey(new ArpTerminationTableEntryKey(ipAddress, physAddress)); - entry.setPhysAddress(physAddress); - entry.setIpAddress(ipAddress); - return entry.build(); - } - - private void verifyBdIpMacAddDelWasInvoked(final BdIpMacAddDel expected) throws - VppInvocationException { - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(BdIpMacAddDel.class); - verify(api).bdIpMacAddDel(argumentCaptor.capture()); - final BdIpMacAddDel actual = argumentCaptor.getValue(); - assertArrayEquals(expected.macAddress, actual.macAddress); - assertArrayEquals(expected.ipAddress, actual.ipAddress); - assertEquals(expected.bdId, actual.bdId); - assertEquals(expected.isAdd, actual.isAdd); - } - - @Test - public void testCreate() throws Exception { - whenBdIpMacAddDelThenSuccess(); - customizer.writeCurrentAttributes(id, entry, writeContext); - verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ipAddressRaw, physAddressRaw, (byte) 1)); - } - - @Test - public void testCreateIpv6() throws Exception { - whenBdIpMacAddDelThenSuccess(); - customizer.writeCurrentAttributes(id, ip6entry, writeContext); - verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ip6AddressRaw, physAddressRaw, (byte) 1)); - } - - @Test - public void testCreateFailed() throws Exception { - whenBdIpMacAddDelThenFailure(); - try { - customizer.writeCurrentAttributes(id, entry, writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ipAddressRaw, physAddressRaw, (byte) 1)); - return; - } - fail("WriteFailedException.CreateFailedException was expected"); - } - - @Test(expected = UnsupportedOperationException.class) - public void testUpdate() throws Exception { - customizer.updateCurrentAttributes(InstanceIdentifier.create(ArpTerminationTableEntry.class), - mock(ArpTerminationTableEntry.class), - mock(ArpTerminationTableEntry.class), writeContext); - } - - @Test - public void testDelete() throws Exception { - whenBdIpMacAddDelThenSuccess(); - customizer.deleteCurrentAttributes(id, entry, writeContext); - verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ipAddressRaw, physAddressRaw, (byte) 0)); - } - - @Test - public void testDeleteIpv6() throws Exception { - whenBdIpMacAddDelThenSuccess(); - customizer.deleteCurrentAttributes(id, ip6entry, writeContext); - verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ip6AddressRaw, physAddressRaw, (byte) 0)); - } - - @Test - public void testDeleteFailed() throws Exception { - whenBdIpMacAddDelThenFailure(); - try { - customizer.deleteCurrentAttributes(id, entry, writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ipAddressRaw, physAddressRaw, (byte) 0)); - return; - } - fail("WriteFailedException.DeleteFailedException was expected"); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/BridgeDomainCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/BridgeDomainCustomizerTest.java deleted file mode 100644 index 25b398fab..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/BridgeDomainCustomizerTest.java +++ /dev/null @@ -1,338 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.vpp; - -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import com.google.common.base.Optional; -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.vpp.jvpp.VppInvocationException; -import io.fd.vpp.jvpp.core.dto.BridgeDomainAddDel; -import io.fd.vpp.jvpp.core.dto.BridgeDomainAddDelReply; -import java.util.Arrays; -import javax.annotation.Nullable; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceAugmentationBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.L2Builder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.base.attributes.interconnection.BridgeBasedBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.BridgeDomains; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomain; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomainBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomainKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; - -public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator { - - private static final String BD_CTX_NAME = "bd-test-instance"; - private static final byte ADD_OR_UPDATE_BD = (byte) 1; - private BridgeDomainCustomizer customizer; - - @Nullable - private static Boolean intToBoolean(final int value) { - if (value == 0) { - return Boolean.FALSE; - } - if (value == 1) { - return Boolean.TRUE; - } - return null; - } - - private static KeyedInstanceIdentifier bdIdentifierForName( - final String bdName) { - return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(bdName)); - } - - @Override - public void setUpTest() throws Exception { - customizer = new BridgeDomainCustomizer(api, new NamingContext("generatedBDName", BD_CTX_NAME)); - } - - private BridgeDomain generateBridgeDomain(final String bdName) { - final byte arpTerm = 0; - final byte flood = 1; - final byte forward = 0; - final byte learn = 1; - final byte uuf = 0; - return generateBridgeDomain(bdName, arpTerm, flood, forward, learn, uuf); - } - - private BridgeDomain generateBridgeDomain(final String bdName, final int arpTerm, final int flood, - final int forward, final int learn, final int uuf) { - return new BridgeDomainBuilder() - .setName(bdName) - .setArpTermination(intToBoolean(arpTerm)) - .setFlood(intToBoolean(flood)) - .setForward(intToBoolean(forward)) - .setLearn(intToBoolean(learn)) - .setUnknownUnicastFlood(intToBoolean(uuf)) - .build(); - } - - private void verifyBridgeDomainAddOrUpdateWasInvoked(final BridgeDomain bd, final int bdId) - throws VppInvocationException { - final BridgeDomainAddDel expected = new BridgeDomainAddDel(); - expected.arpTerm = booleanToByte(bd.isArpTermination()); - expected.flood = booleanToByte(bd.isFlood()); - expected.forward = booleanToByte(bd.isForward()); - expected.learn = booleanToByte(bd.isLearn()); - expected.uuFlood = booleanToByte(bd.isUnknownUnicastFlood()); - expected.isAdd = ADD_OR_UPDATE_BD; - expected.bdId = bdId; - verify(api).bridgeDomainAddDel(expected); - } - - private void verifyBridgeDomainDeleteWasInvoked(final int bdId) throws VppInvocationException { - final BridgeDomainAddDel expected = new BridgeDomainAddDel(); - expected.bdId = bdId; - verify(api).bridgeDomainAddDel(expected); - } - - private void whenBridgeDomainAddDelThenSuccess() { - when(api.bridgeDomainAddDel(any(BridgeDomainAddDel.class))).thenReturn(future(new BridgeDomainAddDelReply())); - } - - private void whenBridgeDomainAddDelThenFailure() { - doReturn(failedFuture()).when(api).bridgeDomainAddDel(any(BridgeDomainAddDel.class)); - } - - @Test - public void testAddBridgeDomain() throws Exception { - final int bdId = 1; - final String bdName = "bd1"; - final BridgeDomain bd = generateBridgeDomain(bdName); - noMappingDefined(mappingContext, bdName, BD_CTX_NAME); - - whenBridgeDomainAddDelThenSuccess(); - - customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); - - verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId); - verify(mappingContext).put(mappingIid(bdName, BD_CTX_NAME), mapping(bdName, bdId).get()); - } - - @Test - public void testAddBridgeDomainPresentInBdContext() throws Exception { - final int bdId = 1; - final String bdName = "bd1"; - final BridgeDomain bd = generateBridgeDomain(bdName); - defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); - - whenBridgeDomainAddDelThenSuccess(); - - customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); - - verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId); - verify(mappingContext).put(mappingIid(bdName, BD_CTX_NAME), mapping(bdName, bdId).get()); - } - - @Test - public void testAddBridgeDomainFailed() throws Exception { - final int bdId = 1; - final String bdName = "bd1"; - final BridgeDomain bd = generateBridgeDomain(bdName); - noMappingDefined(mappingContext, bdName, BD_CTX_NAME); - - whenBridgeDomainAddDelThenFailure(); - - try { - customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); - } catch (WriteFailedException e) { - verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId); - return; - } - fail("WriteFailedException.CreateFailedException was expected"); - } - - @Test - public void testDeleteBridgeDomain() throws Exception { - final int bdId = 1; - final String bdName = "bd1"; - final BridgeDomain bd = generateBridgeDomain(bdName); - defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); - when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent()); - - whenBridgeDomainAddDelThenSuccess(); - - customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); - - verifyBridgeDomainDeleteWasInvoked(bdId); - } - - @Test - public void testDeleteReferencedBridgeDomain() throws Exception { - final int bdId = 1; - final String bdName = "bd1"; - final BridgeDomain bd = generateBridgeDomain(bdName); - defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); - when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.of( - new InterfacesBuilder().setInterface(Arrays.asList(l2ReferenceToBd("bd1"), l2ReferenceToBd("other-bd"))) - .build() - )); - - try { - customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); - } catch (IllegalStateException e) { - verify(api, never()).bridgeDomainAddDel(any(BridgeDomainAddDel.class)); - return; - } - fail("IllegalStateException was expected"); - } - - @Test - public void testDeleteReferencedPartialData() throws Exception { - final int bdId = 1; - final String bdName = "bd1"; - final BridgeDomain bd = generateBridgeDomain(bdName); - defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); - whenBridgeDomainAddDelThenSuccess(); - when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.of( - new InterfacesBuilder().setInterface(Arrays.asList(new InterfaceBuilder() - .addAugmentation(VppInterfaceAugmentation.class, new VppInterfaceAugmentationBuilder().build()) - .build())).build() - )); - - customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); - verifyBridgeDomainDeleteWasInvoked(bdId); - } - - private static Interface l2ReferenceToBd(final String bridgeDomain) { - return new InterfaceBuilder() - .addAugmentation(VppInterfaceAugmentation.class, new VppInterfaceAugmentationBuilder() - .setL2(new L2Builder() - .setInterconnection(new BridgeBasedBuilder() - .setBridgeDomain(bridgeDomain) - .build()) - .build()) - .build()) - .build(); - } - - @Test - public void testDeleteUnknownBridgeDomain() throws Exception { - final String bdName = "bd1"; - final BridgeDomain bd = generateBridgeDomain("bd1"); - noMappingDefined(mappingContext, bdName, BD_CTX_NAME); - when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent()); - - try { - customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); - } catch (IllegalArgumentException e) { - verify(api, never()).bridgeDomainAddDel(any(BridgeDomainAddDel.class)); - return; - } - fail("IllegalArgumentException was expected"); - } - - @Test - public void testDeleteBridgeDomainFailed() throws Exception { - final int bdId = 1; - final String bdName = "bd1"; - final BridgeDomain bd = generateBridgeDomain(bdName); - defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); - when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent()); - - whenBridgeDomainAddDelThenFailure(); - - try { - customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); - } catch (WriteFailedException e) { - verifyBridgeDomainDeleteWasInvoked(bdId); - return; - } - - fail("WriteFailedException.DeleteFailedException was expected"); - } - - @Test - public void testUpdateBridgeDomain() throws Exception { - final int bdId = 1; - final String bdName = "bd1"; - defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); - - final byte arpTermBefore = 1; - final byte floodBefore = 1; - final byte forwardBefore = 0; - final byte learnBefore = 1; - final byte uufBefore = 0; - - final BridgeDomain dataBefore = - generateBridgeDomain(bdName, arpTermBefore, floodBefore, forwardBefore, learnBefore, uufBefore); - final BridgeDomain dataAfter = - generateBridgeDomain(bdName, arpTermBefore ^ 1, floodBefore ^ 1, forwardBefore ^ 1, learnBefore ^ 1, - uufBefore ^ 1); - - whenBridgeDomainAddDelThenSuccess(); - - customizer - .updateCurrentAttributes(bdIdentifierForName(bdName), dataBefore, dataAfter, - writeContext); - verifyBridgeDomainAddOrUpdateWasInvoked(dataAfter, bdId); - } - - @Test - public void testUpdateUnknownBridgeDomain() throws Exception { - final String bdName = "bd1"; - final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0, 1, 0); - final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0, 1, 0); - noMappingDefined(mappingContext, bdName, BD_CTX_NAME); - - try { - customizer - .updateCurrentAttributes(bdIdentifierForName(bdName), bdBefore, bdAfter, - writeContext); - } catch (IllegalArgumentException e) { - verify(api, never()).bridgeDomainAddDel(any(BridgeDomainAddDel.class)); - return; - } - fail("IllegalArgumentException was expected"); - } - - @Test - public void testUpdateBridgeDomainFailed() throws Exception { - final int bdId = 1; - final String bdName = "bd1"; - final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0, 1, 0); - final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0, 1, 0); - defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); - - whenBridgeDomainAddDelThenFailure(); - - try { - customizer.updateCurrentAttributes(bdIdentifierForName(bdName), bdBefore, bdAfter, writeContext); - } catch (WriteFailedException e) { - verifyBridgeDomainAddOrUpdateWasInvoked(bdAfter, bdId); - return; - } - fail("IllegalStateException was expected"); - } - -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/L2FibEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/L2FibEntryCustomizerTest.java deleted file mode 100644 index 551b0879e..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/L2FibEntryCustomizerTest.java +++ /dev/null @@ -1,283 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.vpp; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.vpp.jvpp.VppBaseCallException; -import io.fd.vpp.jvpp.VppInvocationException; -import io.fd.vpp.jvpp.core.dto.L2FibAddDel; -import io.fd.vpp.jvpp.core.dto.L2FibAddDelReply; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.L2FibFilter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.L2FibForward; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.BridgeDomains; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomain; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomainKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class L2FibEntryCustomizerTest extends WriterCustomizerTest { - private static final String BD_CTX_NAME = "bd-test-instance"; - private static final String IFC_CTX_NAME = "ifc-test-instance"; - - private static final String BD_NAME = "testBD0"; - private static final int BD_ID = 111; - private static final String IFACE_NAME = "eth0"; - private static final int IFACE_ID = 123; - private static final int NO_INTERFACE = -1; - - private L2FibEntryCustomizer customizer; - - private static InstanceIdentifier getL2FibEntryId(final PhysAddress address) { - return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(BD_NAME)) - .child(L2FibTable.class).child(L2FibEntry.class, new L2FibEntryKey(address)); - } - - @Override - public void setUpTest() throws Exception { - defineMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME); - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - - customizer = new L2FibEntryCustomizer( - api, - new NamingContext("generatedBdName", BD_CTX_NAME), - new NamingContext("generatedIfaceName", IFC_CTX_NAME)); - } - - private void whenL2FibAddDelThenSuccess() { - doReturn(future(new L2FibAddDelReply())).when(api).l2FibAddDel(any(L2FibAddDel.class)); - } - - private void whenL2FibAddDelThenFailure() { - doReturn(failedFuture()).when(api).l2FibAddDel(any(L2FibAddDel.class)); - } - - private L2FibAddDel generateL2FibAddDelFilterRequest(final long mac, final byte isAdd, final int ifaceIndex) { - final L2FibAddDel request = new L2FibAddDel(); - request.mac = mac; - request.bdId = BD_ID; - request.swIfIndex = ifaceIndex; - request.isAdd = isAdd; - if (isAdd == 1) { - request.staticMac = 1; - request.filterMac = 1; - } - return request; - } - - private L2FibAddDel generateL2FibAddDelForwardRequest(final long mac, final byte isAdd, final int ifaceIndex) { - final L2FibAddDel request = new L2FibAddDel(); - request.mac = mac; - request.bdId = BD_ID; - request.swIfIndex = ifaceIndex; - request.isAdd = isAdd; - if (isAdd == 1) { - request.staticMac = 1; - request.filterMac = 0; - } - return request; - } - - private L2FibEntry generateL2FibFilterEntry(final PhysAddress address) { - final L2FibEntryBuilder entry = new L2FibEntryBuilder(); - entry.setKey(new L2FibEntryKey(address)); - entry.setPhysAddress(address); - entry.setStaticConfig(true); - entry.setBridgedVirtualInterface(false); - entry.setAction(L2FibFilter.class); - return entry.build(); - } - - private L2FibEntry generateL2FibForwardEntry(final PhysAddress address) { - final L2FibEntryBuilder entry = new L2FibEntryBuilder(); - entry.setKey(new L2FibEntryKey(address)); - entry.setPhysAddress(address); - entry.setStaticConfig(true); - entry.setBridgedVirtualInterface(false); - entry.setAction(L2FibForward.class); - entry.setOutgoingInterface(IFACE_NAME); - return entry.build(); - } - - - private void verifyL2FibAddDelWasInvoked(final L2FibAddDel expected) throws - VppInvocationException { - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(L2FibAddDel.class); - verify(api).l2FibAddDel(argumentCaptor.capture()); - final L2FibAddDel actual = argumentCaptor.getValue(); - assertEquals(expected.mac, actual.mac); - assertEquals(expected.bdId, actual.bdId); - assertEquals(expected.swIfIndex, actual.swIfIndex); - assertEquals(expected.isAdd, actual.isAdd); - assertEquals(expected.staticMac, actual.staticMac); - assertEquals(expected.filterMac, actual.filterMac); - } - - @Test - public void testCreateFilter() throws Exception { - final long address_vpp = 0x0102030405060000L; - final PhysAddress address = new PhysAddress("01:02:03:04:05:06"); - final L2FibEntry entry = generateL2FibFilterEntry(address); - final InstanceIdentifier id = getL2FibEntryId(address); - - whenL2FibAddDelThenSuccess(); - - customizer.writeCurrentAttributes(id, entry, writeContext); - - verifyL2FibAddDelWasInvoked(generateL2FibAddDelFilterRequest(address_vpp, (byte) 1, NO_INTERFACE)); - } - - @Test - public void testCreateForward() throws Exception { - final long address_vpp = 0x0102030405060000L; - final PhysAddress address = new PhysAddress("01:02:03:04:05:06"); - final L2FibEntry entry = generateL2FibForwardEntry(address); - final InstanceIdentifier id = getL2FibEntryId(address); - - whenL2FibAddDelThenSuccess(); - - customizer.writeCurrentAttributes(id, entry, writeContext); - - verifyL2FibAddDelWasInvoked(generateL2FibAddDelForwardRequest(address_vpp, (byte) 1, IFACE_ID)); - } - - @Test - public void testCreateFilterFailed() throws Exception { - final long address_vpp = 0x1122334455660000L; - final PhysAddress address = new PhysAddress("11:22:33:44:55:66"); - final L2FibEntry entry = generateL2FibFilterEntry(address); - final InstanceIdentifier id = getL2FibEntryId(address); - - whenL2FibAddDelThenFailure(); - - try { - customizer.writeCurrentAttributes(id, entry, writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verifyL2FibAddDelWasInvoked(generateL2FibAddDelFilterRequest(address_vpp, (byte) 1, NO_INTERFACE)); - return; - } - fail("WriteFailedException.CreateFailedException was expected"); - } - - @Test - public void testCreateForwardFailed() throws Exception { - final long address_vpp = 0x1122334455660000L; - final PhysAddress address = new PhysAddress("11:22:33:44:55:66"); - final L2FibEntry entry = generateL2FibForwardEntry(address); - final InstanceIdentifier id = getL2FibEntryId(address); - - whenL2FibAddDelThenFailure(); - - try { - customizer.writeCurrentAttributes(id, entry, writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verifyL2FibAddDelWasInvoked(generateL2FibAddDelForwardRequest(address_vpp, (byte) 1, IFACE_ID)); - return; - } - fail("WriteFailedException.CreateFailedException was expected"); - } - - @Test(expected = UnsupportedOperationException.class) - public void testUpdate() throws Exception { - customizer.updateCurrentAttributes(InstanceIdentifier.create(L2FibEntry.class), mock(L2FibEntry.class), - mock(L2FibEntry.class), writeContext); - } - - @Test - public void testDeleteFilter() throws Exception { - final long address_vpp = 0x1122334455660000L; - final PhysAddress address = new PhysAddress("11:22:33:44:55:66"); - final L2FibEntry entry = generateL2FibFilterEntry(address); - final InstanceIdentifier id = getL2FibEntryId(address); - - whenL2FibAddDelThenSuccess(); - - customizer.deleteCurrentAttributes(id, entry, writeContext); - - verifyL2FibAddDelWasInvoked(generateL2FibAddDelFilterRequest(address_vpp, (byte) 0, NO_INTERFACE)); - } - - @Test - public void testDeleteForward() throws Exception { - final long address_vpp = 0x1122334455660000L; - final PhysAddress address = new PhysAddress("11:22:33:44:55:66"); - final L2FibEntry entry = generateL2FibForwardEntry(address); - final InstanceIdentifier id = getL2FibEntryId(address); - - whenL2FibAddDelThenSuccess(); - - customizer.deleteCurrentAttributes(id, entry, writeContext); - - verifyL2FibAddDelWasInvoked(generateL2FibAddDelForwardRequest(address_vpp, (byte) 0, IFACE_ID)); - } - - - @Test - public void testDeleteFilterFailed() throws Exception { - final long address_vpp = 0x0102030405060000L; - final PhysAddress address = new PhysAddress("01:02:03:04:05:06"); - final L2FibEntry entry = generateL2FibFilterEntry(address); - final InstanceIdentifier id = getL2FibEntryId(address); - - whenL2FibAddDelThenFailure(); - - try { - customizer.deleteCurrentAttributes(id, entry, writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verifyL2FibAddDelWasInvoked(generateL2FibAddDelFilterRequest(address_vpp, (byte) 0, NO_INTERFACE)); - return; - } - fail("WriteFailedException.DeleteFailedException was expected"); - } - - @Test - public void testDeleteForwardFailed() throws Exception { - final long address_vpp = 0x0102030405060000L; - final PhysAddress address = new PhysAddress("01:02:03:04:05:06"); - final L2FibEntry entry = generateL2FibForwardEntry(address); - final InstanceIdentifier id = getL2FibEntryId(address); - - whenL2FibAddDelThenFailure(); - - try { - customizer.deleteCurrentAttributes(id, entry, writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verifyL2FibAddDelWasInvoked(generateL2FibAddDelForwardRequest(address_vpp, (byte) 0, IFACE_ID)); - return; - } - fail("WriteFailedException.DeleteFailedException was expected"); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/BridgeDomainCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/BridgeDomainCustomizerTest.java deleted file mode 100644 index 0fbdb986e..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/BridgeDomainCustomizerTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.vppstate; - -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.BridgeDomainsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomain; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomainBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomainKey; - -public class BridgeDomainCustomizerTest - extends ListReaderCustomizerTest { - - private NamingContext bdContext; - private NamingContext interfacesContext; - - public BridgeDomainCustomizerTest() { - super(BridgeDomain.class, BridgeDomainsBuilder.class); - } - - @Override - public void setUp() { - bdContext = new NamingContext("generatedBdName", "bd-test-instance"); - interfacesContext = new NamingContext("generatedIfaceName", "ifc-test-instance"); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new BridgeDomainCustomizer(api, bdContext); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/L2FibEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/L2FibEntryCustomizerTest.java deleted file mode 100644 index 94a654c15..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/L2FibEntryCustomizerTest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.vppstate; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.ExecutionException; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.L2FibForward; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTableBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.BridgeDomains; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomain; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomainKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.VppInvocationException; -import io.fd.vpp.jvpp.core.dto.L2FibTableDump; -import io.fd.vpp.jvpp.core.dto.L2FibTableEntry; -import io.fd.vpp.jvpp.core.dto.L2FibTableEntryReplyDump; - -public class L2FibEntryCustomizerTest extends ListReaderCustomizerTest { - - private static final String BD_NAME = "testBD0"; - private static final int BD_ID = 111; - private static final String IFACE_NAME = "eth0"; - private static final int IFACE_ID = 123; - private static final String BD_CTX_NAME = "bd-test-instance"; - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private NamingContext bdContext; - private NamingContext interfacesContext; - - public L2FibEntryCustomizerTest() { - super(L2FibEntry.class, L2FibTableBuilder.class); - } - - @Override - public void setUp() { - bdContext = new NamingContext("generatedBdName", BD_CTX_NAME); - defineMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME); - interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new L2FibEntryCustomizer(api, bdContext, interfacesContext); - } - - private static InstanceIdentifier getL2FibEntryId(final String bdName, final PhysAddress address) { - return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(bdName)) - .child(L2FibTable.class).child(L2FibEntry.class, new L2FibEntryKey(address)); - } - - private void whenL2FibTableDumpThenReturn(final List l2FibTableEntryList) - throws ExecutionException, InterruptedException, VppInvocationException { - final L2FibTableEntryReplyDump reply = new L2FibTableEntryReplyDump(); - reply.l2FibTableEntry = l2FibTableEntryList; - when(api.l2FibTableDump(any(L2FibTableDump.class))).thenReturn(future(reply)); - } - - @Test - public void testRead() throws Exception { - final long address_vpp = 0x0000010203040506L; - final PhysAddress address = new PhysAddress("01:02:03:04:05:06"); - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - - whenL2FibTableDumpThenReturn(Collections.singletonList(generateL2FibEntry(address_vpp))); - - final L2FibEntryBuilder builder = mock(L2FibEntryBuilder.class); - getCustomizer().readCurrentAttributes(getL2FibEntryId(BD_NAME, address), builder, ctx); - - verify(builder).setAction(L2FibForward.class); - verify(builder).setBridgedVirtualInterface(false); - verify(builder).setOutgoingInterface(IFACE_NAME); - verify(builder).setStaticConfig(false); - verify(builder).setPhysAddress(address); - verify(builder).setKey(new L2FibEntryKey(address)); - } - - private L2FibTableEntry generateL2FibEntry(final long mac) { - final L2FibTableEntry entry = new L2FibTableEntry(); - entry.mac = mac; - entry.swIfIndex = IFACE_ID; - return entry; - } - - @Test - public void testGetAllIds() throws Exception { - final long address_vpp = 0x0000112233445566L; - final PhysAddress address = new PhysAddress("11:22:33:44:55:66"); - - whenL2FibTableDumpThenReturn(Collections.singletonList(generateL2FibEntry(address_vpp))); - - final List ids = getCustomizer().getAllIds(getL2FibEntryId(BD_NAME, address), ctx); - assertEquals(1, ids.size()); - assertEquals(address, ids.get(0).getPhysAddress()); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/VersionCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/VersionCustomizerTest.java deleted file mode 100644 index 2f12cbde1..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/VersionCustomizerTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.vppstate; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; -import io.fd.vpp.jvpp.core.dto.ShowVersion; -import io.fd.vpp.jvpp.core.dto.ShowVersionReply; -import io.fd.vpp.jvpp.dto.ControlPing; -import io.fd.vpp.jvpp.dto.ControlPingReply; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppStateBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.Version; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.VersionBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class VersionCustomizerTest extends ReaderCustomizerTest { - - public VersionCustomizerTest() { - super(Version.class, VppStateBuilder.class); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new VersionCustomizer(api); - } - - @Test - public void testReadCurrentAttributes() throws Exception { - final ShowVersionReply reply = new ShowVersionReply(); - reply.version = new byte[] {}; - reply.program = new byte[] {}; - reply.buildDate = new byte[] {}; - reply.buildDirectory = new byte[] {}; - - when(api.showVersion(any(ShowVersion.class))).thenReturn(future(reply)); - when(api.send(any(ControlPing.class))).thenReturn(future(new ControlPingReply())); - getCustomizer().readCurrentAttributes(InstanceIdentifier.create(Version.class), new VersionBuilder(), ctx); - verify(api).showVersion(any(ShowVersion.class)); - verify(api).send(any(ControlPing.class)); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/VppStateTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/VppStateTest.java deleted file mode 100644 index 7134a595a..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/VppStateTest.java +++ /dev/null @@ -1,326 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.vppstate; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -import com.google.common.base.Optional; -import com.google.common.collect.Iterables; -import com.google.common.collect.Multimap; -import io.fd.honeycomb.translate.MappingContext; -import io.fd.honeycomb.translate.ModificationCache; -import io.fd.honeycomb.translate.impl.read.GenericListReader; -import io.fd.honeycomb.translate.impl.read.GenericReader; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.read.registry.ReaderRegistry; -import io.fd.honeycomb.translate.impl.read.registry.CompositeReaderRegistryBuilder; -import io.fd.hc2vpp.common.test.util.NamingContextHelper; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.common.test.util.FutureProducer; -import io.fd.vpp.jvpp.dto.ControlPing; -import io.fd.vpp.jvpp.dto.ControlPingReply; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import javax.annotation.Nonnull; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppState; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppStateBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.BridgeDomains; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.BridgeDomainsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.Version; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.VersionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomain; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomainBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomainKey; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.BridgeDomainDetails; -import io.fd.vpp.jvpp.core.dto.BridgeDomainDetailsReplyDump; -import io.fd.vpp.jvpp.core.dto.BridgeDomainDump; -import io.fd.vpp.jvpp.core.dto.L2FibTableDump; -import io.fd.vpp.jvpp.core.dto.L2FibTableEntry; -import io.fd.vpp.jvpp.core.dto.L2FibTableEntryReplyDump; -import io.fd.vpp.jvpp.core.dto.ShowVersion; -import io.fd.vpp.jvpp.core.dto.ShowVersionReply; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; - -public class VppStateTest implements FutureProducer, NamingContextHelper { - - private static final String BD_CTX_NAME = "bd-test-instance"; - @Mock - private FutureJVppCore api; - @Mock - private ReadContext ctx; - @Mock - private MappingContext mappingContext; - - private NamingContext bdContext; - - private ReaderRegistry readerRegistry; - - private static InstanceIdentifier bridgeDomainsId; - - /** - * Create root VppState reader with all its children wired. - */ - private static ReaderRegistry getVppStateReader(@Nonnull final FutureJVppCore jVpp, - @Nonnull final NamingContext bdContext) { - final CompositeReaderRegistryBuilder registry = new CompositeReaderRegistryBuilder(); - - // VppState(Structural) - final InstanceIdentifier vppStateId = InstanceIdentifier.create(VppState.class); - registry.addStructuralReader(vppStateId, VppStateBuilder.class); - // Version - registry.add(new GenericReader<>(vppStateId.child(Version.class), new VersionCustomizer(jVpp))); - // BridgeDomains(Structural) - bridgeDomainsId = vppStateId.child(BridgeDomains.class); - registry.addStructuralReader(bridgeDomainsId, BridgeDomainsBuilder.class); - // BridgeDomain - registry.add(getBridgeDomainReader(jVpp, bdContext)); - return registry.build(); - } - - private static GenericListReader getBridgeDomainReader( - final @Nonnull FutureJVppCore jVpp, final @Nonnull NamingContext bdContext) { - final InstanceIdentifier bridgeDomainId = bridgeDomainsId.child(BridgeDomain.class); - return new GenericListReader<>(bridgeDomainId, new BridgeDomainCustomizer(jVpp, bdContext)); - } - - @Before - public void setUp() throws Exception { - initMocks(this); - final ModificationCache cache = new ModificationCache(); - doReturn(cache).when(ctx).getModificationCache(); - doReturn(mappingContext).when(ctx).getMappingContext(); - - bdContext = new NamingContext("generatedBdName", BD_CTX_NAME); - readerRegistry = getVppStateReader(api, bdContext); - } - - private static Version getVersion() { - return new VersionBuilder() - .setName("test") - .setBuildDirectory("1") - .setBranch("2") - .setBuildDate("3") - .setPid(0L) - .build(); - } - - private void whenShowVersionThenReturn(final Version version) { - final ShowVersionReply reply = new ShowVersionReply(); - reply.buildDate = version.getBuildDate().getBytes(); - reply.program = version.getName().getBytes(); - reply.version = version.getBranch().getBytes(); - reply.buildDirectory = version.getBuildDirectory().getBytes(); - when(api.showVersion(any(ShowVersion.class))).thenReturn(future(reply)); - // Version Customizer uses ControlPing to obtain PID - when(api.send(any(ControlPing.class))).thenReturn(future(new ControlPingReply())); - } - - private void whenL2FibTableDumpThenReturn(final List entryList) { - final L2FibTableEntryReplyDump reply = new L2FibTableEntryReplyDump(); - reply.l2FibTableEntry = entryList; - when(api.l2FibTableDump(any(L2FibTableDump.class))).thenReturn(future(reply)); - } - - private void whenBridgeDomainDumpThenReturn(final List bdList) { - final BridgeDomainDetailsReplyDump reply = new BridgeDomainDetailsReplyDump(); - reply.bridgeDomainDetails = bdList; - - doAnswer(invocation -> { - BridgeDomainDump request = (BridgeDomainDump) invocation.getArguments()[0]; - if (request.bdId == -1) { - reply.bridgeDomainDetails = bdList; - } else { - reply.bridgeDomainDetails = Collections.singletonList(bdList.get(request.bdId)); - } - return future(reply); - }).when(api).bridgeDomainDump(any(BridgeDomainDump.class)); - } - - @Test - public void testReadAll() throws Exception { - final Version version = getVersion(); - whenShowVersionThenReturn(version); - - final BridgeDomainDetails bridgeDomainDetails = new BridgeDomainDetails(); - final BridgeDomainDetails bridgeDomainDetails2 = new BridgeDomainDetails(); - bridgeDomainDetails2.bdId = 1; - - final List bdList = Arrays.asList(bridgeDomainDetails, bridgeDomainDetails2); - mockBdMapping(bridgeDomainDetails, "bd1"); - mockBdMapping(bridgeDomainDetails2, "bd2"); - - whenBridgeDomainDumpThenReturn(bdList); - - final Multimap, ? extends DataObject> dataObjects = - readerRegistry.readAll(ctx); - assertEquals(dataObjects.size(), 1); - final VppState dataObject = - (VppState) Iterables.getOnlyElement(dataObjects.get(Iterables.getOnlyElement(dataObjects.keySet()))); - assertEquals(version, dataObject.getVersion()); - assertEquals(2, dataObject.getBridgeDomains().getBridgeDomain().size()); - } - - @Test - public void testReadSpecific() throws Exception { - final Version version = getVersion(); - whenShowVersionThenReturn(version); - whenBridgeDomainDumpThenReturn(Collections.emptyList()); - - final Optional read = readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx); - assertTrue(read.isPresent()); - assertEquals(version, ((VppState) read.get()).getVersion()); - } - - @Test - public void testReadBridgeDomains() throws Exception { - final Version version = getVersion(); - whenShowVersionThenReturn(version); - final BridgeDomainDetails details = new BridgeDomainDetails(); - whenBridgeDomainDumpThenReturn(Collections.singletonList(details)); - - mockBdMapping(details, "bdn1"); - VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get(); - - Optional read = - readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class), ctx); - assertTrue(read.isPresent()); - assertEquals(readRoot.getBridgeDomains(), read.get()); - } - - /** - * L2fib does not have a dedicated reader, relying on auto filtering - */ - @Test - @Ignore("L2 FIB was moved to dedicated customizer. TODO: add infra test that covers such case") - @SuppressWarnings("unchecked") - public void testReadL2Fib() throws Exception { - final BridgeDomainDetails bd = new BridgeDomainDetails(); - bd.bdId = 0; - final String bdName = "bdn1"; - mockBdMapping(bd, bdName); - defineMapping(mappingContext, "eth1", 0, "ifc-test-instance"); - - whenBridgeDomainDumpThenReturn(Collections.singletonList(bd)); - final L2FibTableEntry l2FibEntry = new L2FibTableEntry(); - l2FibEntry.bdId = 0; - l2FibEntry.mac = 0x0605040302010000L; - whenL2FibTableDumpThenReturn(Collections.singletonList(l2FibEntry)); - - // Deep child without a dedicated reader with specific l2fib key - final InstanceIdentifier idExisting = - InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( - BridgeDomain.class, new BridgeDomainKey("bdn1")).child(L2FibTable.class) - .child(L2FibEntry.class, new L2FibEntryKey(new PhysAddress("01:02:03:04:05:06"))); - Optional read = - readerRegistry.read(idExisting, ctx); - assertTrue(read.isPresent()); - - // non existing l2fib - final InstanceIdentifier idNonExisting = - InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( - BridgeDomain.class, new BridgeDomainKey("bdn1")).child(L2FibTable.class) - .child(L2FibEntry.class, new L2FibEntryKey(new PhysAddress("FF:FF:FF:04:05:06"))); - read = readerRegistry.read(idNonExisting, ctx); - assertFalse(read.isPresent()); - } - - private void mockBdMapping(final BridgeDomainDetails bd, final String bdName) { - defineMapping(mappingContext, bdName, bd.bdId, BD_CTX_NAME); - } - - @Test - public void testReadBridgeDomainAll() throws Exception { - final Version version = getVersion(); - whenShowVersionThenReturn(version); - final BridgeDomainDetails details = new BridgeDomainDetails(); - whenBridgeDomainDumpThenReturn(Collections.singletonList(details)); - mockBdMapping(details, "bd2"); - - VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get(); - - final GenericListReader bridgeDomainReader = - getBridgeDomainReader(api, bdContext); - - final List read = - bridgeDomainReader.readList(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( - BridgeDomain.class), ctx); - - assertEquals(readRoot.getBridgeDomains().getBridgeDomain(), read); - } - - @Test - public void testReadBridgeDomain() throws Exception { - final BridgeDomainDetails bd = new BridgeDomainDetails(); - bd.bdId = 0; - final String bdName = "bdn1"; - mockBdMapping(bd, bdName); - - whenBridgeDomainDumpThenReturn(Collections.singletonList(bd)); - whenShowVersionThenReturn(getVersion()); - - VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get(); - - final Optional read = - readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( - BridgeDomain.class, new BridgeDomainKey(bdName)), ctx); - - assertTrue(read.isPresent()); - assertEquals(readRoot.getBridgeDomains().getBridgeDomain().stream().filter( - input -> input.getKey().getName().equals(bdName)).findFirst().get(), - read.get()); - } - - @Test(expected = ReadFailedException.class) - public void testReadBridgeDomainNotExisting() throws Exception { - final String nonExistingBdName = "NOT EXISTING"; - noMappingDefined(mappingContext, nonExistingBdName, BD_CTX_NAME); - - readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( - BridgeDomain.class, new BridgeDomainKey(nonExistingBdName)), ctx); - } - - @Test - public void testReadVersion() throws Exception { - whenShowVersionThenReturn(getVersion()); - whenBridgeDomainDumpThenReturn(Collections.emptyList()); - VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get(); - - Optional read = - readerRegistry.read(InstanceIdentifier.create(VppState.class).child(Version.class), ctx); - assertTrue(read.isPresent()); - assertEquals(readRoot.getVersion(), read.get()); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/resources/v3po.json b/v3po/v3po2vpp/src/test/resources/v3po.json deleted file mode 100644 index 9ea66efe8..000000000 --- a/v3po/v3po2vpp/src/test/resources/v3po.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "keepalive-delay": "30" -} -- cgit 1.2.3-korg