From 2388db4347cf0c4a1032cb945db2fdb1011d74d7 Mon Sep 17 00:00:00 2001 From: Michal Cmarada Date: Thu, 28 Feb 2019 10:21:59 +0100 Subject: Update package names updating package names from io.fd.vpp.jvpp* to io.fd.jvpp* Change-Id: Ia1634db8f0875ff6ecfeddc281041cd49c4aacc2 Signed-off-by: Michal Cmarada --- java/CMakeLists.txt | 8 +- java/Readme.txt | 4 +- .../fd/jvpp/acl/examples/AclExpectedDumpData.java | 135 ++++++++++++++ .../io/fd/jvpp/acl/examples/AclTestData.java | 101 ++++++++++ .../io/fd/jvpp/acl/examples/AclTestRequests.java | 159 ++++++++++++++++ .../io/fd/jvpp/acl/examples/FutureApiExample.java | 68 +++++++ java/jvpp-acl/io/fd/jvpp/acl/examples/Readme.txt | 4 + .../io/fd/jvpp/acl/test/CallbackApiTest.java | 33 ++++ .../io/fd/jvpp/acl/test/FutureApiTest.java | 62 +++++++ java/jvpp-acl/io/fd/jvpp/acl/test/Readme.txt | 4 + .../vpp/jvpp/acl/examples/AclExpectedDumpData.java | 135 -------------- .../io/fd/vpp/jvpp/acl/examples/AclTestData.java | 101 ---------- .../fd/vpp/jvpp/acl/examples/AclTestRequests.java | 159 ---------------- .../fd/vpp/jvpp/acl/examples/FutureApiExample.java | 68 ------- .../io/fd/vpp/jvpp/acl/examples/Readme.txt | 4 - .../io/fd/vpp/jvpp/acl/test/CallbackApiTest.java | 33 ---- .../io/fd/vpp/jvpp/acl/test/FutureApiTest.java | 62 ------- java/jvpp-acl/io/fd/vpp/jvpp/acl/test/Readme.txt | 4 - java/jvpp-acl/jvpp_acl.c | 10 +- java/jvpp-common/jvpp_common.c | 2 +- .../fd/jvpp/core/examples/CallbackApiExample.java | 100 ++++++++++ .../core/examples/CallbackApiReadPerfTest.java | 146 +++++++++++++++ .../core/examples/CallbackApiWritePerfTest.java | 162 ++++++++++++++++ .../jvpp/core/examples/CallbackCliApiExample.java | 68 +++++++ .../core/examples/CallbackJVppFacadeExample.java | 110 +++++++++++ .../CallbackJVppFacadeNotificationExample.java | 97 ++++++++++ .../examples/CallbackNotificationApiExample.java | 88 +++++++++ .../core/examples/CreateSubInterfaceExample.java | 121 ++++++++++++ .../io/fd/jvpp/core/examples/FutureApiExample.java | 127 +++++++++++++ .../examples/FutureApiNotificationExample.java | 67 +++++++ .../jvpp/core/examples/FutureApiReadPerfTest.java | 137 ++++++++++++++ .../io/fd/jvpp/core/examples/L2AclExample.java | 206 +++++++++++++++++++++ .../jvpp/core/examples/LispAdjacencyExample.java | 125 +++++++++++++ .../fd/jvpp/core/examples/NotificationUtils.java | 52 ++++++ java/jvpp-core/io/fd/jvpp/core/examples/Readme.txt | 24 +++ .../io/fd/jvpp/core/test/CallbackApiTest.java | 33 ++++ .../io/fd/jvpp/core/test/FutureApiTest.java | 79 ++++++++ java/jvpp-core/io/fd/jvpp/core/test/Readme.txt | 18 ++ .../vpp/jvpp/core/examples/CallbackApiExample.java | 100 ---------- .../core/examples/CallbackApiReadPerfTest.java | 146 --------------- .../core/examples/CallbackApiWritePerfTest.java | 162 ---------------- .../jvpp/core/examples/CallbackCliApiExample.java | 68 ------- .../core/examples/CallbackJVppFacadeExample.java | 110 ----------- .../CallbackJVppFacadeNotificationExample.java | 97 ---------- .../examples/CallbackNotificationApiExample.java | 88 --------- .../core/examples/CreateSubInterfaceExample.java | 121 ------------ .../vpp/jvpp/core/examples/FutureApiExample.java | 127 ------------- .../examples/FutureApiNotificationExample.java | 67 ------- .../jvpp/core/examples/FutureApiReadPerfTest.java | 137 -------------- .../io/fd/vpp/jvpp/core/examples/L2AclExample.java | 206 --------------------- .../jvpp/core/examples/LispAdjacencyExample.java | 125 ------------- .../vpp/jvpp/core/examples/NotificationUtils.java | 52 ------ .../io/fd/vpp/jvpp/core/examples/Readme.txt | 24 --- .../io/fd/vpp/jvpp/core/test/CallbackApiTest.java | 33 ---- .../io/fd/vpp/jvpp/core/test/FutureApiTest.java | 79 -------- java/jvpp-core/io/fd/vpp/jvpp/core/test/Readme.txt | 18 -- java/jvpp-core/jvpp_core.c | 6 +- java/jvpp-gtpu/jvpp_gtpu.c | 10 +- java/jvpp-ikev2/jvpp_ikev2.c | 10 +- .../ioamexport/examples/IoamExportApiExample.java | 56 ++++++ .../io/fd/jvpp/ioamexport/examples/Readme.txt | 4 + .../fd/jvpp/ioamexport/test/CallbackApiTest.java | 33 ++++ .../io/fd/jvpp/ioamexport/test/FutureApiTest.java | 60 ++++++ .../io/fd/jvpp/ioamexport/test/Readme.txt | 4 + .../ioamexport/examples/IoamExportApiExample.java | 56 ------ .../io/fd/vpp/jvpp/ioamexport/examples/Readme.txt | 4 - .../vpp/jvpp/ioamexport/test/CallbackApiTest.java | 33 ---- .../fd/vpp/jvpp/ioamexport/test/FutureApiTest.java | 60 ------ .../io/fd/vpp/jvpp/ioamexport/test/Readme.txt | 4 - java/jvpp-ioamexport/jvpp_ioam_export.c | 10 +- .../jvpp/ioampot/examples/IoamPotApiExample.java | 76 ++++++++ .../io/fd/jvpp/ioampot/examples/Readme.txt | 4 + .../io/fd/jvpp/ioampot/test/CallbackApiTest.java | 33 ++++ .../io/fd/jvpp/ioampot/test/FutureApiTest.java | 66 +++++++ .../io/fd/jvpp/ioampot/test/Readme.txt | 4 + .../jvpp/ioampot/examples/IoamPotApiExample.java | 76 -------- .../io/fd/vpp/jvpp/ioampot/examples/Readme.txt | 4 - .../fd/vpp/jvpp/ioampot/test/CallbackApiTest.java | 33 ---- .../io/fd/vpp/jvpp/ioampot/test/FutureApiTest.java | 66 ------- .../io/fd/vpp/jvpp/ioampot/test/Readme.txt | 4 - java/jvpp-ioampot/jvpp_ioam_pot.c | 10 +- .../ioamtrace/examples/IoamTraceApiExample.java | 77 ++++++++ .../io/fd/jvpp/ioamtrace/examples/Readme.txt | 4 + .../io/fd/jvpp/ioamtrace/test/CallbackApiTest.java | 33 ++++ .../io/fd/jvpp/ioamtrace/test/FutureApiTest.java | 60 ++++++ .../io/fd/jvpp/ioamtrace/test/Readme.txt | 4 + .../ioamtrace/examples/IoamTraceApiExample.java | 77 -------- .../io/fd/vpp/jvpp/ioamtrace/examples/Readme.txt | 4 - .../vpp/jvpp/ioamtrace/test/CallbackApiTest.java | 33 ---- .../fd/vpp/jvpp/ioamtrace/test/FutureApiTest.java | 60 ------ .../io/fd/vpp/jvpp/ioamtrace/test/Readme.txt | 4 - java/jvpp-ioamtrace/jvpp_ioam_trace.c | 10 +- .../fd/jvpp/nat/examples/CallbackApiExample.java | 68 +++++++ java/jvpp-nat/io/fd/jvpp/nat/examples/Readme.txt | 1 + .../io/fd/jvpp/nat/test/CallbackApiTest.java | 33 ++++ .../io/fd/jvpp/nat/test/FutureApiTest.java | 66 +++++++ java/jvpp-nat/io/fd/jvpp/nat/test/Readme.txt | 4 + .../vpp/jvpp/nat/examples/CallbackApiExample.java | 68 ------- .../io/fd/vpp/jvpp/nat/examples/Readme.txt | 1 - .../io/fd/vpp/jvpp/nat/test/CallbackApiTest.java | 33 ---- .../io/fd/vpp/jvpp/nat/test/FutureApiTest.java | 66 ------- java/jvpp-nat/io/fd/vpp/jvpp/nat/test/Readme.txt | 4 - java/jvpp-nat/jvpp_nat.c | 10 +- java/jvpp-nsh/jvpp_nsh.c | 10 +- java/jvpp-pppoe/jvpp_pppoe.c | 10 +- .../io/fd/jvpp/AbstractCallbackApiTest.java | 63 +++++++ java/jvpp-registry/io/fd/jvpp/Assertions.java | 32 ++++ java/jvpp-registry/io/fd/jvpp/JVpp.java | 56 ++++++ java/jvpp-registry/io/fd/jvpp/JVppRegistry.java | 76 ++++++++ .../jvpp-registry/io/fd/jvpp/JVppRegistryImpl.java | 187 +++++++++++++++++++ .../io/fd/jvpp/NativeLibraryLoader.java | 73 ++++++++ .../io/fd/jvpp/VppBaseCallException.java | 79 ++++++++ .../io/fd/jvpp/VppCallbackException.java | 48 +++++ java/jvpp-registry/io/fd/jvpp/VppConnection.java | 45 +++++ .../io/fd/jvpp/VppInvocationException.java | 33 ++++ .../jvpp-registry/io/fd/jvpp/VppJNIConnection.java | 152 +++++++++++++++ .../io/fd/jvpp/callback/ControlPingCallback.java | 29 +++ .../io/fd/jvpp/callback/JVppCallback.java | 29 +++ .../fd/jvpp/callback/JVppNotificationCallback.java | 24 +++ .../io/fd/jvpp/coverity/SuppressFBWarnings.java | 40 ++++ java/jvpp-registry/io/fd/jvpp/dto/ControlPing.java | 34 ++++ .../io/fd/jvpp/dto/ControlPingReply.java | 58 ++++++ java/jvpp-registry/io/fd/jvpp/dto/JVppDump.java | 24 +++ java/jvpp-registry/io/fd/jvpp/dto/JVppReply.java | 24 +++ .../io/fd/jvpp/dto/JVppReplyDump.java | 25 +++ java/jvpp-registry/io/fd/jvpp/dto/JVppRequest.java | 34 ++++ .../fd/jvpp/future/AbstractFutureJVppInvoker.java | 180 ++++++++++++++++++ .../io/fd/jvpp/future/FutureJVppInvoker.java | 49 +++++ .../io/fd/jvpp/notification/EventRegistry.java | 25 +++ .../jvpp/notification/EventRegistryProvider.java | 28 +++ .../io/fd/jvpp/test/ConnectionTest.java | 44 +++++ .../io/fd/vpp/jvpp/AbstractCallbackApiTest.java | 63 ------- java/jvpp-registry/io/fd/vpp/jvpp/Assertions.java | 32 ---- java/jvpp-registry/io/fd/vpp/jvpp/JVpp.java | 56 ------ .../jvpp-registry/io/fd/vpp/jvpp/JVppRegistry.java | 76 -------- .../io/fd/vpp/jvpp/JVppRegistryImpl.java | 187 ------------------- .../io/fd/vpp/jvpp/NativeLibraryLoader.java | 73 -------- .../io/fd/vpp/jvpp/VppBaseCallException.java | 79 -------- .../io/fd/vpp/jvpp/VppCallbackException.java | 48 ----- .../io/fd/vpp/jvpp/VppConnection.java | 45 ----- .../io/fd/vpp/jvpp/VppInvocationException.java | 33 ---- .../io/fd/vpp/jvpp/VppJNIConnection.java | 152 --------------- .../fd/vpp/jvpp/callback/ControlPingCallback.java | 29 --- .../io/fd/vpp/jvpp/callback/JVppCallback.java | 29 --- .../jvpp/callback/JVppNotificationCallback.java | 24 --- .../fd/vpp/jvpp/coverity/SuppressFBWarnings.java | 40 ---- .../io/fd/vpp/jvpp/dto/ControlPing.java | 34 ---- .../io/fd/vpp/jvpp/dto/ControlPingReply.java | 58 ------ .../jvpp-registry/io/fd/vpp/jvpp/dto/JVppDump.java | 24 --- .../io/fd/vpp/jvpp/dto/JVppReply.java | 24 --- .../io/fd/vpp/jvpp/dto/JVppReplyDump.java | 25 --- .../io/fd/vpp/jvpp/dto/JVppRequest.java | 34 ---- .../vpp/jvpp/future/AbstractFutureJVppInvoker.java | 180 ------------------ .../io/fd/vpp/jvpp/future/FutureJVppInvoker.java | 49 ----- .../io/fd/vpp/jvpp/notification/EventRegistry.java | 25 --- .../jvpp/notification/EventRegistryProvider.java | 28 --- .../io/fd/vpp/jvpp/test/ConnectionTest.java | 44 ----- java/jvpp-registry/jvpp_registry.c | 18 +- java/jvpp/gen/jvppgen/callback_gen.py | 4 +- java/jvpp/gen/jvppgen/dto_gen.py | 10 +- java/jvpp/gen/jvppgen/jni_gen.py | 4 +- java/jvpp/gen/jvppgen/jni_impl_gen.py | 4 +- java/jvpp/gen/jvppgen/jni_msg_handlers_gen.py | 2 +- java/jvpp/gen/jvppgen/jvpp_callback_facade_gen.py | 30 +-- java/jvpp/gen/jvppgen/jvpp_common_gen.py | 4 +- java/jvpp/gen/jvppgen/jvpp_future_facade_gen.py | 40 ++-- java/jvpp/gen/jvppgen/jvpp_ifc_gen.py | 10 +- java/jvpp/gen/jvppgen/jvpp_impl_gen.py | 20 +- java/jvpp/gen/jvppgen/jvpp_model.py | 30 +-- java/jvpp/gen/jvppgen/notification_gen.py | 10 +- 170 files changed, 4655 insertions(+), 4655 deletions(-) create mode 100644 java/jvpp-acl/io/fd/jvpp/acl/examples/AclExpectedDumpData.java create mode 100644 java/jvpp-acl/io/fd/jvpp/acl/examples/AclTestData.java create mode 100644 java/jvpp-acl/io/fd/jvpp/acl/examples/AclTestRequests.java create mode 100644 java/jvpp-acl/io/fd/jvpp/acl/examples/FutureApiExample.java create mode 100644 java/jvpp-acl/io/fd/jvpp/acl/examples/Readme.txt create mode 100644 java/jvpp-acl/io/fd/jvpp/acl/test/CallbackApiTest.java create mode 100644 java/jvpp-acl/io/fd/jvpp/acl/test/FutureApiTest.java create mode 100644 java/jvpp-acl/io/fd/jvpp/acl/test/Readme.txt delete mode 100644 java/jvpp-acl/io/fd/vpp/jvpp/acl/examples/AclExpectedDumpData.java delete mode 100644 java/jvpp-acl/io/fd/vpp/jvpp/acl/examples/AclTestData.java delete mode 100644 java/jvpp-acl/io/fd/vpp/jvpp/acl/examples/AclTestRequests.java delete mode 100644 java/jvpp-acl/io/fd/vpp/jvpp/acl/examples/FutureApiExample.java delete mode 100644 java/jvpp-acl/io/fd/vpp/jvpp/acl/examples/Readme.txt delete mode 100644 java/jvpp-acl/io/fd/vpp/jvpp/acl/test/CallbackApiTest.java delete mode 100644 java/jvpp-acl/io/fd/vpp/jvpp/acl/test/FutureApiTest.java delete mode 100644 java/jvpp-acl/io/fd/vpp/jvpp/acl/test/Readme.txt create mode 100644 java/jvpp-core/io/fd/jvpp/core/examples/CallbackApiExample.java create mode 100644 java/jvpp-core/io/fd/jvpp/core/examples/CallbackApiReadPerfTest.java create mode 100644 java/jvpp-core/io/fd/jvpp/core/examples/CallbackApiWritePerfTest.java create mode 100644 java/jvpp-core/io/fd/jvpp/core/examples/CallbackCliApiExample.java create mode 100644 java/jvpp-core/io/fd/jvpp/core/examples/CallbackJVppFacadeExample.java create mode 100644 java/jvpp-core/io/fd/jvpp/core/examples/CallbackJVppFacadeNotificationExample.java create mode 100644 java/jvpp-core/io/fd/jvpp/core/examples/CallbackNotificationApiExample.java create mode 100644 java/jvpp-core/io/fd/jvpp/core/examples/CreateSubInterfaceExample.java create mode 100644 java/jvpp-core/io/fd/jvpp/core/examples/FutureApiExample.java create mode 100644 java/jvpp-core/io/fd/jvpp/core/examples/FutureApiNotificationExample.java create mode 100644 java/jvpp-core/io/fd/jvpp/core/examples/FutureApiReadPerfTest.java create mode 100644 java/jvpp-core/io/fd/jvpp/core/examples/L2AclExample.java create mode 100644 java/jvpp-core/io/fd/jvpp/core/examples/LispAdjacencyExample.java create mode 100644 java/jvpp-core/io/fd/jvpp/core/examples/NotificationUtils.java create mode 100644 java/jvpp-core/io/fd/jvpp/core/examples/Readme.txt create mode 100644 java/jvpp-core/io/fd/jvpp/core/test/CallbackApiTest.java create mode 100644 java/jvpp-core/io/fd/jvpp/core/test/FutureApiTest.java create mode 100644 java/jvpp-core/io/fd/jvpp/core/test/Readme.txt delete mode 100644 java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackApiExample.java delete mode 100644 java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackApiReadPerfTest.java delete mode 100644 java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackApiWritePerfTest.java delete mode 100644 java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackCliApiExample.java delete mode 100644 java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackJVppFacadeExample.java delete mode 100644 java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackJVppFacadeNotificationExample.java delete mode 100644 java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackNotificationApiExample.java delete mode 100644 java/jvpp-core/io/fd/vpp/jvpp/core/examples/CreateSubInterfaceExample.java delete mode 100644 java/jvpp-core/io/fd/vpp/jvpp/core/examples/FutureApiExample.java delete mode 100644 java/jvpp-core/io/fd/vpp/jvpp/core/examples/FutureApiNotificationExample.java delete mode 100644 java/jvpp-core/io/fd/vpp/jvpp/core/examples/FutureApiReadPerfTest.java delete mode 100644 java/jvpp-core/io/fd/vpp/jvpp/core/examples/L2AclExample.java delete mode 100644 java/jvpp-core/io/fd/vpp/jvpp/core/examples/LispAdjacencyExample.java delete mode 100644 java/jvpp-core/io/fd/vpp/jvpp/core/examples/NotificationUtils.java delete mode 100644 java/jvpp-core/io/fd/vpp/jvpp/core/examples/Readme.txt delete mode 100644 java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackApiTest.java delete mode 100644 java/jvpp-core/io/fd/vpp/jvpp/core/test/FutureApiTest.java delete mode 100644 java/jvpp-core/io/fd/vpp/jvpp/core/test/Readme.txt create mode 100644 java/jvpp-ioamexport/io/fd/jvpp/ioamexport/examples/IoamExportApiExample.java create mode 100644 java/jvpp-ioamexport/io/fd/jvpp/ioamexport/examples/Readme.txt create mode 100644 java/jvpp-ioamexport/io/fd/jvpp/ioamexport/test/CallbackApiTest.java create mode 100644 java/jvpp-ioamexport/io/fd/jvpp/ioamexport/test/FutureApiTest.java create mode 100644 java/jvpp-ioamexport/io/fd/jvpp/ioamexport/test/Readme.txt delete mode 100644 java/jvpp-ioamexport/io/fd/vpp/jvpp/ioamexport/examples/IoamExportApiExample.java delete mode 100644 java/jvpp-ioamexport/io/fd/vpp/jvpp/ioamexport/examples/Readme.txt delete mode 100644 java/jvpp-ioamexport/io/fd/vpp/jvpp/ioamexport/test/CallbackApiTest.java delete mode 100644 java/jvpp-ioamexport/io/fd/vpp/jvpp/ioamexport/test/FutureApiTest.java delete mode 100644 java/jvpp-ioamexport/io/fd/vpp/jvpp/ioamexport/test/Readme.txt create mode 100644 java/jvpp-ioampot/io/fd/jvpp/ioampot/examples/IoamPotApiExample.java create mode 100644 java/jvpp-ioampot/io/fd/jvpp/ioampot/examples/Readme.txt create mode 100644 java/jvpp-ioampot/io/fd/jvpp/ioampot/test/CallbackApiTest.java create mode 100644 java/jvpp-ioampot/io/fd/jvpp/ioampot/test/FutureApiTest.java create mode 100644 java/jvpp-ioampot/io/fd/jvpp/ioampot/test/Readme.txt delete mode 100644 java/jvpp-ioampot/io/fd/vpp/jvpp/ioampot/examples/IoamPotApiExample.java delete mode 100644 java/jvpp-ioampot/io/fd/vpp/jvpp/ioampot/examples/Readme.txt delete mode 100644 java/jvpp-ioampot/io/fd/vpp/jvpp/ioampot/test/CallbackApiTest.java delete mode 100644 java/jvpp-ioampot/io/fd/vpp/jvpp/ioampot/test/FutureApiTest.java delete mode 100644 java/jvpp-ioampot/io/fd/vpp/jvpp/ioampot/test/Readme.txt create mode 100644 java/jvpp-ioamtrace/io/fd/jvpp/ioamtrace/examples/IoamTraceApiExample.java create mode 100644 java/jvpp-ioamtrace/io/fd/jvpp/ioamtrace/examples/Readme.txt create mode 100644 java/jvpp-ioamtrace/io/fd/jvpp/ioamtrace/test/CallbackApiTest.java create mode 100644 java/jvpp-ioamtrace/io/fd/jvpp/ioamtrace/test/FutureApiTest.java create mode 100644 java/jvpp-ioamtrace/io/fd/jvpp/ioamtrace/test/Readme.txt delete mode 100644 java/jvpp-ioamtrace/io/fd/vpp/jvpp/ioamtrace/examples/IoamTraceApiExample.java delete mode 100644 java/jvpp-ioamtrace/io/fd/vpp/jvpp/ioamtrace/examples/Readme.txt delete mode 100644 java/jvpp-ioamtrace/io/fd/vpp/jvpp/ioamtrace/test/CallbackApiTest.java delete mode 100644 java/jvpp-ioamtrace/io/fd/vpp/jvpp/ioamtrace/test/FutureApiTest.java delete mode 100644 java/jvpp-ioamtrace/io/fd/vpp/jvpp/ioamtrace/test/Readme.txt create mode 100644 java/jvpp-nat/io/fd/jvpp/nat/examples/CallbackApiExample.java create mode 100644 java/jvpp-nat/io/fd/jvpp/nat/examples/Readme.txt create mode 100644 java/jvpp-nat/io/fd/jvpp/nat/test/CallbackApiTest.java create mode 100644 java/jvpp-nat/io/fd/jvpp/nat/test/FutureApiTest.java create mode 100644 java/jvpp-nat/io/fd/jvpp/nat/test/Readme.txt delete mode 100644 java/jvpp-nat/io/fd/vpp/jvpp/nat/examples/CallbackApiExample.java delete mode 100644 java/jvpp-nat/io/fd/vpp/jvpp/nat/examples/Readme.txt delete mode 100644 java/jvpp-nat/io/fd/vpp/jvpp/nat/test/CallbackApiTest.java delete mode 100644 java/jvpp-nat/io/fd/vpp/jvpp/nat/test/FutureApiTest.java delete mode 100644 java/jvpp-nat/io/fd/vpp/jvpp/nat/test/Readme.txt create mode 100644 java/jvpp-registry/io/fd/jvpp/AbstractCallbackApiTest.java create mode 100644 java/jvpp-registry/io/fd/jvpp/Assertions.java create mode 100644 java/jvpp-registry/io/fd/jvpp/JVpp.java create mode 100644 java/jvpp-registry/io/fd/jvpp/JVppRegistry.java create mode 100644 java/jvpp-registry/io/fd/jvpp/JVppRegistryImpl.java create mode 100644 java/jvpp-registry/io/fd/jvpp/NativeLibraryLoader.java create mode 100644 java/jvpp-registry/io/fd/jvpp/VppBaseCallException.java create mode 100644 java/jvpp-registry/io/fd/jvpp/VppCallbackException.java create mode 100644 java/jvpp-registry/io/fd/jvpp/VppConnection.java create mode 100644 java/jvpp-registry/io/fd/jvpp/VppInvocationException.java create mode 100644 java/jvpp-registry/io/fd/jvpp/VppJNIConnection.java create mode 100644 java/jvpp-registry/io/fd/jvpp/callback/ControlPingCallback.java create mode 100644 java/jvpp-registry/io/fd/jvpp/callback/JVppCallback.java create mode 100644 java/jvpp-registry/io/fd/jvpp/callback/JVppNotificationCallback.java create mode 100644 java/jvpp-registry/io/fd/jvpp/coverity/SuppressFBWarnings.java create mode 100644 java/jvpp-registry/io/fd/jvpp/dto/ControlPing.java create mode 100644 java/jvpp-registry/io/fd/jvpp/dto/ControlPingReply.java create mode 100644 java/jvpp-registry/io/fd/jvpp/dto/JVppDump.java create mode 100644 java/jvpp-registry/io/fd/jvpp/dto/JVppReply.java create mode 100644 java/jvpp-registry/io/fd/jvpp/dto/JVppReplyDump.java create mode 100644 java/jvpp-registry/io/fd/jvpp/dto/JVppRequest.java create mode 100644 java/jvpp-registry/io/fd/jvpp/future/AbstractFutureJVppInvoker.java create mode 100644 java/jvpp-registry/io/fd/jvpp/future/FutureJVppInvoker.java create mode 100644 java/jvpp-registry/io/fd/jvpp/notification/EventRegistry.java create mode 100644 java/jvpp-registry/io/fd/jvpp/notification/EventRegistryProvider.java create mode 100644 java/jvpp-registry/io/fd/jvpp/test/ConnectionTest.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/AbstractCallbackApiTest.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/Assertions.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/JVpp.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/JVppRegistry.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/JVppRegistryImpl.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/NativeLibraryLoader.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/VppBaseCallException.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/VppCallbackException.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/VppConnection.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/VppInvocationException.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/VppJNIConnection.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/callback/ControlPingCallback.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/callback/JVppCallback.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/callback/JVppNotificationCallback.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/coverity/SuppressFBWarnings.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/dto/ControlPing.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/dto/ControlPingReply.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/dto/JVppDump.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/dto/JVppReply.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/dto/JVppReplyDump.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/dto/JVppRequest.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/future/AbstractFutureJVppInvoker.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/future/FutureJVppInvoker.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/notification/EventRegistry.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/notification/EventRegistryProvider.java delete mode 100644 java/jvpp-registry/io/fd/vpp/jvpp/test/ConnectionTest.java (limited to 'java') diff --git a/java/CMakeLists.txt b/java/CMakeLists.txt index c1c9e16..7f014d4 100644 --- a/java/CMakeLists.txt +++ b/java/CMakeLists.txt @@ -35,7 +35,7 @@ set(JVPP_LIBS jvpp_common ${VPPINFRA_DIR} ${VLIBMEMORYCLIENT_DIR} ${SVM_DIR} Threads::Threads m rt) ############# Registry package ################## -set(PACKAGE_DIR_JVPP_REGISTRY io/fd/vpp/jvpp) +set(PACKAGE_DIR_JVPP_REGISTRY io/fd/jvpp) unset(files) FILE(GLOB files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} @@ -67,7 +67,7 @@ add_custom_command(TARGET jvpp-registry ${CMAKE_CURRENT_BINARY_DIR}/jvpp-registry-${JAPI_LIB_VERSION}.jar -C jvpp-registry/target . COMMAND rm ARGS -rf jvpp-registry/target - jvpp-registry/io_fd_vpp_jvpp_*.h + jvpp-registry/io_fd_jvpp_*.h WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "JAR_GEN registry" ) @@ -106,8 +106,8 @@ function(jargen name) ${CMAKE_CURRENT_BINARY_DIR}/jvpp-${name}-${JAPI_LIB_VERSION}.jar -C jvpp-${name}/target . COMMAND rm ARGS -rf jvpp-${name}/target jvpp-${name}/jvpp-${name}.files - jvpp-${name}/jvpp_${name}_gen.h jvpp-${name}/io_fd_vpp_jvpp_*.h - jvpp-registry/io_fd_vpp_jvpp_*.h + jvpp-${name}/jvpp_${name}_gen.h jvpp-${name}/io_fd_jvpp_*.h + jvpp-registry/io_fd_jvpp_*.h WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "JAR_GEN ${name}" ) diff --git a/java/Readme.txt b/java/Readme.txt index 689b9b3..375c596 100644 --- a/java/Readme.txt +++ b/java/Readme.txt @@ -137,10 +137,10 @@ JVpp Java | | == Package structure -* *io.fd.vpp.jvpp* - top level package for generated JVpp interface+ implementation and hand-crafted +* *io.fd.jvpp* - top level package for generated JVpp interface+ implementation and hand-crafted VppConnection interface + implementation - packaged as jvpp-registry-version.jar -* *io.fd.vpp.jvpp.[plugin]* - top level package for generated JVpp interface + implementation +* *io.fd.jvpp.[plugin]* - top level package for generated JVpp interface + implementation + plugin's API tests - packaged as jvpp-[plugin]-version.jar ** *dto* - package for DTOs generated from VPP API structures + base/marker hand-crafted interfaces diff --git a/java/jvpp-acl/io/fd/jvpp/acl/examples/AclExpectedDumpData.java b/java/jvpp-acl/io/fd/jvpp/acl/examples/AclExpectedDumpData.java new file mode 100644 index 0000000..f145ae2 --- /dev/null +++ b/java/jvpp-acl/io/fd/jvpp/acl/examples/AclExpectedDumpData.java @@ -0,0 +1,135 @@ +/* + * 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 io.fd.jvpp.acl.examples; + + +import static io.fd.jvpp.acl.examples.AclTestData.FIRST_RULE_ADDRESS_2_AS_ARRAY; +import static io.fd.jvpp.acl.examples.AclTestData.FIRST_RULE_ADDRESS_AS_ARRAY; +import static io.fd.jvpp.acl.examples.AclTestData.FIRST_RULE_DST_ICMP_TYPE_END; +import static io.fd.jvpp.acl.examples.AclTestData.FIRST_RULE_DST_ICMP_TYPE_START; +import static io.fd.jvpp.acl.examples.AclTestData.FIRST_RULE_MAC; +import static io.fd.jvpp.acl.examples.AclTestData.FIRST_RULE_MAC_MASK; +import static io.fd.jvpp.acl.examples.AclTestData.FIRST_RULE_PREFIX; +import static io.fd.jvpp.acl.examples.AclTestData.FIRST_RULE_PREFIX_2; +import static io.fd.jvpp.acl.examples.AclTestData.FIRST_RULE_SRC_ICMP_TYPE_END; +import static io.fd.jvpp.acl.examples.AclTestData.FIRST_RULE_SRC_ICMP_TYPE_START; +import static io.fd.jvpp.acl.examples.AclTestData.ICMP_PROTOCOL; +import static io.fd.jvpp.acl.examples.AclTestData.SECOND_RULE_ADDRESS_2_AS_ARRAY; +import static io.fd.jvpp.acl.examples.AclTestData.SECOND_RULE_ADDRESS_AS_ARRAY; +import static io.fd.jvpp.acl.examples.AclTestData.SECOND_RULE_DST_PORT_RANGE_END; +import static io.fd.jvpp.acl.examples.AclTestData.SECOND_RULE_DST_PORT_RANGE_START; +import static io.fd.jvpp.acl.examples.AclTestData.SECOND_RULE_MAC; +import static io.fd.jvpp.acl.examples.AclTestData.SECOND_RULE_MAC_MASK; +import static io.fd.jvpp.acl.examples.AclTestData.SECOND_RULE_PREFIX; +import static io.fd.jvpp.acl.examples.AclTestData.SECOND_RULE_PREFIX_2; +import static io.fd.jvpp.acl.examples.AclTestData.SECOND_RULE_SRC_PORT_RANGE_END; +import static io.fd.jvpp.acl.examples.AclTestData.SECOND_RULE_SRC_PORT_RANGE_START; +import static io.fd.jvpp.acl.examples.AclTestData.UDP_PROTOCOL; + +import io.fd.jvpp.acl.dto.AclDetails; +import io.fd.jvpp.acl.dto.AclInterfaceListDetails; +import io.fd.jvpp.acl.dto.MacipAclDetails; +import io.fd.jvpp.acl.types.AclRule; +import io.fd.jvpp.acl.types.MacipAclRule; +import java.util.Arrays; + +class AclExpectedDumpData { + + static void verifyMacIpDump(final MacipAclDetails macipAclDetails) { + // asserting data create by previous call + assertEquals(0, macipAclDetails.aclIndex); + assertEquals(2, macipAclDetails.count); + + final MacipAclRule currentIpv4Rule = macipAclDetails.r[0]; + final MacipAclRule currentIpv6Rule = macipAclDetails.r[1]; + + // Comparing one property at the time to better pointer if something is wrong + //Ipv4 rule + assertEquals(0, currentIpv4Rule.isIpv6); + assertEquals(1, currentIpv4Rule.isPermit); + + // cutting expected ipv4 to 4 bytes,vpp sends it as 16 always + assertArrays(FIRST_RULE_ADDRESS_AS_ARRAY, Arrays.copyOfRange(currentIpv4Rule.srcIpAddr, 0, 4)); + assertEquals(FIRST_RULE_PREFIX, currentIpv4Rule.srcIpPrefixLen); + assertArrays(FIRST_RULE_MAC, currentIpv4Rule.srcMac); + assertArrays(FIRST_RULE_MAC_MASK, currentIpv4Rule.srcMacMask); + + //Ipv6 rule + assertEquals(1, currentIpv6Rule.isIpv6); + assertEquals(0, currentIpv6Rule.isPermit); + assertArrays(SECOND_RULE_ADDRESS_AS_ARRAY, currentIpv6Rule.srcIpAddr); + assertEquals(SECOND_RULE_PREFIX, currentIpv6Rule.srcIpPrefixLen); + assertArrays(SECOND_RULE_MAC, currentIpv6Rule.srcMac); + assertArrays(SECOND_RULE_MAC_MASK, currentIpv6Rule.srcMacMask); + } + + static void verifyAclDump(final AclDetails aclDetails) { + assertEquals(0, aclDetails.aclIndex); + assertEquals(2, aclDetails.count); + + final AclRule currentIpv4Rule = aclDetails.r[0]; + final AclRule currentIpv6Rule = aclDetails.r[1]; + + // Comparing one property at the time to better pointer if something is wrong + //Ipv4 rule + assertEquals(0, currentIpv4Rule.isIpv6); + assertEquals(1, currentIpv4Rule.isPermit); + + // cutting expected ipv4 to 4 bytes,vpp sends it as 16 always + assertArrays(FIRST_RULE_ADDRESS_AS_ARRAY, Arrays.copyOfRange(currentIpv4Rule.srcIpAddr, 0, 4)); + assertEquals(FIRST_RULE_PREFIX, currentIpv4Rule.srcIpPrefixLen); + assertArrays(FIRST_RULE_ADDRESS_2_AS_ARRAY, Arrays.copyOfRange(currentIpv4Rule.dstIpAddr, 0, 4)); + assertEquals(FIRST_RULE_PREFIX_2, currentIpv4Rule.dstIpPrefixLen); + + assertEquals(ICMP_PROTOCOL, currentIpv4Rule.proto); + assertEquals(FIRST_RULE_SRC_ICMP_TYPE_START, currentIpv4Rule.srcportOrIcmptypeFirst); + assertEquals(FIRST_RULE_SRC_ICMP_TYPE_END, currentIpv4Rule.srcportOrIcmptypeLast); + assertEquals(FIRST_RULE_DST_ICMP_TYPE_START, currentIpv4Rule.dstportOrIcmpcodeFirst); + assertEquals(FIRST_RULE_DST_ICMP_TYPE_END, currentIpv4Rule.dstportOrIcmpcodeLast); + + assertArrays(SECOND_RULE_ADDRESS_AS_ARRAY, currentIpv6Rule.srcIpAddr); + assertEquals(SECOND_RULE_PREFIX, currentIpv6Rule.srcIpPrefixLen); + assertArrays(SECOND_RULE_ADDRESS_2_AS_ARRAY, currentIpv6Rule.dstIpAddr); + assertEquals(SECOND_RULE_PREFIX_2, currentIpv6Rule.dstIpPrefixLen); + + assertEquals(UDP_PROTOCOL, currentIpv6Rule.proto); + assertEquals(SECOND_RULE_SRC_PORT_RANGE_START, currentIpv6Rule.srcportOrIcmptypeFirst); + assertEquals(SECOND_RULE_SRC_PORT_RANGE_END, currentIpv6Rule.srcportOrIcmptypeLast); + assertEquals(SECOND_RULE_DST_PORT_RANGE_START, currentIpv6Rule.dstportOrIcmpcodeFirst); + assertEquals(SECOND_RULE_DST_PORT_RANGE_END, currentIpv6Rule.dstportOrIcmpcodeLast); + } + + static void verifyAclInterfaceList(final AclInterfaceListDetails aclInterfaceListDetails) { + assertEquals(1, aclInterfaceListDetails.count); + assertEquals(1, aclInterfaceListDetails.acls[0]); + assertEquals(0, aclInterfaceListDetails.nInput); + assertEquals(0, aclInterfaceListDetails.swIfIndex); + } + + private static void assertArrays(final byte[] expected, final byte[] actual) { + if (!Arrays.equals(expected, actual)) { + throw new IllegalArgumentException( + String.format("Expected[%s]/Actual[%s]", Arrays.toString(expected), Arrays.toString(actual))); + } + } + + private static void assertEquals(final int expected, final int actual) { + if (expected != actual) { + throw new IllegalArgumentException(String.format("Expected[%s]/Actual[%s]", expected, actual)); + } + } +} diff --git a/java/jvpp-acl/io/fd/jvpp/acl/examples/AclTestData.java b/java/jvpp-acl/io/fd/jvpp/acl/examples/AclTestData.java new file mode 100644 index 0000000..599d0ac --- /dev/null +++ b/java/jvpp-acl/io/fd/jvpp/acl/examples/AclTestData.java @@ -0,0 +1,101 @@ +/* + * 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 io.fd.jvpp.acl.examples; + + +import io.fd.jvpp.acl.types.AclRule; +import io.fd.jvpp.acl.types.MacipAclRule; + +class AclTestData { + + static final byte[] FIRST_RULE_ADDRESS_AS_ARRAY = {-64, -88, 2, 1}; + static final byte[] FIRST_RULE_ADDRESS_2_AS_ARRAY = {-64, -88, 2, 3}; + static final byte[] SECOND_RULE_ADDRESS_AS_ARRAY = + {32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1}; + static final byte[] SECOND_RULE_ADDRESS_2_AS_ARRAY = + {32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1}; + static final byte[] FIRST_RULE_MAC = {11, 11, 11, 11, 11, 11}; + static final byte[] FIRST_RULE_MAC_MASK = {0, 0, 0, 0, 0, 0}; + static final byte[] SECOND_RULE_MAC = {11, 12, 11, 11, 12, 11}; + static final byte[] SECOND_RULE_MAC_MASK = {(byte) 170, 0, 0, 0, 0, 0}; + static final int FIRST_RULE_PREFIX = 32; + static final int FIRST_RULE_PREFIX_2 = 24; + static final int SECOND_RULE_PREFIX = 64; + static final int SECOND_RULE_PREFIX_2 = 62; + static final int FIRST_RULE_DST_ICMP_TYPE_START = 0; + static final int FIRST_RULE_DST_ICMP_TYPE_END = 8; + static final int FIRST_RULE_SRC_ICMP_TYPE_START = 1; + static final int FIRST_RULE_SRC_ICMP_TYPE_END = 7; + static final int ICMP_PROTOCOL = 1; + static final int SECOND_RULE_DST_PORT_RANGE_START = 2000; + static final int SECOND_RULE_DST_PORT_RANGE_END = 6000; + static final int SECOND_RULE_SRC_PORT_RANGE_START = 400; + static final int SECOND_RULE_SRC_PORT_RANGE_END = 2047; + static final int UDP_PROTOCOL = 17; + + + static MacipAclRule[] createMacipRules() { + MacipAclRule ruleOne = new MacipAclRule(); + ruleOne.isIpv6 = 0; + ruleOne.isPermit = 1; + ruleOne.srcIpAddr = FIRST_RULE_ADDRESS_AS_ARRAY; + ruleOne.srcIpPrefixLen = FIRST_RULE_PREFIX; + ruleOne.srcMac = FIRST_RULE_MAC; + ruleOne.srcMacMask = FIRST_RULE_MAC_MASK;// no mask + + MacipAclRule ruleTwo = new MacipAclRule(); + ruleTwo.isIpv6 = 1; + ruleTwo.isPermit = 0; + ruleTwo.srcIpAddr = SECOND_RULE_ADDRESS_AS_ARRAY; + ruleTwo.srcIpPrefixLen = SECOND_RULE_PREFIX; + ruleTwo.srcMac = SECOND_RULE_MAC; + ruleTwo.srcMacMask = SECOND_RULE_MAC_MASK; + + return new MacipAclRule[]{ruleOne, ruleTwo}; + } + + static AclRule[] createAclRules() { + AclRule ruleOne = new AclRule(); + + ruleOne.isIpv6 = 0; + ruleOne.isPermit = 1; + ruleOne.srcIpAddr = FIRST_RULE_ADDRESS_AS_ARRAY; + ruleOne.srcIpPrefixLen = FIRST_RULE_PREFIX; + ruleOne.dstIpAddr = FIRST_RULE_ADDRESS_2_AS_ARRAY; + ruleOne.dstIpPrefixLen = FIRST_RULE_PREFIX_2; + ruleOne.dstportOrIcmpcodeFirst = FIRST_RULE_DST_ICMP_TYPE_START; + ruleOne.dstportOrIcmpcodeLast = FIRST_RULE_DST_ICMP_TYPE_END; + ruleOne.srcportOrIcmptypeFirst = FIRST_RULE_SRC_ICMP_TYPE_START; + ruleOne.srcportOrIcmptypeLast = FIRST_RULE_SRC_ICMP_TYPE_END; + ruleOne.proto = ICMP_PROTOCOL; //ICMP + + AclRule ruleTwo = new AclRule(); + ruleTwo.isIpv6 = 1; + ruleTwo.isPermit = 0; + ruleTwo.srcIpAddr = SECOND_RULE_ADDRESS_AS_ARRAY; + ruleTwo.srcIpPrefixLen = SECOND_RULE_PREFIX; + ruleTwo.dstIpAddr = SECOND_RULE_ADDRESS_2_AS_ARRAY; + ruleTwo.dstIpPrefixLen = SECOND_RULE_PREFIX_2; + ruleTwo.dstportOrIcmpcodeFirst = SECOND_RULE_DST_PORT_RANGE_START; + ruleTwo.dstportOrIcmpcodeLast = SECOND_RULE_DST_PORT_RANGE_END; + ruleTwo.srcportOrIcmptypeFirst = SECOND_RULE_SRC_PORT_RANGE_START; + ruleTwo.srcportOrIcmptypeLast = SECOND_RULE_SRC_PORT_RANGE_END; + ruleTwo.proto = UDP_PROTOCOL; //UDP + + return new AclRule[]{ruleOne, ruleTwo}; + } +} diff --git a/java/jvpp-acl/io/fd/jvpp/acl/examples/AclTestRequests.java b/java/jvpp-acl/io/fd/jvpp/acl/examples/AclTestRequests.java new file mode 100644 index 0000000..13c73c2 --- /dev/null +++ b/java/jvpp-acl/io/fd/jvpp/acl/examples/AclTestRequests.java @@ -0,0 +1,159 @@ +/* + * 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 io.fd.jvpp.acl.examples; + +import static io.fd.jvpp.acl.examples.AclTestData.createAclRules; +import static io.fd.jvpp.acl.examples.AclTestData.createMacipRules; + +import io.fd.jvpp.VppInvocationException; +import io.fd.jvpp.acl.dto.AclAddReplace; +import io.fd.jvpp.acl.dto.AclAddReplaceReply; +import io.fd.jvpp.acl.dto.AclDel; +import io.fd.jvpp.acl.dto.AclDelReply; +import io.fd.jvpp.acl.dto.AclDetailsReplyDump; +import io.fd.jvpp.acl.dto.AclDump; +import io.fd.jvpp.acl.dto.AclInterfaceListDetailsReplyDump; +import io.fd.jvpp.acl.dto.AclInterfaceListDump; +import io.fd.jvpp.acl.dto.AclInterfaceSetAclList; +import io.fd.jvpp.acl.dto.AclInterfaceSetAclListReply; +import io.fd.jvpp.acl.dto.MacipAclAdd; +import io.fd.jvpp.acl.dto.MacipAclAddReply; +import io.fd.jvpp.acl.dto.MacipAclAddReplace; +import io.fd.jvpp.acl.dto.MacipAclAddReplaceReply; +import io.fd.jvpp.acl.dto.MacipAclDel; +import io.fd.jvpp.acl.dto.MacipAclDelReply; +import io.fd.jvpp.acl.dto.MacipAclDetailsReplyDump; +import io.fd.jvpp.acl.dto.MacipAclDump; +import io.fd.jvpp.acl.future.FutureJVppAclFacade; +import java.util.concurrent.ExecutionException; + +class AclTestRequests { + + static MacipAclDetailsReplyDump sendMacIpDumpRequest(final FutureJVppAclFacade jvpp) + throws ExecutionException, InterruptedException { + System.out.println("Sending MacipAclDump request..."); + MacipAclDetailsReplyDump dump = jvpp.macipAclDump(new MacipAclDump()).toCompletableFuture().get(); + System.out.println("MacipAclDump returned"); + return dump; + } + + static void sendMacIpAddRequest(final FutureJVppAclFacade jvpp) throws InterruptedException, ExecutionException { + final MacipAclAdd request = createMacIpAddRequest(); + System.out.printf("Sending MacipAclAdd request %s%n", request.toString()); + final MacipAclAddReply reply = jvpp.macipAclAdd(createMacIpAddRequest()).toCompletableFuture().get(); + System.out.printf("MacipAclAdd send result = %s%n", reply); + } + + static void sendMacIpAddReplaceRequest(final FutureJVppAclFacade jvpp) throws InterruptedException, ExecutionException { + final MacipAclAddReplace request = createMacIpAddReplaceRequest(); + System.out.printf("Sending MacipAclAddReplace request %s%n", request.toString()); + final MacipAclAddReplaceReply reply = jvpp.macipAclAddReplace(createMacIpAddReplaceRequest()).toCompletableFuture().get(); + System.out.printf("MacipAclAddReplace send result = %s%n", reply); + } + + static void sendMacIpDelRequest(final FutureJVppAclFacade jvpp) throws InterruptedException, ExecutionException { + final MacipAclDel request = new MacipAclDel(); + request.aclIndex = 0; + System.out.printf("Sending MacipAclDel request %s%n", request.toString()); + final MacipAclDelReply reply = jvpp.macipAclDel(request).toCompletableFuture().get(); + System.out.printf("MacipAclDel send result = %s%n", reply); + } + + static void sendAclAddRequest(final FutureJVppAclFacade jvpp) throws InterruptedException, ExecutionException { + final AclAddReplace request = createAclAddRequest(); + System.out.printf("Sending AclAddReplace request %s%n", request.toString()); + final AclAddReplaceReply reply = jvpp.aclAddReplace(request).toCompletableFuture().get(); + System.out.printf("AclAddReplace send result = %s%n", reply); + } + + static AclDetailsReplyDump sendAclDumpRequest(final FutureJVppAclFacade jvpp) + throws InterruptedException, VppInvocationException, ExecutionException { + System.out.println("Sending AclDump request..."); + final AclDetailsReplyDump dump = jvpp.aclDump(new AclDump()).toCompletableFuture().get(); + System.out.printf("AclDump send result = %s%n", dump); + return dump; + } + + static void sendAclDelRequest(final FutureJVppAclFacade jvpp) throws InterruptedException, ExecutionException { + final AclDel request = new AclDel(); + request.aclIndex = 0; + System.out.printf("Sending AclDel request %s%n", request.toString()); + final AclDelReply reply = jvpp.aclDel(request).toCompletableFuture().get(); + System.out.printf("AclDel send result = %s%n", reply); + } + + static AclInterfaceListDetailsReplyDump sendAclInterfaceListDumpRequest(final FutureJVppAclFacade jvpp) + throws InterruptedException, ExecutionException { + final AclInterfaceListDump request = new AclInterfaceListDump(); + request.swIfIndex = 0; + System.out.printf("Sending AclInterfaceListDump request %s%n", request.toString()); + final AclInterfaceListDetailsReplyDump dump = jvpp.aclInterfaceListDump(request).toCompletableFuture().get(); + System.out.printf("AclInterfaceListDump send result = %s%n", dump); + return dump; + } + + static void sendAclInterfaceSetAclList(final FutureJVppAclFacade jvpp) + throws InterruptedException, ExecutionException { + final AclInterfaceSetAclList request = new AclInterfaceSetAclList(); + request.count = 1; + request.acls = new int[]{1}; + request.swIfIndex = 0; + request.nInput = 0; + System.out.printf("Sending AclInterfaceSetAclList request %s%n", request.toString()); + final AclInterfaceSetAclListReply reply = jvpp.aclInterfaceSetAclList(request).toCompletableFuture().get(); + System.out.printf("AclInterfaceSetAclList send result = %s%n", reply); + } + + static void sendAclInterfaceDeleteList(final FutureJVppAclFacade jvpp) + throws InterruptedException, ExecutionException { + // uses same api but sets list to empty + final AclInterfaceSetAclList request = new AclInterfaceSetAclList(); + request.count = 0; + request.acls = new int[]{}; + request.swIfIndex = 0; + request.nInput = 0; + System.out.printf("Sending AclInterfaceSetAclList(Delete) request %s%n", request.toString()); + final AclInterfaceSetAclListReply reply = jvpp.aclInterfaceSetAclList(request).toCompletableFuture().get(); + System.out.printf("AclInterfaceSetAclList(Delete) send result = %s%n", reply); + } + + private static MacipAclAdd createMacIpAddRequest() { + MacipAclAdd request = new MacipAclAdd(); + + request.count = 2; + request.r = createMacipRules(); + return request; + } + + private static MacipAclAddReplace createMacIpAddReplaceRequest() { + MacipAclAddReplace request = new MacipAclAddReplace(); + + request.count = 2; + request.aclIndex = 0; + request.r = createMacipRules(); + return request; + } + + private static AclAddReplace createAclAddRequest() { + AclAddReplace request = new AclAddReplace(); + + request.aclIndex = -1;// to define new one + request.count = 2; + request.r = createAclRules(); + return request; + } +} diff --git a/java/jvpp-acl/io/fd/jvpp/acl/examples/FutureApiExample.java b/java/jvpp-acl/io/fd/jvpp/acl/examples/FutureApiExample.java new file mode 100644 index 0000000..144d839 --- /dev/null +++ b/java/jvpp-acl/io/fd/jvpp/acl/examples/FutureApiExample.java @@ -0,0 +1,68 @@ +/* + * 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 io.fd.jvpp.acl.examples; + +import static io.fd.jvpp.acl.examples.AclExpectedDumpData.verifyAclDump; +import static io.fd.jvpp.acl.examples.AclExpectedDumpData.verifyAclInterfaceList; +import static io.fd.jvpp.acl.examples.AclExpectedDumpData.verifyMacIpDump; +import static io.fd.jvpp.acl.examples.AclTestRequests.sendAclAddRequest; +import static io.fd.jvpp.acl.examples.AclTestRequests.sendAclDelRequest; +import static io.fd.jvpp.acl.examples.AclTestRequests.sendAclDumpRequest; +import static io.fd.jvpp.acl.examples.AclTestRequests.sendAclInterfaceDeleteList; +import static io.fd.jvpp.acl.examples.AclTestRequests.sendAclInterfaceListDumpRequest; +import static io.fd.jvpp.acl.examples.AclTestRequests.sendAclInterfaceSetAclList; +import static io.fd.jvpp.acl.examples.AclTestRequests.sendMacIpAddRequest; +import static io.fd.jvpp.acl.examples.AclTestRequests.sendMacIpDelRequest; +import static io.fd.jvpp.acl.examples.AclTestRequests.sendMacIpDumpRequest; + +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.JVppRegistryImpl; +import io.fd.jvpp.acl.JVppAclImpl; +import io.fd.jvpp.acl.future.FutureJVppAclFacade; + +public class FutureApiExample { + + public static void main(String[] args) throws Exception { + testCallbackApi(); + } + + private static void testCallbackApi() throws Exception { + System.out.println("Testing Java callback API for acl plugin"); + try (final JVppRegistry registry = new JVppRegistryImpl("macipAclAddTest"); + final FutureJVppAclFacade jvpp = new FutureJVppAclFacade(registry, new JVppAclImpl())) { + + // adds,dump and verifies Mac-Ip acl + sendMacIpAddRequest(jvpp); + verifyMacIpDump(sendMacIpDumpRequest(jvpp).macipAclDetails.get(0)); + + // adds,dumps and verifies Acl acl + sendAclAddRequest(jvpp); + verifyAclDump(sendAclDumpRequest(jvpp).aclDetails.get(0)); + + // adds,dumps and verifies Interface for acl + sendAclInterfaceSetAclList(jvpp); + verifyAclInterfaceList(sendAclInterfaceListDumpRequest(jvpp).aclInterfaceListDetails.get(0)); + + // deletes all created data + sendAclInterfaceDeleteList(jvpp); + sendAclDelRequest(jvpp); + sendMacIpDelRequest(jvpp); + + System.out.println("Disconnecting..."); + } + } +} diff --git a/java/jvpp-acl/io/fd/jvpp/acl/examples/Readme.txt b/java/jvpp-acl/io/fd/jvpp/acl/examples/Readme.txt new file mode 100644 index 0000000..e47b027 --- /dev/null +++ b/java/jvpp-acl/io/fd/jvpp/acl/examples/Readme.txt @@ -0,0 +1,4 @@ +release version: +sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp-native/vpp/vpp-api/java/jvpp-acl-17.10.jar io.fd.jvpp.acl.examples.FutureApiExample +debug version: +sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp-debug-native/vpp/vpp-api/java/jvpp-acl-17.10.jar io.fd.jvpp.acl.examples.FutureApiExample diff --git a/java/jvpp-acl/io/fd/jvpp/acl/test/CallbackApiTest.java b/java/jvpp-acl/io/fd/jvpp/acl/test/CallbackApiTest.java new file mode 100644 index 0000000..5e451e2 --- /dev/null +++ b/java/jvpp-acl/io/fd/jvpp/acl/test/CallbackApiTest.java @@ -0,0 +1,33 @@ +/* + * 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 io.fd.jvpp.acl.test; + +import io.fd.jvpp.AbstractCallbackApiTest; +import io.fd.jvpp.acl.JVppAclImpl; + +import java.util.logging.Logger; + +public class CallbackApiTest extends AbstractCallbackApiTest { + + private static Logger LOG = Logger.getLogger(CallbackApiTest.class.getName()); + + + public static void main(String[] args) throws Exception { + LOG.info("Testing ControlPing using Java callback API for core plugin"); + testControlPing(args[0], new JVppAclImpl()); + } +} diff --git a/java/jvpp-acl/io/fd/jvpp/acl/test/FutureApiTest.java b/java/jvpp-acl/io/fd/jvpp/acl/test/FutureApiTest.java new file mode 100644 index 0000000..7bba3fc --- /dev/null +++ b/java/jvpp-acl/io/fd/jvpp/acl/test/FutureApiTest.java @@ -0,0 +1,62 @@ +/* + * 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 io.fd.jvpp.acl.test; + +import io.fd.jvpp.Assertions; +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.JVppRegistryImpl; +import io.fd.jvpp.acl.JVppAclImpl; +import io.fd.jvpp.acl.dto.AclDetailsReplyDump; +import io.fd.jvpp.acl.dto.AclDump; +import io.fd.jvpp.acl.future.FutureJVppAclFacade; + +import java.util.concurrent.CompletableFuture; +import java.util.logging.Logger; + +public class FutureApiTest { + + private static final Logger LOG = Logger.getLogger(FutureApiTest.class.getName()); + + public static void main(String[] args) throws Exception { + testFutureApi(args); + } + + private static void testFutureApi(String[] args) throws Exception { + LOG.info("Testing Java future API for core plugin"); + try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiTest", args[0]); + final FutureJVppAclFacade jvppFacade = new FutureJVppAclFacade(registry, new JVppAclImpl())) { + LOG.info("Successfully connected to VPP"); + + testAclDump(jvppFacade); + + LOG.info("Disconnecting..."); + } + } + + private static void testAclDump(final FutureJVppAclFacade jvpp) throws Exception { + LOG.info("Sending AclDump request..."); + final AclDump request = new AclDump(); + + final CompletableFuture + replyFuture = jvpp.aclDump(request).toCompletableFuture(); + final AclDetailsReplyDump reply = replyFuture.get(); + + Assertions.assertNotNull(reply); + } + + +} diff --git a/java/jvpp-acl/io/fd/jvpp/acl/test/Readme.txt b/java/jvpp-acl/io/fd/jvpp/acl/test/Readme.txt new file mode 100644 index 0000000..ad8757f --- /dev/null +++ b/java/jvpp-acl/io/fd/jvpp/acl/test/Readme.txt @@ -0,0 +1,4 @@ +release version: +sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp-native/vpp/vpp-api/java/jvpp-acl-17.10.jar io.fd.jvpp.acl.test.[test-name] +debug version: +sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-acl-17.10.jar io.fd.jvpp.acl.test.[test-name] diff --git a/java/jvpp-acl/io/fd/vpp/jvpp/acl/examples/AclExpectedDumpData.java b/java/jvpp-acl/io/fd/vpp/jvpp/acl/examples/AclExpectedDumpData.java deleted file mode 100644 index 4806052..0000000 --- a/java/jvpp-acl/io/fd/vpp/jvpp/acl/examples/AclExpectedDumpData.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.acl.examples; - - -import static io.fd.vpp.jvpp.acl.examples.AclTestData.FIRST_RULE_ADDRESS_2_AS_ARRAY; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.FIRST_RULE_ADDRESS_AS_ARRAY; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.FIRST_RULE_DST_ICMP_TYPE_END; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.FIRST_RULE_DST_ICMP_TYPE_START; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.FIRST_RULE_MAC; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.FIRST_RULE_MAC_MASK; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.FIRST_RULE_PREFIX; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.FIRST_RULE_PREFIX_2; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.FIRST_RULE_SRC_ICMP_TYPE_END; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.FIRST_RULE_SRC_ICMP_TYPE_START; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.ICMP_PROTOCOL; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.SECOND_RULE_ADDRESS_2_AS_ARRAY; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.SECOND_RULE_ADDRESS_AS_ARRAY; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.SECOND_RULE_DST_PORT_RANGE_END; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.SECOND_RULE_DST_PORT_RANGE_START; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.SECOND_RULE_MAC; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.SECOND_RULE_MAC_MASK; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.SECOND_RULE_PREFIX; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.SECOND_RULE_PREFIX_2; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.SECOND_RULE_SRC_PORT_RANGE_END; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.SECOND_RULE_SRC_PORT_RANGE_START; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.UDP_PROTOCOL; - -import io.fd.vpp.jvpp.acl.dto.AclDetails; -import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetails; -import io.fd.vpp.jvpp.acl.dto.MacipAclDetails; -import io.fd.vpp.jvpp.acl.types.AclRule; -import io.fd.vpp.jvpp.acl.types.MacipAclRule; -import java.util.Arrays; - -class AclExpectedDumpData { - - static void verifyMacIpDump(final MacipAclDetails macipAclDetails) { - // asserting data create by previous call - assertEquals(0, macipAclDetails.aclIndex); - assertEquals(2, macipAclDetails.count); - - final MacipAclRule currentIpv4Rule = macipAclDetails.r[0]; - final MacipAclRule currentIpv6Rule = macipAclDetails.r[1]; - - // Comparing one property at the time to better pointer if something is wrong - //Ipv4 rule - assertEquals(0, currentIpv4Rule.isIpv6); - assertEquals(1, currentIpv4Rule.isPermit); - - // cutting expected ipv4 to 4 bytes,vpp sends it as 16 always - assertArrays(FIRST_RULE_ADDRESS_AS_ARRAY, Arrays.copyOfRange(currentIpv4Rule.srcIpAddr, 0, 4)); - assertEquals(FIRST_RULE_PREFIX, currentIpv4Rule.srcIpPrefixLen); - assertArrays(FIRST_RULE_MAC, currentIpv4Rule.srcMac); - assertArrays(FIRST_RULE_MAC_MASK, currentIpv4Rule.srcMacMask); - - //Ipv6 rule - assertEquals(1, currentIpv6Rule.isIpv6); - assertEquals(0, currentIpv6Rule.isPermit); - assertArrays(SECOND_RULE_ADDRESS_AS_ARRAY, currentIpv6Rule.srcIpAddr); - assertEquals(SECOND_RULE_PREFIX, currentIpv6Rule.srcIpPrefixLen); - assertArrays(SECOND_RULE_MAC, currentIpv6Rule.srcMac); - assertArrays(SECOND_RULE_MAC_MASK, currentIpv6Rule.srcMacMask); - } - - static void verifyAclDump(final AclDetails aclDetails) { - assertEquals(0, aclDetails.aclIndex); - assertEquals(2, aclDetails.count); - - final AclRule currentIpv4Rule = aclDetails.r[0]; - final AclRule currentIpv6Rule = aclDetails.r[1]; - - // Comparing one property at the time to better pointer if something is wrong - //Ipv4 rule - assertEquals(0, currentIpv4Rule.isIpv6); - assertEquals(1, currentIpv4Rule.isPermit); - - // cutting expected ipv4 to 4 bytes,vpp sends it as 16 always - assertArrays(FIRST_RULE_ADDRESS_AS_ARRAY, Arrays.copyOfRange(currentIpv4Rule.srcIpAddr, 0, 4)); - assertEquals(FIRST_RULE_PREFIX, currentIpv4Rule.srcIpPrefixLen); - assertArrays(FIRST_RULE_ADDRESS_2_AS_ARRAY, Arrays.copyOfRange(currentIpv4Rule.dstIpAddr, 0, 4)); - assertEquals(FIRST_RULE_PREFIX_2, currentIpv4Rule.dstIpPrefixLen); - - assertEquals(ICMP_PROTOCOL, currentIpv4Rule.proto); - assertEquals(FIRST_RULE_SRC_ICMP_TYPE_START, currentIpv4Rule.srcportOrIcmptypeFirst); - assertEquals(FIRST_RULE_SRC_ICMP_TYPE_END, currentIpv4Rule.srcportOrIcmptypeLast); - assertEquals(FIRST_RULE_DST_ICMP_TYPE_START, currentIpv4Rule.dstportOrIcmpcodeFirst); - assertEquals(FIRST_RULE_DST_ICMP_TYPE_END, currentIpv4Rule.dstportOrIcmpcodeLast); - - assertArrays(SECOND_RULE_ADDRESS_AS_ARRAY, currentIpv6Rule.srcIpAddr); - assertEquals(SECOND_RULE_PREFIX, currentIpv6Rule.srcIpPrefixLen); - assertArrays(SECOND_RULE_ADDRESS_2_AS_ARRAY, currentIpv6Rule.dstIpAddr); - assertEquals(SECOND_RULE_PREFIX_2, currentIpv6Rule.dstIpPrefixLen); - - assertEquals(UDP_PROTOCOL, currentIpv6Rule.proto); - assertEquals(SECOND_RULE_SRC_PORT_RANGE_START, currentIpv6Rule.srcportOrIcmptypeFirst); - assertEquals(SECOND_RULE_SRC_PORT_RANGE_END, currentIpv6Rule.srcportOrIcmptypeLast); - assertEquals(SECOND_RULE_DST_PORT_RANGE_START, currentIpv6Rule.dstportOrIcmpcodeFirst); - assertEquals(SECOND_RULE_DST_PORT_RANGE_END, currentIpv6Rule.dstportOrIcmpcodeLast); - } - - static void verifyAclInterfaceList(final AclInterfaceListDetails aclInterfaceListDetails) { - assertEquals(1, aclInterfaceListDetails.count); - assertEquals(1, aclInterfaceListDetails.acls[0]); - assertEquals(0, aclInterfaceListDetails.nInput); - assertEquals(0, aclInterfaceListDetails.swIfIndex); - } - - private static void assertArrays(final byte[] expected, final byte[] actual) { - if (!Arrays.equals(expected, actual)) { - throw new IllegalArgumentException( - String.format("Expected[%s]/Actual[%s]", Arrays.toString(expected), Arrays.toString(actual))); - } - } - - private static void assertEquals(final int expected, final int actual) { - if (expected != actual) { - throw new IllegalArgumentException(String.format("Expected[%s]/Actual[%s]", expected, actual)); - } - } -} diff --git a/java/jvpp-acl/io/fd/vpp/jvpp/acl/examples/AclTestData.java b/java/jvpp-acl/io/fd/vpp/jvpp/acl/examples/AclTestData.java deleted file mode 100644 index 199b1b6..0000000 --- a/java/jvpp-acl/io/fd/vpp/jvpp/acl/examples/AclTestData.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.acl.examples; - - -import io.fd.vpp.jvpp.acl.types.AclRule; -import io.fd.vpp.jvpp.acl.types.MacipAclRule; - -class AclTestData { - - static final byte[] FIRST_RULE_ADDRESS_AS_ARRAY = {-64, -88, 2, 1}; - static final byte[] FIRST_RULE_ADDRESS_2_AS_ARRAY = {-64, -88, 2, 3}; - static final byte[] SECOND_RULE_ADDRESS_AS_ARRAY = - {32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1}; - static final byte[] SECOND_RULE_ADDRESS_2_AS_ARRAY = - {32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1}; - static final byte[] FIRST_RULE_MAC = {11, 11, 11, 11, 11, 11}; - static final byte[] FIRST_RULE_MAC_MASK = {0, 0, 0, 0, 0, 0}; - static final byte[] SECOND_RULE_MAC = {11, 12, 11, 11, 12, 11}; - static final byte[] SECOND_RULE_MAC_MASK = {(byte) 170, 0, 0, 0, 0, 0}; - static final int FIRST_RULE_PREFIX = 32; - static final int FIRST_RULE_PREFIX_2 = 24; - static final int SECOND_RULE_PREFIX = 64; - static final int SECOND_RULE_PREFIX_2 = 62; - static final int FIRST_RULE_DST_ICMP_TYPE_START = 0; - static final int FIRST_RULE_DST_ICMP_TYPE_END = 8; - static final int FIRST_RULE_SRC_ICMP_TYPE_START = 1; - static final int FIRST_RULE_SRC_ICMP_TYPE_END = 7; - static final int ICMP_PROTOCOL = 1; - static final int SECOND_RULE_DST_PORT_RANGE_START = 2000; - static final int SECOND_RULE_DST_PORT_RANGE_END = 6000; - static final int SECOND_RULE_SRC_PORT_RANGE_START = 400; - static final int SECOND_RULE_SRC_PORT_RANGE_END = 2047; - static final int UDP_PROTOCOL = 17; - - - static MacipAclRule[] createMacipRules() { - MacipAclRule ruleOne = new MacipAclRule(); - ruleOne.isIpv6 = 0; - ruleOne.isPermit = 1; - ruleOne.srcIpAddr = FIRST_RULE_ADDRESS_AS_ARRAY; - ruleOne.srcIpPrefixLen = FIRST_RULE_PREFIX; - ruleOne.srcMac = FIRST_RULE_MAC; - ruleOne.srcMacMask = FIRST_RULE_MAC_MASK;// no mask - - MacipAclRule ruleTwo = new MacipAclRule(); - ruleTwo.isIpv6 = 1; - ruleTwo.isPermit = 0; - ruleTwo.srcIpAddr = SECOND_RULE_ADDRESS_AS_ARRAY; - ruleTwo.srcIpPrefixLen = SECOND_RULE_PREFIX; - ruleTwo.srcMac = SECOND_RULE_MAC; - ruleTwo.srcMacMask = SECOND_RULE_MAC_MASK; - - return new MacipAclRule[]{ruleOne, ruleTwo}; - } - - static AclRule[] createAclRules() { - AclRule ruleOne = new AclRule(); - - ruleOne.isIpv6 = 0; - ruleOne.isPermit = 1; - ruleOne.srcIpAddr = FIRST_RULE_ADDRESS_AS_ARRAY; - ruleOne.srcIpPrefixLen = FIRST_RULE_PREFIX; - ruleOne.dstIpAddr = FIRST_RULE_ADDRESS_2_AS_ARRAY; - ruleOne.dstIpPrefixLen = FIRST_RULE_PREFIX_2; - ruleOne.dstportOrIcmpcodeFirst = FIRST_RULE_DST_ICMP_TYPE_START; - ruleOne.dstportOrIcmpcodeLast = FIRST_RULE_DST_ICMP_TYPE_END; - ruleOne.srcportOrIcmptypeFirst = FIRST_RULE_SRC_ICMP_TYPE_START; - ruleOne.srcportOrIcmptypeLast = FIRST_RULE_SRC_ICMP_TYPE_END; - ruleOne.proto = ICMP_PROTOCOL; //ICMP - - AclRule ruleTwo = new AclRule(); - ruleTwo.isIpv6 = 1; - ruleTwo.isPermit = 0; - ruleTwo.srcIpAddr = SECOND_RULE_ADDRESS_AS_ARRAY; - ruleTwo.srcIpPrefixLen = SECOND_RULE_PREFIX; - ruleTwo.dstIpAddr = SECOND_RULE_ADDRESS_2_AS_ARRAY; - ruleTwo.dstIpPrefixLen = SECOND_RULE_PREFIX_2; - ruleTwo.dstportOrIcmpcodeFirst = SECOND_RULE_DST_PORT_RANGE_START; - ruleTwo.dstportOrIcmpcodeLast = SECOND_RULE_DST_PORT_RANGE_END; - ruleTwo.srcportOrIcmptypeFirst = SECOND_RULE_SRC_PORT_RANGE_START; - ruleTwo.srcportOrIcmptypeLast = SECOND_RULE_SRC_PORT_RANGE_END; - ruleTwo.proto = UDP_PROTOCOL; //UDP - - return new AclRule[]{ruleOne, ruleTwo}; - } -} diff --git a/java/jvpp-acl/io/fd/vpp/jvpp/acl/examples/AclTestRequests.java b/java/jvpp-acl/io/fd/vpp/jvpp/acl/examples/AclTestRequests.java deleted file mode 100644 index 149ea46..0000000 --- a/java/jvpp-acl/io/fd/vpp/jvpp/acl/examples/AclTestRequests.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.acl.examples; - -import static io.fd.vpp.jvpp.acl.examples.AclTestData.createAclRules; -import static io.fd.vpp.jvpp.acl.examples.AclTestData.createMacipRules; - -import io.fd.vpp.jvpp.VppInvocationException; -import io.fd.vpp.jvpp.acl.dto.AclAddReplace; -import io.fd.vpp.jvpp.acl.dto.AclAddReplaceReply; -import io.fd.vpp.jvpp.acl.dto.AclDel; -import io.fd.vpp.jvpp.acl.dto.AclDelReply; -import io.fd.vpp.jvpp.acl.dto.AclDetailsReplyDump; -import io.fd.vpp.jvpp.acl.dto.AclDump; -import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetailsReplyDump; -import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDump; -import io.fd.vpp.jvpp.acl.dto.AclInterfaceSetAclList; -import io.fd.vpp.jvpp.acl.dto.AclInterfaceSetAclListReply; -import io.fd.vpp.jvpp.acl.dto.MacipAclAdd; -import io.fd.vpp.jvpp.acl.dto.MacipAclAddReply; -import io.fd.vpp.jvpp.acl.dto.MacipAclAddReplace; -import io.fd.vpp.jvpp.acl.dto.MacipAclAddReplaceReply; -import io.fd.vpp.jvpp.acl.dto.MacipAclDel; -import io.fd.vpp.jvpp.acl.dto.MacipAclDelReply; -import io.fd.vpp.jvpp.acl.dto.MacipAclDetailsReplyDump; -import io.fd.vpp.jvpp.acl.dto.MacipAclDump; -import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; -import java.util.concurrent.ExecutionException; - -class AclTestRequests { - - static MacipAclDetailsReplyDump sendMacIpDumpRequest(final FutureJVppAclFacade jvpp) - throws ExecutionException, InterruptedException { - System.out.println("Sending MacipAclDump request..."); - MacipAclDetailsReplyDump dump = jvpp.macipAclDump(new MacipAclDump()).toCompletableFuture().get(); - System.out.println("MacipAclDump returned"); - return dump; - } - - static void sendMacIpAddRequest(final FutureJVppAclFacade jvpp) throws InterruptedException, ExecutionException { - final MacipAclAdd request = createMacIpAddRequest(); - System.out.printf("Sending MacipAclAdd request %s%n", request.toString()); - final MacipAclAddReply reply = jvpp.macipAclAdd(createMacIpAddRequest()).toCompletableFuture().get(); - System.out.printf("MacipAclAdd send result = %s%n", reply); - } - - static void sendMacIpAddReplaceRequest(final FutureJVppAclFacade jvpp) throws InterruptedException, ExecutionException { - final MacipAclAddReplace request = createMacIpAddReplaceRequest(); - System.out.printf("Sending MacipAclAddReplace request %s%n", request.toString()); - final MacipAclAddReplaceReply reply = jvpp.macipAclAddReplace(createMacIpAddReplaceRequest()).toCompletableFuture().get(); - System.out.printf("MacipAclAddReplace send result = %s%n", reply); - } - - static void sendMacIpDelRequest(final FutureJVppAclFacade jvpp) throws InterruptedException, ExecutionException { - final MacipAclDel request = new MacipAclDel(); - request.aclIndex = 0; - System.out.printf("Sending MacipAclDel request %s%n", request.toString()); - final MacipAclDelReply reply = jvpp.macipAclDel(request).toCompletableFuture().get(); - System.out.printf("MacipAclDel send result = %s%n", reply); - } - - static void sendAclAddRequest(final FutureJVppAclFacade jvpp) throws InterruptedException, ExecutionException { - final AclAddReplace request = createAclAddRequest(); - System.out.printf("Sending AclAddReplace request %s%n", request.toString()); - final AclAddReplaceReply reply = jvpp.aclAddReplace(request).toCompletableFuture().get(); - System.out.printf("AclAddReplace send result = %s%n", reply); - } - - static AclDetailsReplyDump sendAclDumpRequest(final FutureJVppAclFacade jvpp) - throws InterruptedException, VppInvocationException, ExecutionException { - System.out.println("Sending AclDump request..."); - final AclDetailsReplyDump dump = jvpp.aclDump(new AclDump()).toCompletableFuture().get(); - System.out.printf("AclDump send result = %s%n", dump); - return dump; - } - - static void sendAclDelRequest(final FutureJVppAclFacade jvpp) throws InterruptedException, ExecutionException { - final AclDel request = new AclDel(); - request.aclIndex = 0; - System.out.printf("Sending AclDel request %s%n", request.toString()); - final AclDelReply reply = jvpp.aclDel(request).toCompletableFuture().get(); - System.out.printf("AclDel send result = %s%n", reply); - } - - static AclInterfaceListDetailsReplyDump sendAclInterfaceListDumpRequest(final FutureJVppAclFacade jvpp) - throws InterruptedException, ExecutionException { - final AclInterfaceListDump request = new AclInterfaceListDump(); - request.swIfIndex = 0; - System.out.printf("Sending AclInterfaceListDump request %s%n", request.toString()); - final AclInterfaceListDetailsReplyDump dump = jvpp.aclInterfaceListDump(request).toCompletableFuture().get(); - System.out.printf("AclInterfaceListDump send result = %s%n", dump); - return dump; - } - - static void sendAclInterfaceSetAclList(final FutureJVppAclFacade jvpp) - throws InterruptedException, ExecutionException { - final AclInterfaceSetAclList request = new AclInterfaceSetAclList(); - request.count = 1; - request.acls = new int[]{1}; - request.swIfIndex = 0; - request.nInput = 0; - System.out.printf("Sending AclInterfaceSetAclList request %s%n", request.toString()); - final AclInterfaceSetAclListReply reply = jvpp.aclInterfaceSetAclList(request).toCompletableFuture().get(); - System.out.printf("AclInterfaceSetAclList send result = %s%n", reply); - } - - static void sendAclInterfaceDeleteList(final FutureJVppAclFacade jvpp) - throws InterruptedException, ExecutionException { - // uses same api but sets list to empty - final AclInterfaceSetAclList request = new AclInterfaceSetAclList(); - request.count = 0; - request.acls = new int[]{}; - request.swIfIndex = 0; - request.nInput = 0; - System.out.printf("Sending AclInterfaceSetAclList(Delete) request %s%n", request.toString()); - final AclInterfaceSetAclListReply reply = jvpp.aclInterfaceSetAclList(request).toCompletableFuture().get(); - System.out.printf("AclInterfaceSetAclList(Delete) send result = %s%n", reply); - } - - private static MacipAclAdd createMacIpAddRequest() { - MacipAclAdd request = new MacipAclAdd(); - - request.count = 2; - request.r = createMacipRules(); - return request; - } - - private static MacipAclAddReplace createMacIpAddReplaceRequest() { - MacipAclAddReplace request = new MacipAclAddReplace(); - - request.count = 2; - request.aclIndex = 0; - request.r = createMacipRules(); - return request; - } - - private static AclAddReplace createAclAddRequest() { - AclAddReplace request = new AclAddReplace(); - - request.aclIndex = -1;// to define new one - request.count = 2; - request.r = createAclRules(); - return request; - } -} diff --git a/java/jvpp-acl/io/fd/vpp/jvpp/acl/examples/FutureApiExample.java b/java/jvpp-acl/io/fd/vpp/jvpp/acl/examples/FutureApiExample.java deleted file mode 100644 index 862df8d..0000000 --- a/java/jvpp-acl/io/fd/vpp/jvpp/acl/examples/FutureApiExample.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.acl.examples; - -import static io.fd.vpp.jvpp.acl.examples.AclExpectedDumpData.verifyAclDump; -import static io.fd.vpp.jvpp.acl.examples.AclExpectedDumpData.verifyAclInterfaceList; -import static io.fd.vpp.jvpp.acl.examples.AclExpectedDumpData.verifyMacIpDump; -import static io.fd.vpp.jvpp.acl.examples.AclTestRequests.sendAclAddRequest; -import static io.fd.vpp.jvpp.acl.examples.AclTestRequests.sendAclDelRequest; -import static io.fd.vpp.jvpp.acl.examples.AclTestRequests.sendAclDumpRequest; -import static io.fd.vpp.jvpp.acl.examples.AclTestRequests.sendAclInterfaceDeleteList; -import static io.fd.vpp.jvpp.acl.examples.AclTestRequests.sendAclInterfaceListDumpRequest; -import static io.fd.vpp.jvpp.acl.examples.AclTestRequests.sendAclInterfaceSetAclList; -import static io.fd.vpp.jvpp.acl.examples.AclTestRequests.sendMacIpAddRequest; -import static io.fd.vpp.jvpp.acl.examples.AclTestRequests.sendMacIpDelRequest; -import static io.fd.vpp.jvpp.acl.examples.AclTestRequests.sendMacIpDumpRequest; - -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.JVppRegistryImpl; -import io.fd.vpp.jvpp.acl.JVppAclImpl; -import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; - -public class FutureApiExample { - - public static void main(String[] args) throws Exception { - testCallbackApi(); - } - - private static void testCallbackApi() throws Exception { - System.out.println("Testing Java callback API for acl plugin"); - try (final JVppRegistry registry = new JVppRegistryImpl("macipAclAddTest"); - final FutureJVppAclFacade jvpp = new FutureJVppAclFacade(registry, new JVppAclImpl())) { - - // adds,dump and verifies Mac-Ip acl - sendMacIpAddRequest(jvpp); - verifyMacIpDump(sendMacIpDumpRequest(jvpp).macipAclDetails.get(0)); - - // adds,dumps and verifies Acl acl - sendAclAddRequest(jvpp); - verifyAclDump(sendAclDumpRequest(jvpp).aclDetails.get(0)); - - // adds,dumps and verifies Interface for acl - sendAclInterfaceSetAclList(jvpp); - verifyAclInterfaceList(sendAclInterfaceListDumpRequest(jvpp).aclInterfaceListDetails.get(0)); - - // deletes all created data - sendAclInterfaceDeleteList(jvpp); - sendAclDelRequest(jvpp); - sendMacIpDelRequest(jvpp); - - System.out.println("Disconnecting..."); - } - } -} diff --git a/java/jvpp-acl/io/fd/vpp/jvpp/acl/examples/Readme.txt b/java/jvpp-acl/io/fd/vpp/jvpp/acl/examples/Readme.txt deleted file mode 100644 index d17fbfc..0000000 --- a/java/jvpp-acl/io/fd/vpp/jvpp/acl/examples/Readme.txt +++ /dev/null @@ -1,4 +0,0 @@ -release version: -sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp-native/vpp/vpp-api/java/jvpp-acl-17.10.jar io.fd.vpp.jvpp.acl.examples.FutureApiExample -debug version: -sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp-debug-native/vpp/vpp-api/java/jvpp-acl-17.10.jar io.fd.vpp.jvpp.acl.examples.FutureApiExample diff --git a/java/jvpp-acl/io/fd/vpp/jvpp/acl/test/CallbackApiTest.java b/java/jvpp-acl/io/fd/vpp/jvpp/acl/test/CallbackApiTest.java deleted file mode 100644 index a7bbb7f..0000000 --- a/java/jvpp-acl/io/fd/vpp/jvpp/acl/test/CallbackApiTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.acl.test; - -import io.fd.vpp.jvpp.AbstractCallbackApiTest; -import io.fd.vpp.jvpp.acl.JVppAclImpl; - -import java.util.logging.Logger; - -public class CallbackApiTest extends AbstractCallbackApiTest { - - private static Logger LOG = Logger.getLogger(CallbackApiTest.class.getName()); - - - public static void main(String[] args) throws Exception { - LOG.info("Testing ControlPing using Java callback API for core plugin"); - testControlPing(args[0], new JVppAclImpl()); - } -} diff --git a/java/jvpp-acl/io/fd/vpp/jvpp/acl/test/FutureApiTest.java b/java/jvpp-acl/io/fd/vpp/jvpp/acl/test/FutureApiTest.java deleted file mode 100644 index ff1c73c..0000000 --- a/java/jvpp-acl/io/fd/vpp/jvpp/acl/test/FutureApiTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.acl.test; - -import io.fd.vpp.jvpp.Assertions; -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.JVppRegistryImpl; -import io.fd.vpp.jvpp.acl.JVppAclImpl; -import io.fd.vpp.jvpp.acl.dto.AclDetailsReplyDump; -import io.fd.vpp.jvpp.acl.dto.AclDump; -import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; - -import java.util.concurrent.CompletableFuture; -import java.util.logging.Logger; - -public class FutureApiTest { - - private static final Logger LOG = Logger.getLogger(FutureApiTest.class.getName()); - - public static void main(String[] args) throws Exception { - testFutureApi(args); - } - - private static void testFutureApi(String[] args) throws Exception { - LOG.info("Testing Java future API for core plugin"); - try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiTest", args[0]); - final FutureJVppAclFacade jvppFacade = new FutureJVppAclFacade(registry, new JVppAclImpl())) { - LOG.info("Successfully connected to VPP"); - - testAclDump(jvppFacade); - - LOG.info("Disconnecting..."); - } - } - - private static void testAclDump(final FutureJVppAclFacade jvpp) throws Exception { - LOG.info("Sending AclDump request..."); - final AclDump request = new AclDump(); - - final CompletableFuture - replyFuture = jvpp.aclDump(request).toCompletableFuture(); - final AclDetailsReplyDump reply = replyFuture.get(); - - Assertions.assertNotNull(reply); - } - - -} diff --git a/java/jvpp-acl/io/fd/vpp/jvpp/acl/test/Readme.txt b/java/jvpp-acl/io/fd/vpp/jvpp/acl/test/Readme.txt deleted file mode 100644 index 1b46585..0000000 --- a/java/jvpp-acl/io/fd/vpp/jvpp/acl/test/Readme.txt +++ /dev/null @@ -1,4 +0,0 @@ -release version: -sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp-native/vpp/vpp-api/java/jvpp-acl-17.10.jar io.fd.vpp.jvpp.acl.test.[test-name] -debug version: -sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-acl-17.10.jar io.fd.vpp.jvpp.acl.test.[test-name] diff --git a/java/jvpp-acl/jvpp_acl.c b/java/jvpp-acl/jvpp_acl.c index 22e44f1..1e48566 100644 --- a/java/jvpp-acl/jvpp_acl.c +++ b/java/jvpp-acl/jvpp_acl.c @@ -32,19 +32,19 @@ #include -#include "jvpp-acl/io_fd_vpp_jvpp_acl_JVppAclImpl.h" +#include "jvpp-acl/io_fd_jvpp_acl_JVppAclImpl.h" #include "jvpp_acl.h" #include "jvpp-acl/jvpp_acl_gen.h" /* - * Class: io_fd_vpp_jvpp_acl_JVppaclImpl + * Class: io_fd_jvpp_acl_JVppaclImpl * Method: init0 * Signature: (JI)V */ -JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_acl_JVppAclImpl_init0 +JNIEXPORT void JNICALL Java_io_fd_jvpp_acl_JVppAclImpl_init0 (JNIEnv *env, jclass clazz, jobject callback, jlong queue_address, jint my_client_index) { acl_main_t * plugin_main = &acl_main; - clib_warning ("Java_io_fd_vpp_jvpp_acl_JVppAclImpl_init0"); + clib_warning ("Java_io_fd_jvpp_acl_JVppAclImpl_init0"); plugin_main->my_client_index = my_client_index; plugin_main->vl_input_queue = uword_to_pointer (queue_address, svm_queue_t *); @@ -69,7 +69,7 @@ JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_acl_JVppAclImpl_init0 #undef _ } -JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_acl_JVppAclImpl_close0 +JNIEXPORT void JNICALL Java_io_fd_jvpp_acl_JVppAclImpl_close0 (JNIEnv *env, jclass clazz) { acl_main_t * plugin_main = &acl_main; diff --git a/java/jvpp-common/jvpp_common.c b/java/jvpp-common/jvpp_common.c index 2425607..4c56775 100644 --- a/java/jvpp-common/jvpp_common.c +++ b/java/jvpp-common/jvpp_common.c @@ -57,7 +57,7 @@ void call_on_error(const char* callName, int contextId, int retval, return; } jmethodID callbackExcMethod = (*env)->GetMethodID(env, callbackClass, - "onError", "(Lio/fd/vpp/jvpp/VppCallbackException;)V"); + "onError", "(Lio/fd/jvpp/VppCallbackException;)V"); if (!callbackExcMethod) { DEBUG_LOG("CallOnError : callbackExcMethod is null!\n"); return; diff --git a/java/jvpp-core/io/fd/jvpp/core/examples/CallbackApiExample.java b/java/jvpp-core/io/fd/jvpp/core/examples/CallbackApiExample.java new file mode 100644 index 0000000..6b2d893 --- /dev/null +++ b/java/jvpp-core/io/fd/jvpp/core/examples/CallbackApiExample.java @@ -0,0 +1,100 @@ +/* + * 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 io.fd.jvpp.core.examples; + +import io.fd.jvpp.JVpp; +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.JVppRegistryImpl; +import io.fd.jvpp.VppCallbackException; +import io.fd.jvpp.core.JVppCoreImpl; +import io.fd.jvpp.core.callback.GetNodeIndexReplyCallback; +import io.fd.jvpp.core.callback.ShowVersionReplyCallback; +import io.fd.jvpp.core.callback.SwInterfaceDetailsCallback; +import io.fd.jvpp.core.dto.GetNodeIndex; +import io.fd.jvpp.core.dto.GetNodeIndexReply; +import io.fd.jvpp.core.dto.ShowVersion; +import io.fd.jvpp.core.dto.ShowVersionReply; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import io.fd.jvpp.core.dto.SwInterfaceDump; +import java.nio.charset.StandardCharsets; + +public class CallbackApiExample { + + public static void main(String[] args) throws Exception { + testCallbackApi(); + } + + private static void testCallbackApi() throws Exception { + System.out.println("Testing Java callback API with JVppRegistry"); + try (final JVppRegistry registry = new JVppRegistryImpl("CallbackApiExample"); + final JVpp jvpp = new JVppCoreImpl()) { + registry.register(jvpp, new TestCallback()); + + System.out.println("Sending ShowVersion request..."); + final int result = jvpp.send(new ShowVersion()); + System.out.printf("ShowVersion send result = %d%n", result); + + System.out.println("Sending GetNodeIndex request..."); + GetNodeIndex getNodeIndexRequest = new GetNodeIndex(); + getNodeIndexRequest.nodeName = "non-existing-node".getBytes(StandardCharsets.UTF_8); + jvpp.send(getNodeIndexRequest); + + System.out.println("Sending SwInterfaceDump request..."); + SwInterfaceDump swInterfaceDumpRequest = new SwInterfaceDump(); + swInterfaceDumpRequest.nameFilterValid = 0; + swInterfaceDumpRequest.nameFilter = "".getBytes(StandardCharsets.UTF_8); + jvpp.send(swInterfaceDumpRequest); + + Thread.sleep(1000); + System.out.println("Disconnecting..."); + } + Thread.sleep(1000); + } + + static class TestCallback implements GetNodeIndexReplyCallback, ShowVersionReplyCallback, SwInterfaceDetailsCallback { + + @Override + public void onGetNodeIndexReply(final GetNodeIndexReply msg) { + System.out.printf("Received GetNodeIndexReply: %s%n", msg); + } + + @Override + public void onShowVersionReply(final ShowVersionReply msg) { + System.out.printf("Received ShowVersionReply: context=%d, program=%s, version=%s, " + + "buildDate=%s, buildDirectory=%s%n", + msg.context, + 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", + msg.interfaceName, msg.l2AddressLength, msg.adminUpDown, + msg.linkUpDown, msg.linkSpeed, (int) msg.linkMtu); + } + + @Override + public void onError(VppCallbackException ex) { + System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(), + ex.getCtxId(), ex.getErrorCode()); + } + } +} diff --git a/java/jvpp-core/io/fd/jvpp/core/examples/CallbackApiReadPerfTest.java b/java/jvpp-core/io/fd/jvpp/core/examples/CallbackApiReadPerfTest.java new file mode 100644 index 0000000..26a371e --- /dev/null +++ b/java/jvpp-core/io/fd/jvpp/core/examples/CallbackApiReadPerfTest.java @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2017 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 io.fd.jvpp.core.examples; + +import io.fd.jvpp.JVpp; +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.JVppRegistryImpl; +import io.fd.jvpp.VppCallbackException; +import io.fd.jvpp.core.JVppCoreImpl; +import io.fd.jvpp.core.callback.ShowVersionReplyCallback; +import io.fd.jvpp.core.dto.*; + +import java.util.logging.Logger; + +public class CallbackApiReadPerfTest { + + private static final Logger LOG = Logger.getLogger(CallbackApiReadPerfTest.class.getName()); + private static final ShowVersion REQUEST = new ShowVersion(); + + /** + * + * @param args - for running for one sec requires no parameter + * - for running for set amount of requests requires one parameters, desired REQUEST amount + * @throws Exception if arguments aren't String representations of numbers + */ + public static void main(String[] args) throws Exception { + if (args.length != 0) { + testInvokeCounter(true, Integer.parseUnsignedInt(args[0])); + } else { + testInvokeCounter(false, 0); + } + } + + /** + * + * @param setCount true = run with set amount of requests, false = run for 1 sec + * @param count number of request with which test should be run + * @throws Exception + */ + private static void testInvokeCounter(boolean setCount, int count) throws Exception { + LOG.info("Testing callback API Invocation Counter"); + try (final JVppRegistry registry = new JVppRegistryImpl("CallbackApiReadPerfTest"); + final JVpp jvpp = new JVppCoreImpl()) { + TestCallback callback = new TestCallback(count); + registry.register(jvpp, callback); + if (!setCount) { + for(int i = 0; i < 5; i++) { + callback.reset(); + LOG.info("Starting invocation for 1sec"); + long time = System.nanoTime(); + do { + jvpp.send(REQUEST); + } while (System.nanoTime() - time < 1000000000 || callback.stop()); + int replyCount = callback.getReplyCounter(); + LOG.info(String.format("Invocation count within 1 second: %d", replyCount)); + } + } else { + for (int i = 0; i < 5; i++) { + LOG.info("Starting invocations"); + callback.reset(); + long time = System.nanoTime(); + for (int x = 0; x < count; x++) { + jvpp.send(REQUEST); + } + long timeAfter = callback.getTime(); + LOG.info(String.format("Invocations took %d ns (%f invocations/s)", timeAfter - time, + count * (1000000000.0/(timeAfter - time)))); + } + } + + + Thread.sleep(1000); + LOG.info("Disconnecting..."); + } + Thread.sleep(1000); + } + + static class TestCallback implements ShowVersionReplyCallback { + + private int replyCounter = 0; + private int count; + private long time = 0; + private boolean stop = false; + + public TestCallback(int count) throws Exception { + this.count = count; + } + + public int getReplyCounter() { + return replyCounter; + } + + public void reset() { + replyCounter = 0; + time = 0; + stop = false; + } + + public boolean stop() { + this.stop = true; + return false; + } + + /* actual method called from VPP + not thread safe but since there's only one VPP thread listening for requests and calling + this method it's OK + */ + @Override + public void onShowVersionReply(final ShowVersionReply msg) { + if (stop) { + return; + } + replyCounter++; + if (replyCounter == count ) { + time = System.nanoTime(); + } + } + + @Override + public void onError(VppCallbackException ex) { + System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(), + ex.getCtxId(), ex.getErrorCode()); + } + + public long getTime() throws Exception { + while(time == 0) { + Thread.sleep(1000); + } + return time; + } + } +} diff --git a/java/jvpp-core/io/fd/jvpp/core/examples/CallbackApiWritePerfTest.java b/java/jvpp-core/io/fd/jvpp/core/examples/CallbackApiWritePerfTest.java new file mode 100644 index 0000000..dd045fe --- /dev/null +++ b/java/jvpp-core/io/fd/jvpp/core/examples/CallbackApiWritePerfTest.java @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2017 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 io.fd.jvpp.core.examples; + +import io.fd.jvpp.JVpp; +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.JVppRegistryImpl; +import io.fd.jvpp.VppCallbackException; +import io.fd.jvpp.core.JVppCoreImpl; +import io.fd.jvpp.core.dto.*; +import io.fd.jvpp.core.callback.ClassifyAddDelTableReplyCallback; + +import java.util.logging.Logger; + +public class CallbackApiWritePerfTest { + + private static final Logger LOG = Logger.getLogger(CallbackApiWritePerfTest.class.getName()); + private static final ClassifyAddDelTable REQUEST = createAddDelTable(); + + private static ClassifyAddDelTable createAddDelTable () { + ClassifyAddDelTable addDelTable = new ClassifyAddDelTable(); + addDelTable.isAdd = 1; + addDelTable.tableIndex = -1; + addDelTable.nbuckets = 2; + addDelTable.memorySize = 2 << 20; + addDelTable.nextTableIndex = ~0; // default + addDelTable.missNextIndex = ~0; // default + addDelTable.skipNVectors = 0; + addDelTable.matchNVectors = 1; + addDelTable.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 addDelTable; + }; + + /** + * + * @param args - for running for one sec requires no parameter + * - for running for set amount of requests requires one parameters, desired REQUEST amount + * @throws Exception if arguments aren't String representations of numbers + */ + public static void main(String[] args) throws Exception { + if (args.length != 0) { + testInvokeCounter(true, Integer.parseUnsignedInt(args[0])); + } else { + testInvokeCounter(false, 0); + } + } + + /** + * + * @param setCount true = run with set amount of requests, false = run for 1 sec + * @param count number of requests with which test should be run + * @throws Exception + */ + private static void testInvokeCounter(boolean setCount, int count) throws Exception { + LOG.info("Testing callback API Invocation Counter"); + try (final JVppRegistry registry = new JVppRegistryImpl("CallbackApiWritePerfTest"); + final JVpp jvpp = new JVppCoreImpl()) { + TestCallback callback = new TestCallback(count); + registry.register(jvpp, callback); + if (!setCount) { + for(int i = 0; i < 5; i++) { + callback.reset(); + LOG.info("Starting invocation for 1sec"); + long time = System.nanoTime(); + do { + jvpp.send(REQUEST); + } while (System.nanoTime() - time < 1000000000 || callback.stop()); + int replyCount = callback.getReplyCounter(); + LOG.info(String.format("Invocation count within 1 second: %d", replyCount)); + } + } else { + for(int i = 0; i < 5; i++) { + LOG.info("Starting invocations"); + callback.reset(); + long time = System.nanoTime(); + for (int x = 1; x <= count; x++) { + jvpp.send(REQUEST); + } + long timeAfter = callback.getTime(); + LOG.info(String.format("Invocations took %d ns (%f invocations/s)", timeAfter - time, + count * (1000000000.0 / (timeAfter - time)))); + } + } + + + Thread.sleep(1000); + LOG.info("Disconnecting..."); + } + Thread.sleep(1000); + } + + static class TestCallback implements ClassifyAddDelTableReplyCallback { + + private int replyCounter = 0; + private int count; + private long time = 0; + private boolean stop = false; + + public TestCallback(int count) throws Exception { + this.count = count; + } + + public int getReplyCounter() { + return replyCounter; + } + + public void reset() { + replyCounter = 0; + time = 0; + stop = false; + } + + public boolean stop() { + this.stop = true; + return false; + } + + /* actual method called from VPP + not thread safe but since there's only one VPP thread listening for requests and calling + this method it's OK + */ + @Override + public void onClassifyAddDelTableReply(final ClassifyAddDelTableReply msg) { + if (stop) { + return; + } + replyCounter++; + if (replyCounter == count ) { + time = System.nanoTime(); + } + } + + @Override + public void onError(VppCallbackException ex) { + System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(), + ex.getCtxId(), ex.getErrorCode()); + } + + public long getTime() throws Exception { + while(time == 0) { + Thread.sleep(1000); + } + return time; + } + } +} diff --git a/java/jvpp-core/io/fd/jvpp/core/examples/CallbackCliApiExample.java b/java/jvpp-core/io/fd/jvpp/core/examples/CallbackCliApiExample.java new file mode 100644 index 0000000..49a3f62 --- /dev/null +++ b/java/jvpp-core/io/fd/jvpp/core/examples/CallbackCliApiExample.java @@ -0,0 +1,68 @@ +/* + * 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. + */ + +package io.fd.jvpp.core.examples; + +import io.fd.jvpp.JVpp; +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.JVppRegistryImpl; +import io.fd.jvpp.VppCallbackException; +import io.fd.jvpp.core.JVppCoreImpl; +import io.fd.jvpp.core.callback.CliInbandReplyCallback; +import io.fd.jvpp.core.dto.CliInband; +import io.fd.jvpp.core.dto.CliInbandReply; + +import java.nio.charset.StandardCharsets; + +public class CallbackCliApiExample { + + public static void main(String[] args) throws Exception { + testCallbackApi(); + } + + private static void testCallbackApi() throws Exception { + System.out.println("Testing Java callback API for Cli with JVppRegistry"); + try (final JVppRegistry registry = new JVppRegistryImpl("CallbackCliApiExample"); + final JVpp jvpp = new JVppCoreImpl()) { + registry.register(jvpp, new TestCallback()); + + System.out.println("Sending CliInband request..."); + CliInband req = new CliInband(); + req.cmd = "create loopback interface"; + final int result = jvpp.send(req); + System.out.printf("CliInband send result = %d%n", result); + + Thread.sleep(1000); + System.out.println("Disconnecting..."); + } + Thread.sleep(1000); + } + + static class TestCallback implements CliInbandReplyCallback { + + @Override + public void onCliInbandReply(final CliInbandReply msg) { + System.out.printf("%s", msg.toString()); + System.out.printf("Received CliInbandReply: context=%d, reply=%s", msg.context, msg.reply); + } + + @Override + public void onError(VppCallbackException ex) { + System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(), + ex.getCtxId(), ex.getErrorCode()); + } + } +} diff --git a/java/jvpp-core/io/fd/jvpp/core/examples/CallbackJVppFacadeExample.java b/java/jvpp-core/io/fd/jvpp/core/examples/CallbackJVppFacadeExample.java new file mode 100644 index 0000000..b9409f8 --- /dev/null +++ b/java/jvpp-core/io/fd/jvpp/core/examples/CallbackJVppFacadeExample.java @@ -0,0 +1,110 @@ +/* + * 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 io.fd.jvpp.core.examples; + +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.JVppRegistryImpl; +import io.fd.jvpp.VppCallbackException; +import io.fd.jvpp.core.JVppCoreImpl; +import io.fd.jvpp.core.callback.GetNodeIndexReplyCallback; +import io.fd.jvpp.core.callback.ShowVersionReplyCallback; +import io.fd.jvpp.core.callfacade.CallbackJVppCoreFacade; +import io.fd.jvpp.core.dto.GetNodeIndex; +import io.fd.jvpp.core.dto.GetNodeIndexReply; +import io.fd.jvpp.core.dto.ShowVersionReply; +import java.nio.charset.StandardCharsets; + +/** + * CallbackJVppFacade together with CallbackJVppFacadeCallback allow for setting different callback for each request. + * This is more convenient than the approach shown in CallbackApiExample. + */ +public class CallbackJVppFacadeExample { + + private static ShowVersionReplyCallback showVersionCallback1 = new ShowVersionReplyCallback() { + @Override + 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, + msg.program, + msg.version, + msg.buildDate, + msg.buildDirectory); + } + + @Override + public void onError(VppCallbackException ex) { + System.out.printf("Received onError exception in showVersionCallback1: call=%s, reply=%d, context=%d%n", + ex.getMethodName(), ex.getErrorCode(), ex.getCtxId()); + } + }; + + private static ShowVersionReplyCallback showVersionCallback2 = new ShowVersionReplyCallback() { + @Override + 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, + msg.program, + msg.version, + msg.buildDate, + msg.buildDirectory); + } + + @Override + public void onError(VppCallbackException ex) { + System.out.printf("Received onError exception in showVersionCallback2: call=%s, reply=%d, context=%d%n", + ex.getMethodName(), ex.getErrorCode(), ex.getCtxId()); + } + + }; + + private static GetNodeIndexReplyCallback getNodeIndexCallback = new GetNodeIndexReplyCallback() { + @Override + public void onGetNodeIndexReply(final GetNodeIndexReply msg) { + System.out.printf("Received GetNodeIndexReply: %s%n", msg); + } + + @Override + public void onError(VppCallbackException ex) { + System.out.printf("Received onError exception in getNodeIndexCallback: call=%s, reply=%d, context=%d%n", + ex.getMethodName(), ex.getErrorCode(), ex.getCtxId()); + } + }; + + private static void testCallbackFacade() throws Exception { + System.out.println("Testing CallbackJVppFacade"); + + try (final JVppRegistry registry = new JVppRegistryImpl("CallbackFacadeExample"); + final CallbackJVppCoreFacade callbackFacade = new CallbackJVppCoreFacade(registry, new JVppCoreImpl())) { + System.out.println("Successfully connected to VPP"); + + callbackFacade.showVersion(showVersionCallback1); + callbackFacade.showVersion(showVersionCallback2); + + GetNodeIndex getNodeIndexRequest = new GetNodeIndex(); + getNodeIndexRequest.nodeName = "dummyNode".getBytes(StandardCharsets.UTF_8); + callbackFacade.getNodeIndex(getNodeIndexRequest, getNodeIndexCallback); + + Thread.sleep(2000); + System.out.println("Disconnecting..."); + } + Thread.sleep(1000); + } + + public static void main(String[] args) throws Exception { + testCallbackFacade(); + } +} diff --git a/java/jvpp-core/io/fd/jvpp/core/examples/CallbackJVppFacadeNotificationExample.java b/java/jvpp-core/io/fd/jvpp/core/examples/CallbackJVppFacadeNotificationExample.java new file mode 100644 index 0000000..3ac2310 --- /dev/null +++ b/java/jvpp-core/io/fd/jvpp/core/examples/CallbackJVppFacadeNotificationExample.java @@ -0,0 +1,97 @@ +/* + * 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 io.fd.jvpp.core.examples; + +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.JVppRegistryImpl; +import io.fd.jvpp.VppCallbackException; +import io.fd.jvpp.core.JVppCore; +import io.fd.jvpp.core.JVppCoreImpl; +import io.fd.jvpp.core.callback.WantInterfaceEventsReplyCallback; +import io.fd.jvpp.core.callback.SwInterfaceEventCallback; +import io.fd.jvpp.core.callfacade.CallbackJVppCoreFacade; +import io.fd.jvpp.core.dto.WantInterfaceEventsReply; +import io.fd.jvpp.core.dto.SwInterfaceEvent; + +public class CallbackJVppFacadeNotificationExample { + + private static void testCallbackFacade() throws Exception { + System.out.println("Testing CallbackJVppFacade for notifications"); + + try (final JVppRegistry registry = new JVppRegistryImpl("CallbackFacadeExample"); + final JVppCore jvpp = new JVppCoreImpl()) { + final CallbackJVppCoreFacade jvppCallbackFacade = new CallbackJVppCoreFacade(registry, jvpp); + System.out.println("Successfully connected to VPP"); + + final AutoCloseable notificationListenerReg = + jvppCallbackFacade.getEventRegistry().registerSwInterfaceEventCallback( + new SwInterfaceEventCallback() { + public void onSwInterfaceEvent(SwInterfaceEvent reply) { + System.out.printf("Received interface notification: ifc: %s%n", reply); + } + + public void onError (VppCallbackException ex) { + System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", + ex.getMethodName(), ex.getCtxId(), ex.getErrorCode()); + } + }); + + jvppCallbackFacade.wantInterfaceEvents(NotificationUtils.getEnableInterfaceNotificationsReq(), + new WantInterfaceEventsReplyCallback() { + @Override + public void onWantInterfaceEventsReply(final WantInterfaceEventsReply reply) { + System.out.println("Interface events started"); + } + + @Override + public void onError(final VppCallbackException ex) { + System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", + ex.getMethodName(), ex.getCtxId(), ex.getErrorCode()); + } + }); + + System.out.println("Changing interface configuration"); + NotificationUtils.getChangeInterfaceState().send(jvpp); + + Thread.sleep(1000); + + jvppCallbackFacade.wantInterfaceEvents(NotificationUtils.getDisableInterfaceNotificationsReq(), + new WantInterfaceEventsReplyCallback() { + @Override + public void onWantInterfaceEventsReply(final WantInterfaceEventsReply reply) { + System.out.println("Interface events stopped"); + } + + @Override + public void onError(final VppCallbackException ex) { + System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", + ex.getMethodName(), ex.getCtxId(), ex.getErrorCode()); + } + }); + + notificationListenerReg.close(); + + Thread.sleep(2000); + System.out.println("Disconnecting..."); + } + Thread.sleep(1000); + } + + public static void main(String[] args) throws Exception { + testCallbackFacade(); + } +} diff --git a/java/jvpp-core/io/fd/jvpp/core/examples/CallbackNotificationApiExample.java b/java/jvpp-core/io/fd/jvpp/core/examples/CallbackNotificationApiExample.java new file mode 100644 index 0000000..6de0a6f --- /dev/null +++ b/java/jvpp-core/io/fd/jvpp/core/examples/CallbackNotificationApiExample.java @@ -0,0 +1,88 @@ +/* + * 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 io.fd.jvpp.core.examples; + +import static io.fd.jvpp.core.examples.NotificationUtils.getChangeInterfaceState; +import static io.fd.jvpp.core.examples.NotificationUtils.getDisableInterfaceNotificationsReq; +import static io.fd.jvpp.core.examples.NotificationUtils.getEnableInterfaceNotificationsReq; +import static io.fd.jvpp.core.examples.NotificationUtils.printNotification; + +import io.fd.jvpp.JVpp; +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.JVppRegistryImpl; +import io.fd.jvpp.VppCallbackException; +import io.fd.jvpp.core.JVppCoreImpl; +import io.fd.jvpp.core.callback.SwInterfaceEventCallback; +import io.fd.jvpp.core.callback.WantInterfaceEventsReplyCallback; +import io.fd.jvpp.core.dto.SwInterfaceEvent; +import io.fd.jvpp.core.dto.SwInterfaceSetFlagsReply; +import io.fd.jvpp.core.dto.WantInterfaceEventsReply; + +public class CallbackNotificationApiExample { + + private static void testCallbackApi() throws Exception { + System.out.println("Testing Java callback API for notifications"); + try (final JVppRegistry registry = new JVppRegistryImpl("CallbackNotificationApiExample"); + final JVpp jvpp = new JVppCoreImpl()) { + registry.register(jvpp, new TestCallback()); + System.out.println("Successfully connected to VPP"); + + getEnableInterfaceNotificationsReq().send(jvpp); + System.out.println("Interface notifications started"); + // TODO test ifc dump which also triggers interface flags send + + System.out.println("Changing interface configuration"); + getChangeInterfaceState().send(jvpp); + + // Notifications are received + Thread.sleep(500); + + getDisableInterfaceNotificationsReq().send(jvpp); + System.out.println("Interface events stopped"); + + Thread.sleep(2000); + System.out.println("Disconnecting..."); + } + Thread.sleep(1000); + } + + public static void main(String[] args) throws Exception { + testCallbackApi(); + } + + private static class TestCallback implements SwInterfaceEventCallback, + WantInterfaceEventsReplyCallback { + + @Override + public void onSwInterfaceEvent( + final SwInterfaceEvent msg) { + printNotification(msg); + } + + @Override + public void onWantInterfaceEventsReply(final WantInterfaceEventsReply wantInterfaceEventsReply) { + System.out.println("Interface notification stream updated"); + } + + @Override + public void onError(VppCallbackException ex) { + System.out.printf("Received onError exception in getNodeIndexCallback: call=%s, reply=%d, context=%d%n", + ex.getMethodName(), ex.getErrorCode(), ex.getCtxId()); + + } + } +} diff --git a/java/jvpp-core/io/fd/jvpp/core/examples/CreateSubInterfaceExample.java b/java/jvpp-core/io/fd/jvpp/core/examples/CreateSubInterfaceExample.java new file mode 100644 index 0000000..cc07520 --- /dev/null +++ b/java/jvpp-core/io/fd/jvpp/core/examples/CreateSubInterfaceExample.java @@ -0,0 +1,121 @@ +/* + * 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 io.fd.jvpp.core.examples; + +import static java.util.Objects.requireNonNull; + +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.JVppRegistryImpl; +import io.fd.jvpp.core.JVppCoreImpl; +import io.fd.jvpp.core.dto.CreateSubif; +import io.fd.jvpp.core.dto.CreateSubifReply; +import io.fd.jvpp.core.dto.SwInterfaceDetailsReplyDump; +import io.fd.jvpp.core.dto.SwInterfaceDump; +import io.fd.jvpp.core.future.FutureJVppCoreFacade; +import java.nio.charset.StandardCharsets; + +/** + *

Tests sub-interface creation.
Equivalent to:
+ * + *

{@code
+ * vppctl create sub GigabitEthernet0/9/0 1 dot1q 100 inner-dot1q any
+ * }
+ * 
+ * + * To verify invoke:
+ *
{@code
+ * vpp_api_test json
+ * vat# sw_interface_dump
+ * }
+ */
+public class CreateSubInterfaceExample {
+
+    private static SwInterfaceDump createSwInterfaceDumpRequest(final String ifaceName) {
+        SwInterfaceDump request = new SwInterfaceDump();
+        request.nameFilter = ifaceName.getBytes(StandardCharsets.UTF_8);
+        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: %s%n", reply);
+    }
+
+    private static void testCreateSubInterface() throws Exception {
+        System.out.println("Testing sub-interface creation using Java callback API");
+        try (final JVppRegistry registry = new JVppRegistryImpl("CreateSubInterfaceExample");
+             final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, new JVppCoreImpl())) {
+            System.out.println("Successfully connected to VPP");
+            Thread.sleep(1000);
+
+            final String ifaceName = "Gigabitethernet0/8/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/8/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...");
+        }
+        Thread.sleep(1000);
+    }
+
+    public static void main(String[] args) throws Exception {
+        testCreateSubInterface();
+    }
+}
diff --git a/java/jvpp-core/io/fd/jvpp/core/examples/FutureApiExample.java b/java/jvpp-core/io/fd/jvpp/core/examples/FutureApiExample.java
new file mode 100644
index 0000000..ff1755d
--- /dev/null
+++ b/java/jvpp-core/io/fd/jvpp/core/examples/FutureApiExample.java
@@ -0,0 +1,127 @@
+/*
+ * 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 io.fd.jvpp.core.examples;
+
+import io.fd.jvpp.JVppRegistry;
+import io.fd.jvpp.JVppRegistryImpl;
+import io.fd.jvpp.core.JVppCoreImpl;
+import io.fd.jvpp.core.dto.BridgeDomainDetailsReplyDump;
+import io.fd.jvpp.core.dto.BridgeDomainDump;
+import io.fd.jvpp.core.dto.GetNodeIndex;
+import io.fd.jvpp.core.dto.GetNodeIndexReply;
+import io.fd.jvpp.core.dto.ShowVersion;
+import io.fd.jvpp.core.dto.ShowVersionReply;
+import io.fd.jvpp.core.dto.SwInterfaceDetails;
+import io.fd.jvpp.core.dto.SwInterfaceDetailsReplyDump;
+import io.fd.jvpp.core.dto.SwInterfaceDump;
+import io.fd.jvpp.core.future.FutureJVppCoreFacade;
+import java.nio.charset.StandardCharsets;
+import java.util.Objects;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Future;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class FutureApiExample {
+
+    private static final Logger LOG = Logger.getLogger(FutureApiExample.class.getName());
+
+    private static void testShowVersion(final FutureJVppCoreFacade jvpp) throws Exception {
+        LOG.info("Sending ShowVersion request...");
+        final Future replyFuture = jvpp.showVersion(new ShowVersion()).toCompletableFuture();
+        final ShowVersionReply reply = replyFuture.get();
+        LOG.info(
+            String.format(
+                "Received ShowVersionReply: context=%d, program=%s, version=%s, buildDate=%s, buildDirectory=%s%n",
+                reply.context, reply.program,
+                reply.version,
+                reply.buildDate,
+                reply.buildDirectory));
+    }
+
+    private static void testEmptyBridgeDomainDump(final FutureJVppCoreFacade jvpp) throws Exception {
+        LOG.info("Sending ShowVersion request...");
+        final BridgeDomainDump request = new BridgeDomainDump();
+        request.bdId = -1; // dump call
+
+        final CompletableFuture
+            replyFuture = jvpp.bridgeDomainDump(request).toCompletableFuture();
+        final BridgeDomainDetailsReplyDump reply = replyFuture.get();
+
+        if (reply == null || reply.bridgeDomainDetails == null) {
+            LOG.severe("Received null response for empty dump: " + reply);
+        } else {
+            LOG.info(
+                String.format(
+                    "Received bridge-domain dump reply with list of bridge-domains: %s",
+                    reply.bridgeDomainDetails));
+        }
+    }
+
+    private static void testGetNodeIndex(final FutureJVppCoreFacade jvpp) {
+        LOG.info("Sending GetNodeIndex request...");
+        final GetNodeIndex request = new GetNodeIndex();
+        request.nodeName = "non-existing-node".getBytes(StandardCharsets.UTF_8);
+        final Future replyFuture = jvpp.getNodeIndex(request).toCompletableFuture();
+        try {
+            final GetNodeIndexReply reply = replyFuture.get();
+            LOG.info(
+                String.format(
+                    "Received GetNodeIndexReply: context=%d, nodeIndex=%d%n", reply.context, reply.nodeIndex));
+        } catch (Exception e) {
+            LOG.log(Level.SEVERE, "GetNodeIndex request failed", e);
+        }
+    }
+
+    private static void testSwInterfaceDump(final FutureJVppCoreFacade jvpp) throws Exception {
+        LOG.info("Sending SwInterfaceDump request...");
+        final SwInterfaceDump request = new SwInterfaceDump();
+        request.nameFilterValid = 0;
+        request.nameFilter = "".getBytes(StandardCharsets.UTF_8);
+
+        final Future replyFuture = jvpp.swInterfaceDump(request).toCompletableFuture();
+        final SwInterfaceDetailsReplyDump reply = replyFuture.get();
+        for (SwInterfaceDetails details : reply.swInterfaceDetails) {
+            Objects.requireNonNull(details, "reply.swInterfaceDetails contains null element!");
+            LOG.info(
+                String.format("Received SwInterfaceDetails: interfaceName=%s, l2AddressLength=%d, adminUpDown=%d, "
+                        + "linkUpDown=%d, linkSpeed=%d, linkMtu=%d%n",
+                    details.interfaceName,
+                    details.l2AddressLength, details.adminUpDown,
+                    details.linkUpDown, details.linkSpeed, (int) details.linkMtu));
+        }
+    }
+
+    private static void testFutureApi() throws Exception {
+        LOG.info("Testing Java future API");
+        try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiExample");
+             final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, new JVppCoreImpl())) {
+            LOG.info("Successfully connected to VPP");
+
+            testEmptyBridgeDomainDump(jvppFacade);
+            testShowVersion(jvppFacade);
+            testGetNodeIndex(jvppFacade);
+            testSwInterfaceDump(jvppFacade);
+
+            LOG.info("Disconnecting...");
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        testFutureApi();
+    }
+}
diff --git a/java/jvpp-core/io/fd/jvpp/core/examples/FutureApiNotificationExample.java b/java/jvpp-core/io/fd/jvpp/core/examples/FutureApiNotificationExample.java
new file mode 100644
index 0000000..67fd05c
--- /dev/null
+++ b/java/jvpp-core/io/fd/jvpp/core/examples/FutureApiNotificationExample.java
@@ -0,0 +1,67 @@
+/*
+ * 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 io.fd.jvpp.core.examples;
+
+import static io.fd.jvpp.core.examples.NotificationUtils.getChangeInterfaceState;
+import static io.fd.jvpp.core.examples.NotificationUtils.getDisableInterfaceNotificationsReq;
+import static io.fd.jvpp.core.examples.NotificationUtils.getEnableInterfaceNotificationsReq;
+
+import io.fd.jvpp.JVppRegistry;
+import io.fd.jvpp.JVppRegistryImpl;
+import io.fd.jvpp.core.JVppCoreImpl;
+import io.fd.jvpp.core.future.FutureJVppCoreFacade;
+import io.fd.jvpp.core.callback.SwInterfaceEventCallback;
+import io.fd.jvpp.core.dto.SwInterfaceEvent;
+import io.fd.jvpp.VppCallbackException;
+
+public class FutureApiNotificationExample {
+
+    private static void testFutureApi() throws Exception {
+        System.out.println("Testing Java future API for notifications");
+        try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiNotificationExample");
+             final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, new JVppCoreImpl());
+             final AutoCloseable notificationListenerReg =
+                 jvppFacade.getEventRegistry()
+                     .registerSwInterfaceEventCallback(new SwInterfaceEventCallback() {
+                         public void onSwInterfaceEvent(SwInterfaceEvent reply) {
+                             System.out.printf("Received interface notification: ifc: %s%n", reply);
+                         }
+
+                         public void onError (VppCallbackException ex) {
+                             System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n",
+                                     ex.getMethodName(), ex.getCtxId(), ex.getErrorCode());
+                         }
+                     })) {
+            System.out.println("Successfully connected to VPP");
+            jvppFacade.wantInterfaceEvents(getEnableInterfaceNotificationsReq()).toCompletableFuture().get();
+            System.out.println("Interface events started");
+
+            System.out.println("Changing interface configuration");
+            jvppFacade.swInterfaceSetFlags(getChangeInterfaceState()).toCompletableFuture().get();
+
+            Thread.sleep(1000);
+
+            jvppFacade.wantInterfaceEvents(getDisableInterfaceNotificationsReq()).toCompletableFuture().get();
+            System.out.println("Interface events stopped");
+            System.out.println("Disconnecting...");
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        testFutureApi();
+    }
+}
diff --git a/java/jvpp-core/io/fd/jvpp/core/examples/FutureApiReadPerfTest.java b/java/jvpp-core/io/fd/jvpp/core/examples/FutureApiReadPerfTest.java
new file mode 100644
index 0000000..747a66a
--- /dev/null
+++ b/java/jvpp-core/io/fd/jvpp/core/examples/FutureApiReadPerfTest.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2017 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 io.fd.jvpp.core.examples;
+
+import io.fd.jvpp.JVppRegistry;
+import io.fd.jvpp.JVppRegistryImpl;
+import io.fd.jvpp.core.JVppCoreImpl;
+import io.fd.jvpp.core.callback.ShowVersionReplyCallback;
+import io.fd.jvpp.core.dto.*;
+import io.fd.jvpp.core.future.FutureJVppCoreFacade;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.logging.Logger;
+
+public class FutureApiReadPerfTest {
+
+    private static final Logger LOG = Logger.getLogger(FutureApiReadPerfTest.class.getName());
+    private static final ShowVersion REQUEST = new ShowVersion();
+    private static volatile int currentCount = 0;
+    private static int desiredCount = 0;
+    private static long timeAfter = 0;
+    private static volatile boolean stop = false;
+    /**
+     * Run after reply message is received
+     * in case of running for 1 sec check if time passed (stop variable) and if it does skip processing
+     * in case of running for set amount of REQUEST, record time in which was last reply received
+     * not thread save but since reading part process only one message at a time it's ok
+     */
+    private static Runnable replyFc = () -> {
+        if (stop) {
+            return;
+        }
+        currentCount++;
+        if(currentCount == desiredCount) {
+            timeAfter = System.nanoTime();
+        }
+    };
+
+    /**
+     * Used to reset counters and flags between runs
+     */
+    private static void reset() {
+        currentCount = 0;
+        timeAfter = 0;
+        stop = false;
+    }
+
+    public static boolean stop() {
+        stop = true;
+        return false;
+    }
+
+    /**
+     *
+     * @return time of last reply received
+     * @throws Exception during thread sleep
+     */
+    private static long getTime() throws Exception {
+        while(timeAfter == 0) {
+            LOG.info(String.format("Received %d replies", currentCount));
+            Thread.sleep(1000);
+        }
+        return timeAfter;
+    }
+
+    /**
+     *
+     * @param args - for running for one sec requires no parameter
+     *             - for running for set amount of requests requires one parameters, desired REQUEST amount
+     * @throws Exception if arguments aren't String representations of numbers
+     */
+    public static void main(String[] args) throws Exception {
+        if (args.length == 1) {
+            desiredCount =  Integer.parseUnsignedInt(args[0]);
+            testInvokeCounter(true);
+        } else {
+            testInvokeCounter(false);
+        }
+    }
+
+    /**
+     *
+     * @param setCount true = run with set amount of requests, false = run for 1 sec
+     * @throws Exception
+     */
+    private static void testInvokeCounter(boolean setCount) throws Exception {
+        LOG.info("Testing callback API Invocation Counter");
+        try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiReadPerfTest");
+             final FutureJVppCoreFacade jvpp = new FutureJVppCoreFacade(registry, new JVppCoreImpl())) {
+            if (!setCount) {
+                for(int i = 0; i < 5; i++) {
+                    reset();
+                    LOG.info("Starting invocation for 1sec");
+                    long time = System.nanoTime();
+                    do {
+                        CompletableFuture replyFuture = jvpp.showVersion(REQUEST).toCompletableFuture();
+                        replyFuture.thenRun(replyFc);
+                    } while (System.nanoTime() - time < 1000000000 || stop());
+                    LOG.info(String.format("Invocation count within 1 second: %d", currentCount));
+                }
+            } else {
+                for (int i = 0; i < 5; i++) {
+                    LOG.info("Starting invocations");
+                    reset();
+                    long time = System.nanoTime();
+                    for (int x = 0; x < desiredCount; x++) {
+                        CompletableFuture replyFuture = jvpp.showVersion(REQUEST).toCompletableFuture();
+                        replyFuture.thenRun(replyFc);
+                    }
+                    LOG.info("Invocations send");
+                    long timeAfter = getTime();
+                    LOG.info(String.format("Invocations took %d ns (%f invocations/s)", timeAfter - time,
+                            desiredCount * (1000000000.0/(timeAfter - time))));
+                }
+            }
+
+
+            Thread.sleep(1000);
+            LOG.info("Disconnecting...");
+        }
+        Thread.sleep(1000);
+    }
+}
diff --git a/java/jvpp-core/io/fd/jvpp/core/examples/L2AclExample.java b/java/jvpp-core/io/fd/jvpp/core/examples/L2AclExample.java
new file mode 100644
index 0000000..7f6742a
--- /dev/null
+++ b/java/jvpp-core/io/fd/jvpp/core/examples/L2AclExample.java
@@ -0,0 +1,206 @@
+/*
+ * 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 io.fd.jvpp.core.examples;
+
+import io.fd.jvpp.JVppRegistry;
+import io.fd.jvpp.JVppRegistryImpl;
+import io.fd.jvpp.core.JVppCoreImpl;
+import io.fd.jvpp.core.dto.ClassifyAddDelSession;
+import io.fd.jvpp.core.dto.ClassifyAddDelSessionReply;
+import io.fd.jvpp.core.dto.ClassifyAddDelTable;
+import io.fd.jvpp.core.dto.ClassifyAddDelTableReply;
+import io.fd.jvpp.core.dto.ClassifySessionDetailsReplyDump;
+import io.fd.jvpp.core.dto.ClassifySessionDump;
+import io.fd.jvpp.core.dto.ClassifyTableByInterface;
+import io.fd.jvpp.core.dto.ClassifyTableByInterfaceReply;
+import io.fd.jvpp.core.dto.ClassifyTableIds;
+import io.fd.jvpp.core.dto.ClassifyTableIdsReply;
+import io.fd.jvpp.core.dto.ClassifyTableInfo;
+import io.fd.jvpp.core.dto.ClassifyTableInfoReply;
+import io.fd.jvpp.core.dto.InputAclSetInterface;
+import io.fd.jvpp.core.dto.InputAclSetInterfaceReply;
+import io.fd.jvpp.core.future.FutureJVppCoreFacade;
+
+/**
+ * 

Tests L2 ACL creation and read.
Equivalent to the following vppctl commands:
+ * + *

{@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 set int input acl intfc local0 l2-table 0
+ * vppctl sh class table verbose
+ * }
+ * 
+ */ +public class L2AclExample { + + private static final int LOCAL0_IFACE_ID = 0; + private static final char[] hexArray = "0123456789ABCDEF".toCharArray(); + + + 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 String bytesToHex(byte[] bytes) { + char[] hexChars = new char[bytes.length * 2]; + for ( int j = 0; j < bytes.length; j++ ) { + int v = bytes[j] & 0xFF; + hexChars[j * 2] = hexArray[v >>> 4]; + hexChars[j * 2 + 1] = hexArray[v & 0x0F]; + } + return new java.lang.String(hexChars); + } + + private static ClassifyTableInfo createClassifyTableInfoRequest(final int tableId) { + ClassifyTableInfo request = new ClassifyTableInfo(); + request.tableId = tableId; + 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 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 = 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: %s%n", reply); + } + + private static void print(ClassifyTableIdsReply reply) { + System.out.printf("ClassifyTableIdsReply: %s%n", reply); + } + + private static void print(final ClassifyTableInfoReply reply) { + System.out.println(reply); + if (reply != null) { + System.out.println("Mask hex: " + bytesToHex(reply.mask)); + } + } + + private static void print(ClassifyAddDelSessionReply reply) { + System.out.printf("ClassifyAddDelSessionReply: context=%s%n", reply); + } + + private static void print(final ClassifySessionDetailsReplyDump reply) { + System.out.println(reply); + reply.classifySessionDetails.forEach(detail -> { + System.out.println(detail); + System.out.println("Match hex: " + bytesToHex(detail.match)); + }); + } + + private static void print(final InputAclSetInterfaceReply reply) { + System.out.printf("InputAclSetInterfaceReply: context=%s%n", reply); + } + + private static void print(final ClassifyTableByInterfaceReply reply) { + System.out.printf("ClassifyAddDelTableReply: %s%n", reply); + } + + private static void testL2Acl() throws Exception { + System.out.println("Testing L2 ACLs using Java callback API"); + try (final JVppRegistry registry = new JVppRegistryImpl("L2AclExample"); + final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, new JVppCoreImpl())) { + + System.out.println("Successfully connected to VPP"); + Thread.sleep(1000); + + final ClassifyAddDelTableReply classifyAddDelTableReply = + 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(); + print(classifyAddDelSessionReply); + + final ClassifySessionDetailsReplyDump classifySessionDetailsReplyDump = + jvppFacade.classifySessionDump(createClassifySessionDumpRequest(classifyAddDelTableReply.newTableIndex)) + .toCompletableFuture().get(); + print(classifySessionDetailsReplyDump); + + final InputAclSetInterfaceReply inputAclSetInterfaceReply = + jvppFacade.inputAclSetInterface(aclSetInterface()).toCompletableFuture().get(); + print(inputAclSetInterfaceReply); + + final ClassifyTableByInterfaceReply classifyTableByInterfaceReply = + jvppFacade.classifyTableByInterface(createClassifyTableByInterfaceRequest()).toCompletableFuture() + .get(); + print(classifyTableByInterfaceReply); + + System.out.println("Disconnecting..."); + } + Thread.sleep(1000); + } + + public static void main(String[] args) throws Exception { + testL2Acl(); + } +} diff --git a/java/jvpp-core/io/fd/jvpp/core/examples/LispAdjacencyExample.java b/java/jvpp-core/io/fd/jvpp/core/examples/LispAdjacencyExample.java new file mode 100644 index 0000000..32addbc --- /dev/null +++ b/java/jvpp-core/io/fd/jvpp/core/examples/LispAdjacencyExample.java @@ -0,0 +1,125 @@ +/* + * 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 io.fd.jvpp.core.examples; + +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.JVppRegistryImpl; +import io.fd.jvpp.core.JVppCoreImpl; +import io.fd.jvpp.core.dto.LispAddDelAdjacency; +import io.fd.jvpp.core.dto.LispAddDelLocalEid; +import io.fd.jvpp.core.dto.LispAddDelLocatorSet; +import io.fd.jvpp.core.dto.LispAddDelRemoteMapping; +import io.fd.jvpp.core.dto.LispAdjacenciesGet; +import io.fd.jvpp.core.dto.LispAdjacenciesGetReply; +import io.fd.jvpp.core.dto.LispEnableDisable; +import io.fd.jvpp.core.future.FutureJVppCoreFacade; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.ExecutionException; +import java.util.logging.Logger; + +/** + * Tests lisp adjacency creation and read (custom vpe.api type support showcase). + */ +public class LispAdjacencyExample { + + private static final Logger LOG = Logger.getLogger(LispAdjacencyExample.class.getName()); + + private static void enableLisp(final FutureJVppCoreFacade jvpp) throws ExecutionException, InterruptedException { + final LispEnableDisable request = new LispEnableDisable(); + request.isEn = 1; + jvpp.lispEnableDisable(request).toCompletableFuture().get(); + LOG.info("Lisp enabled successfully"); + } + + private static void addLocatorSet(final FutureJVppCoreFacade jvpp) throws ExecutionException, InterruptedException { + final LispAddDelLocatorSet request = new LispAddDelLocatorSet(); + request.isAdd = 1; + request.locatorSetName = "ls1".getBytes(StandardCharsets.UTF_8); + jvpp.lispAddDelLocatorSet(request).toCompletableFuture().get(); + LOG.info("Locator set created successfully:" + request.toString()); + } + + private static void addLocalEid(final FutureJVppCoreFacade jvpp) throws ExecutionException, InterruptedException { + final LispAddDelLocalEid request = new LispAddDelLocalEid(); + request.isAdd = 1; + request.locatorSetName = "ls1".getBytes(StandardCharsets.UTF_8); + request.eid = new byte[] {1, 2, 1, 10}; + request.eidType = 0; // ip4 + request.vni = 0; + request.prefixLen = 32; + jvpp.lispAddDelLocalEid(request).toCompletableFuture().get(); + LOG.info("Local EID created successfully:" + request.toString()); + } + + private static void addRemoteMapping(final FutureJVppCoreFacade jvpp) + throws ExecutionException, InterruptedException { + final LispAddDelRemoteMapping request = new LispAddDelRemoteMapping(); + request.isAdd = 1; + request.vni = 0; + request.eid = new byte[] {1, 2, 1, 20}; + request.eidLen = 32; + request.rlocNum = 1; + // FIXME!!!! + //request.rlocs = new byte[] {1, 1, 1, 1, 2, 1, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + jvpp.lispAddDelRemoteMapping(request).toCompletableFuture().get(); + LOG.info("Remote mapping created successfully:" + request.toString()); + } + + private static void addAdjacency(final FutureJVppCoreFacade jvpp) throws ExecutionException, InterruptedException { + final LispAddDelAdjacency request = new LispAddDelAdjacency(); + request.isAdd = 1; + request.leid = new byte[] {1, 2, 1, 10}; + request.leidLen = 32; + request.reid = new byte[] {1, 2, 1, 20}; + request.reidLen = 32; + request.eidType = 0; // ip4 + request.vni = 0; + jvpp.lispAddDelAdjacency(request).toCompletableFuture().get(); + LOG.info("Lisp adjacency created successfully:" + request.toString()); + } + + private static void showAdjacencies(final FutureJVppCoreFacade jvpp) + throws ExecutionException, InterruptedException { + final LispAdjacenciesGetReply reply = + jvpp.lispAdjacenciesGet(new LispAdjacenciesGet()).toCompletableFuture().get(); + LOG.info("Lisp adjacency received successfully:" + reply.toString()); + } + + private static void testAdjacency(final FutureJVppCoreFacade jvpp) throws Exception { + enableLisp(jvpp); + addLocatorSet(jvpp); + addLocalEid(jvpp); + addRemoteMapping(jvpp); + addAdjacency(jvpp); + showAdjacencies(jvpp); + } + + private static void testFutureApi() throws Exception { + LOG.info("Create lisp adjacency test"); + try (final JVppRegistry registry = new JVppRegistryImpl("LispAdjacencyExample"); + final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, new JVppCoreImpl())) { + LOG.info("Successfully connected to VPP"); + + testAdjacency(jvppFacade); + LOG.info("Disconnecting..."); + } + } + + public static void main(String[] args) throws Exception { + testFutureApi(); + } +} diff --git a/java/jvpp-core/io/fd/jvpp/core/examples/NotificationUtils.java b/java/jvpp-core/io/fd/jvpp/core/examples/NotificationUtils.java new file mode 100644 index 0000000..7b78389 --- /dev/null +++ b/java/jvpp-core/io/fd/jvpp/core/examples/NotificationUtils.java @@ -0,0 +1,52 @@ +/* + * 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 io.fd.jvpp.core.examples; + +import java.io.PrintStream; +import io.fd.jvpp.core.dto.SwInterfaceSetFlags; +import io.fd.jvpp.core.dto.SwInterfaceEvent; +import io.fd.jvpp.core.dto.WantInterfaceEvents; + +final class NotificationUtils { + + private NotificationUtils() {} + + static PrintStream printNotification(final SwInterfaceEvent msg) { + return System.out.printf("Received interface notification: ifc: %s%n", msg); + } + + static SwInterfaceSetFlags getChangeInterfaceState() { + final SwInterfaceSetFlags swInterfaceSetFlags = new SwInterfaceSetFlags(); + swInterfaceSetFlags.swIfIndex = 0; + swInterfaceSetFlags.adminUpDown = 1; + return swInterfaceSetFlags; + } + + static WantInterfaceEvents getEnableInterfaceNotificationsReq() { + WantInterfaceEvents wantInterfaceEvents = new WantInterfaceEvents(); + wantInterfaceEvents.pid = 1; + wantInterfaceEvents.enableDisable = 1; + return wantInterfaceEvents; + } + + static WantInterfaceEvents getDisableInterfaceNotificationsReq() { + WantInterfaceEvents wantInterfaceEvents = new WantInterfaceEvents(); + wantInterfaceEvents.pid = 1; + wantInterfaceEvents.enableDisable = 0; + return wantInterfaceEvents; + } +} diff --git a/java/jvpp-core/io/fd/jvpp/core/examples/Readme.txt b/java/jvpp-core/io/fd/jvpp/core/examples/Readme.txt new file mode 100644 index 0000000..df4dd89 --- /dev/null +++ b/java/jvpp-core/io/fd/jvpp/core/examples/Readme.txt @@ -0,0 +1,24 @@ +This package contains basic examples for jvpp. To run the examples: + +- Make sure VPP is running +- From VPP's build-root/ folder execute: + - release version: sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-18.01.jar:build-vpp-native/vpp/vpp-api/java/jvpp-core-18.01.jar io.fd.jvpp.core.examples.[test name] + - debug version: sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-18.01.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-core-18.01.jar io.fd.jvpp.core.examples.[test name] + +Available examples: +CallbackApiExample - Similar to ControlPingTest, invokes more complex calls (e.g. interface dump) using low level JVpp APIs +CallbackJVppFacadeNotificationExample - Example of interface notifications using Callback based JVpp facade +CallbackJVppFacadeExample - Execution of more complex calls using Callback based JVpp facade +CallbackNotificationApiExample - Example of interface notifications using low level JVpp APIs +CreateSubInterfaceExample - Example of sub-interface creation +FutureApiNotificationExample - Example of interface notifications using Future based JVpp facade +FutureApiExample - Execution of more complex calls using Future based JVpp facade +L2AclExample - Example of L2 ACL creation +LispAdjacencyExample - Example of lisp adjacency creation and read (custom vpe.api type support showcase) + +CallbackApiReadPerfTest, FutureApiReadPerfTest, CallbackApiWritePerfTest - test provide two ways to count invocations: +1) maximum number of invocations and received replyies within 1 sec +sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-18.01.jar:build-vpp-native/vpp/vpp-api/java/jvpp-core-18.01.jar io.fd.jvpp.core.examples.[test name] +2) measure time in ns from first request to receiving last reply over set amount of requests +sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-18.01.jar:build-vpp-native/vpp/vpp-api/java/jvpp-core-18.01.jar io.fd.jvpp.core.examples.[test name] [number of request to send] + diff --git a/java/jvpp-core/io/fd/jvpp/core/test/CallbackApiTest.java b/java/jvpp-core/io/fd/jvpp/core/test/CallbackApiTest.java new file mode 100644 index 0000000..06255a7 --- /dev/null +++ b/java/jvpp-core/io/fd/jvpp/core/test/CallbackApiTest.java @@ -0,0 +1,33 @@ +/* + * 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 io.fd.jvpp.core.test; + +import io.fd.jvpp.AbstractCallbackApiTest; +import io.fd.jvpp.core.JVppCoreImpl; + +import java.util.logging.Logger; + +public class CallbackApiTest extends AbstractCallbackApiTest { + + private static Logger LOG = Logger.getLogger(CallbackApiTest.class.getName()); + + + public static void main(String[] args) throws Exception { + LOG.info("Testing ControlPing using Java callback API for core plugin"); + testControlPing(args[0], new JVppCoreImpl()); + } +} diff --git a/java/jvpp-core/io/fd/jvpp/core/test/FutureApiTest.java b/java/jvpp-core/io/fd/jvpp/core/test/FutureApiTest.java new file mode 100644 index 0000000..6af4a41 --- /dev/null +++ b/java/jvpp-core/io/fd/jvpp/core/test/FutureApiTest.java @@ -0,0 +1,79 @@ +/* + * 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 io.fd.jvpp.core.test; + +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.JVppRegistryImpl; +import io.fd.jvpp.core.JVppCoreImpl; +import io.fd.jvpp.core.dto.BridgeDomainDetailsReplyDump; +import io.fd.jvpp.core.dto.BridgeDomainDump; +import io.fd.jvpp.core.dto.GetNodeIndex; +import io.fd.jvpp.core.dto.GetNodeIndexReply; +import io.fd.jvpp.core.dto.ShowVersion; +import io.fd.jvpp.core.dto.ShowVersionReply; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import io.fd.jvpp.core.dto.SwInterfaceDetailsReplyDump; +import io.fd.jvpp.core.dto.SwInterfaceDump; +import io.fd.jvpp.core.future.FutureJVppCoreFacade; +import java.nio.charset.StandardCharsets; +import java.util.Objects; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Future; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class FutureApiTest { + + private static final Logger LOG = Logger.getLogger(FutureApiTest.class.getName()); + + public static void main(String[] args) throws Exception { + testFutureApi(args); + } + + private static void testFutureApi(String[] args) throws Exception { + LOG.info("Testing Java future API for core plugin"); + try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiTest", args[0]); + final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, new JVppCoreImpl())) { + LOG.info("Successfully connected to VPP"); + + testEmptyBridgeDomainDump(jvppFacade); + + LOG.info("Disconnecting..."); + } + } + + private static void testEmptyBridgeDomainDump(final FutureJVppCoreFacade jvpp) throws Exception { + LOG.info("Sending BridgeDomainDump request..."); + final BridgeDomainDump request = new BridgeDomainDump(); + request.bdId = -1; // dump call + + final CompletableFuture + replyFuture = jvpp.bridgeDomainDump(request).toCompletableFuture(); + final BridgeDomainDetailsReplyDump reply = replyFuture.get(); + + if (reply == null || reply.bridgeDomainDetails == null) { + throw new IllegalStateException("Received null response for empty dump: " + reply); + } else { + LOG.info( + String.format( + "Received bridge-domain dump reply with list of bridge-domains: %s", + reply.bridgeDomainDetails)); + } + } + + +} diff --git a/java/jvpp-core/io/fd/jvpp/core/test/Readme.txt b/java/jvpp-core/io/fd/jvpp/core/test/Readme.txt new file mode 100644 index 0000000..f7cb5fc --- /dev/null +++ b/java/jvpp-core/io/fd/jvpp/core/test/Readme.txt @@ -0,0 +1,18 @@ +This package contains basic tests for jvpp. To run the tests: + +- Make sure VPP is running +- From VPP's build-root/ folder execute: + - release version: sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp-native/vpp/vpp-api/java/jvpp-core-17.10.jar io.fd.jvpp.core.test.[test name] + - debug version: sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-core-17.10.jar io.fd.jvpp.core.test.[test name] + +Available tests: +CallbackApiTest - Similar to ControlPingTest, invokes more complex calls (e.g. interface dump) using low level JVpp APIs +CallbackJVppFacadeNotificationTest - Tests interface notifications using Callback based JVpp facade +CallbackJVppFacadeTest - Execution of more complex calls using Callback based JVpp facade +CallbackNotificationApiTest - Tests interface notifications using low level JVpp APIs +ControlPingTest - Simple test executing a single control ping using low level JVpp APIs +CreateSubInterfaceTest - Tests sub-interface creation +FutureApiNotificationTest - Tests interface notifications using Future based JVpp facade +FutureApiTest - Execution of more complex calls using Future based JVpp facade +L2AclTest - Tests L2 ACL creation +LispAdjacencyTest - Tests lisp adjacency creation and read (custom vpe.api type support showcase) diff --git a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackApiExample.java b/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackApiExample.java deleted file mode 100644 index b6558ff..0000000 --- a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackApiExample.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.core.examples; - -import io.fd.vpp.jvpp.JVpp; -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.JVppRegistryImpl; -import io.fd.vpp.jvpp.VppCallbackException; -import io.fd.vpp.jvpp.core.JVppCoreImpl; -import io.fd.vpp.jvpp.core.callback.GetNodeIndexReplyCallback; -import io.fd.vpp.jvpp.core.callback.ShowVersionReplyCallback; -import io.fd.vpp.jvpp.core.callback.SwInterfaceDetailsCallback; -import io.fd.vpp.jvpp.core.dto.GetNodeIndex; -import io.fd.vpp.jvpp.core.dto.GetNodeIndexReply; -import io.fd.vpp.jvpp.core.dto.ShowVersion; -import io.fd.vpp.jvpp.core.dto.ShowVersionReply; -import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; -import io.fd.vpp.jvpp.core.dto.SwInterfaceDump; -import java.nio.charset.StandardCharsets; - -public class CallbackApiExample { - - public static void main(String[] args) throws Exception { - testCallbackApi(); - } - - private static void testCallbackApi() throws Exception { - System.out.println("Testing Java callback API with JVppRegistry"); - try (final JVppRegistry registry = new JVppRegistryImpl("CallbackApiExample"); - final JVpp jvpp = new JVppCoreImpl()) { - registry.register(jvpp, new TestCallback()); - - System.out.println("Sending ShowVersion request..."); - final int result = jvpp.send(new ShowVersion()); - System.out.printf("ShowVersion send result = %d%n", result); - - System.out.println("Sending GetNodeIndex request..."); - GetNodeIndex getNodeIndexRequest = new GetNodeIndex(); - getNodeIndexRequest.nodeName = "non-existing-node".getBytes(StandardCharsets.UTF_8); - jvpp.send(getNodeIndexRequest); - - System.out.println("Sending SwInterfaceDump request..."); - SwInterfaceDump swInterfaceDumpRequest = new SwInterfaceDump(); - swInterfaceDumpRequest.nameFilterValid = 0; - swInterfaceDumpRequest.nameFilter = "".getBytes(StandardCharsets.UTF_8); - jvpp.send(swInterfaceDumpRequest); - - Thread.sleep(1000); - System.out.println("Disconnecting..."); - } - Thread.sleep(1000); - } - - static class TestCallback implements GetNodeIndexReplyCallback, ShowVersionReplyCallback, SwInterfaceDetailsCallback { - - @Override - public void onGetNodeIndexReply(final GetNodeIndexReply msg) { - System.out.printf("Received GetNodeIndexReply: %s%n", msg); - } - - @Override - public void onShowVersionReply(final ShowVersionReply msg) { - System.out.printf("Received ShowVersionReply: context=%d, program=%s, version=%s, " - + "buildDate=%s, buildDirectory=%s%n", - msg.context, - 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", - msg.interfaceName, msg.l2AddressLength, msg.adminUpDown, - msg.linkUpDown, msg.linkSpeed, (int) msg.linkMtu); - } - - @Override - public void onError(VppCallbackException ex) { - System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(), - ex.getCtxId(), ex.getErrorCode()); - } - } -} diff --git a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackApiReadPerfTest.java b/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackApiReadPerfTest.java deleted file mode 100644 index 6ff440d..0000000 --- a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackApiReadPerfTest.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (c) 2017 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 io.fd.vpp.jvpp.core.examples; - -import io.fd.vpp.jvpp.JVpp; -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.JVppRegistryImpl; -import io.fd.vpp.jvpp.VppCallbackException; -import io.fd.vpp.jvpp.core.JVppCoreImpl; -import io.fd.vpp.jvpp.core.callback.ShowVersionReplyCallback; -import io.fd.vpp.jvpp.core.dto.*; - -import java.util.logging.Logger; - -public class CallbackApiReadPerfTest { - - private static final Logger LOG = Logger.getLogger(CallbackApiReadPerfTest.class.getName()); - private static final ShowVersion REQUEST = new ShowVersion(); - - /** - * - * @param args - for running for one sec requires no parameter - * - for running for set amount of requests requires one parameters, desired REQUEST amount - * @throws Exception if arguments aren't String representations of numbers - */ - public static void main(String[] args) throws Exception { - if (args.length != 0) { - testInvokeCounter(true, Integer.parseUnsignedInt(args[0])); - } else { - testInvokeCounter(false, 0); - } - } - - /** - * - * @param setCount true = run with set amount of requests, false = run for 1 sec - * @param count number of request with which test should be run - * @throws Exception - */ - private static void testInvokeCounter(boolean setCount, int count) throws Exception { - LOG.info("Testing callback API Invocation Counter"); - try (final JVppRegistry registry = new JVppRegistryImpl("CallbackApiReadPerfTest"); - final JVpp jvpp = new JVppCoreImpl()) { - TestCallback callback = new TestCallback(count); - registry.register(jvpp, callback); - if (!setCount) { - for(int i = 0; i < 5; i++) { - callback.reset(); - LOG.info("Starting invocation for 1sec"); - long time = System.nanoTime(); - do { - jvpp.send(REQUEST); - } while (System.nanoTime() - time < 1000000000 || callback.stop()); - int replyCount = callback.getReplyCounter(); - LOG.info(String.format("Invocation count within 1 second: %d", replyCount)); - } - } else { - for (int i = 0; i < 5; i++) { - LOG.info("Starting invocations"); - callback.reset(); - long time = System.nanoTime(); - for (int x = 0; x < count; x++) { - jvpp.send(REQUEST); - } - long timeAfter = callback.getTime(); - LOG.info(String.format("Invocations took %d ns (%f invocations/s)", timeAfter - time, - count * (1000000000.0/(timeAfter - time)))); - } - } - - - Thread.sleep(1000); - LOG.info("Disconnecting..."); - } - Thread.sleep(1000); - } - - static class TestCallback implements ShowVersionReplyCallback { - - private int replyCounter = 0; - private int count; - private long time = 0; - private boolean stop = false; - - public TestCallback(int count) throws Exception { - this.count = count; - } - - public int getReplyCounter() { - return replyCounter; - } - - public void reset() { - replyCounter = 0; - time = 0; - stop = false; - } - - public boolean stop() { - this.stop = true; - return false; - } - - /* actual method called from VPP - not thread safe but since there's only one VPP thread listening for requests and calling - this method it's OK - */ - @Override - public void onShowVersionReply(final ShowVersionReply msg) { - if (stop) { - return; - } - replyCounter++; - if (replyCounter == count ) { - time = System.nanoTime(); - } - } - - @Override - public void onError(VppCallbackException ex) { - System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(), - ex.getCtxId(), ex.getErrorCode()); - } - - public long getTime() throws Exception { - while(time == 0) { - Thread.sleep(1000); - } - return time; - } - } -} diff --git a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackApiWritePerfTest.java b/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackApiWritePerfTest.java deleted file mode 100644 index 1940ddc..0000000 --- a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackApiWritePerfTest.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2017 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 io.fd.vpp.jvpp.core.examples; - -import io.fd.vpp.jvpp.JVpp; -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.JVppRegistryImpl; -import io.fd.vpp.jvpp.VppCallbackException; -import io.fd.vpp.jvpp.core.JVppCoreImpl; -import io.fd.vpp.jvpp.core.dto.*; -import io.fd.vpp.jvpp.core.callback.ClassifyAddDelTableReplyCallback; - -import java.util.logging.Logger; - -public class CallbackApiWritePerfTest { - - private static final Logger LOG = Logger.getLogger(CallbackApiWritePerfTest.class.getName()); - private static final ClassifyAddDelTable REQUEST = createAddDelTable(); - - private static ClassifyAddDelTable createAddDelTable () { - ClassifyAddDelTable addDelTable = new ClassifyAddDelTable(); - addDelTable.isAdd = 1; - addDelTable.tableIndex = -1; - addDelTable.nbuckets = 2; - addDelTable.memorySize = 2 << 20; - addDelTable.nextTableIndex = ~0; // default - addDelTable.missNextIndex = ~0; // default - addDelTable.skipNVectors = 0; - addDelTable.matchNVectors = 1; - addDelTable.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 addDelTable; - }; - - /** - * - * @param args - for running for one sec requires no parameter - * - for running for set amount of requests requires one parameters, desired REQUEST amount - * @throws Exception if arguments aren't String representations of numbers - */ - public static void main(String[] args) throws Exception { - if (args.length != 0) { - testInvokeCounter(true, Integer.parseUnsignedInt(args[0])); - } else { - testInvokeCounter(false, 0); - } - } - - /** - * - * @param setCount true = run with set amount of requests, false = run for 1 sec - * @param count number of requests with which test should be run - * @throws Exception - */ - private static void testInvokeCounter(boolean setCount, int count) throws Exception { - LOG.info("Testing callback API Invocation Counter"); - try (final JVppRegistry registry = new JVppRegistryImpl("CallbackApiWritePerfTest"); - final JVpp jvpp = new JVppCoreImpl()) { - TestCallback callback = new TestCallback(count); - registry.register(jvpp, callback); - if (!setCount) { - for(int i = 0; i < 5; i++) { - callback.reset(); - LOG.info("Starting invocation for 1sec"); - long time = System.nanoTime(); - do { - jvpp.send(REQUEST); - } while (System.nanoTime() - time < 1000000000 || callback.stop()); - int replyCount = callback.getReplyCounter(); - LOG.info(String.format("Invocation count within 1 second: %d", replyCount)); - } - } else { - for(int i = 0; i < 5; i++) { - LOG.info("Starting invocations"); - callback.reset(); - long time = System.nanoTime(); - for (int x = 1; x <= count; x++) { - jvpp.send(REQUEST); - } - long timeAfter = callback.getTime(); - LOG.info(String.format("Invocations took %d ns (%f invocations/s)", timeAfter - time, - count * (1000000000.0 / (timeAfter - time)))); - } - } - - - Thread.sleep(1000); - LOG.info("Disconnecting..."); - } - Thread.sleep(1000); - } - - static class TestCallback implements ClassifyAddDelTableReplyCallback { - - private int replyCounter = 0; - private int count; - private long time = 0; - private boolean stop = false; - - public TestCallback(int count) throws Exception { - this.count = count; - } - - public int getReplyCounter() { - return replyCounter; - } - - public void reset() { - replyCounter = 0; - time = 0; - stop = false; - } - - public boolean stop() { - this.stop = true; - return false; - } - - /* actual method called from VPP - not thread safe but since there's only one VPP thread listening for requests and calling - this method it's OK - */ - @Override - public void onClassifyAddDelTableReply(final ClassifyAddDelTableReply msg) { - if (stop) { - return; - } - replyCounter++; - if (replyCounter == count ) { - time = System.nanoTime(); - } - } - - @Override - public void onError(VppCallbackException ex) { - System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(), - ex.getCtxId(), ex.getErrorCode()); - } - - public long getTime() throws Exception { - while(time == 0) { - Thread.sleep(1000); - } - return time; - } - } -} diff --git a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackCliApiExample.java b/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackCliApiExample.java deleted file mode 100644 index b692291..0000000 --- a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackCliApiExample.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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. - */ - -package io.fd.vpp.jvpp.core.examples; - -import io.fd.vpp.jvpp.JVpp; -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.JVppRegistryImpl; -import io.fd.vpp.jvpp.VppCallbackException; -import io.fd.vpp.jvpp.core.JVppCoreImpl; -import io.fd.vpp.jvpp.core.callback.CliInbandReplyCallback; -import io.fd.vpp.jvpp.core.dto.CliInband; -import io.fd.vpp.jvpp.core.dto.CliInbandReply; - -import java.nio.charset.StandardCharsets; - -public class CallbackCliApiExample { - - public static void main(String[] args) throws Exception { - testCallbackApi(); - } - - private static void testCallbackApi() throws Exception { - System.out.println("Testing Java callback API for Cli with JVppRegistry"); - try (final JVppRegistry registry = new JVppRegistryImpl("CallbackCliApiExample"); - final JVpp jvpp = new JVppCoreImpl()) { - registry.register(jvpp, new TestCallback()); - - System.out.println("Sending CliInband request..."); - CliInband req = new CliInband(); - req.cmd = "create loopback interface"; - final int result = jvpp.send(req); - System.out.printf("CliInband send result = %d%n", result); - - Thread.sleep(1000); - System.out.println("Disconnecting..."); - } - Thread.sleep(1000); - } - - static class TestCallback implements CliInbandReplyCallback { - - @Override - public void onCliInbandReply(final CliInbandReply msg) { - System.out.printf("%s", msg.toString()); - System.out.printf("Received CliInbandReply: context=%d, reply=%s", msg.context, msg.reply); - } - - @Override - public void onError(VppCallbackException ex) { - System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(), - ex.getCtxId(), ex.getErrorCode()); - } - } -} diff --git a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackJVppFacadeExample.java b/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackJVppFacadeExample.java deleted file mode 100644 index a8b9186..0000000 --- a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackJVppFacadeExample.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.core.examples; - -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.JVppRegistryImpl; -import io.fd.vpp.jvpp.VppCallbackException; -import io.fd.vpp.jvpp.core.JVppCoreImpl; -import io.fd.vpp.jvpp.core.callback.GetNodeIndexReplyCallback; -import io.fd.vpp.jvpp.core.callback.ShowVersionReplyCallback; -import io.fd.vpp.jvpp.core.callfacade.CallbackJVppCoreFacade; -import io.fd.vpp.jvpp.core.dto.GetNodeIndex; -import io.fd.vpp.jvpp.core.dto.GetNodeIndexReply; -import io.fd.vpp.jvpp.core.dto.ShowVersionReply; -import java.nio.charset.StandardCharsets; - -/** - * CallbackJVppFacade together with CallbackJVppFacadeCallback allow for setting different callback for each request. - * This is more convenient than the approach shown in CallbackApiExample. - */ -public class CallbackJVppFacadeExample { - - private static ShowVersionReplyCallback showVersionCallback1 = new ShowVersionReplyCallback() { - @Override - 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, - msg.program, - msg.version, - msg.buildDate, - msg.buildDirectory); - } - - @Override - public void onError(VppCallbackException ex) { - System.out.printf("Received onError exception in showVersionCallback1: call=%s, reply=%d, context=%d%n", - ex.getMethodName(), ex.getErrorCode(), ex.getCtxId()); - } - }; - - private static ShowVersionReplyCallback showVersionCallback2 = new ShowVersionReplyCallback() { - @Override - 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, - msg.program, - msg.version, - msg.buildDate, - msg.buildDirectory); - } - - @Override - public void onError(VppCallbackException ex) { - System.out.printf("Received onError exception in showVersionCallback2: call=%s, reply=%d, context=%d%n", - ex.getMethodName(), ex.getErrorCode(), ex.getCtxId()); - } - - }; - - private static GetNodeIndexReplyCallback getNodeIndexCallback = new GetNodeIndexReplyCallback() { - @Override - public void onGetNodeIndexReply(final GetNodeIndexReply msg) { - System.out.printf("Received GetNodeIndexReply: %s%n", msg); - } - - @Override - public void onError(VppCallbackException ex) { - System.out.printf("Received onError exception in getNodeIndexCallback: call=%s, reply=%d, context=%d%n", - ex.getMethodName(), ex.getErrorCode(), ex.getCtxId()); - } - }; - - private static void testCallbackFacade() throws Exception { - System.out.println("Testing CallbackJVppFacade"); - - try (final JVppRegistry registry = new JVppRegistryImpl("CallbackFacadeExample"); - final CallbackJVppCoreFacade callbackFacade = new CallbackJVppCoreFacade(registry, new JVppCoreImpl())) { - System.out.println("Successfully connected to VPP"); - - callbackFacade.showVersion(showVersionCallback1); - callbackFacade.showVersion(showVersionCallback2); - - GetNodeIndex getNodeIndexRequest = new GetNodeIndex(); - getNodeIndexRequest.nodeName = "dummyNode".getBytes(StandardCharsets.UTF_8); - callbackFacade.getNodeIndex(getNodeIndexRequest, getNodeIndexCallback); - - Thread.sleep(2000); - System.out.println("Disconnecting..."); - } - Thread.sleep(1000); - } - - public static void main(String[] args) throws Exception { - testCallbackFacade(); - } -} diff --git a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackJVppFacadeNotificationExample.java b/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackJVppFacadeNotificationExample.java deleted file mode 100644 index 832464a..0000000 --- a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackJVppFacadeNotificationExample.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.core.examples; - -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.JVppRegistryImpl; -import io.fd.vpp.jvpp.VppCallbackException; -import io.fd.vpp.jvpp.core.JVppCore; -import io.fd.vpp.jvpp.core.JVppCoreImpl; -import io.fd.vpp.jvpp.core.callback.WantInterfaceEventsReplyCallback; -import io.fd.vpp.jvpp.core.callback.SwInterfaceEventCallback; -import io.fd.vpp.jvpp.core.callfacade.CallbackJVppCoreFacade; -import io.fd.vpp.jvpp.core.dto.WantInterfaceEventsReply; -import io.fd.vpp.jvpp.core.dto.SwInterfaceEvent; - -public class CallbackJVppFacadeNotificationExample { - - private static void testCallbackFacade() throws Exception { - System.out.println("Testing CallbackJVppFacade for notifications"); - - try (final JVppRegistry registry = new JVppRegistryImpl("CallbackFacadeExample"); - final JVppCore jvpp = new JVppCoreImpl()) { - final CallbackJVppCoreFacade jvppCallbackFacade = new CallbackJVppCoreFacade(registry, jvpp); - System.out.println("Successfully connected to VPP"); - - final AutoCloseable notificationListenerReg = - jvppCallbackFacade.getEventRegistry().registerSwInterfaceEventCallback( - new SwInterfaceEventCallback() { - public void onSwInterfaceEvent(SwInterfaceEvent reply) { - System.out.printf("Received interface notification: ifc: %s%n", reply); - } - - public void onError (VppCallbackException ex) { - System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", - ex.getMethodName(), ex.getCtxId(), ex.getErrorCode()); - } - }); - - jvppCallbackFacade.wantInterfaceEvents(NotificationUtils.getEnableInterfaceNotificationsReq(), - new WantInterfaceEventsReplyCallback() { - @Override - public void onWantInterfaceEventsReply(final WantInterfaceEventsReply reply) { - System.out.println("Interface events started"); - } - - @Override - public void onError(final VppCallbackException ex) { - System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", - ex.getMethodName(), ex.getCtxId(), ex.getErrorCode()); - } - }); - - System.out.println("Changing interface configuration"); - NotificationUtils.getChangeInterfaceState().send(jvpp); - - Thread.sleep(1000); - - jvppCallbackFacade.wantInterfaceEvents(NotificationUtils.getDisableInterfaceNotificationsReq(), - new WantInterfaceEventsReplyCallback() { - @Override - public void onWantInterfaceEventsReply(final WantInterfaceEventsReply reply) { - System.out.println("Interface events stopped"); - } - - @Override - public void onError(final VppCallbackException ex) { - System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", - ex.getMethodName(), ex.getCtxId(), ex.getErrorCode()); - } - }); - - notificationListenerReg.close(); - - Thread.sleep(2000); - System.out.println("Disconnecting..."); - } - Thread.sleep(1000); - } - - public static void main(String[] args) throws Exception { - testCallbackFacade(); - } -} diff --git a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackNotificationApiExample.java b/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackNotificationApiExample.java deleted file mode 100644 index 9ed418e..0000000 --- a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CallbackNotificationApiExample.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.core.examples; - -import static io.fd.vpp.jvpp.core.examples.NotificationUtils.getChangeInterfaceState; -import static io.fd.vpp.jvpp.core.examples.NotificationUtils.getDisableInterfaceNotificationsReq; -import static io.fd.vpp.jvpp.core.examples.NotificationUtils.getEnableInterfaceNotificationsReq; -import static io.fd.vpp.jvpp.core.examples.NotificationUtils.printNotification; - -import io.fd.vpp.jvpp.JVpp; -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.JVppRegistryImpl; -import io.fd.vpp.jvpp.VppCallbackException; -import io.fd.vpp.jvpp.core.JVppCoreImpl; -import io.fd.vpp.jvpp.core.callback.SwInterfaceEventCallback; -import io.fd.vpp.jvpp.core.callback.WantInterfaceEventsReplyCallback; -import io.fd.vpp.jvpp.core.dto.SwInterfaceEvent; -import io.fd.vpp.jvpp.core.dto.SwInterfaceSetFlagsReply; -import io.fd.vpp.jvpp.core.dto.WantInterfaceEventsReply; - -public class CallbackNotificationApiExample { - - private static void testCallbackApi() throws Exception { - System.out.println("Testing Java callback API for notifications"); - try (final JVppRegistry registry = new JVppRegistryImpl("CallbackNotificationApiExample"); - final JVpp jvpp = new JVppCoreImpl()) { - registry.register(jvpp, new TestCallback()); - System.out.println("Successfully connected to VPP"); - - getEnableInterfaceNotificationsReq().send(jvpp); - System.out.println("Interface notifications started"); - // TODO test ifc dump which also triggers interface flags send - - System.out.println("Changing interface configuration"); - getChangeInterfaceState().send(jvpp); - - // Notifications are received - Thread.sleep(500); - - getDisableInterfaceNotificationsReq().send(jvpp); - System.out.println("Interface events stopped"); - - Thread.sleep(2000); - System.out.println("Disconnecting..."); - } - Thread.sleep(1000); - } - - public static void main(String[] args) throws Exception { - testCallbackApi(); - } - - private static class TestCallback implements SwInterfaceEventCallback, - WantInterfaceEventsReplyCallback { - - @Override - public void onSwInterfaceEvent( - final SwInterfaceEvent msg) { - printNotification(msg); - } - - @Override - public void onWantInterfaceEventsReply(final WantInterfaceEventsReply wantInterfaceEventsReply) { - System.out.println("Interface notification stream updated"); - } - - @Override - public void onError(VppCallbackException ex) { - System.out.printf("Received onError exception in getNodeIndexCallback: call=%s, reply=%d, context=%d%n", - ex.getMethodName(), ex.getErrorCode(), ex.getCtxId()); - - } - } -} diff --git a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CreateSubInterfaceExample.java b/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CreateSubInterfaceExample.java deleted file mode 100644 index 3db6d30..0000000 --- a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/CreateSubInterfaceExample.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.core.examples; - -import static java.util.Objects.requireNonNull; - -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.JVppRegistryImpl; -import io.fd.vpp.jvpp.core.JVppCoreImpl; -import io.fd.vpp.jvpp.core.dto.CreateSubif; -import io.fd.vpp.jvpp.core.dto.CreateSubifReply; -import io.fd.vpp.jvpp.core.dto.SwInterfaceDetailsReplyDump; -import io.fd.vpp.jvpp.core.dto.SwInterfaceDump; -import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade; -import java.nio.charset.StandardCharsets; - -/** - *

Tests sub-interface creation.
Equivalent to:
- * - *

{@code
- * vppctl create sub GigabitEthernet0/9/0 1 dot1q 100 inner-dot1q any
- * }
- * 
- * - * To verify invoke:
- *
{@code
- * vpp_api_test json
- * vat# sw_interface_dump
- * }
- */
-public class CreateSubInterfaceExample {
-
-    private static SwInterfaceDump createSwInterfaceDumpRequest(final String ifaceName) {
-        SwInterfaceDump request = new SwInterfaceDump();
-        request.nameFilter = ifaceName.getBytes(StandardCharsets.UTF_8);
-        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: %s%n", reply);
-    }
-
-    private static void testCreateSubInterface() throws Exception {
-        System.out.println("Testing sub-interface creation using Java callback API");
-        try (final JVppRegistry registry = new JVppRegistryImpl("CreateSubInterfaceExample");
-             final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, new JVppCoreImpl())) {
-            System.out.println("Successfully connected to VPP");
-            Thread.sleep(1000);
-
-            final String ifaceName = "Gigabitethernet0/8/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/8/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...");
-        }
-        Thread.sleep(1000);
-    }
-
-    public static void main(String[] args) throws Exception {
-        testCreateSubInterface();
-    }
-}
diff --git a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/FutureApiExample.java b/java/jvpp-core/io/fd/vpp/jvpp/core/examples/FutureApiExample.java
deleted file mode 100644
index 030e689..0000000
--- a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/FutureApiExample.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * 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 io.fd.vpp.jvpp.core.examples;
-
-import io.fd.vpp.jvpp.JVppRegistry;
-import io.fd.vpp.jvpp.JVppRegistryImpl;
-import io.fd.vpp.jvpp.core.JVppCoreImpl;
-import io.fd.vpp.jvpp.core.dto.BridgeDomainDetailsReplyDump;
-import io.fd.vpp.jvpp.core.dto.BridgeDomainDump;
-import io.fd.vpp.jvpp.core.dto.GetNodeIndex;
-import io.fd.vpp.jvpp.core.dto.GetNodeIndexReply;
-import io.fd.vpp.jvpp.core.dto.ShowVersion;
-import io.fd.vpp.jvpp.core.dto.ShowVersionReply;
-import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails;
-import io.fd.vpp.jvpp.core.dto.SwInterfaceDetailsReplyDump;
-import io.fd.vpp.jvpp.core.dto.SwInterfaceDump;
-import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade;
-import java.nio.charset.StandardCharsets;
-import java.util.Objects;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.Future;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-public class FutureApiExample {
-
-    private static final Logger LOG = Logger.getLogger(FutureApiExample.class.getName());
-
-    private static void testShowVersion(final FutureJVppCoreFacade jvpp) throws Exception {
-        LOG.info("Sending ShowVersion request...");
-        final Future replyFuture = jvpp.showVersion(new ShowVersion()).toCompletableFuture();
-        final ShowVersionReply reply = replyFuture.get();
-        LOG.info(
-            String.format(
-                "Received ShowVersionReply: context=%d, program=%s, version=%s, buildDate=%s, buildDirectory=%s%n",
-                reply.context, reply.program,
-                reply.version,
-                reply.buildDate,
-                reply.buildDirectory));
-    }
-
-    private static void testEmptyBridgeDomainDump(final FutureJVppCoreFacade jvpp) throws Exception {
-        LOG.info("Sending ShowVersion request...");
-        final BridgeDomainDump request = new BridgeDomainDump();
-        request.bdId = -1; // dump call
-
-        final CompletableFuture
-            replyFuture = jvpp.bridgeDomainDump(request).toCompletableFuture();
-        final BridgeDomainDetailsReplyDump reply = replyFuture.get();
-
-        if (reply == null || reply.bridgeDomainDetails == null) {
-            LOG.severe("Received null response for empty dump: " + reply);
-        } else {
-            LOG.info(
-                String.format(
-                    "Received bridge-domain dump reply with list of bridge-domains: %s",
-                    reply.bridgeDomainDetails));
-        }
-    }
-
-    private static void testGetNodeIndex(final FutureJVppCoreFacade jvpp) {
-        LOG.info("Sending GetNodeIndex request...");
-        final GetNodeIndex request = new GetNodeIndex();
-        request.nodeName = "non-existing-node".getBytes(StandardCharsets.UTF_8);
-        final Future replyFuture = jvpp.getNodeIndex(request).toCompletableFuture();
-        try {
-            final GetNodeIndexReply reply = replyFuture.get();
-            LOG.info(
-                String.format(
-                    "Received GetNodeIndexReply: context=%d, nodeIndex=%d%n", reply.context, reply.nodeIndex));
-        } catch (Exception e) {
-            LOG.log(Level.SEVERE, "GetNodeIndex request failed", e);
-        }
-    }
-
-    private static void testSwInterfaceDump(final FutureJVppCoreFacade jvpp) throws Exception {
-        LOG.info("Sending SwInterfaceDump request...");
-        final SwInterfaceDump request = new SwInterfaceDump();
-        request.nameFilterValid = 0;
-        request.nameFilter = "".getBytes(StandardCharsets.UTF_8);
-
-        final Future replyFuture = jvpp.swInterfaceDump(request).toCompletableFuture();
-        final SwInterfaceDetailsReplyDump reply = replyFuture.get();
-        for (SwInterfaceDetails details : reply.swInterfaceDetails) {
-            Objects.requireNonNull(details, "reply.swInterfaceDetails contains null element!");
-            LOG.info(
-                String.format("Received SwInterfaceDetails: interfaceName=%s, l2AddressLength=%d, adminUpDown=%d, "
-                        + "linkUpDown=%d, linkSpeed=%d, linkMtu=%d%n",
-                    details.interfaceName,
-                    details.l2AddressLength, details.adminUpDown,
-                    details.linkUpDown, details.linkSpeed, (int) details.linkMtu));
-        }
-    }
-
-    private static void testFutureApi() throws Exception {
-        LOG.info("Testing Java future API");
-        try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiExample");
-             final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, new JVppCoreImpl())) {
-            LOG.info("Successfully connected to VPP");
-
-            testEmptyBridgeDomainDump(jvppFacade);
-            testShowVersion(jvppFacade);
-            testGetNodeIndex(jvppFacade);
-            testSwInterfaceDump(jvppFacade);
-
-            LOG.info("Disconnecting...");
-        }
-    }
-
-    public static void main(String[] args) throws Exception {
-        testFutureApi();
-    }
-}
diff --git a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/FutureApiNotificationExample.java b/java/jvpp-core/io/fd/vpp/jvpp/core/examples/FutureApiNotificationExample.java
deleted file mode 100644
index 3c84fd7..0000000
--- a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/FutureApiNotificationExample.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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 io.fd.vpp.jvpp.core.examples;
-
-import static io.fd.vpp.jvpp.core.examples.NotificationUtils.getChangeInterfaceState;
-import static io.fd.vpp.jvpp.core.examples.NotificationUtils.getDisableInterfaceNotificationsReq;
-import static io.fd.vpp.jvpp.core.examples.NotificationUtils.getEnableInterfaceNotificationsReq;
-
-import io.fd.vpp.jvpp.JVppRegistry;
-import io.fd.vpp.jvpp.JVppRegistryImpl;
-import io.fd.vpp.jvpp.core.JVppCoreImpl;
-import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade;
-import io.fd.vpp.jvpp.core.callback.SwInterfaceEventCallback;
-import io.fd.vpp.jvpp.core.dto.SwInterfaceEvent;
-import io.fd.vpp.jvpp.VppCallbackException;
-
-public class FutureApiNotificationExample {
-
-    private static void testFutureApi() throws Exception {
-        System.out.println("Testing Java future API for notifications");
-        try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiNotificationExample");
-             final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, new JVppCoreImpl());
-             final AutoCloseable notificationListenerReg =
-                 jvppFacade.getEventRegistry()
-                     .registerSwInterfaceEventCallback(new SwInterfaceEventCallback() {
-                         public void onSwInterfaceEvent(SwInterfaceEvent reply) {
-                             System.out.printf("Received interface notification: ifc: %s%n", reply);
-                         }
-
-                         public void onError (VppCallbackException ex) {
-                             System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n",
-                                     ex.getMethodName(), ex.getCtxId(), ex.getErrorCode());
-                         }
-                     })) {
-            System.out.println("Successfully connected to VPP");
-            jvppFacade.wantInterfaceEvents(getEnableInterfaceNotificationsReq()).toCompletableFuture().get();
-            System.out.println("Interface events started");
-
-            System.out.println("Changing interface configuration");
-            jvppFacade.swInterfaceSetFlags(getChangeInterfaceState()).toCompletableFuture().get();
-
-            Thread.sleep(1000);
-
-            jvppFacade.wantInterfaceEvents(getDisableInterfaceNotificationsReq()).toCompletableFuture().get();
-            System.out.println("Interface events stopped");
-            System.out.println("Disconnecting...");
-        }
-    }
-
-    public static void main(String[] args) throws Exception {
-        testFutureApi();
-    }
-}
diff --git a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/FutureApiReadPerfTest.java b/java/jvpp-core/io/fd/vpp/jvpp/core/examples/FutureApiReadPerfTest.java
deleted file mode 100644
index f335b28..0000000
--- a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/FutureApiReadPerfTest.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright (c) 2017 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 io.fd.vpp.jvpp.core.examples;
-
-import io.fd.vpp.jvpp.JVppRegistry;
-import io.fd.vpp.jvpp.JVppRegistryImpl;
-import io.fd.vpp.jvpp.core.JVppCoreImpl;
-import io.fd.vpp.jvpp.core.callback.ShowVersionReplyCallback;
-import io.fd.vpp.jvpp.core.dto.*;
-import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade;
-
-import java.util.concurrent.CompletableFuture;
-import java.util.logging.Logger;
-
-public class FutureApiReadPerfTest {
-
-    private static final Logger LOG = Logger.getLogger(FutureApiReadPerfTest.class.getName());
-    private static final ShowVersion REQUEST = new ShowVersion();
-    private static volatile int currentCount = 0;
-    private static int desiredCount = 0;
-    private static long timeAfter = 0;
-    private static volatile boolean stop = false;
-    /**
-     * Run after reply message is received
-     * in case of running for 1 sec check if time passed (stop variable) and if it does skip processing
-     * in case of running for set amount of REQUEST, record time in which was last reply received
-     * not thread save but since reading part process only one message at a time it's ok
-     */
-    private static Runnable replyFc = () -> {
-        if (stop) {
-            return;
-        }
-        currentCount++;
-        if(currentCount == desiredCount) {
-            timeAfter = System.nanoTime();
-        }
-    };
-
-    /**
-     * Used to reset counters and flags between runs
-     */
-    private static void reset() {
-        currentCount = 0;
-        timeAfter = 0;
-        stop = false;
-    }
-
-    public static boolean stop() {
-        stop = true;
-        return false;
-    }
-
-    /**
-     *
-     * @return time of last reply received
-     * @throws Exception during thread sleep
-     */
-    private static long getTime() throws Exception {
-        while(timeAfter == 0) {
-            LOG.info(String.format("Received %d replies", currentCount));
-            Thread.sleep(1000);
-        }
-        return timeAfter;
-    }
-
-    /**
-     *
-     * @param args - for running for one sec requires no parameter
-     *             - for running for set amount of requests requires one parameters, desired REQUEST amount
-     * @throws Exception if arguments aren't String representations of numbers
-     */
-    public static void main(String[] args) throws Exception {
-        if (args.length == 1) {
-            desiredCount =  Integer.parseUnsignedInt(args[0]);
-            testInvokeCounter(true);
-        } else {
-            testInvokeCounter(false);
-        }
-    }
-
-    /**
-     *
-     * @param setCount true = run with set amount of requests, false = run for 1 sec
-     * @throws Exception
-     */
-    private static void testInvokeCounter(boolean setCount) throws Exception {
-        LOG.info("Testing callback API Invocation Counter");
-        try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiReadPerfTest");
-             final FutureJVppCoreFacade jvpp = new FutureJVppCoreFacade(registry, new JVppCoreImpl())) {
-            if (!setCount) {
-                for(int i = 0; i < 5; i++) {
-                    reset();
-                    LOG.info("Starting invocation for 1sec");
-                    long time = System.nanoTime();
-                    do {
-                        CompletableFuture replyFuture = jvpp.showVersion(REQUEST).toCompletableFuture();
-                        replyFuture.thenRun(replyFc);
-                    } while (System.nanoTime() - time < 1000000000 || stop());
-                    LOG.info(String.format("Invocation count within 1 second: %d", currentCount));
-                }
-            } else {
-                for (int i = 0; i < 5; i++) {
-                    LOG.info("Starting invocations");
-                    reset();
-                    long time = System.nanoTime();
-                    for (int x = 0; x < desiredCount; x++) {
-                        CompletableFuture replyFuture = jvpp.showVersion(REQUEST).toCompletableFuture();
-                        replyFuture.thenRun(replyFc);
-                    }
-                    LOG.info("Invocations send");
-                    long timeAfter = getTime();
-                    LOG.info(String.format("Invocations took %d ns (%f invocations/s)", timeAfter - time,
-                            desiredCount * (1000000000.0/(timeAfter - time))));
-                }
-            }
-
-
-            Thread.sleep(1000);
-            LOG.info("Disconnecting...");
-        }
-        Thread.sleep(1000);
-    }
-}
diff --git a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/L2AclExample.java b/java/jvpp-core/io/fd/vpp/jvpp/core/examples/L2AclExample.java
deleted file mode 100644
index 0be85d4..0000000
--- a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/L2AclExample.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * 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 io.fd.vpp.jvpp.core.examples;
-
-import io.fd.vpp.jvpp.JVppRegistry;
-import io.fd.vpp.jvpp.JVppRegistryImpl;
-import io.fd.vpp.jvpp.core.JVppCoreImpl;
-import io.fd.vpp.jvpp.core.dto.ClassifyAddDelSession;
-import io.fd.vpp.jvpp.core.dto.ClassifyAddDelSessionReply;
-import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTable;
-import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTableReply;
-import io.fd.vpp.jvpp.core.dto.ClassifySessionDetailsReplyDump;
-import io.fd.vpp.jvpp.core.dto.ClassifySessionDump;
-import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterface;
-import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterfaceReply;
-import io.fd.vpp.jvpp.core.dto.ClassifyTableIds;
-import io.fd.vpp.jvpp.core.dto.ClassifyTableIdsReply;
-import io.fd.vpp.jvpp.core.dto.ClassifyTableInfo;
-import io.fd.vpp.jvpp.core.dto.ClassifyTableInfoReply;
-import io.fd.vpp.jvpp.core.dto.InputAclSetInterface;
-import io.fd.vpp.jvpp.core.dto.InputAclSetInterfaceReply;
-import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade;
-
-/**
- * 

Tests L2 ACL creation and read.
Equivalent to the following vppctl commands:
- * - *

{@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 set int input acl intfc local0 l2-table 0
- * vppctl sh class table verbose
- * }
- * 
- */ -public class L2AclExample { - - private static final int LOCAL0_IFACE_ID = 0; - private static final char[] hexArray = "0123456789ABCDEF".toCharArray(); - - - 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 String bytesToHex(byte[] bytes) { - char[] hexChars = new char[bytes.length * 2]; - for ( int j = 0; j < bytes.length; j++ ) { - int v = bytes[j] & 0xFF; - hexChars[j * 2] = hexArray[v >>> 4]; - hexChars[j * 2 + 1] = hexArray[v & 0x0F]; - } - return new java.lang.String(hexChars); - } - - private static ClassifyTableInfo createClassifyTableInfoRequest(final int tableId) { - ClassifyTableInfo request = new ClassifyTableInfo(); - request.tableId = tableId; - 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 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 = 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: %s%n", reply); - } - - private static void print(ClassifyTableIdsReply reply) { - System.out.printf("ClassifyTableIdsReply: %s%n", reply); - } - - private static void print(final ClassifyTableInfoReply reply) { - System.out.println(reply); - if (reply != null) { - System.out.println("Mask hex: " + bytesToHex(reply.mask)); - } - } - - private static void print(ClassifyAddDelSessionReply reply) { - System.out.printf("ClassifyAddDelSessionReply: context=%s%n", reply); - } - - private static void print(final ClassifySessionDetailsReplyDump reply) { - System.out.println(reply); - reply.classifySessionDetails.forEach(detail -> { - System.out.println(detail); - System.out.println("Match hex: " + bytesToHex(detail.match)); - }); - } - - private static void print(final InputAclSetInterfaceReply reply) { - System.out.printf("InputAclSetInterfaceReply: context=%s%n", reply); - } - - private static void print(final ClassifyTableByInterfaceReply reply) { - System.out.printf("ClassifyAddDelTableReply: %s%n", reply); - } - - private static void testL2Acl() throws Exception { - System.out.println("Testing L2 ACLs using Java callback API"); - try (final JVppRegistry registry = new JVppRegistryImpl("L2AclExample"); - final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, new JVppCoreImpl())) { - - System.out.println("Successfully connected to VPP"); - Thread.sleep(1000); - - final ClassifyAddDelTableReply classifyAddDelTableReply = - 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(); - print(classifyAddDelSessionReply); - - final ClassifySessionDetailsReplyDump classifySessionDetailsReplyDump = - jvppFacade.classifySessionDump(createClassifySessionDumpRequest(classifyAddDelTableReply.newTableIndex)) - .toCompletableFuture().get(); - print(classifySessionDetailsReplyDump); - - final InputAclSetInterfaceReply inputAclSetInterfaceReply = - jvppFacade.inputAclSetInterface(aclSetInterface()).toCompletableFuture().get(); - print(inputAclSetInterfaceReply); - - final ClassifyTableByInterfaceReply classifyTableByInterfaceReply = - jvppFacade.classifyTableByInterface(createClassifyTableByInterfaceRequest()).toCompletableFuture() - .get(); - print(classifyTableByInterfaceReply); - - System.out.println("Disconnecting..."); - } - Thread.sleep(1000); - } - - public static void main(String[] args) throws Exception { - testL2Acl(); - } -} diff --git a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/LispAdjacencyExample.java b/java/jvpp-core/io/fd/vpp/jvpp/core/examples/LispAdjacencyExample.java deleted file mode 100644 index f637669..0000000 --- a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/LispAdjacencyExample.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.core.examples; - -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.JVppRegistryImpl; -import io.fd.vpp.jvpp.core.JVppCoreImpl; -import io.fd.vpp.jvpp.core.dto.LispAddDelAdjacency; -import io.fd.vpp.jvpp.core.dto.LispAddDelLocalEid; -import io.fd.vpp.jvpp.core.dto.LispAddDelLocatorSet; -import io.fd.vpp.jvpp.core.dto.LispAddDelRemoteMapping; -import io.fd.vpp.jvpp.core.dto.LispAdjacenciesGet; -import io.fd.vpp.jvpp.core.dto.LispAdjacenciesGetReply; -import io.fd.vpp.jvpp.core.dto.LispEnableDisable; -import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade; -import java.nio.charset.StandardCharsets; -import java.util.concurrent.ExecutionException; -import java.util.logging.Logger; - -/** - * Tests lisp adjacency creation and read (custom vpe.api type support showcase). - */ -public class LispAdjacencyExample { - - private static final Logger LOG = Logger.getLogger(LispAdjacencyExample.class.getName()); - - private static void enableLisp(final FutureJVppCoreFacade jvpp) throws ExecutionException, InterruptedException { - final LispEnableDisable request = new LispEnableDisable(); - request.isEn = 1; - jvpp.lispEnableDisable(request).toCompletableFuture().get(); - LOG.info("Lisp enabled successfully"); - } - - private static void addLocatorSet(final FutureJVppCoreFacade jvpp) throws ExecutionException, InterruptedException { - final LispAddDelLocatorSet request = new LispAddDelLocatorSet(); - request.isAdd = 1; - request.locatorSetName = "ls1".getBytes(StandardCharsets.UTF_8); - jvpp.lispAddDelLocatorSet(request).toCompletableFuture().get(); - LOG.info("Locator set created successfully:" + request.toString()); - } - - private static void addLocalEid(final FutureJVppCoreFacade jvpp) throws ExecutionException, InterruptedException { - final LispAddDelLocalEid request = new LispAddDelLocalEid(); - request.isAdd = 1; - request.locatorSetName = "ls1".getBytes(StandardCharsets.UTF_8); - request.eid = new byte[] {1, 2, 1, 10}; - request.eidType = 0; // ip4 - request.vni = 0; - request.prefixLen = 32; - jvpp.lispAddDelLocalEid(request).toCompletableFuture().get(); - LOG.info("Local EID created successfully:" + request.toString()); - } - - private static void addRemoteMapping(final FutureJVppCoreFacade jvpp) - throws ExecutionException, InterruptedException { - final LispAddDelRemoteMapping request = new LispAddDelRemoteMapping(); - request.isAdd = 1; - request.vni = 0; - request.eid = new byte[] {1, 2, 1, 20}; - request.eidLen = 32; - request.rlocNum = 1; - // FIXME!!!! - //request.rlocs = new byte[] {1, 1, 1, 1, 2, 1, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - jvpp.lispAddDelRemoteMapping(request).toCompletableFuture().get(); - LOG.info("Remote mapping created successfully:" + request.toString()); - } - - private static void addAdjacency(final FutureJVppCoreFacade jvpp) throws ExecutionException, InterruptedException { - final LispAddDelAdjacency request = new LispAddDelAdjacency(); - request.isAdd = 1; - request.leid = new byte[] {1, 2, 1, 10}; - request.leidLen = 32; - request.reid = new byte[] {1, 2, 1, 20}; - request.reidLen = 32; - request.eidType = 0; // ip4 - request.vni = 0; - jvpp.lispAddDelAdjacency(request).toCompletableFuture().get(); - LOG.info("Lisp adjacency created successfully:" + request.toString()); - } - - private static void showAdjacencies(final FutureJVppCoreFacade jvpp) - throws ExecutionException, InterruptedException { - final LispAdjacenciesGetReply reply = - jvpp.lispAdjacenciesGet(new LispAdjacenciesGet()).toCompletableFuture().get(); - LOG.info("Lisp adjacency received successfully:" + reply.toString()); - } - - private static void testAdjacency(final FutureJVppCoreFacade jvpp) throws Exception { - enableLisp(jvpp); - addLocatorSet(jvpp); - addLocalEid(jvpp); - addRemoteMapping(jvpp); - addAdjacency(jvpp); - showAdjacencies(jvpp); - } - - private static void testFutureApi() throws Exception { - LOG.info("Create lisp adjacency test"); - try (final JVppRegistry registry = new JVppRegistryImpl("LispAdjacencyExample"); - final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, new JVppCoreImpl())) { - LOG.info("Successfully connected to VPP"); - - testAdjacency(jvppFacade); - LOG.info("Disconnecting..."); - } - } - - public static void main(String[] args) throws Exception { - testFutureApi(); - } -} diff --git a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/NotificationUtils.java b/java/jvpp-core/io/fd/vpp/jvpp/core/examples/NotificationUtils.java deleted file mode 100644 index e963d63..0000000 --- a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/NotificationUtils.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.core.examples; - -import java.io.PrintStream; -import io.fd.vpp.jvpp.core.dto.SwInterfaceSetFlags; -import io.fd.vpp.jvpp.core.dto.SwInterfaceEvent; -import io.fd.vpp.jvpp.core.dto.WantInterfaceEvents; - -final class NotificationUtils { - - private NotificationUtils() {} - - static PrintStream printNotification(final SwInterfaceEvent msg) { - return System.out.printf("Received interface notification: ifc: %s%n", msg); - } - - static SwInterfaceSetFlags getChangeInterfaceState() { - final SwInterfaceSetFlags swInterfaceSetFlags = new SwInterfaceSetFlags(); - swInterfaceSetFlags.swIfIndex = 0; - swInterfaceSetFlags.adminUpDown = 1; - return swInterfaceSetFlags; - } - - static WantInterfaceEvents getEnableInterfaceNotificationsReq() { - WantInterfaceEvents wantInterfaceEvents = new WantInterfaceEvents(); - wantInterfaceEvents.pid = 1; - wantInterfaceEvents.enableDisable = 1; - return wantInterfaceEvents; - } - - static WantInterfaceEvents getDisableInterfaceNotificationsReq() { - WantInterfaceEvents wantInterfaceEvents = new WantInterfaceEvents(); - wantInterfaceEvents.pid = 1; - wantInterfaceEvents.enableDisable = 0; - return wantInterfaceEvents; - } -} diff --git a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/Readme.txt b/java/jvpp-core/io/fd/vpp/jvpp/core/examples/Readme.txt deleted file mode 100644 index 9fe3c7a..0000000 --- a/java/jvpp-core/io/fd/vpp/jvpp/core/examples/Readme.txt +++ /dev/null @@ -1,24 +0,0 @@ -This package contains basic examples for jvpp. To run the examples: - -- Make sure VPP is running -- From VPP's build-root/ folder execute: - - release version: sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-18.01.jar:build-vpp-native/vpp/vpp-api/java/jvpp-core-18.01.jar io.fd.vpp.jvpp.core.examples.[test name] - - debug version: sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-18.01.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-core-18.01.jar io.fd.vpp.jvpp.core.examples.[test name] - -Available examples: -CallbackApiExample - Similar to ControlPingTest, invokes more complex calls (e.g. interface dump) using low level JVpp APIs -CallbackJVppFacadeNotificationExample - Example of interface notifications using Callback based JVpp facade -CallbackJVppFacadeExample - Execution of more complex calls using Callback based JVpp facade -CallbackNotificationApiExample - Example of interface notifications using low level JVpp APIs -CreateSubInterfaceExample - Example of sub-interface creation -FutureApiNotificationExample - Example of interface notifications using Future based JVpp facade -FutureApiExample - Execution of more complex calls using Future based JVpp facade -L2AclExample - Example of L2 ACL creation -LispAdjacencyExample - Example of lisp adjacency creation and read (custom vpe.api type support showcase) - -CallbackApiReadPerfTest, FutureApiReadPerfTest, CallbackApiWritePerfTest - test provide two ways to count invocations: -1) maximum number of invocations and received replyies within 1 sec -sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-18.01.jar:build-vpp-native/vpp/vpp-api/java/jvpp-core-18.01.jar io.fd.vpp.jvpp.core.examples.[test name] -2) measure time in ns from first request to receiving last reply over set amount of requests -sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-18.01.jar:build-vpp-native/vpp/vpp-api/java/jvpp-core-18.01.jar io.fd.vpp.jvpp.core.examples.[test name] [number of request to send] - diff --git a/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackApiTest.java b/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackApiTest.java deleted file mode 100644 index 493116c..0000000 --- a/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackApiTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.core.test; - -import io.fd.vpp.jvpp.AbstractCallbackApiTest; -import io.fd.vpp.jvpp.core.JVppCoreImpl; - -import java.util.logging.Logger; - -public class CallbackApiTest extends AbstractCallbackApiTest { - - private static Logger LOG = Logger.getLogger(CallbackApiTest.class.getName()); - - - public static void main(String[] args) throws Exception { - LOG.info("Testing ControlPing using Java callback API for core plugin"); - testControlPing(args[0], new JVppCoreImpl()); - } -} diff --git a/java/jvpp-core/io/fd/vpp/jvpp/core/test/FutureApiTest.java b/java/jvpp-core/io/fd/vpp/jvpp/core/test/FutureApiTest.java deleted file mode 100644 index d3acecc..0000000 --- a/java/jvpp-core/io/fd/vpp/jvpp/core/test/FutureApiTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.core.test; - -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.JVppRegistryImpl; -import io.fd.vpp.jvpp.core.JVppCoreImpl; -import io.fd.vpp.jvpp.core.dto.BridgeDomainDetailsReplyDump; -import io.fd.vpp.jvpp.core.dto.BridgeDomainDump; -import io.fd.vpp.jvpp.core.dto.GetNodeIndex; -import io.fd.vpp.jvpp.core.dto.GetNodeIndexReply; -import io.fd.vpp.jvpp.core.dto.ShowVersion; -import io.fd.vpp.jvpp.core.dto.ShowVersionReply; -import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; -import io.fd.vpp.jvpp.core.dto.SwInterfaceDetailsReplyDump; -import io.fd.vpp.jvpp.core.dto.SwInterfaceDump; -import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade; -import java.nio.charset.StandardCharsets; -import java.util.Objects; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Future; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class FutureApiTest { - - private static final Logger LOG = Logger.getLogger(FutureApiTest.class.getName()); - - public static void main(String[] args) throws Exception { - testFutureApi(args); - } - - private static void testFutureApi(String[] args) throws Exception { - LOG.info("Testing Java future API for core plugin"); - try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiTest", args[0]); - final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, new JVppCoreImpl())) { - LOG.info("Successfully connected to VPP"); - - testEmptyBridgeDomainDump(jvppFacade); - - LOG.info("Disconnecting..."); - } - } - - private static void testEmptyBridgeDomainDump(final FutureJVppCoreFacade jvpp) throws Exception { - LOG.info("Sending BridgeDomainDump request..."); - final BridgeDomainDump request = new BridgeDomainDump(); - request.bdId = -1; // dump call - - final CompletableFuture - replyFuture = jvpp.bridgeDomainDump(request).toCompletableFuture(); - final BridgeDomainDetailsReplyDump reply = replyFuture.get(); - - if (reply == null || reply.bridgeDomainDetails == null) { - throw new IllegalStateException("Received null response for empty dump: " + reply); - } else { - LOG.info( - String.format( - "Received bridge-domain dump reply with list of bridge-domains: %s", - reply.bridgeDomainDetails)); - } - } - - -} diff --git a/java/jvpp-core/io/fd/vpp/jvpp/core/test/Readme.txt b/java/jvpp-core/io/fd/vpp/jvpp/core/test/Readme.txt deleted file mode 100644 index b74cf60..0000000 --- a/java/jvpp-core/io/fd/vpp/jvpp/core/test/Readme.txt +++ /dev/null @@ -1,18 +0,0 @@ -This package contains basic tests for jvpp. To run the tests: - -- Make sure VPP is running -- From VPP's build-root/ folder execute: - - release version: sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp-native/vpp/vpp-api/java/jvpp-core-17.10.jar io.fd.vpp.jvpp.core.test.[test name] - - debug version: sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-core-17.10.jar io.fd.vpp.jvpp.core.test.[test name] - -Available tests: -CallbackApiTest - Similar to ControlPingTest, invokes more complex calls (e.g. interface dump) using low level JVpp APIs -CallbackJVppFacadeNotificationTest - Tests interface notifications using Callback based JVpp facade -CallbackJVppFacadeTest - Execution of more complex calls using Callback based JVpp facade -CallbackNotificationApiTest - Tests interface notifications using low level JVpp APIs -ControlPingTest - Simple test executing a single control ping using low level JVpp APIs -CreateSubInterfaceTest - Tests sub-interface creation -FutureApiNotificationTest - Tests interface notifications using Future based JVpp facade -FutureApiTest - Execution of more complex calls using Future based JVpp facade -L2AclTest - Tests L2 ACL creation -LispAdjacencyTest - Tests lisp adjacency creation and read (custom vpe.api type support showcase) diff --git a/java/jvpp-core/jvpp_core.c b/java/jvpp-core/jvpp_core.c index 2e62426..da8ab09 100644 --- a/java/jvpp-core/jvpp_core.c +++ b/java/jvpp-core/jvpp_core.c @@ -43,10 +43,10 @@ typedef struct { core_main_t core_main __attribute__((aligned (64))); -#include "io_fd_vpp_jvpp_core_JVppCoreImpl.h" +#include "io_fd_jvpp_core_JVppCoreImpl.h" #include "jvpp_core_gen.h" -JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_core_JVppCoreImpl_init0 +JNIEXPORT void JNICALL Java_io_fd_jvpp_core_JVppCoreImpl_init0 (JNIEnv * env, jclass clazz, jobject callback, jlong queue_address, jint my_client_index) { core_main_t * plugin_main = &core_main; plugin_main->my_client_index = my_client_index; @@ -72,7 +72,7 @@ JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_core_JVppCoreImpl_init0 #undef _ } -JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_core_JVppCoreImpl_close0 +JNIEXPORT void JNICALL Java_io_fd_jvpp_core_JVppCoreImpl_close0 (JNIEnv *env, jclass clazz) { core_main_t * plugin_main = &core_main; diff --git a/java/jvpp-gtpu/jvpp_gtpu.c b/java/jvpp-gtpu/jvpp_gtpu.c index 8e523ca..cb6bfd2 100644 --- a/java/jvpp-gtpu/jvpp_gtpu.c +++ b/java/jvpp-gtpu/jvpp_gtpu.c @@ -32,19 +32,19 @@ #include -#include "jvpp-gtpu/io_fd_vpp_jvpp_gtpu_JVppGtpuImpl.h" +#include "jvpp-gtpu/io_fd_jvpp_gtpu_JVppGtpuImpl.h" #include "jvpp_gtpu.h" #include "jvpp-gtpu/jvpp_gtpu_gen.h" /* - * Class: io_fd_vpp_jvpp_gtpu_JVppgtpuImpl + * Class: io_fd_jvpp_gtpu_JVppgtpuImpl * Method: init0 * Signature: (JI)V */ -JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_gtpu_JVppGtpuImpl_init0 +JNIEXPORT void JNICALL Java_io_fd_jvpp_gtpu_JVppGtpuImpl_init0 (JNIEnv *env, jclass clazz, jobject callback, jlong queue_address, jint my_client_index) { gtpu_main_t * plugin_main = >pu_main; - clib_warning ("Java_io_fd_vpp_jvpp_gtpu_JVppGtpuImpl_init0"); + clib_warning ("Java_io_fd_jvpp_gtpu_JVppGtpuImpl_init0"); plugin_main->my_client_index = my_client_index; plugin_main->vl_input_queue = (svm_queue_t *)queue_address; @@ -69,7 +69,7 @@ JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_gtpu_JVppGtpuImpl_init0 #undef _ } -JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_gtpu_JVppGtpuImpl_close0 +JNIEXPORT void JNICALL Java_io_fd_jvpp_gtpu_JVppGtpuImpl_close0 (JNIEnv *env, jclass clazz) { gtpu_main_t * plugin_main = >pu_main; diff --git a/java/jvpp-ikev2/jvpp_ikev2.c b/java/jvpp-ikev2/jvpp_ikev2.c index 4e6aa03..a833cd4 100755 --- a/java/jvpp-ikev2/jvpp_ikev2.c +++ b/java/jvpp-ikev2/jvpp_ikev2.c @@ -32,19 +32,19 @@ #include -#include "jvpp-ikev2/io_fd_vpp_jvpp_ikev2_JVppIkev2Impl.h" +#include "jvpp-ikev2/io_fd_jvpp_ikev2_JVppIkev2Impl.h" #include "jvpp_ikev2.h" #include "jvpp-ikev2/jvpp_ikev2_gen.h" /* - * Class: io_fd_vpp_jvpp_ikev2_JVppIkev2Impl + * Class: io_fd_jvpp_ikev2_JVppIkev2Impl * Method: init0 * Signature: (JI)V */ -JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_ikev2_JVppIkev2Impl_init0 +JNIEXPORT void JNICALL Java_io_fd_jvpp_ikev2_JVppIkev2Impl_init0 (JNIEnv *env, jclass clazz, jobject callback, jlong queue_address, jint my_client_index) { ikev2_main_t * plugin_main = &ikev2_main; - clib_warning ("Java_io_fd_vpp_jvpp_ikev2_JVppIkev2Impl_init0"); + clib_warning ("Java_io_fd_jvpp_ikev2_JVppIkev2Impl_init0"); plugin_main->my_client_index = my_client_index; plugin_main->vl_input_queue = uword_to_pointer (queue_address, svm_queue_t *); @@ -69,7 +69,7 @@ JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_ikev2_JVppIkev2Impl_init0 #undef _ } -JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_ikev2_JVppIkev2Impl_close0 +JNIEXPORT void JNICALL Java_io_fd_jvpp_ikev2_JVppIkev2Impl_close0 (JNIEnv *env, jclass clazz) { ikev2_main_t * plugin_main = &ikev2_main; diff --git a/java/jvpp-ioamexport/io/fd/jvpp/ioamexport/examples/IoamExportApiExample.java b/java/jvpp-ioamexport/io/fd/jvpp/ioamexport/examples/IoamExportApiExample.java new file mode 100644 index 0000000..eb052dd --- /dev/null +++ b/java/jvpp-ioamexport/io/fd/jvpp/ioamexport/examples/IoamExportApiExample.java @@ -0,0 +1,56 @@ +/* + * 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 io.fd.jvpp.ioamexport.examples; + +import java.net.InetAddress; + +import io.fd.jvpp.JVpp; +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.JVppRegistryImpl; +import io.fd.jvpp.VppCallbackException; +import io.fd.jvpp.ioamexport.JVppIoamexportImpl; +import io.fd.jvpp.ioamexport.future.FutureJVppIoamexportFacade; +import io.fd.jvpp.ioamexport.dto.IoamExportIp6EnableDisable; +import io.fd.jvpp.ioamexport.dto.IoamExportIp6EnableDisableReply; + +public class IoamExportApiExample { + + public static void main(String[] args) throws Exception { + ioamExportTestApi(); + } + + private static void ioamExportTestApi() throws Exception { + System.out.println("Testing Java API for ioam export plugin"); + try (final JVppRegistry registry = new JVppRegistryImpl("ioamExportApiExample"); + final JVpp jvpp = new JVppIoamexportImpl()) { + FutureJVppIoamexportFacade ioamexportJvpp = new FutureJVppIoamexportFacade(registry,jvpp); + System.out.println("Sending ioam export request..."); + IoamExportIp6EnableDisable request = new IoamExportIp6EnableDisable(); + request.isDisable = 0; + InetAddress collectorAddress = InetAddress.getByName("2001:0DB8:AC10:FE01:0000:0000:0000:0000"); + InetAddress srcAddress = InetAddress.getByName("2001:0DB8:AC10:FE01:0000:0000:0000:0001"); + request.collectorAddress = collectorAddress.getAddress(); + request.srcAddress = srcAddress.getAddress(); + IoamExportIp6EnableDisableReply reply = ioamexportJvpp.ioamExportIp6EnableDisable(request).toCompletableFuture().get(); + System.out.printf("IoamExportIp6EnableDisableReply = "+reply.toString()+"%n"); + + Thread.sleep(1000); + + System.out.println("Disconnecting..."); + } + } +} diff --git a/java/jvpp-ioamexport/io/fd/jvpp/ioamexport/examples/Readme.txt b/java/jvpp-ioamexport/io/fd/jvpp/ioamexport/examples/Readme.txt new file mode 100644 index 0000000..d28e71f --- /dev/null +++ b/java/jvpp-ioamexport/io/fd/jvpp/ioamexport/examples/Readme.txt @@ -0,0 +1,4 @@ +release version: +sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp-native/vpp/vpp-api/java/jvpp-ioamexport-17.10.jar io.fd.jvpp.ioamexport.examples.IoamExportApiExample +debug vresion: +sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-ioamexport-17.10.jar io.fd.jvpp.ioamexport.examples.IoamExportApiExample diff --git a/java/jvpp-ioamexport/io/fd/jvpp/ioamexport/test/CallbackApiTest.java b/java/jvpp-ioamexport/io/fd/jvpp/ioamexport/test/CallbackApiTest.java new file mode 100644 index 0000000..14efa42 --- /dev/null +++ b/java/jvpp-ioamexport/io/fd/jvpp/ioamexport/test/CallbackApiTest.java @@ -0,0 +1,33 @@ +/* + * 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 io.fd.jvpp.ioamexport.test; + +import io.fd.jvpp.AbstractCallbackApiTest; +import io.fd.jvpp.ioamexport.JVppIoamexportImpl; + +import java.util.logging.Logger; + + +public class CallbackApiTest extends AbstractCallbackApiTest { + + private static Logger LOG = Logger.getLogger(CallbackApiTest.class.getName()); + + public static void main(String[] args) throws Exception { + LOG.info("Testing ControlPing using Java callback API for ioamexport plugin"); + testControlPing(args[0], new JVppIoamexportImpl()); + } +} diff --git a/java/jvpp-ioamexport/io/fd/jvpp/ioamexport/test/FutureApiTest.java b/java/jvpp-ioamexport/io/fd/jvpp/ioamexport/test/FutureApiTest.java new file mode 100644 index 0000000..b4208e7 --- /dev/null +++ b/java/jvpp-ioamexport/io/fd/jvpp/ioamexport/test/FutureApiTest.java @@ -0,0 +1,60 @@ +/* + * 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 io.fd.jvpp.ioamexport.test; + + +import io.fd.jvpp.Assertions; +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.JVppRegistryImpl; +import io.fd.jvpp.ioamexport.JVppIoamexportImpl; +import io.fd.jvpp.ioamexport.dto.IoamExportIp6EnableDisable; +import io.fd.jvpp.ioamexport.dto.IoamExportIp6EnableDisableReply; +import io.fd.jvpp.ioamexport.future.FutureJVppIoamexportFacade; + +import java.util.concurrent.Future; +import java.util.logging.Logger; + +public class FutureApiTest { + + private static final Logger LOG = Logger.getLogger(FutureApiTest.class.getName()); + + public static void main(String[] args) throws Exception { + testCallbackApi(args); + } + + private static void testCallbackApi(String[] args) throws Exception { + LOG.info("Testing Java callback API for ioamexport plugin"); + try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiTest", args[0]); + final FutureJVppIoamexportFacade jvpp = new FutureJVppIoamexportFacade(registry, new JVppIoamexportImpl())) { + LOG.info("Successfully connected to VPP"); + + testIoamExportIp6EnableDisable(jvpp); + + LOG.info("Disconnecting..."); + } + } + + private static void testIoamExportIp6EnableDisable(FutureJVppIoamexportFacade jvpp) throws Exception { + LOG.info("Sending IoamExportIp6EnableDisable request..."); + final IoamExportIp6EnableDisable request = new IoamExportIp6EnableDisable(); + + final Future replyFuture = jvpp.ioamExportIp6EnableDisable(request).toCompletableFuture(); + final IoamExportIp6EnableDisableReply reply = replyFuture.get(); + + Assertions.assertNotNull(reply); + } +} diff --git a/java/jvpp-ioamexport/io/fd/jvpp/ioamexport/test/Readme.txt b/java/jvpp-ioamexport/io/fd/jvpp/ioamexport/test/Readme.txt new file mode 100644 index 0000000..78a10c1 --- /dev/null +++ b/java/jvpp-ioamexport/io/fd/jvpp/ioamexport/test/Readme.txt @@ -0,0 +1,4 @@ +release version: +sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-ioamexport-17.10.jar io.fd.jvpp.ioamexport.test.[test-name] +debug version: +sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-ioamexport-17.10.jar io.fd.jvpp.ioamexport.test.[test-name] diff --git a/java/jvpp-ioamexport/io/fd/vpp/jvpp/ioamexport/examples/IoamExportApiExample.java b/java/jvpp-ioamexport/io/fd/vpp/jvpp/ioamexport/examples/IoamExportApiExample.java deleted file mode 100644 index 2f5b7db..0000000 --- a/java/jvpp-ioamexport/io/fd/vpp/jvpp/ioamexport/examples/IoamExportApiExample.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.ioamexport.examples; - -import java.net.InetAddress; - -import io.fd.vpp.jvpp.JVpp; -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.JVppRegistryImpl; -import io.fd.vpp.jvpp.VppCallbackException; -import io.fd.vpp.jvpp.ioamexport.JVppIoamexportImpl; -import io.fd.vpp.jvpp.ioamexport.future.FutureJVppIoamexportFacade; -import io.fd.vpp.jvpp.ioamexport.dto.IoamExportIp6EnableDisable; -import io.fd.vpp.jvpp.ioamexport.dto.IoamExportIp6EnableDisableReply; - -public class IoamExportApiExample { - - public static void main(String[] args) throws Exception { - ioamExportTestApi(); - } - - private static void ioamExportTestApi() throws Exception { - System.out.println("Testing Java API for ioam export plugin"); - try (final JVppRegistry registry = new JVppRegistryImpl("ioamExportApiExample"); - final JVpp jvpp = new JVppIoamexportImpl()) { - FutureJVppIoamexportFacade ioamexportJvpp = new FutureJVppIoamexportFacade(registry,jvpp); - System.out.println("Sending ioam export request..."); - IoamExportIp6EnableDisable request = new IoamExportIp6EnableDisable(); - request.isDisable = 0; - InetAddress collectorAddress = InetAddress.getByName("2001:0DB8:AC10:FE01:0000:0000:0000:0000"); - InetAddress srcAddress = InetAddress.getByName("2001:0DB8:AC10:FE01:0000:0000:0000:0001"); - request.collectorAddress = collectorAddress.getAddress(); - request.srcAddress = srcAddress.getAddress(); - IoamExportIp6EnableDisableReply reply = ioamexportJvpp.ioamExportIp6EnableDisable(request).toCompletableFuture().get(); - System.out.printf("IoamExportIp6EnableDisableReply = "+reply.toString()+"%n"); - - Thread.sleep(1000); - - System.out.println("Disconnecting..."); - } - } -} diff --git a/java/jvpp-ioamexport/io/fd/vpp/jvpp/ioamexport/examples/Readme.txt b/java/jvpp-ioamexport/io/fd/vpp/jvpp/ioamexport/examples/Readme.txt deleted file mode 100644 index f2dfe91..0000000 --- a/java/jvpp-ioamexport/io/fd/vpp/jvpp/ioamexport/examples/Readme.txt +++ /dev/null @@ -1,4 +0,0 @@ -release version: -sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp-native/vpp/vpp-api/java/jvpp-ioamexport-17.10.jar io.fd.vpp.jvpp.ioamexport.examples.IoamExportApiExample -debug vresion: -sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-ioamexport-17.10.jar io.fd.vpp.jvpp.ioamexport.examples.IoamExportApiExample diff --git a/java/jvpp-ioamexport/io/fd/vpp/jvpp/ioamexport/test/CallbackApiTest.java b/java/jvpp-ioamexport/io/fd/vpp/jvpp/ioamexport/test/CallbackApiTest.java deleted file mode 100644 index ba49d77..0000000 --- a/java/jvpp-ioamexport/io/fd/vpp/jvpp/ioamexport/test/CallbackApiTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.ioamexport.test; - -import io.fd.vpp.jvpp.AbstractCallbackApiTest; -import io.fd.vpp.jvpp.ioamexport.JVppIoamexportImpl; - -import java.util.logging.Logger; - - -public class CallbackApiTest extends AbstractCallbackApiTest { - - private static Logger LOG = Logger.getLogger(CallbackApiTest.class.getName()); - - public static void main(String[] args) throws Exception { - LOG.info("Testing ControlPing using Java callback API for ioamexport plugin"); - testControlPing(args[0], new JVppIoamexportImpl()); - } -} diff --git a/java/jvpp-ioamexport/io/fd/vpp/jvpp/ioamexport/test/FutureApiTest.java b/java/jvpp-ioamexport/io/fd/vpp/jvpp/ioamexport/test/FutureApiTest.java deleted file mode 100644 index 048d244..0000000 --- a/java/jvpp-ioamexport/io/fd/vpp/jvpp/ioamexport/test/FutureApiTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.ioamexport.test; - - -import io.fd.vpp.jvpp.Assertions; -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.JVppRegistryImpl; -import io.fd.vpp.jvpp.ioamexport.JVppIoamexportImpl; -import io.fd.vpp.jvpp.ioamexport.dto.IoamExportIp6EnableDisable; -import io.fd.vpp.jvpp.ioamexport.dto.IoamExportIp6EnableDisableReply; -import io.fd.vpp.jvpp.ioamexport.future.FutureJVppIoamexportFacade; - -import java.util.concurrent.Future; -import java.util.logging.Logger; - -public class FutureApiTest { - - private static final Logger LOG = Logger.getLogger(FutureApiTest.class.getName()); - - public static void main(String[] args) throws Exception { - testCallbackApi(args); - } - - private static void testCallbackApi(String[] args) throws Exception { - LOG.info("Testing Java callback API for ioamexport plugin"); - try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiTest", args[0]); - final FutureJVppIoamexportFacade jvpp = new FutureJVppIoamexportFacade(registry, new JVppIoamexportImpl())) { - LOG.info("Successfully connected to VPP"); - - testIoamExportIp6EnableDisable(jvpp); - - LOG.info("Disconnecting..."); - } - } - - private static void testIoamExportIp6EnableDisable(FutureJVppIoamexportFacade jvpp) throws Exception { - LOG.info("Sending IoamExportIp6EnableDisable request..."); - final IoamExportIp6EnableDisable request = new IoamExportIp6EnableDisable(); - - final Future replyFuture = jvpp.ioamExportIp6EnableDisable(request).toCompletableFuture(); - final IoamExportIp6EnableDisableReply reply = replyFuture.get(); - - Assertions.assertNotNull(reply); - } -} diff --git a/java/jvpp-ioamexport/io/fd/vpp/jvpp/ioamexport/test/Readme.txt b/java/jvpp-ioamexport/io/fd/vpp/jvpp/ioamexport/test/Readme.txt deleted file mode 100644 index 820071a..0000000 --- a/java/jvpp-ioamexport/io/fd/vpp/jvpp/ioamexport/test/Readme.txt +++ /dev/null @@ -1,4 +0,0 @@ -release version: -sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-ioamexport-17.10.jar io.fd.vpp.jvpp.ioamexport.test.[test-name] -debug version: -sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-ioamexport-17.10.jar io.fd.vpp.jvpp.ioamexport.test.[test-name] diff --git a/java/jvpp-ioamexport/jvpp_ioam_export.c b/java/jvpp-ioamexport/jvpp_ioam_export.c index 74ae438..6aa58e4 100644 --- a/java/jvpp-ioamexport/jvpp_ioam_export.c +++ b/java/jvpp-ioamexport/jvpp_ioam_export.c @@ -32,19 +32,19 @@ #include -#include "jvpp-ioamexport/io_fd_vpp_jvpp_ioamexport_JVppIoamexportImpl.h" +#include "jvpp-ioamexport/io_fd_jvpp_ioamexport_JVppIoamexportImpl.h" #include "jvpp_ioam_export.h" #include "jvpp-ioamexport/jvpp_ioamexport_gen.h" /* - * Class: io_fd_vpp_jvpp_ioamexport_JVppIoamexportImpl + * Class: io_fd_jvpp_ioamexport_JVppIoamexportImpl * Method: init0 * Signature: (JI)V */ -JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_ioamexport_JVppIoamexportImpl_init0 +JNIEXPORT void JNICALL Java_io_fd_jvpp_ioamexport_JVppIoamexportImpl_init0 (JNIEnv *env, jclass clazz, jobject callback, jlong queue_address, jint my_client_index) { ioamexport_main_t * plugin_main = &ioamexport_main; - clib_warning ("Java_io_fd_vpp_jvpp_ioamexport_JVppIoamexportImpl_init0"); + clib_warning ("Java_io_fd_jvpp_ioamexport_JVppIoamexportImpl_init0"); plugin_main->my_client_index = my_client_index; plugin_main->vl_input_queue = uword_to_pointer (queue_address, svm_queue_t *); @@ -69,7 +69,7 @@ JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_ioamexport_JVppIoamexportImpl_init0 #undef _ } -JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_ioamexport_JVppIoamexportImpl_close0 +JNIEXPORT void JNICALL Java_io_fd_jvpp_ioamexport_JVppIoamexportImpl_close0 (JNIEnv *env, jclass clazz) { ioamexport_main_t * plugin_main = &ioamexport_main; diff --git a/java/jvpp-ioampot/io/fd/jvpp/ioampot/examples/IoamPotApiExample.java b/java/jvpp-ioampot/io/fd/jvpp/ioampot/examples/IoamPotApiExample.java new file mode 100644 index 0000000..528249a --- /dev/null +++ b/java/jvpp-ioampot/io/fd/jvpp/ioampot/examples/IoamPotApiExample.java @@ -0,0 +1,76 @@ +/* + * 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 io.fd.jvpp.ioampot.examples; + +import io.fd.jvpp.JVpp; +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.JVppRegistryImpl; +import io.fd.jvpp.VppCallbackException; +import io.fd.jvpp.ioampot.JVppIoampotImpl; +import io.fd.jvpp.ioampot.callback.PotProfileAddReplyCallback; +import io.fd.jvpp.ioampot.dto.PotProfileAdd; +import io.fd.jvpp.ioampot.dto.PotProfileAddReply; +import java.nio.charset.StandardCharsets; + +public class IoamPotApiExample { + + static class IoamPotTestCallback implements PotProfileAddReplyCallback { + + @Override + public void onPotProfileAddReply(final PotProfileAddReply reply) { + System.out.printf("Received PotProfileAddReply reply: context=%d%n", + reply.context); + } + + @Override + public void onError(VppCallbackException ex) { + System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(), + ex.getCtxId(), ex.getErrorCode()); + } + } + + public static void main(String[] args) throws Exception { + ioamPotTestApi(); + } + + private static void ioamPotTestApi() throws Exception { + System.out.println("Testing Java API for ioam pot plugin"); + try (final JVppRegistry registry = new JVppRegistryImpl("ioamPotApiExample"); + final JVpp jvpp = new JVppIoampotImpl()) { + registry.register(jvpp, new IoamPotTestCallback()); + + System.out.println("Sending ioam pot profile add request..."); + PotProfileAdd request = new PotProfileAdd(); + request.id = 0; + request.validator = 4; + request.secretKey = 1; + request.secretShare = 2; + request.prime = 1234; + request.maxBits = 53; + request.lpc = 1234; + request.polynomialPublic = 1234; + request.listNameLen = (byte)"test pot profile".getBytes(StandardCharsets.UTF_8).length; + request.listName = "test pot profile".getBytes(StandardCharsets.UTF_8); + final int result = jvpp.send(request); + System.out.printf("PotProfileAdd send result = %d%n", result); + + Thread.sleep(1000); + + System.out.println("Disconnecting..."); + } + } +} diff --git a/java/jvpp-ioampot/io/fd/jvpp/ioampot/examples/Readme.txt b/java/jvpp-ioampot/io/fd/jvpp/ioampot/examples/Readme.txt new file mode 100644 index 0000000..333fb90 --- /dev/null +++ b/java/jvpp-ioampot/io/fd/jvpp/ioampot/examples/Readme.txt @@ -0,0 +1,4 @@ +release version: +sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp-native/vpp/vpp-api/java/jvpp-ioampot-17.10.jar io.fd.jvpp.ioampot.examples.IoamPotApiExample +debug vresion: +sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-ioampot-17.10.jar io.fd.jvpp.ioampot.examples.IoamPotApiExample diff --git a/java/jvpp-ioampot/io/fd/jvpp/ioampot/test/CallbackApiTest.java b/java/jvpp-ioampot/io/fd/jvpp/ioampot/test/CallbackApiTest.java new file mode 100644 index 0000000..90dce0e --- /dev/null +++ b/java/jvpp-ioampot/io/fd/jvpp/ioampot/test/CallbackApiTest.java @@ -0,0 +1,33 @@ +/* + * 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 io.fd.jvpp.ioampot.test; + +import io.fd.jvpp.AbstractCallbackApiTest; +import io.fd.jvpp.ioampot.JVppIoampotImpl; + +import java.util.logging.Logger; + +public class CallbackApiTest extends AbstractCallbackApiTest { + + private static Logger LOG = Logger.getLogger(CallbackApiTest.class.getName()); + + + public static void main(String[] args) throws Exception { + LOG.info("Testing ControlPing using Java callback API for ioampot plugin"); + testControlPing(args[0], new JVppIoampotImpl()); + } +} diff --git a/java/jvpp-ioampot/io/fd/jvpp/ioampot/test/FutureApiTest.java b/java/jvpp-ioampot/io/fd/jvpp/ioampot/test/FutureApiTest.java new file mode 100644 index 0000000..5b3f284 --- /dev/null +++ b/java/jvpp-ioampot/io/fd/jvpp/ioampot/test/FutureApiTest.java @@ -0,0 +1,66 @@ +/* + * 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 io.fd.jvpp.ioampot.test; + + +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.JVppRegistryImpl; +import io.fd.jvpp.ioampot.JVppIoampotImpl; +import io.fd.jvpp.ioampot.dto.PotProfileShowConfigDetailsReplyDump; +import io.fd.jvpp.ioampot.dto.PotProfileShowConfigDump; +import io.fd.jvpp.ioampot.future.FutureJVppIoampotFacade; + +import java.util.concurrent.Future; +import java.util.logging.Logger; + +public class FutureApiTest { + + private static final Logger LOG = Logger.getLogger(io.fd.jvpp.ioampot.test.FutureApiTest.class.getName()); + + public static void main(String[] args) throws Exception { + testCallbackApi(args); + } + + private static void testCallbackApi(String[] args) throws Exception { + LOG.info("Testing Java callback API for ioampot plugin"); + try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiTest", args[0]); + final FutureJVppIoampotFacade jvpp = new FutureJVppIoampotFacade(registry, new JVppIoampotImpl())) { + LOG.info("Successfully connected to VPP"); + + testPotProfileShowConfigDump(jvpp); + + LOG.info("Disconnecting..."); + } + } + + private static void testPotProfileShowConfigDump(FutureJVppIoampotFacade jvpp) throws Exception { + LOG.info("Sending PotProfileShowConfigDump request..."); + final PotProfileShowConfigDump request = new PotProfileShowConfigDump(); + + final Future replyFuture = jvpp.potProfileShowConfigDump(request).toCompletableFuture(); + final PotProfileShowConfigDetailsReplyDump reply = replyFuture.get(); + + if (reply == null || reply.potProfileShowConfigDetails == null) { + throw new IllegalStateException("Received null response for empty dump: " + reply); + } else { + LOG.info( + String.format( + "Received pot profile show config dump reply: %s", + reply.potProfileShowConfigDetails)); + } + } +} diff --git a/java/jvpp-ioampot/io/fd/jvpp/ioampot/test/Readme.txt b/java/jvpp-ioampot/io/fd/jvpp/ioampot/test/Readme.txt new file mode 100644 index 0000000..5d31198 --- /dev/null +++ b/java/jvpp-ioampot/io/fd/jvpp/ioampot/test/Readme.txt @@ -0,0 +1,4 @@ +release version: +sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-ioampot-17.10.jar io.fd.jvpp.ioampot.test.[test-name] +debug version: +sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-ioampot-17.10.jar io.fd.jvpp.ioampot.test.[test-name] diff --git a/java/jvpp-ioampot/io/fd/vpp/jvpp/ioampot/examples/IoamPotApiExample.java b/java/jvpp-ioampot/io/fd/vpp/jvpp/ioampot/examples/IoamPotApiExample.java deleted file mode 100644 index b9ed7d0..0000000 --- a/java/jvpp-ioampot/io/fd/vpp/jvpp/ioampot/examples/IoamPotApiExample.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.ioampot.examples; - -import io.fd.vpp.jvpp.JVpp; -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.JVppRegistryImpl; -import io.fd.vpp.jvpp.VppCallbackException; -import io.fd.vpp.jvpp.ioampot.JVppIoampotImpl; -import io.fd.vpp.jvpp.ioampot.callback.PotProfileAddReplyCallback; -import io.fd.vpp.jvpp.ioampot.dto.PotProfileAdd; -import io.fd.vpp.jvpp.ioampot.dto.PotProfileAddReply; -import java.nio.charset.StandardCharsets; - -public class IoamPotApiExample { - - static class IoamPotTestCallback implements PotProfileAddReplyCallback { - - @Override - public void onPotProfileAddReply(final PotProfileAddReply reply) { - System.out.printf("Received PotProfileAddReply reply: context=%d%n", - reply.context); - } - - @Override - public void onError(VppCallbackException ex) { - System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(), - ex.getCtxId(), ex.getErrorCode()); - } - } - - public static void main(String[] args) throws Exception { - ioamPotTestApi(); - } - - private static void ioamPotTestApi() throws Exception { - System.out.println("Testing Java API for ioam pot plugin"); - try (final JVppRegistry registry = new JVppRegistryImpl("ioamPotApiExample"); - final JVpp jvpp = new JVppIoampotImpl()) { - registry.register(jvpp, new IoamPotTestCallback()); - - System.out.println("Sending ioam pot profile add request..."); - PotProfileAdd request = new PotProfileAdd(); - request.id = 0; - request.validator = 4; - request.secretKey = 1; - request.secretShare = 2; - request.prime = 1234; - request.maxBits = 53; - request.lpc = 1234; - request.polynomialPublic = 1234; - request.listNameLen = (byte)"test pot profile".getBytes(StandardCharsets.UTF_8).length; - request.listName = "test pot profile".getBytes(StandardCharsets.UTF_8); - final int result = jvpp.send(request); - System.out.printf("PotProfileAdd send result = %d%n", result); - - Thread.sleep(1000); - - System.out.println("Disconnecting..."); - } - } -} diff --git a/java/jvpp-ioampot/io/fd/vpp/jvpp/ioampot/examples/Readme.txt b/java/jvpp-ioampot/io/fd/vpp/jvpp/ioampot/examples/Readme.txt deleted file mode 100644 index e91550b..0000000 --- a/java/jvpp-ioampot/io/fd/vpp/jvpp/ioampot/examples/Readme.txt +++ /dev/null @@ -1,4 +0,0 @@ -release version: -sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp-native/vpp/vpp-api/java/jvpp-ioampot-17.10.jar io.fd.vpp.jvpp.ioampot.examples.IoamPotApiExample -debug vresion: -sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-ioampot-17.10.jar io.fd.vpp.jvpp.ioampot.examples.IoamPotApiExample diff --git a/java/jvpp-ioampot/io/fd/vpp/jvpp/ioampot/test/CallbackApiTest.java b/java/jvpp-ioampot/io/fd/vpp/jvpp/ioampot/test/CallbackApiTest.java deleted file mode 100644 index 20b85d8..0000000 --- a/java/jvpp-ioampot/io/fd/vpp/jvpp/ioampot/test/CallbackApiTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.ioampot.test; - -import io.fd.vpp.jvpp.AbstractCallbackApiTest; -import io.fd.vpp.jvpp.ioampot.JVppIoampotImpl; - -import java.util.logging.Logger; - -public class CallbackApiTest extends AbstractCallbackApiTest { - - private static Logger LOG = Logger.getLogger(CallbackApiTest.class.getName()); - - - public static void main(String[] args) throws Exception { - LOG.info("Testing ControlPing using Java callback API for ioampot plugin"); - testControlPing(args[0], new JVppIoampotImpl()); - } -} diff --git a/java/jvpp-ioampot/io/fd/vpp/jvpp/ioampot/test/FutureApiTest.java b/java/jvpp-ioampot/io/fd/vpp/jvpp/ioampot/test/FutureApiTest.java deleted file mode 100644 index 6401c67..0000000 --- a/java/jvpp-ioampot/io/fd/vpp/jvpp/ioampot/test/FutureApiTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.ioampot.test; - - -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.JVppRegistryImpl; -import io.fd.vpp.jvpp.ioampot.JVppIoampotImpl; -import io.fd.vpp.jvpp.ioampot.dto.PotProfileShowConfigDetailsReplyDump; -import io.fd.vpp.jvpp.ioampot.dto.PotProfileShowConfigDump; -import io.fd.vpp.jvpp.ioampot.future.FutureJVppIoampotFacade; - -import java.util.concurrent.Future; -import java.util.logging.Logger; - -public class FutureApiTest { - - private static final Logger LOG = Logger.getLogger(io.fd.vpp.jvpp.ioampot.test.FutureApiTest.class.getName()); - - public static void main(String[] args) throws Exception { - testCallbackApi(args); - } - - private static void testCallbackApi(String[] args) throws Exception { - LOG.info("Testing Java callback API for ioampot plugin"); - try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiTest", args[0]); - final FutureJVppIoampotFacade jvpp = new FutureJVppIoampotFacade(registry, new JVppIoampotImpl())) { - LOG.info("Successfully connected to VPP"); - - testPotProfileShowConfigDump(jvpp); - - LOG.info("Disconnecting..."); - } - } - - private static void testPotProfileShowConfigDump(FutureJVppIoampotFacade jvpp) throws Exception { - LOG.info("Sending PotProfileShowConfigDump request..."); - final PotProfileShowConfigDump request = new PotProfileShowConfigDump(); - - final Future replyFuture = jvpp.potProfileShowConfigDump(request).toCompletableFuture(); - final PotProfileShowConfigDetailsReplyDump reply = replyFuture.get(); - - if (reply == null || reply.potProfileShowConfigDetails == null) { - throw new IllegalStateException("Received null response for empty dump: " + reply); - } else { - LOG.info( - String.format( - "Received pot profile show config dump reply: %s", - reply.potProfileShowConfigDetails)); - } - } -} diff --git a/java/jvpp-ioampot/io/fd/vpp/jvpp/ioampot/test/Readme.txt b/java/jvpp-ioampot/io/fd/vpp/jvpp/ioampot/test/Readme.txt deleted file mode 100644 index f3cae26..0000000 --- a/java/jvpp-ioampot/io/fd/vpp/jvpp/ioampot/test/Readme.txt +++ /dev/null @@ -1,4 +0,0 @@ -release version: -sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-ioampot-17.10.jar io.fd.vpp.jvpp.ioampot.test.[test-name] -debug version: -sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-ioampot-17.10.jar io.fd.vpp.jvpp.ioampot.test.[test-name] diff --git a/java/jvpp-ioampot/jvpp_ioam_pot.c b/java/jvpp-ioampot/jvpp_ioam_pot.c index ce1da69..0fdf147 100644 --- a/java/jvpp-ioampot/jvpp_ioam_pot.c +++ b/java/jvpp-ioampot/jvpp_ioam_pot.c @@ -32,19 +32,19 @@ #include -#include "jvpp-ioampot/io_fd_vpp_jvpp_ioampot_JVppIoampotImpl.h" +#include "jvpp-ioampot/io_fd_jvpp_ioampot_JVppIoampotImpl.h" #include "jvpp_ioam_pot.h" #include "jvpp-ioampot/jvpp_ioampot_gen.h" /* - * Class: io_fd_vpp_jvpp_ioampot_JVppIoampotImpl + * Class: io_fd_jvpp_ioampot_JVppIoampotImpl * Method: init0 * Signature: (JI)V */ -JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_ioampot_JVppIoampotImpl_init0 +JNIEXPORT void JNICALL Java_io_fd_jvpp_ioampot_JVppIoampotImpl_init0 (JNIEnv *env, jclass clazz, jobject callback, jlong queue_address, jint my_client_index) { ioampot_main_t * plugin_main = &ioampot_main; - clib_warning ("Java_io_fd_vpp_jvpp_ioampot_JVppIoampotImpl_init0"); + clib_warning ("Java_io_fd_jvpp_ioampot_JVppIoampotImpl_init0"); plugin_main->my_client_index = my_client_index; plugin_main->vl_input_queue = uword_to_pointer (queue_address, svm_queue_t *); @@ -69,7 +69,7 @@ JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_ioampot_JVppIoampotImpl_init0 #undef _ } -JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_ioampot_JVppIoampotImpl_close0 +JNIEXPORT void JNICALL Java_io_fd_jvpp_ioampot_JVppIoampotImpl_close0 (JNIEnv *env, jclass clazz) { ioampot_main_t * plugin_main = &ioampot_main; diff --git a/java/jvpp-ioamtrace/io/fd/jvpp/ioamtrace/examples/IoamTraceApiExample.java b/java/jvpp-ioamtrace/io/fd/jvpp/ioamtrace/examples/IoamTraceApiExample.java new file mode 100644 index 0000000..d0adc4a --- /dev/null +++ b/java/jvpp-ioamtrace/io/fd/jvpp/ioamtrace/examples/IoamTraceApiExample.java @@ -0,0 +1,77 @@ +/* + * 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 io.fd.jvpp.ioamtrace.examples; + +import io.fd.jvpp.JVpp; +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.JVppRegistryImpl; +import io.fd.jvpp.VppCallbackException; +import io.fd.jvpp.ioamtrace.future.FutureJVppIoamtraceFacade; +import io.fd.jvpp.ioamtrace.JVppIoamtraceImpl; +import io.fd.jvpp.ioamtrace.callback.TraceProfileAddReplyCallback; +import io.fd.jvpp.ioamtrace.dto.TraceProfileAdd; +import io.fd.jvpp.ioamtrace.dto.TraceProfileAddReply; +import io.fd.jvpp.ioamtrace.dto.TraceProfileShowConfig; +import io.fd.jvpp.ioamtrace.dto.TraceProfileShowConfigReply; + +public class IoamTraceApiExample { + + static class IoamTraceTestCallback implements TraceProfileAddReplyCallback { + + @Override + public void onTraceProfileAddReply(final TraceProfileAddReply reply) { + System.out.printf("Received TraceProfileAddReply reply: context=%d%n", + reply.context); + } + + @Override + public void onError(VppCallbackException ex) { + System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(), + ex.getCtxId(), ex.getErrorCode()); + } + } + + public static void main(String[] args) throws Exception { + ioamTraceTestApi(); + } + + private static void ioamTraceTestApi() throws Exception { + System.out.println("Testing Java API for ioam trace plugin"); + try (final JVppRegistry registry = new JVppRegistryImpl("ioamTraceApiTest"); + final JVpp jvpp = new JVppIoamtraceImpl()) { + FutureJVppIoamtraceFacade ioamtraceJvpp = new FutureJVppIoamtraceFacade(registry,jvpp); + + System.out.println("Sending ioam trace profile add request..."); + TraceProfileAdd request = new TraceProfileAdd(); + request.traceType = 0x1f; + request.numElts = 4; + request.nodeId = 1; + request.traceTsp = 2; + request.appData = 1234; + final int result = jvpp.send(request); + System.out.printf("TraceProfileAdd send result = %d%n", result); + + Thread.sleep(1000); + + TraceProfileShowConfig showRequest = new TraceProfileShowConfig(); + TraceProfileShowConfigReply reply = ioamtraceJvpp.traceProfileShowConfig(showRequest).toCompletableFuture().get(); + System.out.printf("TraceProfileShowConfig result = "+ reply.toString()); + + System.out.println("Disconnecting..."); + } + } +} diff --git a/java/jvpp-ioamtrace/io/fd/jvpp/ioamtrace/examples/Readme.txt b/java/jvpp-ioamtrace/io/fd/jvpp/ioamtrace/examples/Readme.txt new file mode 100644 index 0000000..3d66388 --- /dev/null +++ b/java/jvpp-ioamtrace/io/fd/jvpp/ioamtrace/examples/Readme.txt @@ -0,0 +1,4 @@ +release version: +sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp-native/vpp/vpp-api/java/jvpp-ioamtrace-17.10.jar io.fd.jvpp.ioamtrace.examples.IoamTraceApiExample +debug vresion: +sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-ioamtrace-17.10.jar io.fd.jvpp.ioamtrace.examples.IoamTraceApiExample diff --git a/java/jvpp-ioamtrace/io/fd/jvpp/ioamtrace/test/CallbackApiTest.java b/java/jvpp-ioamtrace/io/fd/jvpp/ioamtrace/test/CallbackApiTest.java new file mode 100644 index 0000000..e932c29 --- /dev/null +++ b/java/jvpp-ioamtrace/io/fd/jvpp/ioamtrace/test/CallbackApiTest.java @@ -0,0 +1,33 @@ +/* + * 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 io.fd.jvpp.ioamtrace.test; + +import io.fd.jvpp.AbstractCallbackApiTest; +import io.fd.jvpp.ioamtrace.JVppIoamtraceImpl; + +import java.util.logging.Logger; + +public class CallbackApiTest extends AbstractCallbackApiTest { + + private static Logger LOG = Logger.getLogger(CallbackApiTest.class.getName()); + + + public static void main(String[] args) throws Exception { + LOG.info("Testing ControlPing using Java callback API for ioamtrace plugin"); + testControlPing(args[0], new JVppIoamtraceImpl()); + } +} diff --git a/java/jvpp-ioamtrace/io/fd/jvpp/ioamtrace/test/FutureApiTest.java b/java/jvpp-ioamtrace/io/fd/jvpp/ioamtrace/test/FutureApiTest.java new file mode 100644 index 0000000..92f54c4 --- /dev/null +++ b/java/jvpp-ioamtrace/io/fd/jvpp/ioamtrace/test/FutureApiTest.java @@ -0,0 +1,60 @@ +/* + * 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 io.fd.jvpp.ioamtrace.test; + + +import io.fd.jvpp.Assertions; +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.JVppRegistryImpl; +import io.fd.jvpp.ioamtrace.JVppIoamtraceImpl; +import io.fd.jvpp.ioamtrace.dto.TraceProfileShowConfig; +import io.fd.jvpp.ioamtrace.dto.TraceProfileShowConfigReply; +import io.fd.jvpp.ioamtrace.future.FutureJVppIoamtraceFacade; + +import java.util.concurrent.Future; +import java.util.logging.Logger; + +public class FutureApiTest { + + private static final Logger LOG = Logger.getLogger(io.fd.jvpp.ioamtrace.test.FutureApiTest.class.getName()); + + public static void main(String[] args) throws Exception { + testCallbackApi(args); + } + + private static void testCallbackApi(String[] args) throws Exception { + LOG.info("Testing Java callback API for ioamtrace plugin"); + try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiTest", args[0]); + final FutureJVppIoamtraceFacade jvpp = new FutureJVppIoamtraceFacade(registry, new JVppIoamtraceImpl())) { + LOG.info("Successfully connected to VPP"); + + testTraceProfileShowConfig(jvpp); + + LOG.info("Disconnecting..."); + } + } + + private static void testTraceProfileShowConfig(FutureJVppIoamtraceFacade jvpp) throws Exception { + LOG.info("Sending TraceProfileShowConfig request..."); + final TraceProfileShowConfig request = new TraceProfileShowConfig(); + + final Future replyFuture = jvpp.traceProfileShowConfig(request).toCompletableFuture(); + final TraceProfileShowConfigReply reply = replyFuture.get(); + + Assertions.assertNotNull(reply); + } +} diff --git a/java/jvpp-ioamtrace/io/fd/jvpp/ioamtrace/test/Readme.txt b/java/jvpp-ioamtrace/io/fd/jvpp/ioamtrace/test/Readme.txt new file mode 100644 index 0000000..15f3340 --- /dev/null +++ b/java/jvpp-ioamtrace/io/fd/jvpp/ioamtrace/test/Readme.txt @@ -0,0 +1,4 @@ +release version: +sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-ioamtrace-17.10.jar io.fd.jvpp.ioamtrace.test.[test-name] +debug version: +sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-ioamtrace-17.10.jar io.fd.jvpp.ioamtrace.test.[test-name] diff --git a/java/jvpp-ioamtrace/io/fd/vpp/jvpp/ioamtrace/examples/IoamTraceApiExample.java b/java/jvpp-ioamtrace/io/fd/vpp/jvpp/ioamtrace/examples/IoamTraceApiExample.java deleted file mode 100644 index d63d137..0000000 --- a/java/jvpp-ioamtrace/io/fd/vpp/jvpp/ioamtrace/examples/IoamTraceApiExample.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.ioamtrace.examples; - -import io.fd.vpp.jvpp.JVpp; -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.JVppRegistryImpl; -import io.fd.vpp.jvpp.VppCallbackException; -import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtraceFacade; -import io.fd.vpp.jvpp.ioamtrace.JVppIoamtraceImpl; -import io.fd.vpp.jvpp.ioamtrace.callback.TraceProfileAddReplyCallback; -import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAdd; -import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAddReply; -import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileShowConfig; -import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileShowConfigReply; - -public class IoamTraceApiExample { - - static class IoamTraceTestCallback implements TraceProfileAddReplyCallback { - - @Override - public void onTraceProfileAddReply(final TraceProfileAddReply reply) { - System.out.printf("Received TraceProfileAddReply reply: context=%d%n", - reply.context); - } - - @Override - public void onError(VppCallbackException ex) { - System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(), - ex.getCtxId(), ex.getErrorCode()); - } - } - - public static void main(String[] args) throws Exception { - ioamTraceTestApi(); - } - - private static void ioamTraceTestApi() throws Exception { - System.out.println("Testing Java API for ioam trace plugin"); - try (final JVppRegistry registry = new JVppRegistryImpl("ioamTraceApiTest"); - final JVpp jvpp = new JVppIoamtraceImpl()) { - FutureJVppIoamtraceFacade ioamtraceJvpp = new FutureJVppIoamtraceFacade(registry,jvpp); - - System.out.println("Sending ioam trace profile add request..."); - TraceProfileAdd request = new TraceProfileAdd(); - request.traceType = 0x1f; - request.numElts = 4; - request.nodeId = 1; - request.traceTsp = 2; - request.appData = 1234; - final int result = jvpp.send(request); - System.out.printf("TraceProfileAdd send result = %d%n", result); - - Thread.sleep(1000); - - TraceProfileShowConfig showRequest = new TraceProfileShowConfig(); - TraceProfileShowConfigReply reply = ioamtraceJvpp.traceProfileShowConfig(showRequest).toCompletableFuture().get(); - System.out.printf("TraceProfileShowConfig result = "+ reply.toString()); - - System.out.println("Disconnecting..."); - } - } -} diff --git a/java/jvpp-ioamtrace/io/fd/vpp/jvpp/ioamtrace/examples/Readme.txt b/java/jvpp-ioamtrace/io/fd/vpp/jvpp/ioamtrace/examples/Readme.txt deleted file mode 100644 index e8c3907..0000000 --- a/java/jvpp-ioamtrace/io/fd/vpp/jvpp/ioamtrace/examples/Readme.txt +++ /dev/null @@ -1,4 +0,0 @@ -release version: -sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp-native/vpp/vpp-api/java/jvpp-ioamtrace-17.10.jar io.fd.vpp.jvpp.ioamtrace.examples.IoamTraceApiExample -debug vresion: -sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-ioamtrace-17.10.jar io.fd.vpp.jvpp.ioamtrace.examples.IoamTraceApiExample diff --git a/java/jvpp-ioamtrace/io/fd/vpp/jvpp/ioamtrace/test/CallbackApiTest.java b/java/jvpp-ioamtrace/io/fd/vpp/jvpp/ioamtrace/test/CallbackApiTest.java deleted file mode 100644 index 4a71db5..0000000 --- a/java/jvpp-ioamtrace/io/fd/vpp/jvpp/ioamtrace/test/CallbackApiTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.ioamtrace.test; - -import io.fd.vpp.jvpp.AbstractCallbackApiTest; -import io.fd.vpp.jvpp.ioamtrace.JVppIoamtraceImpl; - -import java.util.logging.Logger; - -public class CallbackApiTest extends AbstractCallbackApiTest { - - private static Logger LOG = Logger.getLogger(CallbackApiTest.class.getName()); - - - public static void main(String[] args) throws Exception { - LOG.info("Testing ControlPing using Java callback API for ioamtrace plugin"); - testControlPing(args[0], new JVppIoamtraceImpl()); - } -} diff --git a/java/jvpp-ioamtrace/io/fd/vpp/jvpp/ioamtrace/test/FutureApiTest.java b/java/jvpp-ioamtrace/io/fd/vpp/jvpp/ioamtrace/test/FutureApiTest.java deleted file mode 100644 index 4e13ed1..0000000 --- a/java/jvpp-ioamtrace/io/fd/vpp/jvpp/ioamtrace/test/FutureApiTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.ioamtrace.test; - - -import io.fd.vpp.jvpp.Assertions; -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.JVppRegistryImpl; -import io.fd.vpp.jvpp.ioamtrace.JVppIoamtraceImpl; -import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileShowConfig; -import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileShowConfigReply; -import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtraceFacade; - -import java.util.concurrent.Future; -import java.util.logging.Logger; - -public class FutureApiTest { - - private static final Logger LOG = Logger.getLogger(io.fd.vpp.jvpp.ioamtrace.test.FutureApiTest.class.getName()); - - public static void main(String[] args) throws Exception { - testCallbackApi(args); - } - - private static void testCallbackApi(String[] args) throws Exception { - LOG.info("Testing Java callback API for ioamtrace plugin"); - try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiTest", args[0]); - final FutureJVppIoamtraceFacade jvpp = new FutureJVppIoamtraceFacade(registry, new JVppIoamtraceImpl())) { - LOG.info("Successfully connected to VPP"); - - testTraceProfileShowConfig(jvpp); - - LOG.info("Disconnecting..."); - } - } - - private static void testTraceProfileShowConfig(FutureJVppIoamtraceFacade jvpp) throws Exception { - LOG.info("Sending TraceProfileShowConfig request..."); - final TraceProfileShowConfig request = new TraceProfileShowConfig(); - - final Future replyFuture = jvpp.traceProfileShowConfig(request).toCompletableFuture(); - final TraceProfileShowConfigReply reply = replyFuture.get(); - - Assertions.assertNotNull(reply); - } -} diff --git a/java/jvpp-ioamtrace/io/fd/vpp/jvpp/ioamtrace/test/Readme.txt b/java/jvpp-ioamtrace/io/fd/vpp/jvpp/ioamtrace/test/Readme.txt deleted file mode 100644 index 9a1ba82..0000000 --- a/java/jvpp-ioamtrace/io/fd/vpp/jvpp/ioamtrace/test/Readme.txt +++ /dev/null @@ -1,4 +0,0 @@ -release version: -sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-ioamtrace-17.10.jar io.fd.vpp.jvpp.ioamtrace.test.[test-name] -debug version: -sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-ioamtrace-17.10.jar io.fd.vpp.jvpp.ioamtrace.test.[test-name] diff --git a/java/jvpp-ioamtrace/jvpp_ioam_trace.c b/java/jvpp-ioamtrace/jvpp_ioam_trace.c index 3532d91..e793dcd 100644 --- a/java/jvpp-ioamtrace/jvpp_ioam_trace.c +++ b/java/jvpp-ioamtrace/jvpp_ioam_trace.c @@ -32,19 +32,19 @@ #include -#include "jvpp-ioamtrace/io_fd_vpp_jvpp_ioamtrace_JVppIoamtraceImpl.h" +#include "jvpp-ioamtrace/io_fd_jvpp_ioamtrace_JVppIoamtraceImpl.h" #include "jvpp_ioam_trace.h" #include "jvpp-ioamtrace/jvpp_ioamtrace_gen.h" /* - * Class: io_fd_vpp_jvpp_ioamtrace_JVppIoamtraceImpl + * Class: io_fd_jvpp_ioamtrace_JVppIoamtraceImpl * Method: init0 * Signature: (JI)V */ -JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_ioamtrace_JVppIoamtraceImpl_init0 +JNIEXPORT void JNICALL Java_io_fd_jvpp_ioamtrace_JVppIoamtraceImpl_init0 (JNIEnv *env, jclass clazz, jobject callback, jlong queue_address, jint my_client_index) { ioamtrace_main_t * plugin_main = &ioamtrace_main; - clib_warning ("Java_io_fd_vpp_jvpp_ioamtrace_JVppIoamtraceImpl_init0"); + clib_warning ("Java_io_fd_jvpp_ioamtrace_JVppIoamtraceImpl_init0"); plugin_main->my_client_index = my_client_index; plugin_main->vl_input_queue = uword_to_pointer (queue_address, svm_queue_t *); @@ -69,7 +69,7 @@ JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_ioamtrace_JVppIoamtraceImpl_init0 #undef _ } -JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_ioamtrace_JVppIoamtraceImpl_close0 +JNIEXPORT void JNICALL Java_io_fd_jvpp_ioamtrace_JVppIoamtraceImpl_close0 (JNIEnv *env, jclass clazz) { ioamtrace_main_t * plugin_main = &ioamtrace_main; diff --git a/java/jvpp-nat/io/fd/jvpp/nat/examples/CallbackApiExample.java b/java/jvpp-nat/io/fd/jvpp/nat/examples/CallbackApiExample.java new file mode 100644 index 0000000..93fd308 --- /dev/null +++ b/java/jvpp-nat/io/fd/jvpp/nat/examples/CallbackApiExample.java @@ -0,0 +1,68 @@ +/* + * 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 io.fd.jvpp.nat.examples; + +import io.fd.jvpp.JVpp; +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.JVppRegistryImpl; +import io.fd.jvpp.VppCallbackException; +import io.fd.jvpp.nat.JVppNatImpl; +import io.fd.jvpp.nat.callback.Nat44InterfaceAddDelFeatureReplyCallback; +import io.fd.jvpp.nat.dto.Nat44InterfaceAddDelFeature; +import io.fd.jvpp.nat.dto.Nat44InterfaceAddDelFeatureReply; + +public class CallbackApiExample { + + static class TestCallback implements Nat44InterfaceAddDelFeatureReplyCallback { + + @Override + public void onNat44InterfaceAddDelFeatureReply(final Nat44InterfaceAddDelFeatureReply msg) { + System.out.printf("Received Nat44InterfaceAddDelFeatureReply: context=%d%n", + msg.context); + } + + @Override + public void onError(VppCallbackException ex) { + System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(), + ex.getCtxId(), ex.getErrorCode()); + } + } + + public static void main(String[] args) throws Exception { + testCallbackApi(); + } + + private static void testCallbackApi() throws Exception { + System.out.println("Testing Java callback API for nat plugin"); + try (final JVppRegistry registry = new JVppRegistryImpl("NatCallbackApiTest"); + final JVpp jvpp = new JVppNatImpl()) { + registry.register(jvpp, new TestCallback()); + + System.out.println("Sending Nat44InterfaceAddDelFeature request..."); + Nat44InterfaceAddDelFeature request = new Nat44InterfaceAddDelFeature(); + request.isAdd = 1; + request.isInside = 1; + request.swIfIndex = 1; + final int result = jvpp.send(request); + System.out.printf("Nat44InterfaceAddDelFeature send result = %d%n", result); + + Thread.sleep(1000); + + System.out.println("Disconnecting..."); + } + } +} diff --git a/java/jvpp-nat/io/fd/jvpp/nat/examples/Readme.txt b/java/jvpp-nat/io/fd/jvpp/nat/examples/Readme.txt new file mode 100644 index 0000000..3ae52d8 --- /dev/null +++ b/java/jvpp-nat/io/fd/jvpp/nat/examples/Readme.txt @@ -0,0 +1 @@ +sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp-native/vpp/vpp-api/java/jvpp-nat-17.10.jar io.fd.jvpp.nat.examples.CallbackApiExample diff --git a/java/jvpp-nat/io/fd/jvpp/nat/test/CallbackApiTest.java b/java/jvpp-nat/io/fd/jvpp/nat/test/CallbackApiTest.java new file mode 100644 index 0000000..dfa3816 --- /dev/null +++ b/java/jvpp-nat/io/fd/jvpp/nat/test/CallbackApiTest.java @@ -0,0 +1,33 @@ +/* + * 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 io.fd.jvpp.nat.test; + +import io.fd.jvpp.AbstractCallbackApiTest; +import io.fd.jvpp.nat.JVppNatImpl; + +import java.util.logging.Logger; + +public class CallbackApiTest extends AbstractCallbackApiTest { + + private static Logger LOG = Logger.getLogger(CallbackApiTest.class.getName()); + + + public static void main(String[] args) throws Exception { + LOG.info("Testing ControlPing using Java callback API for core plugin"); + testControlPing(args[0], new JVppNatImpl()); + } +} diff --git a/java/jvpp-nat/io/fd/jvpp/nat/test/FutureApiTest.java b/java/jvpp-nat/io/fd/jvpp/nat/test/FutureApiTest.java new file mode 100644 index 0000000..529dedf --- /dev/null +++ b/java/jvpp-nat/io/fd/jvpp/nat/test/FutureApiTest.java @@ -0,0 +1,66 @@ +/* + * 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 io.fd.jvpp.nat.test; + + +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.JVppRegistryImpl; +import io.fd.jvpp.nat.JVppNatImpl; +import io.fd.jvpp.nat.dto.Nat44AddressDetailsReplyDump; +import io.fd.jvpp.nat.dto.Nat44AddressDump; +import io.fd.jvpp.nat.future.FutureJVppNatFacade; + +import java.util.concurrent.Future; +import java.util.logging.Logger; + +public class FutureApiTest { + + private static final Logger LOG = Logger.getLogger(io.fd.jvpp.nat.test.FutureApiTest.class.getName()); + + public static void main(String[] args) throws Exception { + testCallbackApi(args); + } + + private static void testCallbackApi(String[] args) throws Exception { + LOG.info("Testing Java callback API for nat plugin"); + try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiTest", args[0]); + final FutureJVppNatFacade jvpp = new FutureJVppNatFacade(registry, new JVppNatImpl())) { + LOG.info("Successfully connected to VPP"); + + testAclDump(jvpp); + + LOG.info("Disconnecting..."); + } + } + + private static void testAclDump(FutureJVppNatFacade jvpp) throws Exception { + LOG.info("Sending Nat44AddressDump request..."); + final Nat44AddressDump request = new Nat44AddressDump(); + + final Future replyFuture = jvpp.nat44AddressDump(request).toCompletableFuture(); + final Nat44AddressDetailsReplyDump reply = replyFuture.get(); + + if (reply == null || reply.nat44AddressDetails == null) { + throw new IllegalStateException("Received null response for empty dump: " + reply); + } else { + LOG.info( + String.format( + "Received nat address dump reply with list of nat address: %s", + reply.nat44AddressDetails)); + } + } +} diff --git a/java/jvpp-nat/io/fd/jvpp/nat/test/Readme.txt b/java/jvpp-nat/io/fd/jvpp/nat/test/Readme.txt new file mode 100644 index 0000000..7885638 --- /dev/null +++ b/java/jvpp-nat/io/fd/jvpp/nat/test/Readme.txt @@ -0,0 +1,4 @@ +release version: +sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-nat-17.10.jar io.fd.jvpp.nat.test.[test-name] +debug version: +sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-nat-17.10.jar io.fd.jvpp.nat.test.[test-name] diff --git a/java/jvpp-nat/io/fd/vpp/jvpp/nat/examples/CallbackApiExample.java b/java/jvpp-nat/io/fd/vpp/jvpp/nat/examples/CallbackApiExample.java deleted file mode 100644 index e0d93ff..0000000 --- a/java/jvpp-nat/io/fd/vpp/jvpp/nat/examples/CallbackApiExample.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.nat.examples; - -import io.fd.vpp.jvpp.JVpp; -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.JVppRegistryImpl; -import io.fd.vpp.jvpp.VppCallbackException; -import io.fd.vpp.jvpp.nat.JVppNatImpl; -import io.fd.vpp.jvpp.nat.callback.Nat44InterfaceAddDelFeatureReplyCallback; -import io.fd.vpp.jvpp.nat.dto.Nat44InterfaceAddDelFeature; -import io.fd.vpp.jvpp.nat.dto.Nat44InterfaceAddDelFeatureReply; - -public class CallbackApiExample { - - static class TestCallback implements Nat44InterfaceAddDelFeatureReplyCallback { - - @Override - public void onNat44InterfaceAddDelFeatureReply(final Nat44InterfaceAddDelFeatureReply msg) { - System.out.printf("Received Nat44InterfaceAddDelFeatureReply: context=%d%n", - msg.context); - } - - @Override - public void onError(VppCallbackException ex) { - System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(), - ex.getCtxId(), ex.getErrorCode()); - } - } - - public static void main(String[] args) throws Exception { - testCallbackApi(); - } - - private static void testCallbackApi() throws Exception { - System.out.println("Testing Java callback API for nat plugin"); - try (final JVppRegistry registry = new JVppRegistryImpl("NatCallbackApiTest"); - final JVpp jvpp = new JVppNatImpl()) { - registry.register(jvpp, new TestCallback()); - - System.out.println("Sending Nat44InterfaceAddDelFeature request..."); - Nat44InterfaceAddDelFeature request = new Nat44InterfaceAddDelFeature(); - request.isAdd = 1; - request.isInside = 1; - request.swIfIndex = 1; - final int result = jvpp.send(request); - System.out.printf("Nat44InterfaceAddDelFeature send result = %d%n", result); - - Thread.sleep(1000); - - System.out.println("Disconnecting..."); - } - } -} diff --git a/java/jvpp-nat/io/fd/vpp/jvpp/nat/examples/Readme.txt b/java/jvpp-nat/io/fd/vpp/jvpp/nat/examples/Readme.txt deleted file mode 100644 index ac75e04..0000000 --- a/java/jvpp-nat/io/fd/vpp/jvpp/nat/examples/Readme.txt +++ /dev/null @@ -1 +0,0 @@ -sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp-native/vpp/vpp-api/java/jvpp-nat-17.10.jar io.fd.vpp.jvpp.nat.examples.CallbackApiExample diff --git a/java/jvpp-nat/io/fd/vpp/jvpp/nat/test/CallbackApiTest.java b/java/jvpp-nat/io/fd/vpp/jvpp/nat/test/CallbackApiTest.java deleted file mode 100644 index a6f8214..0000000 --- a/java/jvpp-nat/io/fd/vpp/jvpp/nat/test/CallbackApiTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.nat.test; - -import io.fd.vpp.jvpp.AbstractCallbackApiTest; -import io.fd.vpp.jvpp.nat.JVppNatImpl; - -import java.util.logging.Logger; - -public class CallbackApiTest extends AbstractCallbackApiTest { - - private static Logger LOG = Logger.getLogger(CallbackApiTest.class.getName()); - - - public static void main(String[] args) throws Exception { - LOG.info("Testing ControlPing using Java callback API for core plugin"); - testControlPing(args[0], new JVppNatImpl()); - } -} diff --git a/java/jvpp-nat/io/fd/vpp/jvpp/nat/test/FutureApiTest.java b/java/jvpp-nat/io/fd/vpp/jvpp/nat/test/FutureApiTest.java deleted file mode 100644 index 26d6b98..0000000 --- a/java/jvpp-nat/io/fd/vpp/jvpp/nat/test/FutureApiTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.nat.test; - - -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.JVppRegistryImpl; -import io.fd.vpp.jvpp.nat.JVppNatImpl; -import io.fd.vpp.jvpp.nat.dto.Nat44AddressDetailsReplyDump; -import io.fd.vpp.jvpp.nat.dto.Nat44AddressDump; -import io.fd.vpp.jvpp.nat.future.FutureJVppNatFacade; - -import java.util.concurrent.Future; -import java.util.logging.Logger; - -public class FutureApiTest { - - private static final Logger LOG = Logger.getLogger(io.fd.vpp.jvpp.nat.test.FutureApiTest.class.getName()); - - public static void main(String[] args) throws Exception { - testCallbackApi(args); - } - - private static void testCallbackApi(String[] args) throws Exception { - LOG.info("Testing Java callback API for nat plugin"); - try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiTest", args[0]); - final FutureJVppNatFacade jvpp = new FutureJVppNatFacade(registry, new JVppNatImpl())) { - LOG.info("Successfully connected to VPP"); - - testAclDump(jvpp); - - LOG.info("Disconnecting..."); - } - } - - private static void testAclDump(FutureJVppNatFacade jvpp) throws Exception { - LOG.info("Sending Nat44AddressDump request..."); - final Nat44AddressDump request = new Nat44AddressDump(); - - final Future replyFuture = jvpp.nat44AddressDump(request).toCompletableFuture(); - final Nat44AddressDetailsReplyDump reply = replyFuture.get(); - - if (reply == null || reply.nat44AddressDetails == null) { - throw new IllegalStateException("Received null response for empty dump: " + reply); - } else { - LOG.info( - String.format( - "Received nat address dump reply with list of nat address: %s", - reply.nat44AddressDetails)); - } - } -} diff --git a/java/jvpp-nat/io/fd/vpp/jvpp/nat/test/Readme.txt b/java/jvpp-nat/io/fd/vpp/jvpp/nat/test/Readme.txt deleted file mode 100644 index 6f75808..0000000 --- a/java/jvpp-nat/io/fd/vpp/jvpp/nat/test/Readme.txt +++ /dev/null @@ -1,4 +0,0 @@ -release version: -sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-nat-17.10.jar io.fd.vpp.jvpp.nat.test.[test-name] -debug version: -sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-nat-17.10.jar io.fd.vpp.jvpp.nat.test.[test-name] diff --git a/java/jvpp-nat/jvpp_nat.c b/java/jvpp-nat/jvpp_nat.c index bdae1e6..20e4244 100644 --- a/java/jvpp-nat/jvpp_nat.c +++ b/java/jvpp-nat/jvpp_nat.c @@ -32,19 +32,19 @@ #include -#include "jvpp-nat/io_fd_vpp_jvpp_nat_JVppNatImpl.h" +#include "jvpp-nat/io_fd_jvpp_nat_JVppNatImpl.h" #include "jvpp_nat.h" #include "jvpp-nat/jvpp_nat_gen.h" /* - * Class: io_fd_vpp_jvpp_nat_JVppNatImpl + * Class: io_fd_jvpp_nat_JVppNatImpl * Method: init0 * Signature: (JI)V */ -JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_nat_JVppNatImpl_init0 +JNIEXPORT void JNICALL Java_io_fd_jvpp_nat_JVppNatImpl_init0 (JNIEnv *env, jclass clazz, jobject callback, jlong queue_address, jint my_client_index) { nat_main_t * plugin_main = &nat_main; - clib_warning ("Java_io_fd_vpp_jvpp_nat_JVppNatImpl_init0"); + clib_warning ("Java_io_fd_jvpp_nat_JVppNatImpl_init0"); plugin_main->my_client_index = my_client_index; plugin_main->vl_input_queue = uword_to_pointer (queue_address, svm_queue_t *); @@ -69,7 +69,7 @@ JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_nat_JVppNatImpl_init0 #undef _ } -JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_nat_JVppNatImpl_close0 +JNIEXPORT void JNICALL Java_io_fd_jvpp_nat_JVppNatImpl_close0 (JNIEnv *env, jclass clazz) { nat_main_t * plugin_main = &nat_main; diff --git a/java/jvpp-nsh/jvpp_nsh.c b/java/jvpp-nsh/jvpp_nsh.c index 1736ce7..e220d9a 100644 --- a/java/jvpp-nsh/jvpp_nsh.c +++ b/java/jvpp-nsh/jvpp_nsh.c @@ -31,19 +31,19 @@ #include -#include "jvpp-nsh/io_fd_vpp_jvpp_nsh_JVppNshImpl.h" +#include "jvpp-nsh/io_fd_jvpp_nsh_JVppNshImpl.h" #include "jvpp_nsh.h" #include "jvpp-nsh/jvpp_nsh_gen.h" /* - * Class: io_fd_vpp_jvpp_nsh_JVppnshImpl + * Class: io_fd_jvpp_nsh_JVppnshImpl * Method: init0 * Signature: (JI)V */ -JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_nsh_JVppNshImpl_init0 +JNIEXPORT void JNICALL Java_io_fd_jvpp_nsh_JVppNshImpl_init0 (JNIEnv *env, jclass clazz, jobject callback, jlong queue_address, jint my_client_index) { nsh_main_t * plugin_main = &nsh_main; - clib_warning ("Java_io_fd_vpp_jvpp_nsh_JVppNshImpl_init0"); + clib_warning ("Java_io_fd_jvpp_nsh_JVppNshImpl_init0"); plugin_main->my_client_index = my_client_index; plugin_main->vl_input_queue = (svm_queue_t *)queue_address; @@ -68,7 +68,7 @@ JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_nsh_JVppNshImpl_init0 #undef _ } -JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_nsh_JVppNshImpl_close0 +JNIEXPORT void JNICALL Java_io_fd_jvpp_nsh_JVppNshImpl_close0 (JNIEnv *env, jclass clazz) { nsh_main_t * plugin_main = &nsh_main; diff --git a/java/jvpp-pppoe/jvpp_pppoe.c b/java/jvpp-pppoe/jvpp_pppoe.c index 02bd20e..552ba5d 100644 --- a/java/jvpp-pppoe/jvpp_pppoe.c +++ b/java/jvpp-pppoe/jvpp_pppoe.c @@ -32,19 +32,19 @@ #include -#include "jvpp-pppoe/io_fd_vpp_jvpp_pppoe_JVppPppoeImpl.h" +#include "jvpp-pppoe/io_fd_jvpp_pppoe_JVppPppoeImpl.h" #include "jvpp_pppoe.h" #include "jvpp-pppoe/jvpp_pppoe_gen.h" /* - * Class: io_fd_vpp_jvpp_pppoe_JVpppppoeImpl + * Class: io_fd_jvpp_pppoe_JVpppppoeImpl * Method: init0 * Signature: (JI)V */ -JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_pppoe_JVppPppoeImpl_init0 +JNIEXPORT void JNICALL Java_io_fd_jvpp_pppoe_JVppPppoeImpl_init0 (JNIEnv *env, jclass clazz, jobject callback, jlong queue_address, jint my_client_index) { pppoe_main_t * plugin_main = &pppoe_main; - clib_warning ("Java_io_fd_vpp_jvpp_pppoe_JVppPppoeImpl_init0"); + clib_warning ("Java_io_fd_jvpp_pppoe_JVppPppoeImpl_init0"); plugin_main->my_client_index = my_client_index; plugin_main->vl_input_queue = (svm_queue_t *)queue_address; @@ -69,7 +69,7 @@ JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_pppoe_JVppPppoeImpl_init0 #undef _ } -JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_pppoe_JVppPppoeImpl_close0 +JNIEXPORT void JNICALL Java_io_fd_jvpp_pppoe_JVppPppoeImpl_close0 (JNIEnv *env, jclass clazz) { pppoe_main_t * plugin_main = &pppoe_main; diff --git a/java/jvpp-registry/io/fd/jvpp/AbstractCallbackApiTest.java b/java/jvpp-registry/io/fd/jvpp/AbstractCallbackApiTest.java new file mode 100644 index 0000000..a2e38e1 --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/AbstractCallbackApiTest.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2017 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 io.fd.jvpp; + +import io.fd.jvpp.callback.ControlPingCallback; +import io.fd.jvpp.dto.ControlPing; +import io.fd.jvpp.dto.ControlPingReply; + +public abstract class AbstractCallbackApiTest { + + private static int receivedPingCount = 0; + private static int errorPingCount = 0; + + public static void testControlPing(String shm_prefix, JVpp jvpp) throws Exception { + try (JVppRegistry registry = new JVppRegistryImpl("CallbackApiTest", shm_prefix)) { + + registry.register(jvpp, new ControlPingCallback() { + @Override + public void onControlPingReply(final ControlPingReply reply) { + System.out.printf("Received ControlPingReply: %s%n", reply); + receivedPingCount++; + } + + @Override + public void onError(VppCallbackException ex) { + System.out.printf("Received onError exception: call=%s, reply=%d, context=%d ", ex.getMethodName(), + ex.getErrorCode(), ex.getCtxId()); + errorPingCount++; + } + + }); + System.out.println("Successfully connected to VPP"); + Thread.sleep(1000); + + System.out.println("Sending control ping using JVppRegistry"); + registry.controlPing(jvpp.getClass()); + + Thread.sleep(2000); + + System.out.println("Sending control ping using JVpp plugin"); + jvpp.send(new ControlPing()); + + Thread.sleep(2000); + System.out.println("Disconnecting..."); + Assertions.assertEquals(2, receivedPingCount); + Assertions.assertEquals(0, errorPingCount); + } + } +} diff --git a/java/jvpp-registry/io/fd/jvpp/Assertions.java b/java/jvpp-registry/io/fd/jvpp/Assertions.java new file mode 100644 index 0000000..2a403ad --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/Assertions.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2017 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 io.fd.jvpp; + +public class Assertions { + + public static void assertEquals(final int expected, final int actual) { + if (expected != actual) { + throw new IllegalArgumentException(String.format("Expected[%s]/Actual[%s]", expected, actual)); + } + } + + public static void assertNotNull(final Object value) { + if (value == null) { + throw new IllegalArgumentException("Variable is null"); + } + } +} diff --git a/java/jvpp-registry/io/fd/jvpp/JVpp.java b/java/jvpp-registry/io/fd/jvpp/JVpp.java new file mode 100644 index 0000000..251b0a7 --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/JVpp.java @@ -0,0 +1,56 @@ +/* + * 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 io.fd.jvpp; + +import io.fd.jvpp.callback.JVppCallback; +import io.fd.jvpp.dto.ControlPing; +import io.fd.jvpp.dto.JVppRequest; + +/** + * Base interface for plugin's Java API. + */ +public interface JVpp extends AutoCloseable { + + /** + * Sends request to vpp. + * + * @param request request to be sent + * @return unique identifer of message in message queue + * @throws VppInvocationException when message could not be sent + */ + int send(final JVppRequest request) throws VppInvocationException; + + /** + * Initializes plugin's Java API. + * + * @param registry plugin registry + * @param callback called by vpe.api message handlers + * @param queueAddress address of vpp shared memory queue + * @param clientIndex vpp client identifier + */ + void init(final JVppRegistry registry, final JVppCallback callback, final long queueAddress, + final int clientIndex); + + /** + * Sends control_ping message. + * + * @param controlPing request DTO + * @return unique identifer of message in message queue + * @throws VppInvocationException when message could not be sent + */ + int controlPing(final ControlPing controlPing) throws VppInvocationException; +} diff --git a/java/jvpp-registry/io/fd/jvpp/JVppRegistry.java b/java/jvpp-registry/io/fd/jvpp/JVppRegistry.java new file mode 100644 index 0000000..f182a0a --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/JVppRegistry.java @@ -0,0 +1,76 @@ +/* + * 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 io.fd.jvpp; + +import io.fd.jvpp.callback.JVppCallback; + +/** + * Manages VPP connection and stores plugin callbacks. + */ +public interface JVppRegistry extends AutoCloseable { + + /** + * Vpp connection managed by the registry. + * + * @return representation of vpp connection + */ + VppConnection getConnection(); + + /** + * Registers callback and initializes Java API for given plugin. + * + * @param jvpp plugin name + * @param callback callback provided by the plugin + * @throws NullPointerException if name or callback is null + * @throws IllegalArgumentException if plugin was already registered + */ + void register(final JVpp jvpp, final JVppCallback callback); + + /** + * Unregisters callback for the given plugin. + * + * @param name plugin name + * @throws NullPointerException if name is null + * @throws IllegalArgumentException if plugin was not registered + */ + void unregister(final String name); + + /** + * Returns callback registered for the plugin. + * + * @param name plugin name + * @return callback provided by the plugin + * @throws NullPointerException if name is null + * @throws IllegalArgumentException if plugin was not registered + */ + JVppCallback get(final String name); + + /** + * Sends control ping. Reply handler calls callback registered for give plugin. + * + * Control ping is used for initial RX thread to Java thread attachment + * that takes place in the plugin's JNI lib + * and to wrap dump message replies in one list. + * + * VPP plugins don't have to provide special control ping, therefore + * it is necessary to providing control ping support in JVppRegistry. + + * @param clazz identifies plugin that should receive ping callback + * @return unique identifier of message in message queue + */ + int controlPing(final Class clazz) throws VppInvocationException; +} diff --git a/java/jvpp-registry/io/fd/jvpp/JVppRegistryImpl.java b/java/jvpp-registry/io/fd/jvpp/JVppRegistryImpl.java new file mode 100644 index 0000000..7caa64c --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/JVppRegistryImpl.java @@ -0,0 +1,187 @@ +/* + * 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 io.fd.jvpp; + +import static java.util.Objects.requireNonNull; + +import io.fd.jvpp.callback.ControlPingCallback; +import io.fd.jvpp.callback.JVppCallback; +import io.fd.jvpp.dto.ControlPingReply; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Default implementation of JVppRegistry. + */ +public final class JVppRegistryImpl implements JVppRegistry, ControlPingCallback { + + private static final Logger LOG = Logger.getLogger(JVppRegistryImpl.class.getName()); + + private final VppJNIConnection connection; + // Unguarded concurrent map, no race conditions expected on top of that + private final Map pluginRegistry; + // Guarded by self + private final Map pingCalls; + + public JVppRegistryImpl(final String clientName) throws IOException { + connection = new VppJNIConnection(clientName); + connection.connect(); + pluginRegistry = new ConcurrentHashMap<>(); + pingCalls = new HashMap<>(); + } + + public JVppRegistryImpl(final String clientName, final String shmPrefix) throws IOException { + connection = new VppJNIConnection(clientName, shmPrefix); + connection.connect(); + pluginRegistry = new ConcurrentHashMap<>(); + pingCalls = new HashMap<>(); + } + + @Override + public VppConnection getConnection() { + return connection; + } + + @Override + public void register(final JVpp jvpp, final JVppCallback callback) { + requireNonNull(jvpp, "jvpp should not be null"); + requireNonNull(callback, "Callback should not be null"); + final String name = jvpp.getClass().getName(); + if (pluginRegistry.containsKey(name)) { + throw new IllegalArgumentException( + String.format("Callback for plugin %s was already registered", name)); + } + jvpp.init(this, callback, connection.getConnectionInfo().queueAddress, + connection.getConnectionInfo().clientIndex); + pluginRegistry.put(name, callback); + } + + @Override + public void unregister(final String name) { + requireNonNull(name, "Plugin name should not be null"); + final JVppCallback previous = pluginRegistry.remove(name); + assertPluginWasRegistered(name, previous); + } + + @Override + public JVppCallback get(final String name) { + requireNonNull(name, "Plugin name should not be null"); + JVppCallback value = pluginRegistry.get(name); + assertPluginWasRegistered(name, value); + return value; + } + + private native int controlPing0() throws VppInvocationException; + + @Override + public int controlPing(final Class clazz) throws VppInvocationException { + connection.checkActive(); + final String name = clazz.getName(); + + final ControlPingCallback callback = (ControlPingCallback) pluginRegistry.get(clazz.getName()); + assertPluginWasRegistered(name, callback); + + // controlPing0 is sending function and can go to waiting in case of e. g. full queue + // because of that it cant be in same synchronization block as used by reply handler function + int context = controlPing0(); + if (context < 0) { + throw new VppInvocationException("controlPing", context); + } + + synchronized (pingCalls) { + // if callback is in map it's because reply was already received + EarlyControlPingReply earlyReplyCallback = (EarlyControlPingReply) pingCalls.remove(context); + if(earlyReplyCallback == null) { + pingCalls.put(context, callback); + } else { + callback.onControlPingReply(earlyReplyCallback.getReply()); + } + } + + return context; + } + + @Override + public void onControlPingReply(final ControlPingReply reply) { + final ControlPingCallback callback; + synchronized (pingCalls) { + callback = pingCalls.remove(reply.context); + if (callback == null) { + // reply received early, because we don't know callback to call + // we wrap the reply and let the sender to call it + pingCalls.put(reply.context, new EarlyControlPingReply(reply)); + return; + } + } + // pass the reply to the callback registered by the ping caller + callback.onControlPingReply(reply); + } + + @Override + public void onError(final VppCallbackException ex) { + final int ctxId = ex.getCtxId(); + final ControlPingCallback callback; + + synchronized (pingCalls) { + callback = pingCalls.get(ctxId); + } + if (callback == null) { + LOG.log(Level.WARNING, "No callback was registered for reply id={0} ", ctxId); + return; + } + // pass the error to the callback registered by the ping caller + callback.onError(ex); + } + + private static void assertPluginWasRegistered(final String name, final JVppCallback value) { + if (value == null) { + throw new IllegalArgumentException(String.format("Callback for plugin %s is not registered", name)); + } + } + + @Override + public void close() throws Exception { + connection.close(); + } + + private static class EarlyControlPingReply implements ControlPingCallback { + + private final ControlPingReply reply; + + public EarlyControlPingReply(final ControlPingReply reply) { + this.reply = reply; + } + + public ControlPingReply getReply() { + return reply; + } + + @Override + public void onError(VppCallbackException ex) { + throw new IllegalStateException("Calling onError in EarlyControlPingReply"); + } + + @Override + public void onControlPingReply(ControlPingReply reply) { + throw new IllegalStateException("Calling onControlPingReply in EarlyControlPingReply"); + } + } +} diff --git a/java/jvpp-registry/io/fd/jvpp/NativeLibraryLoader.java b/java/jvpp-registry/io/fd/jvpp/NativeLibraryLoader.java new file mode 100644 index 0000000..54097f1 --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/NativeLibraryLoader.java @@ -0,0 +1,73 @@ +/* + * 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 io.fd.jvpp; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Utility class for loading JNI libraries. + */ +public final class NativeLibraryLoader { + + private static final Logger LOG = Logger.getLogger(NativeLibraryLoader.class.getName()); + + private NativeLibraryLoader() { + throw new UnsupportedOperationException("This utility class cannot be instantiated."); + } + + /** + * Loads JNI library using class loader of the given class. + * + * @param libName name of the library to be loaded + */ + public static void loadLibrary(final String libName, final Class clazz) throws IOException { + java.util.Objects.requireNonNull(libName, "libName should not be null"); + java.util.Objects.requireNonNull(clazz, "clazz should not be null"); + try (final InputStream is = clazz.getResourceAsStream('/' + libName)) { + if (is == null) { + throw new IOException("Failed to open library resource " + libName); + } + loadStream(libName, is); + } + } + + private static void loadStream(final String libName, final InputStream is) throws IOException { + final Set perms = PosixFilePermissions.fromString("rwxr-x---"); + final Path p = Files.createTempFile(libName, null, PosixFilePermissions.asFileAttribute(perms)); + try { + Files.copy(is, p, StandardCopyOption.REPLACE_EXISTING); + Runtime.getRuntime().load(p.toString()); + } catch (Exception e) { + throw new IOException("Failed to load library " + p, e); + } finally { + try { + Files.deleteIfExists(p); + } catch (IOException e) { + LOG.log(Level.WARNING, String.format("Failed to delete temporary file %s.", p), e); + } + } + } +} diff --git a/java/jvpp-registry/io/fd/jvpp/VppBaseCallException.java b/java/jvpp-registry/io/fd/jvpp/VppBaseCallException.java new file mode 100644 index 0000000..1fbe579 --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/VppBaseCallException.java @@ -0,0 +1,79 @@ +/* + * 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 io.fd.jvpp; + + +/** + * Base exception representing failed operation of JVpp request call + */ +public abstract class VppBaseCallException extends Exception { + private final String methodName; + private final int errorCode; + + /** + * Constructs an VppCallbackException with the specified api method name and error code. + * + * @param methodName name of a method, which invocation or execution failed + * @param errorCode negative error code value associated with this failure + * @throws NullPointerException if apiMethodName is null + */ + public VppBaseCallException(final String methodName, final int errorCode) { + super(String.format("vppApi.%s failed with error code: %d", methodName, errorCode)); + this.methodName = java.util.Objects.requireNonNull(methodName, "apiMethodName is null!"); + this.errorCode = errorCode; + if(errorCode >= 0) { + throw new IllegalArgumentException("Error code must be < 0. Was " + errorCode + + " for " + methodName ); + } + } + + /** + * Constructs an VppCallbackException with the specified api method name, error description and error code. + * + * @param methodName name of a method, which invocation or execution failed + * @param message description of error reason + * @param errorCode negative error code value associated with this failure + * @throws NullPointerException if apiMethodName is null + */ + public VppBaseCallException(final String methodName, final String message, final int errorCode) { + super(String.format("vppApi.%s failed: %s (error code: %d)", methodName,message, errorCode)); + this.methodName = java.util.Objects.requireNonNull(methodName, "apiMethodName is null!"); + this.errorCode = errorCode; + if(errorCode >= 0) { + throw new IllegalArgumentException("Error code must be < 0. Was " + errorCode + + " for " + methodName ); + } + } + + /** + * Returns name of a method, which invocation failed. + * + * @return method name + */ + public String getMethodName() { + return methodName; + } + + /** + * Returns the error code associated with this failure. + * + * @return a negative integer error code + */ + public int getErrorCode() { + return errorCode; + } +} diff --git a/java/jvpp-registry/io/fd/jvpp/VppCallbackException.java b/java/jvpp-registry/io/fd/jvpp/VppCallbackException.java new file mode 100644 index 0000000..2cd6a45 --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/VppCallbackException.java @@ -0,0 +1,48 @@ +/* + * 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 io.fd.jvpp; + +/** + * Callback Exception representing failed operation of JVpp request call + */ +public class VppCallbackException extends VppBaseCallException { + private final int ctxId; + + /** + * Constructs an VppCallbackException with the specified api method name and error code. + * + * @param methodName name of a method, which invocation failed. + * @param message description of error reason + * @param ctxId api request context identifier + * @param errorCode negative error code value associated with this failure + * @throws NullPointerException if apiMethodName is null + */ + public VppCallbackException(final String methodName, final String message, final int ctxId, final int errorCode ){ + super(methodName, message, errorCode); + this.ctxId = ctxId; + } + + /** + * Returns api request context identifier. + * + * @return value of context identifier + */ + public int getCtxId() { + return ctxId; + } + +} diff --git a/java/jvpp-registry/io/fd/jvpp/VppConnection.java b/java/jvpp-registry/io/fd/jvpp/VppConnection.java new file mode 100644 index 0000000..5d7c03a --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/VppConnection.java @@ -0,0 +1,45 @@ +/* + * 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 io.fd.jvpp; + +import java.io.IOException; + +/** + * Representation of a management connection to VPP. + */ +public interface VppConnection extends AutoCloseable { + + /** + * Opens VppConnection for communication with VPP. + * + * @throws IOException if connection is not established + */ + void connect() throws IOException; + + /** + * Checks if this instance connection is active. + * + * @throws IllegalStateException if this instance was disconnected. + */ + void checkActive(); + + /** + * Closes Vpp connection. + */ + @Override + void close(); +} diff --git a/java/jvpp-registry/io/fd/jvpp/VppInvocationException.java b/java/jvpp-registry/io/fd/jvpp/VppInvocationException.java new file mode 100644 index 0000000..8125eb6 --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/VppInvocationException.java @@ -0,0 +1,33 @@ +/* + * 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 io.fd.jvpp; + +/** + * Exception thrown when Vpp jAPI method invocation failed. + */ +public class VppInvocationException extends VppBaseCallException { + /** + * Constructs an VppApiInvocationFailedException with the specified api method name and error code. + * + * @param methodName name of a method, which invocation failed. + * @param errorCode negative error code value associated with this failure + * @throws NullPointerException if apiMethodName is null + */ + public VppInvocationException(final String methodName, final int errorCode) { + super(methodName, errorCode); + } +} diff --git a/java/jvpp-registry/io/fd/jvpp/VppJNIConnection.java b/java/jvpp-registry/io/fd/jvpp/VppJNIConnection.java new file mode 100644 index 0000000..ff0eb1e --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/VppJNIConnection.java @@ -0,0 +1,152 @@ +/* + * 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 io.fd.jvpp; + +import static io.fd.jvpp.NativeLibraryLoader.loadLibrary; +import static java.lang.String.format; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * JNI based representation of a management connection to VPP. + */ +public final class VppJNIConnection implements VppConnection { + private static final Logger LOG = Logger.getLogger(VppJNIConnection.class.getName()); + private static final String DEFAULT_SHM_PREFIX = "/vpe-api"; + + static { + final String libName = "libjvpp_registry.so"; + try { + loadLibrary(libName, VppJNIConnection.class); + } catch (IOException e) { + LOG.log(Level.SEVERE, format("Can't find vpp jni library: %s", libName), e); + throw new ExceptionInInitializerError(e); + } + } + + private ConnectionInfo connectionInfo; + + private final String clientName; + private final String shmPrefix; + private volatile boolean disconnected = false; + + /** + * Create VPPJNIConnection instance for client connecting to VPP. + * + * @param clientName client name instance to be used for communication. Single connection per clientName is + * allowed. + */ + public VppJNIConnection(final String clientName) { + this.clientName = Objects.requireNonNull(clientName, "Null clientName"); + this.shmPrefix = DEFAULT_SHM_PREFIX; + } + + public VppJNIConnection(final String clientName, final String shmPrefix) { + this.clientName = Objects.requireNonNull(clientName, "Null clientName"); + this.shmPrefix = Objects.requireNonNull(shmPrefix, "Null shmPrefix"); + } + + /** + * Guarded by VppJNIConnection.class + */ + private static final Map connections = new HashMap<>(); + + /** + * Initiate VPP connection for current instance + * + * Multiple instances are allowed since this class is not a singleton (VPP allows multiple management connections). + * + * However only a single connection per clientName is allowed. + * + * @throws IOException in case the connection could not be established + */ + + @Override + public void connect() throws IOException { + _connect(shmPrefix); + } + + private void _connect(final String shmPrefix) throws IOException { + Objects.requireNonNull(shmPrefix, "Shared memory prefix must be defined"); + + synchronized (VppJNIConnection.class) { + if (connections.containsKey(clientName)) { + throw new IOException("Client " + clientName + " already connected"); + } + + connectionInfo = clientConnect(shmPrefix, clientName); + if (connectionInfo.status != 0) { + throw new IOException("Connection returned error " + connectionInfo.status); + } + connections.put(clientName, this); + } + } + + @Override + public final void checkActive() { + if (disconnected) { + throw new IllegalStateException("Disconnected client " + clientName); + } + } + + @Override + public final synchronized void close() { + if (!disconnected) { + disconnected = true; + try { + clientDisconnect(); + } finally { + synchronized (VppJNIConnection.class) { + connections.remove(clientName); + } + } + } + } + + public ConnectionInfo getConnectionInfo() { + return connectionInfo; + } + + /** + * VPP connection information used by plugins to reuse the connection. + */ + public static final class ConnectionInfo { + public final long queueAddress; + public final int clientIndex; + public final int status; // FIXME throw exception instead + public final int pid; + + public ConnectionInfo(long queueAddress, int clientIndex, int status, int pid) { + this.queueAddress = queueAddress; + this.clientIndex = clientIndex; + this.status = status; + this.pid = pid; + } + } + + private static native ConnectionInfo clientConnect(String shmPrefix, String clientName); + + private static native void clientDisconnect(); + +} diff --git a/java/jvpp-registry/io/fd/jvpp/callback/ControlPingCallback.java b/java/jvpp-registry/io/fd/jvpp/callback/ControlPingCallback.java new file mode 100644 index 0000000..f2cca3c --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/callback/ControlPingCallback.java @@ -0,0 +1,29 @@ +/* + * 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 io.fd.jvpp.callback; + +import io.fd.jvpp.dto.ControlPingReply; + +/** + * Represents callback for control_ping message. + */ +public interface ControlPingCallback extends JVppCallback { + + void onControlPingReply(ControlPingReply reply); + +} + diff --git a/java/jvpp-registry/io/fd/jvpp/callback/JVppCallback.java b/java/jvpp-registry/io/fd/jvpp/callback/JVppCallback.java new file mode 100644 index 0000000..00e85c9 --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/callback/JVppCallback.java @@ -0,0 +1,29 @@ +/* + * 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 io.fd.jvpp.callback; +import io.fd.jvpp.VppCallbackException; + +/** + * Base JVppCallback interface + */ +public interface JVppCallback { + /** + * onError callback handler used to report failing operation + * @param ex VppCallbackException object containing details about failing operation + */ + void onError(VppCallbackException ex); +} diff --git a/java/jvpp-registry/io/fd/jvpp/callback/JVppNotificationCallback.java b/java/jvpp-registry/io/fd/jvpp/callback/JVppNotificationCallback.java new file mode 100644 index 0000000..7193f4d --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/callback/JVppNotificationCallback.java @@ -0,0 +1,24 @@ +/* + * 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 io.fd.jvpp.callback; + +/** +* Notification callback +*/ +public interface JVppNotificationCallback { + +} diff --git a/java/jvpp-registry/io/fd/jvpp/coverity/SuppressFBWarnings.java b/java/jvpp-registry/io/fd/jvpp/coverity/SuppressFBWarnings.java new file mode 100644 index 0000000..7f9724d --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/coverity/SuppressFBWarnings.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2017 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 io.fd.jvpp.coverity; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * Used to suppress FindBugs warnings found by Coverity.
+ * We don't want extra dependency, so we define our own annotation version. + * + * @see Findbugs sourceforge + */ +@Retention(RetentionPolicy.CLASS) +public @interface SuppressFBWarnings { + /** + * The set of FindBugs warnings that are to be suppressed in annotated element. The value can be a bug category, + * kind or pattern. + */ + String[] value() default {}; + + /** + * Optional documentation of the reason why the warning is suppressed + */ + String justification() default ""; +} diff --git a/java/jvpp-registry/io/fd/jvpp/dto/ControlPing.java b/java/jvpp-registry/io/fd/jvpp/dto/ControlPing.java new file mode 100644 index 0000000..e2a7c26 --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/dto/ControlPing.java @@ -0,0 +1,34 @@ +/* + * 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 io.fd.jvpp.dto; + +import io.fd.jvpp.JVpp; +import io.fd.jvpp.VppInvocationException; + +/** + * Represents request DTO for control_ping message. + */ +public final class ControlPing implements JVppRequest { + + @Override + public int send(final JVpp jvpp) throws VppInvocationException { + return jvpp.controlPing(this); + } + +} + + diff --git a/java/jvpp-registry/io/fd/jvpp/dto/ControlPingReply.java b/java/jvpp-registry/io/fd/jvpp/dto/ControlPingReply.java new file mode 100644 index 0000000..68d5a2d --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/dto/ControlPingReply.java @@ -0,0 +1,58 @@ +/* + * 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 io.fd.jvpp.dto; + +import java.util.Objects; + +/** + * Represents reply DTO for control_ping message. + */ +public final class ControlPingReply implements JVppReply { + + public int context; + public int clientIndex; + public int vpePid; + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ControlPingReply that = (ControlPingReply) o; + return context == that.context && + clientIndex == that.clientIndex && + vpePid == that.vpePid; + } + + @Override + public int hashCode() { + return Objects.hash(context, clientIndex, vpePid); + } + + @Override + public String toString() { + return "ControlPingReply{" + + "context=" + context + + ", clientIndex=" + clientIndex + + ", vpePid=" + vpePid + + '}'; + } +} + diff --git a/java/jvpp-registry/io/fd/jvpp/dto/JVppDump.java b/java/jvpp-registry/io/fd/jvpp/dto/JVppDump.java new file mode 100644 index 0000000..9f8db7f --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/dto/JVppDump.java @@ -0,0 +1,24 @@ +/* + * 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 io.fd.jvpp.dto; + +/** +* Base interface for all dump requests +*/ +public interface JVppDump extends JVppRequest { + +} diff --git a/java/jvpp-registry/io/fd/jvpp/dto/JVppReply.java b/java/jvpp-registry/io/fd/jvpp/dto/JVppReply.java new file mode 100644 index 0000000..9088ade --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/dto/JVppReply.java @@ -0,0 +1,24 @@ +/* + * 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 io.fd.jvpp.dto; + +/** +* Base interface for all reply DTOs +*/ +public interface JVppReply { + +} diff --git a/java/jvpp-registry/io/fd/jvpp/dto/JVppReplyDump.java b/java/jvpp-registry/io/fd/jvpp/dto/JVppReplyDump.java new file mode 100644 index 0000000..a24b120 --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/dto/JVppReplyDump.java @@ -0,0 +1,25 @@ +/* + * 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 io.fd.jvpp.dto; + +/** +* Base interface for all dump replies +*/ +public interface JVppReplyDump> + extends JVppReply { + +} diff --git a/java/jvpp-registry/io/fd/jvpp/dto/JVppRequest.java b/java/jvpp-registry/io/fd/jvpp/dto/JVppRequest.java new file mode 100644 index 0000000..f82f5a3 --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/dto/JVppRequest.java @@ -0,0 +1,34 @@ +/* + * 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 io.fd.jvpp.dto; + +import io.fd.jvpp.JVpp; +import io.fd.jvpp.VppInvocationException; + +/** +* Base interface for all request DTOs +*/ +public interface JVppRequest { + + /** + * Invoke current operation asynchronously on VPP + * + * @return context id of this request. Can be used to track incoming response + */ + int send(JVpp jvpp) throws VppInvocationException; + +} diff --git a/java/jvpp-registry/io/fd/jvpp/future/AbstractFutureJVppInvoker.java b/java/jvpp-registry/io/fd/jvpp/future/AbstractFutureJVppInvoker.java new file mode 100644 index 0000000..406ccfb --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/future/AbstractFutureJVppInvoker.java @@ -0,0 +1,180 @@ +/* + * 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 io.fd.jvpp.future; + + +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; + +import io.fd.jvpp.JVpp; +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.VppInvocationException; +import io.fd.jvpp.dto.JVppDump; +import io.fd.jvpp.dto.JVppReply; +import io.fd.jvpp.dto.JVppReplyDump; +import io.fd.jvpp.dto.JVppRequest; + +/** + * Future facade on top of JVpp + */ +public abstract class AbstractFutureJVppInvoker implements FutureJVppInvoker { + + private final JVpp jvpp; + private final JVppRegistry registry; + + /** + * Guarded by self + */ + private final Map>> requests; + + protected AbstractFutureJVppInvoker(final JVpp jvpp, final JVppRegistry registry, + final Map>> requestMap) { + this.jvpp = Objects.requireNonNull(jvpp, "jvpp should not be null"); + this.registry = Objects.requireNonNull(registry, "registry should not be null"); + // Request map represents the shared state between this facade and it's callback + // where facade puts futures in and callback completes + removes them + this.requests = Objects.requireNonNull(requestMap, "Null requestMap"); + } + + protected final Map>> getRequests() { + synchronized (requests) { + return requests; + } + } + + // TODO use Optional in Future, java8 + + @Override + @SuppressWarnings("unchecked") + public > CompletionStage send(REQ req) { + try { + // jvpp.send() can go to waiting state if sending queue is full, putting it into same + // synchronization block as used by receiving part (synchronized(requests)) can lead + // to deadlock between these two sides or at least slowing sending process by slow + // reader + final CompletableFuture replyCompletableFuture; + final int contextId = jvpp.send(req); + + if(req instanceof JVppDump) { + throw new IllegalArgumentException("Send with empty reply dump has to be used in case of dump calls"); + } + + synchronized(requests) { + CompletableFuture> replyFuture = requests.get(contextId); + if (replyFuture == null) { + // reply not yet received, put new future into map + replyCompletableFuture = new CompletableFuture<>(); + requests.put(contextId, replyCompletableFuture); + } else { + // reply already received (should be completed by reader), + // remove future from map and return it to caller + replyCompletableFuture = (CompletableFuture) replyFuture; + requests.remove(contextId); + } + } + + // TODO in case of timeouts/missing replies, requests from the map are not removed + // consider adding cancel method, that would remove requests from the map and cancel + // associated replyCompletableFuture + + return replyCompletableFuture; + } catch (VppInvocationException ex) { + final CompletableFuture replyCompletableFuture = new CompletableFuture<>(); + replyCompletableFuture.completeExceptionally(ex); + return replyCompletableFuture; + } + } + + @Override + @SuppressWarnings("unchecked") + public , DUMP extends JVppReplyDump> CompletionStage send( + REQ req, DUMP emptyReplyDump) { + try { + // jvpp.send() and registry.controlPing() can go to waiting state if sending queue is full, + // putting it into same synchronization block as used by receiving part (synchronized(requests)) + // can lead to deadlock between these two sides or at least slowing sending process by slow reader + final CompletableDumpFuture replyDumpFuture; + final int contextId = jvpp.send(req); + + if(!(req instanceof JVppDump)) { + throw new IllegalArgumentException("Send without empty reply dump has to be used in case of regular calls"); + } + + synchronized(requests) { + CompletableFuture> replyFuture = requests.get(contextId); + if (replyFuture == null) { + // reply not received yet, put new future to map + replyDumpFuture = new CompletableDumpFuture<>(contextId, emptyReplyDump); + requests.put(contextId, replyDumpFuture); + } else { + // reply already received, save existing future + replyDumpFuture = (CompletableDumpFuture) replyFuture; + } + } + + final int pingId = registry.controlPing(jvpp.getClass()); + + synchronized(requests) { + if (requests.remove(pingId) == null) { + // reply not received yet, put future into map under pingId + requests.put(pingId, replyDumpFuture); + } else { + // reply already received, complete future + // ping reply couldn't complete the future because it is not in map under + // ping id + replyDumpFuture.complete(replyDumpFuture.getReplyDump()); + requests.remove(contextId); + } + } + + // TODO in case of timeouts/missing replies, requests from the map are not removed + // consider adding cancel method, that would remove requests from the map and cancel + // associated replyCompletableFuture + + return replyDumpFuture; + } catch (VppInvocationException ex) { + final CompletableFuture replyCompletableFuture = new CompletableFuture<>(); + replyCompletableFuture.completeExceptionally(ex); + return replyCompletableFuture; + } + } + + public static final class CompletableDumpFuture> extends CompletableFuture { + private final T replyDump; + private final int contextId; + + public CompletableDumpFuture(final int contextId, final T emptyDump) { + this.contextId = contextId; + this.replyDump = emptyDump; + } + + public int getContextId() { + return contextId; + } + + public T getReplyDump() { + return replyDump; + } + } + + @Override + public void close() throws Exception { + jvpp.close(); + } +} diff --git a/java/jvpp-registry/io/fd/jvpp/future/FutureJVppInvoker.java b/java/jvpp-registry/io/fd/jvpp/future/FutureJVppInvoker.java new file mode 100644 index 0000000..f421f5a --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/future/FutureJVppInvoker.java @@ -0,0 +1,49 @@ +/* + * 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 io.fd.jvpp.future; + + +import io.fd.jvpp.dto.JVppReply; +import io.fd.jvpp.dto.JVppReplyDump; +import io.fd.jvpp.dto.JVppRequest; + +import java.util.concurrent.CompletionStage; +import io.fd.jvpp.notification.EventRegistryProvider; + +/** +* Future facade on top of JVpp +*/ +public interface FutureJVppInvoker extends EventRegistryProvider, AutoCloseable { + + /** + * Invoke asynchronous operation on VPP + * + * @return CompletionStage with future result of an async VPP call + * @throws io.fd.jvpp.VppInvocationException when send request failed with details + */ + > CompletionStage send(REQ req); + + + /** + * Invoke asynchronous dump operation on VPP + * + * @return CompletionStage with aggregated future result of an async VPP dump call + * @throws io.fd.jvpp.VppInvocationException when send request failed with details + */ + , DUMP extends JVppReplyDump> CompletionStage send( + REQ req, DUMP emptyReplyDump); +} diff --git a/java/jvpp-registry/io/fd/jvpp/notification/EventRegistry.java b/java/jvpp-registry/io/fd/jvpp/notification/EventRegistry.java new file mode 100644 index 0000000..f25b038 --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/notification/EventRegistry.java @@ -0,0 +1,25 @@ +/* + * 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 io.fd.jvpp.notification; + +/** + * Base registry for notification callbacks. + */ +public interface EventRegistry extends AutoCloseable { + + void close(); +} diff --git a/java/jvpp-registry/io/fd/jvpp/notification/EventRegistryProvider.java b/java/jvpp-registry/io/fd/jvpp/notification/EventRegistryProvider.java new file mode 100644 index 0000000..a1702da --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/notification/EventRegistryProvider.java @@ -0,0 +1,28 @@ +/* + * 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 io.fd.jvpp.notification; + +/** + * Provides notification registry + */ +public interface EventRegistryProvider { + + /** + * Get current notification registry instance + */ + EventRegistry getEventRegistry(); +} diff --git a/java/jvpp-registry/io/fd/jvpp/test/ConnectionTest.java b/java/jvpp-registry/io/fd/jvpp/test/ConnectionTest.java new file mode 100644 index 0000000..b982d11 --- /dev/null +++ b/java/jvpp-registry/io/fd/jvpp/test/ConnectionTest.java @@ -0,0 +1,44 @@ +/* + * 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 io.fd.jvpp.test; + +import io.fd.jvpp.JVppRegistry; +import io.fd.jvpp.JVppRegistryImpl; + +/** + * Run using: + * sudo java -cp build-vpp-native/vpp-api/java/jvpp-registry-16.09.jar io.fd.jvpp.test.ConnectionTest + */ +public class ConnectionTest { + + private static void testConnect() throws Exception { + System.out.println("Testing JNI connection with JVppRegistry"); + final JVppRegistry registry = new JVppRegistryImpl("ConnectionTest"); + try { + System.out.println("Successfully connected to vpp"); + Thread.sleep(5000); + System.out.println("Disconnecting..."); + Thread.sleep(1000); + } finally { + registry.close(); + } + } + + public static void main(String[] args) throws Exception { + testConnect(); + } +} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/AbstractCallbackApiTest.java b/java/jvpp-registry/io/fd/vpp/jvpp/AbstractCallbackApiTest.java deleted file mode 100644 index d221d1e..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/AbstractCallbackApiTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2017 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 io.fd.vpp.jvpp; - -import io.fd.vpp.jvpp.callback.ControlPingCallback; -import io.fd.vpp.jvpp.dto.ControlPing; -import io.fd.vpp.jvpp.dto.ControlPingReply; - -public abstract class AbstractCallbackApiTest { - - private static int receivedPingCount = 0; - private static int errorPingCount = 0; - - public static void testControlPing(String shm_prefix, JVpp jvpp) throws Exception { - try (JVppRegistry registry = new JVppRegistryImpl("CallbackApiTest", shm_prefix)) { - - registry.register(jvpp, new ControlPingCallback() { - @Override - public void onControlPingReply(final ControlPingReply reply) { - System.out.printf("Received ControlPingReply: %s%n", reply); - receivedPingCount++; - } - - @Override - public void onError(VppCallbackException ex) { - System.out.printf("Received onError exception: call=%s, reply=%d, context=%d ", ex.getMethodName(), - ex.getErrorCode(), ex.getCtxId()); - errorPingCount++; - } - - }); - System.out.println("Successfully connected to VPP"); - Thread.sleep(1000); - - System.out.println("Sending control ping using JVppRegistry"); - registry.controlPing(jvpp.getClass()); - - Thread.sleep(2000); - - System.out.println("Sending control ping using JVpp plugin"); - jvpp.send(new ControlPing()); - - Thread.sleep(2000); - System.out.println("Disconnecting..."); - Assertions.assertEquals(2, receivedPingCount); - Assertions.assertEquals(0, errorPingCount); - } - } -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/Assertions.java b/java/jvpp-registry/io/fd/vpp/jvpp/Assertions.java deleted file mode 100644 index f8b591f..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/Assertions.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2017 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 io.fd.vpp.jvpp; - -public class Assertions { - - public static void assertEquals(final int expected, final int actual) { - if (expected != actual) { - throw new IllegalArgumentException(String.format("Expected[%s]/Actual[%s]", expected, actual)); - } - } - - public static void assertNotNull(final Object value) { - if (value == null) { - throw new IllegalArgumentException("Variable is null"); - } - } -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/JVpp.java b/java/jvpp-registry/io/fd/vpp/jvpp/JVpp.java deleted file mode 100644 index 55f25a7..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/JVpp.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp; - -import io.fd.vpp.jvpp.callback.JVppCallback; -import io.fd.vpp.jvpp.dto.ControlPing; -import io.fd.vpp.jvpp.dto.JVppRequest; - -/** - * Base interface for plugin's Java API. - */ -public interface JVpp extends AutoCloseable { - - /** - * Sends request to vpp. - * - * @param request request to be sent - * @return unique identifer of message in message queue - * @throws VppInvocationException when message could not be sent - */ - int send(final JVppRequest request) throws VppInvocationException; - - /** - * Initializes plugin's Java API. - * - * @param registry plugin registry - * @param callback called by vpe.api message handlers - * @param queueAddress address of vpp shared memory queue - * @param clientIndex vpp client identifier - */ - void init(final JVppRegistry registry, final JVppCallback callback, final long queueAddress, - final int clientIndex); - - /** - * Sends control_ping message. - * - * @param controlPing request DTO - * @return unique identifer of message in message queue - * @throws VppInvocationException when message could not be sent - */ - int controlPing(final ControlPing controlPing) throws VppInvocationException; -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/JVppRegistry.java b/java/jvpp-registry/io/fd/vpp/jvpp/JVppRegistry.java deleted file mode 100644 index 6535db0..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/JVppRegistry.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp; - -import io.fd.vpp.jvpp.callback.JVppCallback; - -/** - * Manages VPP connection and stores plugin callbacks. - */ -public interface JVppRegistry extends AutoCloseable { - - /** - * Vpp connection managed by the registry. - * - * @return representation of vpp connection - */ - VppConnection getConnection(); - - /** - * Registers callback and initializes Java API for given plugin. - * - * @param jvpp plugin name - * @param callback callback provided by the plugin - * @throws NullPointerException if name or callback is null - * @throws IllegalArgumentException if plugin was already registered - */ - void register(final JVpp jvpp, final JVppCallback callback); - - /** - * Unregisters callback for the given plugin. - * - * @param name plugin name - * @throws NullPointerException if name is null - * @throws IllegalArgumentException if plugin was not registered - */ - void unregister(final String name); - - /** - * Returns callback registered for the plugin. - * - * @param name plugin name - * @return callback provided by the plugin - * @throws NullPointerException if name is null - * @throws IllegalArgumentException if plugin was not registered - */ - JVppCallback get(final String name); - - /** - * Sends control ping. Reply handler calls callback registered for give plugin. - * - * Control ping is used for initial RX thread to Java thread attachment - * that takes place in the plugin's JNI lib - * and to wrap dump message replies in one list. - * - * VPP plugins don't have to provide special control ping, therefore - * it is necessary to providing control ping support in JVppRegistry. - - * @param clazz identifies plugin that should receive ping callback - * @return unique identifier of message in message queue - */ - int controlPing(final Class clazz) throws VppInvocationException; -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/JVppRegistryImpl.java b/java/jvpp-registry/io/fd/vpp/jvpp/JVppRegistryImpl.java deleted file mode 100644 index baef14c..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/JVppRegistryImpl.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp; - -import static java.util.Objects.requireNonNull; - -import io.fd.vpp.jvpp.callback.ControlPingCallback; -import io.fd.vpp.jvpp.callback.JVppCallback; -import io.fd.vpp.jvpp.dto.ControlPingReply; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Default implementation of JVppRegistry. - */ -public final class JVppRegistryImpl implements JVppRegistry, ControlPingCallback { - - private static final Logger LOG = Logger.getLogger(JVppRegistryImpl.class.getName()); - - private final VppJNIConnection connection; - // Unguarded concurrent map, no race conditions expected on top of that - private final Map pluginRegistry; - // Guarded by self - private final Map pingCalls; - - public JVppRegistryImpl(final String clientName) throws IOException { - connection = new VppJNIConnection(clientName); - connection.connect(); - pluginRegistry = new ConcurrentHashMap<>(); - pingCalls = new HashMap<>(); - } - - public JVppRegistryImpl(final String clientName, final String shmPrefix) throws IOException { - connection = new VppJNIConnection(clientName, shmPrefix); - connection.connect(); - pluginRegistry = new ConcurrentHashMap<>(); - pingCalls = new HashMap<>(); - } - - @Override - public VppConnection getConnection() { - return connection; - } - - @Override - public void register(final JVpp jvpp, final JVppCallback callback) { - requireNonNull(jvpp, "jvpp should not be null"); - requireNonNull(callback, "Callback should not be null"); - final String name = jvpp.getClass().getName(); - if (pluginRegistry.containsKey(name)) { - throw new IllegalArgumentException( - String.format("Callback for plugin %s was already registered", name)); - } - jvpp.init(this, callback, connection.getConnectionInfo().queueAddress, - connection.getConnectionInfo().clientIndex); - pluginRegistry.put(name, callback); - } - - @Override - public void unregister(final String name) { - requireNonNull(name, "Plugin name should not be null"); - final JVppCallback previous = pluginRegistry.remove(name); - assertPluginWasRegistered(name, previous); - } - - @Override - public JVppCallback get(final String name) { - requireNonNull(name, "Plugin name should not be null"); - JVppCallback value = pluginRegistry.get(name); - assertPluginWasRegistered(name, value); - return value; - } - - private native int controlPing0() throws VppInvocationException; - - @Override - public int controlPing(final Class clazz) throws VppInvocationException { - connection.checkActive(); - final String name = clazz.getName(); - - final ControlPingCallback callback = (ControlPingCallback) pluginRegistry.get(clazz.getName()); - assertPluginWasRegistered(name, callback); - - // controlPing0 is sending function and can go to waiting in case of e. g. full queue - // because of that it cant be in same synchronization block as used by reply handler function - int context = controlPing0(); - if (context < 0) { - throw new VppInvocationException("controlPing", context); - } - - synchronized (pingCalls) { - // if callback is in map it's because reply was already received - EarlyControlPingReply earlyReplyCallback = (EarlyControlPingReply) pingCalls.remove(context); - if(earlyReplyCallback == null) { - pingCalls.put(context, callback); - } else { - callback.onControlPingReply(earlyReplyCallback.getReply()); - } - } - - return context; - } - - @Override - public void onControlPingReply(final ControlPingReply reply) { - final ControlPingCallback callback; - synchronized (pingCalls) { - callback = pingCalls.remove(reply.context); - if (callback == null) { - // reply received early, because we don't know callback to call - // we wrap the reply and let the sender to call it - pingCalls.put(reply.context, new EarlyControlPingReply(reply)); - return; - } - } - // pass the reply to the callback registered by the ping caller - callback.onControlPingReply(reply); - } - - @Override - public void onError(final VppCallbackException ex) { - final int ctxId = ex.getCtxId(); - final ControlPingCallback callback; - - synchronized (pingCalls) { - callback = pingCalls.get(ctxId); - } - if (callback == null) { - LOG.log(Level.WARNING, "No callback was registered for reply id={0} ", ctxId); - return; - } - // pass the error to the callback registered by the ping caller - callback.onError(ex); - } - - private static void assertPluginWasRegistered(final String name, final JVppCallback value) { - if (value == null) { - throw new IllegalArgumentException(String.format("Callback for plugin %s is not registered", name)); - } - } - - @Override - public void close() throws Exception { - connection.close(); - } - - private static class EarlyControlPingReply implements ControlPingCallback { - - private final ControlPingReply reply; - - public EarlyControlPingReply(final ControlPingReply reply) { - this.reply = reply; - } - - public ControlPingReply getReply() { - return reply; - } - - @Override - public void onError(VppCallbackException ex) { - throw new IllegalStateException("Calling onError in EarlyControlPingReply"); - } - - @Override - public void onControlPingReply(ControlPingReply reply) { - throw new IllegalStateException("Calling onControlPingReply in EarlyControlPingReply"); - } - } -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/NativeLibraryLoader.java b/java/jvpp-registry/io/fd/vpp/jvpp/NativeLibraryLoader.java deleted file mode 100644 index ce6d1bf..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/NativeLibraryLoader.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.nio.file.attribute.PosixFilePermission; -import java.nio.file.attribute.PosixFilePermissions; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Utility class for loading JNI libraries. - */ -public final class NativeLibraryLoader { - - private static final Logger LOG = Logger.getLogger(NativeLibraryLoader.class.getName()); - - private NativeLibraryLoader() { - throw new UnsupportedOperationException("This utility class cannot be instantiated."); - } - - /** - * Loads JNI library using class loader of the given class. - * - * @param libName name of the library to be loaded - */ - public static void loadLibrary(final String libName, final Class clazz) throws IOException { - java.util.Objects.requireNonNull(libName, "libName should not be null"); - java.util.Objects.requireNonNull(clazz, "clazz should not be null"); - try (final InputStream is = clazz.getResourceAsStream('/' + libName)) { - if (is == null) { - throw new IOException("Failed to open library resource " + libName); - } - loadStream(libName, is); - } - } - - private static void loadStream(final String libName, final InputStream is) throws IOException { - final Set perms = PosixFilePermissions.fromString("rwxr-x---"); - final Path p = Files.createTempFile(libName, null, PosixFilePermissions.asFileAttribute(perms)); - try { - Files.copy(is, p, StandardCopyOption.REPLACE_EXISTING); - Runtime.getRuntime().load(p.toString()); - } catch (Exception e) { - throw new IOException("Failed to load library " + p, e); - } finally { - try { - Files.deleteIfExists(p); - } catch (IOException e) { - LOG.log(Level.WARNING, String.format("Failed to delete temporary file %s.", p), e); - } - } - } -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/VppBaseCallException.java b/java/jvpp-registry/io/fd/vpp/jvpp/VppBaseCallException.java deleted file mode 100644 index 7fc1682..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/VppBaseCallException.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp; - - -/** - * Base exception representing failed operation of JVpp request call - */ -public abstract class VppBaseCallException extends Exception { - private final String methodName; - private final int errorCode; - - /** - * Constructs an VppCallbackException with the specified api method name and error code. - * - * @param methodName name of a method, which invocation or execution failed - * @param errorCode negative error code value associated with this failure - * @throws NullPointerException if apiMethodName is null - */ - public VppBaseCallException(final String methodName, final int errorCode) { - super(String.format("vppApi.%s failed with error code: %d", methodName, errorCode)); - this.methodName = java.util.Objects.requireNonNull(methodName, "apiMethodName is null!"); - this.errorCode = errorCode; - if(errorCode >= 0) { - throw new IllegalArgumentException("Error code must be < 0. Was " + errorCode + - " for " + methodName ); - } - } - - /** - * Constructs an VppCallbackException with the specified api method name, error description and error code. - * - * @param methodName name of a method, which invocation or execution failed - * @param message description of error reason - * @param errorCode negative error code value associated with this failure - * @throws NullPointerException if apiMethodName is null - */ - public VppBaseCallException(final String methodName, final String message, final int errorCode) { - super(String.format("vppApi.%s failed: %s (error code: %d)", methodName,message, errorCode)); - this.methodName = java.util.Objects.requireNonNull(methodName, "apiMethodName is null!"); - this.errorCode = errorCode; - if(errorCode >= 0) { - throw new IllegalArgumentException("Error code must be < 0. Was " + errorCode + - " for " + methodName ); - } - } - - /** - * Returns name of a method, which invocation failed. - * - * @return method name - */ - public String getMethodName() { - return methodName; - } - - /** - * Returns the error code associated with this failure. - * - * @return a negative integer error code - */ - public int getErrorCode() { - return errorCode; - } -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/VppCallbackException.java b/java/jvpp-registry/io/fd/vpp/jvpp/VppCallbackException.java deleted file mode 100644 index adcc5d2..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/VppCallbackException.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp; - -/** - * Callback Exception representing failed operation of JVpp request call - */ -public class VppCallbackException extends VppBaseCallException { - private final int ctxId; - - /** - * Constructs an VppCallbackException with the specified api method name and error code. - * - * @param methodName name of a method, which invocation failed. - * @param message description of error reason - * @param ctxId api request context identifier - * @param errorCode negative error code value associated with this failure - * @throws NullPointerException if apiMethodName is null - */ - public VppCallbackException(final String methodName, final String message, final int ctxId, final int errorCode ){ - super(methodName, message, errorCode); - this.ctxId = ctxId; - } - - /** - * Returns api request context identifier. - * - * @return value of context identifier - */ - public int getCtxId() { - return ctxId; - } - -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/VppConnection.java b/java/jvpp-registry/io/fd/vpp/jvpp/VppConnection.java deleted file mode 100644 index e6fd3bd..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/VppConnection.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp; - -import java.io.IOException; - -/** - * Representation of a management connection to VPP. - */ -public interface VppConnection extends AutoCloseable { - - /** - * Opens VppConnection for communication with VPP. - * - * @throws IOException if connection is not established - */ - void connect() throws IOException; - - /** - * Checks if this instance connection is active. - * - * @throws IllegalStateException if this instance was disconnected. - */ - void checkActive(); - - /** - * Closes Vpp connection. - */ - @Override - void close(); -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/VppInvocationException.java b/java/jvpp-registry/io/fd/vpp/jvpp/VppInvocationException.java deleted file mode 100644 index a7ccb19..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/VppInvocationException.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp; - -/** - * Exception thrown when Vpp jAPI method invocation failed. - */ -public class VppInvocationException extends VppBaseCallException { - /** - * Constructs an VppApiInvocationFailedException with the specified api method name and error code. - * - * @param methodName name of a method, which invocation failed. - * @param errorCode negative error code value associated with this failure - * @throws NullPointerException if apiMethodName is null - */ - public VppInvocationException(final String methodName, final int errorCode) { - super(methodName, errorCode); - } -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/VppJNIConnection.java b/java/jvpp-registry/io/fd/vpp/jvpp/VppJNIConnection.java deleted file mode 100644 index 6a414f3..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/VppJNIConnection.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp; - -import static io.fd.vpp.jvpp.NativeLibraryLoader.loadLibrary; -import static java.lang.String.format; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * JNI based representation of a management connection to VPP. - */ -public final class VppJNIConnection implements VppConnection { - private static final Logger LOG = Logger.getLogger(VppJNIConnection.class.getName()); - private static final String DEFAULT_SHM_PREFIX = "/vpe-api"; - - static { - final String libName = "libjvpp_registry.so"; - try { - loadLibrary(libName, VppJNIConnection.class); - } catch (IOException e) { - LOG.log(Level.SEVERE, format("Can't find vpp jni library: %s", libName), e); - throw new ExceptionInInitializerError(e); - } - } - - private ConnectionInfo connectionInfo; - - private final String clientName; - private final String shmPrefix; - private volatile boolean disconnected = false; - - /** - * Create VPPJNIConnection instance for client connecting to VPP. - * - * @param clientName client name instance to be used for communication. Single connection per clientName is - * allowed. - */ - public VppJNIConnection(final String clientName) { - this.clientName = Objects.requireNonNull(clientName, "Null clientName"); - this.shmPrefix = DEFAULT_SHM_PREFIX; - } - - public VppJNIConnection(final String clientName, final String shmPrefix) { - this.clientName = Objects.requireNonNull(clientName, "Null clientName"); - this.shmPrefix = Objects.requireNonNull(shmPrefix, "Null shmPrefix"); - } - - /** - * Guarded by VppJNIConnection.class - */ - private static final Map connections = new HashMap<>(); - - /** - * Initiate VPP connection for current instance - * - * Multiple instances are allowed since this class is not a singleton (VPP allows multiple management connections). - * - * However only a single connection per clientName is allowed. - * - * @throws IOException in case the connection could not be established - */ - - @Override - public void connect() throws IOException { - _connect(shmPrefix); - } - - private void _connect(final String shmPrefix) throws IOException { - Objects.requireNonNull(shmPrefix, "Shared memory prefix must be defined"); - - synchronized (VppJNIConnection.class) { - if (connections.containsKey(clientName)) { - throw new IOException("Client " + clientName + " already connected"); - } - - connectionInfo = clientConnect(shmPrefix, clientName); - if (connectionInfo.status != 0) { - throw new IOException("Connection returned error " + connectionInfo.status); - } - connections.put(clientName, this); - } - } - - @Override - public final void checkActive() { - if (disconnected) { - throw new IllegalStateException("Disconnected client " + clientName); - } - } - - @Override - public final synchronized void close() { - if (!disconnected) { - disconnected = true; - try { - clientDisconnect(); - } finally { - synchronized (VppJNIConnection.class) { - connections.remove(clientName); - } - } - } - } - - public ConnectionInfo getConnectionInfo() { - return connectionInfo; - } - - /** - * VPP connection information used by plugins to reuse the connection. - */ - public static final class ConnectionInfo { - public final long queueAddress; - public final int clientIndex; - public final int status; // FIXME throw exception instead - public final int pid; - - public ConnectionInfo(long queueAddress, int clientIndex, int status, int pid) { - this.queueAddress = queueAddress; - this.clientIndex = clientIndex; - this.status = status; - this.pid = pid; - } - } - - private static native ConnectionInfo clientConnect(String shmPrefix, String clientName); - - private static native void clientDisconnect(); - -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/callback/ControlPingCallback.java b/java/jvpp-registry/io/fd/vpp/jvpp/callback/ControlPingCallback.java deleted file mode 100644 index efddfdb..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/callback/ControlPingCallback.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.callback; - -import io.fd.vpp.jvpp.dto.ControlPingReply; - -/** - * Represents callback for control_ping message. - */ -public interface ControlPingCallback extends JVppCallback { - - void onControlPingReply(ControlPingReply reply); - -} - diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/callback/JVppCallback.java b/java/jvpp-registry/io/fd/vpp/jvpp/callback/JVppCallback.java deleted file mode 100644 index ae02063..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/callback/JVppCallback.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.callback; -import io.fd.vpp.jvpp.VppCallbackException; - -/** - * Base JVppCallback interface - */ -public interface JVppCallback { - /** - * onError callback handler used to report failing operation - * @param ex VppCallbackException object containing details about failing operation - */ - void onError(VppCallbackException ex); -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/callback/JVppNotificationCallback.java b/java/jvpp-registry/io/fd/vpp/jvpp/callback/JVppNotificationCallback.java deleted file mode 100644 index 8ab0cb2..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/callback/JVppNotificationCallback.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.callback; - -/** -* Notification callback -*/ -public interface JVppNotificationCallback { - -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/coverity/SuppressFBWarnings.java b/java/jvpp-registry/io/fd/vpp/jvpp/coverity/SuppressFBWarnings.java deleted file mode 100644 index 1e780bb..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/coverity/SuppressFBWarnings.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2017 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 io.fd.vpp.jvpp.coverity; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/** - * Used to suppress FindBugs warnings found by Coverity.
- * We don't want extra dependency, so we define our own annotation version. - * - * @see Findbugs sourceforge - */ -@Retention(RetentionPolicy.CLASS) -public @interface SuppressFBWarnings { - /** - * The set of FindBugs warnings that are to be suppressed in annotated element. The value can be a bug category, - * kind or pattern. - */ - String[] value() default {}; - - /** - * Optional documentation of the reason why the warning is suppressed - */ - String justification() default ""; -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/dto/ControlPing.java b/java/jvpp-registry/io/fd/vpp/jvpp/dto/ControlPing.java deleted file mode 100644 index 984e167..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/dto/ControlPing.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.dto; - -import io.fd.vpp.jvpp.JVpp; -import io.fd.vpp.jvpp.VppInvocationException; - -/** - * Represents request DTO for control_ping message. - */ -public final class ControlPing implements JVppRequest { - - @Override - public int send(final JVpp jvpp) throws VppInvocationException { - return jvpp.controlPing(this); - } - -} - - diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/dto/ControlPingReply.java b/java/jvpp-registry/io/fd/vpp/jvpp/dto/ControlPingReply.java deleted file mode 100644 index 61e4d0e..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/dto/ControlPingReply.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.dto; - -import java.util.Objects; - -/** - * Represents reply DTO for control_ping message. - */ -public final class ControlPingReply implements JVppReply { - - public int context; - public int clientIndex; - public int vpePid; - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - final ControlPingReply that = (ControlPingReply) o; - return context == that.context && - clientIndex == that.clientIndex && - vpePid == that.vpePid; - } - - @Override - public int hashCode() { - return Objects.hash(context, clientIndex, vpePid); - } - - @Override - public String toString() { - return "ControlPingReply{" + - "context=" + context + - ", clientIndex=" + clientIndex + - ", vpePid=" + vpePid + - '}'; - } -} - diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/dto/JVppDump.java b/java/jvpp-registry/io/fd/vpp/jvpp/dto/JVppDump.java deleted file mode 100644 index 60b9898..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/dto/JVppDump.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.dto; - -/** -* Base interface for all dump requests -*/ -public interface JVppDump extends JVppRequest { - -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/dto/JVppReply.java b/java/jvpp-registry/io/fd/vpp/jvpp/dto/JVppReply.java deleted file mode 100644 index 73f512d..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/dto/JVppReply.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.dto; - -/** -* Base interface for all reply DTOs -*/ -public interface JVppReply { - -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/dto/JVppReplyDump.java b/java/jvpp-registry/io/fd/vpp/jvpp/dto/JVppReplyDump.java deleted file mode 100644 index 1511139..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/dto/JVppReplyDump.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.dto; - -/** -* Base interface for all dump replies -*/ -public interface JVppReplyDump> - extends JVppReply { - -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/dto/JVppRequest.java b/java/jvpp-registry/io/fd/vpp/jvpp/dto/JVppRequest.java deleted file mode 100644 index 9b301da..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/dto/JVppRequest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.dto; - -import io.fd.vpp.jvpp.JVpp; -import io.fd.vpp.jvpp.VppInvocationException; - -/** -* Base interface for all request DTOs -*/ -public interface JVppRequest { - - /** - * Invoke current operation asynchronously on VPP - * - * @return context id of this request. Can be used to track incoming response - */ - int send(JVpp jvpp) throws VppInvocationException; - -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/future/AbstractFutureJVppInvoker.java b/java/jvpp-registry/io/fd/vpp/jvpp/future/AbstractFutureJVppInvoker.java deleted file mode 100644 index ac85f53..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/future/AbstractFutureJVppInvoker.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.future; - - -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionStage; - -import io.fd.vpp.jvpp.JVpp; -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.VppInvocationException; -import io.fd.vpp.jvpp.dto.JVppDump; -import io.fd.vpp.jvpp.dto.JVppReply; -import io.fd.vpp.jvpp.dto.JVppReplyDump; -import io.fd.vpp.jvpp.dto.JVppRequest; - -/** - * Future facade on top of JVpp - */ -public abstract class AbstractFutureJVppInvoker implements FutureJVppInvoker { - - private final JVpp jvpp; - private final JVppRegistry registry; - - /** - * Guarded by self - */ - private final Map>> requests; - - protected AbstractFutureJVppInvoker(final JVpp jvpp, final JVppRegistry registry, - final Map>> requestMap) { - this.jvpp = Objects.requireNonNull(jvpp, "jvpp should not be null"); - this.registry = Objects.requireNonNull(registry, "registry should not be null"); - // Request map represents the shared state between this facade and it's callback - // where facade puts futures in and callback completes + removes them - this.requests = Objects.requireNonNull(requestMap, "Null requestMap"); - } - - protected final Map>> getRequests() { - synchronized (requests) { - return requests; - } - } - - // TODO use Optional in Future, java8 - - @Override - @SuppressWarnings("unchecked") - public > CompletionStage send(REQ req) { - try { - // jvpp.send() can go to waiting state if sending queue is full, putting it into same - // synchronization block as used by receiving part (synchronized(requests)) can lead - // to deadlock between these two sides or at least slowing sending process by slow - // reader - final CompletableFuture replyCompletableFuture; - final int contextId = jvpp.send(req); - - if(req instanceof JVppDump) { - throw new IllegalArgumentException("Send with empty reply dump has to be used in case of dump calls"); - } - - synchronized(requests) { - CompletableFuture> replyFuture = requests.get(contextId); - if (replyFuture == null) { - // reply not yet received, put new future into map - replyCompletableFuture = new CompletableFuture<>(); - requests.put(contextId, replyCompletableFuture); - } else { - // reply already received (should be completed by reader), - // remove future from map and return it to caller - replyCompletableFuture = (CompletableFuture) replyFuture; - requests.remove(contextId); - } - } - - // TODO in case of timeouts/missing replies, requests from the map are not removed - // consider adding cancel method, that would remove requests from the map and cancel - // associated replyCompletableFuture - - return replyCompletableFuture; - } catch (VppInvocationException ex) { - final CompletableFuture replyCompletableFuture = new CompletableFuture<>(); - replyCompletableFuture.completeExceptionally(ex); - return replyCompletableFuture; - } - } - - @Override - @SuppressWarnings("unchecked") - public , DUMP extends JVppReplyDump> CompletionStage send( - REQ req, DUMP emptyReplyDump) { - try { - // jvpp.send() and registry.controlPing() can go to waiting state if sending queue is full, - // putting it into same synchronization block as used by receiving part (synchronized(requests)) - // can lead to deadlock between these two sides or at least slowing sending process by slow reader - final CompletableDumpFuture replyDumpFuture; - final int contextId = jvpp.send(req); - - if(!(req instanceof JVppDump)) { - throw new IllegalArgumentException("Send without empty reply dump has to be used in case of regular calls"); - } - - synchronized(requests) { - CompletableFuture> replyFuture = requests.get(contextId); - if (replyFuture == null) { - // reply not received yet, put new future to map - replyDumpFuture = new CompletableDumpFuture<>(contextId, emptyReplyDump); - requests.put(contextId, replyDumpFuture); - } else { - // reply already received, save existing future - replyDumpFuture = (CompletableDumpFuture) replyFuture; - } - } - - final int pingId = registry.controlPing(jvpp.getClass()); - - synchronized(requests) { - if (requests.remove(pingId) == null) { - // reply not received yet, put future into map under pingId - requests.put(pingId, replyDumpFuture); - } else { - // reply already received, complete future - // ping reply couldn't complete the future because it is not in map under - // ping id - replyDumpFuture.complete(replyDumpFuture.getReplyDump()); - requests.remove(contextId); - } - } - - // TODO in case of timeouts/missing replies, requests from the map are not removed - // consider adding cancel method, that would remove requests from the map and cancel - // associated replyCompletableFuture - - return replyDumpFuture; - } catch (VppInvocationException ex) { - final CompletableFuture replyCompletableFuture = new CompletableFuture<>(); - replyCompletableFuture.completeExceptionally(ex); - return replyCompletableFuture; - } - } - - public static final class CompletableDumpFuture> extends CompletableFuture { - private final T replyDump; - private final int contextId; - - public CompletableDumpFuture(final int contextId, final T emptyDump) { - this.contextId = contextId; - this.replyDump = emptyDump; - } - - public int getContextId() { - return contextId; - } - - public T getReplyDump() { - return replyDump; - } - } - - @Override - public void close() throws Exception { - jvpp.close(); - } -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/future/FutureJVppInvoker.java b/java/jvpp-registry/io/fd/vpp/jvpp/future/FutureJVppInvoker.java deleted file mode 100644 index 65250ed..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/future/FutureJVppInvoker.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.future; - - -import io.fd.vpp.jvpp.dto.JVppReply; -import io.fd.vpp.jvpp.dto.JVppReplyDump; -import io.fd.vpp.jvpp.dto.JVppRequest; - -import java.util.concurrent.CompletionStage; -import io.fd.vpp.jvpp.notification.EventRegistryProvider; - -/** -* Future facade on top of JVpp -*/ -public interface FutureJVppInvoker extends EventRegistryProvider, AutoCloseable { - - /** - * Invoke asynchronous operation on VPP - * - * @return CompletionStage with future result of an async VPP call - * @throws io.fd.vpp.jvpp.VppInvocationException when send request failed with details - */ - > CompletionStage send(REQ req); - - - /** - * Invoke asynchronous dump operation on VPP - * - * @return CompletionStage with aggregated future result of an async VPP dump call - * @throws io.fd.vpp.jvpp.VppInvocationException when send request failed with details - */ - , DUMP extends JVppReplyDump> CompletionStage send( - REQ req, DUMP emptyReplyDump); -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/notification/EventRegistry.java b/java/jvpp-registry/io/fd/vpp/jvpp/notification/EventRegistry.java deleted file mode 100644 index 12515a5..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/notification/EventRegistry.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.notification; - -/** - * Base registry for notification callbacks. - */ -public interface EventRegistry extends AutoCloseable { - - void close(); -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/notification/EventRegistryProvider.java b/java/jvpp-registry/io/fd/vpp/jvpp/notification/EventRegistryProvider.java deleted file mode 100644 index 1ac5d55..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/notification/EventRegistryProvider.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.notification; - -/** - * Provides notification registry - */ -public interface EventRegistryProvider { - - /** - * Get current notification registry instance - */ - EventRegistry getEventRegistry(); -} diff --git a/java/jvpp-registry/io/fd/vpp/jvpp/test/ConnectionTest.java b/java/jvpp-registry/io/fd/vpp/jvpp/test/ConnectionTest.java deleted file mode 100644 index 27b4d29..0000000 --- a/java/jvpp-registry/io/fd/vpp/jvpp/test/ConnectionTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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 io.fd.vpp.jvpp.test; - -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.JVppRegistryImpl; - -/** - * Run using: - * sudo java -cp build-vpp-native/vpp-api/java/jvpp-registry-16.09.jar io.fd.vpp.jvpp.test.ConnectionTest - */ -public class ConnectionTest { - - private static void testConnect() throws Exception { - System.out.println("Testing JNI connection with JVppRegistry"); - final JVppRegistry registry = new JVppRegistryImpl("ConnectionTest"); - try { - System.out.println("Successfully connected to vpp"); - Thread.sleep(5000); - System.out.println("Disconnecting..."); - Thread.sleep(1000); - } finally { - registry.close(); - } - } - - public static void main(String[] args) throws Exception { - testConnect(); - } -} diff --git a/java/jvpp-registry/jvpp_registry.c b/java/jvpp-registry/jvpp_registry.c index bbe9719..a8dfa60 100644 --- a/java/jvpp-registry/jvpp_registry.c +++ b/java/jvpp-registry/jvpp_registry.c @@ -22,8 +22,8 @@ #include #include -#include "io_fd_vpp_jvpp_VppJNIConnection.h" -#include "io_fd_vpp_jvpp_JVppRegistryImpl.h" +#include "io_fd_jvpp_VppJNIConnection.h" +#include "io_fd_jvpp_JVppRegistryImpl.h" #include #define vl_typedefs /* define message structures */ @@ -145,7 +145,7 @@ static void vl_api_control_ping_reply_t_handler( rm->controlPingReplyClass, "", "()V"); jmethodID callbackMethod = (*env)->GetMethodID(env, rm->registryClass, "onControlPingReply", - "(Lio/fd/vpp/jvpp/dto/ControlPingReply;)V"); + "(Lio/fd/jvpp/dto/ControlPingReply;)V"); jobject dto = (*env)->NewObject(env, rm->controlPingReplyClass, constructor); @@ -276,7 +276,7 @@ static int connect_to_vpe(char *shm_prefix, char *name) { return send_initial_control_ping(); } -JNIEXPORT jobject JNICALL Java_io_fd_vpp_jvpp_VppJNIConnection_clientConnect( +JNIEXPORT jobject JNICALL Java_io_fd_jvpp_VppJNIConnection_clientConnect( JNIEnv *env, jclass obj, jstring shmPrefix, jstring clientName) { /* * TODO introducing memory prefix as variable can be used in hc2vpp @@ -291,7 +291,7 @@ JNIEXPORT jobject JNICALL Java_io_fd_vpp_jvpp_VppJNIConnection_clientConnect( jvpp_registry_main_t * rm = &jvpp_registry_main; jclass connectionInfoClass = (*env)->FindClass(env, - "io/fd/vpp/jvpp/VppJNIConnection$ConnectionInfo"); + "io/fd/jvpp/VppJNIConnection$ConnectionInfo"); jmethodID connectionInfoConstructor = (*env)->GetMethodID(env, connectionInfoClass, "", "(JIII)V"); @@ -327,7 +327,7 @@ JNIEXPORT jobject JNICALL Java_io_fd_vpp_jvpp_VppJNIConnection_clientConnect( (jint) jm->my_client_index, (jint) rv, (jint) rm->vpe_pid); } -JNIEXPORT jint JNICALL Java_io_fd_vpp_jvpp_JVppRegistryImpl_controlPing0( +JNIEXPORT jint JNICALL Java_io_fd_jvpp_JVppRegistryImpl_controlPing0( JNIEnv *env, jobject regstryObject) { jvpp_main_t * jm = &jvpp_main; vl_api_control_ping_t * mp; @@ -353,7 +353,7 @@ JNIEXPORT jint JNICALL Java_io_fd_vpp_jvpp_JVppRegistryImpl_controlPing0( return my_context_id; } -JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_VppJNIConnection_clientDisconnect( +JNIEXPORT void JNICALL Java_io_fd_jvpp_VppJNIConnection_clientDisconnect( JNIEnv *env, jclass clazz) { jvpp_registry_main_t * rm = &jvpp_registry_main; rm->is_connected = 0; // TODO make thread safe @@ -380,7 +380,7 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) { } rm->controlPingReplyClass = (jclass) (*env)->NewGlobalRef(env, - (*env)->FindClass(env, "io/fd/vpp/jvpp/dto/ControlPingReply")); + (*env)->FindClass(env, "io/fd/jvpp/dto/ControlPingReply")); if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionDescribe(env); clib_warning("Failed to cache class references\n"); @@ -388,7 +388,7 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) { } rm->callbackExceptionClass = (jclass) (*env)->NewGlobalRef(env, - (*env)->FindClass(env, "io/fd/vpp/jvpp/VppCallbackException")); + (*env)->FindClass(env, "io/fd/jvpp/VppCallbackException")); if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionDescribe(env); return JNI_ERR; diff --git a/java/jvpp/gen/jvppgen/callback_gen.py b/java/jvpp/gen/jvppgen/callback_gen.py index b1ad201..f1cc3a1 100755 --- a/java/jvpp/gen/jvppgen/callback_gen.py +++ b/java/jvpp/gen/jvppgen/callback_gen.py @@ -56,7 +56,7 @@ _CALLBACK_TEMPLATE = Template("""package $plugin_package.callback; *

Represents callback for plugin's api message. *
It was generated by jvppgen/callback_gen.py based on $json_filename. */ -public interface ${name}Callback extends io.fd.vpp.jvpp.callback.JVppCallback { +public interface ${name}Callback extends io.fd.jvpp.callback.JVppCallback { void on${name}(${plugin_package}.dto.${name} reply); } @@ -68,6 +68,6 @@ _GLOBAL_CALLBACK_TEMPLATE = Template("""package $plugin_package.callback; *

Global aggregated callback interface. *
It was generated by jvppgen/callback_gen.py based on $json_filename. */ -public interface JVpp${plugin_name}GlobalCallback extends io.fd.vpp.jvpp.callback.ControlPingCallback, $callbacks { +public interface JVpp${plugin_name}GlobalCallback extends io.fd.jvpp.callback.ControlPingCallback, $callbacks { } """) diff --git a/java/jvpp/gen/jvppgen/dto_gen.py b/java/jvpp/gen/jvppgen/dto_gen.py index cbd969d..c6e20fa 100755 --- a/java/jvpp/gen/jvppgen/dto_gen.py +++ b/java/jvpp/gen/jvppgen/dto_gen.py @@ -74,7 +74,7 @@ package $plugin_package.dto; $json_definition *

*/ -public final class $class_name implements io.fd.vpp.jvpp.dto.$base_type { +public final class $class_name implements io.fd.jvpp.dto.$base_type { $fields $hash_code $equals @@ -94,7 +94,7 @@ def _generate_send(model, msg): _SEND_TEMPLATE = Template(""" @Override - public int send(final io.fd.vpp.jvpp.JVpp jvpp) throws io.fd.vpp.jvpp.VppInvocationException { + public int send(final io.fd.jvpp.JVpp jvpp) throws io.fd.jvpp.VppInvocationException { return (($plugin_package.JVpp${plugin_name})jvpp).$method_name($args); }""") @@ -124,7 +124,7 @@ package $plugin_package.dto; $json_definition *
*/ -public final class $class_name implements io.fd.vpp.jvpp.dto.JVppReply<$plugin_package.dto.$request_name> { +public final class $class_name implements io.fd.jvpp.dto.JVppReply<$plugin_package.dto.$request_name> { $fields $hash_code $equals @@ -192,12 +192,12 @@ package $plugin_package.dto; $json_definition * */ -public final class ${details_class}ReplyDump implements io.fd.vpp.jvpp.dto.JVppReplyDump<${plugin_package}.dto.${dump_class}, ${plugin_package}.dto.${details_class}> { +public final class ${details_class}ReplyDump implements io.fd.jvpp.dto.JVppReplyDump<${plugin_package}.dto.${dump_class}, ${plugin_package}.dto.${details_class}> { public java.util.List<${details_class}> ${details_field} = new java.util.ArrayList<>(); @Override - @io.fd.vpp.jvpp.coverity.SuppressFBWarnings("UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD") + @io.fd.jvpp.coverity.SuppressFBWarnings("UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD") public int hashCode() { return java.util.Objects.hash(${details_field}); } diff --git a/java/jvpp/gen/jvppgen/jni_gen.py b/java/jvpp/gen/jvppgen/jni_gen.py index ad6c261..d73f7bf 100755 --- a/java/jvpp/gen/jvppgen/jni_gen.py +++ b/java/jvpp/gen/jvppgen/jni_gen.py @@ -65,10 +65,10 @@ def _generate_class_cache(plugin_name, messages): continue references.append(( msg.java_name_lower, - 'io/fd/vpp/jvpp/%s/dto/%s' % (plugin_name, msg.java_name_upper) + 'io/fd/jvpp/%s/dto/%s' % (plugin_name, msg.java_name_upper) )) - references.append(('callbackException', 'io/fd/vpp/jvpp/VppCallbackException')) + references.append(('callbackException', 'io/fd/jvpp/VppCallbackException')) return _CLASS_CACHE_TEMPLATE.substitute( class_references=_generate_class_references(references), diff --git a/java/jvpp/gen/jvppgen/jni_impl_gen.py b/java/jvpp/gen/jvppgen/jni_impl_gen.py index ef1bcbb..e53e5de 100755 --- a/java/jvpp/gen/jvppgen/jni_impl_gen.py +++ b/java/jvpp/gen/jvppgen/jni_impl_gen.py @@ -68,7 +68,7 @@ _JNI_IMPL_TEMPLATE = Template(""" * Generated based on $json_filename: $json_definition */ -JNIEXPORT jint JNICALL Java_io_fd_vpp_jvpp_${plugin_name}_JVpp${plugin_java_name}Impl_${java_method_name}0 +JNIEXPORT jint JNICALL Java_io_fd_jvpp_${plugin_name}_JVpp${plugin_java_name}Impl_${java_method_name}0 (JNIEnv * env, jclass clazz${arguments}) { ${plugin_name}_main_t *plugin_main = &${plugin_name}_main; vl_api_${c_name}_t * mp; @@ -98,7 +98,7 @@ $msg_initialization # TODO: cache method and field identifiers to achieve better performance # https://jira.fd.io/browse/HONEYCOMB-42 -_REQUEST_CLASS_TEMPLATE = Template(""" jclass requestClass = (*env)->FindClass(env, "io/fd/vpp/jvpp/${plugin_name}/dto/${java_dto_name}"); +_REQUEST_CLASS_TEMPLATE = Template(""" jclass requestClass = (*env)->FindClass(env, "io/fd/jvpp/${plugin_name}/dto/${java_dto_name}"); """) diff --git a/java/jvpp/gen/jvppgen/jni_msg_handlers_gen.py b/java/jvpp/gen/jvppgen/jni_msg_handlers_gen.py index ccd3dbc..e223526 100755 --- a/java/jvpp/gen/jvppgen/jni_msg_handlers_gen.py +++ b/java/jvpp/gen/jvppgen/jni_msg_handlers_gen.py @@ -67,7 +67,7 @@ $err_handler // User does not have to provide callbacks for all VPP messages. // We are ignoring messages that are not supported by user. (*env)->ExceptionClear(env); // just in case exception occurred in different place and was not properly cleared - jmethodID callbackMethod = (*env)->GetMethodID(env, plugin_main->callbackClass, "on${dto_name}", "(Lio/fd/vpp/jvpp/${plugin_name}/dto/${dto_name};)V"); + jmethodID callbackMethod = (*env)->GetMethodID(env, plugin_main->callbackClass, "on${dto_name}", "(Lio/fd/jvpp/${plugin_name}/dto/${dto_name};)V"); exc = (*env)->ExceptionOccurred(env); if (exc) { clib_warning("Unable to extract on${dto_name} method reference from ${plugin_name} plugin's callbackClass. Ignoring message.\\n"); diff --git a/java/jvpp/gen/jvppgen/jvpp_callback_facade_gen.py b/java/jvpp/gen/jvppgen/jvpp_callback_facade_gen.py index ebc552b..d41080d 100644 --- a/java/jvpp/gen/jvppgen/jvpp_callback_facade_gen.py +++ b/java/jvpp/gen/jvppgen/jvpp_callback_facade_gen.py @@ -41,7 +41,7 @@ package $plugin_package.callfacade; *

Callback Java API representation of $plugin_package plugin. *
It was generated by jvpp_callback_facade_gen.py based on $json_filename. */ -public interface CallbackJVpp${plugin_name} extends io.fd.vpp.jvpp.notification.EventRegistryProvider, java.lang.AutoCloseable { +public interface CallbackJVpp${plugin_name} extends io.fd.jvpp.notification.EventRegistryProvider, java.lang.AutoCloseable { // TODO add send @@ -72,10 +72,10 @@ def _generate_ifc_methods(model): return "\n".join(methods) _IFC_NO_ARG_METHOD_TEMPLATE = Template( - """ void $name($plugin_package.callback.${reply}Callback callback) throws io.fd.vpp.jvpp.VppInvocationException;""") + """ void $name($plugin_package.callback.${reply}Callback callback) throws io.fd.jvpp.VppInvocationException;""") _IFC_METHOD_TEMPLATE = Template( - """ void $name($plugin_package.dto.$request request, $plugin_package.callback.${reply}Callback callback) throws io.fd.vpp.jvpp.VppInvocationException;""") + """ void $name($plugin_package.dto.$request request, $plugin_package.callback.${reply}Callback callback) throws io.fd.jvpp.VppInvocationException;""") def _generate_impl(work_dir, model): @@ -97,18 +97,18 @@ package $plugin_package.callfacade; public final class CallbackJVpp${plugin_name}Facade implements CallbackJVpp${plugin_name} { private final $plugin_package.JVpp${plugin_name} jvpp; - private final java.util.Map callbacks; + private final java.util.Map callbacks; private final $plugin_package.notification.${plugin_name}EventRegistryImpl eventRegistry = new $plugin_package.notification.${plugin_name}EventRegistryImpl(); /** *

Create CallbackJVpp${plugin_name}Facade object for provided JVpp instance. * Constructor internally creates CallbackJVppFacadeCallback class for processing callbacks * and then connects to provided JVpp instance * - * @param jvpp provided io.fd.vpp.jvpp.JVpp instance + * @param jvpp provided io.fd.jvpp.JVpp instance * * @throws java.io.IOException in case instance cannot connect to JVPP */ - public CallbackJVpp${plugin_name}Facade(final io.fd.vpp.jvpp.JVppRegistry registry, final $plugin_package.JVpp${plugin_name} jvpp) throws java.io.IOException { + public CallbackJVpp${plugin_name}Facade(final io.fd.jvpp.JVppRegistry registry, final $plugin_package.JVpp${plugin_name} jvpp) throws java.io.IOException { this.jvpp = java.util.Objects.requireNonNull(jvpp,"jvpp is null"); this.callbacks = new java.util.HashMap<>(); java.util.Objects.requireNonNull(registry, "JVppRegistry should not be null"); @@ -154,14 +154,14 @@ def _generate_impl_methods(model): return "\n".join(methods) _IMPL_NO_ARG_METHOD_TEMPLATE = Template( - """ public final void $name($plugin_package.callback.${reply}Callback callback) throws io.fd.vpp.jvpp.VppInvocationException { + """ public final void $name($plugin_package.callback.${reply}Callback callback) throws io.fd.jvpp.VppInvocationException { synchronized (callbacks) { callbacks.put(jvpp.$name(), callback); } } """) -_IMPL_METHOD_TEMPLATE = Template(""" public final void $name($plugin_package.dto.$request request, $plugin_package.callback.${reply}Callback callback) throws io.fd.vpp.jvpp.VppInvocationException { +_IMPL_METHOD_TEMPLATE = Template(""" public final void $name($plugin_package.dto.$request request, $plugin_package.callback.${reply}Callback callback) throws io.fd.jvpp.VppInvocationException { synchronized (callbacks) { callbacks.put(jvpp.$name(request), callback); } @@ -187,20 +187,20 @@ package $plugin_package.callfacade; */ public final class CallbackJVpp${plugin_name}FacadeCallback implements $plugin_package.callback.JVpp${plugin_name}GlobalCallback { - private final java.util.Map requests; + private final java.util.Map requests; private final $plugin_package.notification.Global${plugin_name}EventCallback eventCallback; private static final java.util.logging.Logger LOG = java.util.logging.Logger.getLogger(CallbackJVpp${plugin_name}FacadeCallback.class.getName()); - public CallbackJVpp${plugin_name}FacadeCallback(final java.util.Map requestMap, + public CallbackJVpp${plugin_name}FacadeCallback(final java.util.Map requestMap, final $plugin_package.notification.Global${plugin_name}EventCallback eventCallback) { this.requests = requestMap; this.eventCallback = eventCallback; } @Override - public void onError(io.fd.vpp.jvpp.VppCallbackException reply) { + public void onError(io.fd.jvpp.VppCallbackException reply) { - io.fd.vpp.jvpp.callback.JVppCallback failedCall; + io.fd.jvpp.callback.JVppCallback failedCall; synchronized(requests) { failedCall = requests.remove(reply.getCtxId()); } @@ -217,12 +217,12 @@ public final class CallbackJVpp${plugin_name}FacadeCallback implements $plugin_p @Override @SuppressWarnings("unchecked") - public void onControlPingReply(final io.fd.vpp.jvpp.dto.ControlPingReply reply) { + public void onControlPingReply(final io.fd.jvpp.dto.ControlPingReply reply) { - io.fd.vpp.jvpp.callback.ControlPingCallback callback; + io.fd.jvpp.callback.ControlPingCallback callback; final int replyId = reply.context; synchronized(requests) { - callback = (io.fd.vpp.jvpp.callback.ControlPingCallback) requests.remove(replyId); + callback = (io.fd.jvpp.callback.ControlPingCallback) requests.remove(replyId); } if(callback != null) { diff --git a/java/jvpp/gen/jvppgen/jvpp_common_gen.py b/java/jvpp/gen/jvppgen/jvpp_common_gen.py index 499adbc..430c927 100755 --- a/java/jvpp/gen/jvppgen/jvpp_common_gen.py +++ b/java/jvpp/gen/jvppgen/jvpp_common_gen.py @@ -32,14 +32,14 @@ def generate_hash_code(fields): _HASH_CODE_TEMPLATE = Template(""" @Override - @io.fd.vpp.jvpp.coverity.SuppressFBWarnings("UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD") + @io.fd.jvpp.coverity.SuppressFBWarnings("UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD") public int hashCode() { return java.util.Objects.hash($fields); }""") _HASH_CODE_SINGLE_ARRAY_TEMPLATE = Template(""" @Override - @io.fd.vpp.jvpp.coverity.SuppressFBWarnings("UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD") + @io.fd.jvpp.coverity.SuppressFBWarnings("UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD") public int hashCode() { return java.util.Arrays.hashCode($array_field); }""") diff --git a/java/jvpp/gen/jvppgen/jvpp_future_facade_gen.py b/java/jvpp/gen/jvppgen/jvpp_future_facade_gen.py index 3da367a..7585906 100644 --- a/java/jvpp/gen/jvppgen/jvpp_future_facade_gen.py +++ b/java/jvpp/gen/jvppgen/jvpp_future_facade_gen.py @@ -40,7 +40,7 @@ package $plugin_package.future; *

Async facade extension adding specific methods for each request invocation *
It was generated by jvpp_future_facade_gen.py based on $json_filename. */ -public interface FutureJVpp${plugin_name} extends io.fd.vpp.jvpp.future.FutureJVppInvoker { +public interface FutureJVpp${plugin_name} extends io.fd.jvpp.future.FutureJVppInvoker { $methods @Override @@ -94,7 +94,7 @@ package $plugin_package.future; *

Implementation of FutureJVpp based on AbstractFutureJVppInvoker *
It was generated by jvpp_future_facade_gen.py based on $json_filename. */ -public class FutureJVpp${plugin_name}Facade extends io.fd.vpp.jvpp.future.AbstractFutureJVppInvoker implements FutureJVpp${plugin_name} { +public class FutureJVpp${plugin_name}Facade extends io.fd.jvpp.future.AbstractFutureJVppInvoker implements FutureJVpp${plugin_name} { private final $plugin_package.notification.${plugin_name}EventRegistryImpl eventRegistry = new $plugin_package.notification.${plugin_name}EventRegistryImpl(); @@ -103,11 +103,11 @@ public class FutureJVpp${plugin_name}Facade extends io.fd.vpp.jvpp.future.Abstra * Constructor internally creates FutureJVppFacadeCallback class for processing callbacks * and then connects to provided JVpp instance * - * @param jvpp provided io.fd.vpp.jvpp.JVpp instance + * @param jvpp provided io.fd.jvpp.JVpp instance * * @throws java.io.IOException in case instance cannot connect to JVPP */ - public FutureJVpp${plugin_name}Facade(final io.fd.vpp.jvpp.JVppRegistry registry, final io.fd.vpp.jvpp.JVpp jvpp) throws java.io.IOException { + public FutureJVpp${plugin_name}Facade(final io.fd.jvpp.JVppRegistry registry, final io.fd.jvpp.JVpp jvpp) throws java.io.IOException { super(jvpp, registry, new java.util.HashMap<>()); java.util.Objects.requireNonNull(registry, "JVppRegistry should not be null"); registry.register(jvpp, new FutureJVpp${plugin_name}FacadeCallback(getRequests(), eventRegistry)); @@ -178,12 +178,12 @@ package $plugin_package.future; */ public final class FutureJVpp${plugin_name}FacadeCallback implements $plugin_package.callback.JVpp${plugin_name}GlobalCallback { - private final java.util.Map>> requests; + private final java.util.Map>> requests; private final $plugin_package.notification.Global${plugin_name}EventCallback notificationCallback; private static final java.util.logging.Logger LOG = java.util.logging.Logger.getLogger(FutureJVpp${plugin_name}FacadeCallback.class.getName()); public FutureJVpp${plugin_name}FacadeCallback( - final java.util.Map>> requestMap, + final java.util.Map>> requestMap, final $plugin_package.notification.Global${plugin_name}EventCallback notificationCallback) { this.requests = requestMap; this.notificationCallback = notificationCallback; @@ -191,11 +191,11 @@ public final class FutureJVpp${plugin_name}FacadeCallback implements $plugin_pac @Override @SuppressWarnings("unchecked") - public void onError(io.fd.vpp.jvpp.VppCallbackException reply) { - final java.util.concurrent.CompletableFuture> completableFuture; + public void onError(io.fd.jvpp.VppCallbackException reply) { + final java.util.concurrent.CompletableFuture> completableFuture; synchronized(requests) { - completableFuture = (java.util.concurrent.CompletableFuture>) requests.get(reply.getCtxId()); + completableFuture = (java.util.concurrent.CompletableFuture>) requests.get(reply.getCtxId()); } if(completableFuture != null) { @@ -209,19 +209,19 @@ public final class FutureJVpp${plugin_name}FacadeCallback implements $plugin_pac @Override @SuppressWarnings("unchecked") - public void onControlPingReply(final io.fd.vpp.jvpp.dto.ControlPingReply reply) { - java.util.concurrent.CompletableFuture> completableFuture; + public void onControlPingReply(final io.fd.jvpp.dto.ControlPingReply reply) { + java.util.concurrent.CompletableFuture> completableFuture; final int replyId = reply.context; synchronized(requests) { - completableFuture = (java.util.concurrent.CompletableFuture>) requests.get(replyId); + completableFuture = (java.util.concurrent.CompletableFuture>) requests.get(replyId); if(completableFuture != null) { // Finish dump call - if (completableFuture instanceof io.fd.vpp.jvpp.future.AbstractFutureJVppInvoker.CompletableDumpFuture) { - completableFuture.complete(((io.fd.vpp.jvpp.future.AbstractFutureJVppInvoker.CompletableDumpFuture) completableFuture).getReplyDump()); + if (completableFuture instanceof io.fd.jvpp.future.AbstractFutureJVppInvoker.CompletableDumpFuture) { + completableFuture.complete(((io.fd.jvpp.future.AbstractFutureJVppInvoker.CompletableDumpFuture) completableFuture).getReplyDump()); // Remove future mapped to dump call context id - requests.remove(((io.fd.vpp.jvpp.future.AbstractFutureJVppInvoker.CompletableDumpFuture) completableFuture).getContextId()); + requests.remove(((io.fd.jvpp.future.AbstractFutureJVppInvoker.CompletableDumpFuture) completableFuture).getContextId()); } else { // reply to regular control ping, complete the future completableFuture.complete(reply); @@ -277,19 +277,19 @@ _FUTURE_JVPP_FACADE_DETAILS_CALLBACK_TEMPLATE = Template(""" @Override @SuppressWarnings("unchecked") public void on$callback_dto(final $plugin_package.dto.$callback_dto reply) { - io.fd.vpp.jvpp.future.AbstractFutureJVppInvoker.CompletableDumpFuture<$plugin_package.dto.${callback_dto}ReplyDump> completableFuture; + io.fd.jvpp.future.AbstractFutureJVppInvoker.CompletableDumpFuture<$plugin_package.dto.${callback_dto}ReplyDump> completableFuture; final int replyId = reply.context; if (LOG.isLoggable(java.util.logging.Level.FINE)) { LOG.fine(java.lang.String.format("Received $callback_dto event message: %s", reply)); } synchronized(requests) { - completableFuture = (io.fd.vpp.jvpp.future.AbstractFutureJVppInvoker.CompletableDumpFuture<$plugin_package.dto.${callback_dto}ReplyDump>) requests.get(replyId); + completableFuture = (io.fd.jvpp.future.AbstractFutureJVppInvoker.CompletableDumpFuture<$plugin_package.dto.${callback_dto}ReplyDump>) requests.get(replyId); if(completableFuture == null) { // reply received before writer created future, // create new future, and put into map to notify sender that reply is already received, // following details replies will add information to this future - completableFuture = new io.fd.vpp.jvpp.future.AbstractFutureJVppInvoker.CompletableDumpFuture<>(replyId, + completableFuture = new io.fd.jvpp.future.AbstractFutureJVppInvoker.CompletableDumpFuture<>(replyId, new $plugin_package.dto.${callback_dto}ReplyDump()); requests.put(replyId, completableFuture); } @@ -302,14 +302,14 @@ _FUTURE_JVPP_FACADE_REPLY_CALLBACK_TEMPLATE = Template(""" @Override @SuppressWarnings("unchecked") public void on$callback_dto(final $plugin_package.dto.$callback_dto reply) { - java.util.concurrent.CompletableFuture> completableFuture; + java.util.concurrent.CompletableFuture> completableFuture; final int replyId = reply.context; if (LOG.isLoggable(java.util.logging.Level.FINE)) { LOG.fine(java.lang.String.format("Received $callback_dto event message: %s", reply)); } synchronized(requests) { completableFuture = - (java.util.concurrent.CompletableFuture>) requests.get(replyId); + (java.util.concurrent.CompletableFuture>) requests.get(replyId); if(completableFuture != null) { // received reply on request, complete future created by sender and remove it from map diff --git a/java/jvpp/gen/jvppgen/jvpp_ifc_gen.py b/java/jvpp/gen/jvppgen/jvpp_ifc_gen.py index e2b2922..8350bbe 100755 --- a/java/jvpp/gen/jvppgen/jvpp_ifc_gen.py +++ b/java/jvpp/gen/jvppgen/jvpp_ifc_gen.py @@ -48,9 +48,9 @@ def _jvpp_ifc_filter(msg): _JVPP_IFC_METHOD_TEMPLATE = Template( - """ int $name($plugin_package.dto.$type request) throws io.fd.vpp.jvpp.VppInvocationException;""") + """ int $name($plugin_package.dto.$type request) throws io.fd.jvpp.VppInvocationException;""") -_JVPP_IFC_NO_ARG_METHOD_TEMPLATE = Template(""" int $name() throws io.fd.vpp.jvpp.VppInvocationException;""") +_JVPP_IFC_NO_ARG_METHOD_TEMPLATE = Template(""" int $name() throws io.fd.jvpp.VppInvocationException;""") _JVPP_IFC_TEMPLATE = Template("""package $plugin_package; @@ -59,13 +59,13 @@ _JVPP_IFC_TEMPLATE = Template("""package $plugin_package; *
It was generated by jvpp_impl_gen.py based on $json_filename. *
(python representation of api file generated by vppapigen) */ -public interface JVpp${plugin_name} extends io.fd.vpp.jvpp.JVpp { +public interface JVpp${plugin_name} extends io.fd.jvpp.JVpp { /** * Generic dispatch method for sending requests to VPP * - * @throws io.fd.vpp.jvpp.VppInvocationException if send request had failed + * @throws io.fd.jvpp.VppInvocationException if send request had failed */ - int send(io.fd.vpp.jvpp.dto.JVppRequest request) throws io.fd.vpp.jvpp.VppInvocationException; + int send(io.fd.jvpp.dto.JVppRequest request) throws io.fd.jvpp.VppInvocationException; $methods } """) diff --git a/java/jvpp/gen/jvppgen/jvpp_impl_gen.py b/java/jvpp/gen/jvppgen/jvpp_impl_gen.py index 376952b..f646efa 100755 --- a/java/jvpp/gen/jvppgen/jvpp_impl_gen.py +++ b/java/jvpp/gen/jvppgen/jvpp_impl_gen.py @@ -62,9 +62,9 @@ import java.nio.file.attribute.PosixFilePermissions; import java.util.Set; import java.util.logging.Logger; import java.util.logging.Level; -import io.fd.vpp.jvpp.callback.JVppCallback; -import io.fd.vpp.jvpp.VppConnection; -import io.fd.vpp.jvpp.JVppRegistry; +import io.fd.jvpp.callback.JVppCallback; +import io.fd.jvpp.VppConnection; +import io.fd.jvpp.JVppRegistry; /** *

Default implementation of JVpp interface. @@ -133,12 +133,12 @@ public final class JVpp${plugin_name}Impl implements $plugin_package.JVpp${plugi } @Override - public int send(io.fd.vpp.jvpp.dto.JVppRequest request) throws io.fd.vpp.jvpp.VppInvocationException { + public int send(io.fd.jvpp.dto.JVppRequest request) throws io.fd.jvpp.VppInvocationException { return request.send(this); } @Override - public final int controlPing(final io.fd.vpp.jvpp.dto.ControlPing controlPing) throws io.fd.vpp.jvpp.VppInvocationException { + public final int controlPing(final io.fd.jvpp.dto.ControlPing controlPing) throws io.fd.jvpp.VppInvocationException { return registry.controlPing(JVpp${plugin_name}Impl.class); } $methods @@ -147,7 +147,7 @@ $methods _JVPP_IMPL_METHOD_TEMPLATE = Template(""" private static native int ${name}0($plugin_package.dto.$type request); - public final int $name($plugin_package.dto.$type request) throws io.fd.vpp.jvpp.VppInvocationException { + public final int $name($plugin_package.dto.$type request) throws io.fd.jvpp.VppInvocationException { java.util.Objects.requireNonNull(request, "Null request object"); connection.checkActive(); if (LOG.isLoggable(Level.FINE)) { @@ -155,19 +155,19 @@ _JVPP_IMPL_METHOD_TEMPLATE = Template(""" } int result=${name}0(request); if (result<0){ - throw new io.fd.vpp.jvpp.VppInvocationException("${name}", result); + throw new io.fd.jvpp.VppInvocationException("${name}", result); } return result; }""") _JVPP_IMPL_NO_ARG_METHOD_TEMPLATE = Template(""" - private static native int ${name}0() throws io.fd.vpp.jvpp.VppInvocationException; - public final int $name() throws io.fd.vpp.jvpp.VppInvocationException { + private static native int ${name}0() throws io.fd.jvpp.VppInvocationException; + public final int $name() throws io.fd.jvpp.VppInvocationException { connection.checkActive(); LOG.fine("Sending $type event message"); int result=${name}0(); if(result<0){ - throw new io.fd.vpp.jvpp.VppInvocationException("${name}", result); + throw new io.fd.jvpp.VppInvocationException("${name}", result); } return result; }""") diff --git a/java/jvpp/gen/jvppgen/jvpp_model.py b/java/jvpp/gen/jvppgen/jvpp_model.py index c5a7e74..6c599c0 100755 --- a/java/jvpp/gen/jvppgen/jvpp_model.py +++ b/java/jvpp/gen/jvppgen/jvpp_model.py @@ -19,7 +19,7 @@ from collections import OrderedDict import binascii -BASE_PACKAGE = "io.fd.vpp.jvpp" +BASE_PACKAGE = "io.fd.jvpp" class ParseException(Exception): @@ -34,8 +34,8 @@ class Type(object): :param name: name of type as defined in .api file, e.g. u8, u32[] or mac_entry :param java_name: corresponding java name, e.g. byte, int[] or MacEntry - :param java_name_fqn: fully qualified java name, e.g. io.fd.vpp.jvpp.core.types.MacEntry - :param jni_signature: JNI Type signature, e.g. B, [I or Lio.fd.vpp.jvpp.core.types.MacEntry; + :param java_name_fqn: fully qualified java name, e.g. io.fd.jvpp.core.types.MacEntry + :param jni_signature: JNI Type signature, e.g. B, [I or Lio.fd.jvpp.core.types.MacEntry; See https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/types.html#type_signatures :param jni_type: JNI reference type, e.g. jbyte jintArray, jobject See https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/types.html#reference_types @@ -121,8 +121,8 @@ class Enum(Type): super(Enum, self).__init__( name=name, java_name=_java_name, - java_name_fqn="io.fd.vpp.jvpp.%s.types.%s" % (plugin_name, _java_name), - jni_signature="Lio/fd/vpp/jvpp/%s/types/%s;" % (plugin_name, _java_name), + java_name_fqn="io.fd.jvpp.%s.types.%s" % (plugin_name, _java_name), + jni_signature="Lio/fd/jvpp/%s/types/%s;" % (plugin_name, _java_name), jni_type="jobject", jni_accessor="Object", host_to_net_function="_host_to_net_%s" % name, @@ -136,7 +136,7 @@ class Enum(Type): self.vpp_name = "%s%s%s" % (_VPP_TYPE_PREFIX, name, _VPP_TYPE_SUFFIX) # Fully qualified class name used by FindClass function, see: # https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#FindClass - self.jni_name = "io/fd/vpp/jvpp/%s/types/%s" % (plugin_name, _java_name) + self.jni_name = "io/fd/jvpp/%s/types/%s" % (plugin_name, _java_name) def get_host_to_net_function(self, host_ref_name, net_ref_name): return "_host_to_net_%s(env, %s, &(%s))" % (self.name, host_ref_name, net_ref_name) @@ -149,8 +149,8 @@ class EnumSet(Type): super(EnumSet, self).__init__( name=name, java_name=_java_name, - java_name_fqn="io.fd.vpp.jvpp.%s.types.%s" % (plugin_name, _java_name), - jni_signature="Lio/fd/vpp/jvpp/%s/types/%s;" % (plugin_name, _java_name), + java_name_fqn="io.fd.jvpp.%s.types.%s" % (plugin_name, _java_name), + jni_signature="Lio/fd/jvpp/%s/types/%s;" % (plugin_name, _java_name), jni_type="jobject", jni_accessor="Object", host_to_net_function="_host_to_net_%s" % name, @@ -164,7 +164,7 @@ class EnumSet(Type): self.vpp_name = "%s%s%s" % (_VPP_TYPE_PREFIX, name, _VPP_TYPE_SUFFIX) # Fully qualified class name used by FindClass function, see: # https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#FindClass - self.jni_name = "io/fd/vpp/jvpp/%s/types/%s" % (plugin_name, _java_name) + self.jni_name = "io/fd/jvpp/%s/types/%s" % (plugin_name, _java_name) def get_host_to_net_function(self, host_ref_name, net_ref_name): return "_host_to_net_%s(env, %s, &(%s))" % (self.name, host_ref_name, net_ref_name) @@ -177,8 +177,8 @@ class Class(Type): super(Class, self).__init__( name=name, java_name=_java_name, - java_name_fqn="io.fd.vpp.jvpp.%s.types.%s" % (plugin_name, _java_name), - jni_signature="Lio/fd/vpp/jvpp/%s/types/%s;" % (plugin_name, _java_name), + java_name_fqn="io.fd.jvpp.%s.types.%s" % (plugin_name, _java_name), + jni_signature="Lio/fd/jvpp/%s/types/%s;" % (plugin_name, _java_name), jni_type="jobject", jni_accessor="Object", host_to_net_function="_host_to_net_%s" % name, @@ -192,7 +192,7 @@ class Class(Type): self.vpp_name = "%s%s%s" % (_VPP_TYPE_PREFIX, name, _VPP_TYPE_SUFFIX) # Fully qualified class name used by FindClass function, see: # https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#FindClass - self.jni_name = "io/fd/vpp/jvpp/%s/types/%s" % (plugin_name, _java_name) + self.jni_name = "io/fd/jvpp/%s/types/%s" % (plugin_name, _java_name) def get_host_to_net_function(self, host_ref_name, net_ref_name): return "_host_to_net_%s(env, %s, &(%s))" % (self.name, host_ref_name, net_ref_name) @@ -205,8 +205,8 @@ class Union(Type): super(Union, self).__init__( name=name, java_name=_java_name, - java_name_fqn="io.fd.vpp.jvpp.%s.types.%s" % (plugin_name, _java_name), - jni_signature="Lio/fd/vpp/jvpp/%s/types/%s;" % (plugin_name, _java_name), + java_name_fqn="io.fd.jvpp.%s.types.%s" % (plugin_name, _java_name), + jni_signature="Lio/fd/jvpp/%s/types/%s;" % (plugin_name, _java_name), jni_type="jobject", jni_accessor="Object", host_to_net_function="_host_to_net_%s" % name, @@ -220,7 +220,7 @@ class Union(Type): self.vpp_name = "%s%s%s" % (_VPP_TYPE_PREFIX, name, _VPP_TYPE_SUFFIX) # Fully qualified class name used by FindClass function, see: # https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#FindClass - self.jni_name = "io/fd/vpp/jvpp/%s/types/%s" % (plugin_name, _java_name) + self.jni_name = "io/fd/jvpp/%s/types/%s" % (plugin_name, _java_name) def get_host_to_net_function(self, host_ref_name, net_ref_name): return "_host_to_net_%s(env, %s, &(%s))" % (self.name, host_ref_name, net_ref_name) diff --git a/java/jvpp/gen/jvppgen/notification_gen.py b/java/jvpp/gen/jvppgen/notification_gen.py index fa86fe4..d2bb729 100644 --- a/java/jvpp/gen/jvppgen/notification_gen.py +++ b/java/jvpp/gen/jvppgen/notification_gen.py @@ -63,7 +63,7 @@ package $plugin_package.notification; *

Registry for notification callbacks defined in ${plugin_name}. *
It was generated by notification_gen.py based on $json_filename. */ -public interface ${plugin_name}EventRegistry extends io.fd.vpp.jvpp.notification.EventRegistry { +public interface ${plugin_name}EventRegistry extends io.fd.jvpp.notification.EventRegistry { $register_callback_methods @@ -119,7 +119,7 @@ _HANDLER_IMPL_TEMPLATE = Template(""" if (LOG.isLoggable(java.util.logging.Level.FINE)) { LOG.fine(java.lang.String.format("Received $notification event message: %s", notification)); } - final io.fd.vpp.jvpp.callback.JVppCallback jVppCallback = registeredCallbacks.get($plugin_package.dto.$notification.class); + final io.fd.jvpp.callback.JVppCallback jVppCallback = registeredCallbacks.get($plugin_package.dto.$notification.class); if (null != jVppCallback) { (($plugin_package.callback.$callback) registeredCallbacks .get($plugin_package.dto.$notification.class)) @@ -138,7 +138,7 @@ package $plugin_package.notification; public final class ${plugin_name}EventRegistryImpl implements ${plugin_name}EventRegistry, Global${plugin_name}EventCallback { // TODO add a special NotificationCallback interface and only allow those to be registered - private final java.util.concurrent.ConcurrentMap, io.fd.vpp.jvpp.callback.JVppCallback> registeredCallbacks = + private final java.util.concurrent.ConcurrentMap, io.fd.jvpp.callback.JVppCallback> registeredCallbacks = new java.util.concurrent.ConcurrentHashMap<>(); private static java.util.logging.Logger LOG = java.util.logging.Logger.getLogger(${plugin_name}EventRegistryImpl.class.getName()); @@ -151,7 +151,7 @@ public final class ${plugin_name}EventRegistryImpl implements ${plugin_name}Even } @Override - public void onError(io.fd.vpp.jvpp.VppCallbackException ex) { + public void onError(io.fd.jvpp.VppCallbackException ex) { java.util.logging.Logger LOG = java.util.logging.Logger.getLogger(${plugin_name}EventRegistryImpl.class.getName()); LOG.log(java.util.logging.Level.WARNING, java.lang.String.format("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(), ex.getCtxId(), ex.getErrorCode()), ex); @@ -210,7 +210,7 @@ package $plugin_package.notification; * Provides ${plugin_name}EventRegistry. *
The file was generated by notification_gen.py based on $json_filename. */ -public interface ${plugin_name}EventRegistryProvider extends io.fd.vpp.jvpp.notification.EventRegistryProvider { +public interface ${plugin_name}EventRegistryProvider extends io.fd.jvpp.notification.EventRegistryProvider { @Override public ${plugin_name}EventRegistry getEventRegistry(); -- cgit 1.2.3-korg