summaryrefslogtreecommitdiffstats
path: root/extras/japi/java/jvpp-core
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2018-11-28 11:36:05 +0100
committerNeale Ranns <nranns@cisco.com>2018-12-13 12:11:50 +0000
commit413f4a5b2123c1625d615315db293a080078482b (patch)
tree6cfd8376c1d84b93793b062731ec9594487dc95e /extras/japi/java/jvpp-core
parent6f666ad99ae1e384aa851af5e0feed3d2a25e709 (diff)
API: Use string type instead of u8.
The new string type is modelled after string in proto3. It is always variable length. Change-Id: I64884067e28a80072c8dac31b7c7c82d6e306051 Signed-off-by: Ole Troan <ot@cisco.com> Signed-off-by: Michal Cmarada <mcmarada@cisco.com> Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'extras/japi/java/jvpp-core')
-rw-r--r--extras/japi/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackApiExample.java10
-rw-r--r--extras/japi/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackJVppFacadeExample.java16
-rw-r--r--extras/japi/java/jvpp-core/io/fd/vpp/jvpp/core/examples/FutureApiExample.java10
-rw-r--r--extras/japi/java/jvpp-core/io/fd/vpp/jvpp/core/examples/L2AclExample.java2
-rw-r--r--extras/japi/java/jvpp-core/jvpp_core.c5
-rw-r--r--extras/japi/java/jvpp-core/jvpp_core.h61
6 files changed, 82 insertions, 22 deletions
diff --git a/extras/japi/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackApiExample.java b/extras/japi/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackApiExample.java
index b99979cf301..b6558ffaa7e 100644
--- a/extras/japi/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackApiExample.java
+++ b/extras/japi/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackApiExample.java
@@ -77,17 +77,17 @@ public class CallbackApiExample {
System.out.printf("Received ShowVersionReply: context=%d, program=%s, version=%s, "
+ "buildDate=%s, buildDirectory=%s%n",
msg.context,
- new String(msg.program, StandardCharsets.UTF_8),
- new String(msg.version, StandardCharsets.UTF_8),
- new String(msg.buildDate, StandardCharsets.UTF_8),
- new String(msg.buildDirectory, StandardCharsets.UTF_8));
+ msg.program,
+ msg.version,
+ msg.buildDate,
+ msg.buildDirectory);
}
@Override
public void onSwInterfaceDetails(final SwInterfaceDetails msg) {
System.out.printf("Received SwInterfaceDetails: interfaceName=%s, l2AddressLength=%d, adminUpDown=%d, "
+ "linkUpDown=%d, linkSpeed=%d, linkMtu=%d%n",
- new String(msg.interfaceName, StandardCharsets.UTF_8), msg.l2AddressLength, msg.adminUpDown,
+ msg.interfaceName, msg.l2AddressLength, msg.adminUpDown,
msg.linkUpDown, msg.linkSpeed, (int) msg.linkMtu);
}
diff --git a/extras/japi/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackJVppFacadeExample.java b/extras/japi/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackJVppFacadeExample.java
index dc2bdcba569..a8b91860b75 100644
--- a/extras/japi/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackJVppFacadeExample.java
+++ b/extras/japi/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackJVppFacadeExample.java
@@ -39,10 +39,10 @@ public class CallbackJVppFacadeExample {
public void onShowVersionReply(final ShowVersionReply msg) {
System.out.printf("ShowVersionCallback1 received ShowVersionReply: context=%d, program=%s,"
+ "version=%s, buildDate=%s, buildDirectory=%s%n", msg.context,
- new String(msg.program, StandardCharsets.UTF_8),
- new String(msg.version, StandardCharsets.UTF_8),
- new String(msg.buildDate, StandardCharsets.UTF_8),
- new String(msg.buildDirectory, StandardCharsets.UTF_8));
+ msg.program,
+ msg.version,
+ msg.buildDate,
+ msg.buildDirectory);
}
@Override
@@ -57,10 +57,10 @@ public class CallbackJVppFacadeExample {
public void onShowVersionReply(final ShowVersionReply msg) {
System.out.printf("ShowVersionCallback2 received ShowVersionReply: context=%d, program=%s,"
+ "version=%s, buildDate=%s, buildDirectory=%s%n", msg.context,
- new String(msg.program, StandardCharsets.UTF_8),
- new String(msg.version, StandardCharsets.UTF_8),
- new String(msg.buildDate, StandardCharsets.UTF_8),
- new String(msg.buildDirectory, StandardCharsets.UTF_8));
+ msg.program,
+ msg.version,
+ msg.buildDate,
+ msg.buildDirectory);
}
@Override
diff --git a/extras/japi/java/jvpp-core/io/fd/vpp/jvpp/core/examples/FutureApiExample.java b/extras/japi/java/jvpp-core/io/fd/vpp/jvpp/core/examples/FutureApiExample.java
index 931c9b337aa..030e68995a2 100644
--- a/extras/japi/java/jvpp-core/io/fd/vpp/jvpp/core/examples/FutureApiExample.java
+++ b/extras/japi/java/jvpp-core/io/fd/vpp/jvpp/core/examples/FutureApiExample.java
@@ -47,10 +47,10 @@ public class FutureApiExample {
LOG.info(
String.format(
"Received ShowVersionReply: context=%d, program=%s, version=%s, buildDate=%s, buildDirectory=%s%n",
- reply.context, new String(reply.program, StandardCharsets.UTF_8),
- new String(reply.version, StandardCharsets.UTF_8),
- new String(reply.buildDate, StandardCharsets.UTF_8),
- new String(reply.buildDirectory, StandardCharsets.UTF_8)));
+ reply.context, reply.program,
+ reply.version,
+ reply.buildDate,
+ reply.buildDirectory));
}
private static void testEmptyBridgeDomainDump(final FutureJVppCoreFacade jvpp) throws Exception {
@@ -100,7 +100,7 @@ public class FutureApiExample {
LOG.info(
String.format("Received SwInterfaceDetails: interfaceName=%s, l2AddressLength=%d, adminUpDown=%d, "
+ "linkUpDown=%d, linkSpeed=%d, linkMtu=%d%n",
- new String(details.interfaceName, StandardCharsets.UTF_8),
+ details.interfaceName,
details.l2AddressLength, details.adminUpDown,
details.linkUpDown, details.linkSpeed, (int) details.linkMtu));
}
diff --git a/extras/japi/java/jvpp-core/io/fd/vpp/jvpp/core/examples/L2AclExample.java b/extras/japi/java/jvpp-core/io/fd/vpp/jvpp/core/examples/L2AclExample.java
index 9a17136a6d9..0be85d4f17f 100644
--- a/extras/japi/java/jvpp-core/io/fd/vpp/jvpp/core/examples/L2AclExample.java
+++ b/extras/japi/java/jvpp-core/io/fd/vpp/jvpp/core/examples/L2AclExample.java
@@ -75,7 +75,7 @@ public class L2AclExample {
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
}
- return new String(hexChars);
+ return new java.lang.String(hexChars);
}
private static ClassifyTableInfo createClassifyTableInfoRequest(final int tableId) {
diff --git a/extras/japi/java/jvpp-core/jvpp_core.c b/extras/japi/java/jvpp-core/jvpp_core.c
index 09d753026d7..0df8589702c 100644
--- a/extras/japi/java/jvpp-core/jvpp_core.c
+++ b/extras/japi/java/jvpp-core/jvpp_core.c
@@ -14,7 +14,7 @@
*/
#include <vnet/vnet.h>
-
+#include <jvpp-common/jvpp_common.h>
#include <vpp/api/vpe_msg_enum.h>
#define vl_typedefs /* define message structures */
#include <vpp/api/vpe_all_api_h.h>
@@ -24,8 +24,7 @@
#include <vlibapi/api.h>
#include <vlibmemory/api.h>
#include <jni.h>
-
-#include <jvpp-common/jvpp_common.h>
+#include <jvpp_core.h>
// TODO: generate jvpp_plugin_name.c files (or at least reuse plugin's main structure)
typedef struct {
diff --git a/extras/japi/java/jvpp-core/jvpp_core.h b/extras/japi/java/jvpp-core/jvpp_core.h
new file mode 100644
index 00000000000..bbf7a71fa31
--- /dev/null
+++ b/extras/japi/java/jvpp-core/jvpp_core.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2018 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.
+ */
+
+#ifndef VPP_JVPP_CORE_H
+#define VPP_JVPP_CORE_H
+
+#include <vlibapi/api_types.h>
+
+#endif //VPP_JVPP_CORE_H
+
+// /**
+// * Host to network byte order conversion for string type. Converts String in Java to VPP string type.
+// * typedef struct
+// * {
+// * u32 length;
+// * u8 buf[0];
+// * } __attribute__ ((packed)) vl_api_string_t;
+// */
+static void _host_to_net_string(JNIEnv * env, jstring javaString, vl_api_string_t * _net)
+{
+ const char *nativeString = (*env)->GetStringUTFChars(env, javaString, 0);
+ int len = strlen(nativeString);
+
+ vl_api_string_t * vl_api_string = (vl_api_string_t *)calloc(1, (sizeof(vl_api_string_t) + len * sizeof(u8)));
+ if (NULL == vl_api_string)
+ return;
+
+ vl_api_string->length = len;
+ memcpy(vl_api_string->buf, nativeString, len);
+
+ _net = vl_api_string;
+ (*env)->ReleaseStringUTFChars(env, javaString, nativeString);
+}
+
+//
+// /**
+// * Network to host byte order conversion for string type. Converts VPP string type to String in Java
+// * typedef struct
+// * {
+// * u32 length;
+// * u8 buf[0];
+// * } __attribute__ ((packed)) vl_api_string_t;
+// */
+static jstring _net_to_host_string(JNIEnv * env, const vl_api_string_t * _net)
+{
+ jstring jstr = (*env)->NewStringUTF(env, (char *)_net->buf);
+
+ return jstr;
+}