diff options
Diffstat (limited to 'v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface')
2 files changed, 24 insertions, 63 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4AddressCustomizer.java index f27229acd..55fd6ca3a 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4AddressCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4AddressCustomizer.java @@ -16,15 +16,11 @@ package io.fd.hc2vpp.v3po.interfacesstate.ip.v4.subinterface; -import static com.google.common.base.Preconditions.checkNotNull; - import com.google.common.base.Optional; -import com.google.common.collect.ImmutableSet; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.v3po.interfacesstate.SubInterfaceCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.ip.IpReader; import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.IfaceDumpFilter; +import io.fd.hc2vpp.v3po.interfacesstate.ip.readers.IpAddressReader; import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; @@ -32,12 +28,9 @@ 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.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.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; @@ -52,27 +45,24 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.annotation.Nonnull; +import java.util.List; + /** * Read customizer for sub-interface Ipv4 addresses. */ -public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer - implements InitializingListReaderCustomizer<Address, AddressKey, AddressBuilder>, IpReader { +public class SubInterfaceIpv4AddressCustomizer extends IpAddressReader + implements InitializingListReaderCustomizer<Address, AddressKey, AddressBuilder> { private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceIpv4AddressCustomizer.class); - private final NamingContext interfaceContext; - private final DumpCacheManager<IpAddressDetailsReplyDump, IfaceDumpFilter> dumpManager; - public SubInterfaceIpv4AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore, @Nonnull final NamingContext interfaceContext) { - super(futureJVppCore); - this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null"); - this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder<IpAddressDetailsReplyDump, IfaceDumpFilter>() + 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(new TypeAwareIdentifierCacheKeyFactory(IpAddressDetailsReplyDump.class, - ImmutableSet.of(SubInterface.class))) - .build(); + .withCacheKeyFactory(subInterfaceScopedCacheKeyFactory(IpAddressDetailsReplyDump.class)) + .build()); } private static String getSubInterfaceName(@Nonnull final InstanceIdentifier<Address> id) { @@ -92,13 +82,8 @@ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer throws ReadFailedException { LOG.debug("Reading attributes for sub-interface address: {}", id); - final String subInterfaceName = getSubInterfaceName(id); - final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext()); - final Optional<IpAddressDetailsReplyDump> dumpOptional = dumpManager - .getDump(id, ctx.getModificationCache(), new IfaceDumpFilter(subInterfaceIndex, false)); - final Optional<IpAddressDetails> ipAddressDetails = - findIpv4AddressDetailsByIp(dumpOptional, id.firstKeyOf(Address.class).getIp()); + findIpv4AddressDetailsByIp(subInterfaceAddressDumpSupplier(id, ctx), id.firstKeyOf(Address.class).getIp()); if (ipAddressDetails.isPresent()) { final IpAddressDetails detail = ipAddressDetails.get(); @@ -106,6 +91,8 @@ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer 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()); } @@ -117,13 +104,7 @@ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer public List<AddressKey> getAllIds(@Nonnull InstanceIdentifier<Address> id, @Nonnull ReadContext ctx) throws ReadFailedException { LOG.debug("Reading list of keys for sub-interface addresses: {}", id); - - final String subInterfaceName = getSubInterfaceName(id); - final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext()); - final Optional<IpAddressDetailsReplyDump> dumpOptional = dumpManager - .getDump(id, ctx.getModificationCache(), new IfaceDumpFilter(subInterfaceIndex, false)); - - return getAllIpv4AddressIds(dumpOptional, AddressKey::new); + return getAllIpv4AddressIds(subInterfaceAddressDumpSupplier(id, ctx), AddressKey::new); } @Override diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4NeighbourCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4NeighbourCustomizer.java index 71833db0d..aaedabd9f 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4NeighbourCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4NeighbourCustomizer.java @@ -17,26 +17,17 @@ package io.fd.hc2vpp.v3po.interfacesstate.ip.v4.subinterface; import com.google.common.base.Optional; -import com.google.common.collect.ImmutableSet; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.ip.IpReader; import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.IfaceDumpFilter; +import io.fd.hc2vpp.v3po.interfacesstate.ip.readers.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; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager.DumpCacheManagerBuilder; -import io.fd.honeycomb.translate.util.read.cache.DumpSupplier; -import io.fd.honeycomb.translate.util.read.cache.TypeAwareIdentifierCacheKeyFactory; 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.interfaces.rev140508.interfaces.state.Interface; 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; @@ -45,22 +36,20 @@ import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -public class SubInterfaceIpv4NeighbourCustomizer extends FutureJVppCustomizer - implements ListReaderCustomizer<Neighbor, NeighborKey, NeighborBuilder>, IpReader { +import javax.annotation.Nonnull; +import java.util.List; +import java.util.function.Function; - private final DumpCacheManager<IpNeighborDetailsReplyDump, IfaceDumpFilter> dumpManager; - private final NamingContext interfaceContext; +public class SubInterfaceIpv4NeighbourCustomizer extends IpNeighbourReader + implements ListReaderCustomizer<Neighbor, NeighborKey, NeighborBuilder> { public SubInterfaceIpv4NeighbourCustomizer(@Nonnull final FutureJVppCore futureJVppCore, @Nonnull final NamingContext interfaceContext) { - super(futureJVppCore); - dumpManager = new DumpCacheManagerBuilder<IpNeighborDetailsReplyDump, IfaceDumpFilter>() + super(interfaceContext, false, new DumpCacheManagerBuilder<IpNeighborDetailsReplyDump, IfaceDumpFilter>() .withExecutor(createNeighbourDumpExecutor(futureJVppCore)) // cached with parent interface scope - .withCacheKeyFactory(new TypeAwareIdentifierCacheKeyFactory(IpNeighborDetailsReplyDump.class, - ImmutableSet.of(Interface.class))) - .build(); - this.interfaceContext = interfaceContext; + .withCacheKeyFactory(subInterfaceScopedCacheKeyFactory(IpNeighborDetailsReplyDump.class)) + .build()); } @Override @@ -74,7 +63,7 @@ public class SubInterfaceIpv4NeighbourCustomizer extends FutureJVppCustomizer final Ipv4AddressNoZone ip = id.firstKeyOf(Neighbor.class).getIp(); - final Optional<IpNeighborDetailsReplyDump> dumpOpt = dumpSupplier(id, ctx).get(); + final Optional<IpNeighborDetailsReplyDump> dumpOpt = subInterfaceNeighboursDump(id, ctx); if (dumpOpt.isPresent()) { dumpOpt.get().ipNeighborDetails @@ -90,7 +79,7 @@ public class SubInterfaceIpv4NeighbourCustomizer extends FutureJVppCustomizer @Override public List<NeighborKey> getAllIds(InstanceIdentifier<Neighbor> id, ReadContext context) throws ReadFailedException { - return getNeighborKeys(dumpSupplier(id, context), keyMapper()); + return getNeighborKeys(subInterfaceNeighboursDump(id, context), keyMapper()); } @Override @@ -101,13 +90,4 @@ public class SubInterfaceIpv4NeighbourCustomizer extends FutureJVppCustomizer private Function<IpNeighborDetails, NeighborKey> keyMapper() { return ipNeighborDetails -> new NeighborKey(arrayToIpv4AddressNoZone(ipNeighborDetails.ipAddress)); } - - private DumpSupplier<Optional<IpNeighborDetailsReplyDump>> dumpSupplier(final InstanceIdentifier<Neighbor> id, - final ReadContext context) { - return () -> dumpManager - .getDump(id, context.getModificationCache(), new IfaceDumpFilter(interfaceContext - .getIndex(id.firstKeyOf(Interface.class).getName(), context.getMappingContext()), - false)); - } - }
\ No newline at end of file |