summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ipsec/ipsec-impl/pom.xml15
-rw-r--r--ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/FutureJVppIkev2Customizer.java38
-rw-r--r--ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/IpsecModule.java17
-rw-r--r--ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/JVppIkev2Provider.java70
-rw-r--r--ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/write/Ikev2GlobalConfigurationCustomizer.java12
-rw-r--r--ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/write/Ikev2PolicyCustomizer.java24
-rw-r--r--ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/write/Ikev2PolicyIdentityCustomizer.java12
-rw-r--r--ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/write/IpsecWriterFactory.java13
-rw-r--r--ipsec/ipsec-impl/src/test/java/io/fd/hc2vpp/ipsec/IpsecModuleTest.java14
-rw-r--r--ipsec/ipsec-impl/src/test/java/io/fd/hc2vpp/ipsec/write/Ikev2GlobalConfigurationCustomizerTest.java14
-rw-r--r--ipsec/ipsec-impl/src/test/java/io/fd/hc2vpp/ipsec/write/Ikev2PolicyCustomizerTest.java42
-rw-r--r--ipsec/ipsec-impl/src/test/java/io/fd/hc2vpp/ipsec/write/Ikev2PolicyIdentityCustomizerTest.java20
12 files changed, 230 insertions, 61 deletions
diff --git a/ipsec/ipsec-impl/pom.xml b/ipsec/ipsec-impl/pom.xml
index f5e632fda..bf705c480 100644
--- a/ipsec/ipsec-impl/pom.xml
+++ b/ipsec/ipsec-impl/pom.xml
@@ -30,6 +30,10 @@
<version>1.19.04-SNAPSHOT</version>
<packaging>bundle</packaging>
+ <properties>
+ <jvpp.version>19.04-SNAPSHOT</jvpp.version>
+ </properties>
+
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
@@ -37,6 +41,12 @@
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>io.fd.jvpp</groupId>
+ <artifactId>jvpp-ikev2</artifactId>
+ <version>${jvpp.version}</version>
+ </dependency>
+
<!--VPP common-->
<dependency>
<groupId>io.fd.honeycomb</groupId>
@@ -53,6 +63,11 @@
<artifactId>cfg-init</artifactId>
</dependency>
+ <dependency>
+ <groupId>io.fd.honeycomb</groupId>
+ <artifactId>binding-init</artifactId>
+ </dependency>
+
<!-- Translation -->
<dependency>
<groupId>io.fd.hc2vpp.common</groupId>
diff --git a/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/FutureJVppIkev2Customizer.java b/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/FutureJVppIkev2Customizer.java
new file mode 100644
index 000000000..c1453681f
--- /dev/null
+++ b/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/FutureJVppIkev2Customizer.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2019 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.hc2vpp.ipsec;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import io.fd.vpp.jvpp.ikev2.future.FutureJVppIkev2Facade;
+import javax.annotation.Nonnull;
+
+/**
+ * Holds reference to jvpp ikev2 implementation
+ */
+public abstract class FutureJVppIkev2Customizer {
+
+ private final FutureJVppIkev2Facade jVppIkev2Facade;
+
+ public FutureJVppIkev2Customizer(@Nonnull final FutureJVppIkev2Facade jVppIkev2Facade) {
+ this.jVppIkev2Facade = checkNotNull(jVppIkev2Facade, "JVpp Ikev2 Future api is null");
+ }
+
+ public FutureJVppIkev2Facade getjVppIkev2Facade() {
+ return jVppIkev2Facade;
+ }
+}
diff --git a/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/IpsecModule.java b/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/IpsecModule.java
index 36dd8ae85..8670eb749 100644
--- a/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/IpsecModule.java
+++ b/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/IpsecModule.java
@@ -16,7 +16,9 @@
package io.fd.hc2vpp.ipsec;
+import com.google.common.annotations.VisibleForTesting;
import com.google.inject.AbstractModule;
+import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.google.inject.multibindings.Multibinder;
import io.fd.hc2vpp.common.translate.util.MultiNamingContext;
@@ -24,6 +26,7 @@ import io.fd.hc2vpp.ipsec.read.IpsecReaderFactory;
import io.fd.hc2vpp.ipsec.write.IpsecWriterFactory;
import io.fd.honeycomb.translate.read.ReaderFactory;
import io.fd.honeycomb.translate.write.WriterFactory;
+import io.fd.vpp.jvpp.ikev2.future.FutureJVppIkev2Facade;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,11 +37,25 @@ public class IpsecModule extends AbstractModule {
private static final Logger LOG = LoggerFactory.getLogger(IpsecModule.class);
private static final String SAD_ENTRIES_MAPPING = "sad-entries-mapping";
+ private final Class<? extends Provider<FutureJVppIkev2Facade>> jvppIkev2ProviderClass;
+
+ public IpsecModule() {
+ this(JVppIkev2Provider.class);
+ }
+
+ @VisibleForTesting
+ protected IpsecModule(
+ final Class<? extends Provider<FutureJVppIkev2Facade>> jvppIkev2ProviderClass) {
+ this.jvppIkev2ProviderClass = jvppIkev2ProviderClass;
+ }
@Override
protected void configure() {
LOG.info("Installing IPSec module");
+ // binds JVpp Ikev2 future facade
+ bind(FutureJVppIkev2Facade.class).toProvider(jvppIkev2ProviderClass).in(Singleton.class);
+
bind(MultiNamingContext.class).toInstance(new MultiNamingContext(SAD_ENTRIES_MAPPING, 1));
LOG.info("Injecting writers factories");
final Multibinder<WriterFactory> writerFactoryBinder = Multibinder.newSetBinder(binder(), WriterFactory.class);
diff --git a/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/JVppIkev2Provider.java b/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/JVppIkev2Provider.java
new file mode 100644
index 000000000..9be082f02
--- /dev/null
+++ b/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/JVppIkev2Provider.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2019 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.hc2vpp.ipsec;
+
+import com.google.inject.Inject;
+import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
+import io.fd.honeycomb.binding.init.ProviderTrait;
+import io.fd.honeycomb.data.init.ShutdownHandler;
+import io.fd.vpp.jvpp.JVppRegistry;
+import io.fd.vpp.jvpp.VppBaseCallException;
+import io.fd.vpp.jvpp.ikev2.JVppIkev2Impl;
+import io.fd.vpp.jvpp.ikev2.dto.Ikev2PluginGetVersion;
+import io.fd.vpp.jvpp.ikev2.dto.Ikev2PluginGetVersionReply;
+import io.fd.vpp.jvpp.ikev2.future.FutureJVppIkev2Facade;
+import java.io.IOException;
+import java.util.concurrent.TimeoutException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+class JVppIkev2Provider extends ProviderTrait<FutureJVppIkev2Facade> implements JvppReplyConsumer {
+
+ private static final Logger LOG = LoggerFactory.getLogger(JVppIkev2Provider.class);
+
+ @Inject
+ private JVppRegistry registry;
+
+ @Inject
+ private ShutdownHandler shutdownHandler;
+
+ private static JVppIkev2Impl initIkev2Api(final ShutdownHandler shutdownHandler) {
+ final JVppIkev2Impl jvppIkev2 = new JVppIkev2Impl();
+ // Free jvpp-ikev2 plugin's resources on shutdown
+ shutdownHandler.register("jvpp-ikev2", jvppIkev2);
+ return jvppIkev2;
+ }
+
+ @Override
+ protected FutureJVppIkev2Facade create() {
+ try {
+ return reportVersionAndGet(initIkev2Api(shutdownHandler));
+ } catch (IOException e) {
+ throw new IllegalStateException("Unable to open VPP management connection", e);
+ } catch (TimeoutException | VppBaseCallException e) {
+ throw new IllegalStateException("Unable to load Ikev2 plugin version", e);
+ }
+ }
+
+ private FutureJVppIkev2Facade reportVersionAndGet(final JVppIkev2Impl jvppIkev2)
+ throws IOException, TimeoutException, VppBaseCallException {
+ final FutureJVppIkev2Facade futureFacade = new FutureJVppIkev2Facade(registry, jvppIkev2);
+ final Ikev2PluginGetVersionReply pluginVersion =
+ getReply(futureFacade.ikev2PluginGetVersion(new Ikev2PluginGetVersion()).toCompletableFuture());
+ LOG.info("Ikev2 plugin successfully loaded[version {}.{}]", pluginVersion.major, pluginVersion.minor);
+ return futureFacade;
+ }
+}
diff --git a/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/write/Ikev2GlobalConfigurationCustomizer.java b/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/write/Ikev2GlobalConfigurationCustomizer.java
index 6886b9b5d..dd7d34edb 100644
--- a/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/write/Ikev2GlobalConfigurationCustomizer.java
+++ b/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/write/Ikev2GlobalConfigurationCustomizer.java
@@ -16,21 +16,21 @@
package io.fd.hc2vpp.ipsec.write;
-import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
+import io.fd.hc2vpp.ipsec.FutureJVppIkev2Customizer;
import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
-import io.fd.vpp.jvpp.core.dto.Ikev2SetLocalKey;
-import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import io.fd.vpp.jvpp.ikev2.dto.Ikev2SetLocalKey;
+import io.fd.vpp.jvpp.ikev2.future.FutureJVppIkev2Facade;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.ipsec.rev181213.IpsecIkeGlobalConfAugmentation;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipsec.rev181214.ikev2.IkeGlobalConfiguration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-public class Ikev2GlobalConfigurationCustomizer extends FutureJVppCustomizer
+public class Ikev2GlobalConfigurationCustomizer extends FutureJVppIkev2Customizer
implements WriterCustomizer<IkeGlobalConfiguration>, JvppReplyConsumer {
- public Ikev2GlobalConfigurationCustomizer(final FutureJVppCore vppApi) {
+ public Ikev2GlobalConfigurationCustomizer(final FutureJVppIkev2Facade vppApi) {
super(vppApi);
}
@@ -44,7 +44,7 @@ public class Ikev2GlobalConfigurationCustomizer extends FutureJVppCustomizer
if (fileAUg.getLocalKeyFile() != null) {
Ikev2SetLocalKey request = new Ikev2SetLocalKey();
request.keyFile = fileAUg.getLocalKeyFile().getBytes();
- getReplyForWrite(getFutureJVpp().ikev2SetLocalKey(request).toCompletableFuture(), id);
+ getReplyForWrite(getjVppIkev2Facade().ikev2SetLocalKey(request).toCompletableFuture(), id);
}
}
}
diff --git a/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/write/Ikev2PolicyCustomizer.java b/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/write/Ikev2PolicyCustomizer.java
index 6cb37329c..47a09c8b1 100644
--- a/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/write/Ikev2PolicyCustomizer.java
+++ b/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/write/Ikev2PolicyCustomizer.java
@@ -17,17 +17,17 @@
package io.fd.hc2vpp.ipsec.write;
import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
-import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
+import io.fd.hc2vpp.ipsec.FutureJVppIkev2Customizer;
import io.fd.hc2vpp.ipsec.dto.AuthMethod;
import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
-import io.fd.vpp.jvpp.core.dto.Ikev2ProfileAddDel;
-import io.fd.vpp.jvpp.core.dto.Ikev2ProfileSetAuth;
-import io.fd.vpp.jvpp.core.dto.Ikev2ProfileSetTs;
-import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import io.fd.vpp.jvpp.ikev2.dto.Ikev2ProfileAddDel;
+import io.fd.vpp.jvpp.ikev2.dto.Ikev2ProfileSetAuth;
+import io.fd.vpp.jvpp.ikev2.dto.Ikev2ProfileSetTs;
+import io.fd.vpp.jvpp.ikev2.future.FutureJVppIkev2Facade;
import java.nio.ByteBuffer;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.ipsec.rev181213.IpsecIkev2PolicyAugmentation;
@@ -38,10 +38,10 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipsec.rev18
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipsec.rev181214.ikev2.policy.profile.grouping.Authentication;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-public class Ikev2PolicyCustomizer extends FutureJVppCustomizer
+public class Ikev2PolicyCustomizer extends FutureJVppIkev2Customizer
implements ListWriterCustomizer<Policy, PolicyKey>, JvppReplyConsumer, ByteDataTranslator, Ipv4Translator {
- public Ikev2PolicyCustomizer(final FutureJVppCore vppApi) {
+ public Ikev2PolicyCustomizer(final FutureJVppIkev2Facade vppApi) {
super(vppApi);
}
@@ -51,7 +51,7 @@ public class Ikev2PolicyCustomizer extends FutureJVppCustomizer
final Ikev2ProfileAddDel request = new Ikev2ProfileAddDel();
request.isAdd = BYTE_TRUE;
request.name = dataAfter.getName().getBytes();
- getReplyForWrite(getFutureJVpp().ikev2ProfileAddDel(request).toCompletableFuture(), id);
+ getReplyForWrite(getjVppIkev2Facade().ikev2ProfileAddDel(request).toCompletableFuture(), id);
addAuthorization(dataAfter, id);
addTrafficSelectors(dataAfter, id);
}
@@ -62,7 +62,7 @@ public class Ikev2PolicyCustomizer extends FutureJVppCustomizer
final Ikev2ProfileAddDel request = new Ikev2ProfileAddDel();
request.isAdd = BYTE_FALSE;
request.name = dataBefore.getName().getBytes();
- getReplyForWrite(getFutureJVpp().ikev2ProfileAddDel(request).toCompletableFuture(), id);
+ getReplyForWrite(getjVppIkev2Facade().ikev2ProfileAddDel(request).toCompletableFuture(), id);
}
@Override
@@ -113,7 +113,7 @@ public class Ikev2PolicyCustomizer extends FutureJVppCustomizer
if (dataAfter.getName() != null) {
addTsRequest.name = dataAfter.getName().getBytes();
}
- getReplyForWrite(getFutureJVpp().ikev2ProfileSetTs(addTsRequest).toCompletableFuture(), id);
+ getReplyForWrite(getjVppIkev2Facade().ikev2ProfileSetTs(addTsRequest).toCompletableFuture(), id);
}
}
}
@@ -141,7 +141,7 @@ public class Ikev2PolicyCustomizer extends FutureJVppCustomizer
request.dataLen = request.data.length;
request.isHex = BYTE_FALSE;
request.authMethod = AuthMethod.RSA_SIG.getValue();
- getReplyForWrite(getFutureJVpp().ikev2ProfileSetAuth(request).toCompletableFuture(), id);
+ getReplyForWrite(getjVppIkev2Facade().ikev2ProfileSetAuth(request).toCompletableFuture(), id);
}
private void setProfilePreSharedKeyAuth(final String name,
@@ -155,6 +155,6 @@ public class Ikev2PolicyCustomizer extends FutureJVppCustomizer
request.data = preSharedKey.stringValue().getBytes();
request.dataLen = request.data.length;
request.name = name.getBytes();
- getReplyForWrite(getFutureJVpp().ikev2ProfileSetAuth(request).toCompletableFuture(), id);
+ getReplyForWrite(getjVppIkev2Facade().ikev2ProfileSetAuth(request).toCompletableFuture(), id);
}
}
diff --git a/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/write/Ikev2PolicyIdentityCustomizer.java b/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/write/Ikev2PolicyIdentityCustomizer.java
index f6b100c54..430aebc88 100644
--- a/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/write/Ikev2PolicyIdentityCustomizer.java
+++ b/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/write/Ikev2PolicyIdentityCustomizer.java
@@ -17,15 +17,15 @@
package io.fd.hc2vpp.ipsec.write;
import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
-import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
import io.fd.hc2vpp.common.translate.util.Ipv6Translator;
import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
+import io.fd.hc2vpp.ipsec.FutureJVppIkev2Customizer;
import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
-import io.fd.vpp.jvpp.core.dto.Ikev2ProfileSetId;
-import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import io.fd.vpp.jvpp.ikev2.dto.Ikev2ProfileSetId;
+import io.fd.vpp.jvpp.ikev2.future.FutureJVppIkev2Facade;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipsec.rev181214.identity.grouping.identity.FqdnString;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipsec.rev181214.identity.grouping.identity.Ipv4Address;
@@ -35,10 +35,10 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipsec.rev18
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipsec.rev181214.ikev2.Policy;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-public class Ikev2PolicyIdentityCustomizer extends FutureJVppCustomizer
+public class Ikev2PolicyIdentityCustomizer extends FutureJVppIkev2Customizer
implements WriterCustomizer<Identity>, JvppReplyConsumer, ByteDataTranslator, Ipv4Translator, Ipv6Translator {
- public Ikev2PolicyIdentityCustomizer(final FutureJVppCore vppApi) {
+ public Ikev2PolicyIdentityCustomizer(final FutureJVppIkev2Facade vppApi) {
super(vppApi);
}
@@ -74,7 +74,7 @@ public class Ikev2PolicyIdentityCustomizer extends FutureJVppCustomizer
request.isLocal = isLocalId
? BYTE_TRUE
: BYTE_FALSE;
- getReplyForWrite(getFutureJVpp().ikev2ProfileSetId(request).toCompletableFuture(), id);
+ getReplyForWrite(getjVppIkev2Facade().ikev2ProfileSetId(request).toCompletableFuture(), id);
}
private void transformIdentityToRequest(
diff --git a/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/write/IpsecWriterFactory.java b/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/write/IpsecWriterFactory.java
index 8b164ac74..4dc7ff1b0 100644
--- a/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/write/IpsecWriterFactory.java
+++ b/ipsec/ipsec-impl/src/main/java/io/fd/hc2vpp/ipsec/write/IpsecWriterFactory.java
@@ -24,6 +24,7 @@ import io.fd.honeycomb.translate.impl.write.GenericWriter;
import io.fd.honeycomb.translate.write.WriterFactory;
import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import io.fd.vpp.jvpp.ikev2.future.FutureJVppIkev2Facade;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.ipsec.rev181213.IpsecIkeGlobalConfAugmentation;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.ipsec.rev181213.IpsecIkev2PolicyAugmentation;
@@ -67,11 +68,15 @@ public final class IpsecWriterFactory implements WriterFactory {
private static final InstanceIdentifier<Spd> SPD_ID = IPSEC_ID.child(Spd.class);
private final FutureJVppCore vppApi;
+ private final FutureJVppIkev2Facade vppIkev2Api;
private MultiNamingContext sadEntriesMapping;
@Inject
- public IpsecWriterFactory(final FutureJVppCore vppApi, final MultiNamingContext sadEntriesMappingContext) {
+ public IpsecWriterFactory(final FutureJVppCore vppApi,
+ final FutureJVppIkev2Facade vppIkev2Api,
+ final MultiNamingContext sadEntriesMappingContext) {
this.vppApi = vppApi;
+ this.vppIkev2Api = vppIkev2Api;
this.sadEntriesMapping = sadEntriesMappingContext;
}
@@ -104,16 +109,16 @@ public final class IpsecWriterFactory implements WriterFactory {
registry.subtreeAdd(Sets.newHashSet(InstanceIdentifier.create(IkeGlobalConfiguration.class)
.augmentation(IpsecIkeGlobalConfAugmentation.class)),
new GenericWriter<>(IKE2_ID.child(IkeGlobalConfiguration.class),
- new Ikev2GlobalConfigurationCustomizer(vppApi)));
+ new Ikev2GlobalConfigurationCustomizer(vppIkev2Api)));
registry.subtreeAdd(Sets.newHashSet(InstanceIdentifier.create(Policy.class).child(
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipsec.rev181214.ikev2.policy.profile.grouping.Authentication.class),
InstanceIdentifier.create(Policy.class).augmentation(IpsecIkev2PolicyAugmentation.class),
InstanceIdentifier.create(Policy.class).augmentation(IpsecIkev2PolicyAugmentation.class)
.child(TrafficSelectors.class)),
- new GenericListWriter<>(IKE2_ID.child(Policy.class), new Ikev2PolicyCustomizer(vppApi)));
+ new GenericListWriter<>(IKE2_ID.child(Policy.class), new Ikev2PolicyCustomizer(vppIkev2Api)));
registry.subtreeAdd(Sets.newHashSet(InstanceIdentifier.create(Identity.class).child(Local.class),
InstanceIdentifier.create(Identity.class).child(Remote.class)),
new GenericWriter<>(IKE2_ID.child(Policy.class).child(Identity.class),
- new Ikev2PolicyIdentityCustomizer(vppApi)));
+ new Ikev2PolicyIdentityCustomizer(vppIkev2Api)));
}
}
diff --git a/ipsec/ipsec-impl/src/test/java/io/fd/hc2vpp/ipsec/IpsecModuleTest.java b/ipsec/ipsec-impl/src/test/java/io/fd/hc2vpp/ipsec/IpsecModuleTest.java
index 42817d42a..878edd9ac 100644
--- a/ipsec/ipsec-impl/src/test/java/io/fd/hc2vpp/ipsec/IpsecModuleTest.java
+++ b/ipsec/ipsec-impl/src/test/java/io/fd/hc2vpp/ipsec/IpsecModuleTest.java
@@ -23,10 +23,12 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
import static org.mockito.MockitoAnnotations.initMocks;
import com.google.inject.Guice;
import com.google.inject.Inject;
+import com.google.inject.Provider;
import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule;
import io.fd.hc2vpp.ipsec.read.IpsecReaderFactory;
@@ -37,6 +39,7 @@ import io.fd.honeycomb.translate.read.ReaderFactory;
import io.fd.honeycomb.translate.util.YangDAG;
import io.fd.honeycomb.translate.write.WriterFactory;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import io.fd.vpp.jvpp.ikev2.future.FutureJVppIkev2Facade;
import java.util.HashSet;
import java.util.Set;
import org.junit.Before;
@@ -58,7 +61,8 @@ public class IpsecModuleTest {
@Before
public void setUp() {
initMocks(this);
- Guice.createInjector(new IpsecModule(), BoundFieldModule.of(this)).injectMembers(this);
+ Guice.createInjector(new IpsecModule(MockJVppIkev2Provider.class), BoundFieldModule.of(this))
+ .injectMembers(this);
}
@Test
@@ -80,4 +84,12 @@ public class IpsecModuleTest {
assertEquals(1, readerFactories.size());
assertTrue(readerFactories.iterator().next() instanceof IpsecReaderFactory);
}
+
+ private static final class MockJVppIkev2Provider implements Provider<FutureJVppIkev2Facade> {
+
+ @Override
+ public FutureJVppIkev2Facade get() {
+ return mock(FutureJVppIkev2Facade.class);
+ }
+ }
}
diff --git a/ipsec/ipsec-impl/src/test/java/io/fd/hc2vpp/ipsec/write/Ikev2GlobalConfigurationCustomizerTest.java b/ipsec/ipsec-impl/src/test/java/io/fd/hc2vpp/ipsec/write/Ikev2GlobalConfigurationCustomizerTest.java
index cf9e8b102..84ae9c7d6 100644
--- a/ipsec/ipsec-impl/src/test/java/io/fd/hc2vpp/ipsec/write/Ikev2GlobalConfigurationCustomizerTest.java
+++ b/ipsec/ipsec-impl/src/test/java/io/fd/hc2vpp/ipsec/write/Ikev2GlobalConfigurationCustomizerTest.java
@@ -23,9 +23,11 @@ import static org.mockito.Mockito.when;
import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
import io.fd.hc2vpp.ipsec.helpers.SchemaContextTestHelper;
import io.fd.honeycomb.translate.write.WriteFailedException;
-import io.fd.vpp.jvpp.core.dto.Ikev2SetLocalKey;
-import io.fd.vpp.jvpp.core.dto.Ikev2SetLocalKeyReply;
+import io.fd.vpp.jvpp.ikev2.dto.Ikev2SetLocalKey;
+import io.fd.vpp.jvpp.ikev2.dto.Ikev2SetLocalKeyReply;
+import io.fd.vpp.jvpp.ikev2.future.FutureJVppIkev2Facade;
import org.junit.Test;
+import org.mockito.Mock;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.ipsec.rev181213.IpsecIkeGlobalConfAugmentation;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.ipsec.rev181213.IpsecIkeGlobalConfAugmentationBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipsec.rev181214.Ikev2;
@@ -39,11 +41,13 @@ public class Ikev2GlobalConfigurationCustomizerTest extends WriterCustomizerTest
.child(IkeGlobalConfiguration.class);
private Ikev2GlobalConfigurationCustomizer customizer;
private static final String LOCAL_KEY_FILE = "/home/localadmin/certs/client-key.pem";
+ @Mock
+ protected FutureJVppIkev2Facade ikev2api;
@Override
protected void setUpTest() throws Exception {
- customizer = new Ikev2GlobalConfigurationCustomizer(api);
- when(api.ikev2SetLocalKey(any())).thenReturn(future(new Ikev2SetLocalKeyReply()));
+ customizer = new Ikev2GlobalConfigurationCustomizer(ikev2api);
+ when(ikev2api.ikev2SetLocalKey(any())).thenReturn(future(new Ikev2SetLocalKeyReply()));
}
@Test
@@ -55,6 +59,6 @@ public class Ikev2GlobalConfigurationCustomizerTest extends WriterCustomizerTest
customizer.writeCurrentAttributes(IID, dataAfterBuilder.build(), writeContext);
Ikev2SetLocalKey request = new Ikev2SetLocalKey();
request.keyFile = LOCAL_KEY_FILE.getBytes();
- verify(api).ikev2SetLocalKey(request);
+ verify(ikev2api).ikev2SetLocalKey(request);
}
}
diff --git a/ipsec/ipsec-impl/src/test/java/io/fd/hc2vpp/ipsec/write/Ikev2PolicyCustomizerTest.java b/ipsec/ipsec-impl/src/test/java/io/fd/hc2vpp/ipsec/write/Ikev2PolicyCustomizerTest.java
index e2062e56c..b53ab7024 100644
--- a/ipsec/ipsec-impl/src/test/java/io/fd/hc2vpp/ipsec/write/Ikev2PolicyCustomizerTest.java
+++ b/ipsec/ipsec-impl/src/test/java/io/fd/hc2vpp/ipsec/write/Ikev2PolicyCustomizerTest.java
@@ -30,15 +30,17 @@ import io.fd.hc2vpp.ipsec.helpers.SchemaContextTestHelper;
import io.fd.honeycomb.test.tools.HoneycombTestRunner;
import io.fd.honeycomb.test.tools.annotations.InjectTestData;
import io.fd.honeycomb.translate.write.WriteFailedException;
-import io.fd.vpp.jvpp.core.dto.Ikev2ProfileAddDel;
-import io.fd.vpp.jvpp.core.dto.Ikev2ProfileAddDelReply;
-import io.fd.vpp.jvpp.core.dto.Ikev2ProfileSetAuth;
-import io.fd.vpp.jvpp.core.dto.Ikev2ProfileSetAuthReply;
-import io.fd.vpp.jvpp.core.dto.Ikev2ProfileSetTs;
-import io.fd.vpp.jvpp.core.dto.Ikev2ProfileSetTsReply;
+import io.fd.vpp.jvpp.ikev2.dto.Ikev2ProfileAddDel;
+import io.fd.vpp.jvpp.ikev2.dto.Ikev2ProfileAddDelReply;
+import io.fd.vpp.jvpp.ikev2.dto.Ikev2ProfileSetAuth;
+import io.fd.vpp.jvpp.ikev2.dto.Ikev2ProfileSetAuthReply;
+import io.fd.vpp.jvpp.ikev2.dto.Ikev2ProfileSetTs;
+import io.fd.vpp.jvpp.ikev2.dto.Ikev2ProfileSetTsReply;
+import io.fd.vpp.jvpp.ikev2.future.FutureJVppIkev2Facade;
import java.nio.ByteBuffer;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.ipsec.rev181213.IpsecIkev2PolicyAugmentation;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.ipsec.rev181213.ikev2.policy.aug.grouping.TrafficSelectors;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipsec.rev181214.Ikev2;
@@ -53,13 +55,15 @@ public class Ikev2PolicyCustomizerTest extends WriterCustomizerTest implements S
private static final String IKEV2_PATH = "/hc2vpp-ietf-ipsec:ikev2";
private Ikev2PolicyCustomizer customizer;
+ @Mock
+ protected FutureJVppIkev2Facade ikev2api;
@Override
protected void setUpTest() throws Exception {
- customizer = new Ikev2PolicyCustomizer(api);
- when(api.ikev2ProfileAddDel(any())).thenReturn(future(new Ikev2ProfileAddDelReply()));
- when(api.ikev2ProfileSetTs(any())).thenReturn(future(new Ikev2ProfileSetTsReply()));
- when(api.ikev2ProfileSetAuth(any())).thenReturn(future(new Ikev2ProfileSetAuthReply()));
+ customizer = new Ikev2PolicyCustomizer(ikev2api);
+ when(ikev2api.ikev2ProfileAddDel(any())).thenReturn(future(new Ikev2ProfileAddDelReply()));
+ when(ikev2api.ikev2ProfileSetTs(any())).thenReturn(future(new Ikev2ProfileSetTsReply()));
+ when(ikev2api.ikev2ProfileSetAuth(any())).thenReturn(future(new Ikev2ProfileSetAuthReply()));
}
@Test
@@ -71,10 +75,10 @@ public class Ikev2PolicyCustomizerTest extends WriterCustomizerTest implements S
profileAddrequest.isAdd = BYTE_TRUE;
profileAddrequest.name = policy.getName().getBytes();
- verify(api).ikev2ProfileAddDel(profileAddrequest);
- verify(api).ikev2ProfileSetTs(translateTStoRequest(policy.augmentation(IpsecIkev2PolicyAugmentation.class)
+ verify(ikev2api).ikev2ProfileAddDel(profileAddrequest);
+ verify(ikev2api).ikev2ProfileSetTs(translateTStoRequest(policy.augmentation(IpsecIkev2PolicyAugmentation.class)
.getTrafficSelectors().get(0), policy.getName()));
- verify(api).ikev2ProfileSetAuth(translateAuthToRequest(policy));
+ verify(ikev2api).ikev2ProfileSetAuth(translateAuthToRequest(policy));
}
@Test
@@ -86,10 +90,10 @@ public class Ikev2PolicyCustomizerTest extends WriterCustomizerTest implements S
final Policy after = ikev2After.getPolicy().get(0);
customizer.updateCurrentAttributes(getId(before.getName()), before, after, writeContext);
- verify(api, times(0)).ikev2ProfileAddDel(any());
- verify(api).ikev2ProfileSetTs(translateTStoRequest(after.augmentation(IpsecIkev2PolicyAugmentation.class)
+ verify(ikev2api, times(0)).ikev2ProfileAddDel(any());
+ verify(ikev2api).ikev2ProfileSetTs(translateTStoRequest(after.augmentation(IpsecIkev2PolicyAugmentation.class)
.getTrafficSelectors().get(0), after.getName()));
- verify(api).ikev2ProfileSetAuth(translateAuthToRequest(after));
+ verify(ikev2api).ikev2ProfileSetAuth(translateAuthToRequest(after));
}
@Test
@@ -100,9 +104,9 @@ public class Ikev2PolicyCustomizerTest extends WriterCustomizerTest implements S
final Ikev2ProfileAddDel request = new Ikev2ProfileAddDel();
request.name = policy.getName().getBytes();
request.isAdd = BYTE_FALSE;
- verify(api).ikev2ProfileAddDel(request);
- verify(api, times(0)).ikev2ProfileSetTs(any());
- verify(api, times(0)).ikev2ProfileSetAuth(any());
+ verify(ikev2api).ikev2ProfileAddDel(request);
+ verify(ikev2api, times(0)).ikev2ProfileSetTs(any());
+ verify(ikev2api, times(0)).ikev2ProfileSetAuth(any());
}
private InstanceIdentifier<Policy> getId(final String name) {
diff --git a/ipsec/ipsec-impl/src/test/java/io/fd/hc2vpp/ipsec/write/Ikev2PolicyIdentityCustomizerTest.java b/ipsec/ipsec-impl/src/test/java/io/fd/hc2vpp/ipsec/write/Ikev2PolicyIdentityCustomizerTest.java
index 3f57acdbb..2a62b9494 100644
--- a/ipsec/ipsec-impl/src/test/java/io/fd/hc2vpp/ipsec/write/Ikev2PolicyIdentityCustomizerTest.java
+++ b/ipsec/ipsec-impl/src/test/java/io/fd/hc2vpp/ipsec/write/Ikev2PolicyIdentityCustomizerTest.java
@@ -28,10 +28,12 @@ import io.fd.hc2vpp.ipsec.helpers.SchemaContextTestHelper;
import io.fd.honeycomb.test.tools.HoneycombTestRunner;
import io.fd.honeycomb.test.tools.annotations.InjectTestData;
import io.fd.honeycomb.translate.write.WriteFailedException;
-import io.fd.vpp.jvpp.core.dto.Ikev2ProfileSetId;
-import io.fd.vpp.jvpp.core.dto.Ikev2ProfileSetIdReply;
+import io.fd.vpp.jvpp.ikev2.dto.Ikev2ProfileSetId;
+import io.fd.vpp.jvpp.ikev2.dto.Ikev2ProfileSetIdReply;
+import io.fd.vpp.jvpp.ikev2.future.FutureJVppIkev2Facade;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipsec.rev181214.Ikev2;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipsec.rev181214.ike.general.policy.profile.grouping.Identity;
@@ -52,11 +54,13 @@ public class Ikev2PolicyIdentityCustomizerTest extends WriterCustomizerTest impl
"/hc2vpp-ietf-ipsec:ikev2/hc2vpp-ietf-ipsec:policy[hc2vpp-ietf-ipsec:name='" + POLICY_NAME +
"']/hc2vpp-ietf-ipsec:identity";
private Ikev2PolicyIdentityCustomizer customizer;
+ @Mock
+ protected FutureJVppIkev2Facade ikev2api;
@Override
protected void setUpTest() throws Exception {
- customizer = new Ikev2PolicyIdentityCustomizer(api);
- when(api.ikev2ProfileSetId(any())).thenReturn(future(new Ikev2ProfileSetIdReply()));
+ customizer = new Ikev2PolicyIdentityCustomizer(ikev2api);
+ when(ikev2api.ikev2ProfileSetId(any())).thenReturn(future(new Ikev2ProfileSetIdReply()));
}
@Test
@@ -70,7 +74,7 @@ public class Ikev2PolicyIdentityCustomizerTest extends WriterCustomizerTest impl
request.isLocal = BYTE_TRUE;
request.data = ipv4AddressNoZoneToArray(IPV4_TYPE_DATA);
request.dataLen = request.data.length;
- verify(api).ikev2ProfileSetId(request);
+ verify(ikev2api).ikev2ProfileSetId(request);
}
@Test
@@ -84,7 +88,7 @@ public class Ikev2PolicyIdentityCustomizerTest extends WriterCustomizerTest impl
request.isLocal = BYTE_FALSE;
request.data = FQDN_TYPE_DATA.getBytes();
request.dataLen = request.data.length;
- verify(api).ikev2ProfileSetId(request);
+ verify(ikev2api).ikev2ProfileSetId(request);
}
@Test
@@ -98,7 +102,7 @@ public class Ikev2PolicyIdentityCustomizerTest extends WriterCustomizerTest impl
request.isLocal = BYTE_FALSE;
request.data = ipv6AddressNoZoneToArray(new Ipv6Address(IPV6_TYPE_DATA));
request.dataLen = request.data.length;
- verify(api).ikev2ProfileSetId(request);
+ verify(ikev2api).ikev2ProfileSetId(request);
}
@Test
@@ -113,7 +117,7 @@ public class Ikev2PolicyIdentityCustomizerTest extends WriterCustomizerTest impl
request.isLocal = BYTE_TRUE;
request.data = RFC822_TYPE_DATA.getBytes();
request.dataLen = request.data.length;
- verify(api).ikev2ProfileSetId(request);
+ verify(ikev2api).ikev2ProfileSetId(request);
}
private InstanceIdentifier<Identity> getId() {