From 220404db4488c6562f50f4b45ba75c8c256c8121 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Mon, 16 Jul 2018 09:05:42 +0200 Subject: HC2VPP-176: add support for api-segment prefix VPP can be run with custom SHM segment prefix: sudo vpp unix {cli-listen /run/vpp/cli-vpp1.sock} api-segment { prefix vpp1 } sudo vppctl -s /run/vpp/cli-vpp1.sock this patch adds optional api-segment-prefix parameter to /opt/honeycomb/config/jvpp.json file. Example configuration: { "jvpp-connection-name": "honeycomb", "api-segment-prefix": "vpp1", "jvpp-request-timeout": 5 } Change-Id: I7ca298644891602afe7898db88bb90d59b49ce4d Signed-off-by: Marek Gradzki --- .../common/integration/JVppRegistryProvider.java | 19 ++++++++++++------- .../common/integration/VppConfigAttributes.java | 4 ++++ 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'vpp-common') diff --git a/vpp-common/vpp-common-integration/src/main/java/io/fd/hc2vpp/common/integration/JVppRegistryProvider.java b/vpp-common/vpp-common-integration/src/main/java/io/fd/hc2vpp/common/integration/JVppRegistryProvider.java index 300e03806..1432f2c53 100644 --- a/vpp-common/vpp-common-integration/src/main/java/io/fd/hc2vpp/common/integration/JVppRegistryProvider.java +++ b/vpp-common/vpp-common-integration/src/main/java/io/fd/hc2vpp/common/integration/JVppRegistryProvider.java @@ -16,6 +16,9 @@ package io.fd.hc2vpp.common.integration; +import static com.google.common.base.Preconditions.checkState; +import static java.lang.String.format; + import com.google.common.base.Charsets; import com.google.common.io.CharStreams; import com.google.common.primitives.UnsignedInts; @@ -25,15 +28,11 @@ import io.fd.honeycomb.data.init.ShutdownHandler; import io.fd.vpp.jvpp.JVppRegistry; import io.fd.vpp.jvpp.JVppRegistryImpl; import io.fd.vpp.jvpp.VppJNIConnection; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStreamReader; - -import static com.google.common.base.Preconditions.checkState; -import static java.lang.String.format; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Provides JVppRegistry. Must be a singleton due to shutdown hook usage. Registers shutdown hook to disconnect from @@ -54,7 +53,13 @@ public final class JVppRegistryProvider extends ProviderTrait { protected JVppRegistry create() { final JVppRegistry registry; try { - registry = new JVppRegistryImpl(config.jvppConnectionName); + if (config.apiSegmentPrefix.isPresent()) { + // TODO(VPP-1342): JVppRegistryImpl requires full SHM region name + final String shmName = String.format("/%s-vpe-api", config.apiSegmentPrefix.get()); + registry = new JVppRegistryImpl(config.jvppConnectionName, shmName); + } else { + registry = new JVppRegistryImpl(config.jvppConnectionName); + } connectedVppPid = initConnectedVppPid(registry); shutdownHandler.register("jvpp-registry", () -> { // Closing JVpp connection with shutdown hook to erase the connection from VPP so HC will be able diff --git a/vpp-common/vpp-common-integration/src/main/java/io/fd/hc2vpp/common/integration/VppConfigAttributes.java b/vpp-common/vpp-common-integration/src/main/java/io/fd/hc2vpp/common/integration/VppConfigAttributes.java index 9c351cb7c..ba1a843a4 100644 --- a/vpp-common/vpp-common-integration/src/main/java/io/fd/hc2vpp/common/integration/VppConfigAttributes.java +++ b/vpp-common/vpp-common-integration/src/main/java/io/fd/hc2vpp/common/integration/VppConfigAttributes.java @@ -16,6 +16,7 @@ package io.fd.hc2vpp.common.integration; +import java.util.Optional; import net.jmob.guice.conf.core.BindConfig; import net.jmob.guice.conf.core.InjectConfig; import net.jmob.guice.conf.core.Syntax; @@ -26,6 +27,9 @@ public class VppConfigAttributes { @InjectConfig("jvpp-connection-name") public String jvppConnectionName; + @InjectConfig("api-segment-prefix") + public Optional apiSegmentPrefix; + @InjectConfig("jvpp-request-timeout") public int jvppRequestTimeout; } -- cgit 1.2.3-korg