summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate
diff options
context:
space:
mode:
Diffstat (limited to 'v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate')
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java132
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java212
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceUtilsTest.java55
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/L2CustomizerTest.java179
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/RewriteCustomizerTest.java127
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceCustomizerTest.java146
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanCustomizerTest.java140
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanGpeCustomizerTest.java285
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java297
9 files changed, 1573 insertions, 0 deletions
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
new file mode 100644
index 000000000..f36e49727
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java
@@ -0,0 +1,132 @@
+/*
+ * 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.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Lists;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
+import io.fd.honeycomb.translate.v3po.test.ReaderCustomizerTest;
+import io.fd.honeycomb.translate.v3po.util.NamingContext;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.MappingsBuilder;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingKey;
+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.acl.base.attributes.L2AclBuilder;
+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.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+import org.openvpp.jvpp.dto.ClassifyTableByInterface;
+import org.openvpp.jvpp.dto.ClassifyTableByInterfaceReply;
+
+public class AclCustomizerTest extends ReaderCustomizerTest<Acl, AclBuilder> {
+
+ private static final String IF_NAME = "local0";
+ private static final int IF_INDEX = 1;
+ private static final int TABLE_INDEX = 123;
+ private static final String TABLE_NAME = "table123";
+
+ private static final String IFC_TEST_INSTANCE = "ifc-test-instance";
+ private static final String CT_TEST_INSTANCE = "ct-test-instance";
+
+ private NamingContext interfaceContext;
+ private NamingContext classifyTableContext;
+
+ public AclCustomizerTest() {
+ super(Acl.class);
+ }
+
+ @Override
+ public void setUpBefore() {
+ interfaceContext = new NamingContext("generatedIfaceName", IFC_TEST_INSTANCE);
+ classifyTableContext = new NamingContext("generatedTableContext", CT_TEST_INSTANCE);
+
+ final KeyedInstanceIdentifier<Mapping, MappingKey> ifcMappingKey = ContextTestUtils
+ .getMappingIid(IF_NAME, IFC_TEST_INSTANCE);
+ final Optional<Mapping> ifcMapping = ContextTestUtils.getMapping(IF_NAME, IF_INDEX);
+ doReturn(ifcMapping).when(mappingContext).read(ifcMappingKey);
+
+ final KeyedInstanceIdentifier<Mapping, MappingKey> ctMappingKey = ContextTestUtils
+ .getMappingIid(TABLE_NAME, CT_TEST_INSTANCE);
+ final Optional<Mapping> ctMapping = ContextTestUtils.getMapping(TABLE_NAME, TABLE_INDEX);
+ doReturn(ctMapping).when(mappingContext).read(ctMappingKey);
+
+ final List<Mapping> allCtMappings = Lists.newArrayList(ctMapping.get());
+ final Mappings allCtMappingsBaObject = new MappingsBuilder().setMapping(allCtMappings).build();
+ doReturn(Optional.of(allCtMappingsBaObject)).when(mappingContext)
+ .read(ctMappingKey.firstIdentifierOf(Mappings.class));
+
+ final List<Mapping> allIfcMappings = Lists.newArrayList(ifcMapping.get());
+ final Mappings allIfcMappingsBaObject = new MappingsBuilder().setMapping(allIfcMappings).build();
+ doReturn(Optional.of(allIfcMappingsBaObject)).when(mappingContext)
+ .read(ifcMappingKey.firstIdentifierOf(Mappings.class));
+ }
+
+ @Override
+ protected ReaderCustomizer<Acl, AclBuilder> initCustomizer() {
+ return new AclCustomizer(api, interfaceContext, classifyTableContext);
+ }
+
+ @Test
+ public void testMerge() {
+ final VppInterfaceStateAugmentationBuilder builder = mock(VppInterfaceStateAugmentationBuilder.class);
+ final Acl value = mock(Acl.class);
+ getCustomizer().merge(builder, value);
+ verify(builder).setAcl(value);
+ }
+
+ 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);
+ final AclBuilder builder = mock(AclBuilder.class);
+
+ final CompletableFuture<ClassifyTableByInterfaceReply> replyFuture = new CompletableFuture<>();
+ final ClassifyTableByInterfaceReply reply = new ClassifyTableByInterfaceReply();
+ reply.l2TableId = TABLE_INDEX;
+ reply.ip4TableId = ~0;
+ reply.ip6TableId = ~0;
+ replyFuture.complete(reply);
+ doReturn(replyFuture).when(api).classifyTableByInterface(any(ClassifyTableByInterface.class));
+
+ getCustomizer().readCurrentAttributes(id, builder, ctx);
+
+ verify(builder).setL2Acl(new L2AclBuilder().setClassifyTable(TABLE_NAME).build());
+ verify(builder).setIp4Acl(null);
+ verify(builder).setIp6Acl(null);
+ }
+
+} \ 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
new file mode 100644
index 000000000..8bde1ac32
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java
@@ -0,0 +1,212 @@
+/*
+ * 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.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+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 com.google.common.base.Optional;
+import com.google.common.collect.Lists;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
+import io.fd.honeycomb.translate.v3po.test.InterfaceTestUtils;
+import io.fd.honeycomb.translate.v3po.test.ListReaderCustomizerTest;
+import io.fd.honeycomb.translate.v3po.util.NamingContext;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.MappingsBuilder;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingKey;
+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.InterfacesStateBuilder;
+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.InterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+import org.openvpp.jvpp.VppInvocationException;
+import org.openvpp.jvpp.dto.SwInterfaceDetails;
+import org.openvpp.jvpp.dto.SwInterfaceDump;
+
+public class InterfaceCustomizerTest extends
+ ListReaderCustomizerTest<Interface, InterfaceKey, InterfaceBuilder> {
+
+ private NamingContext interfacesContext;
+
+ public InterfaceCustomizerTest() {
+ super(Interface.class);
+ }
+
+ @Override
+ public void setUpBefore() {
+ interfacesContext = new NamingContext("generatedIfaceName", "test-instance");
+ }
+
+ @Override
+ protected ReaderCustomizer<Interface, InterfaceBuilder> initCustomizer() {
+ final KeyedInstanceIdentifier<Mapping, MappingKey> eth0Id = ContextTestUtils
+ .getMappingIid("eth0", "test-instance");
+ final KeyedInstanceIdentifier<Mapping, MappingKey> eth1Id = ContextTestUtils
+ .getMappingIid("eth1", "test-instance");
+ final KeyedInstanceIdentifier<Mapping, MappingKey> subEth1Id = ContextTestUtils
+ .getMappingIid("eth1.1", "test-instance");
+ final Optional<Mapping> eth0 = ContextTestUtils.getMapping("eth0", 0);
+ final Optional<Mapping> eth1 = ContextTestUtils.getMapping("eth1", 1);
+ final Optional<Mapping> subEth1 = ContextTestUtils.getMapping("eth1.1", 2);
+
+ final List<Mapping> allMappings =
+ Lists.newArrayList(ContextTestUtils.getMapping("eth0", 0).get(), ContextTestUtils.getMapping("eth1", 1).get(), ContextTestUtils
+ .getMapping("eth1.1", 2).get());
+ final Mappings allMappingsBaObject = new MappingsBuilder().setMapping(allMappings).build();
+ doReturn(Optional.of(allMappingsBaObject)).when(mappingContext).read(eth0Id.firstIdentifierOf(Mappings.class));
+
+ doReturn(eth0).when(mappingContext).read(eth0Id);
+ doReturn(eth1).when(mappingContext).read(eth1Id);
+ doReturn(subEth1).when(mappingContext).read(subEth1Id);
+
+ return new InterfaceCustomizer(api, interfacesContext);
+ }
+
+ // TODO use reflexion and move to ListReaderCustomizerTest
+ @Test
+ public void testMerge() throws Exception {
+ final InterfacesStateBuilder builder = mock(InterfacesStateBuilder.class);
+ final List<Interface> value = Collections.emptyList();
+ getCustomizer().merge(builder, value);
+ verify(builder).setInterface(value);
+ }
+
+ private void verifySwInterfaceDumpWasInvoked(final int nameFilterValid, final String ifaceName,
+ final int dumpIfcsInvocationCount)
+ throws VppInvocationException {
+ // TODO adding equals methods for jvpp DTOs would make ArgumentCaptor usage obsolete
+ ArgumentCaptor<SwInterfaceDump> argumentCaptor = ArgumentCaptor.forClass(SwInterfaceDump.class);
+ verify(api, times(dumpIfcsInvocationCount)).swInterfaceDump(argumentCaptor.capture());
+ final SwInterfaceDump actual = argumentCaptor.getValue();
+ assertEquals(nameFilterValid, actual.nameFilterValid);
+ assertArrayEquals(ifaceName.getBytes(), actual.nameFilter);
+ }
+
+ private static void assertIfacesAreEqual(final Interface iface, final SwInterfaceDetails details) {
+ assertEquals(iface.getName(), new String(details.interfaceName));
+ Assert.assertEquals(InterfaceUtils.yangIfIndexToVpp(iface.getIfIndex().intValue()), details.swIfIndex);
+ assertEquals(iface.getPhysAddress().getValue(), InterfaceUtils.vppPhysAddrToYang(details.l2Address));
+ }
+
+ @Test
+ public void testReadCurrentAttributes() throws Exception {
+ final String ifaceName = "eth0";
+ final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class, new InterfaceKey(ifaceName));
+ final InterfaceBuilder builder = getCustomizer().getBuilder(id);
+
+ final SwInterfaceDetails iface = new SwInterfaceDetails();
+ iface.interfaceName = ifaceName.getBytes();
+ iface.swIfIndex = 0;
+ iface.linkSpeed = 1;
+ iface.l2AddressLength = 6;
+ iface.l2Address = new byte[iface.l2AddressLength];
+ final List<SwInterfaceDetails> interfaceList = Collections.singletonList(iface);
+ InterfaceTestUtils.whenSwInterfaceDumpThenReturn(api, interfaceList);
+
+ getCustomizer().readCurrentAttributes(id, builder, ctx);
+
+ verifySwInterfaceDumpWasInvoked(1, ifaceName, 1);
+ assertIfacesAreEqual(builder.build(), iface);
+ }
+
+ @Test
+ public void testReadCurrentAttributesFailed() throws Exception {
+ final String ifaceName = "eth0";
+ final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class, new InterfaceKey(ifaceName));
+ final InterfaceBuilder builder = getCustomizer().getBuilder(id);
+
+ InterfaceTestUtils.whenSwInterfaceDumpThenReturn(api, Collections.emptyList());
+
+ try {
+ getCustomizer().readCurrentAttributes(id, builder, ctx);
+ } catch (IllegalArgumentException e) {
+ verifySwInterfaceDumpWasInvoked(0, ifaceName, 2);
+ return;
+ }
+
+ fail("ReadFailedException was expected");
+ }
+
+ @Test
+ public void testReadSubInterface() throws Exception {
+ final String ifaceName = "eth1.1";
+ final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class, new InterfaceKey(ifaceName));
+ final InterfaceBuilder builder = mock(InterfaceBuilder.class);
+
+ final SwInterfaceDetails iface = new SwInterfaceDetails();
+ iface.interfaceName = ifaceName.getBytes();
+ iface.swIfIndex = 2;
+ iface.supSwIfIndex = 1;
+ iface.subId = 1;
+ final List<SwInterfaceDetails> interfaceList = Collections.singletonList(iface);
+ InterfaceTestUtils.whenSwInterfaceDumpThenReturn(api, interfaceList);
+
+ getCustomizer().readCurrentAttributes(id, builder, ctx);
+
+ verifySwInterfaceDumpWasInvoked(1, ifaceName, 1);
+ verifyZeroInteractions(builder);
+ }
+
+ @Test
+ public void testGetAllIds() throws Exception {
+ final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class);
+
+ final String swIf0Name = "eth0";
+ final SwInterfaceDetails swIf0 = new SwInterfaceDetails();
+ swIf0.swIfIndex = 0;
+ swIf0.interfaceName = swIf0Name.getBytes();
+ final String swIf1Name = "eth1";
+ final SwInterfaceDetails swIf1 = new SwInterfaceDetails();
+ swIf1.swIfIndex = 1;
+ swIf1.interfaceName = swIf1Name.getBytes();
+ final String swSubIf1Name = "eth1.1";
+ final SwInterfaceDetails swSubIf1 = new SwInterfaceDetails();
+ swSubIf1.swIfIndex = 2;
+ swSubIf1.subId = 1;
+ swSubIf1.supSwIfIndex = 1;
+ swSubIf1.interfaceName = swSubIf1Name.getBytes();
+ InterfaceTestUtils.whenSwInterfaceDumpThenReturn(api, Arrays.asList(swIf0, swIf1, swSubIf1));
+
+ final List<InterfaceKey> expectedIds = Arrays.asList(new InterfaceKey(swIf0Name), new InterfaceKey(swIf1Name));
+ final List<InterfaceKey> actualIds = getCustomizer().getAllIds(id, ctx);
+
+ verifySwInterfaceDumpWasInvoked(0, "", 1);
+
+ // sub-interface should not be on the list
+ assertEquals(expectedIds, actualIds);
+ }
+}
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceUtilsTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceUtilsTest.java
new file mode 100644
index 000000000..c74e1ccfb
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceUtilsTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.EthernetCsmacd;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Tap;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VhostUser;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VxlanGpeTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VxlanTunnel;
+
+public class InterfaceUtilsTest {
+
+ @Test
+ public void testVppPhysAddrToYang() throws Exception {
+ assertEquals("01:02:03:04:05:06", InterfaceUtils.vppPhysAddrToYang(new byte[]{1, 2, 3, 4, 5, 6}));
+ assertEquals("0a:0b:0c:0d:0e:0f", InterfaceUtils.vppPhysAddrToYang(new byte[]{0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0, 0}));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testVppPhysAddrToYangFailNullArgument() throws Exception {
+ InterfaceUtils.vppPhysAddrToYang(null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testVppPhysAddrToYangInvalidByteArrayLength() throws Exception {
+ InterfaceUtils.vppPhysAddrToYang(new byte[]{1, 2, 3, 4, 5});
+ }
+
+ @Test
+ public void testGetInterfaceType() {
+ assertEquals(Tap.class, InterfaceUtils.getInterfaceType("tap0"));
+ assertEquals(VxlanTunnel.class, InterfaceUtils.getInterfaceType("vxlan0"));
+ assertEquals(VxlanGpeTunnel.class, InterfaceUtils.getInterfaceType("vxlan_gpe0"));
+ assertEquals(VhostUser.class, InterfaceUtils.getInterfaceType("VirtualEthernet0/0/0"));
+ assertEquals(EthernetCsmacd.class, InterfaceUtils.getInterfaceType("eth0.0"));
+ assertEquals(EthernetCsmacd.class, InterfaceUtils.getInterfaceType("local0"));
+ }
+} \ No newline at end of file
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
new file mode 100644
index 000000000..ecd32c6d1
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/L2CustomizerTest.java
@@ -0,0 +1,179 @@
+/*
+ * 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.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Lists;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
+import io.fd.honeycomb.translate.v3po.test.ReaderCustomizerTest;
+import io.fd.honeycomb.translate.v3po.util.NamingContext;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.MappingsBuilder;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingKey;
+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.L2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.L2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.base.attributes.Interconnection;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.base.attributes.interconnection.BridgeBasedBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+import org.openvpp.jvpp.VppInvocationException;
+import org.openvpp.jvpp.dto.BridgeDomainDetails;
+import org.openvpp.jvpp.dto.BridgeDomainDetailsReplyDump;
+import org.openvpp.jvpp.dto.BridgeDomainDump;
+import org.openvpp.jvpp.dto.BridgeDomainSwIfDetails;
+import org.openvpp.jvpp.dto.SwInterfaceDetails;
+
+public class L2CustomizerTest extends ReaderCustomizerTest<L2, L2Builder> {
+
+ private NamingContext interfaceContext;
+ private NamingContext bridgeDomainContext;
+
+ public L2CustomizerTest() {
+ super(L2.class);
+ }
+
+ @Override
+ public void setUpBefore() {
+ interfaceContext = new NamingContext("generatedIfaceName", "ifc-test-instance");
+ bridgeDomainContext = new NamingContext("generatedBDName", "bd-test-instance");
+ }
+
+ @Override
+ protected ReaderCustomizer<L2, L2Builder> initCustomizer() {
+ return new L2Customizer(api, interfaceContext, bridgeDomainContext);
+ }
+
+ @Test
+ public void testMerge() {
+ final VppInterfaceStateAugmentationBuilder builder = mock(VppInterfaceStateAugmentationBuilder.class);
+ final L2 value = mock(L2.class);
+ getCustomizer().merge(builder, value);
+ verify(builder).setL2(value);
+ }
+
+ private InstanceIdentifier<L2> getL2Id(final String name) {
+ return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(name))
+ .augmentation(
+ VppInterfaceStateAugmentation.class).child(L2.class);
+ }
+
+ private void whenBridgeDomainSwIfDumpThenReturn(final List<BridgeDomainSwIfDetails> bdSwIfList,
+ final List<BridgeDomainDetails> bridgeDomainDetailses)
+ throws ExecutionException, InterruptedException, VppInvocationException {
+ final BridgeDomainDetailsReplyDump reply = new BridgeDomainDetailsReplyDump();
+ reply.bridgeDomainSwIfDetails = bdSwIfList;
+ reply.bridgeDomainDetails = bridgeDomainDetailses;
+
+ final CompletableFuture<BridgeDomainDetailsReplyDump> replyFuture = new CompletableFuture<>();
+ replyFuture.complete(reply);
+ when(api.bridgeDomainSwIfDump(any(BridgeDomainDump.class))).thenReturn(replyFuture);
+ }
+
+
+ private BridgeDomainSwIfDetails generateBdSwIfDetails(final int ifId, final int bdId) {
+ final BridgeDomainSwIfDetails bdSwIfDetails = new BridgeDomainSwIfDetails();
+ bdSwIfDetails.swIfIndex = ifId;
+ bdSwIfDetails.shg = 1;
+ bdSwIfDetails.bdId = bdId;
+ return bdSwIfDetails;
+ }
+
+ private Interconnection generateInterconnection(final int ifId, final String bdName, final Boolean bvi) {
+ final BridgeBasedBuilder bbBuilder = new BridgeBasedBuilder();
+ bbBuilder.setBridgeDomain(bdName);
+ bbBuilder.setSplitHorizonGroup((short) 1);
+ if (bvi != null) {
+ bbBuilder.setBridgedVirtualInterface(bvi);
+ } else {
+ bbBuilder.setBridgedVirtualInterface(false); // false is default
+ }
+ return bbBuilder.build();
+ }
+
+ @Test
+ public void testRead() throws Exception {
+ final Map<Integer, SwInterfaceDetails> cachedInterfaceDump = new HashMap<>();
+ final int ifId = 1;
+ final int bdId = 1;
+ final String bdName = "bd001";
+ final String ifName = "eth0.sub0";
+ final KeyedInstanceIdentifier<Mapping, MappingKey> ifcIid = ContextTestUtils
+ .getMappingIid(ifName, "ifc-test-instance");
+ doReturn(ContextTestUtils.getMapping(ifName, ifId)).when(mappingContext).read(ifcIid);
+ final KeyedInstanceIdentifier<Mapping, MappingKey> bdIid = ContextTestUtils
+ .getMappingIid(bdName, "bd-test-instance");
+ doReturn(ContextTestUtils.getMapping(bdName, bdId)).when(mappingContext).read(bdIid);
+
+ List<Mapping> allMappings = Lists.newArrayList(ContextTestUtils.getMapping(ifName, ifId).get());
+ Mappings allMappingsBaObject = new MappingsBuilder().setMapping(allMappings).build();
+ doReturn(Optional.of(allMappingsBaObject)).when(mappingContext).read(ifcIid.firstIdentifierOf(Mappings.class));
+
+ allMappings = Lists.newArrayList(ContextTestUtils.getMapping(bdName, bdId).get());
+ allMappingsBaObject = new MappingsBuilder().setMapping(allMappings).build();
+ doReturn(Optional.of(allMappingsBaObject)).when(mappingContext).read(bdIid.firstIdentifierOf(Mappings.class));
+
+ final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails();
+ ifaceDetails.subId = ifId;
+ cachedInterfaceDump.put(ifId, ifaceDetails);
+ cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump);
+
+ // BVI
+ whenBridgeDomainSwIfDumpThenReturn(Collections.singletonList(generateBdSwIfDetails(ifId, bdId)),
+ Collections.singletonList(generateBdDetails(ifId, bdId)));
+
+ L2Builder builder = mock(L2Builder.class);
+ getCustomizer().readCurrentAttributes(getL2Id(ifName), builder, ctx);
+
+ verify(builder).setInterconnection(generateInterconnection(ifId, bdName, true));
+
+ // Not BVI
+ whenBridgeDomainSwIfDumpThenReturn(Collections.singletonList(generateBdSwIfDetails(ifId, bdId)),
+ Collections.singletonList(generateBdDetails(99 /* Different ifc is marked as BVI in bd details */, bdId)));
+
+ builder = mock(L2Builder.class);
+ getCustomizer().readCurrentAttributes(getL2Id(ifName), builder, ctx);
+
+ verify(builder).setInterconnection(generateInterconnection(ifId, bdName, null));
+ }
+
+ private BridgeDomainDetails generateBdDetails(final int ifId, final int bdId) {
+ final BridgeDomainDetails bridgeDomainDetails = new BridgeDomainDetails();
+ bridgeDomainDetails.bviSwIfIndex = ifId;
+ bridgeDomainDetails.bdId = bdId;
+ return bridgeDomainDetails;
+ }
+} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/RewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/RewriteCustomizerTest.java
new file mode 100644
index 000000000..ec0851d9c
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/RewriteCustomizerTest.java
@@ -0,0 +1,127 @@
+/*
+ * 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.junit.Assert.assertEquals;
+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 com.google.common.base.Optional;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.v3po.test.ReaderCustomizerTest;
+import io.fd.honeycomb.translate.v3po.util.NamingContext;
+import io.fd.honeycomb.translate.v3po.util.TagRewriteOperation;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping;
+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._802dot1q;
+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.base.attributes.L2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.l2.Rewrite;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.l2.RewriteBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.tag.rewrite.PushTags;
+import org.opendaylight.yangtools.yang.binding.ChildOf;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.openvpp.jvpp.dto.SwInterfaceDetails;
+
+public class RewriteCustomizerTest extends ReaderCustomizerTest<Rewrite, RewriteBuilder> {
+
+ public static final String VLAN_IF_NAME = "local0.1";
+ public static final int VLAN_IF_ID = 1;
+ public static final int VLAN_IF_INDEX = 11;
+
+ private NamingContext interfacesContext;
+
+ @Captor
+ private ArgumentCaptor<List<PushTags>> captor;
+
+ public RewriteCustomizerTest() {
+ super(Rewrite.class);
+ }
+
+ @Override
+ public void setUpBefore() {
+ interfacesContext = new NamingContext("generatedIfaceName", "test-instance");
+
+ final Optional<Mapping> ifcMapping = ContextTestUtils.getMapping(VLAN_IF_NAME, VLAN_IF_INDEX);
+ doReturn(ifcMapping).when(mappingContext).read(any());
+ }
+
+ @Override
+ protected ReaderCustomizer<Rewrite, RewriteBuilder> initCustomizer() {
+ return new RewriteCustomizer(api, interfacesContext);
+ }
+
+ @Test
+ public void testMerge() {
+ final L2Builder builder = mock(L2Builder.class);
+ final Rewrite value = mock(Rewrite.class);
+ getCustomizer().merge(builder, value);
+ verify(builder).setRewrite(value);
+ }
+
+ private InstanceIdentifier<Rewrite> getVlanTagRewriteId(final String name, final long index) {
+ final Class<ChildOf<? super SubInterface>> child = (Class)Rewrite.class;
+ final InstanceIdentifier id =
+ InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(name)).augmentation(
+ SubinterfaceStateAugmentation.class).child(SubInterfaces.class)
+ .child(SubInterface.class, new SubInterfaceKey(index))
+ .child(child);
+ return id;
+ }
+
+ @Test
+ public void testRead() throws ReadFailedException {
+ final Map<Integer, SwInterfaceDetails> cachedInterfaceDump = new HashMap<>();
+
+ final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails();
+ ifaceDetails.subId = VLAN_IF_ID;
+ ifaceDetails.interfaceName = VLAN_IF_NAME.getBytes();
+ ifaceDetails.vtrOp = TagRewriteOperation.translate_2_to_2.ordinal();
+ ifaceDetails.subNumberOfTags = 2;
+ ifaceDetails.vtrTag1 = 123;
+ ifaceDetails.vtrTag2 = 321;
+ ifaceDetails.vtrPushDot1Q = 1;
+ cachedInterfaceDump.put(VLAN_IF_INDEX, ifaceDetails);
+ cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump);
+
+ final RewriteBuilder builder = mock(RewriteBuilder.class);
+
+ getCustomizer().readCurrentAttributes(getVlanTagRewriteId(VLAN_IF_NAME, VLAN_IF_ID), builder, ctx);
+
+ verify(builder).setVlanType(_802dot1q.class);
+ verify(builder).setPopTags((short) 2);
+
+ verify(builder).setPushTags(captor.capture());
+ final List<PushTags> tags = captor.getValue();
+ assertEquals(ifaceDetails.subNumberOfTags, tags.size());
+ }
+} \ 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
new file mode 100644
index 000000000..b93c9f42a
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceCustomizerTest.java
@@ -0,0 +1,146 @@
+/*
+ * 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.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+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 com.google.common.base.Optional;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
+import io.fd.honeycomb.translate.v3po.test.InterfaceTestUtils;
+import io.fd.honeycomb.translate.v3po.test.ListReaderCustomizerTest;
+import io.fd.honeycomb.translate.v3po.util.NamingContext;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping;
+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.SubInterfacesBuilder;
+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.match.attributes.match.type.VlanTagged;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Match;
+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.dto.SwInterfaceDetails;
+
+public class SubInterfaceCustomizerTest extends
+ ListReaderCustomizerTest<SubInterface, SubInterfaceKey, SubInterfaceBuilder> {
+
+ public static final String SUPER_IF_NAME = "local0";
+ public static final int SUPER_IF_INDEX = 1;
+ public static final String VLAN_IF_NAME = "local0.1";
+ public static final int VLAN_IF_ID = 1;
+ public static final int VLAN_IF_INDEX = 11;
+
+ private NamingContext interfacesContext;
+
+ public SubInterfaceCustomizerTest() {
+ super(SubInterface.class);
+ }
+
+ @Override
+ public void setUpBefore() {
+ interfacesContext = new NamingContext("generatedIfaceName", "test-instance");
+ }
+
+ @Override
+ protected ReaderCustomizer<SubInterface, SubInterfaceBuilder> initCustomizer() {
+ return new SubInterfaceCustomizer(api, interfacesContext);
+ }
+
+ private InstanceIdentifier<SubInterface> getSubInterfaceId(final String name, final long id) {
+ return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(name)).augmentation(
+ SubinterfaceStateAugmentation.class).child(
+ SubInterfaces.class).child(SubInterface.class, new SubInterfaceKey(id));
+ }
+
+ @Test
+ public void testMerge() {
+ final SubInterfacesBuilder builder = mock(SubInterfacesBuilder.class);
+ final List<SubInterface> value = mock(List.class);
+ getCustomizer().merge(builder, value);
+ verify(builder).setSubInterface(value);
+ }
+
+ @Test
+ public void testRead() throws ReadFailedException {
+ final Optional<Mapping> ifcMapping = ContextTestUtils.getMapping(VLAN_IF_NAME, VLAN_IF_INDEX);
+ doReturn(ifcMapping).when(mappingContext).read(any());
+
+ final Map<Integer, SwInterfaceDetails> cachedInterfaceDump = new HashMap<>();
+
+ final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails();
+ ifaceDetails.subId = VLAN_IF_ID;
+ ifaceDetails.interfaceName = VLAN_IF_NAME.getBytes();
+ ifaceDetails.subDot1Ad = 1;
+ ifaceDetails.subNumberOfTags = 2;
+ ifaceDetails.subOuterVlanIdAny = 1;
+ ifaceDetails.subInnerVlanIdAny = 1;
+ ifaceDetails.subExactMatch = 1;
+ cachedInterfaceDump.put(VLAN_IF_INDEX, ifaceDetails);
+ cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump);
+
+ final SubInterfaceBuilder builder = mock(SubInterfaceBuilder.class);
+ getCustomizer().readCurrentAttributes(getSubInterfaceId(VLAN_IF_NAME, VLAN_IF_ID), builder, ctx);
+
+ verify(builder).setIdentifier((long) VLAN_IF_ID);
+
+ ArgumentCaptor<Tags> tagCaptor = ArgumentCaptor.forClass(Tags.class);
+ verify(builder).setTags(tagCaptor.capture());
+ assertEquals(ifaceDetails.subNumberOfTags, tagCaptor.getValue().getTag().size());
+
+ ArgumentCaptor<Match> matchCaptor = ArgumentCaptor.forClass(Match.class);
+ verify(builder).setMatch(matchCaptor.capture());
+ final VlanTagged matchType = (VlanTagged)matchCaptor.getValue().getMatchType();
+ assertTrue(matchType.getVlanTagged().isMatchExactTags());
+ }
+
+ @Test
+ public void testGetAllIds() throws Exception {
+ final Optional<Mapping> ifcMapping = ContextTestUtils.getMapping(SUPER_IF_NAME, SUPER_IF_INDEX);
+ doReturn(ifcMapping).when(mappingContext).read(any());
+
+ final SwInterfaceDetails iface = new SwInterfaceDetails();
+ iface.interfaceName = VLAN_IF_NAME.getBytes();
+ iface.swIfIndex = VLAN_IF_INDEX;
+ iface.subId = VLAN_IF_ID;
+ iface.supSwIfIndex = SUPER_IF_INDEX;
+ final List<SwInterfaceDetails> ifaces = Collections.singletonList(iface);
+ InterfaceTestUtils.whenSwInterfaceDumpThenReturn(api, ifaces);
+
+ final List<SubInterfaceKey> allIds =
+ getCustomizer().getAllIds(getSubInterfaceId(VLAN_IF_NAME, VLAN_IF_ID), ctx);
+
+ assertEquals(ifaces.size(), allIds.size());
+
+ }
+} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanCustomizerTest.java
new file mode 100644
index 000000000..a5c1d3465
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanCustomizerTest.java
@@ -0,0 +1,140 @@
+/*
+ * 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.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+
+import com.google.common.collect.Lists;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
+import io.fd.honeycomb.translate.v3po.test.ReaderCustomizerTest;
+import io.fd.honeycomb.translate.v3po.util.NamingContext;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+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.interfaces.state._interface.Vxlan;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.VxlanBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.openvpp.jvpp.VppInvocationException;
+import org.openvpp.jvpp.dto.SwInterfaceDetails;
+import org.openvpp.jvpp.dto.VxlanTunnelDetails;
+import org.openvpp.jvpp.dto.VxlanTunnelDetailsReplyDump;
+import org.openvpp.jvpp.dto.VxlanTunnelDump;
+
+public class VxlanCustomizerTest extends ReaderCustomizerTest<Vxlan, VxlanBuilder> {
+
+ private NamingContext interfacesContext;
+ static final InstanceIdentifier<Vxlan> IID =
+ InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey("ifc1"))
+ .augmentation(VppInterfaceStateAugmentation.class).child(Vxlan.class);
+
+ public VxlanCustomizerTest() {
+ super(Vxlan.class);
+ }
+
+ @Override
+ public void setUpBefore() {
+ interfacesContext = new NamingContext("vxlan-tunnel", "test-instance");
+ doReturn(ContextTestUtils.getMapping("ifc1", 0)).when(mappingContext).read(
+ ContextTestUtils.getMappingIid("ifc1", "test-instance"));
+
+ final SwInterfaceDetails v = new SwInterfaceDetails();
+ v.interfaceName = "vxlan-tunnel4".getBytes();
+ final Map<Integer, SwInterfaceDetails> map = new HashMap<>();
+ map.put(0, v);
+ cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, map);
+ }
+
+ @Override
+ protected void setUpAfter() throws UnknownHostException, VppInvocationException {
+ final CompletableFuture<VxlanTunnelDetailsReplyDump> vxlanTunnelDetailsReplyDumpCompletionStage =
+ new CompletableFuture<>();
+
+ final VxlanTunnelDetailsReplyDump value = new VxlanTunnelDetailsReplyDump();
+ final VxlanTunnelDetails vxlanTunnelDetails = new VxlanTunnelDetails();
+ vxlanTunnelDetails.isIpv6 = 0;
+ vxlanTunnelDetails.decapNextIndex = 1;
+ vxlanTunnelDetails.dstAddress = InetAddress.getByName("1.2.3.4").getAddress();
+ vxlanTunnelDetails.srcAddress = InetAddress.getByName("1.2.3.5").getAddress();
+ vxlanTunnelDetails.encapVrfId = 55;
+ vxlanTunnelDetails.swIfIndex = 0;
+ vxlanTunnelDetails.vni = 9;
+
+ value.vxlanTunnelDetails = Lists.newArrayList(vxlanTunnelDetails);
+ vxlanTunnelDetailsReplyDumpCompletionStage.complete(value);
+
+ doReturn(vxlanTunnelDetailsReplyDumpCompletionStage).when(api).vxlanTunnelDump(any(VxlanTunnelDump.class));
+ }
+
+ @Test
+ public void testReadCurrentAttributes() throws Exception {
+ final VxlanBuilder builder = getCustomizer().getBuilder(IID);
+ getCustomizer().readCurrentAttributes(IID, builder, ctx);
+
+ assertEquals(9, builder.getVni().getValue().intValue());
+ assertEquals(55, builder.getEncapVrfId().intValue());
+
+ assertNull(builder.getSrc().getIpv6Address());
+ assertNotNull(builder.getSrc().getIpv4Address());
+ assertEquals("1.2.3.5", builder.getSrc().getIpv4Address().getValue());
+
+ assertNull(builder.getDst().getIpv6Address());
+ assertNotNull(builder.getDst().getIpv4Address());
+ assertEquals("1.2.3.4", builder.getDst().getIpv4Address().getValue());
+
+ verify(api).vxlanTunnelDump(any(VxlanTunnelDump.class));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testReadCurrentAttributesVppNameNotCached() throws Exception {
+ InterfaceCustomizer.getCachedInterfaceDump(cache).remove(0);
+
+ final VxlanBuilder builder = getCustomizer().getBuilder(IID);
+ getCustomizer().readCurrentAttributes(IID, builder, ctx);
+ }
+
+ @Test
+ public void testReadCurrentAttributesWrongType() throws Exception {
+ final SwInterfaceDetails v = new SwInterfaceDetails();
+ v.interfaceName = "tap-2".getBytes();
+ InterfaceCustomizer.getCachedInterfaceDump(cache).put(0, v);
+
+ final VxlanBuilder builder = getCustomizer().getBuilder(IID);
+ getCustomizer().readCurrentAttributes(IID, builder, ctx);
+
+ // Should be ignored
+ verifyZeroInteractions(api);
+ }
+
+ @Override
+ protected ReaderCustomizer<Vxlan, VxlanBuilder> initCustomizer() {
+ return new VxlanCustomizer(api, interfacesContext);
+ }
+} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanGpeCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanGpeCustomizerTest.java
new file mode 100644
index 000000000..2569d8ae0
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanGpeCustomizerTest.java
@@ -0,0 +1,285 @@
+/*
+ * 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.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+
+import com.google.common.collect.Lists;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
+import io.fd.honeycomb.translate.v3po.test.ReaderCustomizerTest;
+import io.fd.honeycomb.translate.v3po.util.NamingContext;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+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.interfaces.state._interface.VxlanGpe;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.VxlanGpeBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.openvpp.jvpp.VppBaseCallException;
+import org.openvpp.jvpp.dto.SwInterfaceDetails;
+import org.openvpp.jvpp.dto.VxlanGpeTunnelDetails;
+import org.openvpp.jvpp.dto.VxlanGpeTunnelDetailsReplyDump;
+import org.openvpp.jvpp.dto.VxlanGpeTunnelDump;
+
+public class VxlanGpeCustomizerTest extends ReaderCustomizerTest<VxlanGpe, VxlanGpeBuilder> {
+
+ private NamingContext interfacesContext;
+ static final InstanceIdentifier<VxlanGpe> VXLAN_GPE_ID =
+ InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey("ifc2"))
+ .augmentation(VppInterfaceStateAugmentation.class).child(VxlanGpe.class);
+
+ public VxlanGpeCustomizerTest() {
+ super(VxlanGpe.class);
+ }
+
+ @Override
+ public void setUpBefore() {
+ interfacesContext = new NamingContext("vxlan_gpe_inf", "test-instance");
+ doReturn(ContextTestUtils.getMapping("ifc2", 0)).when(mappingContext).read(
+ ContextTestUtils.getMappingIid("ifc2", "test-instance"));
+
+ final SwInterfaceDetails v = new SwInterfaceDetails();
+ v.interfaceName = "vxlan_gpe_inf2".getBytes();
+ final Map<Integer, SwInterfaceDetails> map = new HashMap<>();
+ map.put(0, v);
+ cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, map);
+ }
+
+ @Override
+ protected void setUpAfter() throws UnknownHostException, VppBaseCallException {
+ final CompletableFuture<VxlanGpeTunnelDetailsReplyDump> vxlanGpeTunnelDetailsReplyDumpCompletionStage =
+ new CompletableFuture<>();
+
+ final VxlanGpeTunnelDetailsReplyDump value = new VxlanGpeTunnelDetailsReplyDump();
+ final VxlanGpeTunnelDetails vxlanGpeTunnelDetails = new VxlanGpeTunnelDetails();
+ vxlanGpeTunnelDetails.isIpv6 = 0;
+ vxlanGpeTunnelDetails.local = InetAddress.getByName("1.2.3.4").getAddress();
+ vxlanGpeTunnelDetails.remote = InetAddress.getByName("1.2.3.5").getAddress();
+ vxlanGpeTunnelDetails.vni = 9;
+ vxlanGpeTunnelDetails.protocol = 1;
+ vxlanGpeTunnelDetails.encapVrfId = 55;
+ vxlanGpeTunnelDetails.decapVrfId = 66;
+ vxlanGpeTunnelDetails.swIfIndex = 0;
+
+ value.vxlanGpeTunnelDetails = Lists.newArrayList(vxlanGpeTunnelDetails);
+ vxlanGpeTunnelDetailsReplyDumpCompletionStage.complete(value);
+
+ doReturn(vxlanGpeTunnelDetailsReplyDumpCompletionStage).when(api).vxlanGpeTunnelDump(any(VxlanGpeTunnelDump.class));
+ }
+
+ @Test
+ public void testReadCurrentAttributes() throws Exception {
+ final VxlanGpeBuilder builder = getCustomizer().getBuilder(VXLAN_GPE_ID);
+ getCustomizer().readCurrentAttributes(VXLAN_GPE_ID, builder, ctx);
+
+ assertNull(builder.getLocal().getIpv6Address());
+ assertNotNull(builder.getLocal().getIpv4Address());
+ assertEquals("1.2.3.4", builder.getLocal().getIpv4Address().getValue());
+
+ assertNull(builder.getRemote().getIpv6Address());
+ assertNotNull(builder.getRemote().getIpv4Address());
+ assertEquals("1.2.3.5", builder.getRemote().getIpv4Address().getValue());
+
+ assertEquals(9, builder.getVni().getValue().intValue());
+ assertEquals(1, builder.getNextProtocol().getIntValue());
+ assertEquals(55, builder.getEncapVrfId().intValue());
+ assertEquals(66, builder.getDecapVrfId().intValue());
+
+ verify(api).vxlanGpeTunnelDump(any(VxlanGpeTunnelDump.class));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testReadCurrentAttributesVppNameNotCached() throws Exception {
+ InterfaceCustomizer.getCachedInterfaceDump(cache).remove(0);
+
+ final VxlanGpeBuilder builder = getCustomizer().getBuilder(VXLAN_GPE_ID);
+ getCustomizer().readCurrentAttributes(VXLAN_GPE_ID, builder, ctx);
+ }
+
+ @Test
+ public void testReadCurrentAttributesWrongType() throws Exception {
+ final SwInterfaceDetails v = new SwInterfaceDetails();
+ v.interfaceName = "tap-3".getBytes();
+ InterfaceCustomizer.getCachedInterfaceDump(cache).put(0, v);
+
+ final VxlanGpeBuilder builder = getCustomizer().getBuilder(VXLAN_GPE_ID);
+ getCustomizer().readCurrentAttributes(VXLAN_GPE_ID, builder, ctx);
+
+ // Should be ignored
+ verifyZeroInteractions(api);
+ }
+
+ @Override
+ protected ReaderCustomizer<VxlanGpe, VxlanGpeBuilder> initCustomizer() {
+ return new VxlanGpeCustomizer(api, interfacesContext);
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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
new file mode 100644
index 000000000..e4814296d
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java
@@ -0,0 +1,297 @@
+/*
+ * 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 io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMapping;
+import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMappingIid;
+import static io.fd.honeycomb.translate.v3po.util.TranslateUtils.reverseBytes;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.honeycomb.translate.v3po.test.ListReaderCustomizerTest;
+import io.fd.honeycomb.translate.ModificationCache;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.v3po.util.NamingContext;
+import io.fd.honeycomb.translate.v3po.util.TranslateUtils;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
+import org.hamcrest.CoreMatchers;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.MappingsBuilder;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+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.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.AddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.AddressKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+import org.openvpp.jvpp.dto.IpAddressDetails;
+import org.openvpp.jvpp.dto.IpAddressDetailsReplyDump;
+import org.openvpp.jvpp.dto.IpAddressDump;
+
+public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address, AddressKey, AddressBuilder> {
+
+ private static final String IFACE_NAME = "eth0";
+ private static final String IFACE_2_NAME = "eth1";
+ private static final int IFACE_ID = 1;
+ private static final int IFACE_2_ID = 2;
+
+ private NamingContext interfacesContext;
+
+ public Ipv4AddressCustomizerTest() {
+ super(Address.class);
+ }
+
+ @Override
+ public void setUpBefore() {
+ interfacesContext = new NamingContext("generatedIfaceName", "test-instance");
+ }
+
+ @Override
+ protected ReaderCustomizer<Address, AddressBuilder> initCustomizer() {
+ final KeyedInstanceIdentifier<Mapping, MappingKey> eth0Id = getMappingIid(IFACE_NAME, "test-instance");
+ final KeyedInstanceIdentifier<Mapping, MappingKey> eth1Id = getMappingIid(IFACE_2_NAME, "test-instance");
+ final Optional<Mapping> eth0 = getMapping(IFACE_NAME, IFACE_ID);
+ final Optional<Mapping> eth1 = getMapping(IFACE_2_NAME, IFACE_2_ID);
+
+ final List<Mapping> allMappings = Lists.newArrayList(eth0.get(), eth1.get());
+ final Mappings allMappingsBaObject = new MappingsBuilder().setMapping(allMappings).build();
+ doReturn(Optional.of(allMappingsBaObject)).when(mappingContext).read(eth0Id.firstIdentifierOf(Mappings.class));
+
+ doReturn(eth0).when(mappingContext).read(eth0Id);
+ doReturn(eth1).when(mappingContext).read(eth1Id);
+
+ return new Ipv4AddressCustomizer(api, interfacesContext);
+ }
+
+ private static InstanceIdentifier<Address> getId(final String address, final String ifaceName) {
+ return InstanceIdentifier.builder(InterfacesState.class)
+ .child(Interface.class, new InterfaceKey(ifaceName))
+ .augmentation(Interface2.class)
+ .child(Ipv4.class)
+ .child(Address.class, new AddressKey(new Ipv4AddressNoZone(new Ipv4Address(address))))
+ .build();
+ }
+
+ @Test
+ public void testReadCurrentAttributesFromCache() throws ReadFailedException {
+ ModificationCache cache = new ModificationCache();
+
+ IpAddressDetails detail1 = new IpAddressDetails();
+ IpAddressDetails detail2 = new IpAddressDetails();
+ IpAddressDetails detail3 = new IpAddressDetails();
+
+ detail1.ip = reverseBytes(
+ TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
+ detail2.ip = reverseBytes(
+ TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2"))));
+ detail3.ip = reverseBytes(
+ TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.3"))));
+
+ IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump();
+ reply.ipAddressDetails = ImmutableList.of(detail1, detail2, detail3);
+
+ cache.put(Ipv4ReadUtils.CACHE_KEY + IFACE_NAME, reply);
+ when(ctx.getModificationCache()).thenReturn(cache);
+
+ final AddressBuilder builder = new AddressBuilder();
+ final InstanceIdentifier<Address> id = getId("192.168.2.1", IFACE_NAME);
+
+ getCustomizer().readCurrentAttributes(id, builder, ctx);
+
+ assertEquals("192.168.2.1", builder.getIp().getValue());
+ }
+
+ @Test
+ public void testReadCurrentAttributesFor2Ifcs() throws ReadFailedException {
+ ModificationCache cache = new ModificationCache();
+
+ IpAddressDetails detail1 = new IpAddressDetails();
+ IpAddressDetails detail2 = new IpAddressDetails();
+
+ detail1.ip = reverseBytes(
+ TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
+ detail2.ip = reverseBytes(
+ TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2"))));
+
+ IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump();
+ reply.ipAddressDetails = ImmutableList.of(detail1);
+ IpAddressDetailsReplyDump reply2 = new IpAddressDetailsReplyDump();
+ reply2.ipAddressDetails = ImmutableList.of(detail2);
+
+ CompletableFuture<IpAddressDetailsReplyDump> future = new CompletableFuture<>();
+ future.complete(reply);
+ CompletableFuture<IpAddressDetailsReplyDump> future2 = new CompletableFuture<>();
+ future2.complete(reply2);
+
+ when(api.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future).thenReturn(future2);
+ when(ctx.getModificationCache()).thenReturn(cache);
+
+ final InstanceIdentifier<Address> id = getId("192.168.2.1", IFACE_NAME);
+ final InstanceIdentifier<Address> id2 = getId("192.168.2.2", IFACE_2_NAME);
+
+ final List<AddressKey> ifc1Ids = getCustomizer().getAllIds(id, ctx);
+ assertThat(ifc1Ids.size(), is(1));
+ assertThat(ifc1Ids, CoreMatchers.hasItem(new AddressKey(new Ipv4AddressNoZone("192.168.2.1"))));
+ final List<AddressKey> ifc2Ids = getCustomizer().getAllIds(id2, ctx);
+ assertThat(ifc2Ids.size(), is(1));
+ assertThat(ifc2Ids, CoreMatchers.hasItem(new AddressKey(new Ipv4AddressNoZone("192.168.2.2"))));
+
+ AddressBuilder builder = new AddressBuilder();
+ getCustomizer().readCurrentAttributes(id, builder, ctx);
+ assertEquals(builder.getIp().getValue(), "192.168.2.1");
+ builder = new AddressBuilder();
+ getCustomizer().readCurrentAttributes(id2, builder, ctx);
+ assertEquals(builder.getIp().getValue(), "192.168.2.2");
+ }
+
+ @Test
+ public void testReadCurrentAttributesFromOperationalData() throws ReadFailedException {
+ ModificationCache cache = new ModificationCache();
+
+ IpAddressDetails detail1 = new IpAddressDetails();
+ IpAddressDetails detail2 = new IpAddressDetails();
+ IpAddressDetails detail3 = new IpAddressDetails();
+
+ detail1.ip = reverseBytes(
+ TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
+ detail2.ip = reverseBytes(
+ TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2"))));
+ detail3.ip = reverseBytes(
+ TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.3"))));
+
+ IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump();
+ reply.ipAddressDetails = ImmutableList.of(detail1, detail2, detail3);
+
+ CompletableFuture<IpAddressDetailsReplyDump> future = new CompletableFuture<>();
+ future.complete(reply);
+
+ when(api.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future);
+ when(ctx.getModificationCache()).thenReturn(cache);
+
+
+ final AddressBuilder builder = new AddressBuilder();
+ final InstanceIdentifier<Address> id = getId("192.168.2.1", IFACE_NAME);
+
+ getCustomizer().readCurrentAttributes(id, builder, ctx);
+
+ assertEquals("192.168.2.1", builder.getIp().getValue());
+ }
+
+ @Test
+ public void testGetAllIdsFromCache() throws ReadFailedException {
+ ModificationCache cache = new ModificationCache();
+
+ IpAddressDetails detail1 = new IpAddressDetails();
+ IpAddressDetails detail2 = new IpAddressDetails();
+ IpAddressDetails detail3 = new IpAddressDetails();
+
+ detail1.ip = reverseBytes(
+ TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
+ detail2.ip = reverseBytes(
+ TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2"))));
+ detail3.ip = reverseBytes(
+ TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.3"))));
+
+ IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump();
+ reply.ipAddressDetails = ImmutableList.of(detail1, detail2, detail3);
+
+ cache.put(Ipv4ReadUtils.CACHE_KEY + IFACE_NAME, reply);
+ when(ctx.getModificationCache()).thenReturn(cache);
+
+ final InstanceIdentifier<Address> id = getId("192.168.2.1", IFACE_NAME);
+
+ List<Ipv4AddressNoZone> ids = getCustomizer().getAllIds(id, ctx).stream()
+ .map(key -> key.getIp())
+ .collect(Collectors.toList());
+
+ verify(api, times(0)).ipAddressDump(Mockito.any(IpAddressDump.class));
+ assertEquals(3, ids.size());
+ assertEquals(true, "192.168.2.1".equals(ids.get(0).getValue()));
+ assertEquals(true, "192.168.2.2".equals(ids.get(1).getValue()));
+ assertEquals(true, "192.168.2.3".equals(ids.get(2).getValue()));
+ }
+
+ @Test
+ public void testGetAllIdsFromOperationalData() throws ReadFailedException {
+ ModificationCache cache = new ModificationCache();
+
+ IpAddressDetails detail1 = new IpAddressDetails();
+ IpAddressDetails detail2 = new IpAddressDetails();
+ IpAddressDetails detail3 = new IpAddressDetails();
+
+ detail1.ip = reverseBytes(
+ TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
+ detail2.ip = reverseBytes(
+ TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2"))));
+ detail3.ip = reverseBytes(
+ TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.3"))));
+
+ IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump();
+ reply.ipAddressDetails = ImmutableList.of(detail1, detail2, detail3);
+
+ CompletableFuture<IpAddressDetailsReplyDump> future = new CompletableFuture<>();
+ future.complete(reply);
+
+ when(api.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future);
+ when(ctx.getModificationCache()).thenReturn(cache);
+
+ final InstanceIdentifier<Address> id = getId("192.168.2.1", IFACE_NAME);
+
+ List<Ipv4AddressNoZone> ids = getCustomizer().getAllIds(id, ctx).stream()
+ .map(key -> key.getIp())
+ .collect(Collectors.toList());
+
+ assertEquals(3, ids.size());
+ assertEquals(true, "192.168.2.1".equals(ids.get(0).getValue()));
+ assertEquals(true, "192.168.2.2".equals(ids.get(1).getValue()));
+ assertEquals(true, "192.168.2.3".equals(ids.get(2).getValue()));
+ }
+
+ @Test
+ public void testMerge() {
+
+ Address address = new AddressBuilder().build();
+ Ipv4Builder ipv4Builder = new Ipv4Builder();
+ getCustomizer().merge(ipv4Builder, Arrays.asList(address));
+
+ assertEquals(1, ipv4Builder.getAddress().size());
+ assertEquals(true, ipv4Builder.getAddress().contains(address));
+ }
+
+}