diff options
Diffstat (limited to 'ioam/impl/src/main')
5 files changed, 215 insertions, 6 deletions
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 index 204d003c9..228653c1c 100755 --- 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 @@ -20,12 +20,15 @@ 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.vppioam.impl.oper.VppIoamReaderFactory; -import io.fd.honeycomb.translate.read.ReaderFactory; -import io.fd.honeycomb.translate.write.WriterFactory; import io.fd.hc2vpp.vppioam.impl.config.VppIoamWriterFactory; +import io.fd.hc2vpp.vppioam.impl.oper.VppIoamReaderFactory; +import io.fd.hc2vpp.vppioam.impl.util.JVppIoamExportProvider; import io.fd.hc2vpp.vppioam.impl.util.JVppIoamPotProvider; import io.fd.hc2vpp.vppioam.impl.util.JVppIoamTraceProvider; +import io.fd.honeycomb.translate.read.ReaderFactory; +import io.fd.honeycomb.translate.write.WriterFactory; +import io.fd.vpp.jvpp.ioamexport.future.FutureJVppIoamexport; +import io.fd.vpp.jvpp.ioamexport.future.FutureJVppIoamexportFacade; import io.fd.vpp.jvpp.ioampot.future.FutureJVppIoampot; import io.fd.vpp.jvpp.ioampot.future.FutureJVppIoampotFacade; import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace; @@ -41,16 +44,19 @@ public final class VppIoamModule extends AbstractModule { private static final Logger LOG = LoggerFactory.getLogger(VppIoamModule.class); private final Class<? extends Provider<FutureJVppIoamtraceFacade>> jvppIoamTraceProviderClass; private final Class<? extends Provider<FutureJVppIoampotFacade>> jvppIoamPotProviderClass; + private final Class<? extends Provider<FutureJVppIoamexportFacade>> jvppIoamExportProviderClass; public VppIoamModule() { - this(JVppIoamTraceProvider.class, JVppIoamPotProvider.class); + this(JVppIoamTraceProvider.class, JVppIoamPotProvider.class, JVppIoamExportProvider.class); } @VisibleForTesting VppIoamModule(Class<? extends Provider<FutureJVppIoamtraceFacade>> jvppIoamTraceProvider, - Class<? extends Provider<FutureJVppIoampotFacade>> jvppIoamPotProviderClass) { + Class<? extends Provider<FutureJVppIoampotFacade>> jvppIoamPotProviderClass, + Class<? extends Provider<FutureJVppIoamexportFacade>> jvppIoamExportProviderClass) { this.jvppIoamTraceProviderClass = jvppIoamTraceProvider; this.jvppIoamPotProviderClass = jvppIoamPotProviderClass; + this.jvppIoamExportProviderClass = jvppIoamExportProviderClass; } @Override @@ -60,6 +66,7 @@ public final class VppIoamModule extends AbstractModule { // Bind to Plugin's JVPP. bind(FutureJVppIoamtrace.class).toProvider(jvppIoamTraceProviderClass).in(Singleton.class); bind(FutureJVppIoampot.class).toProvider(jvppIoamPotProviderClass).in(Singleton.class); + bind(FutureJVppIoamexport.class).toProvider(jvppIoamExportProviderClass).in(Singleton.class); // Below are classes picked up by HC framework Multibinder.newSetBinder(binder(), WriterFactory.class).addBinding().to(VppIoamWriterFactory.class); diff --git a/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/config/IoamExportWriterCustomizer.java b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/config/IoamExportWriterCustomizer.java new file mode 100644 index 000000000..2172750d4 --- /dev/null +++ b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/config/IoamExportWriterCustomizer.java @@ -0,0 +1,95 @@ +/* + * 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.config; + +import io.fd.hc2vpp.common.translate.util.Ipv4Translator; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.vppioam.impl.util.FutureJVppIoamexportCustomizer; +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.ioamexport.dto.IoamExportIp6EnableDisable; +import io.fd.vpp.jvpp.ioamexport.dto.IoamExportIp6EnableDisableReply; +import io.fd.vpp.jvpp.ioamexport.future.FutureJVppIoamexport; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.export.rev170206.IoamExport; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class IoamExportWriterCustomizer extends FutureJVppIoamexportCustomizer + implements WriterCustomizer<IoamExport>, JvppReplyConsumer, Ipv4Translator { + + private static final Logger LOG = LoggerFactory.getLogger(IoamExportWriterCustomizer.class); + + public IoamExportWriterCustomizer(FutureJVppIoamexport jVppIoamexport){ + super(jVppIoamexport); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<IoamExport> instanceIdentifier, + @Nonnull final IoamExport ioamExport, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + addExportProfile(ioamExport,instanceIdentifier); + LOG.info("Export profile {} created, id: {}", ioamExport, instanceIdentifier); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<IoamExport> instanceIdentifier, + @Nonnull final IoamExport dataBefore, @Nonnull final IoamExport dataAfter, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + addExportProfile(dataAfter,instanceIdentifier); + LOG.info("Export profile {} updated , id: {}", dataAfter, instanceIdentifier); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<IoamExport> instanceIdentifier, + @Nonnull final IoamExport ioamExport, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + deleteExportProfile(ioamExport,instanceIdentifier); + LOG.info("Export profile {} deleted, id: {}", ioamExport, instanceIdentifier); + } + + private IoamExportIp6EnableDisableReply addExportProfile(IoamExport ioamExport, InstanceIdentifier<IoamExport> id) + throws WriteFailedException { + IoamExportIp6EnableDisable request = new IoamExportIp6EnableDisable(); + if (ioamExport.isDisable()==null) + request.isDisable = 1; + else + request.isDisable = (byte)(ioamExport.isDisable()?1:0); + request.srcAddress = ipv4AddressNoZoneToArray(ioamExport.getSourceAddress().getValue()); + request.collectorAddress = ipv4AddressNoZoneToArray(ioamExport.getCollectorAddress().getValue()); + return getReplyForCreate(getFutureJVppIoamexport() + .ioamExportIp6EnableDisable(request) + .toCompletableFuture(),id,ioamExport); + + } + + private IoamExportIp6EnableDisableReply deleteExportProfile(IoamExport ioamExport, + InstanceIdentifier<IoamExport> id) + throws WriteFailedException { + IoamExportIp6EnableDisable request = new IoamExportIp6EnableDisable(); + request.isDisable = 1; //disable when deleted + request.srcAddress = ipv4AddressNoZoneToArray(ioamExport.getSourceAddress().getValue()); + request.collectorAddress = ipv4AddressNoZoneToArray(ioamExport.getCollectorAddress().getValue()); + + return getReplyForDelete(getFutureJVppIoamexport() + .ioamExportIp6EnableDisable(request) + .toCompletableFuture(),id); + } + +} 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 index 15d312ff7..ba105eb39 100755 --- 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 @@ -19,11 +19,14 @@ package io.fd.hc2vpp.vppioam.impl.config; import com.google.common.collect.Sets; import com.google.inject.Inject; import io.fd.honeycomb.translate.impl.write.GenericListWriter; +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.ioamexport.future.FutureJVppIoamexport; import io.fd.vpp.jvpp.ioampot.future.FutureJVppIoampot; 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.export.rev170206.IoamExport; 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.trace.config.NodeInterfaces; @@ -38,12 +41,16 @@ public class VppIoamWriterFactory implements WriterFactory { private final FutureJVppIoamtrace jVppIoamtrace; @Nonnull private final FutureJVppIoampot jVppIoampot; + @Nonnull + private final FutureJVppIoamexport jVppIoamexport; @Inject public VppIoamWriterFactory(@Nonnull final FutureJVppIoamtrace jVppIoamtrace, - @Nonnull final FutureJVppIoampot jVppIoampot) { + @Nonnull final FutureJVppIoampot jVppIoampot, + @Nonnull final FutureJVppIoamexport jVppIoamexport) { this.jVppIoamtrace = jVppIoamtrace; this.jVppIoampot = jVppIoampot; + this.jVppIoamexport = jVppIoamexport; } @Override @@ -60,6 +67,10 @@ public class VppIoamWriterFactory implements WriterFactory { registry.subtreeAdd(Sets.newHashSet(InstanceIdentifier.create(PotProfileSet.class) .child(PotProfileList.class)), new GenericListWriter<>(potId, new IoamPotWriterCustomizer(jVppIoampot))); + //Export Config + final InstanceIdentifier<IoamExport> exportId = + InstanceIdentifier.create(IoamExport.class); + registry.add(new GenericWriter<>(exportId,new IoamExportWriterCustomizer(jVppIoamexport))); } } diff --git a/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/util/FutureJVppIoamexportCustomizer.java b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/util/FutureJVppIoamexportCustomizer.java new file mode 100644 index 000000000..adc2ffc10 --- /dev/null +++ b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/util/FutureJVppIoamexportCustomizer.java @@ -0,0 +1,41 @@ +/* + * 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.common.base.Preconditions; +import io.fd.vpp.jvpp.ioamexport.future.FutureJVppIoamexport; +import javax.annotation.Nonnull; + +public abstract class FutureJVppIoamexportCustomizer { + + private final FutureJVppIoamexport futureJVppIoamexport; + + public FutureJVppIoamexportCustomizer (@Nonnull final FutureJVppIoamexport futureJVppIoamexport) { + this.futureJVppIoamexport = Preconditions.checkNotNull(futureJVppIoamexport, + "futureJVppIoamexport should not be null"); + } + + /** + * Get Ioam POT Api reference + * + * @return Ioam POT Api reference + */ + public FutureJVppIoamexport getFutureJVppIoamexport() { + return futureJVppIoamexport; + } + +} diff --git a/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/util/JVppIoamExportProvider.java b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/util/JVppIoamExportProvider.java new file mode 100644 index 000000000..fa4d20004 --- /dev/null +++ b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/util/JVppIoamExportProvider.java @@ -0,0 +1,55 @@ +/* + * 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 io.fd.vpp.jvpp.JVppRegistry; +import io.fd.vpp.jvpp.ioamexport.JVppIoamexportImpl; +import io.fd.vpp.jvpp.ioamexport.future.FutureJVppIoamexportFacade; +import java.io.IOException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class JVppIoamExportProvider extends ProviderTrait<FutureJVppIoamexportFacade> { + + private static final Logger LOG = LoggerFactory.getLogger(JVppIoamExportProvider.class); + + @Inject + private JVppRegistry registry; + + @Override + protected FutureJVppIoamexportFacade create() { + try { + final JVppIoamexportImpl jVppIoamexport = new JVppIoamexportImpl(); + // Free jvpp-ioam-export plugin's resources on shutdown + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + LOG.info("Unloading jvpp-ioam-export plugin"); + jVppIoamexport.close(); + LOG.info("Successfully unloaded jvpp-ioam-export plugin"); + } + }); + + LOG.info("Successfully loaded jvpp-ioam-export plugin"); + return new FutureJVppIoamexportFacade(registry, jVppIoamexport); + } catch (IOException e) { + throw new IllegalStateException("Unable to open VPP management connection", e); + } + } +} |