summaryrefslogtreecommitdiffstats
path: root/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4
diff options
context:
space:
mode:
Diffstat (limited to 'l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4')
-rw-r--r--l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4AddressCustomizer.java144
-rw-r--r--l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4Customizer.java59
-rw-r--r--l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4NeighbourCustomizer.java102
-rw-r--r--l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/subinterface/SubInterfaceIpv4AddressCustomizer.java126
-rw-r--r--l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/subinterface/SubInterfaceIpv4NeighbourCustomizer.java92
5 files changed, 523 insertions, 0 deletions
diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4AddressCustomizer.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4AddressCustomizer.java
new file mode 100644
index 000000000..335f9ed9a
--- /dev/null
+++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4AddressCustomizer.java
@@ -0,0 +1,144 @@
+/*
+ * 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 com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.l3.utils.ip.read.IfaceDumpFilter;
+import io.fd.hc2vpp.l3.utils.ip.read.IpAddressReader;
+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.DumpCacheManagerBuilder;
+import io.fd.vpp.jvpp.core.dto.IpAddressDetails;
+import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import java.util.List;
+import javax.annotation.Nonnull;
+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.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.Subnet;
+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.PrefixLengthBuilder;
+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;
+
+/**
+ * Read customizer for interface Ipv4 addresses.
+ */
+public class Ipv4AddressCustomizer extends IpAddressReader
+ implements InitializingListReaderCustomizer<Address, AddressKey, AddressBuilder> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(Ipv4AddressCustomizer.class);
+
+ public Ipv4AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore,
+ @Nonnull final NamingContext interfaceContext) {
+ super(interfaceContext, false, new DumpCacheManagerBuilder<IpAddressDetailsReplyDump, IfaceDumpFilter>()
+ .withExecutor(createAddressDumpExecutor(futureJVppCore))
+ // Key needs to contain interface ID to distinguish dumps between interfaces
+ .withCacheKeyFactory(interfaceScopedCacheKeyFactory(IpAddressDetailsReplyDump.class))
+ .build());
+ }
+
+ @Override
+ @Nonnull
+ public AddressBuilder getBuilder(@Nonnull InstanceIdentifier<Address> id) {
+ return new AddressBuilder();
+ }
+
+ @Override
+ public void readCurrentAttributes(@Nonnull InstanceIdentifier<Address> id, @Nonnull AddressBuilder builder,
+ @Nonnull ReadContext ctx) throws ReadFailedException {
+ LOG.debug("Reading attributes for interface address: {}", id);
+ final Optional<IpAddressDetailsReplyDump> dumpOptional = interfaceAddressDumpSupplier(id, ctx);
+
+ if (!dumpOptional.isPresent() || dumpOptional.get().ipAddressDetails.isEmpty()) {
+ return;
+ }
+ final Optional<IpAddressDetails> ipAddressDetails = findIpv4AddressDetailsByIp(dumpOptional, id.firstKeyOf(Address.class).getIp());
+
+ if (ipAddressDetails.isPresent()) {
+ final IpAddressDetails detail = ipAddressDetails.get();
+ builder.setIp(arrayToIpv4AddressNoZone(detail.ip))
+ .setSubnet(new PrefixLengthBuilder().setPrefixLength(Short.valueOf(detail.prefixLength)).build());
+
+ if (LOG.isDebugEnabled()) {
+ final String interfaceName = id.firstKeyOf(Interface.class).getName();
+ final int interfaceIndex = getInterfaceContext().getIndex(interfaceName, ctx.getMappingContext());
+ LOG.debug("Attributes for {} interface (id={}) address {} successfully read: {}",
+ interfaceName, interfaceIndex, id, builder.build());
+ }
+ }
+ }
+
+ @Override
+ public List<AddressKey> getAllIds(@Nonnull InstanceIdentifier<Address> id, @Nonnull ReadContext ctx)
+ throws ReadFailedException {
+ LOG.debug("Reading list of keys for interface addresses: {}", id);
+ return getAllIpv4AddressIds(interfaceAddressDumpSupplier(id, ctx), AddressKey::new);
+ }
+
+ @Override
+ public void merge(@Nonnull Builder<? extends DataObject> builder, @Nonnull List<Address> readData) {
+ ((Ipv4Builder) builder).setAddress(readData);
+ }
+
+ @Override
+ public Initialized<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address> init(
+ @Nonnull final InstanceIdentifier<Address> id, @Nonnull final Address readValue,
+ @Nonnull final ReadContext ctx) {
+ return Initialized.create(getCfgId(id),
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressBuilder()
+ .setIp(readValue.getIp())
+ .setSubnet(getSubnet(readValue))
+ .build());
+ }
+
+ private static Subnet getSubnet(final Address address) {
+ final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.Subnet
+ subnet = address.getSubnet();
+
+ // Only prefix length supported
+ Preconditions.checkArgument(
+ subnet instanceof org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.subnet.PrefixLength);
+
+ return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLengthBuilder()
+ .setPrefixLength(
+ ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.subnet.PrefixLength) subnet)
+ .getPrefixLength()).build();
+ }
+
+ static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address> getCfgId(
+ final InstanceIdentifier<Address> id) {
+ return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class))
+ .augmentation(Interface1.class)
+ .child(Ipv4.class)
+ .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address.class,
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressKey(id.firstKeyOf(Address.class).getIp()));
+ }
+}
diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4Customizer.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4Customizer.java
new file mode 100644
index 000000000..28a2aabdb
--- /dev/null
+++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4Customizer.java
@@ -0,0 +1,59 @@
+/*
+ * 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 io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
+import io.fd.honeycomb.translate.read.ReadContext;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+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.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;
+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 class Ipv4Customizer extends FutureJVppCustomizer implements ReaderCustomizer<Ipv4, Ipv4Builder> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(Ipv4Customizer.class);
+
+ public Ipv4Customizer(@Nonnull final FutureJVppCore futureJVppCore) {
+ super(futureJVppCore);
+ }
+
+ @Override
+ public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final Ipv4 readValue) {
+ ((Interface2Builder) parentBuilder).setIpv4(readValue);
+ }
+
+ @Nonnull
+ @Override
+ public Ipv4Builder getBuilder(@Nonnull final InstanceIdentifier<Ipv4> id) {
+ return new Ipv4Builder();
+ }
+
+ @Override
+ public void readCurrentAttributes(@Nonnull final InstanceIdentifier<Ipv4> id, @Nonnull final Ipv4Builder builder,
+ @Nonnull final ReadContext ctx) throws ReadFailedException {
+ LOG.debug("Reading Ipv4 leaves (mtu, forwarding) is not supported by VPP API");
+ }
+
+}
diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4NeighbourCustomizer.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4NeighbourCustomizer.java
new file mode 100644
index 000000000..993fb75f8
--- /dev/null
+++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4NeighbourCustomizer.java
@@ -0,0 +1,102 @@
+/*
+ * 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.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.NeighborOrigin.Dynamic;
+import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.NeighborOrigin.Static;
+
+import com.google.common.base.Optional;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.l3.utils.ip.read.IfaceDumpFilter;
+import io.fd.hc2vpp.l3.utils.ip.read.IpNeighbourReader;
+import io.fd.honeycomb.translate.read.ReadContext;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer;
+import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager.DumpCacheManagerBuilder;
+import io.fd.vpp.jvpp.core.dto.IpNeighborDetails;
+import io.fd.vpp.jvpp.core.dto.IpNeighborDetailsReplyDump;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import java.util.List;
+import java.util.function.Function;
+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.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.concepts.Builder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Operational data read operation customizer for {@link Neighbor}<br>
+ * Currently not supported in jvpp, so this is only dummy implementation<br>
+ */
+public class Ipv4NeighbourCustomizer extends IpNeighbourReader
+ implements ListReaderCustomizer<Neighbor, NeighborKey, NeighborBuilder> {
+
+ public Ipv4NeighbourCustomizer(@Nonnull final FutureJVppCore futureJVppCore,
+ @Nonnull final NamingContext interfaceContext) {
+ super(interfaceContext, false, new DumpCacheManagerBuilder<IpNeighborDetailsReplyDump, IfaceDumpFilter>()
+ .withExecutor(createNeighbourDumpExecutor(futureJVppCore))
+ // cached with parent interface scope
+ .withCacheKeyFactory(interfaceScopedCacheKeyFactory(IpNeighborDetailsReplyDump.class))
+ .build());
+ }
+
+ @Override
+ public NeighborBuilder getBuilder(InstanceIdentifier<Neighbor> id) {
+ return new NeighborBuilder();
+ }
+
+ @Override
+ public void readCurrentAttributes(InstanceIdentifier<Neighbor> id, NeighborBuilder builder, ReadContext ctx)
+ throws ReadFailedException {
+
+ final Ipv4AddressNoZone ip = id.firstKeyOf(Neighbor.class).getIp();
+
+ final Optional<IpNeighborDetailsReplyDump> dumpOpt = interfaceNeighboursDump(id, ctx);
+
+ if (dumpOpt.isPresent()) {
+ dumpOpt.get().ipNeighborDetails
+ .stream()
+ .filter(ipNeighborDetails -> ip.equals(arrayToIpv4AddressNoZone(ipNeighborDetails.ipAddress)))
+ .findFirst()
+ .ifPresent(ipNeighborDetails -> builder.setIp(arrayToIpv4AddressNoZone(ipNeighborDetails.ipAddress))
+ .setKey(keyMapper().apply(ipNeighborDetails))
+ .setLinkLayerAddress(toPhysAddress(ipNeighborDetails.macAddress))
+ .setOrigin(ipNeighborDetails.isStatic == 0
+ ? Dynamic
+ : Static));
+ }
+ }
+
+ @Override
+ public List<NeighborKey> getAllIds(InstanceIdentifier<Neighbor> id, ReadContext context)
+ throws ReadFailedException {
+ return getNeighborKeys(interfaceNeighboursDump(id, context), keyMapper());
+ }
+
+ @Override
+ public void merge(Builder<? extends DataObject> builder, List<Neighbor> readData) {
+ ((Ipv4Builder) builder).setNeighbor(readData);
+ }
+
+ private Function<IpNeighborDetails, NeighborKey> keyMapper() {
+ return ipNeighborDetails -> new NeighborKey(arrayToIpv4AddressNoZone(ipNeighborDetails.ipAddress));
+ }
+} \ No newline at end of file
diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/subinterface/SubInterfaceIpv4AddressCustomizer.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/subinterface/SubInterfaceIpv4AddressCustomizer.java
new file mode 100644
index 000000000..770ece6cf
--- /dev/null
+++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/subinterface/SubInterfaceIpv4AddressCustomizer.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.l3.read.ipv4.subinterface;
+
+import com.google.common.base.Optional;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.l3.utils.ip.read.IfaceDumpFilter;
+import io.fd.hc2vpp.l3.utils.ip.read.IpAddressReader;
+import io.fd.hc2vpp.v3po.interfacesstate.SubInterfaceCustomizer;
+import io.fd.hc2vpp.v3po.util.SubInterfaceUtils;
+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.IpAddressDetails;
+import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import java.util.List;
+import javax.annotation.Nonnull;
+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.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.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.PrefixLengthBuilder;
+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;
+
+/**
+ * Read customizer for sub-interface Ipv4 addresses.
+ */
+public class SubInterfaceIpv4AddressCustomizer extends IpAddressReader
+ implements InitializingListReaderCustomizer<Address, AddressKey, AddressBuilder> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceIpv4AddressCustomizer.class);
+
+ public SubInterfaceIpv4AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore,
+ @Nonnull final NamingContext interfaceContext) {
+ super(interfaceContext, false, new DumpCacheManager.DumpCacheManagerBuilder<IpAddressDetailsReplyDump, IfaceDumpFilter>()
+ .withExecutor(createAddressDumpExecutor(futureJVppCore))
+ //same as with ipv4 addresses for interfaces, these must have cache scope of their parent sub-interface
+ .withCacheKeyFactory(subInterfaceScopedCacheKeyFactory(IpAddressDetailsReplyDump.class))
+ .build());
+ }
+
+ private static String getSubInterfaceName(@Nonnull final InstanceIdentifier<Address> id) {
+ return SubInterfaceUtils.getSubInterfaceName(id.firstKeyOf(Interface.class).getName(),
+ Math.toIntExact(id.firstKeyOf(SubInterface.class).getIdentifier()));
+ }
+
+ @Override
+ @Nonnull
+ public AddressBuilder getBuilder(@Nonnull InstanceIdentifier<Address> id) {
+ return new AddressBuilder();
+ }
+
+ @Override
+ public void readCurrentAttributes(@Nonnull InstanceIdentifier<Address> id, @Nonnull AddressBuilder builder,
+ @Nonnull ReadContext ctx)
+ throws ReadFailedException {
+ LOG.debug("Reading attributes for sub-interface address: {}", id);
+
+ final Optional<IpAddressDetails> ipAddressDetails =
+ findIpv4AddressDetailsByIp(subInterfaceAddressDumpSupplier(id, ctx), id.firstKeyOf(Address.class).getIp());
+
+ if (ipAddressDetails.isPresent()) {
+ final IpAddressDetails detail = ipAddressDetails.get();
+ builder.setIp(arrayToIpv4AddressNoZone(detail.ip));
+ builder.setSubnet(new PrefixLengthBuilder().setPrefixLength((short) detail.prefixLength).build());
+
+ if (LOG.isDebugEnabled()) {
+ final String subInterfaceName = getSubInterfaceName(id);
+ final int subInterfaceIndex = getInterfaceContext().getIndex(subInterfaceName, ctx.getMappingContext());
+ LOG.debug("Attributes for {} sub-interface (id={}) address {} successfully read: {}",
+ subInterfaceName, subInterfaceIndex, id, builder.build());
+ }
+ }
+ }
+
+ @Override
+ @Nonnull
+ public List<AddressKey> getAllIds(@Nonnull InstanceIdentifier<Address> id, @Nonnull ReadContext ctx)
+ throws ReadFailedException {
+ LOG.debug("Reading list of keys for sub-interface addresses: {}", id);
+ return getAllIpv4AddressIds(subInterfaceAddressDumpSupplier(id, ctx), AddressKey::new);
+ }
+
+ @Override
+ public void merge(@Nonnull Builder<? extends DataObject> builder, @Nonnull List<Address> readData) {
+ ((Ipv4Builder) builder).setAddress(readData);
+ }
+
+ @Override
+ public Initialized<Address> init(
+ @Nonnull final InstanceIdentifier<Address> id, @Nonnull final Address readValue,
+ @Nonnull final ReadContext ctx) {
+ return Initialized.create(getCfgId(id), readValue);
+ }
+
+ private InstanceIdentifier<Address> getCfgId(final InstanceIdentifier<Address> id) {
+ return SubInterfaceCustomizer.getCfgId(RWUtils.cutId(id, SubInterface.class))
+ .child(Ipv4.class)
+ .child(Address.class, new AddressKey(id.firstKeyOf(Address.class)));
+ }
+}
diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/subinterface/SubInterfaceIpv4NeighbourCustomizer.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/subinterface/SubInterfaceIpv4NeighbourCustomizer.java
new file mode 100644
index 000000000..55a39180c
--- /dev/null
+++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/subinterface/SubInterfaceIpv4NeighbourCustomizer.java
@@ -0,0 +1,92 @@
+/*
+ * 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.subinterface;
+
+import com.google.common.base.Optional;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.l3.utils.ip.read.IfaceDumpFilter;
+import io.fd.hc2vpp.l3.utils.ip.read.IpNeighbourReader;
+import io.fd.honeycomb.translate.read.ReadContext;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer;
+import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager.DumpCacheManagerBuilder;
+import io.fd.vpp.jvpp.core.dto.IpNeighborDetails;
+import io.fd.vpp.jvpp.core.dto.IpNeighborDetailsReplyDump;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import java.util.List;
+import java.util.function.Function;
+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.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.concepts.Builder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class SubInterfaceIpv4NeighbourCustomizer extends IpNeighbourReader
+ implements ListReaderCustomizer<Neighbor, NeighborKey, NeighborBuilder> {
+
+ public SubInterfaceIpv4NeighbourCustomizer(@Nonnull final FutureJVppCore futureJVppCore,
+ @Nonnull final NamingContext interfaceContext) {
+ super(interfaceContext, false, new DumpCacheManagerBuilder<IpNeighborDetailsReplyDump, IfaceDumpFilter>()
+ .withExecutor(createNeighbourDumpExecutor(futureJVppCore))
+ // cached with parent interface scope
+ .withCacheKeyFactory(subInterfaceScopedCacheKeyFactory(IpNeighborDetailsReplyDump.class))
+ .build());
+ }
+
+ @Override
+ public NeighborBuilder getBuilder(InstanceIdentifier<Neighbor> id) {
+ return new NeighborBuilder();
+ }
+
+ @Override
+ public void readCurrentAttributes(InstanceIdentifier<Neighbor> id, NeighborBuilder builder, ReadContext ctx)
+ throws ReadFailedException {
+
+ final Ipv4AddressNoZone ip = id.firstKeyOf(Neighbor.class).getIp();
+
+ final Optional<IpNeighborDetailsReplyDump> dumpOpt = subInterfaceNeighboursDump(id, ctx);
+
+ if (dumpOpt.isPresent()) {
+ dumpOpt.get().ipNeighborDetails
+ .stream()
+ .filter(ipNeighborDetails -> ip.equals(arrayToIpv4AddressNoZone(ipNeighborDetails.ipAddress)))
+ .findFirst()
+ .ifPresent(ipNeighborDetails -> builder.setIp(arrayToIpv4AddressNoZone(ipNeighborDetails.ipAddress))
+ .setKey(keyMapper().apply(ipNeighborDetails))
+ .setLinkLayerAddress(toPhysAddress(ipNeighborDetails.macAddress)));
+ }
+ }
+
+ @Override
+ public List<NeighborKey> getAllIds(InstanceIdentifier<Neighbor> id, ReadContext context)
+ throws ReadFailedException {
+ return getNeighborKeys(subInterfaceNeighboursDump(id, context), keyMapper());
+ }
+
+ @Override
+ public void merge(Builder<? extends DataObject> builder, List<Neighbor> readData) {
+ ((Ipv4Builder) builder).setNeighbor(readData);
+ }
+
+ private Function<IpNeighborDetails, NeighborKey> keyMapper() {
+ return ipNeighborDetails -> new NeighborKey(arrayToIpv4AddressNoZone(ipNeighborDetails.ipAddress));
+ }
+} \ No newline at end of file