summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv6StateReaderFactory.java15
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv6WriterFactory.java8
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/nd/NdProxyCustomizer.java94
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/nd/NdProxyCustomizer.java140
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/nd/NdProxyCustomizerTest.java95
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/nd/NdProxyCustomizerTest.java129
6 files changed, 481 insertions, 0 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv6StateReaderFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv6StateReaderFactory.java
index 628cd14f3..b1533dfae 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv6StateReaderFactory.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv6StateReaderFactory.java
@@ -25,6 +25,7 @@ import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.hc2vpp.v3po.interfacesstate.ip.v6.Ipv6AddressCustomizer;
import io.fd.hc2vpp.v3po.interfacesstate.ip.v6.Ipv6Customizer;
import io.fd.hc2vpp.v3po.interfacesstate.ip.v6.Ipv6NeighbourCustomizer;
+import io.fd.hc2vpp.v3po.interfacesstate.ip.v6.nd.NdProxyCustomizer;
import io.fd.honeycomb.translate.impl.read.GenericInitListReader;
import io.fd.honeycomb.translate.impl.read.GenericListReader;
import io.fd.honeycomb.translate.impl.read.GenericReader;
@@ -36,6 +37,11 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev14061
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.ipv6.Address;
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.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.NdProxyIp6StateAugmentationBuilder;
+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.yangtools.yang.binding.InstanceIdentifier;
public class Ipv6StateReaderFactory implements ReaderFactory {
@@ -60,5 +66,14 @@ public class Ipv6StateReaderFactory implements ReaderFactory {
// Ipv6 Neighbor
final InstanceIdentifier<Neighbor> neighborId = ipv6Id.child(Neighbor.class);
registry.add(new GenericListReader<>(neighborId, new Ipv6NeighbourCustomizer(jvpp, ifcNamingCtx)));
+ // NdProxyIp6StateAugmentation (Structural)
+ final InstanceIdentifier<NdProxyIp6StateAugmentation> ndAugId = ipv6Id.augmentation(NdProxyIp6StateAugmentation.class);
+ registry.addStructuralReader(ndAugId, NdProxyIp6StateAugmentationBuilder.class);
+ // NdProxies (Structural)
+ final InstanceIdentifier<NdProxies> ndProxiesId = ndAugId.child(NdProxies.class);
+ registry.addStructuralReader(ndProxiesId, NdProxiesBuilder.class);
+ // ND Proxy
+ final InstanceIdentifier<NdProxy> ndProxyId = ndProxiesId.child(NdProxy.class);
+ registry.addAfter(new GenericInitListReader<>(ndProxyId, new NdProxyCustomizer(jvpp, ifcNamingCtx)), ipv6AddrId);
}
}
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv6WriterFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv6WriterFactory.java
index ce63eb1af..9fbd6b9ba 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv6WriterFactory.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv6WriterFactory.java
@@ -24,6 +24,7 @@ import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.hc2vpp.v3po.interfaces.ip.v6.Ipv6AddressCustomizer;
import io.fd.hc2vpp.v3po.interfaces.ip.v6.Ipv6Customizer;
import io.fd.hc2vpp.v3po.interfaces.ip.v6.Ipv6NeighbourCustomizer;
+import io.fd.hc2vpp.v3po.interfaces.ip.v6.nd.NdProxyCustomizer;
import io.fd.honeycomb.translate.impl.write.GenericListWriter;
import io.fd.honeycomb.translate.impl.write.GenericWriter;
import io.fd.honeycomb.translate.write.WriterFactory;
@@ -34,6 +35,9 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev14061
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.Neighbor;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.NdProxyIp6Augmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.NdProxies;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxy;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
/**
@@ -64,5 +68,9 @@ public class Ipv6WriterFactory implements WriterFactory {
registry.addAfter(new GenericListWriter<>(ipv6Id.child(Neighbor.class),
new Ipv6NeighbourCustomizer(jvpp, ifcNamingContext)), ipv6AddressId);
+ // ND Proxy
+ final InstanceIdentifier<NdProxy> ndProxyId =
+ ipv6Id.augmentation(NdProxyIp6Augmentation.class).child(NdProxies.class).child(NdProxy.class);
+ registry.addAfter(new GenericListWriter<>(ndProxyId, new NdProxyCustomizer(jvpp, ifcNamingContext)), ipv6Id);
}
}
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/nd/NdProxyCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/nd/NdProxyCustomizer.java
new file mode 100644
index 000000000..ed3d82ca9
--- /dev/null
+++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/nd/NdProxyCustomizer.java
@@ -0,0 +1,94 @@
+/*
+ * 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.v3po.interfaces.ip.v6.nd;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import io.fd.hc2vpp.common.translate.util.AddressTranslator;
+import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
+import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer;
+import io.fd.honeycomb.translate.write.WriteContext;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.core.dto.Ip6NdProxyAddDel;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import javax.annotation.Nonnull;
+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.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxy;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxyKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class NdProxyCustomizer extends FutureJVppCustomizer
+ implements ListWriterCustomizer<NdProxy, NdProxyKey>, AddressTranslator, JvppReplyConsumer {
+
+ private static final Logger LOG = LoggerFactory.getLogger(NdProxyCustomizer.class);
+ private final NamingContext interfaceContext;
+
+ public NdProxyCustomizer(@Nonnull final FutureJVppCore futureJVppCore,
+ @Nonnull final NamingContext interfaceContext) {
+ super(futureJVppCore);
+ this.interfaceContext = checkNotNull(interfaceContext, "Interface context cannot be null");
+ }
+
+ @Override
+ public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<NdProxy> id, @Nonnull final NdProxy dataAfter,
+ @Nonnull final WriteContext writeContext) throws WriteFailedException {
+ final String interfaceName = id.firstKeyOf(Interface.class).getName();
+ final int swIfIndex = interfaceContext.getIndex(interfaceName, writeContext.getMappingContext());
+ addDelNdProxy(id, swIfIndex, dataAfter.getAddress(), true);
+ LOG.debug("ND proxy was successfully added for interface {}(id={}): {}", interfaceName, swIfIndex, dataAfter);
+ }
+
+ @Override
+ public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<NdProxy> id,
+ @Nonnull final NdProxy dataBefore, @Nonnull final NdProxy dataAfter,
+ @Nonnull final WriteContext writeContext) throws WriteFailedException {
+ throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter,
+ new UnsupportedOperationException("NdProxy update is not supported."));
+ }
+
+ @Override
+ public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<NdProxy> id,
+ @Nonnull final NdProxy dataBefore,
+ @Nonnull final WriteContext writeContext) throws WriteFailedException {
+ final String interfaceName = id.firstKeyOf(Interface.class).getName();
+ final int swIfIndex = interfaceContext.getIndex(interfaceName, writeContext.getMappingContext());
+ addDelNdProxy(id, swIfIndex, dataBefore.getAddress(), false);
+ LOG.debug("ND proxy was successfully removed from interface {}(id={}): {}", interfaceName, swIfIndex,
+ dataBefore);
+ }
+
+ private void addDelNdProxy(final InstanceIdentifier<NdProxy> id, final int swIfIndex,
+ final Ipv6AddressNoZone address, final boolean add)
+ throws WriteFailedException {
+
+ final byte[] addressBytes = ipv6AddressNoZoneToArray(address);
+
+ final Ip6NdProxyAddDel request = new Ip6NdProxyAddDel();
+ request.swIfIndex = swIfIndex;
+ request.address = addressBytes;
+ request.isDel = booleanToByte(!add);
+
+ getReplyForWrite(getFutureJVpp().ip6NdProxyAddDel(request).toCompletableFuture(), id);
+ }
+
+
+}
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/nd/NdProxyCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/nd/NdProxyCustomizer.java
new file mode 100644
index 000000000..7ffde1dd4
--- /dev/null
+++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/nd/NdProxyCustomizer.java
@@ -0,0 +1,140 @@
+/*
+ * 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.v3po.interfacesstate.ip.v6.nd;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Optional;
+import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
+import io.fd.hc2vpp.common.translate.util.Ipv6Translator;
+import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.v3po.interfacesstate.InterfaceCustomizer;
+import io.fd.honeycomb.translate.read.ReadContext;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.Initialized;
+import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer;
+import io.fd.honeycomb.translate.util.RWUtils;
+import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager;
+import io.fd.vpp.jvpp.core.dto.Ip6NdProxyDetailsReplyDump;
+import io.fd.vpp.jvpp.core.dto.Ip6NdProxyDump;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
+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.interfaces.state.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.NdProxyIp6Augmentation;
+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.concepts.Builder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class NdProxyCustomizer extends FutureJVppCustomizer
+ implements InitializingListReaderCustomizer<NdProxy, NdProxyKey, NdProxyBuilder>, JvppReplyConsumer,
+ Ipv6Translator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(NdProxyCustomizer.class);
+ private final NamingContext interfaceContext;
+ private final DumpCacheManager<Ip6NdProxyDetailsReplyDump, Void> dumpManager;
+
+ public NdProxyCustomizer(@Nonnull final FutureJVppCore futureJVppCore,
+ @Nonnull final NamingContext interfaceContext) {
+ super(futureJVppCore);
+ this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null");
+ dumpManager = new DumpCacheManager.DumpCacheManagerBuilder<Ip6NdProxyDetailsReplyDump, Void>()
+ .withExecutor((id, param) -> getReplyForRead(
+ getFutureJVpp().ip6NdProxyDump(new Ip6NdProxyDump()).toCompletableFuture(), id))
+ .acceptOnly(Ip6NdProxyDetailsReplyDump.class)
+ .build();
+ }
+
+ @Nonnull
+ @Override
+ public List<NdProxyKey> getAllIds(@Nonnull final InstanceIdentifier<NdProxy> id,
+ @Nonnull final ReadContext context) throws ReadFailedException {
+ final String interfaceName = id.firstKeyOf(Interface.class).getName();
+ final int swIfIndex = interfaceContext.getIndex(interfaceName, context.getMappingContext());
+ LOG.debug("Reading NDProxies for interface {}(id={})", interfaceName, swIfIndex);
+ final Optional<Ip6NdProxyDetailsReplyDump> dump =
+ dumpManager.getDump(id, context.getModificationCache(), NO_PARAMS);
+
+ if (!dump.isPresent() || dump.get().ip6NdProxyDetails.isEmpty()) {
+ return Collections.emptyList();
+ }
+
+ return dump.get().ip6NdProxyDetails.stream()
+ .filter(detail -> detail.swIfIndex == swIfIndex)
+ .map(detail -> new NdProxyKey(arrayToIpv6AddressNoZone(detail.address)))
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<NdProxy> list) {
+ ((NdProxiesBuilder)builder).setNdProxy(list);
+ }
+
+ @Nonnull
+ @Override
+ public NdProxyBuilder getBuilder(@Nonnull final InstanceIdentifier<NdProxy> instanceIdentifier) {
+ return new NdProxyBuilder();
+ }
+
+ @Override
+ public void readCurrentAttributes(@Nonnull final InstanceIdentifier<NdProxy> id,
+ @Nonnull final NdProxyBuilder builder,
+ @Nonnull final ReadContext context)
+ throws ReadFailedException {
+ // address is the only leaf and list key, so jvpp call is not needed:
+ builder.setAddress(id.firstKeyOf(NdProxy.class).getAddress());
+ }
+
+ @Nonnull
+ @Override
+ public Initialized<? extends DataObject> init(@Nonnull final InstanceIdentifier<NdProxy> id,
+ @Nonnull final NdProxy ndProxy,
+ @Nonnull final ReadContext readContext) {
+ return Initialized.create(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(ndProxy.getAddress())
+ .build());
+ }
+
+ @VisibleForTesting
+ protected static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxy> getCfgId(
+ final InstanceIdentifier<NdProxy> id) {
+ final Ipv6AddressNoZone address = id.firstKeyOf(NdProxy.class).getAddress();
+ return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class))
+ .augmentation(Interface1.class).child(Ipv6.class).augmentation(NdProxyIp6Augmentation.class)
+ .child(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.NdProxies.class)
+ .child(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxy.class,
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxyKey(
+ address));
+ }
+}
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/nd/NdProxyCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/nd/NdProxyCustomizerTest.java
new file mode 100644
index 000000000..7d6fcb062
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/nd/NdProxyCustomizerTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.v3po.interfaces.ip.v6.nd;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.core.dto.Ip6NdProxyAddDel;
+import io.fd.vpp.jvpp.core.dto.Ip6NdProxyAddDelReply;
+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.Interfaces;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.NdProxyIp6Augmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.NdProxies;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxy;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxyKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class NdProxyCustomizerTest extends WriterCustomizerTest {
+ private static final String IF_NAME = "eth1";
+ private static final InstanceIdentifier<NdProxies> ND_PROXIES_IID =
+ InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME))
+ .augmentation(Interface1.class).child(Ipv6.class).augmentation(NdProxyIp6Augmentation.class)
+ .child(NdProxies.class);
+ private static final int IF_INDEX = 1;
+
+ private static final String IFACE_CTX_NAME = "ifc-test-instance";
+
+ private NdProxyCustomizer customizer;
+
+ @Override
+ protected void setUpTest() {
+ customizer = new NdProxyCustomizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME));
+ when(api.ip6NdProxyAddDel(any())).thenReturn(future(new Ip6NdProxyAddDelReply()));
+ defineMapping(mappingContext, IF_NAME, IF_INDEX, IFACE_CTX_NAME);
+ }
+
+ @Test
+ public void testWrite() throws WriteFailedException {
+ final Ipv6AddressNoZone address = new Ipv6AddressNoZone("2001::1");
+ final NdProxy data = new NdProxyBuilder().setAddress(address).build();
+ customizer.writeCurrentAttributes(getId(address), data, writeContext);
+ final Ip6NdProxyAddDel request = new Ip6NdProxyAddDel();
+ request.swIfIndex = IF_INDEX;
+ request.address = new byte[] {0x20, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01};
+ verify(api).ip6NdProxyAddDel(request);
+ }
+
+ @Test(expected = WriteFailedException.UpdateFailedException.class)
+ public void testUpdate() throws WriteFailedException {
+ final Ipv6AddressNoZone address = new Ipv6AddressNoZone("2001::2");
+ final NdProxy data = new NdProxyBuilder().setAddress(address).build();
+ customizer.updateCurrentAttributes(getId(address), mock(NdProxy.class), data, writeContext);
+ }
+
+ @Test
+ public void testDelete() throws WriteFailedException {
+ final Ipv6AddressNoZone address = new Ipv6AddressNoZone("2001::3");
+ final NdProxy data = new NdProxyBuilder().setAddress(address).build();
+ customizer.deleteCurrentAttributes(getId(address), data, writeContext);
+ final Ip6NdProxyAddDel request = new Ip6NdProxyAddDel();
+ request.isDel = 1;
+ request.swIfIndex = IF_INDEX;
+ request.address = new byte[] {0x20, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x03};
+ verify(api).ip6NdProxyAddDel(request);
+ }
+
+ private InstanceIdentifier<NdProxy> getId(final Ipv6AddressNoZone address) {
+ return ND_PROXIES_IID.child(NdProxy.class, new NdProxyKey(address));
+ }
+} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/nd/NdProxyCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/nd/NdProxyCustomizerTest.java
new file mode 100644
index 000000000..0db4c95fd
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/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.v3po.interfacesstate.ip.v6.nd;
+
+import static io.fd.hc2vpp.v3po.interfacesstate.ip.v6.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