diff options
Diffstat (limited to 'lisp/lisp2vpp/src/main/java/io/fd')
35 files changed, 472 insertions, 184 deletions
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/LispModule.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/LispModule.java index 5e674f52b..5324eec2d 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/LispModule.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/LispModule.java @@ -36,6 +36,8 @@ import io.fd.hc2vpp.lisp.translate.read.factory.LispStateReaderFactory; import io.fd.hc2vpp.lisp.translate.read.factory.LocatorSetReaderFactory; import io.fd.hc2vpp.lisp.translate.read.factory.MapResolverReaderFactory; import io.fd.hc2vpp.lisp.translate.read.factory.MapServerReaderFactory; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckServiceImpl; import io.fd.hc2vpp.lisp.translate.write.factory.EidTableWriterFactory; import io.fd.hc2vpp.lisp.translate.write.factory.LispWriterFactory; import io.fd.hc2vpp.lisp.translate.write.factory.LocatorSetWriterFactory; @@ -98,6 +100,8 @@ public class LispModule extends AbstractModule { final Multibinder<ReaderFactory> readerBinder = Multibinder.newSetBinder(binder(), ReaderFactory.class); readerBinder.addBinding().toProvider(ContextsReaderFactoryProvider.class).in(Singleton.class); + bind(LispStateCheckService.class).to(LispStateCheckServiceImpl.class).in(Singleton.class); + LOG.info("Module Lisp successfully configured"); } } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/AbstractLispInfraFactoryBase.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/AbstractLispInfraFactoryBase.java index 022ea19ed..5d2904cb5 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/AbstractLispInfraFactoryBase.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/AbstractLispInfraFactoryBase.java @@ -27,16 +27,16 @@ import com.google.inject.name.Named; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.lisp.context.util.AdjacenciesMappingContext; import io.fd.hc2vpp.lisp.context.util.EidMappingContext; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; import io.fd.honeycomb.translate.impl.write.GenericWriter; import io.fd.honeycomb.translate.spi.write.WriterCustomizer; import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.Lisp; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.LispState; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import javax.annotation.Nonnull; - /** * Basic attributes for lisp writer factories @@ -74,6 +74,9 @@ public abstract class AbstractLispInfraFactoryBase { @Named(ADJACENCIES_IDENTIFICATION_CONTEXT) protected AdjacenciesMappingContext adjacenciesMappingContext; + @Inject + protected LispStateCheckService lispStateCheckService; + @Nonnull protected <D extends DataObject> GenericWriter<D> writer(@Nonnull final InstanceIdentifier<D> type, @Nonnull final WriterCustomizer<D> customizer) { diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/ItrRemoteLocatorSetCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/ItrRemoteLocatorSetCustomizer.java index 2c82b9ad4..5799bd9c3 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/ItrRemoteLocatorSetCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/ItrRemoteLocatorSetCustomizer.java @@ -17,11 +17,14 @@ package io.fd.hc2vpp.lisp.translate.read; +import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS; + import com.google.common.base.Optional; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.lisp.translate.read.init.LispInitPathsMapper; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.hc2vpp.lisp.translate.util.CheckedLispCustomizer; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; @@ -31,25 +34,27 @@ import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager.DumpCacheManag import io.fd.vpp.jvpp.core.dto.LispGetMapRequestItrRlocs; import io.fd.vpp.jvpp.core.dto.LispGetMapRequestItrRlocsReply; import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.itr.remote.locator.sets.grouping.ItrRemoteLocatorSet; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.itr.remote.locator.sets.grouping.ItrRemoteLocatorSetBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.lisp.feature.data.grouping.LispFeatureDataBuilder; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import javax.annotation.Nonnull; - -import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS; - -public class ItrRemoteLocatorSetCustomizer extends FutureJVppCustomizer +public class ItrRemoteLocatorSetCustomizer extends CheckedLispCustomizer implements InitializingReaderCustomizer<ItrRemoteLocatorSet, ItrRemoteLocatorSetBuilder>, ByteDataTranslator, JvppReplyConsumer, LispInitPathsMapper { + private static final Logger LOG = LoggerFactory.getLogger(ItrRemoteLocatorSetCustomizer.class); + private final DumpCacheManager<LispGetMapRequestItrRlocsReply, Void> dumpCacheManager; - public ItrRemoteLocatorSetCustomizer(@Nonnull final FutureJVppCore futureJVppCore) { - super(futureJVppCore); + public ItrRemoteLocatorSetCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final LispStateCheckService lispStateCheckService) { + super(futureJVppCore, lispStateCheckService); dumpCacheManager = new DumpCacheManagerBuilder<LispGetMapRequestItrRlocsReply, Void>() .withExecutor(((identifier, params) -> getReplyForRead( futureJVppCore.lispGetMapRequestItrRlocs(new LispGetMapRequestItrRlocs()).toCompletableFuture(), @@ -69,6 +74,11 @@ public class ItrRemoteLocatorSetCustomizer extends FutureJVppCustomizer @Nonnull final ItrRemoteLocatorSetBuilder builder, @Nonnull final ReadContext ctx) throws ReadFailedException { + if (!lispStateCheckService.lispEnabled(ctx)) { + LOG.info("Lisp feature must be enabled first"); + return; + } + final Optional<LispGetMapRequestItrRlocsReply> reply = dumpCacheManager.getDump(id, ctx.getModificationCache(), NO_PARAMS); if (!reply.isPresent() || reply.get().locatorSetName == null) { diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/LocatorSetCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/LocatorSetCustomizer.java index 4b176fc75..4e23347c9 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/LocatorSetCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/LocatorSetCustomizer.java @@ -16,12 +16,16 @@ package io.fd.hc2vpp.lisp.translate.read; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS; + import com.google.common.base.Optional; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.lisp.translate.read.init.LispInitPathsMapper; import io.fd.hc2vpp.lisp.translate.read.trait.LocatorSetReader; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.hc2vpp.lisp.translate.util.CheckedLispCustomizer; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; @@ -30,6 +34,10 @@ import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; import io.fd.vpp.jvpp.core.dto.LispLocatorSetDetails; import io.fd.vpp.jvpp.core.dto.LispLocatorSetDetailsReplyDump; import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.locator.sets.grouping.LocatorSetsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.locator.sets.grouping.locator.sets.LocatorSet; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.locator.sets.grouping.locator.sets.LocatorSetBuilder; @@ -40,15 +48,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.Nonnull; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import static com.google.common.base.Preconditions.checkNotNull; -import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS; - -public class LocatorSetCustomizer extends FutureJVppCustomizer +public class LocatorSetCustomizer extends CheckedLispCustomizer implements InitializingListReaderCustomizer<LocatorSet, LocatorSetKey, LocatorSetBuilder>, ByteDataTranslator, LocatorSetReader, LispInitPathsMapper { @@ -58,8 +58,9 @@ public class LocatorSetCustomizer extends FutureJVppCustomizer private final NamingContext locatorSetContext; public LocatorSetCustomizer(@Nonnull final FutureJVppCore futureJvpp, - @Nonnull final NamingContext locatorSetContext) { - super(futureJvpp); + @Nonnull final NamingContext locatorSetContext, + @Nonnull final LispStateCheckService lispStateCheckService) { + super(futureJvpp, lispStateCheckService); this.locatorSetContext = checkNotNull(locatorSetContext, "Locator Set mapping context cannot be null"); this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder<LispLocatorSetDetailsReplyDump, Void>() .withExecutor(createExecutor(futureJvpp)) @@ -76,6 +77,10 @@ public class LocatorSetCustomizer extends FutureJVppCustomizer @Override public void readCurrentAttributes(InstanceIdentifier<LocatorSet> id, LocatorSetBuilder builder, ReadContext ctx) throws ReadFailedException { + if (!lispStateCheckService.lispEnabled(ctx)) { + LOG.info("Lisp feature must be enabled first"); + return; + } LOG.debug("Reading attributes for Locator Set {}", id); final Optional<LispLocatorSetDetailsReplyDump> dumpOptional = @@ -105,6 +110,11 @@ public class LocatorSetCustomizer extends FutureJVppCustomizer @Override public List<LocatorSetKey> getAllIds(InstanceIdentifier<LocatorSet> id, ReadContext context) throws ReadFailedException { + if (!lispStateCheckService.lispEnabled(context)) { + LOG.info("Lisp feature must be enabled first"); + return Collections.emptyList(); + } + LOG.debug("Dumping Locator Set {}", id); final Optional<LispLocatorSetDetailsReplyDump> dumpOptional = diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/MapRegisterCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/MapRegisterCustomizer.java index e94bb92f0..808f53eff 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/MapRegisterCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/MapRegisterCustomizer.java @@ -17,9 +17,10 @@ package io.fd.hc2vpp.lisp.translate.read; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.lisp.translate.read.init.LispInitPathsMapper; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.hc2vpp.lisp.translate.util.CheckedLispCustomizer; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; @@ -28,21 +29,24 @@ import io.fd.vpp.jvpp.core.dto.ShowLispMapRegisterState; import io.fd.vpp.jvpp.core.dto.ShowLispMapRegisterStateReply; import io.fd.vpp.jvpp.core.future.FutureJVppCore; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.Lisp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.lisp.feature.data.grouping.LispFeatureData; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.lisp.feature.data.grouping.LispFeatureDataBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.map.register.grouping.MapRegister; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.map.register.grouping.MapRegisterBuilder; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -public class MapRegisterCustomizer extends FutureJVppCustomizer +public class MapRegisterCustomizer extends CheckedLispCustomizer implements InitializingReaderCustomizer<MapRegister, MapRegisterBuilder>, ByteDataTranslator, JvppReplyConsumer, LispInitPathsMapper { - public MapRegisterCustomizer(@Nonnull FutureJVppCore futureJVppCore) { - super(futureJVppCore); + private static final Logger LOG = LoggerFactory.getLogger(MapRegisterCustomizer.class); + + public MapRegisterCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final LispStateCheckService lispStateCheckService) { + super(futureJVppCore, lispStateCheckService); } @Nonnull @@ -55,6 +59,11 @@ public class MapRegisterCustomizer extends FutureJVppCustomizer public void readCurrentAttributes(@Nonnull InstanceIdentifier<MapRegister> instanceIdentifier, @Nonnull MapRegisterBuilder mapRegisterBuilder, @Nonnull ReadContext readContext) throws ReadFailedException { + if (!lispStateCheckService.lispEnabled(readContext)) { + LOG.info("Lisp feature must be enabled first"); + return; + } + final ShowLispMapRegisterStateReply read = getReplyForRead(getFutureJVpp() .showLispMapRegisterState(new ShowLispMapRegisterState()).toCompletableFuture(), instanceIdentifier); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/MapRequestModeCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/MapRequestModeCustomizer.java index 9de5b5c68..267bc04c9 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/MapRequestModeCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/MapRequestModeCustomizer.java @@ -16,9 +16,10 @@ package io.fd.hc2vpp.lisp.translate.read; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.lisp.translate.read.init.LispInitPathsMapper; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.hc2vpp.lisp.translate.util.CheckedLispCustomizer; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; @@ -33,13 +34,18 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -public class MapRequestModeCustomizer extends FutureJVppCustomizer +public class MapRequestModeCustomizer extends CheckedLispCustomizer implements InitializingReaderCustomizer<MapRequestMode, MapRequestModeBuilder>, JvppReplyConsumer, LispInitPathsMapper { - public MapRequestModeCustomizer(@Nonnull FutureJVppCore futureJVppCore) { - super(futureJVppCore); + private static final Logger LOG = LoggerFactory.getLogger(MapRequestModeCustomizer.class); + + public MapRequestModeCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final LispStateCheckService lispStateCheckService) { + super(futureJVppCore, lispStateCheckService); } @Nonnull @@ -52,6 +58,10 @@ public class MapRequestModeCustomizer extends FutureJVppCustomizer public void readCurrentAttributes(@Nonnull InstanceIdentifier<MapRequestMode> instanceIdentifier, @Nonnull MapRequestModeBuilder mapRequestModeBuilder, @Nonnull ReadContext readContext) throws ReadFailedException { + if (!lispStateCheckService.lispEnabled(readContext)) { + LOG.info("Lisp feature must be enabled first"); + return; + } final ShowLispMapRequestModeReply reply = getReplyForRead( getFutureJVpp().showLispMapRequestMode(new ShowLispMapRequestMode()).toCompletableFuture(), instanceIdentifier); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/MapResolverCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/MapResolverCustomizer.java index ac947878b..199d1ff70 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/MapResolverCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/MapResolverCustomizer.java @@ -16,11 +16,14 @@ package io.fd.hc2vpp.lisp.translate.read; +import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS; + import com.google.common.base.Optional; import io.fd.hc2vpp.common.translate.util.AddressTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.lisp.translate.read.init.LispInitPathsMapper; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.hc2vpp.lisp.translate.util.CheckedLispCustomizer; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; @@ -31,6 +34,11 @@ import io.fd.vpp.jvpp.core.dto.LispMapResolverDetails; import io.fd.vpp.jvpp.core.dto.LispMapResolverDetailsReplyDump; import io.fd.vpp.jvpp.core.dto.LispMapResolverDump; import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.map.resolvers.grouping.MapResolvers; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.map.resolvers.grouping.MapResolversBuilder; @@ -43,15 +51,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.Nonnull; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS; - -public class MapResolverCustomizer extends FutureJVppCustomizer +public class MapResolverCustomizer extends CheckedLispCustomizer implements InitializingListReaderCustomizer<MapResolver, MapResolverKey, MapResolverBuilder>, AddressTranslator, JvppReplyConsumer, LispInitPathsMapper { @@ -59,8 +59,9 @@ public class MapResolverCustomizer extends FutureJVppCustomizer private final DumpCacheManager<LispMapResolverDetailsReplyDump, Void> dumpManager; - public MapResolverCustomizer(FutureJVppCore futureJvpp) { - super(futureJvpp); + public MapResolverCustomizer(@Nonnull final FutureJVppCore futureJvpp, + @Nonnull final LispStateCheckService lispStateCheckService) { + super(futureJvpp, lispStateCheckService); this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder<LispMapResolverDetailsReplyDump, Void>() .withExecutor((identifier, params) -> getReplyForRead( @@ -78,6 +79,10 @@ public class MapResolverCustomizer extends FutureJVppCustomizer @Override public void readCurrentAttributes(InstanceIdentifier<MapResolver> id, MapResolverBuilder builder, ReadContext ctx) throws ReadFailedException { + if (!lispStateCheckService.lispEnabled(ctx)) { + LOG.info("Lisp feature must be enabled first"); + return; + } LOG.debug("Reading attributes..."); final Optional<LispMapResolverDetailsReplyDump> dumpOptional = @@ -109,6 +114,10 @@ public class MapResolverCustomizer extends FutureJVppCustomizer @Override public List<MapResolverKey> getAllIds(InstanceIdentifier<MapResolver> id, ReadContext context) throws ReadFailedException { + if (!lispStateCheckService.lispEnabled(context)) { + LOG.info("Lisp feature must be enabled first"); + return Collections.emptyList(); + } LOG.debug("Dumping MapResolver..."); final Optional<LispMapResolverDetailsReplyDump> dumpOptional = @@ -131,7 +140,9 @@ public class MapResolverCustomizer extends FutureJVppCustomizer @Nonnull @Override - public Initialized<? extends DataObject> init(@Nonnull InstanceIdentifier<MapResolver> instanceIdentifier, @Nonnull MapResolver mapResolver, @Nonnull ReadContext readContext) { - return Initialized.create(lispFeaturesBasePath().child(MapResolvers.class).child(MapResolver.class, instanceIdentifier.firstKeyOf(MapResolver.class)), mapResolver); + public Initialized<? extends DataObject> init(@Nonnull InstanceIdentifier<MapResolver> instanceIdentifier, + @Nonnull MapResolver mapResolver, @Nonnull ReadContext readContext) { + return Initialized.create(lispFeaturesBasePath().child(MapResolvers.class) + .child(MapResolver.class, instanceIdentifier.firstKeyOf(MapResolver.class)), mapResolver); } } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/MapServerCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/MapServerCustomizer.java index 8e53f265d..bd4c0ba5d 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/MapServerCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/MapServerCustomizer.java @@ -20,8 +20,9 @@ import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PA import com.google.common.base.Optional; import io.fd.hc2vpp.common.translate.util.AddressTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.hc2vpp.lisp.translate.util.CheckedLispCustomizer; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; @@ -49,15 +50,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -public class MapServerCustomizer extends FutureJVppCustomizer +public class MapServerCustomizer extends CheckedLispCustomizer implements InitializingListReaderCustomizer<MapServer, MapServerKey, MapServerBuilder>, JvppReplyConsumer, AddressTranslator { + private static final Logger LOG = LoggerFactory.getLogger(MapServerCustomizer.class); + private final DumpCacheManager<LispMapServerDetailsReplyDump, Void> dumpManager; - public MapServerCustomizer(@Nonnull FutureJVppCore futureJVppCore) { - super(futureJVppCore); + public MapServerCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final LispStateCheckService lispStateCheckService) { + super(futureJVppCore, lispStateCheckService); dumpManager = new DumpCacheManagerBuilder<LispMapServerDetailsReplyDump, Void>() .acceptOnly(LispMapServerDetailsReplyDump.class) .withExecutor((instanceIdentifier, aVoid) -> @@ -83,6 +89,10 @@ public class MapServerCustomizer extends FutureJVppCustomizer @Override public List<MapServerKey> getAllIds(@Nonnull InstanceIdentifier<MapServer> instanceIdentifier, @Nonnull ReadContext readContext) throws ReadFailedException { + if (!lispStateCheckService.lispEnabled(readContext)) { + LOG.info("Lisp feature must be enabled first"); + return Collections.emptyList(); + } final Optional<LispMapServerDetailsReplyDump> dump = dumpManager.getDump(instanceIdentifier, readContext.getModificationCache(), NO_PARAMS); @@ -112,6 +122,10 @@ public class MapServerCustomizer extends FutureJVppCustomizer public void readCurrentAttributes(@Nonnull InstanceIdentifier<MapServer> instanceIdentifier, @Nonnull MapServerBuilder mapServerBuilder, @Nonnull ReadContext readContext) throws ReadFailedException { + if (!lispStateCheckService.lispEnabled(readContext)) { + LOG.info("Lisp feature must be enabled first"); + return; + } final Optional<LispMapServerDetailsReplyDump> dump = dumpManager.getDump(instanceIdentifier, readContext.getModificationCache(), NO_PARAMS); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/PetrCfgCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/PetrCfgCustomizer.java index 0e27a0ee8..da8f35743 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/PetrCfgCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/PetrCfgCustomizer.java @@ -17,9 +17,10 @@ package io.fd.hc2vpp.lisp.translate.read; import io.fd.hc2vpp.common.translate.util.AddressTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.lisp.translate.read.init.LispInitPathsMapper; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.hc2vpp.lisp.translate.util.CheckedLispCustomizer; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; @@ -34,13 +35,18 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -public class PetrCfgCustomizer extends FutureJVppCustomizer +public class PetrCfgCustomizer extends CheckedLispCustomizer implements InitializingReaderCustomizer<PetrCfg, PetrCfgBuilder>, JvppReplyConsumer, AddressTranslator, LispInitPathsMapper { - public PetrCfgCustomizer(@Nonnull FutureJVppCore futureJVppCore) { - super(futureJVppCore); + private static final Logger LOG = LoggerFactory.getLogger(PetrCfgCustomizer.class); + + public PetrCfgCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final LispStateCheckService lispStateCheckService) { + super(futureJVppCore, lispStateCheckService); } @Nonnull @@ -61,11 +67,15 @@ public class PetrCfgCustomizer extends FutureJVppCustomizer public void readCurrentAttributes(@Nonnull InstanceIdentifier<PetrCfg> instanceIdentifier, @Nonnull PetrCfgBuilder petrCfgBuilder, @Nonnull ReadContext readContext) throws ReadFailedException { + if (!lispStateCheckService.lispEnabled(readContext)) { + LOG.info("Lisp feature must be enabled first"); + return; + } + final ShowLispUsePetrReply read = getReplyForRead(getFutureJVpp().showLispUsePetr(new ShowLispUsePetr()) .toCompletableFuture(), instanceIdentifier); if (read != null && read.status != 0) { - // TODO - https://jira.fd.io/browse/VPP-660 - returns address back in bad form petrCfgBuilder.setPetrAddress(arrayToIpAddress(!byteToBoolean(read.isIp4), read.address)); } } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/PitrCfgCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/PitrCfgCustomizer.java index c7c966f77..6e807ad36 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/PitrCfgCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/PitrCfgCustomizer.java @@ -18,9 +18,10 @@ package io.fd.hc2vpp.lisp.translate.read; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.lisp.translate.read.init.LispInitPathsMapper; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.hc2vpp.lisp.translate.util.CheckedLispCustomizer; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; @@ -29,6 +30,8 @@ import io.fd.vpp.jvpp.VppBaseCallException; import io.fd.vpp.jvpp.core.dto.ShowLispPitr; import io.fd.vpp.jvpp.core.dto.ShowLispPitrReply; import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.concurrent.TimeoutException; +import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.lisp.feature.data.grouping.LispFeatureDataBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.pitr.cfg.grouping.PitrCfg; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.pitr.cfg.grouping.PitrCfgBuilder; @@ -38,21 +41,19 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.Nonnull; -import java.util.concurrent.TimeoutException; - /** * Customizer for reading {@link PitrCfg}<br> Currently unsupported in jvpp */ -public class PitrCfgCustomizer extends FutureJVppCustomizer +public class PitrCfgCustomizer extends CheckedLispCustomizer implements InitializingReaderCustomizer<PitrCfg, PitrCfgBuilder>, ByteDataTranslator, JvppReplyConsumer, LispInitPathsMapper { private static final Logger LOG = LoggerFactory.getLogger(PitrCfgCustomizer.class); - public PitrCfgCustomizer(FutureJVppCore futureJvpp) { - super(futureJvpp); + public PitrCfgCustomizer(@Nonnull final FutureJVppCore futureJvpp, + @Nonnull final LispStateCheckService lispStateCheckService) { + super(futureJvpp, lispStateCheckService); } @Override @@ -63,6 +64,10 @@ public class PitrCfgCustomizer extends FutureJVppCustomizer @Override public void readCurrentAttributes(InstanceIdentifier<PitrCfg> id, PitrCfgBuilder builder, ReadContext ctx) throws ReadFailedException { + if (!lispStateCheckService.lispEnabled(ctx)) { + LOG.info("Lisp feature must be enabled first"); + return; + } LOG.debug("Reading status for Lisp Pitr node {}", id); ShowLispPitrReply reply; diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/RlocProbeCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/RlocProbeCustomizer.java index bd0070141..0cd5b857f 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/RlocProbeCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/RlocProbeCustomizer.java @@ -17,9 +17,10 @@ package io.fd.hc2vpp.lisp.translate.read; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.lisp.translate.read.init.LispInitPathsMapper; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.hc2vpp.lisp.translate.util.CheckedLispCustomizer; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; @@ -34,13 +35,18 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -public class RlocProbeCustomizer extends FutureJVppCustomizer +public class RlocProbeCustomizer extends CheckedLispCustomizer implements InitializingReaderCustomizer<RlocProbe, RlocProbeBuilder>, JvppReplyConsumer, ByteDataTranslator, LispInitPathsMapper { - public RlocProbeCustomizer(@Nonnull FutureJVppCore futureJVppCore) { - super(futureJVppCore); + private static final Logger LOG = LoggerFactory.getLogger(RlocProbeCustomizer.class); + + public RlocProbeCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final LispStateCheckService lispStateCheckService) { + super(futureJVppCore, lispStateCheckService); } @Nonnull @@ -53,6 +59,11 @@ public class RlocProbeCustomizer extends FutureJVppCustomizer public void readCurrentAttributes(@Nonnull InstanceIdentifier<RlocProbe> instanceIdentifier, @Nonnull RlocProbeBuilder rlocProbeBuilder, @Nonnull ReadContext readContext) throws ReadFailedException { + if (!lispStateCheckService.lispEnabled(readContext)) { + LOG.info("Lisp feature must be enabled first"); + return; + } + final ShowLispRlocProbeStateReply read = getReplyForRead(getFutureJVpp() .showLispRlocProbeState(new ShowLispRlocProbeState()).toCompletableFuture(), instanceIdentifier); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/VniTableCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/VniTableCustomizer.java index 3dfb6d6aa..56e60c231 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/VniTableCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/VniTableCustomizer.java @@ -16,9 +16,13 @@ package io.fd.hc2vpp.lisp.translate.read; +import static com.google.common.base.Preconditions.checkState; +import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS; + import com.google.common.base.Optional; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.hc2vpp.lisp.translate.util.CheckedLispCustomizer; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; @@ -29,6 +33,10 @@ import io.fd.vpp.jvpp.core.dto.LispEidTableVniDetails; import io.fd.vpp.jvpp.core.dto.LispEidTableVniDetailsReplyDump; import io.fd.vpp.jvpp.core.dto.LispEidTableVniDump; import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.Lisp; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.eid.table.grouping.EidTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.eid.table.grouping.EidTableBuilder; @@ -43,26 +51,19 @@ import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.Nonnull; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import static com.google.common.base.Preconditions.checkState; -import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS; - /** * Handles the reads of {@link VniTable} nodes */ -public class VniTableCustomizer extends FutureJVppCustomizer +public class VniTableCustomizer extends CheckedLispCustomizer implements InitializingListReaderCustomizer<VniTable, VniTableKey, VniTableBuilder>, JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(VniTableCustomizer.class); private final DumpCacheManager<LispEidTableVniDetailsReplyDump, Void> dumpManager; - public VniTableCustomizer(@Nonnull final FutureJVppCore futureJvpp) { - super(futureJvpp); + public VniTableCustomizer(@Nonnull final FutureJVppCore futureJvpp, + @Nonnull final LispStateCheckService lispStateCheckService) { + super(futureJvpp, lispStateCheckService); this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder<LispEidTableVniDetailsReplyDump, Void>() .withExecutor(((identifier, params) -> getReplyForRead( futureJvpp.lispEidTableVniDump(new LispEidTableVniDump()).toCompletableFuture(), identifier))) @@ -91,6 +92,10 @@ public class VniTableCustomizer extends FutureJVppCustomizer public List<VniTableKey> getAllIds(@Nonnull final InstanceIdentifier<VniTable> id, @Nonnull final ReadContext context) throws ReadFailedException { + if (!lispStateCheckService.lispEnabled(context)) { + LOG.info("Lisp feature must be enabled first"); + return Collections.emptyList(); + } LOG.trace("Reading all IDS..."); final Optional<LispEidTableVniDetailsReplyDump> optionalReply = @@ -108,6 +113,10 @@ public class VniTableCustomizer extends FutureJVppCustomizer public void readCurrentAttributes(@Nonnull final InstanceIdentifier<VniTable> id, @Nonnull final VniTableBuilder builder, @Nonnull final ReadContext ctx) throws ReadFailedException { + if (!lispStateCheckService.lispEnabled(ctx)) { + LOG.info("Lisp feature must be enabled first"); + return; + } checkState(id.firstKeyOf(VniTable.class) != null, "No VNI present"); VniTableKey key = new VniTableKey(id.firstKeyOf(VniTable.class).getVirtualNetworkIdentifier()); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/EidTableReaderFactory.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/EidTableReaderFactory.java index 325be4836..be99d4fac 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/EidTableReaderFactory.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/EidTableReaderFactory.java @@ -19,11 +19,17 @@ package io.fd.hc2vpp.lisp.translate.read.factory; import com.google.common.collect.ImmutableSet; import io.fd.hc2vpp.lisp.translate.AbstractLispInfraFactoryBase; -import io.fd.hc2vpp.lisp.translate.read.*; +import io.fd.hc2vpp.lisp.translate.read.AdjacencyCustomizer; +import io.fd.hc2vpp.lisp.translate.read.BridgeDomainSubtableCustomizer; +import io.fd.hc2vpp.lisp.translate.read.LocalMappingCustomizer; +import io.fd.hc2vpp.lisp.translate.read.RemoteMappingCustomizer; +import io.fd.hc2vpp.lisp.translate.read.VniTableCustomizer; +import io.fd.hc2vpp.lisp.translate.read.VrfSubtableCustomizer; import io.fd.honeycomb.translate.impl.read.GenericInitListReader; import io.fd.honeycomb.translate.impl.read.GenericInitReader; import io.fd.honeycomb.translate.read.ReaderFactory; import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; +import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.adjacencies.grouping.Adjacencies; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.adjacencies.grouping.AdjacenciesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.adjacencies.grouping.adjacencies.Adjacency; @@ -47,8 +53,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.lisp.feature.data.grouping.LispFeatureData; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import javax.annotation.Nonnull; - /** * Factory that produces {@code Reader} for {@code EidTable}<br> with all its inhired child readers @@ -71,7 +75,7 @@ public final class EidTableReaderFactory extends AbstractLispInfraFactoryBase im //EidTable registry.addStructuralReader(EID_TABLE_IID, EidTableBuilder.class); //EidTable -> VniTable - registry.add(new GenericInitListReader<>(VNI_TABLE_IID, new VniTableCustomizer(vppApi))); + registry.add(new GenericInitListReader<>(VNI_TABLE_IID, new VniTableCustomizer(vppApi, lispStateCheckService))); //EidTable -> VniTable -> VrfSubtable registry.add(new GenericInitReader<>(VRF_SUBTABLE_IID, new VrfSubtableCustomizer(vppApi))); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/LispStateReaderFactory.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/LispStateReaderFactory.java index b7bd37588..7757d0822 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/LispStateReaderFactory.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/LispStateReaderFactory.java @@ -54,18 +54,18 @@ public class LispStateReaderFactory extends AbstractLispInfraFactoryBase impleme registry.addStructuralReader(lispStateId.child(LispFeatureData.class), LispFeatureDataBuilder.class); registry.add(new GenericInitReader<>(LISP_FEATURE_ID.child(PitrCfg.class), - new PitrCfgCustomizer(vppApi))); + new PitrCfgCustomizer(vppApi, lispStateCheckService))); registry.add(new GenericInitReader<>(LISP_FEATURE_ID.child(RlocProbe.class), - new RlocProbeCustomizer(vppApi))); + new RlocProbeCustomizer(vppApi, lispStateCheckService))); registry.add(new GenericInitReader<>(LISP_FEATURE_ID.child(PetrCfg.class), - new PetrCfgCustomizer(vppApi))); + new PetrCfgCustomizer(vppApi, lispStateCheckService))); registry.add(new GenericInitReader<>(LISP_FEATURE_ID.child(MapRegister.class), - new MapRegisterCustomizer(vppApi))); + new MapRegisterCustomizer(vppApi, lispStateCheckService))); registry.add(new GenericInitReader<>(LISP_FEATURE_ID.child(MapRequestMode.class), - new MapRequestModeCustomizer(vppApi))); + new MapRequestModeCustomizer(vppApi, lispStateCheckService))); } } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/LocatorSetReaderFactory.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/LocatorSetReaderFactory.java index 17c41f304..75faf0b8f 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/LocatorSetReaderFactory.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/LocatorSetReaderFactory.java @@ -23,6 +23,7 @@ import io.fd.hc2vpp.lisp.translate.read.LocatorSetCustomizer; import io.fd.honeycomb.translate.impl.read.GenericInitListReader; import io.fd.honeycomb.translate.read.ReaderFactory; import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; +import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.lisp.feature.data.grouping.LispFeatureData; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.locator.sets.grouping.LocatorSets; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.locator.sets.grouping.LocatorSetsBuilder; @@ -30,8 +31,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.locator.sets.grouping.locator.sets.locator.set.Interface; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import javax.annotation.Nonnull; - /** * Produces reader for {@link LocatorSets} <br> and all its inhired child readers. @@ -48,7 +47,7 @@ public class LocatorSetReaderFactory extends AbstractLispInfraFactoryBase implem registry.addStructuralReader(locatorSetsInstanceIdentifier, LocatorSetsBuilder.class); registry.add(new GenericInitListReader<>(locatorSetInstanceIdentifier, - new LocatorSetCustomizer(vppApi, locatorSetContext))); + new LocatorSetCustomizer(vppApi, locatorSetContext, lispStateCheckService))); registry.add(new GenericInitListReader<>(locatorSetInstanceIdentifier.child(Interface.class), new InterfaceCustomizer(vppApi, interfaceContext, locatorSetContext))); } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/MapResolverReaderFactory.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/MapResolverReaderFactory.java index 2908770be..8b9fb3cb9 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/MapResolverReaderFactory.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/MapResolverReaderFactory.java @@ -22,14 +22,13 @@ import io.fd.hc2vpp.lisp.translate.read.MapResolverCustomizer; import io.fd.honeycomb.translate.impl.read.GenericInitListReader; import io.fd.honeycomb.translate.read.ReaderFactory; import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; +import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.lisp.feature.data.grouping.LispFeatureData; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.map.resolvers.grouping.MapResolvers; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.map.resolvers.grouping.MapResolversBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.map.resolvers.grouping.map.resolvers.MapResolver; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import javax.annotation.Nonnull; - /** * Builds reader for {@link MapResolvers}<br> and all its inhired child readers @@ -44,6 +43,6 @@ public class MapResolverReaderFactory extends AbstractLispInfraFactoryBase imple registry.addStructuralReader(mapResolversInstanceIdentifier, MapResolversBuilder.class); registry.add(new GenericInitListReader<>(mapResolversInstanceIdentifier.child(MapResolver.class), - new MapResolverCustomizer(vppApi))); + new MapResolverCustomizer(vppApi, lispStateCheckService))); } } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/MapServerReaderFactory.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/MapServerReaderFactory.java index 1af8f939f..e53cee3b3 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/MapServerReaderFactory.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/MapServerReaderFactory.java @@ -38,6 +38,6 @@ public class MapServerReaderFactory extends AbstractLispInfraFactoryBase impleme public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { registry.addStructuralReader(MAP_SERVERS_ID, MapServersBuilder.class); registry.add(new GenericInitListReader<>(MAP_SERVERS_ID.child(MapServer.class), - new MapServerCustomizer(vppApi))); + new MapServerCustomizer(vppApi, lispStateCheckService))); } } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckService.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckService.java new file mode 100644 index 000000000..ab0ea797c --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckService.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2017 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.lisp.translate.service; + +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.write.WriteContext; +import javax.annotation.Nonnull; + +/** + * Provides functionality to check whether lisp is enabled + */ +public interface LispStateCheckService { + + /** + * Checks whether lisp is enabled while operating inside {@link WriteContext} + */ + void checkLispEnabled(@Nonnull final WriteContext ctx); + + /** + * Checks whether lisp is enabled while operating inside {@link ReadContext} + */ + boolean lispEnabled(@Nonnull final ReadContext ctx); +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckServiceImpl.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckServiceImpl.java new file mode 100644 index 000000000..8d46e9bed --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckServiceImpl.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2017 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.lisp.translate.service; + +import static com.google.common.base.Preconditions.checkState; +import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS; + +import com.google.inject.Inject; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager.DumpCacheManagerBuilder; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.vpp.jvpp.core.dto.ShowLispStatus; +import io.fd.vpp.jvpp.core.dto.ShowLispStatusReply; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.Lisp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.LispBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public final class LispStateCheckServiceImpl implements LispStateCheckService, JvppReplyConsumer, ByteDataTranslator { + + private static final Lisp STATIC_LISP_INSTANCE = new LispBuilder().setEnable(false).build(); + private static final ShowLispStatusReply DEFAULT_REPLY = new ShowLispStatusReply(); + private static final InstanceIdentifier<Lisp> IDENTIFIER = InstanceIdentifier.create(Lisp.class); + + private final DumpCacheManager<ShowLispStatusReply, Void> dumpManager; + + @Inject + public LispStateCheckServiceImpl(@Nonnull final FutureJVppCore vppApi) { + dumpManager = new DumpCacheManagerBuilder<ShowLispStatusReply, Void>() + .withExecutor((instanceIdentifier, aVoid) -> getReplyForRead(vppApi.showLispStatus(new ShowLispStatus()) + .toCompletableFuture(), instanceIdentifier)) + .acceptOnly(ShowLispStatusReply.class) + .build(); + } + + public void checkLispEnabled(@Nonnull final WriteContext ctx) { + // no need to dump here, can be read directly from context + checkState(ctx.readAfter(InstanceIdentifier.create(Lisp.class)) + .or(STATIC_LISP_INSTANCE).isEnable(), "Lisp feature not enabled"); + } + + public boolean lispEnabled(@Nonnull final ReadContext ctx) { + // in this case it must be dumped + try { + return byteToBoolean(dumpManager.getDump(IDENTIFIER, ctx.getModificationCache(), NO_PARAMS) + .or(DEFAULT_REPLY).featureStatus); + } catch (ReadFailedException e) { + throw new IllegalStateException("Unable to read Lisp Feature status", e); + } + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/util/CheckedLispCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/util/CheckedLispCustomizer.java new file mode 100644 index 000000000..008e20c11 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/util/CheckedLispCustomizer.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2017 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.lisp.translate.util; + + +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; + +public abstract class CheckedLispCustomizer extends FutureJVppCustomizer { + + protected final LispStateCheckService lispStateCheckService; + + public CheckedLispCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final LispStateCheckService lispStateCheckService) { + super(futureJVppCore); + this.lispStateCheckService = lispStateCheckService; + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/ItrRemoteLocatorSetCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/ItrRemoteLocatorSetCustomizer.java index f4c36cfb3..71be3c749 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/ItrRemoteLocatorSetCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/ItrRemoteLocatorSetCustomizer.java @@ -17,26 +17,28 @@ package io.fd.hc2vpp.lisp.translate.write; -import io.fd.honeycomb.translate.spi.write.WriterCustomizer; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.hc2vpp.lisp.translate.util.CheckedLispCustomizer; +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.VppBaseCallException; +import io.fd.vpp.jvpp.core.dto.LispAddDelMapRequestItrRlocs; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; import java.nio.charset.StandardCharsets; import java.util.concurrent.TimeoutException; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.itr.remote.locator.sets.grouping.ItrRemoteLocatorSet; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.VppBaseCallException; -import io.fd.vpp.jvpp.core.dto.LispAddDelMapRequestItrRlocs; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -public class ItrRemoteLocatorSetCustomizer extends FutureJVppCustomizer implements +public class ItrRemoteLocatorSetCustomizer extends CheckedLispCustomizer implements WriterCustomizer<ItrRemoteLocatorSet>, ByteDataTranslator, JvppReplyConsumer { - public ItrRemoteLocatorSetCustomizer(@Nonnull final FutureJVppCore futureJVppCore) { - super(futureJVppCore); + public ItrRemoteLocatorSetCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final LispStateCheckService lispStateCheckService) { + super(futureJVppCore, lispStateCheckService); } @Override @@ -44,7 +46,7 @@ public class ItrRemoteLocatorSetCustomizer extends FutureJVppCustomizer implemen @Nonnull final ItrRemoteLocatorSet dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException { try { - addDelItrRemoteLocatorSet(true, dataAfter); + addDelItrRemoteLocatorSet(true, dataAfter, writeContext); } catch (TimeoutException | VppBaseCallException e) { throw new WriteFailedException.CreateFailedException(id, dataAfter, e); } @@ -64,14 +66,16 @@ public class ItrRemoteLocatorSetCustomizer extends FutureJVppCustomizer implemen @Nonnull final ItrRemoteLocatorSet dataBefore, @Nonnull final WriteContext writeContext) throws WriteFailedException { try { - addDelItrRemoteLocatorSet(false, dataBefore); + addDelItrRemoteLocatorSet(false, dataBefore, writeContext); } catch (TimeoutException | VppBaseCallException e) { throw new WriteFailedException.DeleteFailedException(id, e); } } - private void addDelItrRemoteLocatorSet(final boolean add, @Nonnull final ItrRemoteLocatorSet data) + private void addDelItrRemoteLocatorSet(final boolean add, @Nonnull final ItrRemoteLocatorSet data, + @Nonnull final WriteContext context) throws TimeoutException, VppBaseCallException { + lispStateCheckService.checkLispEnabled(context); LispAddDelMapRequestItrRlocs request = new LispAddDelMapRequestItrRlocs(); request.isAdd = booleanToByte(add); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizer.java index b83748236..5a606bc37 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizer.java @@ -22,10 +22,11 @@ import static java.nio.charset.StandardCharsets.UTF_8; import com.google.common.base.Optional; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.common.translate.util.ReferenceCheck; import io.fd.hc2vpp.lisp.translate.read.trait.LocatorSetReader; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.hc2vpp.lisp.translate.util.CheckedLispCustomizer; import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; @@ -54,15 +55,16 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; * * @see LocatorSet */ -public class LocatorSetCustomizer extends FutureJVppCustomizer +public class LocatorSetCustomizer extends CheckedLispCustomizer implements ListWriterCustomizer<LocatorSet, LocatorSetKey>, ByteDataTranslator, LocatorSetReader, ReferenceCheck { private final NamingContext locatorSetContext; public LocatorSetCustomizer(@Nonnull final FutureJVppCore futureJvpp, - @Nonnull final NamingContext locatorSetContext) { - super(futureJvpp); + @Nonnull final NamingContext locatorSetContext, + @Nonnull final LispStateCheckService lispStateCheckService) { + super(futureJvpp, lispStateCheckService); this.locatorSetContext = checkNotNull(locatorSetContext, "Locator set context cannot be null"); } @@ -70,6 +72,7 @@ public class LocatorSetCustomizer extends FutureJVppCustomizer public void writeCurrentAttributes(@Nonnull InstanceIdentifier<LocatorSet> id, @Nonnull LocatorSet dataAfter, @Nonnull WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabled(writeContext); checkState(isNonEmptyLocatorSet(writeContext.readAfter(id).get()), "Creating empty locator-sets is not allowed"); final String locatorSetName = dataAfter.getName(); @@ -96,6 +99,7 @@ public class LocatorSetCustomizer extends FutureJVppCustomizer public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<LocatorSet> id, @Nonnull LocatorSet dataBefore, @Nonnull WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabled(writeContext); final String locatorSetName = dataBefore.getName(); final Optional<EidTable> eidTableData = writeContext.readAfter(InstanceIdentifier.create(Lisp.class) diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRegisterCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRegisterCustomizer.java index 1dac298a3..298b14358 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRegisterCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRegisterCustomizer.java @@ -17,30 +17,31 @@ package io.fd.hc2vpp.lisp.translate.write; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.hc2vpp.lisp.translate.util.CheckedLispCustomizer; 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.LispMapRegisterEnableDisable; import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.map.register.grouping.MapRegister; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import javax.annotation.Nonnull; - -public class MapRegisterCustomizer extends FutureJVppCustomizer +public class MapRegisterCustomizer extends CheckedLispCustomizer implements WriterCustomizer<MapRegister>, ByteDataTranslator, JvppReplyConsumer { - public MapRegisterCustomizer(@Nonnull FutureJVppCore futureJVppCore) { - super(futureJVppCore); + public MapRegisterCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final LispStateCheckService lispStateCheckService) { + super(futureJVppCore, lispStateCheckService); } @Override public void writeCurrentAttributes(@Nonnull InstanceIdentifier<MapRegister> instanceIdentifier, @Nonnull MapRegister mapRegister, @Nonnull WriteContext writeContext) throws WriteFailedException { - enableDisableMapRegister(mapRegister.isEnabled(), instanceIdentifier); + enableDisableMapRegister(mapRegister.isEnabled(), instanceIdentifier, writeContext); } @Override @@ -48,17 +49,19 @@ public class MapRegisterCustomizer extends FutureJVppCustomizer @Nonnull MapRegister mapRegisterBefore, @Nonnull MapRegister mapRegisterAfter, @Nonnull WriteContext writeContext) throws WriteFailedException { - enableDisableMapRegister(mapRegisterAfter.isEnabled(), instanceIdentifier); + enableDisableMapRegister(mapRegisterAfter.isEnabled(), instanceIdentifier, writeContext); } @Override public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<MapRegister> instanceIdentifier, @Nonnull MapRegister mapRegister, @Nonnull WriteContext writeContext) throws WriteFailedException { - enableDisableMapRegister(false, instanceIdentifier); + enableDisableMapRegister(false, instanceIdentifier, writeContext); } - private void enableDisableMapRegister(final boolean enable, @Nonnull final InstanceIdentifier<MapRegister> id) throws WriteFailedException { + private void enableDisableMapRegister(final boolean enable, @Nonnull final InstanceIdentifier<MapRegister> id, + @Nonnull final WriteContext context) throws WriteFailedException { + lispStateCheckService.checkLispEnabled(context); LispMapRegisterEnableDisable request = new LispMapRegisterEnableDisable(); request.isEnabled = booleanToByte(enable); getReplyForWrite(getFutureJVpp().lispMapRegisterEnableDisable(request).toCompletableFuture(), id); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRequestModeCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRequestModeCustomizer.java index 0e069504d..d61cd0cfb 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRequestModeCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRequestModeCustomizer.java @@ -18,8 +18,9 @@ package io.fd.hc2vpp.lisp.translate.write; import static com.google.common.base.Preconditions.checkNotNull; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.hc2vpp.lisp.translate.util.CheckedLispCustomizer; import io.fd.honeycomb.translate.spi.write.WriterCustomizer; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; @@ -30,22 +31,20 @@ import java.util.concurrent.CompletableFuture; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.map.request.mode.grouping.MapRequestMode; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -public class MapRequestModeCustomizer extends FutureJVppCustomizer +public class MapRequestModeCustomizer extends CheckedLispCustomizer implements WriterCustomizer<MapRequestMode>, JvppReplyConsumer { - private static final Logger LOG = LoggerFactory.getLogger(MapRequestModeCustomizer.class); - - public MapRequestModeCustomizer(@Nonnull FutureJVppCore futureJVppCore) { - super(futureJVppCore); + public MapRequestModeCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final LispStateCheckService lispStateCheckService) { + super(futureJVppCore, lispStateCheckService); } @Override public void writeCurrentAttributes(@Nonnull InstanceIdentifier<MapRequestMode> instanceIdentifier, @Nonnull MapRequestMode mapRequestMode, @Nonnull WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabled(writeContext); getReplyForWrite(mapRequestModeRequestFuture(mapRequestMode), instanceIdentifier); } @@ -54,6 +53,7 @@ public class MapRequestModeCustomizer extends FutureJVppCustomizer @Nonnull MapRequestMode mapRequestModeBefore, @Nonnull MapRequestMode mapRequestModeAfter, @Nonnull WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabled(writeContext); getReplyForUpdate(mapRequestModeRequestFuture(mapRequestModeAfter), instanceIdentifier, mapRequestModeBefore, mapRequestModeAfter); } @@ -62,8 +62,7 @@ public class MapRequestModeCustomizer extends FutureJVppCustomizer public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<MapRequestMode> instanceIdentifier, @Nonnull MapRequestMode mapRequestMode, @Nonnull WriteContext writeContext) throws WriteFailedException { - //TODO - after HC2VPP-115 - change to throw UnsupportedOperationException - LOG.error("Map request mode cannot be deleted, ignoring"); + throw new UnsupportedOperationException("Map request mode cannot be deleted"); } private CompletableFuture<LispMapRequestModeReply> mapRequestModeRequestFuture( diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizer.java index 7873c8da9..94b45ae21 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizer.java @@ -18,38 +18,40 @@ package io.fd.hc2vpp.lisp.translate.write; import static com.google.common.base.Preconditions.checkNotNull; -import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; import io.fd.hc2vpp.common.translate.util.AddressTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.hc2vpp.lisp.translate.util.CheckedLispCustomizer; +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.VppBaseCallException; +import io.fd.vpp.jvpp.core.dto.LispAddDelMapResolver; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; import java.util.concurrent.TimeoutException; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.map.resolvers.grouping.map.resolvers.MapResolver; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.map.resolvers.grouping.map.resolvers.MapResolverKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.VppBaseCallException; -import io.fd.vpp.jvpp.core.dto.LispAddDelMapResolver; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; /** * Handles updates of {@link MapResolver} list */ -public class MapResolverCustomizer extends FutureJVppCustomizer +public class MapResolverCustomizer extends CheckedLispCustomizer implements ListWriterCustomizer<MapResolver, MapResolverKey>, AddressTranslator, JvppReplyConsumer { - public MapResolverCustomizer(final FutureJVppCore vppApi) { - super(vppApi); + public MapResolverCustomizer(@Nonnull final FutureJVppCore vppApi, + @Nonnull final LispStateCheckService lispStateCheckService) { + super(vppApi, lispStateCheckService); } @Override public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<MapResolver> id, @Nonnull final MapResolver dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException { - + lispStateCheckService.checkLispEnabled(writeContext); checkNotNull(dataAfter, "Data is null"); checkNotNull(dataAfter.getIpAddress(), "Address is null"); @@ -71,7 +73,7 @@ public class MapResolverCustomizer extends FutureJVppCustomizer public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<MapResolver> id, @Nonnull final MapResolver dataBefore, @Nonnull final WriteContext writeContext) throws WriteFailedException { - + lispStateCheckService.checkLispEnabled(writeContext); checkNotNull(dataBefore, "Data is null"); checkNotNull(dataBefore.getIpAddress(), "Address is null"); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapServerCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapServerCustomizer.java index 9697e16bc..ec2b3b37a 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapServerCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapServerCustomizer.java @@ -17,32 +17,34 @@ package io.fd.hc2vpp.lisp.translate.write; import io.fd.hc2vpp.common.translate.util.AddressTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.hc2vpp.lisp.translate.util.CheckedLispCustomizer; 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.LispAddDelMapServer; import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.map.servers.grouping.map.servers.MapServer; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.map.servers.grouping.map.servers.MapServerKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import javax.annotation.Nonnull; - -public class MapServerCustomizer extends FutureJVppCustomizer +public class MapServerCustomizer extends CheckedLispCustomizer implements ListWriterCustomizer<MapServer, MapServerKey>, AddressTranslator, JvppReplyConsumer { - public MapServerCustomizer(@Nonnull FutureJVppCore futureJVppCore) { - super(futureJVppCore); + public MapServerCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final LispStateCheckService lispStateCheckService) { + super(futureJVppCore, lispStateCheckService); } @Override public void writeCurrentAttributes(@Nonnull InstanceIdentifier<MapServer> instanceIdentifier, @Nonnull MapServer mapServer, @Nonnull WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabled(writeContext); addDelMapServer(true, instanceIdentifier, mapServer); } @@ -57,6 +59,7 @@ public class MapServerCustomizer extends FutureJVppCustomizer @Override public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<MapServer> instanceIdentifier, @Nonnull MapServer mapServer, @Nonnull WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabled(writeContext); addDelMapServer(false, instanceIdentifier, mapServer); } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PetrCfgCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PetrCfgCustomizer.java index d3a381490..728de8fca 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PetrCfgCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PetrCfgCustomizer.java @@ -16,34 +16,35 @@ package io.fd.hc2vpp.lisp.translate.write; +import static com.google.common.base.Preconditions.checkNotNull; + import io.fd.hc2vpp.common.translate.util.AddressTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.hc2vpp.lisp.translate.util.CheckedLispCustomizer; 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.LispUsePetr; import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; - import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.use.petr.cfg.grouping.PetrCfg; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import javax.annotation.Nonnull; - -import static com.google.common.base.Preconditions.checkNotNull; - -public class PetrCfgCustomizer extends FutureJVppCustomizer +public class PetrCfgCustomizer extends CheckedLispCustomizer implements WriterCustomizer<PetrCfg>, AddressTranslator, JvppReplyConsumer { - public PetrCfgCustomizer(@Nonnull FutureJVppCore futureJVppCore) { - super(futureJVppCore); + public PetrCfgCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final LispStateCheckService lispStateCheckService) { + super(futureJVppCore, lispStateCheckService); } @Override public void writeCurrentAttributes(@Nonnull InstanceIdentifier<PetrCfg> instanceIdentifier, @Nonnull PetrCfg petrCfg, @Nonnull WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabled(writeContext); enablePetrCfg(instanceIdentifier, petrCfg); } @@ -52,6 +53,7 @@ public class PetrCfgCustomizer extends FutureJVppCustomizer @Nonnull PetrCfg petrCfgBefore, @Nonnull PetrCfg petrCfgAfter, @Nonnull WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabled(writeContext); if (petrCfgAfter.getPetrAddress() != null) { enablePetrCfg(instanceIdentifier, petrCfgAfter); } else { @@ -61,6 +63,7 @@ public class PetrCfgCustomizer extends FutureJVppCustomizer @Override public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<PetrCfg> instanceIdentifier, @Nonnull PetrCfg petrCfg, @Nonnull WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabled(writeContext); disablePetrCfg(instanceIdentifier); } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizer.java index d057c9e83..39986e152 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizer.java @@ -19,35 +19,39 @@ package io.fd.hc2vpp.lisp.translate.write; import static com.google.common.base.Preconditions.checkNotNull; import static java.nio.charset.StandardCharsets.UTF_8; -import io.fd.honeycomb.translate.spi.write.WriterCustomizer; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.hc2vpp.lisp.translate.util.CheckedLispCustomizer; +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; -import java.util.concurrent.TimeoutException; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.pitr.cfg.grouping.PitrCfg; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import io.fd.vpp.jvpp.VppBaseCallException; import io.fd.vpp.jvpp.core.dto.LispPitrSetLocatorSet; import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.concurrent.TimeoutException; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.pitr.cfg.grouping.PitrCfg; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; /** * Customizer for {@code PitrCfg} */ -public class PitrCfgCustomizer extends FutureJVppCustomizer +public class PitrCfgCustomizer extends CheckedLispCustomizer implements WriterCustomizer<PitrCfg>, JvppReplyConsumer, ByteDataTranslator { private static final String DEFAULT_LOCATOR_SET_NAME = "N/A"; - public PitrCfgCustomizer(FutureJVppCore futureJvpp) { - super(futureJvpp); + public PitrCfgCustomizer(@Nonnull final FutureJVppCore futureJvpp, + @Nonnull final LispStateCheckService lispStateCheckService) { + super(futureJvpp, lispStateCheckService); } @Override public void writeCurrentAttributes(InstanceIdentifier<PitrCfg> id, PitrCfg dataAfter, WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabled(writeContext); checkNotNull(dataAfter, "PitrCfg is null"); checkNotNull(dataAfter.getLocatorSet(), "Locator set name is null"); @@ -61,6 +65,7 @@ public class PitrCfgCustomizer extends FutureJVppCustomizer @Override public void updateCurrentAttributes(InstanceIdentifier<PitrCfg> id, PitrCfg dataBefore, PitrCfg dataAfter, WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabled(writeContext); checkNotNull(dataAfter, "PitrCfg is null"); checkNotNull(dataAfter.getLocatorSet(), "Locator set name is null"); @@ -74,6 +79,7 @@ public class PitrCfgCustomizer extends FutureJVppCustomizer @Override public void deleteCurrentAttributes(InstanceIdentifier<PitrCfg> id, PitrCfg dataBefore, WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabled(writeContext); checkNotNull(dataBefore, "PitrCfg is null"); checkNotNull(dataBefore.getLocatorSet(), "Locator set name is null"); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/RlocProbeCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/RlocProbeCustomizer.java index b240d1d2e..e60563454 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/RlocProbeCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/RlocProbeCustomizer.java @@ -17,29 +17,31 @@ package io.fd.hc2vpp.lisp.translate.write; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.hc2vpp.lisp.translate.util.CheckedLispCustomizer; 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.LispRlocProbeEnableDisable; import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.rloc.probing.grouping.RlocProbe; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import javax.annotation.Nonnull; - -public class RlocProbeCustomizer extends FutureJVppCustomizer +public class RlocProbeCustomizer extends CheckedLispCustomizer implements WriterCustomizer<RlocProbe>, ByteDataTranslator, JvppReplyConsumer { - public RlocProbeCustomizer(@Nonnull FutureJVppCore futureJVppCore) { - super(futureJVppCore); + public RlocProbeCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final LispStateCheckService lispStateCheckService) { + super(futureJVppCore, lispStateCheckService); } @Override public void writeCurrentAttributes(@Nonnull InstanceIdentifier<RlocProbe> instanceIdentifier, @Nonnull RlocProbe rlocProbe, @Nonnull WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabled(writeContext); enableDisableRlocProbe(rlocProbe.isEnabled(), instanceIdentifier); } @@ -48,6 +50,7 @@ public class RlocProbeCustomizer extends FutureJVppCustomizer @Nonnull RlocProbe rlocProbeBefore, @Nonnull RlocProbe rlocProbeAfter, @Nonnull WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabled(writeContext); enableDisableRlocProbe(rlocProbeAfter.isEnabled(), instanceIdentifier); } @@ -55,6 +58,7 @@ public class RlocProbeCustomizer extends FutureJVppCustomizer public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<RlocProbe> instanceIdentifier, @Nonnull RlocProbe rlocProbe, @Nonnull WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabled(writeContext); enableDisableRlocProbe(false, instanceIdentifier); } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizer.java index 9effbebe8..05956d998 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizer.java @@ -19,16 +19,17 @@ package io.fd.hc2vpp.lisp.translate.write; import static com.google.common.base.Preconditions.checkState; import com.google.common.base.Optional; +import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService; +import io.fd.hc2vpp.lisp.translate.util.CheckedLispCustomizer; import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; import io.fd.honeycomb.translate.util.RWUtils; - -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.eid.table.grouping.eid.table.VniTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.eid.table.grouping.eid.table.VniTableKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,17 +38,19 @@ import org.slf4j.LoggerFactory; * This customizer serves only as a check if user is not trying to define VniTable <br> * without mapping to vrf/bd */ -public class VniTableCustomizer extends FutureJVppCustomizer implements ListWriterCustomizer<VniTable, VniTableKey> { +public class VniTableCustomizer extends CheckedLispCustomizer implements ListWriterCustomizer<VniTable, VniTableKey> { private static final Logger LOG = LoggerFactory.getLogger(VniTableCustomizer.class); - public VniTableCustomizer(FutureJVppCore futureJvpp) { - super(futureJvpp); + public VniTableCustomizer(@Nonnull final FutureJVppCore futureJvpp, + @Nonnull final LispStateCheckService lispStateCheckService) { + super(futureJvpp, lispStateCheckService); } @Override public void writeCurrentAttributes(InstanceIdentifier<VniTable> id, VniTable dataAfter, WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabled(writeContext); checkAtLeastOnChildExists(id, writeContext, false); } @@ -60,6 +63,7 @@ public class VniTableCustomizer extends FutureJVppCustomizer implements ListWrit @Override public void deleteCurrentAttributes(InstanceIdentifier<VniTable> id, VniTable dataBefore, WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabled(writeContext); checkAtLeastOnChildExists(id, writeContext, true); } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/EidTableWriterFactory.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/EidTableWriterFactory.java index 347e13001..9ffd04b8f 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/EidTableWriterFactory.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/EidTableWriterFactory.java @@ -65,7 +65,7 @@ public final class EidTableWriterFactory extends AbstractLispInfraFactoryBase im @Override public void init(final ModifiableWriterRegistryBuilder registry) { - registry.add(new GenericListWriter<>(VNI_TABLE_ID, new VniTableCustomizer(vppApi))); + registry.add(new GenericListWriter<>(VNI_TABLE_ID, new VniTableCustomizer(vppApi, lispStateCheckService))); registry.add(new GenericWriter<>(VRF_SUBTABLE_ID, new VrfSubtableCustomizer(vppApi))); registry.add(new GenericWriter<>(BRIDGE_DOMAIN_SUBTABLE_ID, diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/LispWriterFactory.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/LispWriterFactory.java index ed7d2122a..46cb9da7b 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/LispWriterFactory.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/LispWriterFactory.java @@ -30,6 +30,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 javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.Lisp; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.lisp.feature.data.grouping.LispFeatureData; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.map.register.grouping.MapRegister; @@ -50,21 +51,26 @@ public final class LispWriterFactory extends AbstractLispInfraFactoryBase implem @Override public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) { - registry.add(new GenericWriter<>(LISP_INSTANCE_IDENTIFIER, new LispCustomizer(vppApi))); + // lisp must be enabled before interfaces + // because as a byproduct of enabling lisp, lisp_gpe interface is created + // and in scenario when vpp data are lost, it would end up calling + // sw_interface_set_flags for non existing interface index + registry.addBefore(new GenericWriter<>(LISP_INSTANCE_IDENTIFIER, new LispCustomizer(vppApi)), + InstanceIdentifier.create(Interfaces.class)); registry.addAfter(writer(LISP_FEATURE_IDENTIFIER.child(PitrCfg.class), - new PitrCfgCustomizer(vppApi)), LOCATOR_SET_ID); + new PitrCfgCustomizer(vppApi, lispStateCheckService)), LOCATOR_SET_ID); registry.add(writer(LISP_FEATURE_IDENTIFIER.child(MapRegister.class), - new MapRegisterCustomizer(vppApi))); + new MapRegisterCustomizer(vppApi, lispStateCheckService))); registry.add(writer(LISP_FEATURE_IDENTIFIER.child(MapRequestMode.class), - new MapRequestModeCustomizer(vppApi))); + new MapRequestModeCustomizer(vppApi, lispStateCheckService))); registry.add(writer(LISP_FEATURE_IDENTIFIER.child(PetrCfg.class), - new PetrCfgCustomizer(vppApi))); + new PetrCfgCustomizer(vppApi, lispStateCheckService))); registry.add(writer(LISP_FEATURE_IDENTIFIER.child(RlocProbe.class), - new RlocProbeCustomizer(vppApi))); + new RlocProbeCustomizer(vppApi, lispStateCheckService))); } } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/LocatorSetWriterFactory.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/LocatorSetWriterFactory.java index cc173df60..7c02752f5 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/LocatorSetWriterFactory.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/LocatorSetWriterFactory.java @@ -45,7 +45,8 @@ public final class LocatorSetWriterFactory extends AbstractLispInfraFactoryBase @Override public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) { // LocatorSet must be written before eid table entries, because local mappings under eid-table are referencing it - registry.addBefore(new GenericListWriter<>(LOCATOR_SET_ID, new LocatorSetCustomizer(vppApi, locatorSetContext)), + registry.addBefore(new GenericListWriter<>(LOCATOR_SET_ID, + new LocatorSetCustomizer(vppApi, locatorSetContext, lispStateCheckService)), Arrays.asList(VRF_SUBTABLE_ID.child(LocalMappings.class).child(LocalMapping.class), BRIDGE_DOMAIN_SUBTABLE_ID.child(LocalMappings.class).child(LocalMapping.class))); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/MapResolverWriterFactory.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/MapResolverWriterFactory.java index 11fe99d89..b60ee16fe 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/MapResolverWriterFactory.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/MapResolverWriterFactory.java @@ -38,6 +38,6 @@ public final class MapResolverWriterFactory extends AbstractLispInfraFactoryBase public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) { registry.add(new GenericListWriter<>( LISP_CONFIG_IDENTIFIER.child(LispFeatureData.class).child(MapResolvers.class).child(MapResolver.class), - new MapResolverCustomizer(vppApi))); + new MapResolverCustomizer(vppApi, lispStateCheckService))); } } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/MapServerWriterFactory.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/MapServerWriterFactory.java index fc0cc4d10..e18b2478f 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/MapServerWriterFactory.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/MapServerWriterFactory.java @@ -32,6 +32,6 @@ public class MapServerWriterFactory extends AbstractLispInfraFactoryBase impleme public void init(@Nonnull ModifiableWriterRegistryBuilder registry) { registry.add(new GenericListWriter<>( LISP_CONFIG_IDENTIFIER.child(LispFeatureData.class).child(MapServers.class).child(MapServer.class), - new MapServerCustomizer(vppApi))); + new MapServerCustomizer(vppApi, lispStateCheckService))); } } |