From 1cbfa68433e3207bcc13f93f0af358ac3957636f Mon Sep 17 00:00:00 2001 From: Jan Srnicek Date: Thu, 1 Jun 2017 07:57:49 +0200 Subject: HC2VPP-164 - Interface/SubInterface filtration Filtration cannot be done by subId ,because 0 is allowed value Change-Id: Ic89e30cb74943b6a4c9c995f032bd22567c5ad1e Signed-off-by: Jan Srnicek (cherry picked from commit c9052815f89fff314d8f6b67fcd62b707d827611) --- .../v3po/interfacesstate/InterfaceCustomizer.java | 12 +++----- .../interfacesstate/InterfaceDataTranslator.java | 34 ++++++++++++++++++++-- .../v3po/interfacesstate/RewriteCustomizer.java | 2 +- .../interfacesstate/SubInterfaceCustomizer.java | 6 ++-- .../interfacesstate/InterfaceCustomizerTest.java | 2 ++ .../interfacesstate/RewriteCustomizerTest.java | 2 ++ .../SubInterfaceCustomizerTest.java | 3 +- 7 files changed, 46 insertions(+), 15 deletions(-) diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizer.java index 70bc0c62b..fe04e5d80 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizer.java @@ -16,6 +16,9 @@ package io.fd.hc2vpp.v3po.interfacesstate; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.v3po.DisabledInterfacesManager; import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.ModificationCache; @@ -23,9 +26,6 @@ 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.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; import io.fd.vpp.jvpp.core.dto.SwInterfaceDetailsReplyDump; import io.fd.vpp.jvpp.core.dto.SwInterfaceDump; @@ -86,10 +86,6 @@ public class InterfaceCustomizer extends FutureJVppCustomizer : (Map) ctx.get(DUMPED_IFCS_CONTEXT_KEY); } - private static boolean isRegularInterface(final SwInterfaceDetails iface) { - return iface.subId == 0; - } - @Nonnull @Override public InterfaceBuilder getBuilder(@Nonnull InstanceIdentifier id) { @@ -183,7 +179,7 @@ public class InterfaceCustomizer extends FutureJVppCustomizer return elt; }) // filter out sub-interfaces - .filter(InterfaceCustomizer::isRegularInterface) + .filter(InterfaceDataTranslator.INSTANCE::isRegularInterface) .map(elt -> elt.swIfIndex) .collect(Collectors.toSet()); diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceDataTranslator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceDataTranslator.java index cbffdd37c..f951d8fc2 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceDataTranslator.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceDataTranslator.java @@ -19,11 +19,11 @@ package io.fd.hc2vpp.v3po.interfacesstate; import static com.google.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.honeycomb.translate.ModificationCache; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; import io.fd.vpp.jvpp.core.dto.SwInterfaceDetailsReplyDump; import io.fd.vpp.jvpp.core.dto.SwInterfaceDump; @@ -50,6 +50,9 @@ import org.slf4j.Logger; public interface InterfaceDataTranslator extends ByteDataTranslator, JvppReplyConsumer { + InterfaceDataTranslator INSTANCE = new InterfaceDataTranslator() { + }; + Gauge64 vppLinkSpeed0 = new Gauge64(BigInteger.ZERO); Gauge64 vppLinkSpeed1 = new Gauge64(BigInteger.valueOf(10L * 1000000)); Gauge64 vppLinkSpeed2 = new Gauge64(BigInteger.valueOf(100L * 1000000)); @@ -259,4 +262,31 @@ public interface InterfaceDataTranslator extends ByteDataTranslator, JvppReplyCo final SwInterfaceDetails cachedDetails) { return ifcType.equals(getInterfaceType(toString(cachedDetails.interfaceName))); } + + /** + * Checks whether provided {@link SwInterfaceDetails} is detail of sub-interface
+ *
  • subId == unique number of sub-interface within set of sub-interfaces of single interface + *
  • swIfIndex == unique index of interface/sub-interface within all interfaces + *
  • supSwIfIndex == unique index of parent interface + *
  • in case of interface , swIfIndex value equals supSwIfIndex + *
  • in case of subinterface, supSwIfIndex equals index of parent interface, + * swIfIndex is index of subinterface itselt + */ + default boolean isSubInterface(@Nonnull final SwInterfaceDetails elt) { + //cant check by subId != 0, because you can pick 0 as value + return elt.supSwIfIndex != elt.swIfIndex; + } + + /** + * Checks whether provided {@link SwInterfaceDetails} is detail of interface
    + *
  • subId == unique number of subinterface within set of subinterfaces of single interface + *
  • swIfIndex == unique index of interface/subinterface within all interfaces + *
  • supSwIfIndex == unique index of parent interface + *
  • in case of interface , swIfIndex value equals supSwIfIndex + *
  • in case of subinterface, supSwIfIndex equals index of parent interface, + * swIfIndex is index of subinterface itselt + */ + default boolean isRegularInterface(@Nonnull final SwInterfaceDetails elt) { + return !isSubInterface(elt); + } } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizer.java index 43df761ff..59aa4190e 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizer.java @@ -93,7 +93,7 @@ public class RewriteCustomizer extends FutureJVppCustomizer interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext()), ctx.getModificationCache(), LOG); LOG.debug("VPP sub-interface details: {}", iface); - checkState(iface.subId != 0, "Interface returned by the VPP is not a sub-interface"); + checkState(isSubInterface(iface), "Interface returned by the VPP is not a sub-interface"); final TagRewriteOperation operation = TagRewriteOperation.get(iface.vtrOp); if (TagRewriteOperation.disabled == operation) { diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizer.java index 5a89ab78f..8a6dd667f 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizer.java @@ -144,7 +144,7 @@ public class SubInterfaceCustomizer extends FutureJVppCustomizer final List interfacesKeys = ifaces.swInterfaceDetails.stream() .filter(elt -> elt != null) // accept only sub-interfaces for current iface: - .filter(elt -> elt.subId != 0 && elt.supSwIfIndex == ifaceId) + .filter(elt -> isSubInterface(elt) && elt.supSwIfIndex == ifaceId) .map(details -> new SubInterfaceKey(new Long(details.subId))) .collect(Collectors.toList()); @@ -175,9 +175,9 @@ public class SubInterfaceCustomizer extends FutureJVppCustomizer interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext()), ctx.getModificationCache(), LOG); LOG.debug("VPP sub-interface details: {}", iface); - checkState(iface.subId != 0, "Interface returned by the VPP is not a sub-interface"); + checkState(isSubInterface(iface), "Interface returned by the VPP is not a sub-interface"); - builder.setIdentifier(Long.valueOf(iface.subId)); + builder.setIdentifier((long) iface.subId); builder.setKey(new SubInterfaceKey(builder.getIdentifier())); // sub-interface-base-attributes: diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizerTest.java index 295805114..2f8a30b84 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizerTest.java @@ -155,9 +155,11 @@ public class InterfaceCustomizerTest extends ListReaderCustomizerTest