From 175197da8ea43335df3daeba4c6296fcd83a057c Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Thu, 10 Nov 2016 13:31:25 +0100 Subject: Post split cleanup - change groupIds - change packages - update poms Change-Id: I343c5a292a67de1dd50687870ca4ab5b7276e93e Signed-off-by: Maros Marsalek Signed-off-by: Marek Gradzki --- ioam/impl/pom.xml | 8 +- .../io/fd/hc2vpp/vppioam/impl/VppIoamModule.java | 60 +++++++ .../impl/config/IoamTraceWriterCustomizer.java | 131 +++++++++++++++ .../vppioam/impl/config/VppIoamWriterFactory.java | 46 +++++ .../impl/util/FutureJVppIoamCustomizer.java | 45 +++++ .../hc2vpp/vppioam/impl/util/JVppIoamProvider.java | 60 +++++++ .../fd/honeycomb/vppioam/impl/VppIoamModule.java | 63 ------- .../impl/config/IoamTraceWriterCustomizer.java | 134 --------------- .../vppioam/impl/config/VppIoamWriterFactory.java | 49 ------ .../impl/util/FutureJVppIoamCustomizer.java | 45 ----- .../vppioam/impl/util/JVppIoamProvider.java | 62 ------- .../fd/hc2vpp/vppioam/impl/VppIoamModuleTest.java | 90 ++++++++++ .../impl/config/IoamTraceWriterCustomizerTest.java | 181 ++++++++++++++++++++ .../honeycomb/vppioam/impl/VppIoamModuleTest.java | 90 ---------- .../impl/config/IoamTraceWriterCustomizerTest.java | 186 --------------------- 15 files changed, 617 insertions(+), 633 deletions(-) create mode 100755 ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/VppIoamModule.java create mode 100755 ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/config/IoamTraceWriterCustomizer.java create mode 100755 ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/config/VppIoamWriterFactory.java create mode 100755 ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/util/FutureJVppIoamCustomizer.java create mode 100755 ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/util/JVppIoamProvider.java delete mode 100755 ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/VppIoamModule.java delete mode 100755 ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/config/IoamTraceWriterCustomizer.java delete mode 100755 ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/config/VppIoamWriterFactory.java delete mode 100755 ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/util/FutureJVppIoamCustomizer.java delete mode 100755 ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/util/JVppIoamProvider.java create mode 100644 ioam/impl/src/test/java/io/fd/hc2vpp/vppioam/impl/VppIoamModuleTest.java create mode 100644 ioam/impl/src/test/java/io/fd/hc2vpp/vppioam/impl/config/IoamTraceWriterCustomizerTest.java delete mode 100644 ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/VppIoamModuleTest.java delete mode 100644 ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/config/IoamTraceWriterCustomizerTest.java (limited to 'ioam/impl') diff --git a/ioam/impl/pom.xml b/ioam/impl/pom.xml index dd106d003..1ffdadcae 100644 --- a/ioam/impl/pom.xml +++ b/ioam/impl/pom.xml @@ -14,15 +14,15 @@ limitations under the License. --> + io.fd.honeycomb.common impl-parent 1.16.12-SNAPSHOT - ../../common/impl-parent 4.0.0 - io.fd.honeycomb.vppioam + io.fd.hc2vpp.ioam vppioam-impl ${project.artifactId} 1.16.12-SNAPSHOT @@ -94,12 +94,12 @@ ${ioam.version} - io.fd.honeycomb.vpp + io.fd.hc2vpp.common vpp-translate-utils ${project.version} - io.fd.honeycomb.vpp + io.fd.hc2vpp.common vpp-translate-test ${project.version} test diff --git a/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/VppIoamModule.java b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/VppIoamModule.java new file mode 100755 index 000000000..bf5df6389 --- /dev/null +++ b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/VppIoamModule.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 io.fd.hc2vpp.vppioam.impl; + +import com.google.common.annotations.VisibleForTesting; +import com.google.inject.AbstractModule; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.Provider; +import io.fd.hc2vpp.vppioam.impl.config.VppIoamWriterFactory; +import io.fd.honeycomb.translate.write.WriterFactory; +import io.fd.hc2vpp.vppioam.impl.util.JVppIoamProvider; +import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace; +import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtraceFacade; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Glue code necessary for Honeycomb distribution to pick up the plugin classes + */ +public final class VppIoamModule extends AbstractModule { + + private static final Logger LOG = LoggerFactory.getLogger(VppIoamModule.class); + private final Class> jvppIoamProviderClass; + + public VppIoamModule() { + this(JVppIoamProvider.class); + } + + @VisibleForTesting + VppIoamModule(Class> jvppIoamProvider) { + this.jvppIoamProviderClass = jvppIoamProvider; + } + + @Override + protected void configure() { + LOG.debug("Installing iOAM module"); + + // Bind to Plugin's JVPP. + bind(FutureJVppIoamtrace.class).toProvider(jvppIoamProviderClass).in(Singleton.class); + + // Below are classes picked up by HC framework + Multibinder.newSetBinder(binder(), WriterFactory.class).addBinding().to(VppIoamWriterFactory.class); + + LOG.debug("Module iOAM successfully configured"); + } +} diff --git a/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/config/IoamTraceWriterCustomizer.java b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/config/IoamTraceWriterCustomizer.java new file mode 100755 index 000000000..bab92fc5d --- /dev/null +++ b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/config/IoamTraceWriterCustomizer.java @@ -0,0 +1,131 @@ +/* + * 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 io.fd.hc2vpp.vppioam.impl.config; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +import io.fd.hc2vpp.vppioam.impl.util.FutureJVppIoamCustomizer; +import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; + +import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAdd; +import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAddReply; +import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileDel; +import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileDelReply; +import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace; + +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.IoamTraceConfig; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig.TraceOp; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.trace.config.NodeInterfaces; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfigKey; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.trace.config.NodeInterfaces; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Writer customizer responsible for Ioam Trace create/delete. + */ +public class IoamTraceWriterCustomizer extends FutureJVppIoamCustomizer + implements ListWriterCustomizer, ByteDataTranslator, JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(IoamTraceWriterCustomizer.class); + + public IoamTraceWriterCustomizer(@Nonnull final FutureJVppIoamtrace futureJVppIoam) { + super(futureJVppIoam); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final TraceConfig dataCurr, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + + try { + addTraceConfig(dataCurr, writeContext, id); + } catch (Exception exCreate) { + LOG.error("Add Trace Configuration failed", exCreate); + throw new WriteFailedException.CreateFailedException(id, dataCurr, exCreate); + } + + LOG.debug("Trace config added iid={}, added {}", id, dataCurr); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final TraceConfig dataBefore, + @Nonnull final TraceConfig dataAfter, + @Nonnull final WriteContext ctx) throws WriteFailedException { + try { + deleteTraceConfig(dataBefore, id); + addTraceConfig(dataAfter, ctx, id); + } catch (Exception exUpdate) { + LOG.error("Update Trace Configuration failed", exUpdate); + throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, exUpdate); + } + + LOG.debug("Trace config updated {}", dataAfter); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final TraceConfig dataBefore, + @Nonnull final WriteContext ctx) throws WriteFailedException { + try { + deleteTraceConfig(dataBefore, id); + } catch (Exception exDelete) { + LOG.error("Delete Trace Configuration failed", exDelete); + throw new WriteFailedException.DeleteFailedException(id, exDelete); + } + + LOG.debug("Trace config deleted:iid={} dataBefore={}", id, dataBefore); + } + + public TraceProfileAddReply addTraceConfig(TraceConfig traceConfig, + WriteContext ctx, + final InstanceIdentifier id) throws Exception { + + TraceProfileAdd traceProfileAdd = new TraceProfileAdd(); + traceProfileAdd.traceType = (byte) traceConfig.getTraceType().byteValue(); //trace type + traceProfileAdd.numElts = (byte) traceConfig.getTraceNumElt().byteValue(); //num of elts + traceProfileAdd.traceTsp = (byte) traceConfig.getTraceTsp().getIntValue(); // tsp + traceProfileAdd.appData = (int) traceConfig.getTraceAppData().intValue(); // appdata + traceProfileAdd.nodeId = (int) traceConfig.getNodeId().intValue(); // nodeid + + /* Write to VPP */ + final TraceProfileAddReply reply = getReplyForWrite((getFutureJVppIoam(). + traceProfileAdd(traceProfileAdd). + toCompletableFuture()), id); + return reply; + } + + public TraceProfileDelReply deleteTraceConfig(TraceConfig dataBefore, + final InstanceIdentifier id) throws Exception { + TraceProfileDel del = new TraceProfileDel(); + + /* Write to VPP */ + TraceProfileDelReply reply = getReplyForWrite((getFutureJVppIoam(). + traceProfileDel(del).toCompletableFuture()), id); + + return reply; + } +} diff --git a/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/config/VppIoamWriterFactory.java b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/config/VppIoamWriterFactory.java new file mode 100755 index 000000000..a5773956c --- /dev/null +++ b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/config/VppIoamWriterFactory.java @@ -0,0 +1,46 @@ +/* + * 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 io.fd.hc2vpp.vppioam.impl.config; + +import com.google.inject.Inject; +import io.fd.honeycomb.translate.impl.write.GenericListWriter; +import io.fd.honeycomb.translate.write.WriterFactory; +import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.IoamTraceConfig; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace; + +public class VppIoamWriterFactory implements WriterFactory { + + @Nonnull + private final FutureJVppIoamtrace jvppIoam; + + @Inject + public VppIoamWriterFactory(@Nonnull final FutureJVppIoamtrace jvppIoam) { + this.jvppIoam = jvppIoam; + } + + @Override + public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) { + // TraceConfig + final InstanceIdentifier trId = + InstanceIdentifier.create(IoamTraceConfig.class).child(TraceConfig.class); + registry.add(new GenericListWriter<>(trId, new IoamTraceWriterCustomizer(jvppIoam))); + } +} diff --git a/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/util/FutureJVppIoamCustomizer.java b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/util/FutureJVppIoamCustomizer.java new file mode 100755 index 000000000..a93ea379c --- /dev/null +++ b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/util/FutureJVppIoamCustomizer.java @@ -0,0 +1,45 @@ +/* + * 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 io.fd.hc2vpp.vppioam.impl.util; + +import com.google.common.annotations.Beta; +import com.google.common.base.Preconditions; +import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace; +import javax.annotation.Nonnull; + +/** + * Abstract utility to hold the IoamApi reference. + */ +@Beta +public abstract class FutureJVppIoamCustomizer { + + private final FutureJVppIoamtrace futureJVppIoam; + + public FutureJVppIoamCustomizer(@Nonnull final FutureJVppIoamtrace futureJVppIoam) { + this.futureJVppIoam = Preconditions.checkNotNull(futureJVppIoam, + "futureJVppIoam should not be null"); + } + + /** + * Get IoamApi reference + * + * @return IoamApi reference + */ + public FutureJVppIoamtrace getFutureJVppIoam() { + return futureJVppIoam; + } +} diff --git a/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/util/JVppIoamProvider.java b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/util/JVppIoamProvider.java new file mode 100755 index 000000000..a34715ca6 --- /dev/null +++ b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/util/JVppIoamProvider.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2016 Cisco and 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.vppioam.impl.util; + +import com.google.inject.Inject; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import java.io.IOException; +import io.fd.vpp.jvpp.JVppRegistry; +import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtraceFacade; +import io.fd.vpp.jvpp.ioamtrace.JVppIoamtraceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Provides future API for jvpp-ioam plugin. Must be a singleton due to shutdown hook usage. + * Registers shutdown hook to free plugin's resources on shutdown. + */ +public final class JVppIoamProvider extends ProviderTrait { + + private static final Logger LOG = LoggerFactory.getLogger(JVppIoamProvider.class); + + @Inject + private JVppRegistry registry; + + @Override + protected FutureJVppIoamtraceFacade create() { + try { + final JVppIoamtraceImpl jVppIoamTr = new JVppIoamtraceImpl(); + // Free jvpp-ioam plugin's resources on shutdown + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + LOG.info("Unloading jvpp-ioam plugin"); + jVppIoamTr.close(); + LOG.info("Successfully unloaded jvpp-ioam plugin"); + } + }); + + LOG.debug("Successfully loaded jvpp-ioam plugin"); + return new FutureJVppIoamtraceFacade(registry, jVppIoamTr); + } catch (IOException e) { + throw new IllegalStateException("Unable to open VPP management connection", e); + } + } +} + diff --git a/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/VppIoamModule.java b/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/VppIoamModule.java deleted file mode 100755 index 34975d71d..000000000 --- a/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/VppIoamModule.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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 io.fd.honeycomb.vppioam.impl; - -import com.google.common.annotations.VisibleForTesting; -import com.google.inject.AbstractModule; -import com.google.inject.Singleton; -import com.google.inject.multibindings.Multibinder; -import com.google.inject.name.Names; -import com.google.inject.Provider; -import io.fd.honeycomb.data.init.DataTreeInitializer; -import io.fd.honeycomb.translate.read.ReaderFactory; -import io.fd.honeycomb.translate.write.WriterFactory; -import io.fd.honeycomb.vppioam.impl.config.VppIoamWriterFactory; -import io.fd.honeycomb.vppioam.impl.util.JVppIoamProvider; -import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace; -import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtraceFacade; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Glue code necessary for Honeycomb distribution to pick up the plugin classes - */ -public final class VppIoamModule extends AbstractModule { - - private static final Logger LOG = LoggerFactory.getLogger(VppIoamModule.class); - private final Class> jvppIoamProviderClass; - - public VppIoamModule() { - this(JVppIoamProvider.class); - } - - @VisibleForTesting - VppIoamModule(Class> jvppIoamProvider) { - this.jvppIoamProviderClass = jvppIoamProvider; - } - - @Override - protected void configure() { - LOG.debug("Installing iOAM module"); - - // Bind to Plugin's JVPP. - bind(FutureJVppIoamtrace.class).toProvider(jvppIoamProviderClass).in(Singleton.class); - - // Below are classes picked up by HC framework - Multibinder.newSetBinder(binder(), WriterFactory.class).addBinding().to(VppIoamWriterFactory.class); - - LOG.debug("Module iOAM successfully configured"); - } -} diff --git a/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/config/IoamTraceWriterCustomizer.java b/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/config/IoamTraceWriterCustomizer.java deleted file mode 100755 index 8a45e87df..000000000 --- a/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/config/IoamTraceWriterCustomizer.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * 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 io.fd.honeycomb.vppioam.impl.config; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - -import io.fd.honeycomb.translate.MappingContext; -import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; -import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator; -import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer; -import io.fd.honeycomb.translate.vpp.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.honeycomb.vppioam.impl.util.FutureJVppIoamCustomizer; - -import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAdd; -import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAddReply; -import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileDel; -import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileDelReply; -import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace; - -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.IoamTraceConfig; -import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig; -import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig.TraceOp; -import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.trace.config.NodeInterfaces; -import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfigKey; -import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.trace.config.NodeInterfaces; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Writer customizer responsible for Ioam Trace create/delete. - */ -public class IoamTraceWriterCustomizer extends FutureJVppIoamCustomizer - implements ListWriterCustomizer, ByteDataTranslator, JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(IoamTraceWriterCustomizer.class); - - public IoamTraceWriterCustomizer(@Nonnull final FutureJVppIoamtrace futureJVppIoam) { - super(futureJVppIoam); - } - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final TraceConfig dataCurr, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - - try { - addTraceConfig(dataCurr, writeContext, id); - } catch (Exception exCreate) { - LOG.error("Add Trace Configuration failed", exCreate); - throw new WriteFailedException.CreateFailedException(id, dataCurr, exCreate); - } - - LOG.debug("Trace config added iid={}, added {}", id, dataCurr); - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final TraceConfig dataBefore, - @Nonnull final TraceConfig dataAfter, - @Nonnull final WriteContext ctx) throws WriteFailedException { - try { - deleteTraceConfig(dataBefore, id); - addTraceConfig(dataAfter, ctx, id); - } catch (Exception exUpdate) { - LOG.error("Update Trace Configuration failed", exUpdate); - throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, exUpdate); - } - - LOG.debug("Trace config updated {}", dataAfter); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final TraceConfig dataBefore, - @Nonnull final WriteContext ctx) throws WriteFailedException { - try { - deleteTraceConfig(dataBefore, id); - } catch (Exception exDelete) { - LOG.error("Delete Trace Configuration failed", exDelete); - throw new WriteFailedException.DeleteFailedException(id, exDelete); - } - - LOG.debug("Trace config deleted:iid={} dataBefore={}", id, dataBefore); - } - - public TraceProfileAddReply addTraceConfig(TraceConfig traceConfig, - WriteContext ctx, - final InstanceIdentifier id) throws Exception { - - TraceProfileAdd traceProfileAdd = new TraceProfileAdd(); - traceProfileAdd.traceType = (byte) traceConfig.getTraceType().byteValue(); //trace type - traceProfileAdd.numElts = (byte) traceConfig.getTraceNumElt().byteValue(); //num of elts - traceProfileAdd.traceTsp = (byte) traceConfig.getTraceTsp().getIntValue(); // tsp - traceProfileAdd.appData = (int) traceConfig.getTraceAppData().intValue(); // appdata - traceProfileAdd.nodeId = (int) traceConfig.getNodeId().intValue(); // nodeid - - /* Write to VPP */ - final TraceProfileAddReply reply = getReplyForWrite((getFutureJVppIoam(). - traceProfileAdd(traceProfileAdd). - toCompletableFuture()), id); - return reply; - } - - public TraceProfileDelReply deleteTraceConfig(TraceConfig dataBefore, - final InstanceIdentifier id) throws Exception { - TraceProfileDel del = new TraceProfileDel(); - - /* Write to VPP */ - TraceProfileDelReply reply = getReplyForWrite((getFutureJVppIoam(). - traceProfileDel(del).toCompletableFuture()), id); - - return reply; - } -} diff --git a/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/config/VppIoamWriterFactory.java b/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/config/VppIoamWriterFactory.java deleted file mode 100755 index 40311cd8c..000000000 --- a/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/config/VppIoamWriterFactory.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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 io.fd.honeycomb.vppioam.impl.config; - -import com.google.common.collect.Sets; -import com.google.inject.Inject; -import com.google.inject.name.Named; -import io.fd.honeycomb.translate.impl.write.GenericListWriter; -import io.fd.honeycomb.translate.vpp.util.NamingContext; -import io.fd.honeycomb.translate.write.WriterFactory; -import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.IoamTraceConfig; -import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace; - -public class VppIoamWriterFactory implements WriterFactory { - - @Nonnull - private final FutureJVppIoamtrace jvppIoam; - - @Inject - public VppIoamWriterFactory(@Nonnull final FutureJVppIoamtrace jvppIoam) { - this.jvppIoam = jvppIoam; - } - - @Override - public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) { - // TraceConfig - final InstanceIdentifier trId = - InstanceIdentifier.create(IoamTraceConfig.class).child(TraceConfig.class); - registry.add(new GenericListWriter<>(trId, new IoamTraceWriterCustomizer(jvppIoam))); - } -} diff --git a/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/util/FutureJVppIoamCustomizer.java b/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/util/FutureJVppIoamCustomizer.java deleted file mode 100755 index b60581a1b..000000000 --- a/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/util/FutureJVppIoamCustomizer.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 io.fd.honeycomb.vppioam.impl.util; - -import com.google.common.annotations.Beta; -import com.google.common.base.Preconditions; -import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace; -import javax.annotation.Nonnull; - -/** - * Abstract utility to hold the IoamApi reference. - */ -@Beta -public abstract class FutureJVppIoamCustomizer { - - private final FutureJVppIoamtrace futureJVppIoam; - - public FutureJVppIoamCustomizer(@Nonnull final FutureJVppIoamtrace futureJVppIoam) { - this.futureJVppIoam = Preconditions.checkNotNull(futureJVppIoam, - "futureJVppIoam should not be null"); - } - - /** - * Get IoamApi reference - * - * @return IoamApi reference - */ - public FutureJVppIoamtrace getFutureJVppIoam() { - return futureJVppIoam; - } -} diff --git a/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/util/JVppIoamProvider.java b/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/util/JVppIoamProvider.java deleted file mode 100755 index d95266457..000000000 --- a/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/util/JVppIoamProvider.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and 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.honeycomb.vppioam.impl.util; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import io.fd.honeycomb.infra.distro.ProviderTrait; -import java.io.IOException; -import io.fd.vpp.jvpp.JVppRegistry; -import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace; -import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtraceFacade; -import io.fd.vpp.jvpp.ioamtrace.JVppIoamtraceImpl; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Provides future API for jvpp-ioam plugin. Must be a singleton due to shutdown hook usage. - * Registers shutdown hook to free plugin's resources on shutdown. - */ -public final class JVppIoamProvider extends ProviderTrait { - - private static final Logger LOG = LoggerFactory.getLogger(JVppIoamProvider.class); - - @Inject - private JVppRegistry registry; - - @Override - protected FutureJVppIoamtraceFacade create() { - try { - final JVppIoamtraceImpl jVppIoamTr = new JVppIoamtraceImpl(); - // Free jvpp-ioam plugin's resources on shutdown - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - LOG.info("Unloading jvpp-ioam plugin"); - jVppIoamTr.close(); - LOG.info("Successfully unloaded jvpp-ioam plugin"); - } - }); - - LOG.debug("Successfully loaded jvpp-ioam plugin"); - return new FutureJVppIoamtraceFacade(registry, jVppIoamTr); - } catch (IOException e) { - throw new IllegalStateException("Unable to open VPP management connection", e); - } - } -} - diff --git a/ioam/impl/src/test/java/io/fd/hc2vpp/vppioam/impl/VppIoamModuleTest.java b/ioam/impl/src/test/java/io/fd/hc2vpp/vppioam/impl/VppIoamModuleTest.java new file mode 100644 index 000000000..b1af9d5b2 --- /dev/null +++ b/ioam/impl/src/test/java/io/fd/hc2vpp/vppioam/impl/VppIoamModuleTest.java @@ -0,0 +1,90 @@ +/* + * 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 io.fd.hc2vpp.vppioam.impl; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.Matchers.empty; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +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.name.Named; +import com.google.inject.testing.fieldbinder.Bind; +import com.google.inject.testing.fieldbinder.BoundFieldModule; +import io.fd.honeycomb.translate.impl.write.registry.FlatWriterRegistryBuilder; +import io.fd.honeycomb.translate.write.WriterFactory; +import java.util.HashSet; +import java.util.Set; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; + +import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtraceFacade; +import io.fd.vpp.jvpp.JVppRegistry; + + +public class VppIoamModuleTest { + + @Named("honeycomb-context") + @Bind + @Mock + private DataBroker honeycombContext; + + @Named("honeycomb-initializer") + @Bind + @Mock + private DataBroker honeycombInitializer; + + @Bind + @Mock + private JVppRegistry registry; + + @Inject + private Set writerFactories = new HashSet<>(); + + @Before + public void setUp() throws Exception { + + initMocks(this); + + Guice.createInjector(new VppIoamModule(MockJVppIoamProvider.class), BoundFieldModule.of(this)).injectMembers(this); + } + + @Test + public void testWriterFactories() throws Exception { + assertThat(writerFactories, is(not(empty()))); + + final FlatWriterRegistryBuilder registryBuilder = new FlatWriterRegistryBuilder(); + writerFactories.forEach(factory -> factory.init(registryBuilder)); + assertNotNull(registryBuilder.build()); + } + + private static final class MockJVppIoamProvider implements Provider { + + @Override + public FutureJVppIoamtraceFacade get() { + return mock(FutureJVppIoamtraceFacade.class); + } + } +} + diff --git a/ioam/impl/src/test/java/io/fd/hc2vpp/vppioam/impl/config/IoamTraceWriterCustomizerTest.java b/ioam/impl/src/test/java/io/fd/hc2vpp/vppioam/impl/config/IoamTraceWriterCustomizerTest.java new file mode 100644 index 000000000..9f5290c6f --- /dev/null +++ b/ioam/impl/src/test/java/io/fd/hc2vpp/vppioam/impl/config/IoamTraceWriterCustomizerTest.java @@ -0,0 +1,181 @@ +/* + * 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 io.fd.hc2vpp.vppioam.impl.config; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAdd; +import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAddReply; +import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileDel; +import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileDelReply; +import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace; + +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.IoamTraceConfig; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig.TraceTsp; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfigBuilder; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig.TraceOp; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.trace.config.NodeInterfaces; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfigKey; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.trace.config.NodeInterfaces; + + +public class IoamTraceWriterCustomizerTest extends WriterCustomizerTest { + + private static final String TRACE_NAME = "trace_test"; + + @Mock + protected FutureJVppIoamtrace jvppIoam; + + private IoamTraceWriterCustomizer customizer; + + @Override + public void setUp() throws Exception { + customizer = new IoamTraceWriterCustomizer(jvppIoam); + } + + private static TraceConfig generateTraceConfig(final String name) { + final TraceConfigBuilder builder = new TraceConfigBuilder(); + builder.setTraceConfigName(name); + builder.setKey(new TraceConfigKey(name)); + builder.setAclName(name); + builder.setTraceType(new Short("31")); + builder.setTraceNumElt(new Short("4")); + builder.setTraceTsp(TraceTsp.Milliseconds); + builder.setTraceOp(TraceOp.Add); + builder.setTraceAppData(new Long("123")); + builder.setNodeId(new Long("1")); + + return builder.build(); + } + + private static InstanceIdentifier getTraceConfigId(final String name) { + return InstanceIdentifier.create(IoamTraceConfig.class) + .child(TraceConfig.class, new TraceConfigKey(name)); + } + + private void whenTraceAddThenSuccess() { + final TraceProfileAddReply reply = new TraceProfileAddReply(); + reply.context = 1; + doReturn(future(reply)).when(jvppIoam).traceProfileAdd(any(TraceProfileAdd.class)); + } + + private void whenTraceAddThenFailure() { + doReturn(failedFuture()).when(jvppIoam).traceProfileAdd(any(TraceProfileAdd.class)); + } + + private void whenTraceDelThenSuccess() { + final TraceProfileDelReply reply = new TraceProfileDelReply(); + reply.context = 1; + doReturn(future(reply)).when(jvppIoam).traceProfileDel(any(TraceProfileDel.class)); + } + + private void whenTraceDelThenFailure() { + doReturn(failedFuture()).when(jvppIoam).traceProfileDel(any(TraceProfileDel.class)); + } + + private static TraceProfileAdd generateTraceProfileAdd() { + final TraceProfileAdd request = new TraceProfileAdd(); + request.traceType = 0x1f; + request.numElts = 4; + request.nodeId = 1; + request.traceTsp = 1; + request.appData = 123; + + return request; + } + + private static TraceProfileDel generateTraceProfileDel() { + final TraceProfileDel request = new TraceProfileDel(); + + return request; + } + + @Test + public void testCreate() throws Exception { + final TraceConfig traceConfig = generateTraceConfig(TRACE_NAME); + final InstanceIdentifier id = getTraceConfigId(TRACE_NAME); + + whenTraceAddThenSuccess(); + + customizer.writeCurrentAttributes(id, traceConfig, writeContext); + + verify(jvppIoam).traceProfileAdd(generateTraceProfileAdd()); + } + + @Test + public void testCreateFailed() throws Exception { + final TraceConfig traceConfig = generateTraceConfig(TRACE_NAME); + final InstanceIdentifier id = getTraceConfigId(TRACE_NAME); + + whenTraceAddThenFailure(); + + try { + customizer.writeCurrentAttributes(id, traceConfig, writeContext); + } catch (WriteFailedException e) { + //assertTrue(e.getCause() instanceof VppBaseCallException); + verify(jvppIoam).traceProfileAdd(generateTraceProfileAdd()); + + return; + } + fail("WriteFailedException.CreateFailedException was expected"); + } + + @Test + public void testDelete() throws Exception { + + final TraceConfig traceConfig = generateTraceConfig(TRACE_NAME); + final InstanceIdentifier id = getTraceConfigId(TRACE_NAME); + + whenTraceDelThenSuccess(); + + customizer.deleteCurrentAttributes(id, traceConfig, writeContext); + + verify(jvppIoam).traceProfileDel(generateTraceProfileDel()); + } + + @Test + public void testDeleteFailed() throws Exception { + + final TraceConfig traceConfig = generateTraceConfig(TRACE_NAME); + final InstanceIdentifier id = getTraceConfigId(TRACE_NAME); + + whenTraceDelThenFailure(); + + try { + customizer.deleteCurrentAttributes(id, traceConfig, writeContext); + } catch (WriteFailedException e) { + //assertTrue(e.getCause() instanceof VppBaseCallException); + verify(jvppIoam).traceProfileDel(generateTraceProfileDel()); + + return; + } + fail("WriteFailedException.DeleteFailedException was expected"); + + customizer.deleteCurrentAttributes(id, traceConfig, writeContext); + } +} diff --git a/ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/VppIoamModuleTest.java b/ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/VppIoamModuleTest.java deleted file mode 100644 index d9176d39d..000000000 --- a/ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/VppIoamModuleTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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 io.fd.honeycomb.vppioam.impl; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -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.name.Named; -import com.google.inject.testing.fieldbinder.Bind; -import com.google.inject.testing.fieldbinder.BoundFieldModule; -import io.fd.honeycomb.translate.impl.write.registry.FlatWriterRegistryBuilder; -import io.fd.honeycomb.translate.write.WriterFactory; -import java.util.HashSet; -import java.util.Set; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; - -import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtraceFacade; -import io.fd.vpp.jvpp.JVppRegistry; - - -public class VppIoamModuleTest { - - @Named("honeycomb-context") - @Bind - @Mock - private DataBroker honeycombContext; - - @Named("honeycomb-initializer") - @Bind - @Mock - private DataBroker honeycombInitializer; - - @Bind - @Mock - private JVppRegistry registry; - - @Inject - private Set writerFactories = new HashSet<>(); - - @Before - public void setUp() throws Exception { - - initMocks(this); - - Guice.createInjector(new VppIoamModule(MockJVppIoamProvider.class), BoundFieldModule.of(this)).injectMembers(this); - } - - @Test - public void testWriterFactories() throws Exception { - assertThat(writerFactories, is(not(empty()))); - - final FlatWriterRegistryBuilder registryBuilder = new FlatWriterRegistryBuilder(); - writerFactories.forEach(factory -> factory.init(registryBuilder)); - assertNotNull(registryBuilder.build()); - } - - private static final class MockJVppIoamProvider implements Provider { - - @Override - public FutureJVppIoamtraceFacade get() { - return mock(FutureJVppIoamtraceFacade.class); - } - } -} - diff --git a/ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/config/IoamTraceWriterCustomizerTest.java b/ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/config/IoamTraceWriterCustomizerTest.java deleted file mode 100644 index 8c182dd01..000000000 --- a/ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/config/IoamTraceWriterCustomizerTest.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * 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 io.fd.honeycomb.vppioam.impl.config; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.honeycomb.translate.vpp.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAdd; -import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAddReply; -import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileDel; -import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileDelReply; -import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace; -import io.fd.vpp.jvpp.VppBaseCallException; -import io.fd.vpp.jvpp.VppCallbackException; - -import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.IoamTraceConfig; -import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig; -import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig.TraceTsp; -import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfigBuilder; -import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig.TraceOp; -import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.trace.config.NodeInterfaces; -import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfigKey; -import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.trace.config.NodeInterfaces; - - -public class IoamTraceWriterCustomizerTest extends WriterCustomizerTest { - - private static final String TRACE_NAME = "trace_test"; - - @Mock - protected FutureJVppIoamtrace jvppIoam; - - private IoamTraceWriterCustomizer customizer; - - @Override - public void setUp() throws Exception { - customizer = new IoamTraceWriterCustomizer(jvppIoam); - } - - private static TraceConfig generateTraceConfig(final String name) { - final TraceConfigBuilder builder = new TraceConfigBuilder(); - builder.setTraceConfigName(name); - builder.setKey(new TraceConfigKey(name)); - builder.setAclName(name); - builder.setTraceType(new Short("31")); - builder.setTraceNumElt(new Short("4")); - builder.setTraceTsp(TraceTsp.Milliseconds); - builder.setTraceOp(TraceOp.Add); - builder.setTraceAppData(new Long("123")); - builder.setNodeId(new Long("1")); - - return builder.build(); - } - - private static InstanceIdentifier getTraceConfigId(final String name) { - return InstanceIdentifier.create(IoamTraceConfig.class) - .child(TraceConfig.class, new TraceConfigKey(name)); - } - - private void whenTraceAddThenSuccess() { - final TraceProfileAddReply reply = new TraceProfileAddReply(); - reply.context = 1; - doReturn(future(reply)).when(jvppIoam).traceProfileAdd(any(TraceProfileAdd.class)); - } - - private void whenTraceAddThenFailure() { - doReturn(failedFuture()).when(jvppIoam).traceProfileAdd(any(TraceProfileAdd.class)); - } - - private void whenTraceDelThenSuccess() { - final TraceProfileDelReply reply = new TraceProfileDelReply(); - reply.context = 1; - doReturn(future(reply)).when(jvppIoam).traceProfileDel(any(TraceProfileDel.class)); - } - - private void whenTraceDelThenFailure() { - doReturn(failedFuture()).when(jvppIoam).traceProfileDel(any(TraceProfileDel.class)); - } - - private static TraceProfileAdd generateTraceProfileAdd() { - final TraceProfileAdd request = new TraceProfileAdd(); - request.traceType = 0x1f; - request.numElts = 4; - request.nodeId = 1; - request.traceTsp = 1; - request.appData = 123; - - return request; - } - - private static TraceProfileDel generateTraceProfileDel() { - final TraceProfileDel request = new TraceProfileDel(); - - return request; - } - - @Test - public void testCreate() throws Exception { - final TraceConfig traceConfig = generateTraceConfig(TRACE_NAME); - final InstanceIdentifier id = getTraceConfigId(TRACE_NAME); - - whenTraceAddThenSuccess(); - - customizer.writeCurrentAttributes(id, traceConfig, writeContext); - - verify(jvppIoam).traceProfileAdd(generateTraceProfileAdd()); - } - - @Test - public void testCreateFailed() throws Exception { - final TraceConfig traceConfig = generateTraceConfig(TRACE_NAME); - final InstanceIdentifier id = getTraceConfigId(TRACE_NAME); - - whenTraceAddThenFailure(); - - try { - customizer.writeCurrentAttributes(id, traceConfig, writeContext); - } catch (WriteFailedException e) { - //assertTrue(e.getCause() instanceof VppBaseCallException); - verify(jvppIoam).traceProfileAdd(generateTraceProfileAdd()); - - return; - } - fail("WriteFailedException.CreateFailedException was expected"); - } - - @Test - public void testDelete() throws Exception { - - final TraceConfig traceConfig = generateTraceConfig(TRACE_NAME); - final InstanceIdentifier id = getTraceConfigId(TRACE_NAME); - - whenTraceDelThenSuccess(); - - customizer.deleteCurrentAttributes(id, traceConfig, writeContext); - - verify(jvppIoam).traceProfileDel(generateTraceProfileDel()); - } - - @Test - public void testDeleteFailed() throws Exception { - - final TraceConfig traceConfig = generateTraceConfig(TRACE_NAME); - final InstanceIdentifier id = getTraceConfigId(TRACE_NAME); - - whenTraceDelThenFailure(); - - try { - customizer.deleteCurrentAttributes(id, traceConfig, writeContext); - } catch (WriteFailedException e) { - //assertTrue(e.getCause() instanceof VppBaseCallException); - verify(jvppIoam).traceProfileDel(generateTraceProfileDel()); - - return; - } - fail("WriteFailedException.DeleteFailedException was expected"); - - customizer.deleteCurrentAttributes(id, traceConfig, writeContext); - } -} -- cgit 1.2.3-korg