HC2VPP-164 - Interface/SubInterface filtration 50/6950/5
authorJan Srnicek <[email protected]>
Thu, 1 Jun 2017 05:57:49 +0000 (07:57 +0200)
committerJan Srnicek <[email protected]>
Thu, 1 Jun 2017 05:57:49 +0000 (07:57 +0200)
Filtration cannot be done by subId ,because 0 is allowed value

Change-Id: Ic89e30cb74943b6a4c9c995f032bd22567c5ad1e
Signed-off-by: Jan Srnicek <[email protected]>
v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizer.java
v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceDataTranslator.java
v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizer.java
v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizer.java
v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizerTest.java
v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizerTest.java
v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizerTest.java

index 70bc0c6..fe04e5d 100644 (file)
@@ -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());
 
index cbffdd3..f951d8f 100644 (file)
@@ -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);
+    }
 }
index 3fd0445..bdb31d4 100644 (file)
@@ -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) {
index 41a3c70..0bed156 100644 (file)
@@ -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:
index 2958051..2f8a30b 100644 (file)
@@ -155,9 +155,11 @@ public class InterfaceCustomizerTest extends ListReaderCustomizerTest<Interface,
 
         final SwInterfaceDetails swIf0 = new SwInterfaceDetails();
         swIf0.swIfIndex = 0;
+        swIf0.supSwIfIndex = 0;
         swIf0.interfaceName = IFACE0_NAME.getBytes();
         final SwInterfaceDetails swIf1 = new SwInterfaceDetails();
         swIf1.swIfIndex = 1;
+        swIf1.supSwIfIndex = 1;
         swIf1.interfaceName = IFACE1_NAME.getBytes();
         final SwInterfaceDetails swSubIf1 = new SwInterfaceDetails();
         swSubIf1.swIfIndex = 2;
index 0ae22b5..c9f9320 100644 (file)
@@ -97,6 +97,8 @@ public class RewriteCustomizerTest extends ReaderCustomizerTest<Rewrite, Rewrite
         ifaceDetails.vtrTag1 = 123;
         ifaceDetails.vtrTag2 = 321;
         ifaceDetails.vtrPushDot1Q = 1;
+        ifaceDetails.swIfIndex= VLAN_IF_INDEX;
+        ifaceDetails.supSwIfIndex = 2;
         cachedInterfaceDump.put(VLAN_IF_INDEX, ifaceDetails);
         cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump);
 
index 94f6db4..5065d4a 100644 (file)
@@ -87,7 +87,8 @@ public class SubInterfaceCustomizerTest extends ListReaderCustomizerTest<SubInte
         final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails();
         ifaceDetails.subId = VLAN_IF_ID;
         ifaceDetails.interfaceName = VLAN_IF_NAME.getBytes();
-        ifaceDetails.subDot1Ad = 1;
+        ifaceDetails.swIfIndex = 2;
+        ifaceDetails.supSwIfIndex = SUPER_IF_INDEX;
         defineMapping(mappingContext, SUPER_IF_NAME, SUPER_IF_INDEX, IFC_CTX_NAME);
         defineMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_CTX_NAME);
         ifaceDetails.subNumberOfTags = 2;