summaryrefslogtreecommitdiffstats
path: root/vpp-japi
diff options
context:
space:
mode:
Diffstat (limited to 'vpp-japi')
-rw-r--r--vpp-japi/japi/org/openvpp/vppjapi/vppApiCallbacks.java5
-rw-r--r--vpp-japi/japi/org/openvpp/vppjapi/vppBridgeDomainDetails.java2
-rw-r--r--vpp-japi/japi/org/openvpp/vppjapi/vppBridgeDomainInterfaceDetails.java2
-rw-r--r--vpp-japi/japi/org/openvpp/vppjapi/vppConn.java184
-rw-r--r--vpp-japi/japi/org/openvpp/vppjapi/vppIPv6Address.java6
-rw-r--r--vpp-japi/japi/org/openvpp/vppjapi/vppInterfaceCounters.java2
-rw-r--r--vpp-japi/japi/test/demo.java17
-rw-r--r--vpp-japi/japi/test/vppApi.java4
8 files changed, 180 insertions, 42 deletions
diff --git a/vpp-japi/japi/org/openvpp/vppjapi/vppApiCallbacks.java b/vpp-japi/japi/org/openvpp/vppjapi/vppApiCallbacks.java
index 5c35897c6a7..df5b953300e 100644
--- a/vpp-japi/japi/org/openvpp/vppjapi/vppApiCallbacks.java
+++ b/vpp-japi/japi/org/openvpp/vppjapi/vppApiCallbacks.java
@@ -14,9 +14,14 @@
*/
package org.openvpp.vppjapi;
+
+import java.io.IOException;
import org.openvpp.vppjapi.vppApi;
public abstract class vppApiCallbacks extends vppApi {
+ public vppApiCallbacks(String clientName) throws IOException {
+ super(clientName);
+ }
/* Disabled!
*
* public abstract void interfaceDetails(
diff --git a/vpp-japi/japi/org/openvpp/vppjapi/vppBridgeDomainDetails.java b/vpp-japi/japi/org/openvpp/vppjapi/vppBridgeDomainDetails.java
index 01fe11d61a2..db859a07204 100644
--- a/vpp-japi/japi/org/openvpp/vppjapi/vppBridgeDomainDetails.java
+++ b/vpp-japi/japi/org/openvpp/vppjapi/vppBridgeDomainDetails.java
@@ -17,7 +17,7 @@ package org.openvpp.vppjapi;
import org.openvpp.vppjapi.vppBridgeDomainInterfaceDetails;
-public class vppBridgeDomainDetails {
+public final class vppBridgeDomainDetails {
public String name;
public int bdId;
public boolean flood;
diff --git a/vpp-japi/japi/org/openvpp/vppjapi/vppBridgeDomainInterfaceDetails.java b/vpp-japi/japi/org/openvpp/vppjapi/vppBridgeDomainInterfaceDetails.java
index f17c0620106..ab99ee45347 100644
--- a/vpp-japi/japi/org/openvpp/vppjapi/vppBridgeDomainInterfaceDetails.java
+++ b/vpp-japi/japi/org/openvpp/vppjapi/vppBridgeDomainInterfaceDetails.java
@@ -15,7 +15,7 @@
package org.openvpp.vppjapi;
-public class vppBridgeDomainInterfaceDetails {
+public final class vppBridgeDomainInterfaceDetails {
public String interfaceName;
public byte splitHorizonGroup;
}
diff --git a/vpp-japi/japi/org/openvpp/vppjapi/vppConn.java b/vpp-japi/japi/org/openvpp/vppjapi/vppConn.java
index cd957808683..8de806dc12a 100644
--- a/vpp-japi/japi/org/openvpp/vppjapi/vppConn.java
+++ b/vpp-japi/japi/org/openvpp/vppjapi/vppConn.java
@@ -23,6 +23,7 @@ import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
import org.openvpp.vppjapi.vppVersion;
import org.openvpp.vppjapi.vppInterfaceDetails;
@@ -32,7 +33,7 @@ import org.openvpp.vppjapi.vppIPv4Address;
import org.openvpp.vppjapi.vppIPv6Address;
import org.openvpp.vppjapi.vppVxlanTunnelDetails;
-public class vppConn {
+public class vppConn implements AutoCloseable {
private static final String LIBNAME = "libvppjni.so.0.0.0";
static {
@@ -40,6 +41,7 @@ public class vppConn {
loadLibrary();
} catch (IOException | RuntimeException e) {
System.out.printf ("Can't find vpp jni library: %s\n", LIBNAME);
+ throw new ExceptionInInitializerError(e);
}
}
@@ -72,25 +74,163 @@ public class vppConn {
}
}
- public native int clientConnect(String clientName);
- public native void clientDisconnect();
- public native int getRetval(int context, int release);
- public native String getInterfaceList (String nameFilter);
- public native int swIfIndexFromName (String interfaceName);
- public native String interfaceNameFromSwIfIndex (int swIfIndex);
- public native void clearInterfaceTable ();
- public native vppInterfaceDetails[] swInterfaceDump (byte nameFilterValid, byte [] nameFilter);
- public native int bridgeDomainIdFromName(String bridgeDomain);
- public native int findOrAddBridgeDomainId(String bridgeDomain);
- public native vppVersion getVppVersion();
- public native vppInterfaceCounters getInterfaceCounters(int swIfIndex);
- public native int[] bridgeDomainDump(int bdId);
- public native vppBridgeDomainDetails getBridgeDomainDetails(int bdId);
- public native vppL2Fib[] l2FibTableDump(int bdId);
- public native int bridgeDomainIdFromInterfaceName(String interfaceName);
- public native vppIPv4Address[] ipv4AddressDump(String interfaceName);
- public native vppIPv6Address[] ipv6AddressDump(String interfaceName);
- public native vppVxlanTunnelDetails[] vxlanTunnelDump(int swIfIndex);
- public native int setInterfaceDescription (String ifName, String ifDesc);
- public native String getInterfaceDescription (String ifName);
+ private static vppConn currentConnection = null;
+ private final AtomicBoolean disconnected = new AtomicBoolean(false);
+ private final String clientName;
+
+ // Hidden on purpose to prevent external instantiation
+ vppConn(final String clientName) throws IOException {
+ this.clientName = clientName;
+
+ synchronized (vppConn.class) {
+ if (currentConnection != null) {
+ throw new IOException("Already connected as " + currentConnection.clientName);
+ }
+
+ final int ret = clientConnect(clientName);
+ if (ret != 0) {
+ throw new IOException("Connection returned error " + ret);
+ }
+
+ currentConnection = this;
+ }
+ }
+
+ @Override
+ public final void close() {
+ if (disconnected.compareAndSet(false, true)) {
+ synchronized (vppConn.class) {
+ clientDisconnect();
+ currentConnection = null;
+ }
+ }
+ }
+
+ /**
+ * Check if this instance is connected.
+ *
+ * @throws IllegalStateException if this instance was disconnected.
+ */
+ protected final void checkConnected() {
+ if (disconnected.get()) {
+ throw new IllegalStateException("Disconnected client " + clientName);
+ }
+ }
+
+ public final int getRetval(int context, int release) {
+ checkConnected();
+ return getRetval0(context, release);
+ }
+
+ public final String getInterfaceList (String nameFilter) {
+ checkConnected();
+ return getInterfaceList0(nameFilter);
+ }
+
+ public final int swIfIndexFromName (String interfaceName) {
+ checkConnected();
+ return swIfIndexFromName0(interfaceName);
+ }
+
+ public final String interfaceNameFromSwIfIndex (int swIfIndex) {
+ checkConnected();
+ return interfaceNameFromSwIfIndex0(swIfIndex);
+ }
+
+ public final void clearInterfaceTable () {
+ checkConnected();
+ clearInterfaceTable0();
+ }
+
+ public final vppInterfaceDetails[] swInterfaceDump (byte nameFilterValid, byte [] nameFilter) {
+ checkConnected();
+ return swInterfaceDump0(nameFilterValid, nameFilter);
+ }
+
+ public final int bridgeDomainIdFromName(String bridgeDomain) {
+ checkConnected();
+ return bridgeDomainIdFromName0(bridgeDomain);
+ }
+
+ public final int findOrAddBridgeDomainId(String bridgeDomain) {
+ checkConnected();
+ return findOrAddBridgeDomainId0(bridgeDomain);
+ }
+
+ public final vppVersion getVppVersion() {
+ checkConnected();
+ return getVppVersion0();
+ }
+
+ public final vppInterfaceCounters getInterfaceCounters(int swIfIndex) {
+ checkConnected();
+ return getInterfaceCounters0(swIfIndex);
+ }
+
+ public final int[] bridgeDomainDump(int bdId) {
+ checkConnected();
+ return bridgeDomainDump0(bdId);
+ }
+
+ public final vppBridgeDomainDetails getBridgeDomainDetails(int bdId) {
+ checkConnected();
+ return getBridgeDomainDetails0(bdId);
+ }
+
+ public final vppL2Fib[] l2FibTableDump(int bdId) {
+ checkConnected();
+ return l2FibTableDump0(bdId);
+ }
+
+ public final int bridgeDomainIdFromInterfaceName(String interfaceName) {
+ checkConnected();
+ return bridgeDomainIdFromInterfaceName0(interfaceName);
+ }
+
+ public final vppIPv4Address[] ipv4AddressDump(String interfaceName) {
+ checkConnected();
+ return ipv4AddressDump0(interfaceName);
+ }
+
+ public final vppIPv6Address[] ipv6AddressDump(String interfaceName) {
+ checkConnected();
+ return ipv6AddressDump0(interfaceName);
+ }
+
+ public final vppVxlanTunnelDetails[] vxlanTunnelDump(int swIfIndex) {
+ checkConnected();
+ return vxlanTunnelDump0(swIfIndex);
+ }
+
+ public final int setInterfaceDescription(String ifName, String ifDesc) {
+ checkConnected();
+ return setInterfaceDescription0(ifName, ifDesc);
+ }
+
+ public final String getInterfaceDescription(String ifName) {
+ checkConnected();
+ return getInterfaceDescription0(ifName);
+ }
+
+ private static native int clientConnect(String clientName);
+ private static native void clientDisconnect();
+ private static native int getRetval0(int context, int release);
+ private static native String getInterfaceList0(String nameFilter);
+ private static native int swIfIndexFromName0(String interfaceName);
+ private static native String interfaceNameFromSwIfIndex0(int swIfIndex);
+ private static native void clearInterfaceTable0();
+ private static native vppInterfaceDetails[] swInterfaceDump0(byte nameFilterValid, byte [] nameFilter);
+ private static native int bridgeDomainIdFromName0(String bridgeDomain);
+ private static native int findOrAddBridgeDomainId0(String bridgeDomain);
+ private static native vppVersion getVppVersion0();
+ private static native vppInterfaceCounters getInterfaceCounters0(int swIfIndex);
+ private static native int[] bridgeDomainDump0(int bdId);
+ private static native vppBridgeDomainDetails getBridgeDomainDetails0(int bdId);
+ private static native vppL2Fib[] l2FibTableDump0(int bdId);
+ private static native int bridgeDomainIdFromInterfaceName0(String interfaceName);
+ private static native vppIPv4Address[] ipv4AddressDump0(String interfaceName);
+ private static native vppIPv6Address[] ipv6AddressDump0(String interfaceName);
+ private static native vppVxlanTunnelDetails[] vxlanTunnelDump0(int swIfIndex);
+ private static native int setInterfaceDescription0(String ifName, String ifDesc);
+ private static native String getInterfaceDescription0(String ifName);
}
diff --git a/vpp-japi/japi/org/openvpp/vppjapi/vppIPv6Address.java b/vpp-japi/japi/org/openvpp/vppjapi/vppIPv6Address.java
index 7bf10f23402..6690a5db981 100644
--- a/vpp-japi/japi/org/openvpp/vppjapi/vppIPv6Address.java
+++ b/vpp-japi/japi/org/openvpp/vppjapi/vppIPv6Address.java
@@ -20,8 +20,8 @@ public class vppIPv6Address {
public final byte[] ip;
public final byte prefixLength;
- public vppIPv6Address(byte[] _ip, byte _prefixLength) {
- ip = _ip;
- prefixLength = _prefixLength;
+ public vppIPv6Address(byte[] ip, byte prefixLength) {
+ this.ip = ip;
+ this.prefixLength = prefixLength;
}
}
diff --git a/vpp-japi/japi/org/openvpp/vppjapi/vppInterfaceCounters.java b/vpp-japi/japi/org/openvpp/vppjapi/vppInterfaceCounters.java
index 8a02ad09633..b2687fb8efb 100644
--- a/vpp-japi/japi/org/openvpp/vppjapi/vppInterfaceCounters.java
+++ b/vpp-japi/japi/org/openvpp/vppjapi/vppInterfaceCounters.java
@@ -15,7 +15,7 @@
package org.openvpp.vppjapi;
-public class vppInterfaceCounters {
+public final class vppInterfaceCounters {
public final long rxOctets;
public final long rxIp4;
diff --git a/vpp-japi/japi/test/demo.java b/vpp-japi/japi/test/demo.java
index ef419d70658..ea1db84bda2 100644
--- a/vpp-japi/japi/test/demo.java
+++ b/vpp-japi/japi/test/demo.java
@@ -15,9 +15,11 @@
import org.openvpp.vppjapi.*;
-public class demo extends vppApi {
+public class demo {
public static void main (String[] args) throws Exception {
- vppApi api = new vppApi ();
+ vppApi api = new vppApi ("JavaTest");
+ System.out.printf ("Connected OK...");
+
String intlist;
int [] contexts;
int i, limit;
@@ -25,15 +27,6 @@ public class demo extends vppApi {
int rv, errors, saved_error;
long before, after;
- rv = api.clientConnect ("JavaTest");
- if (rv == 0)
- System.out.printf ("Connected OK...");
- else
- {
- System.out.printf ("clientConnect returned %d\n", rv);
- System.exit (1);
- }
-
if (false)
{
intlist = api.getInterfaceList ("");
@@ -171,7 +164,7 @@ public class demo extends vppApi {
limit, after - before,
limit / (after - before));
- api.clientDisconnect();
+ api.close();
System.out.printf ("Done...\n");
}
}
diff --git a/vpp-japi/japi/test/vppApi.java b/vpp-japi/japi/test/vppApi.java
index 96ba4a277a7..87af3292449 100644
--- a/vpp-japi/japi/test/vppApi.java
+++ b/vpp-japi/japi/test/vppApi.java
@@ -16,13 +16,13 @@
import java.net.InetAddress;
import org.openvpp.vppjapi.*;
-public class vppApi extends vppConn {
+public class vppApi {
native int controlPing();
native void test (byte[] array, byte[] array2);
public static void main (String[] args) throws Exception {
- vppApi api = new vppApi ();
+ vppConn api = new vppConn ();
String ipv6 = "db01::feed";
String ipv4 = "192.168.1.1";
InetAddress addr6 = InetAddress.getByName(ipv6);