aboutsummaryrefslogtreecommitdiffstats
path: root/vpp-api/java/jvpp/org
diff options
context:
space:
mode:
authorTibor Sirovatka <tsirovat@cisco.com>2016-05-18 14:54:50 +0200
committerDave Wallace <dwallacelf@gmail.com>2016-06-09 02:22:34 +0000
commit42bb61fd162b3dd469c9d98a9dc6d3e2b2eaffce (patch)
tree133e183e7b02d7d7e01f1ea1353421d8a65ddb2b /vpp-api/java/jvpp/org
parentb10427e06077dbe3a9ea9922b97941204001f6b9 (diff)
HONEYCOMB-67 Introduce exception handling into JVPP
Send calls throws VppInvocationException on failure Failed requests (negative retval) reported over onError callback interface method Removed retval attributes from dto/xxxReply.java calls Change-Id: Ibd4e90c320d080e02d75b4bd056a7b11c8e37aa7 Signed-off-by: Tibor Sirovatka <tsirovat@cisco.com>
Diffstat (limited to 'vpp-api/java/jvpp/org')
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/VppBaseCallException.java60
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/VppCallbackException.java47
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/VppInvocationException.java33
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/callback/JVppCallback.java10
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/dto/JVppRequest.java3
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/future/FutureJVppInvoker.java4
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/future/FutureJVppInvokerFacade.java42
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/test/CallbackApiTest.java27
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/test/CallbackJVppFacadeTest.java60
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/test/ControlPingTest.java11
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/test/CreateSubInterfaceTest.java7
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/test/FutureApiTest.java31
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/test/L2AclTest.java13
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/test/OnErrorCallbackTest.java74
-rw-r--r--vpp-api/java/jvpp/org/openvpp/jvpp/test/Readme.txt3
15 files changed, 349 insertions, 76 deletions
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/VppBaseCallException.java b/vpp-api/java/jvpp/org/openvpp/jvpp/VppBaseCallException.java
new file mode 100644
index 00000000000..792af2c69ec
--- /dev/null
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/VppBaseCallException.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 org.openvpp.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 );
+ }
+ }
+
+ /**
+ * 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/vpp-api/java/jvpp/org/openvpp/jvpp/VppCallbackException.java b/vpp-api/java/jvpp/org/openvpp/jvpp/VppCallbackException.java
new file mode 100644
index 00000000000..3d2a1cb2013
--- /dev/null
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/VppCallbackException.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openvpp.jvpp;
+
+/**
+ * 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 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 int ctxId, final int errorCode ){
+ super(methodName, errorCode);
+ this.ctxId = ctxId;
+ }
+
+ /**
+ * Returns api request context identifier.
+ *
+ * @return value of context identifier
+ */
+ public int getCtxId() {
+ return ctxId;
+ }
+
+}
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/VppInvocationException.java b/vpp-api/java/jvpp/org/openvpp/jvpp/VppInvocationException.java
new file mode 100644
index 00000000000..298bcd0ae55
--- /dev/null
+++ b/vpp-api/java/jvpp/org/openvpp/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 org.openvpp.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/vpp-api/java/jvpp/org/openvpp/jvpp/callback/JVppCallback.java b/vpp-api/java/jvpp/org/openvpp/jvpp/callback/JVppCallback.java
index c17f2e0aa96..f681e379bfd 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/callback/JVppCallback.java
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/callback/JVppCallback.java
@@ -15,9 +15,15 @@
*/
package org.openvpp.jvpp.callback;
+import org.openvpp.jvpp.VppCallbackException;
/**
-* Base JVppCallback interface
-*/
+ * 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/vpp-api/java/jvpp/org/openvpp/jvpp/dto/JVppRequest.java b/vpp-api/java/jvpp/org/openvpp/jvpp/dto/JVppRequest.java
index 8cd1534aa13..273e444f601 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/dto/JVppRequest.java
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/dto/JVppRequest.java
@@ -17,6 +17,7 @@
package org.openvpp.jvpp.dto;
import org.openvpp.jvpp.JVpp;
+import org.openvpp.jvpp.VppInvocationException;
/**
* Base interface for all request DTOs
@@ -28,6 +29,6 @@ public interface JVppRequest {
*
* @return context id of this request. Can be used to track incomming response
*/
- int send(JVpp jvpp);
+ int send(JVpp jvpp) throws VppInvocationException;
}
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/future/FutureJVppInvoker.java b/vpp-api/java/jvpp/org/openvpp/jvpp/future/FutureJVppInvoker.java
index 8dab7f5e42d..9219e353cdb 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/future/FutureJVppInvoker.java
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/future/FutureJVppInvoker.java
@@ -17,10 +17,11 @@
package org.openvpp.jvpp.future;
-import java.util.concurrent.CompletionStage;
import org.openvpp.jvpp.dto.JVppReply;
import org.openvpp.jvpp.dto.JVppRequest;
+import java.util.concurrent.CompletionStage;
+
/**
* Future facade on top of JVpp
*/
@@ -30,6 +31,7 @@ public interface FutureJVppInvoker extends AutoCloseable {
* Invoke asynchronous operation on VPP
*
* @return CompletionStage with future result of an async VPP call
+ * @throws org.openvpp.jvpp.VppInvocationException when send request failed with details
*/
<REQ extends JVppRequest, REPLY extends JVppReply<REQ>> CompletionStage<REPLY> send(REQ req);
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/future/FutureJVppInvokerFacade.java b/vpp-api/java/jvpp/org/openvpp/jvpp/future/FutureJVppInvokerFacade.java
index b005b137b1f..69967a1dbc1 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/future/FutureJVppInvokerFacade.java
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/future/FutureJVppInvokerFacade.java
@@ -17,16 +17,14 @@
package org.openvpp.jvpp.future;
+import org.openvpp.jvpp.JVpp;
+import org.openvpp.jvpp.VppInvocationException;
+import org.openvpp.jvpp.dto.*;
+
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
-import org.openvpp.jvpp.JVpp;
-import org.openvpp.jvpp.dto.ControlPing;
-import org.openvpp.jvpp.dto.JVppDump;
-import org.openvpp.jvpp.dto.JVppReply;
-import org.openvpp.jvpp.dto.JVppReplyDump;
-import org.openvpp.jvpp.dto.JVppRequest;
/**
* Future facade on top of JVpp
@@ -59,20 +57,26 @@ public class FutureJVppInvokerFacade implements FutureJVppInvoker {
@SuppressWarnings("unchecked")
public <REQ extends JVppRequest, REPLY extends JVppReply<REQ>> CompletionStage<REPLY> send(REQ req) {
synchronized(requests) {
- final int contextId = jvpp.send(req);
-
- final CompletableFuture<REPLY> replyCompletableFuture;
- if(req instanceof JVppDump) {
- replyCompletableFuture = (CompletableFuture<REPLY>) new CompletableDumpFuture<>(contextId);
- } else {
- replyCompletableFuture = new CompletableFuture<>();
- }
-
- requests.put(contextId, replyCompletableFuture);
- if(req instanceof JVppDump) {
- requests.put(jvpp.send(new ControlPing()), replyCompletableFuture);
+ try {
+ final CompletableFuture<REPLY> replyCompletableFuture;
+ final int contextId = jvpp.send(req);
+
+ if(req instanceof JVppDump) {
+ replyCompletableFuture = (CompletableFuture<REPLY>) new CompletableDumpFuture<>(contextId);
+ } else {
+ replyCompletableFuture = new CompletableFuture<>();
+ }
+
+ requests.put(contextId, replyCompletableFuture);
+ if(req instanceof JVppDump) {
+ requests.put(jvpp.send(new ControlPing()), replyCompletableFuture);
+ }
+ return replyCompletableFuture;
+ } catch (VppInvocationException ex) {
+ final CompletableFuture<REPLY> replyCompletableFuture = new CompletableFuture<>();
+ replyCompletableFuture.completeExceptionally(ex);
+ return replyCompletableFuture;
}
- return replyCompletableFuture;
}
}
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/test/CallbackApiTest.java b/vpp-api/java/jvpp/org/openvpp/jvpp/test/CallbackApiTest.java
index c3bb272368c..8c976db2397 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/test/CallbackApiTest.java
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/test/CallbackApiTest.java
@@ -18,16 +18,12 @@ package org.openvpp.jvpp.test;
import org.openvpp.jvpp.JVpp;
import org.openvpp.jvpp.JVppImpl;
+import org.openvpp.jvpp.VppCallbackException;
import org.openvpp.jvpp.VppJNIConnection;
import org.openvpp.jvpp.callback.GetNodeIndexCallback;
import org.openvpp.jvpp.callback.ShowVersionCallback;
import org.openvpp.jvpp.callback.SwInterfaceCallback;
-import org.openvpp.jvpp.dto.GetNodeIndex;
-import org.openvpp.jvpp.dto.GetNodeIndexReply;
-import org.openvpp.jvpp.dto.ShowVersion;
-import org.openvpp.jvpp.dto.ShowVersionReply;
-import org.openvpp.jvpp.dto.SwInterfaceDetails;
-import org.openvpp.jvpp.dto.SwInterfaceDump;
+import org.openvpp.jvpp.dto.*;
public class CallbackApiTest {
@@ -35,14 +31,14 @@ public class CallbackApiTest {
@Override
public void onGetNodeIndexReply(final GetNodeIndexReply msg) {
- System.out.printf("Received GetNodeIndexReply: context=%d, retval=%d, nodeIndex=%d\n",
- msg.context, msg.retval, msg.nodeIndex);
+ System.out.printf("Received GetNodeIndexReply: context=%d, nodeIndex=%d\n",
+ msg.context, msg.nodeIndex);
}
@Override
- public void onShowVersionReply(final ShowVersionReply msg) {
- System.out.printf("Received ShowVersionReply: context=%d, retval=%d, program=%s, version=%s, " +
+ 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.retval, new String(msg.program), new String(msg.version),
+ msg.context, new String(msg.program), new String(msg.version),
new String(msg.buildDate), new String(msg.buildDirectory));
}
@@ -53,12 +49,17 @@ public class CallbackApiTest {
new String(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());
+ }
}
private static void testCallbackApi() throws Exception {
System.out.println("Testing Java callback API");
- JVpp jvpp = new JVppImpl( new VppJNIConnection("CallbackApiTest"));
- jvpp.connect( new TestCallback());
+ JVpp jvpp = new JVppImpl(new VppJNIConnection("CallbackApiTest"));
+ jvpp.connect(new TestCallback());
System.out.println("Successfully connected to VPP");
System.out.println("Sending ShowVersion request...");
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/test/CallbackJVppFacadeTest.java b/vpp-api/java/jvpp/org/openvpp/jvpp/test/CallbackJVppFacadeTest.java
index b5e505741d5..bb06c761108 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/test/CallbackJVppFacadeTest.java
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/test/CallbackJVppFacadeTest.java
@@ -18,9 +18,14 @@ package org.openvpp.jvpp.test;
import org.openvpp.jvpp.JVpp;
import org.openvpp.jvpp.JVppImpl;
+import org.openvpp.jvpp.VppCallbackException;
import org.openvpp.jvpp.VppJNIConnection;
+import org.openvpp.jvpp.callback.GetNodeIndexCallback;
import org.openvpp.jvpp.callback.ShowVersionCallback;
import org.openvpp.jvpp.callfacade.CallbackJVppFacade;
+import org.openvpp.jvpp.dto.GetNodeIndex;
+import org.openvpp.jvpp.dto.GetNodeIndexReply;
+import org.openvpp.jvpp.dto.ShowVersionReply;
/**
* CallbackJVppFacade together with CallbackJVppFacadeCallback allow for setting different callback for each request.
@@ -28,15 +33,51 @@ import org.openvpp.jvpp.callfacade.CallbackJVppFacade;
*/
public class CallbackJVppFacadeTest {
- private static ShowVersionCallback showVersionCallback1 = msg ->
- System.out.printf("ShowVersionCallback1 received ShowVersionReply: context=%d, retval=%d, program=%s," +
- "version=%s, buildDate=%s, buildDirectory=%s\n", msg.context, msg.retval, new String(msg.program),
- new String(msg.version), new String(msg.buildDate), new String(msg.buildDirectory));
+ private static ShowVersionCallback showVersionCallback1;
+ private static ShowVersionCallback showVersionCallback2;
+ private static GetNodeIndexCallback getNodeIndexCallback;
- private static ShowVersionCallback showVersionCallback2 = msg ->
- System.out.printf("ShowVersionCallback2 received ShowVersionReply: context=%d, retval=%d, program=%s," +
- "version=%s, buildDate=%s, buildDirectory=%s\n", msg.context, msg.retval, new String(msg.program),
- new String(msg.version), new String(msg.buildDate), new String(msg.buildDirectory));
+ static {
+ getNodeIndexCallback = new GetNodeIndexCallback() {
+ @Override
+ public void onGetNodeIndexReply(final GetNodeIndexReply msg) {
+ System.out.printf("Received GetNodeIndexReply: context=%d, nodeIndex=%d\n",
+ msg.context, msg.nodeIndex);
+ }
+
+ @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());
+ }
+ };
+ showVersionCallback2 = new ShowVersionCallback() {
+ @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, new String(msg.program),
+ new String(msg.version), new String(msg.buildDate), new String(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());
+ }
+
+ };
+ showVersionCallback1 = new ShowVersionCallback() {
+ @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, new String(msg.program),
+ new String(msg.version), new String(msg.buildDate), new String(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 void testCallbackFacade() throws Exception {
System.out.println("Testing CallbackJVppFacade");
@@ -49,6 +90,9 @@ public class CallbackJVppFacadeTest {
jvppCallbackFacade.showVersion(showVersionCallback1);
jvppCallbackFacade.showVersion(showVersionCallback2);
+ GetNodeIndex getNodeIndexRequest = new GetNodeIndex();
+ getNodeIndexRequest.nodeName = "dummyNode".getBytes();
+ jvppCallbackFacade.getNodeIndex(getNodeIndexRequest, getNodeIndexCallback);
Thread.sleep(2000);
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/test/ControlPingTest.java b/vpp-api/java/jvpp/org/openvpp/jvpp/test/ControlPingTest.java
index bec302b8089..514bb3ef887 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/test/ControlPingTest.java
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/test/ControlPingTest.java
@@ -18,6 +18,7 @@ package org.openvpp.jvpp.test;
import org.openvpp.jvpp.JVpp;
import org.openvpp.jvpp.JVppImpl;
+import org.openvpp.jvpp.VppCallbackException;
import org.openvpp.jvpp.VppJNIConnection;
import org.openvpp.jvpp.callback.ControlPingCallback;
import org.openvpp.jvpp.dto.ControlPing;
@@ -32,9 +33,15 @@ public class ControlPingTest {
jvpp.connect( new ControlPingCallback() {
@Override
public void onControlPingReply(final ControlPingReply reply) {
- System.out.printf("Received ControlPingReply: context=%d, retval=%d, clientIndex=%d vpePid=%d\n",
- reply.context, reply.retval, reply.clientIndex, reply.vpePid);
+ System.out.printf("Received ControlPingReply: context=%d, clientIndex=%d vpePid=%d\n",
+ reply.context, reply.clientIndex, reply.vpePid);
}
+
+ @Override
+ public void onError(VppCallbackException ex) {
+ System.out.printf("Received onError exception: call=%s, reply=%d, context=%d ", ex.getMethodName(), ex.getErrorCode(), ex.getCtxId());
+ }
+
});
System.out.println("Successfully connected to VPP");
Thread.sleep(1000);
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/test/CreateSubInterfaceTest.java b/vpp-api/java/jvpp/org/openvpp/jvpp/test/CreateSubInterfaceTest.java
index f61867e15f1..b3dc1f49491 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/test/CreateSubInterfaceTest.java
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/test/CreateSubInterfaceTest.java
@@ -16,8 +16,6 @@
package org.openvpp.jvpp.test;
-import static java.util.Objects.requireNonNull;
-
import org.openvpp.jvpp.JVppImpl;
import org.openvpp.jvpp.VppJNIConnection;
import org.openvpp.jvpp.dto.CreateSubif;
@@ -26,6 +24,8 @@ import org.openvpp.jvpp.dto.SwInterfaceDetailsReplyDump;
import org.openvpp.jvpp.dto.SwInterfaceDump;
import org.openvpp.jvpp.future.FutureJVppFacade;
+import static java.util.Objects.requireNonNull;
+
/**
* <p>Tests sub-interface creation.<br> Equivalent to:<br>
*
@@ -76,9 +76,8 @@ public class CreateSubInterfaceTest {
}
private static void print(CreateSubifReply reply) {
- System.out.printf("CreateSubifReply: context=%d, retval=%d, swIfIndex=%d\n",
+ System.out.printf("CreateSubifReply: context=%d, swIfIndex=%d\n",
reply.context,
- reply.retval,
reply.swIfIndex);
}
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/test/FutureApiTest.java b/vpp-api/java/jvpp/org/openvpp/jvpp/test/FutureApiTest.java
index 745482d1667..0000bcd907c 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/test/FutureApiTest.java
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/test/FutureApiTest.java
@@ -16,18 +16,14 @@
package org.openvpp.jvpp.test;
-import java.util.Objects;
-import java.util.concurrent.Future;
import org.openvpp.jvpp.VppJNIConnection;
-import org.openvpp.jvpp.dto.GetNodeIndex;
-import org.openvpp.jvpp.dto.GetNodeIndexReply;
-import org.openvpp.jvpp.dto.ShowVersion;
-import org.openvpp.jvpp.dto.ShowVersionReply;
-import org.openvpp.jvpp.dto.SwInterfaceDetails;
-import org.openvpp.jvpp.dto.SwInterfaceDetailsReplyDump;
-import org.openvpp.jvpp.dto.SwInterfaceDump;
+import org.openvpp.jvpp.dto.*;
import org.openvpp.jvpp.future.FutureJVppFacade;
+import java.util.Objects;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
public class FutureApiTest {
private static void testShowVersion(final FutureJVppFacade jvpp) {
@@ -38,12 +34,12 @@ public class FutureApiTest {
Objects.requireNonNull(replyFuture,"replyFuture is null");
final ShowVersionReply reply = replyFuture.get();
Objects.requireNonNull(reply,"reply is null");
- System.out.printf("Received ShowVersionReply: context=%d, retval=%d, program=%s, " +
+ System.out.printf("Received ShowVersionReply: context=%d, program=%s, " +
"version=%s, buildDate=%s, buildDirectory=%s\n",
- reply.context, reply.retval, new String(reply.program), new String(reply.version),
+ reply.context, new String(reply.program), new String(reply.version),
new String(reply.buildDate), new String(reply.buildDirectory));
} catch (Exception e) {
- System.err.printf("ShowVersion request failed:\n");
+ System.err.printf("ShowVersion request failed:"+e.getCause());
e.printStackTrace();
}
}
@@ -62,10 +58,12 @@ public class FutureApiTest {
Objects.requireNonNull(replyFuture,"replyFuture is null");
final GetNodeIndexReply reply = replyFuture.get();
Objects.requireNonNull(reply,"reply is null");
- System.out.printf("Received GetNodeIndexReply: context=%d, retval=%d, nodeIndex=%d\n",
- reply.context, reply.retval, reply.nodeIndex);
+ System.out.printf("Received GetNodeIndexReply: context=%d, nodeIndex=%d\n",
+ reply.context, reply.nodeIndex);
+ } catch (ExecutionException e) {
+ System.err.printf("GetNodeIndex request failed:"+e.getCause());
} catch (Exception e) {
- System.err.printf("GetNodeIndex request failed:\n");
+ System.err.printf("GetNodeIndex request failed:"+e.getCause());
e.printStackTrace();
}
}
@@ -91,7 +89,7 @@ public class FutureApiTest {
} catch(NullPointerException e) {
throw new IllegalStateException(e.getMessage());
} catch (Exception e) {
- System.err.printf("SwInterfaceDump request failed:\n");
+ System.err.printf("SwInterfaceDump request failed:"+e.getCause());
e.printStackTrace();
}
}
@@ -103,7 +101,6 @@ public class FutureApiTest {
new org.openvpp.jvpp.JVppImpl(new VppJNIConnection("FutureApiTest"));
final FutureJVppFacade jvppFacade = new FutureJVppFacade(impl);
System.out.println("Successfully connected to VPP");
-
testShowVersion(jvppFacade);
testGetNodeIndex(jvppFacade);
testSwInterfaceDump(jvppFacade);
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/test/L2AclTest.java b/vpp-api/java/jvpp/org/openvpp/jvpp/test/L2AclTest.java
index e92b4f5d7b3..d8d04eddfad 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/test/L2AclTest.java
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/test/L2AclTest.java
@@ -83,25 +83,22 @@ public class L2AclTest {
}
private static void print(ClassifyAddDelTableReply reply) {
- System.out.printf("ClassifyAddDelTableReply: context=%d, retval=%d, " +
+ System.out.printf("ClassifyAddDelTableReply: context=%d, " +
"newTableIndex=%d, skipNVectors=%d, matchNVectors=%d\n",
reply.context,
- reply.retval,
reply.newTableIndex,
reply.skipNVectors,
reply.matchNVectors);
}
private static void print(ClassifyAddDelSessionReply reply) {
- System.out.printf("ClassifyAddDelSessionReply: context=%d, retval=%d\n",
- reply.context,
- reply.retval);
+ System.out.printf("ClassifyAddDelSessionReply: context=%d\n",
+ reply.context);
}
private static void print(final InputAclSetInterfaceReply reply) {
- System.out.printf("InputAclSetInterfaceReply: context=%d, retval=%d\n",
- reply.context,
- reply.retval);
+ System.out.printf("InputAclSetInterfaceReply: context=%d\n",
+ reply.context);
}
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/test/OnErrorCallbackTest.java b/vpp-api/java/jvpp/org/openvpp/jvpp/test/OnErrorCallbackTest.java
new file mode 100644
index 00000000000..46d8558338f
--- /dev/null
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/test/OnErrorCallbackTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openvpp.jvpp.test;
+
+import org.openvpp.jvpp.JVpp;
+import org.openvpp.jvpp.JVppImpl;
+import org.openvpp.jvpp.VppCallbackException;
+import org.openvpp.jvpp.VppJNIConnection;
+import org.openvpp.jvpp.callback.GetNodeIndexCallback;
+import org.openvpp.jvpp.callback.ShowVersionCallback;
+import org.openvpp.jvpp.dto.*;
+
+public class OnErrorCallbackTest {
+
+ private static class TestCallback implements GetNodeIndexCallback, ShowVersionCallback{
+
+ @Override
+ public void onGetNodeIndexReply(final GetNodeIndexReply msg) {
+ System.out.printf("Received GetNodeIndexReply: context=%d, nodeIndex=%d\n",
+ msg.context, msg.nodeIndex);
+ }
+ @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, new String(msg.program), new String(msg.version),
+ new String(msg.buildDate), new String(msg.buildDirectory));
+ }
+
+ @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());
+ }
+ }
+
+ private static void testCallbackApi() throws Exception {
+ System.out.println("Testing Java callback API");
+ JVpp jvpp = new JVppImpl(new VppJNIConnection("CallbackApiTest"));
+ jvpp.connect(new TestCallback());
+ System.out.println("Successfully connected to VPP");
+
+ System.out.println("Sending ShowVersion request...");
+ jvpp.send(new ShowVersion());
+
+ System.out.println("Sending GetNodeIndex request...");
+ GetNodeIndex getNodeIndexRequest = new GetNodeIndex();
+ getNodeIndexRequest.nodeName = "dummyNode".getBytes();
+ jvpp.send(getNodeIndexRequest);
+
+ Thread.sleep(5000);
+
+ System.out.println("Disconnecting...");
+ jvpp.close();
+ Thread.sleep(1000);
+ }
+
+ public static void main(String[] args) throws Exception {
+ testCallbackApi();
+ }
+}
diff --git a/vpp-api/java/jvpp/org/openvpp/jvpp/test/Readme.txt b/vpp-api/java/jvpp/org/openvpp/jvpp/test/Readme.txt
index d1ce749f0cc..f9c67ddbcb6 100644
--- a/vpp-api/java/jvpp/org/openvpp/jvpp/test/Readme.txt
+++ b/vpp-api/java/jvpp/org/openvpp/jvpp/test/Readme.txt
@@ -10,4 +10,5 @@ CallbackApiTest - Similar to ControlPingTest, invokes more complex calls (e.g. i
FutureApiTest - Execution of more complex calls using Future based JVpp facade
CallbackJVppFacadeTest - Execution of more complex calls using Callback based JVpp facade
L2AclTest - Tests L2 ACL creation
-CreateSubInterfaceTest - Tests sub-interface creation \ No newline at end of file
+CreateSubInterfaceTest - Tests sub-interface creation
+OnErrorCallbackTest - simple test failing with onError