summaryrefslogtreecommitdiffstats
path: root/l3/impl/src/test/java/io/fd/hc2vpp/l3/read
diff options
context:
space:
mode:
Diffstat (limited to 'l3/impl/src/test/java/io/fd/hc2vpp/l3/read')
-rw-r--r--l3/impl/src/test/java/io/fd/hc2vpp/l3/read/InterfaceChildNodeTest.java200
-rw-r--r--l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4AddressCustomizerTest.java272
-rw-r--r--l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4CustomizerTest.java44
-rw-r--r--l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4NeighbourCustomizerTest.java77
-rw-r--r--l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/SubInterfaceIpv4AddressCustomizerTest.java240
-rw-r--r--l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/SubInterfaceIpv4NeighbourCustomizerTest.java85
-rw-r--r--l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6AddressCustomizerTest.java78
-rw-r--r--l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6NeighbourCustomizerTest.java80
-rw-r--r--l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/SubInterfaceIpv6AddressCustomizerTest.java75
-rw-r--r--l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/SubInterfaceIpv6NeighbourCustomizerTest.java86
-rw-r--r--l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/nd/NdProxyCustomizerTest.java129
11 files changed, 1366 insertions, 0 deletions
diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/InterfaceChildNodeTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/InterfaceChildNodeTest.java
new file mode 100644
index 000000000..48a1b7327
--- /dev/null
+++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/InterfaceChildNodeTest.java
@@ -0,0 +1,200 @@
+/*
+ * Copyright (c) 2017 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.l3.read;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.common.test.util.FutureProducer;
+import io.fd.hc2vpp.common.test.util.NamingContextHelper;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.vpp.jvpp.core.dto.IpAddressDetails;
+import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump;
+import io.fd.vpp.jvpp.core.dto.IpAddressDump;
+import io.fd.vpp.jvpp.core.dto.IpNeighborDetails;
+import io.fd.vpp.jvpp.core.dto.IpNeighborDetailsReplyDump;
+import io.fd.vpp.jvpp.core.dto.IpNeighborDump;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import java.util.Arrays;
+import java.util.List;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
+
+public interface InterfaceChildNodeTest extends NamingContextHelper, FutureProducer {
+
+ String INTERFACE_CONTEXT_NAME = "iface-context";
+ NamingContext INTERFACE_CONTEXT = new NamingContext("prefix", INTERFACE_CONTEXT_NAME);
+
+ String IFACE_NAME = "eth0";
+ int IFACE_ID = 1;
+
+ String SUB_IFACE_NAME = "eth0.4";
+ int SUB_IFACE_ID = 4;
+
+ String IFACE_2_NAME = "eth1";
+ int IFACE_2_ID = 2;
+
+ String SUB_IFACE_2_NAME = "eth1.7";
+ int SUB_IFACE_2_ID = 7;
+
+ String IPV6_ONE_COMPRESSED = "2001:db8:a0b:12f0::1";
+ byte[] IPV6_ONE_BYTES = {32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1};
+ byte IPV6_ONE_PREFIX = 64;
+ Ipv6AddressNoZone IPV6_ONE_ADDRESS_COMPRESSED = new Ipv6AddressNoZone(IPV6_ONE_COMPRESSED);
+
+ String IPV6_TWO_COMPRESSED = "2001:db8:a0b:12f0::2";
+ byte[] IPV6_TWO_BYTES = {32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 2};
+ byte IPV6_TWO_PREFIX = 48;
+ Ipv6AddressNoZone IPV6_TWO_ADDRESS_COMPRESSED = new Ipv6AddressNoZone(IPV6_TWO_COMPRESSED);
+
+ String IPV4_ONE = "192.168.2.1";
+ byte[] IPV4_ONE_BYTES = {-64, -88, 2, 1};
+ byte IPV4_ONE_PREFIX = 24;
+ Ipv4AddressNoZone IPV4_ONE_ADDRESS = new Ipv4AddressNoZone(IPV4_ONE);
+
+ String IPV4_TWO = "192.168.2.2";
+ byte[] IPV4_TWO_BYTES = {-64, -88, 2, 2};
+ byte IPV4_TWO_PREFIX = 24;
+ Ipv4AddressNoZone IPV4_TWO_ADDRESS = new Ipv4AddressNoZone(IPV4_TWO);
+
+ String MAC_ONE = "00:00:00:00:00:00";
+ byte[] MAC_ONE_BYTES = {0, 0, 0, 0, 0, 0};
+ PhysAddress MAC_ONE_ADDRESS = new PhysAddress(MAC_ONE);
+
+ String MAC_TWO = "00:00:00:00:00:01";
+ byte[] MAC_TWO_BYTES = {0, 0, 0, 0, 0, 1};
+ PhysAddress MAC_TWO_ADDRESS = new PhysAddress(MAC_TWO);
+
+ String MAC_THREE = "00:00:00:00:00:02";
+ byte[] MAC_THREE_BYTES = {0, 0, 0, 0, 0, 2};
+ PhysAddress MAC_THREE_ADDRESS = new PhysAddress(MAC_THREE);
+
+ String MAC_FOUR = "00:00:00:00:00:03";
+ byte[] MAC_FOUR_BYTES = {0, 0, 0, 0, 0, 3};
+ PhysAddress MAC_FOUR_ADDRESS = new PhysAddress(MAC_FOUR);
+
+ default void mockNeighborDump(@Nonnull final FutureJVppCore api,
+ @Nonnull final IpNeighborDump request,
+ @Nonnull final IpNeighborDetailsReplyDump reply) {
+ when(api.ipNeighborDump(request)).thenReturn(future(reply));
+ }
+
+ default void mockAddressDump(@Nonnull final FutureJVppCore api,
+ @Nonnull final IpAddressDump request,
+ @Nonnull final IpAddressDetailsReplyDump reply) {
+ when(api.ipAddressDump(request)).thenReturn(future(reply));
+ }
+
+ default IpAddressDump dumpV6AddressesIfaceTwo() {
+ IpAddressDump request = new IpAddressDump();
+ request.isIpv6 = 1;
+ request.swIfIndex = IFACE_2_ID;
+ return request;
+ }
+
+ default IpAddressDump dumpV6AddressesSubIfaceOne() {
+ IpAddressDump request = new IpAddressDump();
+ request.swIfIndex = SUB_IFACE_ID;
+ request.isIpv6 = 1;
+ return request;
+ }
+
+
+ default IpNeighborDump dumpV4NeighborIfaceOne() {
+ IpNeighborDump request = new IpNeighborDump();
+ request.swIfIndex = IFACE_ID;
+ request.isIpv6 = 0;
+ return request;
+ }
+
+ default IpNeighborDump dumpV6NeighborsIfaceOne() {
+ IpNeighborDump request = new IpNeighborDump();
+ request.swIfIndex = IFACE_ID;
+ request.isIpv6 = 1;
+ return request;
+ }
+
+ default IpNeighborDump dumpV6NeighborsSubIfaceTwo() {
+ IpNeighborDump request = new IpNeighborDump();
+ request.swIfIndex = SUB_IFACE_2_ID;
+ request.isIpv6 = 1;
+ return request;
+ }
+
+ default IpNeighborDump dumpV4NeighborsSubIfaceOne() {
+ IpNeighborDump request = new IpNeighborDump();
+ request.swIfIndex = SUB_IFACE_ID;
+ request.isIpv6 = 0;
+ return request;
+ }
+
+ default void verifyList(@Nonnull final List<?> expected, @Nonnull final List<?> current) {
+ assertThat(current, hasSize(expected.size()));
+ assertTrue(expected.containsAll(current));
+ }
+
+ default IpNeighborDetailsReplyDump v4Neighbors() {
+ IpNeighborDetailsReplyDump fullDump = new IpNeighborDetailsReplyDump();
+ fullDump.ipNeighborDetails = Arrays.asList(
+ neighborDump(IPV4_ONE_BYTES, 0, MAC_ONE_BYTES),
+ neighborDump(IPV4_TWO_BYTES, 0, MAC_TWO_BYTES));
+ return fullDump;
+ }
+
+ default IpNeighborDetailsReplyDump v6Neighbors() {
+ IpNeighborDetailsReplyDump fullDump = new IpNeighborDetailsReplyDump();
+ fullDump.ipNeighborDetails = Arrays.asList(
+ neighborDump(IPV6_ONE_BYTES, 1, MAC_THREE_BYTES),
+ neighborDump(IPV6_TWO_BYTES, 1, MAC_FOUR_BYTES));
+ return fullDump;
+ }
+
+ default IpAddressDetailsReplyDump v4Addresses() {
+ IpAddressDetailsReplyDump fullDump = new IpAddressDetailsReplyDump();
+ fullDump.ipAddressDetails = Arrays.asList(
+ addressDump(IPV4_ONE_BYTES, IPV4_ONE_PREFIX),
+ addressDump(IPV4_TWO_BYTES, IPV4_TWO_PREFIX));
+ return fullDump;
+ }
+
+ default IpAddressDetailsReplyDump v6Addresses() {
+ IpAddressDetailsReplyDump fullDump = new IpAddressDetailsReplyDump();
+ fullDump.ipAddressDetails = Arrays.asList(
+ addressDump(IPV6_ONE_BYTES, IPV6_ONE_PREFIX),
+ addressDump(IPV6_TWO_BYTES, IPV6_TWO_PREFIX));
+ return fullDump;
+ }
+
+ static IpNeighborDetails neighborDump(byte[] address, int isIpv6, byte[] mac) {
+ IpNeighborDetails detail = new IpNeighborDetails();
+ detail.ipAddress = address;
+ detail.isIpv6 = (byte) isIpv6;
+ detail.macAddress = mac;
+ return detail;
+ }
+
+ static IpAddressDetails addressDump(byte[] address, byte prefix) {
+ IpAddressDetails details = new IpAddressDetails();
+ details.ip = address;
+ details.prefixLength = prefix;
+ return details;
+ }
+}
diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4AddressCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4AddressCustomizerTest.java
new file mode 100644
index 000000000..d7bd6325b
--- /dev/null
+++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4AddressCustomizerTest.java
@@ -0,0 +1,272 @@
+/*
+ * Copyright (c) 2017 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.l3.read.ipv4;
+
+
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.hasItem;
+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.hc2vpp.common.test.read.ListReaderCustomizerTest;
+import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.l3.read.InterfaceChildNodeTest;
+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.TypeAwareIdentifierCacheKeyFactory;
+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.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,InterfaceChildNodeTest {
+
+
+ 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);
+ }
+
+ 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();
+ }
+
+ @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 TypeAwareIdentifierCacheKeyFactory(IpAddressDetailsReplyDump.class,
+ ImmutableSet.of(Interface.class));
+ }
+
+ @Override
+ protected ReaderCustomizer<Address, AddressBuilder> initCustomizer() {
+ return new Ipv4AddressCustomizer(api, interfacesContext);
+ }
+
+ @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 = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")));
+ detail2.ip = 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, hasItem(new AddressKey(new Ipv4AddressNoZone("192.168.2.1"))));
+ final List<AddressKey> ifc2Ids = getCustomizer().getAllIds(id2, ctx);
+ assertThat(ifc2Ids.size(), is(1));
+ assertThat(ifc2Ids, 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 = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")));
+ detail2.ip = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2")));
+ detail3.ip = 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 = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")));
+ detail2.ip = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2")));
+ detail3.ip = 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 = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")));
+ detailIfaceOneAddressOne.prefixLength = 22;
+
+ detailIfaceTwoAddressOne.ip = 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 = 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/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4CustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4CustomizerTest.java
new file mode 100644
index 000000000..b6bb81b77
--- /dev/null
+++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4CustomizerTest.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2017 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.l3.read.ipv4;
+
+import static org.mockito.Mockito.verifyZeroInteractions;
+
+import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+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/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4NeighbourCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4NeighbourCustomizerTest.java
new file mode 100644
index 000000000..ceea51f71
--- /dev/null
+++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4NeighbourCustomizerTest.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2017 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.l3.read.ipv4;
+
+import static org.junit.Assert.assertEquals;
+
+import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest;
+import io.fd.hc2vpp.l3.read.InterfaceChildNodeTest;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import java.util.Arrays;
+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.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.Neighbor;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.NeighborBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.NeighborKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class Ipv4NeighbourCustomizerTest extends ListReaderCustomizerTest<Neighbor, NeighborKey, NeighborBuilder>
+ implements InterfaceChildNodeTest {
+
+ private InstanceIdentifier<Neighbor> instanceIdentifier;
+
+ public Ipv4NeighbourCustomizerTest() {
+ super(Neighbor.class, Ipv4Builder.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ instanceIdentifier = InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class, new InterfaceKey(IFACE_NAME))
+ .augmentation(Interface2.class)
+ .child(Ipv4.class)
+ .child(Neighbor.class, new NeighborKey(IPV4_ONE_ADDRESS));
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, INTERFACE_CONTEXT_NAME);
+ mockNeighborDump(api, dumpV4NeighborIfaceOne(), v4Neighbors());
+ }
+
+ @Test
+ public void testGetAll() throws ReadFailedException {
+ verifyList(Arrays.asList(new NeighborKey(IPV4_ONE_ADDRESS), new NeighborKey(IPV4_TWO_ADDRESS)),
+ getCustomizer().getAllIds(instanceIdentifier, ctx));
+ }
+
+ @Test
+ public void readCurrent() throws ReadFailedException {
+ final NeighborBuilder builder = new NeighborBuilder();
+ getCustomizer().readCurrentAttributes(instanceIdentifier, builder, ctx);
+
+ assertEquals(IPV4_ONE_ADDRESS, builder.getIp());
+ assertEquals(MAC_ONE_ADDRESS, builder.getLinkLayerAddress());
+ }
+
+ @Override
+ protected ReaderCustomizer<Neighbor, NeighborBuilder> initCustomizer() {
+ return new Ipv4NeighbourCustomizer(api, INTERFACE_CONTEXT);
+ }
+} \ No newline at end of file
diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/SubInterfaceIpv4AddressCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/SubInterfaceIpv4AddressCustomizerTest.java
new file mode 100644
index 000000000..efe6071e6
--- /dev/null
+++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/SubInterfaceIpv4AddressCustomizerTest.java
@@ -0,0 +1,240 @@
+/*
+ * Copyright (c) 2017 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.l3.read.ipv4;
+
+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.hc2vpp.common.test.read.ListReaderCustomizerTest;
+import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.l3.read.ipv4.subinterface.SubInterfaceIpv4AddressCustomizer;
+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.TypeAwareIdentifierCacheKeyFactory;
+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 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 InstanceIdentifier<Address> ifaceOneAddressOneIdentifier;
+ private InstanceIdentifier<Address> ifaceTwoAddressOneIdentifier;
+ private CacheKeyFactory cacheKeyFactory;
+ private NamingContext interfaceContext;
+
+ public SubInterfaceIpv4AddressCustomizerTest() {
+ super(Address.class, Ipv4Builder.class);
+ }
+
+ 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));
+ }
+
+ @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 TypeAwareIdentifierCacheKeyFactory(IpAddressDetailsReplyDump.class,
+ 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);
+ }
+
+ @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 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 = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")));
+ detailIfaceOneAddressOne.prefixLength = 22;
+
+ detailIfaceTwoAddressOne.ip = 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 = 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[]{10, 1, 1, 1};
+ details1.prefixLength = (byte) PREFIX_LENGTH;
+ reply.ipAddressDetails.add(details1);
+
+ final IpAddressDetails details2 = new IpAddressDetails();
+ details2.ip = new byte[]{10, 1, 1, 2};
+ details2.prefixLength = (byte) PREFIX_LENGTH;
+ reply.ipAddressDetails.add(details2);
+
+ return reply;
+ }
+} \ No newline at end of file
diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/SubInterfaceIpv4NeighbourCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/SubInterfaceIpv4NeighbourCustomizerTest.java
new file mode 100644
index 000000000..f865f98cb
--- /dev/null
+++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/SubInterfaceIpv4NeighbourCustomizerTest.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2017 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.l3.read.ipv4;
+
+import static org.junit.Assert.assertEquals;
+
+import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest;
+import io.fd.hc2vpp.l3.read.InterfaceChildNodeTest;
+import io.fd.hc2vpp.l3.read.ipv4.subinterface.SubInterfaceIpv4NeighbourCustomizer;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import java.util.Arrays;
+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.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.Neighbor;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.NeighborBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.NeighborKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class SubInterfaceIpv4NeighbourCustomizerTest extends ListReaderCustomizerTest<Neighbor, NeighborKey, NeighborBuilder>
+ implements InterfaceChildNodeTest {
+
+ private InstanceIdentifier<Neighbor> instanceIdentifier;
+
+ public SubInterfaceIpv4NeighbourCustomizerTest() {
+ super(Neighbor.class, Ipv4Builder.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ instanceIdentifier = InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class, new InterfaceKey(IFACE_NAME))
+ .augmentation(SubinterfaceStateAugmentation.class)
+ .child(SubInterfaces.class)
+ .child(SubInterface.class, new SubInterfaceKey((long) SUB_IFACE_ID))
+ .child(Ipv4.class)
+ .child(Neighbor.class, new NeighborKey(IPV4_TWO_ADDRESS));
+
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, INTERFACE_CONTEXT_NAME);
+ defineMapping(mappingContext, SUB_IFACE_NAME, SUB_IFACE_ID, INTERFACE_CONTEXT_NAME);
+ mockNeighborDump(api, dumpV4NeighborsSubIfaceOne(), v4Neighbors());
+ }
+
+ @Test
+ public void testGetAll() throws ReadFailedException {
+ verifyList(Arrays.asList(new NeighborKey(IPV4_ONE_ADDRESS), new NeighborKey(IPV4_TWO_ADDRESS)),
+ getCustomizer().getAllIds(instanceIdentifier, ctx));
+ }
+
+ @Test
+ public void testReadCurrent() throws ReadFailedException {
+ final NeighborBuilder neighborBuilder = new NeighborBuilder();
+ getCustomizer().readCurrentAttributes(instanceIdentifier, neighborBuilder, ctx);
+
+ assertEquals(MAC_TWO_ADDRESS, neighborBuilder.getLinkLayerAddress());
+ assertEquals(IPV4_TWO_ADDRESS, neighborBuilder.getIp());
+ }
+
+ @Override
+ protected ReaderCustomizer<Neighbor, NeighborBuilder> initCustomizer() {
+ return new SubInterfaceIpv4NeighbourCustomizer(api, INTERFACE_CONTEXT);
+ }
+} \ No newline at end of file
diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6AddressCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6AddressCustomizerTest.java
new file mode 100644
index 000000000..edde1db1c
--- /dev/null
+++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6AddressCustomizerTest.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2017 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.l3.read.ipv6;
+
+import static org.junit.Assert.assertEquals;
+
+import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest;
+import io.fd.hc2vpp.l3.read.InterfaceChildNodeTest;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import java.util.Arrays;
+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.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.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.AddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.AddressKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class Ipv6AddressCustomizerTest extends ListReaderCustomizerTest<Address, AddressKey, AddressBuilder>
+ implements InterfaceChildNodeTest {
+
+ private InstanceIdentifier<Address> instanceIdentifier;
+
+ public Ipv6AddressCustomizerTest() {
+ super(Address.class, Ipv6Builder.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ instanceIdentifier = InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class, new InterfaceKey(IFACE_2_NAME))
+ .augmentation(Interface2.class)
+ .child(Ipv6.class)
+ .child(Address.class, new AddressKey(IPV6_TWO_ADDRESS_COMPRESSED));
+ defineMapping(mappingContext, IFACE_2_NAME, IFACE_2_ID, INTERFACE_CONTEXT_NAME);
+ mockAddressDump(api, dumpV6AddressesIfaceTwo(), v6Addresses());
+ }
+
+ @Override
+ protected ReaderCustomizer<Address, AddressBuilder> initCustomizer() {
+ return new Ipv6AddressCustomizer(api, INTERFACE_CONTEXT);
+ }
+
+ @Test
+ public void testGetAll() throws ReadFailedException {
+ verifyList(Arrays.asList(
+ new AddressKey(IPV6_ONE_ADDRESS_COMPRESSED), new AddressKey(IPV6_TWO_ADDRESS_COMPRESSED)),
+ getCustomizer().getAllIds(instanceIdentifier, ctx));
+ }
+
+ @Test
+ public void testReadCurrent() throws ReadFailedException {
+ AddressBuilder builder = new AddressBuilder();
+ getCustomizer().readCurrentAttributes(instanceIdentifier, builder, ctx);
+
+ assertEquals(IPV6_TWO_ADDRESS_COMPRESSED, builder.getIp());
+ assertEquals(IPV6_TWO_PREFIX, builder.getPrefixLength().longValue());
+ }
+} \ No newline at end of file
diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6NeighbourCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6NeighbourCustomizerTest.java
new file mode 100644
index 000000000..0551977e5
--- /dev/null
+++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6NeighbourCustomizerTest.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2017 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.l3.read.ipv6;
+
+import static org.junit.Assert.assertEquals;
+
+import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest;
+import io.fd.hc2vpp.l3.read.InterfaceChildNodeTest;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import java.util.Arrays;
+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.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.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.Neighbor;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.NeighborBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.NeighborKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+
+public class Ipv6NeighbourCustomizerTest extends ListReaderCustomizerTest<Neighbor, NeighborKey, NeighborBuilder>
+ implements InterfaceChildNodeTest {
+
+ private InstanceIdentifier<Neighbor> instanceIdentifier;
+
+ public Ipv6NeighbourCustomizerTest() {
+ super(Neighbor.class, Ipv6Builder.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ instanceIdentifier = InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class, new InterfaceKey(IFACE_NAME))
+ .augmentation(Interface2.class)
+ .child(Ipv6.class)
+ .child(Neighbor.class, new NeighborKey(IPV6_ONE_ADDRESS_COMPRESSED));
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, INTERFACE_CONTEXT_NAME);
+ mockNeighborDump(api, dumpV6NeighborsIfaceOne(), v6Neighbors());
+ }
+
+ @Test
+ public void testGetAll() throws ReadFailedException {
+ verifyList(Arrays.asList(
+ new NeighborKey(IPV6_ONE_ADDRESS_COMPRESSED),
+ new NeighborKey(IPV6_TWO_ADDRESS_COMPRESSED)),
+ getCustomizer().getAllIds(instanceIdentifier, ctx));
+ }
+
+ @Test
+ public void readCurrent() throws ReadFailedException {
+ final NeighborBuilder builder = new NeighborBuilder();
+ getCustomizer().readCurrentAttributes(instanceIdentifier, builder, ctx);
+
+ assertEquals(IPV6_ONE_ADDRESS_COMPRESSED, builder.getIp());
+ assertEquals(MAC_THREE_ADDRESS, builder.getLinkLayerAddress());
+ }
+
+ @Override
+ protected ReaderCustomizer<Neighbor, NeighborBuilder> initCustomizer() {
+ return new Ipv6NeighbourCustomizer(api, INTERFACE_CONTEXT);
+ }
+} \ No newline at end of file
diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/SubInterfaceIpv6AddressCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/SubInterfaceIpv6AddressCustomizerTest.java
new file mode 100644
index 000000000..ee342234e
--- /dev/null
+++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/SubInterfaceIpv6AddressCustomizerTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2017 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.l3.read.ipv6;
+
+import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest;
+import io.fd.hc2vpp.l3.read.InterfaceChildNodeTest;
+import io.fd.hc2vpp.l3.read.ipv6.subinterface.SubInterfaceIpv6AddressCustomizer;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import java.util.Arrays;
+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.SubInterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.Ipv6Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.AddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.AddressKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class SubInterfaceIpv6AddressCustomizerTest extends ListReaderCustomizerTest<Address, AddressKey, AddressBuilder>
+ implements InterfaceChildNodeTest {
+
+ private InstanceIdentifier<Address> instanceIdentifier;
+
+ public SubInterfaceIpv6AddressCustomizerTest() {
+ super(Address.class, Ipv6Builder.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ instanceIdentifier = InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class, new InterfaceKey(IFACE_NAME))
+ .augmentation(SubinterfaceStateAugmentation.class)
+ .child(SubInterfaces.class)
+ .child(SubInterface.class, new SubInterfaceKey((long) SUB_IFACE_ID))
+ .child(Ipv6.class)
+ .child(Address.class, new AddressKey(IPV6_TWO_ADDRESS_COMPRESSED));
+
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, INTERFACE_CONTEXT_NAME);
+ defineMapping(mappingContext, SUB_IFACE_NAME, SUB_IFACE_ID, INTERFACE_CONTEXT_NAME);
+ mockAddressDump(api, dumpV6AddressesSubIfaceOne(), v6Addresses());
+ }
+
+ @Test
+ public void testGetAll() throws ReadFailedException {
+ verifyList(Arrays.asList(
+ new AddressKey(IPV6_ONE_ADDRESS_COMPRESSED), new AddressKey(IPV6_TWO_ADDRESS_COMPRESSED)),
+ getCustomizer().getAllIds(instanceIdentifier, ctx));
+ }
+
+ @Override
+ protected ReaderCustomizer<Address, AddressBuilder> initCustomizer() {
+ return new SubInterfaceIpv6AddressCustomizer(api, INTERFACE_CONTEXT);
+ }
+} \ No newline at end of file
diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/SubInterfaceIpv6NeighbourCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/SubInterfaceIpv6NeighbourCustomizerTest.java
new file mode 100644
index 000000000..e9400921e
--- /dev/null
+++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/SubInterfaceIpv6NeighbourCustomizerTest.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2017 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.l3.read.ipv6;
+
+import static org.junit.Assert.assertEquals;
+
+import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest;
+import io.fd.hc2vpp.l3.read.InterfaceChildNodeTest;
+import io.fd.hc2vpp.l3.read.ipv6.subinterface.SubInterfaceIpv6NeighbourCustomizer;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import java.util.Arrays;
+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.SubInterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.Ipv6Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.Neighbor;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.NeighborBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.NeighborKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class SubInterfaceIpv6NeighbourCustomizerTest extends ListReaderCustomizerTest<Neighbor, NeighborKey, NeighborBuilder>
+ implements InterfaceChildNodeTest {
+
+ private InstanceIdentifier<Neighbor> instanceIdentifier;
+
+ public SubInterfaceIpv6NeighbourCustomizerTest() {
+ super(Neighbor.class, Ipv6Builder.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ instanceIdentifier = InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class, new InterfaceKey(IFACE_2_NAME))
+ .augmentation(SubinterfaceStateAugmentation.class)
+ .child(SubInterfaces.class)
+ .child(SubInterface.class, new SubInterfaceKey((long) SUB_IFACE_2_ID))
+ .child(Ipv6.class)
+ .child(Neighbor.class, new NeighborKey(IPV6_TWO_ADDRESS_COMPRESSED));
+ defineMapping(mappingContext, IFACE_2_NAME, IFACE_2_ID, INTERFACE_CONTEXT_NAME);
+ defineMapping(mappingContext, SUB_IFACE_2_NAME, SUB_IFACE_2_ID, INTERFACE_CONTEXT_NAME);
+ mockNeighborDump(api, dumpV6NeighborsSubIfaceTwo(), v6Neighbors());
+ }
+
+ @Test
+ public void testGetAll() throws ReadFailedException {
+ verifyList(Arrays.asList(
+ new NeighborKey(IPV6_ONE_ADDRESS_COMPRESSED),
+ new NeighborKey(IPV6_TWO_ADDRESS_COMPRESSED)),
+ getCustomizer().getAllIds(instanceIdentifier, ctx));
+ }
+
+ @Test
+ public void readCurrent() throws ReadFailedException {
+ NeighborBuilder builder = new NeighborBuilder();
+ getCustomizer().readCurrentAttributes(instanceIdentifier, builder, ctx);
+
+ assertEquals(IPV6_TWO_ADDRESS_COMPRESSED, builder.getIp());
+ assertEquals(MAC_FOUR_ADDRESS, builder.getLinkLayerAddress());
+ }
+
+ @Override
+ protected ReaderCustomizer<Neighbor, NeighborBuilder> initCustomizer() {
+ return new SubInterfaceIpv6NeighbourCustomizer(api, INTERFACE_CONTEXT);
+ }
+} \ No newline at end of file
diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/nd/NdProxyCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/nd/NdProxyCustomizerTest.java
new file mode 100644
index 000000000..fe2fd4754
--- /dev/null
+++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/nd/NdProxyCustomizerTest.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2017 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.l3.read.ipv6.nd;
+
+import static io.fd.hc2vpp.l3.read.ipv6.nd.NdProxyCustomizer.getCfgId;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.common.test.read.InitializingListReaderCustomizerTest;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.vpp.jvpp.core.dto.Ip6NdProxyDetails;
+import io.fd.vpp.jvpp.core.dto.Ip6NdProxyDetailsReplyDump;
+import java.util.List;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.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.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.NdProxyIp6StateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces.state._interface.ipv6.NdProxies;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces.state._interface.ipv6.NdProxiesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces.state._interface.ipv6.nd.proxies.NdProxy;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces.state._interface.ipv6.nd.proxies.NdProxyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces.state._interface.ipv6.nd.proxies.NdProxyKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class NdProxyCustomizerTest extends InitializingListReaderCustomizerTest<NdProxy, NdProxyKey, NdProxyBuilder> {
+ private static final String IF1_NAME = "eth1";
+ private static final int IF1_INDEX = 1;
+ private static final String IF2_NAME = "eth2";
+ private static final int IF2_INDEX = 2;
+ private static final String IFACE_CTX_NAME = "ifc-test-instance";
+
+ public NdProxyCustomizerTest() {
+ super(NdProxy.class, NdProxiesBuilder.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ defineMapping(mappingContext, IF1_NAME, IF1_INDEX, IFACE_CTX_NAME);
+ defineMapping(mappingContext, IF2_NAME, IF2_INDEX, IFACE_CTX_NAME);
+ final Ip6NdProxyDetailsReplyDump reply = new Ip6NdProxyDetailsReplyDump();
+ final Ip6NdProxyDetails proxy1 = new Ip6NdProxyDetails();
+ proxy1.swIfIndex = IF1_INDEX;
+ proxy1.address = new byte[] {0x20, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01};
+ final Ip6NdProxyDetails proxy2 = new Ip6NdProxyDetails();
+ proxy2.swIfIndex = IF1_INDEX;
+ proxy2.address = new byte[] {0x20, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x02};
+ final Ip6NdProxyDetails proxy3 = new Ip6NdProxyDetails();
+ proxy3.swIfIndex = IF2_INDEX;
+ proxy3.address = new byte[] {0x20, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x03};
+ reply.ip6NdProxyDetails.add(proxy1);
+ reply.ip6NdProxyDetails.add(proxy2);
+ reply.ip6NdProxyDetails.add(proxy3);
+ when(api.ip6NdProxyDump(any())).thenReturn(future(reply));
+ }
+
+ @Override
+ protected ReaderCustomizer<NdProxy, NdProxyBuilder> initCustomizer() {
+ return new NdProxyCustomizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME));
+ }
+
+ @Test
+ public void readCurrent() throws ReadFailedException {
+ final NdProxyBuilder builder = new NdProxyBuilder();
+ final Ipv6AddressNoZone address = new Ipv6AddressNoZone("2001::1");
+ getCustomizer().readCurrentAttributes(getId(IF1_NAME, address), builder, ctx);
+ assertEquals(builder.getAddress(), address);
+ }
+
+ @Test
+ public void testGetAllInterface1() throws ReadFailedException {
+ final List<NdProxyKey> allIds = getCustomizer().getAllIds(getProxiesId(IF1_NAME).child(NdProxy.class), ctx);
+ assertThat(allIds, containsInAnyOrder(
+ new NdProxyKey(new Ipv6AddressNoZone("2001::1")),
+ new NdProxyKey(new Ipv6AddressNoZone("2001::2"))
+ ));
+ }
+
+ @Test
+ public void testGetAllInterface2() throws ReadFailedException {
+ final List<NdProxyKey> allIds = getCustomizer().getAllIds(getProxiesId(IF2_NAME).child(NdProxy.class), ctx);
+ assertThat(allIds, containsInAnyOrder(new NdProxyKey(new Ipv6AddressNoZone("2001::3"))));
+ }
+
+ @Test
+ public void testInit() {
+ final Ipv6AddressNoZone address = new Ipv6AddressNoZone("2001::1");
+ final InstanceIdentifier<NdProxy> id = getId(IF1_NAME, address);
+ invokeInitTest(
+ id,
+ new NdProxyBuilder().setAddress(address).build(),
+ getCfgId(id),
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxyBuilder()
+ .setAddress(address).build()
+ );
+ }
+
+ private InstanceIdentifier<NdProxy> getId(final String ifName, final Ipv6AddressNoZone address) {
+ return getProxiesId(ifName).child(NdProxy.class, new NdProxyKey(address));
+ }
+
+ private InstanceIdentifier<NdProxies> getProxiesId(final String ifName) {
+ return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(ifName))
+ .augmentation(Interface2.class).child(Ipv6.class).augmentation(NdProxyIp6StateAugmentation.class)
+ .child(NdProxies.class);
+ }
+} \ No newline at end of file