diff options
author | Marek Gradzki <mgradzki@cisco.com> | 2016-09-27 08:58:07 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2016-09-27 08:58:07 +0200 |
commit | 7c020f63afe3c5b4eb23897262024cdee1920ec8 (patch) | |
tree | cccedbb97ef47ccfab3ab83552d09265bab5dab1 /v3po/v3po2vpp/src | |
parent | bc335de41876acd8720dce1030a79b3a7b39c3b1 (diff) |
HONEYCOMB-195: increase v3po coverage over 80%. Part II
Change-Id: Ia28078cad65c1a45754f1d440c3f6413836aa60d
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src')
13 files changed, 643 insertions, 49 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VhostUserCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VhostUserCustomizer.java index 032b3c214..dd5de7722 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VhostUserCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VhostUserCustomizer.java @@ -125,6 +125,7 @@ public class VhostUserCustomizer extends FutureJVppCustomizer builder.setNumMemoryRegions((long) swInterfaceVhostUserDetails.numRegions); builder.setSocket(toString(swInterfaceVhostUserDetails.sockFilename)); builder.setVirtioNetHdrSize((long) swInterfaceVhostUserDetails.virtioNetHdrSz); + // TODO: map error code to meaningful message after VPP-436 is done builder.setConnectError(Integer.toString(swInterfaceVhostUserDetails.sockErrno)); LOG.debug("Vhost user interface: {}, id: {} attributes read as: {}", key.getName(), index, builder); diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java index bd96bfbb9..c07049ffd 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java @@ -98,8 +98,8 @@ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer if (ipAddressDetails.isPresent()) { final IpAddressDetails detail = ipAddressDetails.get(); - builder.setIp(arrayToIpv4AddressNoZone(detail.ip)) - .setSubnet(new PrefixLengthBuilder().setPrefixLength(Short.valueOf(detail.prefixLength)).build()); + builder.setIp(arrayToIpv4AddressNoZone(detail.ip)); + builder.setSubnet(new PrefixLengthBuilder().setPrefixLength(Short.valueOf(detail.prefixLength)).build()); if (LOG.isDebugEnabled()) { LOG.debug("Attributes for {} sub-interface (id={}) address {} successfully read: {}", diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java index 8977a74bf..b04b94430 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java @@ -17,10 +17,11 @@ package io.fd.honeycomb.translate.v3po.interfacesstate; 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 static org.mockito.Mockito.when; +import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager; @@ -36,7 +37,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Acl; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.AclBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.openvpp.jvpp.core.dto.ClassifyTableByInterface; import org.openvpp.jvpp.core.dto.ClassifyTableByInterfaceReply; public class AclCustomizerTest extends ReaderCustomizerTest<Acl, AclBuilder> { @@ -45,6 +45,9 @@ public class AclCustomizerTest extends ReaderCustomizerTest<Acl, AclBuilder> { private static final int IF_INDEX = 1; private static final int TABLE_INDEX = 123; private static final String TABLE_NAME = "table123"; + private static final InstanceIdentifier<Acl> IID = + InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(VppInterfaceStateAugmentation.class).child(Acl.class); private static final String IFC_CTX_NAME = "ifc-test-instance"; @@ -68,30 +71,28 @@ public class AclCustomizerTest extends ReaderCustomizerTest<Acl, AclBuilder> { return new AclCustomizer(api, interfaceContext, classifyTableContext); } - private InstanceIdentifier<Acl> getAclId(final String name) { - return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(name)) - .augmentation( - VppInterfaceStateAugmentation.class).child(Acl.class); - } - @Test - public void testRead() throws Exception { - final InstanceIdentifier<Acl> id = getAclId(IF_NAME); + public void testRead() throws ReadFailedException { final AclBuilder builder = mock(AclBuilder.class); final ClassifyTableByInterfaceReply reply = new ClassifyTableByInterfaceReply(); reply.l2TableId = TABLE_INDEX; reply.ip4TableId = ~0; reply.ip6TableId = ~0; - doReturn(future(reply)).when(api).classifyTableByInterface(any(ClassifyTableByInterface.class)); + when(api.classifyTableByInterface(any())).thenReturn(future(reply)); - doReturn(TABLE_NAME).when(classifyTableContext).getTableName(TABLE_INDEX, mappingContext); + when(classifyTableContext.getTableName(TABLE_INDEX, mappingContext)).thenReturn(TABLE_NAME); - getCustomizer().readCurrentAttributes(id, builder, ctx); + getCustomizer().readCurrentAttributes(IID, builder, ctx); verify(builder).setL2Acl(new L2AclBuilder().setClassifyTable(TABLE_NAME).build()); verify(builder).setIp4Acl(null); verify(builder).setIp6Acl(null); } + @Test(expected = ReadFailedException.class) + public void testReadFailed() throws ReadFailedException { + when(api.classifyTableByInterface(any())).thenReturn(failedFuture()); + getCustomizer().readCurrentAttributes(IID, mock(AclBuilder.class), ctx); + } }
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/EthernetCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/EthernetCustomizerTest.java new file mode 100644 index 000000000..d1d768971 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/EthernetCustomizerTest.java @@ -0,0 +1,90 @@ +/* + * 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.honeycomb.translate.v3po.interfacesstate; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.honeycomb.translate.v3po.util.NamingContext; +import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest; +import io.fd.honeycomb.vpp.test.util.InterfaceDumpHelper; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.EthernetStateAttributes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentationBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Ethernet; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.EthernetBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.core.dto.SwInterfaceDetails; + +public class EthernetCustomizerTest extends ReaderCustomizerTest<Ethernet, EthernetBuilder> implements + InterfaceDumpHelper { + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private static final String IF_NAME = "local0"; + private static final int IF_INDEX = 1; + private static final InstanceIdentifier<Ethernet> IID = + InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(VppInterfaceStateAugmentation.class).child(Ethernet.class); + private NamingContext interfaceContext; + + public EthernetCustomizerTest() { + super(Ethernet.class, VppInterfaceStateAugmentationBuilder.class); + } + + @Override + protected void setUp() throws Exception { + interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); + } + + @Override + protected ReaderCustomizer<Ethernet, EthernetBuilder> initCustomizer() { + return new EthernetCustomizer(api, interfaceContext); + } + + private void testRead(final int linkDuplex, final EthernetStateAttributes.Duplex duplex) throws ReadFailedException { + final EthernetBuilder builder = mock(EthernetBuilder.class); + final short mtu = 123; + whenSwInterfaceDumpThenReturn(api, ifaceDetails(mtu, linkDuplex)); + getCustomizer().readCurrentAttributes(IID, builder, ctx); + verify(builder).setMtu((int)mtu); + verify(builder).setDuplex(duplex); + } + + private SwInterfaceDetails ifaceDetails(final short mtu, final int duplex) { + final SwInterfaceDetails details = new SwInterfaceDetails(); + details.swIfIndex = IF_INDEX; + details.linkMtu = mtu; + details.linkDuplex = (byte)duplex; + return details; + } + + @Test + public void testReadHalfDuplex() throws ReadFailedException { + testRead(1, EthernetStateAttributes.Duplex.Half); + } + + @Test + public void testReadFullDuplex() throws ReadFailedException { + testRead(2, EthernetStateAttributes.Duplex.Full); + } +}
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java index a10468ee8..1522fbaee 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java @@ -18,20 +18,18 @@ package io.fd.honeycomb.translate.v3po.interfacesstate; import static org.junit.Assert.assertEquals; 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.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.honeycomb.translate.v3po.DisabledInterfacesManager; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest; +import io.fd.honeycomb.vpp.test.util.InterfaceDumpHelper; import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.junit.Assert; import org.junit.Test; @@ -44,11 +42,10 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces. import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.openvpp.jvpp.VppInvocationException; import org.openvpp.jvpp.core.dto.SwInterfaceDetails; -import org.openvpp.jvpp.core.dto.SwInterfaceDetailsReplyDump; import org.openvpp.jvpp.core.dto.SwInterfaceDump; -public class InterfaceCustomizerTest extends - ListReaderCustomizerTest<Interface, InterfaceKey, InterfaceBuilder> implements InterfaceDataTranslator { +public class InterfaceCustomizerTest extends ListReaderCustomizerTest<Interface, InterfaceKey, InterfaceBuilder> + implements InterfaceDataTranslator, InterfaceDumpHelper { private static final String IFC_CTX_NAME = "ifc-test-instance"; private static final String IFACE0_NAME = "eth0"; @@ -79,12 +76,6 @@ public class InterfaceCustomizerTest extends return new InterfaceCustomizer(api, interfacesContext, interfaceDisableContext); } - private void whenSwInterfaceDumpThenReturn(final List<SwInterfaceDetails> interfaceList) { - final SwInterfaceDetailsReplyDump reply = new SwInterfaceDetailsReplyDump(); - reply.swInterfaceDetails = interfaceList; - when(api.swInterfaceDump(any(SwInterfaceDump.class))).thenReturn(future(reply)); - } - private void verifySwInterfaceDumpWasInvoked(final int nameFilterValid, final String ifaceName, final int dumpIfcsInvocationCount) throws VppInvocationException { @@ -112,8 +103,7 @@ public class InterfaceCustomizerTest extends iface.linkSpeed = 1; iface.l2AddressLength = 6; iface.l2Address = new byte[iface.l2AddressLength]; - final List<SwInterfaceDetails> interfaceList = Collections.singletonList(iface); - whenSwInterfaceDumpThenReturn(interfaceList); + whenSwInterfaceDumpThenReturn(api, iface); getCustomizer().readCurrentAttributes(id, builder, ctx); @@ -128,7 +118,7 @@ public class InterfaceCustomizerTest extends .child(Interface.class, new InterfaceKey(ifaceName)); final InterfaceBuilder builder = getCustomizer().getBuilder(id); - whenSwInterfaceDumpThenReturn(Collections.emptyList()); + whenSwInterfaceDumpThenReturn(api); try { getCustomizer().readCurrentAttributes(id, builder, ctx); @@ -151,8 +141,7 @@ public class InterfaceCustomizerTest extends iface.swIfIndex = 2; iface.supSwIfIndex = 1; iface.subId = 1; - final List<SwInterfaceDetails> interfaceList = Collections.singletonList(iface); - whenSwInterfaceDumpThenReturn(interfaceList); + whenSwInterfaceDumpThenReturn(api, iface); getCustomizer().readCurrentAttributes(id, builder, ctx); @@ -176,7 +165,7 @@ public class InterfaceCustomizerTest extends swSubIf1.subId = 1; swSubIf1.supSwIfIndex = 1; swSubIf1.interfaceName = SUB_IFACE_NAME.getBytes(); - whenSwInterfaceDumpThenReturn(Arrays.asList(swIf0, swIf1, swSubIf1)); + whenSwInterfaceDumpThenReturn(api, swIf0, swIf1, swSubIf1); final List<InterfaceKey> expectedIds = Arrays.asList(new InterfaceKey(IFACE0_NAME), new InterfaceKey( IFACE1_NAME)); @@ -201,7 +190,7 @@ public class InterfaceCustomizerTest extends final SwInterfaceDetails swIf1 = new SwInterfaceDetails(); swIf1.swIfIndex = 1; swIf1.interfaceName = IFACE1_NAME.getBytes(); - whenSwInterfaceDumpThenReturn(Arrays.asList(swIf0, swIf1)); + whenSwInterfaceDumpThenReturn(api, swIf0, swIf1); final List<InterfaceKey> expectedIds = Arrays.asList(new InterfaceKey(IFACE0_NAME)); final List<InterfaceKey> actualIds = getCustomizer().getAllIds(id, ctx); diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/L2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/L2CustomizerTest.java index 5583ae348..48d635af2 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/L2CustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/L2CustomizerTest.java @@ -117,7 +117,7 @@ public class L2CustomizerTest extends ReaderCustomizerTest<L2, L2Builder> { cachedInterfaceDump.put(ifId, ifaceDetails); cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump); - // BVI + // BVIinterfaceContext whenBridgeDomainSwIfDumpThenReturn(Collections.singletonList(generateBdSwIfDetails(ifId, bdId)), Collections.singletonList(generateBdDetails(ifId, bdId))); diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceAclCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceAclCustomizerTest.java new file mode 100644 index 000000000..457842c24 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceAclCustomizerTest.java @@ -0,0 +1,107 @@ +/* + * 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.honeycomb.translate.v3po.interfacesstate; + +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.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.honeycomb.translate.v3po.util.NamingContext; +import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager; +import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip4AclBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.acl.base.attributes.Ip6AclBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceStateAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Acl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.AclBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.core.dto.ClassifyTableByInterfaceReply; + +public class SubInterfaceAclCustomizerTest extends ReaderCustomizerTest<Acl, AclBuilder> { + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private static final String IF_NAME = "local0"; + private static final int IF_INDEX = 1; + private static final String SUB_IF_NAME = "local0.1"; + private static final long SUB_IF_ID = 1; + private static final int SUB_IF_INDEX = 11; + private static final int TABLE_INDEX = 123; + private static final String TABLE_NAME = "table123"; + + private static final InstanceIdentifier<Acl> IID = + InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(SubinterfaceStateAugmentation.class).child(SubInterfaces.class) + .child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)).child(Acl.class); + + private NamingContext interfaceContext; + + @Mock + private VppClassifierContextManager classifyTableContext; + + public SubInterfaceAclCustomizerTest() { + super(Acl.class, SubInterfaceBuilder.class); + } + + @Override + protected void setUp() throws Exception { + interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); + defineMapping(mappingContext, SUB_IF_NAME, SUB_IF_INDEX, IFC_CTX_NAME); + } + + @Override + protected ReaderCustomizer<Acl, AclBuilder> initCustomizer() { + return new SubInterfaceAclCustomizer(api, interfaceContext, classifyTableContext); + } + + @Test + public void testRead() throws ReadFailedException { + final AclBuilder builder = mock(AclBuilder.class); + + final ClassifyTableByInterfaceReply reply = new ClassifyTableByInterfaceReply(); + reply.swIfIndex = SUB_IF_INDEX; + reply.l2TableId = ~0; + reply.ip4TableId = TABLE_INDEX; + reply.ip6TableId = TABLE_INDEX; + when(api.classifyTableByInterface(any())).thenReturn(future(reply)); + + when(classifyTableContext.getTableName(TABLE_INDEX, mappingContext)).thenReturn(TABLE_NAME); + + getCustomizer().readCurrentAttributes(IID, builder, ctx); + + verify(builder).setL2Acl(null); + verify(builder).setIp4Acl(new Ip4AclBuilder().setClassifyTable(TABLE_NAME).build()); + verify(builder).setIp6Acl(new Ip6AclBuilder().setClassifyTable(TABLE_NAME).build()); + } + + @Test(expected = ReadFailedException.class) + public void testReadFailed() throws ReadFailedException { + when(api.classifyTableByInterface(any())).thenReturn(failedFuture()); + getCustomizer().readCurrentAttributes(IID, mock(AclBuilder.class), ctx); + } +}
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceCustomizerTest.java index d52cb3fc2..49076d0cc 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceCustomizerTest.java @@ -18,16 +18,14 @@ package io.fd.honeycomb.translate.v3po.interfacesstate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -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.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest; -import java.util.Collections; +import io.fd.honeycomb.vpp.test.util.InterfaceDumpHelper; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -47,11 +45,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Tags; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.openvpp.jvpp.core.dto.SwInterfaceDetails; -import org.openvpp.jvpp.core.dto.SwInterfaceDetailsReplyDump; -import org.openvpp.jvpp.core.dto.SwInterfaceDump; -public class SubInterfaceCustomizerTest extends - ListReaderCustomizerTest<SubInterface, SubInterfaceKey, SubInterfaceBuilder> { +public class SubInterfaceCustomizerTest extends ListReaderCustomizerTest<SubInterface, SubInterfaceKey, SubInterfaceBuilder> implements + InterfaceDumpHelper { private static final String IFC_CTX_NAME = "ifc-test-instance"; private static final String SUPER_IF_NAME = "local0"; @@ -123,15 +119,11 @@ public class SubInterfaceCustomizerTest extends iface.swIfIndex = VLAN_IF_INDEX; iface.subId = VLAN_IF_ID; iface.supSwIfIndex = SUPER_IF_INDEX; - final List<SwInterfaceDetails> ifaces = Collections.singletonList(iface); - - final SwInterfaceDetailsReplyDump reply = new SwInterfaceDetailsReplyDump(); - reply.swInterfaceDetails = ifaces; - when(api.swInterfaceDump(any(SwInterfaceDump.class))).thenReturn(future(reply)); + whenSwInterfaceDumpThenReturn(api, iface); final List<SubInterfaceKey> allIds = getCustomizer().getAllIds(getSubInterfaceId(SUPER_IF_NAME, VLAN_IF_ID), ctx); - assertEquals(ifaces.size(), allIds.size()); + assertEquals(1, allIds.size()); } }
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceL2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceL2CustomizerTest.java new file mode 100644 index 000000000..306a44a30 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceL2CustomizerTest.java @@ -0,0 +1,64 @@ +package io.fd.honeycomb.translate.v3po.interfacesstate; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.honeycomb.translate.v3po.util.NamingContext; +import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceStateAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.L2; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.L2Builder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceL2CustomizerTest extends ReaderCustomizerTest<L2, L2Builder> { + + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private static final String BD_CTX_NAME = "bd-test-instance"; + private NamingContext interfaceContext; + private NamingContext bridgeDomainContext; + + private static final String IF_NAME = "local0"; + private static final int IF_INDEX = 1; + private static final String SUB_IF_NAME = "local0.1"; + private static final long SUB_IF_ID = 1; + private static final int SUB_IF_INDEX = 11; + private InstanceIdentifier<L2> IID = + InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(SubinterfaceStateAugmentation.class) + .child(SubInterfaces.class).child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)).child(L2.class); + + public SubInterfaceL2CustomizerTest() { + super(L2.class, SubInterfaceBuilder.class); + } + + @Override + protected void setUp() { + interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + bridgeDomainContext = new NamingContext("generatedBDName", BD_CTX_NAME); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); + defineMapping(mappingContext, SUB_IF_NAME, SUB_IF_INDEX, IFC_CTX_NAME); + } + + @Override + protected ReaderCustomizer<L2, L2Builder> initCustomizer() { + return new SubInterfaceL2Customizer(api, interfaceContext, bridgeDomainContext); + } + + @Test(expected = ReadFailedException.class) + public void testReadFailed() throws ReadFailedException { + final L2Builder builder = mock(L2Builder.class); + when(api.swInterfaceDump(any())).thenReturn(failedFuture()); + getCustomizer().readCurrentAttributes(IID, builder, ctx); + } +}
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/TapCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/TapCustomizerTest.java new file mode 100644 index 000000000..41eae36ca --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/TapCustomizerTest.java @@ -0,0 +1,98 @@ +/* + * 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.honeycomb.translate.v3po.interfacesstate; + +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.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.honeycomb.translate.v3po.util.NamingContext; +import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest; +import io.fd.honeycomb.vpp.test.util.InterfaceDumpHelper; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentationBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Tap; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.TapBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.core.dto.SwInterfaceDetails; +import org.openvpp.jvpp.core.dto.SwInterfaceTapDetails; +import org.openvpp.jvpp.core.dto.SwInterfaceTapDetailsReplyDump; + +public class TapCustomizerTest extends ReaderCustomizerTest<Tap, TapBuilder> implements InterfaceDumpHelper { + + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private static final String IF_NAME = "tap1"; + private static final String TAP_NAME = "testTapName"; + private static final int IF_INDEX = 1; + private static final InstanceIdentifier<Tap> IID = + InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(VppInterfaceStateAugmentation.class).child(Tap.class); + private NamingContext interfaceContext; + + public TapCustomizerTest() { + super(Tap.class, VppInterfaceStateAugmentationBuilder.class); + } + + @Override + protected void setUp() throws Exception { + interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); + whenSwInterfaceDumpThenReturn(api, ifaceDetails()); + } + + private SwInterfaceDetails ifaceDetails() { + final SwInterfaceDetails details = new SwInterfaceDetails(); + details.swIfIndex = IF_INDEX; + details.interfaceName = IF_NAME.getBytes(); + return details; + } + + @Override + protected ReaderCustomizer<Tap, TapBuilder> initCustomizer() { + return new TapCustomizer(api, interfaceContext); + } + + @Test + public void testRead() throws ReadFailedException { + final TapBuilder builder = mock(TapBuilder.class); + when(api.swInterfaceTapDump(any())).thenReturn(future(tapDump())); + getCustomizer().readCurrentAttributes(IID, builder, ctx); + verify(builder).setTapName(TAP_NAME); + } + + @Test(expected = ReadFailedException.class) + public void testReadFailed() throws ReadFailedException { + when(api.swInterfaceTapDump(any())).thenReturn(failedFuture()); + getCustomizer().readCurrentAttributes(IID, mock(TapBuilder.class), ctx); + } + + private SwInterfaceTapDetailsReplyDump tapDump() { + final SwInterfaceTapDetailsReplyDump reply = new SwInterfaceTapDetailsReplyDump(); + final SwInterfaceTapDetails details = new SwInterfaceTapDetails(); + details.devName = TAP_NAME.getBytes(); + details.swIfIndex = IF_INDEX; + reply.swInterfaceTapDetails.add(details); + return reply; + } +}
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VhostUserCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VhostUserCustomizerTest.java new file mode 100644 index 000000000..3e4c220eb --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VhostUserCustomizerTest.java @@ -0,0 +1,115 @@ +/* + * 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.honeycomb.translate.v3po.interfacesstate; + +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.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.honeycomb.translate.v3po.util.NamingContext; +import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest; +import io.fd.honeycomb.vpp.test.util.InterfaceDumpHelper; +import java.math.BigInteger; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VhostUserRole; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentationBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.VhostUser; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.VhostUserBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.core.dto.SwInterfaceDetails; +import org.openvpp.jvpp.core.dto.SwInterfaceVhostUserDetails; +import org.openvpp.jvpp.core.dto.SwInterfaceVhostUserDetailsReplyDump; + +public class VhostUserCustomizerTest extends ReaderCustomizerTest<VhostUser, VhostUserBuilder> implements + InterfaceDumpHelper { + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private static final String IF_NAME = "VirtualEthernet1"; + private static final int IF_INDEX = 1; + private static final InstanceIdentifier<VhostUser> IID = + InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(VppInterfaceStateAugmentation.class).child(VhostUser.class); + + private NamingContext interfaceContext; + + public VhostUserCustomizerTest() { + super(VhostUser.class, VppInterfaceStateAugmentationBuilder.class); + } + + @Override + protected void setUp() throws Exception { + interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); + whenSwInterfaceDumpThenReturn(api, ifaceDetails()); + } + + private SwInterfaceDetails ifaceDetails() { + final SwInterfaceDetails details = new SwInterfaceDetails(); + details.swIfIndex = IF_INDEX; + details.interfaceName = IF_NAME.getBytes(); + return details; + } + + @Override + protected ReaderCustomizer<VhostUser, VhostUserBuilder> initCustomizer() { + return new VhostUserCustomizer(api, interfaceContext); + } + + @Test + public void testRead() throws ReadFailedException { + final VhostUserBuilder builder = mock(VhostUserBuilder.class); + when(api.swInterfaceVhostUserDump(any())).thenReturn(future(vhostDump())); + getCustomizer().readCurrentAttributes(IID, builder, ctx); + verifyVhostBuilder(builder); + } + + @Test(expected = ReadFailedException.class) + public void testReadFailed() throws ReadFailedException { + when(api.swInterfaceVhostUserDump(any())).thenReturn(failedFuture()); + getCustomizer().readCurrentAttributes(IID, mock(VhostUserBuilder.class), ctx); + } + + private SwInterfaceVhostUserDetailsReplyDump vhostDump() { + final SwInterfaceVhostUserDetailsReplyDump reply = new SwInterfaceVhostUserDetailsReplyDump(); + final SwInterfaceVhostUserDetails details = new SwInterfaceVhostUserDetails(); + details.swIfIndex = IF_INDEX; + details.interfaceName = IF_NAME.getBytes(); + details.isServer = 1; + details.features = 2; + details.numRegions = 3; + details.sockFilename = "socketName".getBytes(); + details.virtioNetHdrSz = 4; + details.sockErrno = 5; + reply.swInterfaceVhostUserDetails.add(details); + return reply; + } + + private void verifyVhostBuilder(final VhostUserBuilder builder) { + verify(builder).setRole(VhostUserRole.Server); + verify(builder).setFeatures(BigInteger.valueOf(2)); + verify(builder).setNumMemoryRegions(3L); + verify(builder).setSocket("socketName"); + verify(builder).setVirtioNetHdrSize(4L); + verify(builder).setConnectError("5"); + } +}
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java index c841b4571..dc3585169 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java @@ -60,7 +60,6 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address, private static final int IFACE_ID = 1; private static final int IFACE_2_ID = 2; private static final String IFC_CTX_NAME = "ifc-test-instance"; - public static final String CACHE_KEY = Ipv4AddressCustomizer.class.getName(); private NamingContext interfacesContext; diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizerTest.java new file mode 100644 index 000000000..2f298a9a6 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizerTest.java @@ -0,0 +1,138 @@ +/* + * 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.honeycomb.translate.v3po.interfacesstate.ip; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.hasSize; +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.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; +import io.fd.honeycomb.translate.v3po.util.NamingContext; +import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest; +import java.util.List; +import org.junit.Test; +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.interfaces.rev140508.InterfacesState; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceStateAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.ip4.attributes.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.ip4.attributes.Ipv4Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.ip4.attributes.ipv4.Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.ip4.attributes.ipv4.AddressBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.ip4.attributes.ipv4.AddressKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.ip4.attributes.ipv4.address.subnet.PrefixLengthBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.core.dto.IpAddressDetails; +import org.openvpp.jvpp.core.dto.IpAddressDetailsReplyDump; + +public class SubInterfaceIpv4AddressCustomizerTest extends ListReaderCustomizerTest<Address, AddressKey, AddressBuilder> { + + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private static final String IF_NAME = "local0"; + private static final int IF_INDEX = 1; + private static final String SUB_IF_NAME = "local0.1"; + private static final long SUB_IF_ID = 1; + private static final int SUB_IF_INDEX = 11; + private static final InstanceIdentifier<Ipv4> IP4_IID = + InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(SubinterfaceStateAugmentation.class) + .child(SubInterfaces.class).child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)) + .child(Ipv4.class); + private static final Ipv4AddressNoZone IP1 = new Ipv4AddressNoZone("10.1.1.1"); + private static final Ipv4AddressNoZone IP2 = new Ipv4AddressNoZone("10.1.1.2"); + private static final short PREFIX_LENGTH = 16; + + private NamingContext interfaceContext; + + public SubInterfaceIpv4AddressCustomizerTest() { + super(Address.class, Ipv4Builder.class); + } + + @Override + protected void setUp() throws Exception { + interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); + defineMapping(mappingContext, SUB_IF_NAME, SUB_IF_INDEX, IFC_CTX_NAME); + } + + @Override + protected ListReaderCustomizer<Address, AddressKey, AddressBuilder> initCustomizer() { + return new SubInterfaceIpv4AddressCustomizer(api, interfaceContext); + } + + private static InstanceIdentifier<Address> getId() { + return IP4_IID.child(Address.class); + } + + private static InstanceIdentifier<Address> getId(final Ipv4AddressNoZone ip) { + return IP4_IID.child(Address.class, new AddressKey(ip)); + } + + @Test + public void testRead() throws ReadFailedException { + final AddressBuilder builder = mock(AddressBuilder.class); + when(api.ipAddressDump(any())).thenReturn(future(dump())); + getCustomizer().readCurrentAttributes(getId(IP2), builder, ctx); + verify(builder).setIp(IP2); + verify(builder).setSubnet(new PrefixLengthBuilder().setPrefixLength(PREFIX_LENGTH).build()); + } + + @Test(expected = ReadFailedException.class) + public void testReadFailed() throws ReadFailedException { + when(api.ipAddressDump(any())).thenReturn(failedFuture()); + getCustomizer().readCurrentAttributes(getId(IP1), mock(AddressBuilder.class), ctx); + } + + @Test + public void testGetAllIds() throws ReadFailedException { + when(api.ipAddressDump(any())).thenReturn(future(dump())); + final List<AddressKey> allIds = getCustomizer().getAllIds(getId(), ctx); + assertThat(allIds, hasSize(2)); + assertThat(allIds, containsInAnyOrder(new AddressKey(IP1), new AddressKey(IP2))); + } + + @Test(expected = ReadFailedException.class) + public void testGetAllIdsFailed() throws ReadFailedException { + when(api.ipAddressDump(any())).thenReturn(failedFuture()); + getCustomizer().getAllIds(getId(), ctx); + } + + private IpAddressDetailsReplyDump dump() { + final IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump(); + + final IpAddressDetails details1 = new IpAddressDetails(); + details1.ip = new byte[] {1, 1, 1, 10}; + details1.prefixLength = (byte) PREFIX_LENGTH; + reply.ipAddressDetails.add(details1); + + final IpAddressDetails details2 = new IpAddressDetails(); + details2.ip = new byte[] {2, 1, 1, 10}; + details2.prefixLength = (byte) PREFIX_LENGTH; + reply.ipAddressDetails.add(details2); + + return reply; + } +}
\ No newline at end of file |