summaryrefslogtreecommitdiffstats
path: root/vpp-api/java
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2016-05-30 21:52:37 +0200
committerDave Wallace <dwallacelf@gmail.com>2016-05-31 21:19:07 +0000
commit34e7772443f57f4fa561b4affb682329fb9f3bc4 (patch)
tree4d6e3a708a180417f1757675abc19d7633b5d196 /vpp-api/java
parentcb51846ae00fba9b0792fb284635e2e7b9d5fd34 (diff)
Fix u16 type handling in jvpp
Change-Id: I6e5ed2562c65dde6c9f6f085c8b9d40f80684894 Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'vpp-api/java')
-rw-r--r--vpp-api/java/jvpp/gen/jvpp_c_gen.py10
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/test/CreateSubInterfaceTest.java124
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/test/Readme.txt3
3 files changed, 133 insertions, 4 deletions
diff --git a/vpp-api/java/jvpp/gen/jvpp_c_gen.py b/vpp-api/java/jvpp/gen/jvpp_c_gen.py
index c02c826fc49..476a768d9a0 100644
--- a/vpp-api/java/jvpp/gen/jvpp_c_gen.py
+++ b/vpp-api/java/jvpp/gen/jvpp_c_gen.py
@@ -116,7 +116,7 @@ vl_api_ip6_fib_counter_t_array_struct_setter_template = Template("""
// vl_api_ip6_fib_counter_t_array_field_setter_template FIXME""")
struct_setter_templates = {'u8': u8_struct_setter_template,
- 'u16': u32_struct_setter_template,
+ 'u16': u16_struct_setter_template,
'u32': u32_struct_setter_template,
'i32': u32_struct_setter_template,
'u64': u64_struct_setter_template,
@@ -218,6 +218,10 @@ default_dto_field_setter_template = Template("""
(*env)->Set${jni_setter}(env, dto, ${java_name}FieldId, mp->${c_name});
""")
+u16_dto_field_setter_template = Template("""
+ (*env)->Set${jni_setter}(env, dto, ${java_name}FieldId, clib_net_to_host_u16(mp->${c_name}));
+""")
+
u32_dto_field_setter_template = Template("""
(*env)->Set${jni_setter}(env, dto, ${java_name}FieldId, clib_net_to_host_u32(mp->${c_name}));
""")
@@ -247,11 +251,11 @@ u64_array_dto_field_setter_template = Template("""
""")
dto_field_setter_templates = {'u8': default_dto_field_setter_template,
- 'u16': u32_dto_field_setter_template,
+ 'u16': u16_dto_field_setter_template,
'u32': u32_dto_field_setter_template,
'i32': u32_dto_field_setter_template,
'u64': u64_dto_field_setter_template,
- 'f64': default_dto_field_setter_template,
+ 'f64': default_dto_field_setter_template, #fixme
'u64[]': u64_array_dto_field_setter_template,
'u8[]': u8_array_dto_field_setter_template
}
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/test/CreateSubInterfaceTest.java b/vpp-api/java/jvpp/org/openvpp/jvpp/test/CreateSubInterfaceTest.java
new file mode 100644
index 00000000000..f61867e15f1
--- /dev/null
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/test/CreateSubInterfaceTest.java
@@ -0,0 +1,124 @@
+/*
+ * 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 static java.util.Objects.requireNonNull;
+
+import org.openvpp.jvpp.JVppImpl;
+import org.openvpp.jvpp.VppJNIConnection;
+import org.openvpp.jvpp.dto.CreateSubif;
+import org.openvpp.jvpp.dto.CreateSubifReply;
+import org.openvpp.jvpp.dto.SwInterfaceDetailsReplyDump;
+import org.openvpp.jvpp.dto.SwInterfaceDump;
+import org.openvpp.jvpp.future.FutureJVppFacade;
+
+/**
+ * <p>Tests sub-interface creation.<br> Equivalent to:<br>
+ *
+ * <pre>{@code
+ * vppctl create sub GigabitEthernet0/9/0 1 dot1q 100 inner-dot1q any
+ * }
+ * </pre>
+ *
+ * To verify invoke:<br>
+ * <pre>{@code
+ * vpp_api_test json
+ * vat# sw_interface_dump
+ * }
+ */
+public class CreateSubInterfaceTest {
+
+
+ private static SwInterfaceDump createSwInterfaceDumpRequest(final String ifaceName) {
+ SwInterfaceDump request = new SwInterfaceDump();
+ request.nameFilter = ifaceName.getBytes();
+ request.nameFilterValid = 1;
+ return request;
+ }
+
+ private static void requireSingleIface(final SwInterfaceDetailsReplyDump response, final String ifaceName) {
+ if (response.swInterfaceDetails.size() != 1) {
+ throw new IllegalStateException(
+ String.format("Expected one interface matching filter %s but was %d", ifaceName,
+ response.swInterfaceDetails.size()));
+ }
+ }
+
+ private static CreateSubif createSubifRequest(final int swIfIndex, final int subId) {
+ CreateSubif request = new CreateSubif();
+ request.swIfIndex = swIfIndex; // super interface id
+ request.subId = subId;
+ request.noTags = 0;
+ request.oneTag = 0;
+ request.twoTags = 1;
+ request.dot1Ad = 0;
+ request.exactMatch = 1;
+ request.defaultSub = 0;
+ request.outerVlanIdAny = 0;
+ request.innerVlanIdAny = 1;
+ request.outerVlanId = 100;
+ request.innerVlanId = 0;
+ return request;
+ }
+
+ private static void print(CreateSubifReply reply) {
+ System.out.printf("CreateSubifReply: context=%d, retval=%d, swIfIndex=%d\n",
+ reply.context,
+ reply.retval,
+ reply.swIfIndex);
+ }
+
+ private static void testCreateSubInterface() throws Exception {
+ System.out.println("Testing sub-interface creation using Java callback API");
+ final JVppImpl jvpp = new JVppImpl(new VppJNIConnection("SubIfaceTest"));
+ final FutureJVppFacade jvppFacade = new FutureJVppFacade(jvpp);
+
+ System.out.println("Successfully connected to VPP");
+ Thread.sleep(1000);
+
+ final String ifaceName = "GigabitEthernet0/9/0";
+
+ final SwInterfaceDetailsReplyDump swInterfaceDetails =
+ jvppFacade.swInterfaceDump(createSwInterfaceDumpRequest(ifaceName)).toCompletableFuture().get();
+
+ requireNonNull(swInterfaceDetails, "swInterfaceDump returned null");
+ requireNonNull(swInterfaceDetails.swInterfaceDetails, "swInterfaceDetails is null");
+ requireSingleIface(swInterfaceDetails, ifaceName);
+
+ final int swIfIndex = swInterfaceDetails.swInterfaceDetails.get(0).swIfIndex;
+ final int subId = 1;
+
+ final CreateSubifReply createSubifReply =
+ jvppFacade.createSubif(createSubifRequest(swIfIndex, subId)).toCompletableFuture().get();
+ print(createSubifReply);
+
+ final String subIfaceName = "GigabitEthernet0/9/0." + subId;
+ final SwInterfaceDetailsReplyDump subIface =
+ jvppFacade.swInterfaceDump(createSwInterfaceDumpRequest(subIfaceName)).toCompletableFuture().get();
+ requireNonNull(swInterfaceDetails, "swInterfaceDump returned null");
+ requireNonNull(subIface.swInterfaceDetails, "swInterfaceDump returned null");
+ requireSingleIface(swInterfaceDetails, ifaceName);
+
+ System.out.println("Disconnecting...");
+ jvpp.close();
+ Thread.sleep(1000);
+ }
+
+ public static void main(String[] args) throws Exception {
+ testCreateSubInterface();
+ }
+}
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 79486acc3a9..d1ce749f0cc 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/test/Readme.txt
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/test/Readme.txt
@@ -9,4 +9,5 @@ ControlPingTest - Simple test executing a single control ping using low level JV
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
-L2AclTest - Tests L2 ACL creation \ No newline at end of file
+L2AclTest - Tests L2 ACL creation
+CreateSubInterfaceTest - Tests sub-interface creation \ No newline at end of file