Add support for classify table/session read to jvpp: 71/1771/2
authorMarek Gradzki <mgradzki@cisco.com>
Mon, 27 Jun 2016 08:45:09 +0000 (10:45 +0200)
committerMarek Gradzki <mgradzki@cisco.com>
Mon, 27 Jun 2016 15:11:41 +0000 (17:11 +0200)
* provides length information for variable length arrays
  in classify table/sessione reply messages
* provides jvpp example for reading classify tables/sessions

Change-Id: I47f8fca5c849ec874d4e23f28177e310689db522
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
vpp-api/java/jvpp/org/openvpp/jvpp/test/L2AclTest.java
vpp/vpp-api/vpe.api

index d8d04ed..802df63 100644 (file)
 
 package org.openvpp.jvpp.test;
 
+import java.util.Arrays;
+import javax.xml.bind.DatatypeConverter;
 import org.openvpp.jvpp.JVppImpl;
 import org.openvpp.jvpp.VppJNIConnection;
 import org.openvpp.jvpp.dto.ClassifyAddDelSession;
 import org.openvpp.jvpp.dto.ClassifyAddDelSessionReply;
 import org.openvpp.jvpp.dto.ClassifyAddDelTable;
 import org.openvpp.jvpp.dto.ClassifyAddDelTableReply;
+import org.openvpp.jvpp.dto.ClassifySessionDetails;
+import org.openvpp.jvpp.dto.ClassifySessionDetailsReplyDump;
+import org.openvpp.jvpp.dto.ClassifySessionDump;
+import org.openvpp.jvpp.dto.ClassifyTableByInterface;
+import org.openvpp.jvpp.dto.ClassifyTableByInterfaceReply;
+import org.openvpp.jvpp.dto.ClassifyTableIds;
+import org.openvpp.jvpp.dto.ClassifyTableIdsReply;
+import org.openvpp.jvpp.dto.ClassifyTableInfo;
+import org.openvpp.jvpp.dto.ClassifyTableInfoReply;
 import org.openvpp.jvpp.dto.InputAclSetInterface;
 import org.openvpp.jvpp.dto.InputAclSetInterfaceReply;
 import org.openvpp.jvpp.future.FutureJVppFacade;
 
 /**
- * <p>Tests L2 ACL creation.<br>
- * Equivalent to the following vppctl commands:<br>
+ * <p>Tests L2 ACL creation and read.<br> Equivalent to the following vppctl commands:<br>
  *
  * <pre>{@code
  * vppctl classify table mask l2 src
  * vppctl classify session acl-hit-next deny opaque-index 0 table-index 0 match l2 src 01:02:03:04:05:06
- * vppctl vppctl set int input acl intfc local0 l2-table 0
+ * vppctl set int input acl intfc local0 l2-table 0
+ * vppctl sh class table verbose
  * }
  * </pre>
- *
- * To verify invoke:<br>
- * {@code vppctl sh class table verbose}
  */
 public class L2AclTest {
 
+    private static final int LOCAL0_IFACE_ID = 0;
+
     private static ClassifyAddDelTable createClassifyTable() {
         ClassifyAddDelTable request = new ClassifyAddDelTable();
         request.isAdd = 1;
@@ -53,8 +63,14 @@ public class L2AclTest {
         request.skipNVectors = 0;
         request.matchNVectors = 1;
         request.mask =
-                new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-                        (byte) 0xff, (byte) 0xff, 0x00, 0x00, 0x00, 0x00};
+            new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+                (byte) 0xff, (byte) 0xff, 0x00, 0x00, 0x00, 0x00};
+        return request;
+    }
+
+    private static ClassifyTableInfo createClassifyTableInfoRequest(final int tableId) {
+        ClassifyTableInfo request = new ClassifyTableInfo();
+        request.tableId = tableId;
         return request;
     }
 
@@ -67,39 +83,89 @@ public class L2AclTest {
         request.advance = 0; // default
         // match 01:02:03:04:05:06 mac address
         request.match =
-                new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04,
-                        (byte) 0x05, (byte) 0x06, 0x00, 0x00, 0x00, 0x00};
+            new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04,
+                (byte) 0x05, (byte) 0x06, 0x00, 0x00, 0x00, 0x00};
+        return request;
+    }
+
+    private static ClassifySessionDump createClassifySessionDumpRequest(final int newTableIndex) {
+        ClassifySessionDump request = new ClassifySessionDump();
+        request.tableId = newTableIndex;
         return request;
     }
 
     private static InputAclSetInterface aclSetInterface() {
         InputAclSetInterface request = new InputAclSetInterface();
         request.isAdd = 1;
-        request.swIfIndex = 0;
+        request.swIfIndex = LOCAL0_IFACE_ID;
         request.ip4TableIndex = ~0; // skip
         request.ip6TableIndex = ~0; // skip
         request.l2TableIndex = 0;
         return request;
     }
 
+    private static ClassifyTableByInterface createClassifyTableByInterfaceRequest() {
+        ClassifyTableByInterface request = new ClassifyTableByInterface();
+        request.swIfIndex = LOCAL0_IFACE_ID;
+        return request;
+    }
+
     private static void print(ClassifyAddDelTableReply reply) {
         System.out.printf("ClassifyAddDelTableReply: context=%d, " +
-                        "newTableIndex=%d, skipNVectors=%d, matchNVectors=%d\n",
-                reply.context,
-                reply.newTableIndex,
-                reply.skipNVectors,
-                reply.matchNVectors);
+                "newTableIndex=%d, skipNVectors=%d, matchNVectors=%d\n",
+            reply.context, reply.newTableIndex, reply.skipNVectors, reply.matchNVectors);
+    }
+
+    private static void print(ClassifyTableIdsReply reply) {
+        System.out.printf("ClassifyTableIdsReply: context=%d, count=%d, ids.length=%d\n",
+            reply.context, reply.count, reply.ids.length);
+        Arrays.stream(reply.ids).forEach(System.out::println);
+    }
+
+    private static void print(final ClassifyTableInfoReply reply) {
+        final StringBuilder builder = new StringBuilder("ClassifyTableInfoReply:\n");
+        builder.append("context: ").append(reply.context).append('\n');
+        builder.append("tableId: ").append(reply.tableId).append('\n');
+        builder.append("nbuckets: ").append(reply.nbuckets).append('\n');
+        builder.append("matchNVectors: ").append(reply.matchNVectors).append('\n');
+        builder.append("skipNVectors: ").append(reply.skipNVectors).append('\n');
+        builder.append("activeSessions: ").append(reply.activeSessions).append('\n');
+        builder.append("nextTableIndex: ").append(reply.nextTableIndex).append('\n');
+        builder.append("missNextIndex: ").append(reply.missNextIndex).append('\n');
+        builder.append("maskLength: ").append(reply.maskLength).append('\n');
+        builder.append("mask: ").append(DatatypeConverter.printHexBinary(reply.mask)).append('\n');
+        System.out.println(builder.toString());
     }
 
     private static void print(ClassifyAddDelSessionReply reply) {
         System.out.printf("ClassifyAddDelSessionReply: context=%d\n",
-                reply.context);
+            reply.context);
+    }
+
+    private static void print(final ClassifySessionDetailsReplyDump reply) {
+        if (reply.classifySessionDetails == null) {
+            System.out.println("ClassifySessionDetailsReplyDump: classifySessionDetails == NULL");
+        }
+        for (final ClassifySessionDetails details : reply.classifySessionDetails) {
+            final StringBuilder builder = new StringBuilder("ClassifySessionDetails:\n");
+            builder.append("context: ").append(details.context).append('\n');
+            builder.append("tableId: ").append(details.tableId).append('\n');
+            builder.append("hitNextIndex: ").append(details.hitNextIndex).append('\n');
+            builder.append("advance: ").append(details.advance).append('\n');
+            builder.append("opaqueIndex: ").append(details.opaqueIndex).append('\n');
+            builder.append("matchLength: ").append(details.matchLength).append('\n');
+            builder.append("match: ").append(DatatypeConverter.printHexBinary(details.match)).append('\n');
+            System.out.println(builder.toString());
+        }
     }
 
     private static void print(final InputAclSetInterfaceReply reply) {
-        System.out.printf("InputAclSetInterfaceReply: context=%d\n",
-                reply.context);
+        System.out.printf("InputAclSetInterfaceReply: context=%d\n", reply.context);
+    }
 
+    private static void print(final ClassifyTableByInterfaceReply reply) {
+        System.out.printf("ClassifyAddDelTableReply: context=%d, swIfIndex=%d, l2TableId=%d, ip4TableId=%d," +
+            "ip6TableId=%d\n", reply.context, reply.swIfIndex, reply.l2TableId, reply.ip4TableId, reply.ip6TableId);
     }
 
     private static void testL2Acl() throws Exception {
@@ -111,18 +177,36 @@ public class L2AclTest {
         Thread.sleep(1000);
 
         final ClassifyAddDelTableReply classifyAddDelTableReply =
-                jvppFacade.classifyAddDelTable(createClassifyTable()).toCompletableFuture().get();
+            jvppFacade.classifyAddDelTable(createClassifyTable()).toCompletableFuture().get();
         print(classifyAddDelTableReply);
 
+        final ClassifyTableIdsReply classifyTableIdsReply =
+            jvppFacade.classifyTableIds(new ClassifyTableIds()).toCompletableFuture().get();
+        print(classifyTableIdsReply);
+
+        final ClassifyTableInfoReply classifyTableInfoReply =
+            jvppFacade.classifyTableInfo(createClassifyTableInfoRequest(classifyAddDelTableReply.newTableIndex))
+                .toCompletableFuture().get();
+        print(classifyTableInfoReply);
+
         final ClassifyAddDelSessionReply classifyAddDelSessionReply =
-                jvppFacade.classifyAddDelSession(createClassifySession(classifyAddDelTableReply.newTableIndex))
-                        .toCompletableFuture().get();
+            jvppFacade.classifyAddDelSession(createClassifySession(classifyAddDelTableReply.newTableIndex))
+                .toCompletableFuture().get();
         print(classifyAddDelSessionReply);
 
+        final ClassifySessionDetailsReplyDump classifySessionDetailsReplyDump =
+            jvppFacade.classifySessionDump(createClassifySessionDumpRequest(classifyAddDelTableReply.newTableIndex))
+                .toCompletableFuture().get();
+        print(classifySessionDetailsReplyDump);
+
         final InputAclSetInterfaceReply inputAclSetInterfaceReply =
-                jvppFacade.inputAclSetInterface(aclSetInterface()).toCompletableFuture().get();
+            jvppFacade.inputAclSetInterface(aclSetInterface()).toCompletableFuture().get();
         print(inputAclSetInterfaceReply);
 
+        final ClassifyTableByInterfaceReply classifyTableByInterfaceReply =
+            jvppFacade.classifyTableByInterface(createClassifyTableByInterfaceRequest()).toCompletableFuture().get();
+        print(classifyTableByInterfaceReply);
+
         System.out.println("Disconnecting...");
         jvpp.close();
         Thread.sleep(1000);
index a1ea1b2..0184a3e 100644 (file)
@@ -3854,7 +3854,7 @@ manual_java define classify_table_ids_reply {
     u32 context;
     u32 retval;
     u32 count;
-    u32 ids[0];
+    u32 ids[count];
 };
 
 /** \brief Classify table ids by interface index request
@@ -3919,7 +3919,7 @@ manual_java define classify_table_info_reply {
     u32 next_table_index;
     u32 miss_next_index;
     u32 mask_length;
-    u8  mask[0];
+    u8  mask[mask_length];
 };
 
 /** \brief Classify sessions dump request
@@ -3950,5 +3950,5 @@ manual_java define classify_session_details {
     i32 advance;
     u32 opaque_index;
     u32 match_length;
-    u8 match[0];
+    u8 match[match_length];
 };