summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate
diff options
context:
space:
mode:
authorMaros Marsalek <mmarsale@cisco.com>2016-11-10 13:31:25 +0100
committerMarek Gradzki <mgradzki@cisco.com>2016-11-19 21:29:39 +0100
commit175197da8ea43335df3daeba4c6296fcd83a057c (patch)
tree110298a990c6191933c2ad65d1a06333bab76cee /v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate
parent1813bf59fa53e8eb913d34b212d45b227dead799 (diff)
Post split cleanup
- change groupIds - change packages - update poms Change-Id: I343c5a292a67de1dd50687870ca4ab5b7276e93e Signed-off-by: Maros Marsalek <mmarsale@cisco.com> Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate')
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/EthernetCustomizerTest.java90
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/GreCustomizerTest.java131
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizerTest.java200
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceDataTranslatorTest.java55
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/L2CustomizerTest.java145
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizerTest.java114
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizerTest.java129
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceL2CustomizerTest.java80
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/TapCustomizerTest.java98
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VhostUserCustomizerTest.java115
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizerTest.java133
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanGpeCustomizerTest.java278
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/acl/ingress/AclCustomizerTest.java99
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/acl/ingress/SubInterfaceAclCustomizerTest.java108
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java284
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4CustomizerTest.java44
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizerTest.java247
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/pbb/PbbRewriteStateCustomizerTest.java35
18 files changed, 2385 insertions, 0 deletions
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/EthernetCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/EthernetCustomizerTest.java
new file mode 100644
index 000000000..338d63333
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/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.hc2vpp.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.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest;
+import io.fd.hc2vpp.common.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.rev161214.EthernetStateAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceStateAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.Ethernet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.EthernetBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import io.fd.vpp.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/hc2vpp/v3po/interfacesstate/GreCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/GreCustomizerTest.java
new file mode 100644
index 000000000..1aadb5bd1
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/GreCustomizerTest.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.v3po.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.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+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.rev161214.VppInterfaceStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceStateAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.Gre;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.GreBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import io.fd.vpp.jvpp.VppInvocationException;
+import io.fd.vpp.jvpp.core.dto.GreTunnelDetails;
+import io.fd.vpp.jvpp.core.dto.GreTunnelDetailsReplyDump;
+import io.fd.vpp.jvpp.core.dto.GreTunnelDump;
+import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails;
+
+public class GreCustomizerTest extends ReaderCustomizerTest<Gre, GreBuilder> {
+
+ private static final String IFACE_NAME = "ifc1";
+ private static final int IFACE_ID = 0;
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+
+ private NamingContext interfacesContext;
+ static final InstanceIdentifier<Gre> IID =
+ InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IFACE_NAME))
+ .augmentation(VppInterfaceStateAugmentation.class).child(Gre.class);
+
+ public GreCustomizerTest() {
+ super(Gre.class, VppInterfaceStateAugmentationBuilder.class);
+ }
+
+ @Override
+ public void setUp() throws UnknownHostException, VppInvocationException {
+ interfacesContext = new NamingContext("gre-tunnel", IFC_CTX_NAME);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+
+ final SwInterfaceDetails v = new SwInterfaceDetails();
+ v.interfaceName = "gre-tunnel4".getBytes();
+ final Map<Integer, SwInterfaceDetails> map = new HashMap<>();
+ map.put(0, v);
+ cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, map);
+
+ final GreTunnelDetailsReplyDump value = new GreTunnelDetailsReplyDump();
+ final GreTunnelDetails greTunnelDetails = new GreTunnelDetails();
+ greTunnelDetails.isIpv6 = 0;
+ greTunnelDetails.dstAddress = InetAddress.getByName("1.2.3.4").getAddress();
+ greTunnelDetails.srcAddress = InetAddress.getByName("1.2.3.5").getAddress();
+ greTunnelDetails.outerFibId = 55;
+ greTunnelDetails.swIfIndex = 0;
+ value.greTunnelDetails = Lists.newArrayList(greTunnelDetails);
+
+ doReturn(future(value)).when(api).greTunnelDump(any(GreTunnelDump.class));
+ }
+
+ @Test
+ public void testReadCurrentAttributes() throws Exception {
+ final GreBuilder builder = getCustomizer().getBuilder(IID);
+ getCustomizer().readCurrentAttributes(IID, builder, ctx);
+
+ assertEquals(55, builder.getOuterFibId().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).greTunnelDump(any(GreTunnelDump.class));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testReadCurrentAttributesVppNameNotCached() throws Exception {
+ InterfaceCustomizer.getCachedInterfaceDump(cache).remove(0);
+
+ final GreBuilder 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 GreBuilder builder = getCustomizer().getBuilder(IID);
+ getCustomizer().readCurrentAttributes(IID, builder, ctx);
+
+ // Should be ignored
+ verifyZeroInteractions(api);
+ }
+
+ @Override
+ protected ReaderCustomizer<Gre, GreBuilder> initCustomizer() {
+ return new GreCustomizer(api, interfacesContext);
+ }
+} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizerTest.java
new file mode 100644
index 000000000..295805114
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizerTest.java
@@ -0,0 +1,200 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.v3po.interfacesstate;
+
+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 io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.hc2vpp.v3po.DisabledInterfacesManager;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest;
+import io.fd.hc2vpp.common.test.util.InterfaceDumpHelper;
+import java.util.Arrays;
+import java.util.List;
+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.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 io.fd.vpp.jvpp.VppInvocationException;
+import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails;
+import io.fd.vpp.jvpp.core.dto.SwInterfaceDump;
+
+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";
+ private static final String IFACE1_NAME = "eth1";
+ private static final String SUB_IFACE_NAME = "eth1.1";
+ private static final int IFACE0_ID = 0;
+ private static final int IFACE1_ID = 1;
+ private static final int SUB_IFACE_ID = 2;
+
+ private NamingContext interfacesContext;
+ @Mock
+ private DisabledInterfacesManager interfaceDisableContext;
+
+ public InterfaceCustomizerTest() {
+ super(Interface.class, InterfacesStateBuilder.class);
+ }
+
+ @Override
+ public void setUp() {
+ interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
+ defineMapping(mappingContext, IFACE0_NAME, IFACE0_ID, IFC_CTX_NAME);
+ defineMapping(mappingContext, IFACE1_NAME, IFACE1_ID, IFC_CTX_NAME);
+ defineMapping(mappingContext, SUB_IFACE_NAME, SUB_IFACE_ID, IFC_CTX_NAME);
+ }
+
+ @Override
+ protected ReaderCustomizer<Interface, InterfaceBuilder> initCustomizer() {
+ return new InterfaceCustomizer(api, interfacesContext, interfaceDisableContext);
+ }
+
+ private void verifySwInterfaceDumpWasInvoked(final int nameFilterValid, final String ifaceName,
+ final int dumpIfcsInvocationCount)
+ throws VppInvocationException {
+ final SwInterfaceDump expected = new SwInterfaceDump();
+ expected.nameFilterValid = (byte) nameFilterValid;
+ expected.nameFilter = ifaceName.getBytes();
+ verify(api, times(dumpIfcsInvocationCount)).swInterfaceDump(expected);
+ }
+
+ private void assertIfacesAreEqual(final Interface iface, final SwInterfaceDetails details) {
+ assertEquals(iface.getName(), new String(details.interfaceName));
+ assertEquals(yangIfIndexToVpp(iface.getIfIndex().intValue()), details.swIfIndex);
+ assertEquals(iface.getPhysAddress().getValue(), vppPhysAddrToYang(details.l2Address));
+ }
+
+ @Test
+ public void testReadCurrentAttributes() throws Exception {
+ final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class, new InterfaceKey(IFACE0_NAME));
+ final InterfaceBuilder builder = getCustomizer().getBuilder(id);
+
+ final SwInterfaceDetails iface = new SwInterfaceDetails();
+ iface.interfaceName = IFACE0_NAME.getBytes();
+ iface.swIfIndex = 0;
+ iface.linkSpeed = 1;
+ iface.l2AddressLength = 6;
+ iface.l2Address = new byte[iface.l2AddressLength];
+ whenSwInterfaceDumpThenReturn(api, iface);
+
+ getCustomizer().readCurrentAttributes(id, builder, ctx);
+
+ verifySwInterfaceDumpWasInvoked(1, IFACE0_NAME, 1);
+ assertIfacesAreEqual(builder.build(), iface);
+ }
+
+ @Test
+ public void testReadCurrentAttributesFailed() throws Exception {
+ final String ifaceName = IFACE0_NAME;
+ final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class, new InterfaceKey(ifaceName));
+ final InterfaceBuilder builder = getCustomizer().getBuilder(id);
+
+ whenSwInterfaceDumpThenReturn(api);
+
+ 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 InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class, new InterfaceKey(SUB_IFACE_NAME));
+ final InterfaceBuilder builder = mock(InterfaceBuilder.class);
+
+ final SwInterfaceDetails iface = new SwInterfaceDetails();
+ iface.interfaceName = SUB_IFACE_NAME.getBytes();
+ iface.swIfIndex = 2;
+ iface.supSwIfIndex = 1;
+ iface.subId = 1;
+ whenSwInterfaceDumpThenReturn(api, iface);
+
+ getCustomizer().readCurrentAttributes(id, builder, ctx);
+
+ verifySwInterfaceDumpWasInvoked(1, SUB_IFACE_NAME, 1);
+ verifyZeroInteractions(builder);
+ }
+
+ @Test
+ public void testGetAllIds() throws Exception {
+ final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class);
+
+ final SwInterfaceDetails swIf0 = new SwInterfaceDetails();
+ swIf0.swIfIndex = 0;
+ swIf0.interfaceName = IFACE0_NAME.getBytes();
+ final SwInterfaceDetails swIf1 = new SwInterfaceDetails();
+ swIf1.swIfIndex = 1;
+ swIf1.interfaceName = IFACE1_NAME.getBytes();
+ final SwInterfaceDetails swSubIf1 = new SwInterfaceDetails();
+ swSubIf1.swIfIndex = 2;
+ swSubIf1.subId = 1;
+ swSubIf1.supSwIfIndex = 1;
+ swSubIf1.interfaceName = SUB_IFACE_NAME.getBytes();
+ whenSwInterfaceDumpThenReturn(api, swIf0, swIf1, swSubIf1);
+
+ final List<InterfaceKey> expectedIds = Arrays.asList(new InterfaceKey(IFACE0_NAME), new InterfaceKey(
+ IFACE1_NAME));
+ final List<InterfaceKey> actualIds = getCustomizer().getAllIds(id, ctx);
+
+ verifySwInterfaceDumpWasInvoked(0, "", 1);
+
+ // sub-interface should not be on the list
+ assertEquals(expectedIds, actualIds);
+ }
+
+ @Test
+ public void testGetAllIdsWithDisabled() throws Exception {
+ final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class);
+
+ doReturn(true).when(interfaceDisableContext).isInterfaceDisabled(1, mappingContext);
+
+ final SwInterfaceDetails swIf0 = new SwInterfaceDetails();
+ swIf0.swIfIndex = 0;
+ swIf0.interfaceName = IFACE0_NAME.getBytes();
+ final SwInterfaceDetails swIf1 = new SwInterfaceDetails();
+ swIf1.swIfIndex = 1;
+ swIf1.interfaceName = IFACE1_NAME.getBytes();
+ whenSwInterfaceDumpThenReturn(api, swIf0, swIf1);
+
+ final List<InterfaceKey> expectedIds = Arrays.asList(new InterfaceKey(IFACE0_NAME));
+ final List<InterfaceKey> actualIds = getCustomizer().getAllIds(id, ctx);
+
+ // disabled interface should not be on the list
+ assertEquals(expectedIds, actualIds);
+ }
+}
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceDataTranslatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceDataTranslatorTest.java
new file mode 100644
index 000000000..7c7f64817
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceDataTranslatorTest.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.hc2vpp.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.rev161214.Tap;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VhostUser;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VxlanGpeTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VxlanTunnel;
+
+public class InterfaceDataTranslatorTest implements InterfaceDataTranslator {
+
+ @Test
+ public void testVppPhysAddrToYang() throws Exception {
+ assertEquals("01:02:03:04:05:06", vppPhysAddrToYang(new byte[]{1, 2, 3, 4, 5, 6}));
+ assertEquals("0a:0b:0c:0d:0e:0f", vppPhysAddrToYang(new byte[]{0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0, 0}));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testVppPhysAddrToYangFailNullArgument() throws Exception {
+ vppPhysAddrToYang(null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testVppPhysAddrToYangInvalidByteArrayLength() throws Exception {
+ vppPhysAddrToYang(new byte[]{1, 2, 3, 4, 5});
+ }
+
+ @Test
+ public void testGetInterfaceType() {
+ assertEquals(Tap.class, getInterfaceType("tap0"));
+ assertEquals(VxlanTunnel.class, getInterfaceType("vxlan0"));
+ assertEquals(VxlanGpeTunnel.class, getInterfaceType("vxlan_gpe0"));
+ assertEquals(VhostUser.class, getInterfaceType("VirtualEthernet0/0/0"));
+ assertEquals(EthernetCsmacd.class, getInterfaceType("eth0.0"));
+ assertEquals(EthernetCsmacd.class, getInterfaceType("local0"));
+ }
+} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/L2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/L2CustomizerTest.java
new file mode 100644
index 000000000..531e18d22
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/L2CustomizerTest.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.v3po.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.spi.read.ReaderCustomizer;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+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.rev161214.VppInterfaceStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceStateAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.L2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.L2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.base.attributes.Interconnection;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.base.attributes.interconnection.BridgeBasedBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import io.fd.vpp.jvpp.core.dto.BridgeDomainDetails;
+import io.fd.vpp.jvpp.core.dto.BridgeDomainDetailsReplyDump;
+import io.fd.vpp.jvpp.core.dto.BridgeDomainDump;
+import io.fd.vpp.jvpp.core.dto.BridgeDomainSwIfDetails;
+import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails;
+
+public class L2CustomizerTest 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;
+
+ public L2CustomizerTest() {
+ super(L2.class, VppInterfaceStateAugmentationBuilder.class);
+ }
+
+ @Override
+ public void setUp() {
+ interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
+ bridgeDomainContext = new NamingContext("generatedBDName", BD_CTX_NAME);
+ }
+
+ @Override
+ protected ReaderCustomizer<L2, L2Builder> initCustomizer() {
+ return new L2Customizer(api, interfaceContext, bridgeDomainContext);
+ }
+
+ 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) {
+ final BridgeDomainDetailsReplyDump reply = new BridgeDomainDetailsReplyDump();
+ reply.bridgeDomainSwIfDetails = bdSwIfList;
+ reply.bridgeDomainDetails = bridgeDomainDetailses;
+ when(api.bridgeDomainSwIfDump(any(BridgeDomainDump.class))).thenReturn(future(reply));
+ }
+
+
+ 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";
+ defineMapping(mappingContext, ifName, ifId, IFC_CTX_NAME);
+ defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
+
+ final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails();
+ ifaceDetails.subId = ifId;
+ cachedInterfaceDump.put(ifId, ifaceDetails);
+ cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump);
+
+ // BVIinterfaceContext
+ 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/hc2vpp/v3po/interfacesstate/RewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizerTest.java
new file mode 100644
index 000000000..1b79f518c
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizerTest.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.v3po.interfacesstate;
+
+import static org.junit.Assert.assertEquals;
+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.hc2vpp.common.test.read.ReaderCustomizerTest;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.common.translate.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.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.rev161214.SubinterfaceStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214._802dot1q;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.SubInterfaces;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.L2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.l2.Rewrite;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.l2.RewriteBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.tag.rewrite.PushTags;
+import org.opendaylight.yangtools.yang.binding.ChildOf;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails;
+
+public class RewriteCustomizerTest extends ReaderCustomizerTest<Rewrite, RewriteBuilder> {
+
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String IF_NAME = "local0";
+ private static final String VLAN_IF_NAME = "local0.1";
+ private static final int VLAN_IF_INDEX = 11;
+ private static final int VLAN_ID = 1;
+
+ private NamingContext interfacesContext;
+
+ @Captor
+ private ArgumentCaptor<List<PushTags>> captor;
+
+ public RewriteCustomizerTest() {
+ super(Rewrite.class, L2Builder.class);
+ }
+
+ @Override
+ public void setUp() {
+ interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
+ defineMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_CTX_NAME);
+ }
+
+ @Override
+ protected ReaderCustomizer<Rewrite, RewriteBuilder> initCustomizer() {
+ return new RewriteCustomizer(api, interfacesContext);
+ }
+
+ 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_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(IF_NAME, VLAN_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/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizerTest.java
new file mode 100644
index 000000000..802d040dc
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizerTest.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.v3po.interfacesstate;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+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.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest;
+import io.fd.hc2vpp.common.test.util.InterfaceDumpHelper;
+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.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.rev161214.SubinterfaceStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.SubInterfaces;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.SubInterfacesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.match.attributes.match.type.VlanTagged;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.Tags;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails;
+
+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";
+ private static final int SUPER_IF_INDEX = 1;
+ private static final String VLAN_IF_NAME = "local0.1";
+ private static final int VLAN_IF_ID = 1;
+ private static final int VLAN_IF_INDEX = 11;
+
+ private NamingContext interfacesContext;
+
+ public SubInterfaceCustomizerTest() {
+ super(SubInterface.class, SubInterfacesBuilder.class);
+ }
+
+ @Override
+ public void setUp() {
+ interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
+ defineMapping(mappingContext, SUPER_IF_NAME, SUPER_IF_INDEX, IFC_CTX_NAME);
+ defineMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_CTX_NAME);
+ }
+
+ @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 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.subDot1Ad = 1;
+ defineMapping(mappingContext, SUPER_IF_NAME, SUPER_IF_INDEX, IFC_CTX_NAME);
+ defineMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_CTX_NAME);
+ 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(SUPER_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 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;
+ whenSwInterfaceDumpThenReturn(api, iface);
+
+ final List<SubInterfaceKey> allIds =
+ getCustomizer().getAllIds(getSubInterfaceId(SUPER_IF_NAME, VLAN_IF_ID), ctx);
+
+ assertEquals(1, allIds.size());
+ }
+} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceL2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceL2CustomizerTest.java
new file mode 100644
index 000000000..fc7d8e853
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceL2CustomizerTest.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.v3po.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.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.common.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.rev161214.SubinterfaceStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.SubInterfaces;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.L2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.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/hc2vpp/v3po/interfacesstate/TapCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/TapCustomizerTest.java
new file mode 100644
index 000000000..c9de7102a
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/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.hc2vpp.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.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest;
+import io.fd.hc2vpp.common.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.rev161214.VppInterfaceStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceStateAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.Tap;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.TapBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails;
+import io.fd.vpp.jvpp.core.dto.SwInterfaceTapDetails;
+import io.fd.vpp.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/hc2vpp/v3po/interfacesstate/VhostUserCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VhostUserCustomizerTest.java
new file mode 100644
index 000000000..57655db73
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/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.hc2vpp.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.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest;
+import io.fd.hc2vpp.common.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.rev161214.VhostUserRole;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceStateAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.VhostUser;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.VhostUserBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails;
+import io.fd.vpp.jvpp.core.dto.SwInterfaceVhostUserDetails;
+import io.fd.vpp.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/hc2vpp/v3po/interfacesstate/VxlanCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizerTest.java
new file mode 100644
index 000000000..d59d13672
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizerTest.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.v3po.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.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+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.rev161214.VppInterfaceStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceStateAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.Vxlan;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.VxlanBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import io.fd.vpp.jvpp.VppInvocationException;
+import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails;
+import io.fd.vpp.jvpp.core.dto.VxlanTunnelDetails;
+import io.fd.vpp.jvpp.core.dto.VxlanTunnelDetailsReplyDump;
+import io.fd.vpp.jvpp.core.dto.VxlanTunnelDump;
+
+public class VxlanCustomizerTest extends ReaderCustomizerTest<Vxlan, VxlanBuilder> {
+
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String IF_NAME = "ifc1";
+ private static final int IF_INDEX = 0;
+
+ private NamingContext interfacesContext;
+ static final InstanceIdentifier<Vxlan> IID =
+ InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME))
+ .augmentation(VppInterfaceStateAugmentation.class).child(Vxlan.class);
+
+ public VxlanCustomizerTest() {
+ super(Vxlan.class, VppInterfaceStateAugmentationBuilder.class);
+ }
+
+ @Override
+ public void setUp() throws UnknownHostException, VppInvocationException {
+ interfacesContext = new NamingContext("vxlan-tunnel", IFC_CTX_NAME);
+ defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
+
+ 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);
+
+ 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);
+ doReturn(future(value)).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/hc2vpp/v3po/interfacesstate/VxlanGpeCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanGpeCustomizerTest.java
new file mode 100644
index 000000000..e0abd51ec
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanGpeCustomizerTest.java
@@ -0,0 +1,278 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.v3po.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.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+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.rev161214.VppInterfaceStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceStateAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.VxlanGpe;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.VxlanGpeBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import io.fd.vpp.jvpp.VppBaseCallException;
+import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails;
+import io.fd.vpp.jvpp.core.dto.VxlanGpeTunnelDetails;
+import io.fd.vpp.jvpp.core.dto.VxlanGpeTunnelDetailsReplyDump;
+import io.fd.vpp.jvpp.core.dto.VxlanGpeTunnelDump;
+
+public class VxlanGpeCustomizerTest extends ReaderCustomizerTest<VxlanGpe, VxlanGpeBuilder> {
+
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String IF_NAME = "ifc2";
+ private static final int IF_INDEX = 0;
+
+ private NamingContext interfacesContext;
+ private static final InstanceIdentifier<VxlanGpe> VXLAN_GPE_ID =
+ InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME))
+ .augmentation(VppInterfaceStateAugmentation.class).child(VxlanGpe.class);
+
+ public VxlanGpeCustomizerTest() {
+ super(VxlanGpe.class, VppInterfaceStateAugmentationBuilder.class);
+ }
+
+ @Override
+ public void setUp() throws UnknownHostException, VppBaseCallException {
+ interfacesContext = new NamingContext("vxlan_gpe_inf", IFC_CTX_NAME);
+ defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
+
+ 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);
+
+ 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);
+ doReturn(future(value)).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/hc2vpp/v3po/interfacesstate/acl/ingress/AclCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/acl/ingress/AclCustomizerTest.java
new file mode 100644
index 000000000..6948302e8
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/acl/ingress/AclCustomizerTest.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.v3po.interfacesstate.acl.ingress;
+
+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.hc2vpp.v3po.vppclassifier.VppClassifierContextManager;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest;
+import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterfaceReply;
+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.rev161214.VppInterfaceStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.acl.base.attributes.L2AclBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.Acl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.AclBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.acl.Ingress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.acl.IngressBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class AclCustomizerTest extends ReaderCustomizerTest<Ingress, IngressBuilder> {
+
+ 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 InstanceIdentifier<Ingress> IID =
+ InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME))
+ .augmentation(VppInterfaceStateAugmentation.class).child(Acl.class).child(Ingress.class);
+
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+
+ private NamingContext interfaceContext;
+
+ @Mock
+ private VppClassifierContextManager classifyTableContext;
+
+ public AclCustomizerTest() {
+ super(Ingress.class, AclBuilder.class);
+ }
+
+ @Override
+ public void setUp() {
+ interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
+ defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
+ }
+
+ @Override
+ protected ReaderCustomizer<Ingress, IngressBuilder> initCustomizer() {
+ return new AclCustomizer(api, interfaceContext, classifyTableContext);
+ }
+
+ @Test
+ public void testRead() throws ReadFailedException {
+ final IngressBuilder builder = mock(IngressBuilder.class);
+
+ final ClassifyTableByInterfaceReply reply = new ClassifyTableByInterfaceReply();
+ reply.l2TableId = TABLE_INDEX;
+ reply.ip4TableId = ~0;
+ reply.ip6TableId = ~0;
+ when(api.classifyTableByInterface(any())).thenReturn(future(reply));
+
+ when(classifyTableContext.getTableName(TABLE_INDEX, mappingContext)).thenReturn(TABLE_NAME);
+
+ 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(IngressBuilder.class), ctx);
+ }
+} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/acl/ingress/SubInterfaceAclCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/acl/ingress/SubInterfaceAclCustomizerTest.java
new file mode 100644
index 000000000..9dbb20fb0
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/acl/ingress/SubInterfaceAclCustomizerTest.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.v3po.interfacesstate.acl.ingress;
+
+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.hc2vpp.v3po.vppclassifier.VppClassifierContextManager;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest;
+import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterfaceReply;
+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.vpp.acl.rev161214.acl.base.attributes.Ip4AclBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.acl.base.attributes.Ip6AclBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.SubinterfaceStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.SubInterfaces;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.Acl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.AclBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.acl.Ingress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.acl.IngressBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class SubInterfaceAclCustomizerTest extends ReaderCustomizerTest<Ingress, IngressBuilder> {
+ 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<Ingress> 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).child(Ingress.class);
+
+ private NamingContext interfaceContext;
+
+ @Mock
+ private VppClassifierContextManager classifyTableContext;
+
+ public SubInterfaceAclCustomizerTest() {
+ super(Ingress.class, AclBuilder.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<Ingress, IngressBuilder> initCustomizer() {
+ return new SubInterfaceAclCustomizer(api, interfaceContext, classifyTableContext);
+ }
+
+ @Test
+ public void testRead() throws ReadFailedException {
+ final IngressBuilder builder = mock(IngressBuilder.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(IngressBuilder.class), ctx);
+ }
+} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java
new file mode 100644
index 000000000..a2eda9157
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java
@@ -0,0 +1,284 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.v3po.interfacesstate.ip;
+
+
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.honeycomb.translate.util.read.cache.CacheKeyFactory;
+import io.fd.honeycomb.translate.util.read.cache.IdentifierCacheKeyFactory;
+import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest;
+import io.fd.vpp.jvpp.core.dto.IpAddressDetails;
+import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump;
+import io.fd.vpp.jvpp.core.dto.IpAddressDump;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
+import org.hamcrest.Matchers;
+import org.junit.Test;
+import org.mockito.Mockito;
+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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.subnet.PrefixLength;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address, AddressKey, AddressBuilder> implements
+ Ipv4Translator {
+
+ 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 static final String IFC_CTX_NAME = "ifc-test-instance";
+
+ private NamingContext interfacesContext;
+ private InstanceIdentifier<Address> ifaceOneAddressOneIdentifier;
+ private InstanceIdentifier<Address> ifaceTwoAddressOneIdentifier;
+ private CacheKeyFactory cacheKeyFactory;
+
+ public Ipv4AddressCustomizerTest() {
+ super(Address.class, Ipv4Builder.class);
+ }
+
+ @Override
+ public void setUp() {
+ interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ defineMapping(mappingContext, IFACE_2_NAME, IFACE_2_ID, IFC_CTX_NAME);
+
+ ifaceOneAddressOneIdentifier =
+ InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class, new InterfaceKey(IFACE_NAME))
+ .augmentation(Interface2.class)
+ .child(Ipv4.class)
+ .child(Address.class, new AddressKey(new Ipv4AddressNoZone("192.168.2.1")));
+ ifaceTwoAddressOneIdentifier =
+ InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class, new InterfaceKey(IFACE_2_NAME))
+ .augmentation(Interface2.class)
+ .child(Ipv4.class)
+ .child(Address.class, new AddressKey(new Ipv4AddressNoZone("192.168.2.1")));
+
+ // to simulate complex key
+ cacheKeyFactory = new IdentifierCacheKeyFactory(ImmutableSet.of(Interface.class));
+ }
+
+ @Override
+ protected ReaderCustomizer<Address, AddressBuilder> initCustomizer() {
+ 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 testReadCurrentAttributesFor2Ifcs() throws ReadFailedException {
+ //changed to mock to not store first dumped data(otherwise that double thenReturn on line 118 is not gonna work)
+
+ IpAddressDetails detail1 = new IpAddressDetails();
+ IpAddressDetails detail2 = new IpAddressDetails();
+
+ detail1.ip = reverseBytes(
+ ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
+ detail2.ip = reverseBytes(
+ 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)
+ .thenReturn(future).thenReturn(future2);
+ when(api.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future(reply)).thenReturn(future(reply2))
+ .thenReturn(future(reply)).thenReturn(future(reply2));
+ 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, Matchers.hasItem(new AddressKey(new Ipv4AddressNoZone("192.168.2.1"))));
+ final List<AddressKey> ifc2Ids = getCustomizer().getAllIds(id2, ctx);
+ assertThat(ifc2Ids.size(), is(1));
+ assertThat(ifc2Ids, Matchers.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 testReadCurrentAttributesSuccessfull() throws ReadFailedException {
+ IpAddressDetails detail1 = new IpAddressDetails();
+ IpAddressDetails detail2 = new IpAddressDetails();
+ IpAddressDetails detail3 = new IpAddressDetails();
+
+ detail1.ip = reverseBytes(
+ ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
+ detail2.ip = reverseBytes(
+ ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2"))));
+ detail3.ip = reverseBytes(
+ ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.3"))));
+
+ IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump();
+ reply.ipAddressDetails = ImmutableList.of(detail1, detail2, detail3);
+ when(api.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future(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 testGetAllIdsFromSuccessfull() throws ReadFailedException {
+ IpAddressDetails detail1 = new IpAddressDetails();
+ IpAddressDetails detail2 = new IpAddressDetails();
+ IpAddressDetails detail3 = new IpAddressDetails();
+
+ detail1.ip = reverseBytes(
+ ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
+ detail2.ip = reverseBytes(
+ ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2"))));
+ detail3.ip = reverseBytes(
+ ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.3"))));
+
+ IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump();
+ reply.ipAddressDetails = ImmutableList.of(detail1, detail2, detail3);
+ when(api.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future(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());
+
+ 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 testCachingScopeSpecificRequest() throws ReadFailedException {
+ fillCacheForTwoIfaces();
+ final AddressBuilder ifaceOneAddressBuilder = new AddressBuilder();
+ final AddressBuilder ifaceTwoAddressBuilder = new AddressBuilder();
+
+ getCustomizer().readCurrentAttributes(ifaceOneAddressOneIdentifier, ifaceOneAddressBuilder, ctx);
+ getCustomizer().readCurrentAttributes(ifaceTwoAddressOneIdentifier, ifaceTwoAddressBuilder, ctx);
+
+ // addresses have caching scope of parent interface, so returned address should have respective prefix lengths
+ assertEquals("192.168.2.1", ifaceOneAddressBuilder.getIp().getValue());
+ assertTrue(ifaceOneAddressBuilder.getSubnet() instanceof PrefixLength);
+ assertEquals(22, PrefixLength.class.cast(ifaceOneAddressBuilder.getSubnet()).getPrefixLength().intValue());
+
+ assertEquals("192.168.2.1", ifaceTwoAddressBuilder.getIp().getValue());
+ assertTrue(ifaceTwoAddressBuilder.getSubnet() instanceof PrefixLength);
+ assertEquals(23, PrefixLength.class.cast(ifaceTwoAddressBuilder.getSubnet()).getPrefixLength().intValue());
+ }
+
+ @Test
+ public void testCachingScopeGetAll() throws ReadFailedException {
+ fillCacheForFirstIfaceSecondEmpty();
+
+ final List<AddressKey> keysForIfaceOne = getCustomizer().getAllIds(ifaceOneAddressOneIdentifier, ctx);
+ assertThat(keysForIfaceOne, hasSize(1));
+ final AddressKey keyIfaceOne = keysForIfaceOne.get(0);
+ assertEquals("192.168.2.1", keyIfaceOne.getIp().getValue());
+
+ final List<AddressKey> keysForIfaceTwo = getCustomizer().getAllIds(ifaceTwoAddressOneIdentifier, ctx);
+ assertThat(keysForIfaceTwo, is(empty()));
+ }
+
+ private void fillCacheForTwoIfaces() {
+ IpAddressDetails detailIfaceOneAddressOne = new IpAddressDetails();
+ IpAddressDetails detailIfaceTwoAddressOne = new IpAddressDetails();
+ IpAddressDetailsReplyDump replyIfaceOne = new IpAddressDetailsReplyDump();
+ IpAddressDetailsReplyDump replyIfaceTwo = new IpAddressDetailsReplyDump();
+
+ replyIfaceOne.ipAddressDetails = Arrays.asList(detailIfaceOneAddressOne);
+ replyIfaceTwo.ipAddressDetails = Arrays.asList(detailIfaceTwoAddressOne);
+
+ detailIfaceOneAddressOne.ip = reverseBytes(
+ ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
+ detailIfaceOneAddressOne.prefixLength = 22;
+
+ detailIfaceTwoAddressOne.ip = reverseBytes(
+ ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
+ detailIfaceTwoAddressOne.prefixLength = 23;
+
+ cache.put(cacheKeyFactory.createKey(ifaceOneAddressOneIdentifier), replyIfaceOne);
+ cache.put(cacheKeyFactory.createKey(ifaceTwoAddressOneIdentifier), replyIfaceTwo);
+ }
+
+ private void fillCacheForFirstIfaceSecondEmpty() {
+ IpAddressDetails detailIfaceOneAddressOne = new IpAddressDetails();
+ IpAddressDetailsReplyDump replyIfaceOne = new IpAddressDetailsReplyDump();
+ replyIfaceOne.ipAddressDetails = Arrays.asList(detailIfaceOneAddressOne);
+
+ detailIfaceOneAddressOne.ip = reverseBytes(
+ ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
+ detailIfaceOneAddressOne.prefixLength = 22;
+
+ cache.put(cacheKeyFactory.createKey(ifaceOneAddressOneIdentifier), replyIfaceOne);
+ cache.put(cacheKeyFactory.createKey(ifaceTwoAddressOneIdentifier), new IpAddressDetailsReplyDump());
+ }
+}
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4CustomizerTest.java
new file mode 100644
index 000000000..1bfb62771
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4CustomizerTest.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.v3po.interfacesstate.ip;
+
+import static org.mockito.Mockito.verifyZeroInteractions;
+
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2Builder;
+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;
+
+public class Ipv4CustomizerTest extends ReaderCustomizerTest<Ipv4, Ipv4Builder> {
+
+ public Ipv4CustomizerTest() {
+ super(Ipv4.class, Interface2Builder.class);
+ }
+
+ @Test
+ public void testReadCurrentAttributes() throws Exception {
+ customizer.readCurrentAttributes(null, null, ctx);
+ verifyZeroInteractions(api);
+ }
+
+ @Override
+ protected ReaderCustomizer<Ipv4, Ipv4Builder> initCustomizer() {
+ return new Ipv4Customizer(api);
+ }
+} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizerTest.java
new file mode 100644
index 000000000..cecc70235
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizerTest.java
@@ -0,0 +1,247 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.v3po.interfacesstate.ip;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+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 com.google.common.collect.ImmutableSet;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer;
+import io.fd.honeycomb.translate.util.read.cache.CacheKeyFactory;
+import io.fd.honeycomb.translate.util.read.cache.IdentifierCacheKeyFactory;
+import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest;
+import io.fd.vpp.jvpp.core.dto.IpAddressDetails;
+import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump;
+import java.util.Arrays;
+import java.util.List;
+import org.junit.Assert;
+import org.junit.Test;
+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.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.SubinterfaceStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.SubInterfaces;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.AddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.AddressKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.address.subnet.PrefixLength;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.address.subnet.PrefixLengthBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class SubInterfaceIpv4AddressCustomizerTest extends ListReaderCustomizerTest<Address, AddressKey, AddressBuilder>
+ implements Ipv4Translator {
+
+ 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 String SUB_IF_2_NAME = "local0.2";
+ private static final long SUB_IF_ID = 1;
+ private static final int SUB_IF_INDEX = 11;
+ private static final int SUB_IF_2_INDEX = 12;
+ 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 InstanceIdentifier<Address> ifaceOneAddressOneIdentifier;
+ private InstanceIdentifier<Address> ifaceTwoAddressOneIdentifier;
+ private CacheKeyFactory cacheKeyFactory;
+ 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);
+
+ ifaceOneAddressOneIdentifier = InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class, new InterfaceKey(IF_NAME))
+ .augmentation(SubinterfaceStateAugmentation.class)
+ .child(SubInterfaces.class)
+ .child(SubInterface.class, new SubInterfaceKey(1L))
+ .child(Ipv4.class)
+ .child(Address.class, new AddressKey(new Ipv4AddressNoZone("192.168.2.1")));
+ ifaceTwoAddressOneIdentifier = InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class, new InterfaceKey(IF_NAME))
+ .augmentation(SubinterfaceStateAugmentation.class)
+ .child(SubInterfaces.class)
+ .child(SubInterface.class, new SubInterfaceKey(2L))
+ .child(Ipv4.class)
+ .child(Address.class, new AddressKey(new Ipv4AddressNoZone("192.168.2.1")));
+
+ // to simulate complex key
+ cacheKeyFactory = new IdentifierCacheKeyFactory(ImmutableSet.of(SubInterface.class));
+
+ defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
+ defineMapping(mappingContext, SUB_IF_NAME, SUB_IF_INDEX, IFC_CTX_NAME);
+ defineMapping(mappingContext, SUB_IF_2_NAME, SUB_IF_2_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);
+ }
+
+ @Test
+ public void testCacheScope() {
+
+ }
+
+ @Test
+ public void testCachingScopeSpecificRequest() throws ReadFailedException {
+ fillCacheForTwoIfaces();
+ final AddressBuilder ifaceOneAddressBuilder = new AddressBuilder();
+ final AddressBuilder ifaceTwoAddressBuilder = new AddressBuilder();
+
+ getCustomizer().readCurrentAttributes(ifaceOneAddressOneIdentifier, ifaceOneAddressBuilder, ctx);
+ getCustomizer().readCurrentAttributes(ifaceTwoAddressOneIdentifier, ifaceTwoAddressBuilder, ctx);
+
+ // addresses have caching scope of parent interface, so returned address should have respective prefix lengths
+ assertEquals("192.168.2.1", ifaceOneAddressBuilder.getIp().getValue());
+ assertTrue(ifaceOneAddressBuilder.getSubnet() instanceof PrefixLength);
+ assertEquals(22, PrefixLength.class.cast(ifaceOneAddressBuilder.getSubnet()).getPrefixLength().intValue());
+
+ assertEquals("192.168.2.1", ifaceTwoAddressBuilder.getIp().getValue());
+ assertTrue(ifaceTwoAddressBuilder.getSubnet() instanceof PrefixLength);
+ assertEquals(23, PrefixLength.class.cast(ifaceTwoAddressBuilder.getSubnet()).getPrefixLength().intValue());
+ }
+
+ @Test
+ public void testCachingScopeGetAll() throws ReadFailedException {
+ fillCacheForFirstIfaceSecondEmpty();
+
+ final List<AddressKey> keysForIfaceOne = getCustomizer().getAllIds(ifaceOneAddressOneIdentifier, ctx);
+ Assert.assertThat(keysForIfaceOne, hasSize(1));
+ final AddressKey keyIfaceOne = keysForIfaceOne.get(0);
+ assertEquals("192.168.2.1", keyIfaceOne.getIp().getValue());
+
+ final List<AddressKey> keysForIfaceTwo = getCustomizer().getAllIds(ifaceTwoAddressOneIdentifier, ctx);
+ Assert.assertThat(keysForIfaceTwo, is(empty()));
+ }
+
+ private void fillCacheForTwoIfaces() {
+ IpAddressDetails detailIfaceOneAddressOne = new IpAddressDetails();
+ IpAddressDetails detailIfaceTwoAddressOne = new IpAddressDetails();
+ IpAddressDetailsReplyDump replyIfaceOne = new IpAddressDetailsReplyDump();
+ IpAddressDetailsReplyDump replyIfaceTwo = new IpAddressDetailsReplyDump();
+
+ replyIfaceOne.ipAddressDetails = Arrays.asList(detailIfaceOneAddressOne);
+ replyIfaceTwo.ipAddressDetails = Arrays.asList(detailIfaceTwoAddressOne);
+
+ detailIfaceOneAddressOne.ip = reverseBytes(
+ ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
+ detailIfaceOneAddressOne.prefixLength = 22;
+
+ detailIfaceTwoAddressOne.ip = reverseBytes(
+ ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
+ detailIfaceTwoAddressOne.prefixLength = 23;
+
+ cache.put(cacheKeyFactory.createKey(ifaceOneAddressOneIdentifier), replyIfaceOne);
+ cache.put(cacheKeyFactory.createKey(ifaceTwoAddressOneIdentifier), replyIfaceTwo);
+ }
+
+ private void fillCacheForFirstIfaceSecondEmpty() {
+ IpAddressDetails detailIfaceOneAddressOne = new IpAddressDetails();
+ IpAddressDetailsReplyDump replyIfaceOne = new IpAddressDetailsReplyDump();
+ replyIfaceOne.ipAddressDetails = Arrays.asList(detailIfaceOneAddressOne);
+
+ detailIfaceOneAddressOne.ip = reverseBytes(
+ ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
+ detailIfaceOneAddressOne.prefixLength = 22;
+
+ cache.put(cacheKeyFactory.createKey(ifaceOneAddressOneIdentifier), replyIfaceOne);
+ cache.put(cacheKeyFactory.createKey(ifaceTwoAddressOneIdentifier), new IpAddressDetailsReplyDump());
+ }
+
+ 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
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/pbb/PbbRewriteStateCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/pbb/PbbRewriteStateCustomizerTest.java
new file mode 100644
index 000000000..2fd959add
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/pbb/PbbRewriteStateCustomizerTest.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.v3po.interfacesstate.pbb;
+
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.pbb.rev161214.PbbRewriteStateInterfaceAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.pbb.rev161214.interfaces.state._interface.PbbRewriteState;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.pbb.rev161214.interfaces.state._interface.PbbRewriteStateBuilder;
+
+public class PbbRewriteStateCustomizerTest extends ReaderCustomizerTest<PbbRewriteState, PbbRewriteStateBuilder> {
+
+ public PbbRewriteStateCustomizerTest() {
+ super(PbbRewriteState.class, PbbRewriteStateInterfaceAugmentationBuilder.class);
+ }
+
+ @Override
+ protected ReaderCustomizer<PbbRewriteState, PbbRewriteStateBuilder> initCustomizer() {
+ return new PbbRewriteStateCustomizer(api);
+ }
+}