summaryrefslogtreecommitdiffstats
path: root/vpp-api/java/jvpp/org
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2016-05-24 13:32:26 +0200
committerMarek Gradzki <mgradzki@cisco.com>2016-05-24 15:44:28 +0000
commitc4cb44c05d121da2e0f0ccd39d5e1bf470731a85 (patch)
tree09fcf64e9fb23053baa775b23ec4e33d2a97cebb /vpp-api/java/jvpp/org
parent4a71314e0bee9f0fc236190a2a6df957adef67f6 (diff)
VPP-86: fix array copy in generated JNI code
Change-Id: Ic67b3c0623d98c5ee3f1ffa1e1bd9cfb96b233bd Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'vpp-api/java/jvpp/org')
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/test/L2AclTest.java137
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/test/Readme.txt7
2 files changed, 140 insertions, 4 deletions
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/test/L2AclTest.java b/vpp-api/java/jvpp/org/openvpp/jvpp/test/L2AclTest.java
new file mode 100644
index 00000000000..e92b4f5d7b3
--- /dev/null
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/test/L2AclTest.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openvpp.jvpp.test;
+
+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.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>
+ *
+ * <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
+ * }
+ * </pre>
+ *
+ * To verify invoke:<br>
+ * {@code vppctl sh class table verbose}
+ */
+public class L2AclTest {
+
+ private static ClassifyAddDelTable createClassifyTable() {
+ ClassifyAddDelTable request = new ClassifyAddDelTable();
+ request.isAdd = 1;
+ request.tableIndex = ~0; // default
+ request.nbuckets = 2;
+ request.memorySize = 2 << 20;
+ request.nextTableIndex = ~0; // default
+ request.missNextIndex = ~0; // default
+ 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};
+ return request;
+ }
+
+ private static ClassifyAddDelSession createClassifySession(final int tableIndex) {
+ ClassifyAddDelSession request = new ClassifyAddDelSession();
+ request.isAdd = 1;
+ request.tableIndex = tableIndex;
+ request.hitNextIndex = 0; // deny
+ request.opaqueIndex = 0;
+ 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};
+ return request;
+ }
+
+ private static InputAclSetInterface aclSetInterface() {
+ InputAclSetInterface request = new InputAclSetInterface();
+ request.isAdd = 1;
+ request.swIfIndex = 0;
+ request.ip4TableIndex = ~0; // skip
+ request.ip6TableIndex = ~0; // skip
+ request.l2TableIndex = 0;
+ return request;
+ }
+
+ private static void print(ClassifyAddDelTableReply reply) {
+ System.out.printf("ClassifyAddDelTableReply: context=%d, retval=%d, " +
+ "newTableIndex=%d, skipNVectors=%d, matchNVectors=%d\n",
+ reply.context,
+ reply.retval,
+ reply.newTableIndex,
+ reply.skipNVectors,
+ reply.matchNVectors);
+ }
+
+ private static void print(ClassifyAddDelSessionReply reply) {
+ System.out.printf("ClassifyAddDelSessionReply: context=%d, retval=%d\n",
+ reply.context,
+ reply.retval);
+ }
+
+ private static void print(final InputAclSetInterfaceReply reply) {
+ System.out.printf("InputAclSetInterfaceReply: context=%d, retval=%d\n",
+ reply.context,
+ reply.retval);
+
+ }
+
+ private static void testL2Acl() throws Exception {
+ System.out.println("Testing L2 ACLs using Java callback API");
+ final JVppImpl jvpp = new JVppImpl(new VppJNIConnection("L2AclTest"));
+ final FutureJVppFacade jvppFacade = new FutureJVppFacade(jvpp);
+
+ System.out.println("Successfully connected to VPP");
+ Thread.sleep(1000);
+
+ final ClassifyAddDelTableReply classifyAddDelTableReply =
+ jvppFacade.classifyAddDelTable(createClassifyTable()).toCompletableFuture().get();
+ print(classifyAddDelTableReply);
+
+ final ClassifyAddDelSessionReply classifyAddDelSessionReply =
+ jvppFacade.classifyAddDelSession(createClassifySession(classifyAddDelTableReply.newTableIndex))
+ .toCompletableFuture().get();
+ print(classifyAddDelSessionReply);
+
+ final InputAclSetInterfaceReply inputAclSetInterfaceReply =
+ jvppFacade.inputAclSetInterface(aclSetInterface()).toCompletableFuture().get();
+ print(inputAclSetInterfaceReply);
+
+ System.out.println("Disconnecting...");
+ jvpp.close();
+ Thread.sleep(1000);
+ }
+
+ public static void main(String[] args) throws Exception {
+ testL2Acl();
+ }
+}
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/test/Readme.txt b/vpp-api/java/jvpp/org/openvpp/jvpp/test/Readme.txt
index df4100dd973..79486acc3a9 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/test/Readme.txt
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/test/Readme.txt
@@ -2,12 +2,11 @@ This package contains basic tests for jvpp. To run the tests:
- Make sure VPP is running
- From VPP's build-root/ folder execute:
- - sudo java -cp .:build-vpp-native/vpp-api/java/jvpp-1.0.0.jar org.openvpp.jvpp.test.ControlPingTest
- - sudo java -cp .:build-vpp-native/vpp-api/java/jvpp-1.0.0.jar org.openvpp.jvpp.test.FutureApiTest
- - sudo java -cp .:build-vpp-native/vpp-api/java/jvpp-1.0.0.jar org.openvpp.jvpp.test.CallbackApiTest
+ - sudo java -cp build-vpp-native/vpp-api/java/jvpp-16.09.jar org.openvpp.jvpp.test.[test name]
Available tests:
ControlPingTest - Simple test executing a single control ping using low level JVpp APIs
CallbackApiTest - Similar to ControlPingTest, invokes more complex calls (e.g. interface dump) using low level JVpp APIs
FutureApiTest - Execution of more complex calls using Future based JVpp facade
-CallbackJVppFacadeTest - Execution of more complex calls using Callback based JVpp facade \ No newline at end of file
+CallbackJVppFacadeTest - Execution of more complex calls using Callback based JVpp facade
+L2AclTest - Tests L2 ACL creation \ No newline at end of file