summaryrefslogtreecommitdiffstats
path: root/vpp-api/java
diff options
context:
space:
mode:
Diffstat (limited to 'vpp-api/java')
-rw-r--r--vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackApiTest.java78
-rw-r--r--vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackJVppFacadeNotificationTest.java36
-rw-r--r--vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackJVppFacadeTest.java40
-rw-r--r--vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackNotificationApiTest.java68
-rw-r--r--vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/ControlPingTest.java47
-rw-r--r--vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CreateSubInterfaceTest.java47
-rw-r--r--vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/FutureApiNotificationTest.java45
-rw-r--r--vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/FutureApiTest.java59
-rw-r--r--vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/L2AclTest.java61
-rw-r--r--vpp-api/java/jvpp-registry/io/fd/vpp/jvpp/future/AbstractFutureJVppInvoker.java2
-rw-r--r--vpp-api/java/jvpp-registry/io/fd/vpp/jvpp/test/ConnectionTest.java17
11 files changed, 237 insertions, 263 deletions
diff --git a/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackApiTest.java b/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackApiTest.java
index 3e1eb0a6124..986993b854f 100644
--- a/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackApiTest.java
+++ b/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackApiTest.java
@@ -33,6 +33,37 @@ import io.fd.vpp.jvpp.core.dto.SwInterfaceDump;
public class CallbackApiTest {
+ 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("CallbackApiTest");
+ 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();
+ jvpp.send(getNodeIndexRequest);
+
+ System.out.println("Sending SwInterfaceDump request...");
+ SwInterfaceDump swInterfaceDumpRequest = new SwInterfaceDump();
+ swInterfaceDumpRequest.nameFilterValid = 0;
+ swInterfaceDumpRequest.nameFilter = "".getBytes();
+ jvpp.send(swInterfaceDumpRequest);
+
+ Thread.sleep(1000);
+ System.out.println("Disconnecting...");
+ }
+ Thread.sleep(1000);
+ }
+
static class TestCallback implements GetNodeIndexCallback, ShowVersionCallback, SwInterfaceCallback {
@Override
@@ -43,56 +74,23 @@ public class CallbackApiTest {
@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));
+ + "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 onSwInterfaceDetails(final SwInterfaceDetails msg) {
System.out.printf("Received SwInterfaceDetails: interfaceName=%s, l2AddressLength=%d, adminUpDown=%d, "
- + "linkUpDown=%d, linkSpeed=%d, linkMtu=%d%n",
- new String(msg.interfaceName), msg.l2AddressLength, msg.adminUpDown,
- msg.linkUpDown, msg.linkSpeed, (int) msg.linkMtu);
+ + "linkUpDown=%d, linkSpeed=%d, linkMtu=%d%n",
+ 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());
+ 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 with JVppRegistry");
- JVppRegistry registry = new JVppRegistryImpl("CallbackApiTest");
- 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();
- jvpp.send(getNodeIndexRequest);
-
- System.out.println("Sending SwInterfaceDump request...");
- SwInterfaceDump swInterfaceDumpRequest = new SwInterfaceDump();
- swInterfaceDumpRequest.nameFilterValid = 0;
- swInterfaceDumpRequest.nameFilter = "".getBytes();
- jvpp.send(swInterfaceDumpRequest);
-
- Thread.sleep(1000);
-
- System.out.println("Disconnecting...");
- registry.close();
- Thread.sleep(1000);
- }
}
diff --git a/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackJVppFacadeNotificationTest.java b/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackJVppFacadeNotificationTest.java
index f8845d622d6..d84cb034ef1 100644
--- a/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackJVppFacadeNotificationTest.java
+++ b/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackJVppFacadeNotificationTest.java
@@ -30,18 +30,17 @@ public class CallbackJVppFacadeNotificationTest {
private static void testCallbackFacade() throws Exception {
System.out.println("Testing CallbackJVppFacade for notifications");
- final JVppRegistry registry = new JVppRegistryImpl("CallbackFacadeTest");
- final JVppCore jvpp = new JVppCoreImpl();
+ try (final JVppRegistry registry = new JVppRegistryImpl("CallbackFacadeTest");
+ final JVppCore jvpp = new JVppCoreImpl()) {
+ final CallbackJVppCoreFacade jvppCallbackFacade = new CallbackJVppCoreFacade(registry, jvpp);
+ System.out.println("Successfully connected to VPP");
- CallbackJVppCoreFacade jvppCallbackFacade = new CallbackJVppCoreFacade(registry, jvpp);
- System.out.println("Successfully connected to VPP");
-
- final AutoCloseable notificationListenerReg =
+ final AutoCloseable notificationListenerReg =
jvppCallbackFacade.getNotificationRegistry().registerSwInterfaceSetFlagsNotificationCallback(
- NotificationUtils::printNotification
+ NotificationUtils::printNotification
);
- jvppCallbackFacade.wantInterfaceEvents(NotificationUtils.getEnableInterfaceNotificationsReq(),
+ jvppCallbackFacade.wantInterfaceEvents(NotificationUtils.getEnableInterfaceNotificationsReq(),
new WantInterfaceEventsCallback() {
@Override
public void onWantInterfaceEventsReply(final WantInterfaceEventsReply reply) {
@@ -51,16 +50,16 @@ public class CallbackJVppFacadeNotificationTest {
@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());
+ ex.getMethodName(), ex.getCtxId(), ex.getErrorCode());
}
});
- System.out.println("Changing interface configuration");
- NotificationUtils.getChangeInterfaceState().send(jvpp);
+ System.out.println("Changing interface configuration");
+ NotificationUtils.getChangeInterfaceState().send(jvpp);
- Thread.sleep(1000);
+ Thread.sleep(1000);
- jvppCallbackFacade.wantInterfaceEvents(NotificationUtils.getDisableInterfaceNotificationsReq(),
+ jvppCallbackFacade.wantInterfaceEvents(NotificationUtils.getDisableInterfaceNotificationsReq(),
new WantInterfaceEventsCallback() {
@Override
public void onWantInterfaceEventsReply(final WantInterfaceEventsReply reply) {
@@ -70,16 +69,15 @@ public class CallbackJVppFacadeNotificationTest {
@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());
+ ex.getMethodName(), ex.getCtxId(), ex.getErrorCode());
}
});
- notificationListenerReg.close();
-
- Thread.sleep(2000);
+ notificationListenerReg.close();
- System.out.println("Disconnecting...");
- registry.close();
+ Thread.sleep(2000);
+ System.out.println("Disconnecting...");
+ }
Thread.sleep(1000);
}
diff --git a/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackJVppFacadeTest.java b/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackJVppFacadeTest.java
index ac79b097048..9f7cb8deadc 100644
--- a/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackJVppFacadeTest.java
+++ b/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackJVppFacadeTest.java
@@ -19,7 +19,6 @@ package io.fd.vpp.jvpp.core.test;
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.GetNodeIndexCallback;
import io.fd.vpp.jvpp.core.callback.ShowVersionCallback;
@@ -38,14 +37,14 @@ public class CallbackJVppFacadeTest {
@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));
+ + "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());
+ ex.getMethodName(), ex.getErrorCode(), ex.getCtxId());
}
};
@@ -53,14 +52,14 @@ public class CallbackJVppFacadeTest {
@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, new String(msg.program),
- new String(msg.version), new String(msg.buildDate), new String(msg.buildDirectory));
+ + "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());
+ ex.getMethodName(), ex.getErrorCode(), ex.getCtxId());
}
};
@@ -74,30 +73,27 @@ public class CallbackJVppFacadeTest {
@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());
+ ex.getMethodName(), ex.getErrorCode(), ex.getCtxId());
}
};
private static void testCallbackFacade() throws Exception {
System.out.println("Testing CallbackJVppFacade");
- final JVppRegistry registry = new JVppRegistryImpl("CallbackFacadeTest");
- final JVppCore jvpp = new JVppCoreImpl();
+ try (final JVppRegistry registry = new JVppRegistryImpl("CallbackFacadeTest");
+ final CallbackJVppCoreFacade callbackFacade = new CallbackJVppCoreFacade(registry, new JVppCoreImpl())) {
+ System.out.println("Successfully connected to VPP");
- CallbackJVppCoreFacade jvppCallbackFacade = new CallbackJVppCoreFacade(registry, jvpp);
- System.out.println("Successfully connected to VPP");
+ callbackFacade.showVersion(showVersionCallback1);
+ callbackFacade.showVersion(showVersionCallback2);
- jvppCallbackFacade.showVersion(showVersionCallback1);
- jvppCallbackFacade.showVersion(showVersionCallback2);
+ GetNodeIndex getNodeIndexRequest = new GetNodeIndex();
+ getNodeIndexRequest.nodeName = "dummyNode".getBytes();
+ callbackFacade.getNodeIndex(getNodeIndexRequest, getNodeIndexCallback);
- GetNodeIndex getNodeIndexRequest = new GetNodeIndex();
- getNodeIndexRequest.nodeName = "dummyNode".getBytes();
- jvppCallbackFacade.getNodeIndex(getNodeIndexRequest, getNodeIndexCallback);
-
- Thread.sleep(2000);
-
- System.out.println("Disconnecting...");
- registry.close();
+ Thread.sleep(2000);
+ System.out.println("Disconnecting...");
+ }
Thread.sleep(1000);
}
diff --git a/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackNotificationApiTest.java b/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackNotificationApiTest.java
index a4b8702c0a4..a9f71f11b00 100644
--- a/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackNotificationApiTest.java
+++ b/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CallbackNotificationApiTest.java
@@ -35,12 +35,42 @@ import io.fd.vpp.jvpp.core.dto.WantInterfaceEventsReply;
public class CallbackNotificationApiTest {
+ private static void testCallbackApi() throws Exception {
+ System.out.println("Testing Java callback API for notifications");
+ try (final JVppRegistry registry = new JVppRegistryImpl("CallbackNotificationTest");
+ 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 SwInterfaceSetFlagsNotificationCallback,
- WantInterfaceEventsCallback, SwInterfaceSetFlagsCallback {
+ WantInterfaceEventsCallback, SwInterfaceSetFlagsCallback {
@Override
public void onSwInterfaceSetFlagsNotification(
- final SwInterfaceSetFlagsNotification msg) {
+ final SwInterfaceSetFlagsNotification msg) {
printNotification(msg);
}
@@ -57,40 +87,8 @@ public class CallbackNotificationApiTest {
@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());
+ ex.getMethodName(), ex.getErrorCode(), ex.getCtxId());
}
}
-
- private static void testCallbackApi() throws Exception {
- System.out.println("Testing Java callback API for notifications");
- JVppRegistry registry = new JVppRegistryImpl("CallbackNotificationTest");
- 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...");
- registry.close();
- Thread.sleep(1000);
- }
-
- public static void main(String[] args) throws Exception {
- testCallbackApi();
- }
}
diff --git a/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/ControlPingTest.java b/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/ControlPingTest.java
index ecf61a535c8..e97f4e3ac9a 100644
--- a/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/ControlPingTest.java
+++ b/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/ControlPingTest.java
@@ -20,8 +20,8 @@ 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.callback.ControlPingCallback;
+import io.fd.vpp.jvpp.core.JVppCoreImpl;
import io.fd.vpp.jvpp.dto.ControlPing;
import io.fd.vpp.jvpp.dto.ControlPingReply;
@@ -29,37 +29,36 @@ public class ControlPingTest {
private static void testControlPing() throws Exception {
System.out.println("Testing ControlPing using Java callback API");
- JVppRegistry registry = new JVppRegistryImpl("ControlPingTest");
- JVpp jvpp = new JVppCoreImpl();
+ try (JVppRegistry registry = new JVppRegistryImpl("ControlPingTest");
+ JVpp jvpp = new JVppCoreImpl()) {
- registry.register(jvpp, new ControlPingCallback() {
- @Override
- public void onControlPingReply(final ControlPingReply reply) {
- System.out.printf("Received ControlPingReply: %s%n", reply);
- }
+ registry.register(jvpp, new ControlPingCallback() {
+ @Override
+ public void onControlPingReply(final ControlPingReply reply) {
+ System.out.printf("Received ControlPingReply: %s%n", reply);
+ }
- @Override
- public void onError(VppCallbackException ex) {
- System.out.printf("Received onError exception: call=%s, reply=%d, context=%d ", ex.getMethodName(),
+ @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);
+ }
- System.out.println("Sending control ping using JVppRegistry");
- registry.controlPing(jvpp.getClass());
+ });
+ System.out.println("Successfully connected to VPP");
+ Thread.sleep(1000);
- Thread.sleep(2000);
+ System.out.println("Sending control ping using JVppRegistry");
+ registry.controlPing(jvpp.getClass());
- System.out.println("Sending control ping using JVpp plugin");
- jvpp.send(new ControlPing());
+ Thread.sleep(2000);
- Thread.sleep(2000);
+ System.out.println("Sending control ping using JVpp plugin");
+ jvpp.send(new ControlPing());
- System.out.println("Disconnecting...");
- registry.close();
+ Thread.sleep(2000);
+ System.out.println("Disconnecting...");
+ }
Thread.sleep(1000);
}
diff --git a/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CreateSubInterfaceTest.java b/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CreateSubInterfaceTest.java
index 43605849821..a96258f4302 100644
--- a/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CreateSubInterfaceTest.java
+++ b/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/CreateSubInterfaceTest.java
@@ -18,7 +18,6 @@ package io.fd.vpp.jvpp.core.test;
import static java.util.Objects.requireNonNull;
-import io.fd.vpp.jvpp.JVpp;
import io.fd.vpp.jvpp.JVppRegistry;
import io.fd.vpp.jvpp.JVppRegistryImpl;
import io.fd.vpp.jvpp.core.JVppCoreImpl;
@@ -54,8 +53,8 @@ public class CreateSubInterfaceTest {
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()));
+ String.format("Expected one interface matching filter %s but was %d", ifaceName,
+ response.swInterfaceDetails.size()));
}
}
@@ -82,38 +81,36 @@ public class CreateSubInterfaceTest {
private static void testCreateSubInterface() throws Exception {
System.out.println("Testing sub-interface creation using Java callback API");
- final JVppRegistry registry = new JVppRegistryImpl("CreateSubInterface");
- final JVpp jvpp = new JVppCoreImpl();
- final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, jvpp);
+ try (final JVppRegistry registry = new JVppRegistryImpl("CreateSubInterface");
+ final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, new JVppCoreImpl())) {
+ System.out.println("Successfully connected to VPP");
+ Thread.sleep(1000);
- System.out.println("Successfully connected to VPP");
- Thread.sleep(1000);
-
- final String ifaceName = "GigabitEthernet0/8/0";
+ final String ifaceName = "GigabitEthernet0/8/0";
- final SwInterfaceDetailsReplyDump swInterfaceDetails =
+ final SwInterfaceDetailsReplyDump swInterfaceDetails =
jvppFacade.swInterfaceDump(createSwInterfaceDumpRequest(ifaceName)).toCompletableFuture().get();
- requireNonNull(swInterfaceDetails, "swInterfaceDump returned null");
- requireNonNull(swInterfaceDetails.swInterfaceDetails, "swInterfaceDetails is null");
- requireSingleIface(swInterfaceDetails, ifaceName);
+ 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 int swIfIndex = swInterfaceDetails.swInterfaceDetails.get(0).swIfIndex;
+ final int subId = 1;
- final CreateSubifReply createSubifReply =
+ final CreateSubifReply createSubifReply =
jvppFacade.createSubif(createSubifRequest(swIfIndex, subId)).toCompletableFuture().get();
- print(createSubifReply);
+ print(createSubifReply);
- final String subIfaceName = "GigabitEthernet0/8/0." + subId;
- final SwInterfaceDetailsReplyDump subIface =
+ 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);
+ requireNonNull(swInterfaceDetails, "swInterfaceDump returned null");
+ requireNonNull(subIface.swInterfaceDetails, "swInterfaceDump returned null");
+ requireSingleIface(swInterfaceDetails, ifaceName);
- System.out.println("Disconnecting...");
- registry.close();
+ System.out.println("Disconnecting...");
+ }
Thread.sleep(1000);
}
diff --git a/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/FutureApiNotificationTest.java b/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/FutureApiNotificationTest.java
index 2ba1b09bfed..9efeae19f8b 100644
--- a/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/FutureApiNotificationTest.java
+++ b/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/FutureApiNotificationTest.java
@@ -20,7 +20,6 @@ import static io.fd.vpp.jvpp.core.test.NotificationUtils.getChangeInterfaceState
import static io.fd.vpp.jvpp.core.test.NotificationUtils.getDisableInterfaceNotificationsReq;
import static io.fd.vpp.jvpp.core.test.NotificationUtils.getEnableInterfaceNotificationsReq;
-import io.fd.vpp.jvpp.JVpp;
import io.fd.vpp.jvpp.JVppRegistry;
import io.fd.vpp.jvpp.JVppRegistryImpl;
import io.fd.vpp.jvpp.core.JVppCoreImpl;
@@ -30,32 +29,24 @@ public class FutureApiNotificationTest {
private static void testFutureApi() throws Exception {
System.out.println("Testing Java future API for notifications");
-
- final JVppRegistry registry = new JVppRegistryImpl("FutureApiNotificationTest");
- final JVpp jvpp = new JVppCoreImpl();
- final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, jvpp);
-
- System.out.println("Successfully connected to VPP");
-
- final AutoCloseable notificationListenerReg =
- jvppFacade.getNotificationRegistry()
- .registerSwInterfaceSetFlagsNotificationCallback(NotificationUtils::printNotification);
-
- 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");
-
- notificationListenerReg.close();
-
- System.out.println("Disconnecting...");
- registry.close();
+ try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiNotificationTest");
+ final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, new JVppCoreImpl());
+ final AutoCloseable notificationListenerReg =
+ jvppFacade.getNotificationRegistry()
+ .registerSwInterfaceSetFlagsNotificationCallback(NotificationUtils::printNotification)) {
+ 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 {
diff --git a/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/FutureApiTest.java b/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/FutureApiTest.java
index 80c1108d279..f478bab442f 100644
--- a/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/FutureApiTest.java
+++ b/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/FutureApiTest.java
@@ -16,12 +16,6 @@
package io.fd.vpp.jvpp.core.test;
-import java.util.Objects;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.Future;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import io.fd.vpp.jvpp.JVpp;
import io.fd.vpp.jvpp.JVppRegistry;
import io.fd.vpp.jvpp.JVppRegistryImpl;
import io.fd.vpp.jvpp.core.JVppCoreImpl;
@@ -35,6 +29,11 @@ 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.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 {
@@ -45,10 +44,10 @@ public class FutureApiTest {
final Future<ShowVersionReply> 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, new String(reply.program), new String(reply.version), new String(reply.buildDate),
- new String(reply.buildDirectory)));
+ String.format(
+ "Received ShowVersionReply: context=%d, program=%s, version=%s, buildDate=%s, buildDirectory=%s%n",
+ reply.context, new String(reply.program), new String(reply.version), new String(reply.buildDate),
+ new String(reply.buildDirectory)));
}
private static void testEmptyBridgeDomainDump(final FutureJVppCoreFacade jvpp) throws Exception {
@@ -57,16 +56,16 @@ public class FutureApiTest {
request.bdId = -1; // dump call
final CompletableFuture<BridgeDomainDetailsReplyDump>
- replyFuture = jvpp.bridgeDomainDump(request).toCompletableFuture();
+ 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 empty bridge-domain dump reply with list of bridge-domains: %s, %s",
- reply.bridgeDomainDetails, reply.bridgeDomainSwIfDetails));
+ String.format(
+ "Received empty bridge-domain dump reply with list of bridge-domains: %s, %s",
+ reply.bridgeDomainDetails, reply.bridgeDomainSwIfDetails));
}
}
@@ -78,8 +77,8 @@ public class FutureApiTest {
try {
final GetNodeIndexReply reply = replyFuture.get();
LOG.info(
- String.format(
- "Received GetNodeIndexReply: context=%d, nodeIndex=%d%n", reply.context, reply.nodeIndex));
+ String.format(
+ "Received GetNodeIndexReply: context=%d, nodeIndex=%d%n", reply.context, reply.nodeIndex));
} catch (Exception e) {
LOG.log(Level.SEVERE, "GetNodeIndex request failed", e);
}
@@ -96,28 +95,26 @@ public class FutureApiTest {
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",
- new String(details.interfaceName), details.l2AddressLength, details.adminUpDown,
- details.linkUpDown, details.linkSpeed, (int) details.linkMtu));
+ String.format("Received SwInterfaceDetails: interfaceName=%s, l2AddressLength=%d, adminUpDown=%d, "
+ + "linkUpDown=%d, linkSpeed=%d, linkMtu=%d%n",
+ new String(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("FutureApiTest");
+ final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, new JVppCoreImpl())) {
+ LOG.info("Successfully connected to VPP");
- final JVppRegistry registry = new JVppRegistryImpl("FutureApiTest");
- final JVpp jvpp = new JVppCoreImpl();
- final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, jvpp);
- LOG.info("Successfully connected to VPP");
-
- testEmptyBridgeDomainDump(jvppFacade);
- testShowVersion(jvppFacade);
- testGetNodeIndex(jvppFacade);
- testSwInterfaceDump(jvppFacade);
+ testEmptyBridgeDomainDump(jvppFacade);
+ testShowVersion(jvppFacade);
+ testGetNodeIndex(jvppFacade);
+ testSwInterfaceDump(jvppFacade);
- LOG.info("Disconnecting...");
- registry.close();
+ LOG.info("Disconnecting...");
+ }
}
public static void main(String[] args) throws Exception {
diff --git a/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/L2AclTest.java b/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/L2AclTest.java
index d7da5ecbaf3..6b3fa993f4d 100644
--- a/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/L2AclTest.java
+++ b/vpp-api/java/jvpp-core/io/fd/vpp/jvpp/core/test/L2AclTest.java
@@ -16,8 +16,6 @@
package io.fd.vpp.jvpp.core.test;
-import javax.xml.bind.DatatypeConverter;
-import io.fd.vpp.jvpp.JVpp;
import io.fd.vpp.jvpp.JVppRegistry;
import io.fd.vpp.jvpp.JVppRegistryImpl;
import io.fd.vpp.jvpp.core.JVppCoreImpl;
@@ -36,6 +34,7 @@ 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;
+import javax.xml.bind.DatatypeConverter;
/**
* <p>Tests L2 ACL creation and read.<br> Equivalent to the following vppctl commands:<br>
@@ -63,8 +62,8 @@ public class L2AclTest {
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};
+ 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;
}
@@ -83,8 +82,8 @@ public class L2AclTest {
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};
+ 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;
}
@@ -147,46 +146,46 @@ public class L2AclTest {
private static void testL2Acl() throws Exception {
System.out.println("Testing L2 ACLs using Java callback API");
- final JVppRegistry registry = new JVppRegistryImpl("L2AclTest");
- final JVpp jvpp = new JVppCoreImpl();
- final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, jvpp);
+ try (final JVppRegistry registry = new JVppRegistryImpl("L2AclTest");
+ final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, new JVppCoreImpl())) {
- System.out.println("Successfully connected to VPP");
- Thread.sleep(1000);
+ System.out.println("Successfully connected to VPP");
+ Thread.sleep(1000);
- final ClassifyAddDelTableReply classifyAddDelTableReply =
+ final ClassifyAddDelTableReply classifyAddDelTableReply =
jvppFacade.classifyAddDelTable(createClassifyTable()).toCompletableFuture().get();
- print(classifyAddDelTableReply);
+ print(classifyAddDelTableReply);
- final ClassifyTableIdsReply classifyTableIdsReply =
+ final ClassifyTableIdsReply classifyTableIdsReply =
jvppFacade.classifyTableIds(new ClassifyTableIds()).toCompletableFuture().get();
- print(classifyTableIdsReply);
+ print(classifyTableIdsReply);
- final ClassifyTableInfoReply classifyTableInfoReply =
+ final ClassifyTableInfoReply classifyTableInfoReply =
jvppFacade.classifyTableInfo(createClassifyTableInfoRequest(classifyAddDelTableReply.newTableIndex))
- .toCompletableFuture().get();
- print(classifyTableInfoReply);
+ .toCompletableFuture().get();
+ print(classifyTableInfoReply);
- final ClassifyAddDelSessionReply classifyAddDelSessionReply =
+ final ClassifyAddDelSessionReply classifyAddDelSessionReply =
jvppFacade.classifyAddDelSession(createClassifySession(classifyAddDelTableReply.newTableIndex))
- .toCompletableFuture().get();
- print(classifyAddDelSessionReply);
+ .toCompletableFuture().get();
+ print(classifyAddDelSessionReply);
- final ClassifySessionDetailsReplyDump classifySessionDetailsReplyDump =
+ final ClassifySessionDetailsReplyDump classifySessionDetailsReplyDump =
jvppFacade.classifySessionDump(createClassifySessionDumpRequest(classifyAddDelTableReply.newTableIndex))
- .toCompletableFuture().get();
- print(classifySessionDetailsReplyDump);
+ .toCompletableFuture().get();
+ print(classifySessionDetailsReplyDump);
- final InputAclSetInterfaceReply inputAclSetInterfaceReply =
+ final InputAclSetInterfaceReply inputAclSetInterfaceReply =
jvppFacade.inputAclSetInterface(aclSetInterface()).toCompletableFuture().get();
- print(inputAclSetInterfaceReply);
+ print(inputAclSetInterfaceReply);
- final ClassifyTableByInterfaceReply classifyTableByInterfaceReply =
- jvppFacade.classifyTableByInterface(createClassifyTableByInterfaceRequest()).toCompletableFuture().get();
- print(classifyTableByInterfaceReply);
+ final ClassifyTableByInterfaceReply classifyTableByInterfaceReply =
+ jvppFacade.classifyTableByInterface(createClassifyTableByInterfaceRequest()).toCompletableFuture()
+ .get();
+ print(classifyTableByInterfaceReply);
- System.out.println("Disconnecting...");
- registry.close();
+ System.out.println("Disconnecting...");
+ }
Thread.sleep(1000);
}
diff --git a/vpp-api/java/jvpp-registry/io/fd/vpp/jvpp/future/AbstractFutureJVppInvoker.java b/vpp-api/java/jvpp-registry/io/fd/vpp/jvpp/future/AbstractFutureJVppInvoker.java
index ed8b8db804d..98e140e9df6 100644
--- a/vpp-api/java/jvpp-registry/io/fd/vpp/jvpp/future/AbstractFutureJVppInvoker.java
+++ b/vpp-api/java/jvpp-registry/io/fd/vpp/jvpp/future/AbstractFutureJVppInvoker.java
@@ -51,7 +51,7 @@ public abstract class AbstractFutureJVppInvoker implements FutureJVppInvoker {
this.requests = Objects.requireNonNull(requestMap, "Null requestMap");
}
- protected final Map<Integer, CompletableFuture<? extends JVppReply<?>>> getRequests() {
+ protected synchronized final Map<Integer, CompletableFuture<? extends JVppReply<?>>> getRequests() {
return this.requests;
}
diff --git a/vpp-api/java/jvpp-registry/io/fd/vpp/jvpp/test/ConnectionTest.java b/vpp-api/java/jvpp-registry/io/fd/vpp/jvpp/test/ConnectionTest.java
index ea1d8647e56..27b4d29f866 100644
--- a/vpp-api/java/jvpp-registry/io/fd/vpp/jvpp/test/ConnectionTest.java
+++ b/vpp-api/java/jvpp-registry/io/fd/vpp/jvpp/test/ConnectionTest.java
@@ -27,14 +27,15 @@ public class ConnectionTest {
private static void testConnect() throws Exception {
System.out.println("Testing JNI connection with JVppRegistry");
- JVppRegistry registry = new JVppRegistryImpl("ConnectionTest");
- System.out.println("Successfully connected to vpp");
-
- Thread.sleep(5000);
-
- System.out.println("Disconnecting...");
- registry.close();
- Thread.sleep(1000);
+ 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 {