summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/main/java/io
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2017-06-01 07:57:49 +0200
committerJan Srnicek <jsrnicek@cisco.com>2017-06-01 07:57:49 +0200
commitc9052815f89fff314d8f6b67fcd62b707d827611 (patch)
tree0fb60c6e7845e9143c79445c381613b775ac3990 /v3po/v3po2vpp/src/main/java/io
parentd0d30f67f8b4da8f594b2adc0fa74f3fbf3e1f09 (diff)
HC2VPP-164 - Interface/SubInterface filtration
Filtration cannot be done by subId ,because 0 is allowed value Change-Id: Ic89e30cb74943b6a4c9c995f032bd22567c5ad1e Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/main/java/io')
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizer.java12
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceDataTranslator.java34
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizer.java2
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizer.java6
4 files changed, 40 insertions, 14 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<Integer, SwInterfaceDetails>) ctx.get(DUMPED_IFCS_CONTEXT_KEY);
}
- private static boolean isRegularInterface(final SwInterfaceDetails iface) {
- return iface.subId == 0;
- }
-
@Nonnull
@Override
public InterfaceBuilder getBuilder(@Nonnull InstanceIdentifier<Interface> 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<br>
+ * <li>subId == unique number of sub-interface within set of sub-interfaces of single interface
+ * <li>swIfIndex == unique index of interface/sub-interface within all interfaces
+ * <li>supSwIfIndex == unique index of parent interface
+ * <li>in case of interface , swIfIndex value equals supSwIfIndex
+ * <li>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<br>
+ * <li>subId == unique number of subinterface within set of subinterfaces of single interface
+ * <li>swIfIndex == unique index of interface/subinterface within all interfaces
+ * <li>supSwIfIndex == unique index of parent interface
+ * <li>in case of interface , swIfIndex value equals supSwIfIndex
+ * <li>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 3fd0445fb..bdb31d44a 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 41a3c704b..0bed15683 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<SubInterfaceKey> 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: