HC2VPP-115 - lisp state check before write/read 20/5820/2
authorJan Srnicek <[email protected]>
Wed, 22 Mar 2017 09:35:49 +0000 (10:35 +0100)
committerJan Srnicek <[email protected]>
Wed, 22 Mar 2017 11:03:13 +0000 (11:03 +0000)
 - checks lisp state before read,disabled state will
 result in returning empty data
 - checks lisp state before write,disabled state will
 result in throwing IllegalStateException
 - fixes ordering issues for lisp gpe interfaces

Change-Id: I6dcfc6c7f514aad57841f2aac1b2ee0c6b868c3c
Signed-off-by: Jan Srnicek <[email protected]>
59 files changed:
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/LispModule.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/AbstractLispInfraFactoryBase.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/ItrRemoteLocatorSetCustomizer.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/LocatorSetCustomizer.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/MapRegisterCustomizer.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/MapRequestModeCustomizer.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/MapResolverCustomizer.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/MapServerCustomizer.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/PetrCfgCustomizer.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/PitrCfgCustomizer.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/RlocProbeCustomizer.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/VniTableCustomizer.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/EidTableReaderFactory.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/LispStateReaderFactory.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/LocatorSetReaderFactory.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/MapResolverReaderFactory.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/MapServerReaderFactory.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckService.java [new file with mode: 0644]
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckServiceImpl.java [new file with mode: 0644]
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/util/CheckedLispCustomizer.java [new file with mode: 0644]
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/ItrRemoteLocatorSetCustomizer.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizer.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRegisterCustomizer.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRequestModeCustomizer.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizer.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapServerCustomizer.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PetrCfgCustomizer.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizer.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/RlocProbeCustomizer.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizer.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/EidTableWriterFactory.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/LispWriterFactory.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/LocatorSetWriterFactory.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/MapResolverWriterFactory.java
lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/MapServerWriterFactory.java
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/ItrRemoteLocatorSetCustomizerTest.java
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LispInitializingListReaderCustomizerTest.java [new file with mode: 0644]
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LispInitializingReaderCustomizerTest.java [new file with mode: 0644]
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LocatorSetCustomizerTest.java
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/MapRegisterCustomizerTest.java
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/MapRequestModeCustomizerTest.java
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/MapResolverCustomizerTest.java
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/MapServerCustomizerTest.java
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/PetrCfgCustomizerTest.java
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/PitrCfgCustomizerTest.java
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/RlocProbeCustomizerTest.java
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/VniTableCustomizerTest.java
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckServiceImplTest.java [new file with mode: 0644]
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/ItrRemoteLocatorSetCustomizerTest.java
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LispWriterCustomizerTest.java [new file with mode: 0644]
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizerTest.java
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapRegisterCustomizerTest.java
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapRequestModeCustomizerTest.java
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizerTest.java
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapServerCustomizerTest.java
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/PetrCfgCustomizerTest.java
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizerTest.java
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/RlocProbeCustomizerTest.java
lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizerTest.java

index 5e674f5..5324eec 100644 (file)
@@ -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");
     }
 }
index 022ea19..5d2904c 100644 (file)
@@ -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) {
index 2c82b9a..5799bd9 100644 (file)
 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) {
index 4b176fc..4e23347 100755 (executable)
 
 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 =
index e94bb92..808f53e 100644 (file)
 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);
 
index 9de5b5c..267bc04 100644 (file)
 
 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);
index ac94787..199d1ff 100755 (executable)
 
 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);
     }
 }
index 8e53f26..bd4c0ba 100644 (file)
@@ -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);
 
index 0e27a0e..da8f357 100644 (file)
 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));
         }
     }
index c7c966f..6e807ad 100755 (executable)
@@ -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;
index bd00701..0cd5b85 100644 (file)
 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);
 
index 3dfb6d6..56e60c2 100755 (executable)
 
 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());
index 325be48..be99d4f 100755 (executable)
@@ -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)));
index b7bd375..7757d08 100755 (executable)
@@ -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)));
     }
 }
index 17c41f3..75faf0b 100755 (executable)
@@ -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)));
     }
index 2908770..8b9fb3c 100755 (executable)
@@ -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)));
     }
 }
index 1af8f93..e53cee3 100644 (file)
@@ -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 (file)
index 0000000..ab0ea79
--- /dev/null
@@ -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 (file)
index 0000000..8d46e9b
--- /dev/null
@@ -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 (file)
index 0000000..008e20c
--- /dev/null
@@ -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;
+    }
+}
index f4c36cf..71be3c7 100644 (file)
 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);
index b837482..5a606bc 100755 (executable)
@@ -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)
index 1dac298..298b143 100644 (file)
 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);
index 0e06950..d61cd0c 100644 (file)
@@ -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(
index 7873c8d..94b45ae 100755 (executable)
@@ -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");
 
index 9697e16..ec2b3b3 100644 (file)
 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);
     }
 
index d3a3814..728de8f 100644 (file)
 
 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);
     }
 
index d057c9e..39986e1 100755 (executable)
@@ -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");
 
index b240d1d..e605634 100644 (file)
 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);
     }
 
index 9effbeb..05956d9 100755 (executable)
@@ -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);
     }
 
index 347e130..9ffd04b 100755 (executable)
@@ -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,
index ed7d212..46cb9da 100755 (executable)
@@ -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)));
     }
 }
index cc173df..7c02752 100755 (executable)
@@ -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)));
 
index 11fe99d..b60ee16 100755 (executable)
@@ -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)));
     }
 }
index fc0cc4d..e18b247 100644 (file)
@@ -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)));
     }
 }
index 77cb778..1ae56ac 100644 (file)
@@ -28,7 +28,6 @@ import static org.mockito.Mockito.when;
 
 import io.fd.honeycomb.translate.read.ReadFailedException;
 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
-import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest;
 import io.fd.vpp.jvpp.VppCallbackException;
 import io.fd.vpp.jvpp.core.dto.LispGetMapRequestItrRlocs;
 import io.fd.vpp.jvpp.core.dto.LispGetMapRequestItrRlocsReply;
@@ -46,7 +45,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 
 public class ItrRemoteLocatorSetCustomizerTest
-        extends ReaderCustomizerTest<ItrRemoteLocatorSet, ItrRemoteLocatorSetBuilder> {
+        extends LispInitializingReaderCustomizerTest<ItrRemoteLocatorSet, ItrRemoteLocatorSetBuilder> {
 
     private static final String EXPECTED_LOCATOR_SET_NAME = "loc-set";
 
@@ -61,11 +60,12 @@ public class ItrRemoteLocatorSetCustomizerTest
     public void setUp() throws Exception {
         validId = InstanceIdentifier.create(ItrRemoteLocatorSet.class);
         builder = new ItrRemoteLocatorSetBuilder();
+        mockLispEnabled();
     }
 
     @Override
     protected ReaderCustomizer<ItrRemoteLocatorSet, ItrRemoteLocatorSetBuilder> initCustomizer() {
-        return new ItrRemoteLocatorSetCustomizer(api);
+        return new ItrRemoteLocatorSetCustomizer(api, lispStateCheckService);
     }
 
     @Test
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LispInitializingListReaderCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LispInitializingListReaderCustomizerTest.java
new file mode 100644 (file)
index 0000000..b1af21f
--- /dev/null
@@ -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.read;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.common.test.read.InitializingListReaderCustomizerTest;
+import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService;
+import io.fd.honeycomb.translate.read.ReadContext;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import java.util.List;
+import java.util.Objects;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.opendaylight.yangtools.concepts.Builder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.Identifiable;
+import org.opendaylight.yangtools.yang.binding.Identifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public abstract class LispInitializingListReaderCustomizerTest<D extends DataObject & Identifiable<K>, K extends Identifier<D>, B extends Builder<D>>
+        extends InitializingListReaderCustomizerTest<D, K, B> {
+
+    @Mock
+    protected LispStateCheckService lispStateCheckService;
+
+    protected LispInitializingListReaderCustomizerTest(final Class<D> dataObjectClass,
+                                                       final Class<? extends Builder<? extends DataObject>> parentBuilderClass) {
+        super(dataObjectClass, parentBuilderClass);
+    }
+
+    protected void mockLispEnabled() {
+        when(lispStateCheckService.lispEnabled(any(ReadContext.class))).thenReturn(true);
+    }
+
+    @Test
+    public void testNoInteractionsWhenLispDisabledOnReadSpecific() throws ReadFailedException {
+        when(lispStateCheckService.lispEnabled(any(ReadContext.class))).thenReturn(false);
+        final InstanceIdentifier<D> identifier = InstanceIdentifier.create(dataObjectClass);
+        final B builderTouched = getCustomizer().getBuilder(identifier);
+        final B builderUntouched = getCustomizer().getBuilder(identifier);
+        getCustomizer().readCurrentAttributes(identifier, builderTouched, ctx);
+        assertTrue("No interactions with builder expected while lisp is disabled",
+                Objects.equals(builderTouched.build(), builderUntouched.build()));
+    }
+
+    @Test
+    public void testNoInteractionsWhenLispDisabledOnReadAll() throws ReadFailedException {
+        when(lispStateCheckService.lispEnabled(any(ReadContext.class))).thenReturn(false);
+        final InstanceIdentifier<D> identifier = InstanceIdentifier.create(dataObjectClass);
+        final List<K> allIds = getCustomizer().getAllIds(identifier, ctx);
+        assertTrue("No ids should be returned while lisp is disabled", allIds.isEmpty());
+    }
+}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LispInitializingReaderCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LispInitializingReaderCustomizerTest.java
new file mode 100644 (file)
index 0000000..a686a86
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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.read;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.common.test.read.InitializingReaderCustomizerTest;
+import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService;
+import io.fd.honeycomb.translate.read.ReadContext;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import java.util.Objects;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.opendaylight.yangtools.concepts.Builder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public abstract class LispInitializingReaderCustomizerTest<D extends DataObject, B extends Builder<D>> extends
+        InitializingReaderCustomizerTest<D, B> {
+
+    @Mock
+    protected LispStateCheckService lispStateCheckService;
+
+    public LispInitializingReaderCustomizerTest(final Class<D> dataObjectClass,
+                                                final Class<? extends Builder<? extends DataObject>> parentBuilderClass) {
+        super(dataObjectClass, parentBuilderClass);
+    }
+
+    protected void mockLispEnabled() {
+        when(lispStateCheckService.lispEnabled(any(ReadContext.class))).thenReturn(true);
+    }
+
+    @Test
+    public void testNoInteractionsWhileLispDisabled() throws ReadFailedException {
+        when(lispStateCheckService.lispEnabled(any(ReadContext.class))).thenReturn(false);
+        final InstanceIdentifier<D> identifier = InstanceIdentifier.create(dataObjectClass);
+        final B builderTouched = getCustomizer().getBuilder(identifier);
+        final B builderUntouched = getCustomizer().getBuilder(identifier);
+        getCustomizer().readCurrentAttributes(identifier, builderTouched, ctx);
+        assertTrue("No interactions with builder expected while lisp is disabled",
+                Objects.equals(builderTouched.build(), builderUntouched.build()));
+    }
+}
index b6773d2..82c4cef 100644 (file)
 
 package io.fd.hc2vpp.lisp.translate.read;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.when;
+
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import io.fd.hc2vpp.common.test.read.InitializingListReaderCustomizerTest;
 import io.fd.hc2vpp.common.translate.util.NamingContext;
 import io.fd.honeycomb.test.tools.HoneycombTestRunner;
 import io.fd.honeycomb.test.tools.annotations.InjectTestData;
-import io.fd.honeycomb.test.tools.annotations.InjectablesProcessor;
-import io.fd.honeycomb.test.tools.annotations.SchemaContextProvider;
 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
 import io.fd.vpp.jvpp.core.dto.LispLocatorSetDetails;
 import io.fd.vpp.jvpp.core.dto.LispLocatorSetDetailsReplyDump;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.$YangModuleInfoImpl;
 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.lisp.feature.data.grouping.LispFeatureData;
@@ -39,21 +41,12 @@ 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.LocatorSet;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.locator.sets.grouping.locator.sets.LocatorSetBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.locator.sets.grouping.locator.sets.LocatorSetKey;
-import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 
-import java.nio.charset.StandardCharsets;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.when;
-
 @RunWith(HoneycombTestRunner.class)
 public class LocatorSetCustomizerTest
-        extends InitializingListReaderCustomizerTest<LocatorSet, LocatorSetKey, LocatorSetBuilder>
+        extends LispInitializingListReaderCustomizerTest<LocatorSet, LocatorSetKey, LocatorSetBuilder>
         implements LispInitTest {
 
     private static final String LOC_1_PATH = "/lisp:lisp-state" +
@@ -74,6 +67,7 @@ public class LocatorSetCustomizerTest
 
         defineDumpData();
         defineMapping(mappingContext, "loc-set", 1, "locator-set-context");
+        mockLispEnabled();
     }
 
     private void defineDumpData() {
@@ -125,6 +119,6 @@ public class LocatorSetCustomizerTest
 
     @Override
     protected ReaderCustomizer<LocatorSet, LocatorSetBuilder> initCustomizer() {
-        return new LocatorSetCustomizer(api, new NamingContext("loc", "locator-set-context"));
+        return new LocatorSetCustomizer(api, new NamingContext("loc", "locator-set-context"), lispStateCheckService);
     }
 }
\ No newline at end of file
index 9dc1913..1b582cd 100644 (file)
@@ -20,7 +20,6 @@ import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.when;
 
-import io.fd.hc2vpp.common.test.read.InitializingReaderCustomizerTest;
 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
 import io.fd.vpp.jvpp.core.dto.ShowLispMapRegisterStateReply;
 import org.junit.Before;
@@ -30,7 +29,7 @@ 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.map.register.grouping.MapRegisterBuilder;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class MapRegisterCustomizerTest extends InitializingReaderCustomizerTest implements LispInitTest {
+public class MapRegisterCustomizerTest extends LispInitializingReaderCustomizerTest implements LispInitTest {
     private static final InstanceIdentifier<MapRegister> STATE_IID = LISP_STATE_FTR_IID.child(MapRegister.class);
     private static final InstanceIdentifier<MapRegister> CONFIG_IID = LISP_FTR_IID.child(MapRegister.class);
 
@@ -44,6 +43,7 @@ public class MapRegisterCustomizerTest extends InitializingReaderCustomizerTest
         final ShowLispMapRegisterStateReply reply = new ShowLispMapRegisterStateReply();
         reply.isEnabled = 1;
         when(api.showLispMapRegisterState(any())).thenReturn(future(reply));
+        mockLispEnabled();
     }
 
     @Test
@@ -61,6 +61,6 @@ public class MapRegisterCustomizerTest extends InitializingReaderCustomizerTest
 
     @Override
     protected ReaderCustomizer initCustomizer() {
-        return new MapRegisterCustomizer(api);
+        return new MapRegisterCustomizer(api, lispStateCheckService);
     }
 }
\ No newline at end of file
index 85e6231..6479f99 100644 (file)
@@ -21,19 +21,16 @@ import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.when;
 import static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.MapRequestMode.DestinationOnly;
 
-import io.fd.hc2vpp.common.test.read.InitializingReaderCustomizerTest;
-import io.fd.honeycomb.test.tools.HoneycombTestRunner;
 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
 import io.fd.vpp.jvpp.core.dto.ShowLispMapRequestModeReply;
 import org.junit.Before;
 import org.junit.Test;
-import org.junit.runner.RunWith;
 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.request.mode.grouping.MapRequestMode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.map.request.mode.grouping.MapRequestModeBuilder;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class MapRequestModeCustomizerTest extends InitializingReaderCustomizerTest implements LispInitTest {
+public class MapRequestModeCustomizerTest extends LispInitializingReaderCustomizerTest implements LispInitTest {
     private static final InstanceIdentifier<MapRequestMode> STATE_IID = LISP_STATE_FTR_IID.child(MapRequestMode.class);
     private static final InstanceIdentifier<MapRequestMode> CONFIG_IID = LISP_FTR_IID.child(MapRequestMode.class);
 
@@ -47,6 +44,7 @@ public class MapRequestModeCustomizerTest extends InitializingReaderCustomizerTe
         final ShowLispMapRequestModeReply reply = new ShowLispMapRequestModeReply();
         reply.mode = ((byte) DestinationOnly.getIntValue());
         when(api.showLispMapRequestMode(any())).thenReturn(future(reply));
+        mockLispEnabled();
     }
 
     @Test
@@ -64,6 +62,6 @@ public class MapRequestModeCustomizerTest extends InitializingReaderCustomizerTe
 
     @Override
     protected ReaderCustomizer initCustomizer() {
-        return new MapRequestModeCustomizer(api);
+        return new MapRequestModeCustomizer(api, lispStateCheckService);
     }
 }
\ No newline at end of file
index 5d0be37..e4a0d99 100644 (file)
@@ -23,7 +23,6 @@ import static org.mockito.Mockito.when;
 
 import com.google.common.collect.ImmutableList;
 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
-import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest;
 import io.fd.vpp.jvpp.core.dto.LispMapResolverDetails;
 import io.fd.vpp.jvpp.core.dto.LispMapResolverDetailsReplyDump;
 import java.util.List;
@@ -40,7 +39,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 
 public class MapResolverCustomizerTest
-        extends ListReaderCustomizerTest<MapResolver, MapResolverKey, MapResolverBuilder> {
+        extends LispInitializingListReaderCustomizerTest<MapResolver, MapResolverKey, MapResolverBuilder> {
 
     private static final IpAddress IP_ADDRESS_REVERTED =
             new IpAddress(new Ipv4AddressNoZone("1.2.168.192"));
@@ -59,6 +58,7 @@ public class MapResolverCustomizerTest
         validId = InstanceIdentifier.create(MapResolvers.class)
                 .child(MapResolver.class, new MapResolverKey(IP_ADDRESS_REVERTED));
         defineDumpData();
+        mockLispEnabled();
     }
 
     @Test
@@ -97,6 +97,6 @@ public class MapResolverCustomizerTest
 
     @Override
     protected ReaderCustomizer<MapResolver, MapResolverBuilder> initCustomizer() {
-        return new MapResolverCustomizer(api);
+        return new MapResolverCustomizer(api, lispStateCheckService);
     }
 }
\ No newline at end of file
index 1af2293..ace07e0 100644 (file)
@@ -23,7 +23,6 @@ import static org.junit.Assert.assertEquals;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.when;
 
-import io.fd.hc2vpp.common.test.read.InitializingListReaderCustomizerTest;
 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
 import io.fd.vpp.jvpp.core.dto.LispMapServerDetails;
 import io.fd.vpp.jvpp.core.dto.LispMapServerDetailsReplyDump;
@@ -44,7 +43,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 public class MapServerCustomizerTest
-        extends InitializingListReaderCustomizerTest<MapServer, MapServerKey, MapServerBuilder>
+        extends LispInitializingListReaderCustomizerTest<MapServer, MapServerKey, MapServerBuilder>
         implements LispInitTest {
 
     private static final MapServerKey
@@ -79,6 +78,7 @@ public class MapServerCustomizerTest
 
         reply.lispMapServerDetails = Arrays.asList(server1, server2, server3);
         when(api.lispMapServerDump(any(LispMapServerDump.class))).thenReturn(future(reply));
+        mockLispEnabled();
     }
 
     @Test
@@ -107,6 +107,6 @@ public class MapServerCustomizerTest
 
     @Override
     protected ReaderCustomizer<MapServer, MapServerBuilder> initCustomizer() {
-        return new MapServerCustomizer(api);
+        return new MapServerCustomizer(api, lispStateCheckService);
     }
 }
\ No newline at end of file
index 1075232..4052b16 100644 (file)
@@ -21,7 +21,6 @@ import static org.junit.Assert.assertNull;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.when;
 
-import io.fd.hc2vpp.common.test.read.InitializingReaderCustomizerTest;
 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
 import io.fd.vpp.jvpp.core.dto.ShowLispUsePetrReply;
 import org.junit.Test;
@@ -32,7 +31,7 @@ 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.use.petr.cfg.grouping.PetrCfgBuilder;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class PetrCfgCustomizerTest extends InitializingReaderCustomizerTest implements LispInitTest {
+public class PetrCfgCustomizerTest extends LispInitializingReaderCustomizerTest implements LispInitTest {
     private static final InstanceIdentifier<PetrCfg> STATE_IID = LISP_STATE_FTR_IID.child(PetrCfg.class);
     private static final InstanceIdentifier<PetrCfg> CONFIG_IID = LISP_FTR_IID.child(PetrCfg.class);
 
@@ -54,6 +53,11 @@ public class PetrCfgCustomizerTest extends InitializingReaderCustomizerTest impl
         when(api.showLispUsePetr(any())).thenReturn(future(reply));
     }
 
+    @Override
+    protected void setUp() throws Exception {
+        mockLispEnabled();
+    }
+
     @Test
     public void readCurrentAttributesEnabled() throws Exception {
         mockEnabledReply();
@@ -79,6 +83,6 @@ public class PetrCfgCustomizerTest extends InitializingReaderCustomizerTest impl
 
     @Override
     protected ReaderCustomizer initCustomizer() {
-        return new PetrCfgCustomizer(api);
+        return new PetrCfgCustomizer(api, lispStateCheckService);
     }
 }
\ No newline at end of file
index c1ffc17..c61c13b 100644 (file)
@@ -22,19 +22,17 @@ import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.when;
 
 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
-import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest;
+import io.fd.vpp.jvpp.core.dto.ShowLispPitrReply;
 import java.nio.charset.StandardCharsets;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.LispStateBuilder;
 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;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import io.fd.vpp.jvpp.core.dto.ShowLispPitrReply;
 
 
-public class PitrCfgCustomizerTest extends ReaderCustomizerTest<PitrCfg, PitrCfgBuilder> {
+public class PitrCfgCustomizerTest extends LispInitializingReaderCustomizerTest<PitrCfg, PitrCfgBuilder> {
 
     private static final byte[] LOC_SET_NAME_BYTES = "loc-set".getBytes(StandardCharsets.UTF_8);
 
@@ -49,6 +47,7 @@ public class PitrCfgCustomizerTest extends ReaderCustomizerTest<PitrCfg, PitrCfg
         emptyId = InstanceIdentifier.create(PitrCfg.class);
 
         mockDumpData();
+        mockLispEnabled();
     }
 
     @Test
@@ -72,6 +71,6 @@ public class PitrCfgCustomizerTest extends ReaderCustomizerTest<PitrCfg, PitrCfg
 
     @Override
     protected ReaderCustomizer<PitrCfg, PitrCfgBuilder> initCustomizer() {
-        return new PitrCfgCustomizer(api);
+        return new PitrCfgCustomizer(api, lispStateCheckService);
     }
 }
\ No newline at end of file
index f5d2353..2afe712 100644 (file)
@@ -20,7 +20,6 @@ import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.when;
 
-import io.fd.hc2vpp.common.test.read.InitializingReaderCustomizerTest;
 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
 import io.fd.vpp.jvpp.core.dto.ShowLispRlocProbeStateReply;
 import org.junit.Before;
@@ -30,7 +29,7 @@ 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.rloc.probing.grouping.RlocProbeBuilder;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class RlocProbeCustomizerTest extends InitializingReaderCustomizerTest implements LispInitTest {
+public class RlocProbeCustomizerTest extends LispInitializingReaderCustomizerTest implements LispInitTest {
     private static final InstanceIdentifier<RlocProbe> STATE_IID = LISP_STATE_FTR_IID.child(RlocProbe.class);
     private static final InstanceIdentifier<RlocProbe> CONFIG_IID = LISP_FTR_IID.child(RlocProbe.class);
 
@@ -44,6 +43,7 @@ public class RlocProbeCustomizerTest extends InitializingReaderCustomizerTest im
         final ShowLispRlocProbeStateReply reply = new ShowLispRlocProbeStateReply();
         reply.isEnabled = 1;
         when(api.showLispRlocProbeState(any())).thenReturn(future(reply));
+        mockLispEnabled();
     }
 
     @Test
@@ -62,6 +62,6 @@ public class RlocProbeCustomizerTest extends InitializingReaderCustomizerTest im
 
     @Override
     protected ReaderCustomizer initCustomizer() {
-        return new RlocProbeCustomizer(api);
+        return new RlocProbeCustomizer(api, lispStateCheckService);
     }
 }
\ No newline at end of file
index c25906e..f9610a1 100644 (file)
@@ -26,7 +26,6 @@ import static org.mockito.Mockito.when;
 import com.google.common.collect.ImmutableList;
 import io.fd.honeycomb.translate.read.ReadFailedException;
 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
-import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest;
 import io.fd.vpp.jvpp.VppCallbackException;
 import io.fd.vpp.jvpp.core.dto.LispEidTableVniDetails;
 import io.fd.vpp.jvpp.core.dto.LispEidTableVniDetailsReplyDump;
@@ -42,7 +41,7 @@ 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.eid.table.grouping.eid.table.VniTableKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class VniTableCustomizerTest extends ListReaderCustomizerTest<VniTable, VniTableKey, VniTableBuilder> {
+public class VniTableCustomizerTest extends LispInitializingListReaderCustomizerTest<VniTable, VniTableKey, VniTableBuilder> {
 
     private InstanceIdentifier<VniTable> validId;
 
@@ -53,6 +52,7 @@ public class VniTableCustomizerTest extends ListReaderCustomizerTest<VniTable, V
     @Before
     public void init() {
         validId = InstanceIdentifier.create(EidTable.class).child(VniTable.class, new VniTableKey(12L));
+        mockLispEnabled();
     }
 
     @Test
@@ -116,6 +116,6 @@ public class VniTableCustomizerTest extends ListReaderCustomizerTest<VniTable, V
 
     @Override
     protected ReaderCustomizer<VniTable, VniTableBuilder> initCustomizer() {
-        return new VniTableCustomizer(api);
+        return new VniTableCustomizer(api, lispStateCheckService);
     }
 }
\ No newline at end of file
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckServiceImplTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckServiceImplTest.java
new file mode 100644 (file)
index 0000000..d5a351c
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * 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 org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import com.google.common.base.Optional;
+import io.fd.hc2vpp.common.test.util.FutureProducer;
+import io.fd.honeycomb.translate.ModificationCache;
+import io.fd.honeycomb.translate.read.ReadContext;
+import io.fd.honeycomb.translate.write.WriteContext;
+import io.fd.vpp.jvpp.core.dto.ShowLispStatusReply;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+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 class LispStateCheckServiceImplTest implements FutureProducer {
+
+    private LispStateCheckService impl;
+
+    @Mock
+    private FutureJVppCore vppApi;
+
+    @Mock
+    private WriteContext writeContext;
+
+    @Mock
+    private ReadContext readContext;
+
+    @Before
+    public void init() {
+        initMocks(this);
+        impl = new LispStateCheckServiceImpl(vppApi);
+        when(readContext.getModificationCache()).thenReturn(new ModificationCache());
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testCheckLispEnabledNoConfig() throws Exception {
+        when(writeContext.readAfter(InstanceIdentifier.create(Lisp.class))).thenReturn(Optional.absent());
+        impl.checkLispEnabled(writeContext);
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testCheckLispEnabledDisabledConfig() throws Exception {
+        when(writeContext.readAfter(InstanceIdentifier.create(Lisp.class)))
+                .thenReturn(Optional.of(new LispBuilder().setEnable(false).build()));
+        impl.checkLispEnabled(writeContext);
+    }
+
+    @Test
+    public void testCheckLispEnabledEnabledConfig() throws Exception {
+        // no exception should be thrown here
+        when(writeContext.readAfter(InstanceIdentifier.create(Lisp.class)))
+                .thenReturn(Optional.of(new LispBuilder().setEnable(true).build()));
+        impl.checkLispEnabled(writeContext);
+    }
+
+    @Test
+    public void testLispEnabledDisabledDump() throws Exception {
+        when(vppApi.showLispStatus(any())).thenReturn(future(new ShowLispStatusReply()));
+        assertFalse(impl.lispEnabled(readContext));
+    }
+
+    @Test
+    public void testLispEnabledEnabledDump() throws Exception {
+        final ShowLispStatusReply reply = new ShowLispStatusReply();
+        reply.featureStatus = 1;
+        when(vppApi.showLispStatus(any())).thenReturn(future(reply));
+        assertTrue(impl.lispEnabled(readContext));
+    }
+}
\ No newline at end of file
index 22d1298..e11ec42 100644 (file)
@@ -26,7 +26,6 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 import static org.mockito.MockitoAnnotations.initMocks;
 
-import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
 import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
 import io.fd.honeycomb.translate.write.WriteFailedException;
 import io.fd.vpp.jvpp.VppCallbackException;
@@ -44,7 +43,7 @@ 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.itr.remote.locator.sets.grouping.ItrRemoteLocatorSetBuilder;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class ItrRemoteLocatorSetCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator {
+public class ItrRemoteLocatorSetCustomizerTest extends LispWriterCustomizerTest implements ByteDataTranslator {
 
     private static final String VALID_NAME = "loc-set";
 
@@ -58,7 +57,7 @@ public class ItrRemoteLocatorSetCustomizerTest extends WriterCustomizerTest impl
     @Before
     public void setUpTest() throws Exception {
         initMocks(this);
-        customizer = new ItrRemoteLocatorSetCustomizer(api);
+        customizer = new ItrRemoteLocatorSetCustomizer(api, lispStateCheckService);
         validId = InstanceIdentifier.create(ItrRemoteLocatorSet.class);
         validData = new ItrRemoteLocatorSetBuilder().setRemoteLocatorSetName(VALID_NAME).build();
     }
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LispWriterCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LispWriterCustomizerTest.java
new file mode 100644 (file)
index 0000000..a2d7721
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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.write;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doThrow;
+
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.hc2vpp.lisp.translate.service.LispStateCheckService;
+import io.fd.honeycomb.translate.write.WriteContext;
+import org.mockito.Mock;
+
+public abstract class LispWriterCustomizerTest extends WriterCustomizerTest{
+
+    @Mock
+    protected LispStateCheckService lispStateCheckService;
+
+    protected void mockLispDisabled(){
+        doThrow(IllegalArgumentException.class)
+                .when(lispStateCheckService).checkLispEnabled(any(WriteContext.class));
+    }
+
+
+}
index 6554490..50cba9d 100755 (executable)
@@ -24,11 +24,11 @@ import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
 import static org.mockito.Mockito.when;
 
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
-import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
 import io.fd.hc2vpp.common.translate.util.NamingContext;
 import io.fd.honeycomb.translate.write.WriteFailedException;
 import io.fd.vpp.jvpp.core.dto.LispAddDelLocatorSet;
@@ -55,7 +55,7 @@ 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.InterfaceBuilder;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class LocatorSetCustomizerTest extends WriterCustomizerTest {
+public class LocatorSetCustomizerTest extends LispWriterCustomizerTest {
 
     private static final InstanceIdentifier<EidTable>
             EID_TABLE_ID = InstanceIdentifier.create(Lisp.class)
@@ -68,9 +68,13 @@ public class LocatorSetCustomizerTest extends WriterCustomizerTest {
 
     private LocatorSetCustomizer customizer;
 
+    private final InstanceIdentifier<LocatorSet> EMPTY_ID = InstanceIdentifier.create(LocatorSet.class);
+    private final LocatorSet EMPTY_DATA = new LocatorSetBuilder().build();
+
     @Override
     public void setUpTest() {
-        customizer = new LocatorSetCustomizer(api, new NamingContext("locator-set", "locator-set-context"));
+        customizer = new LocatorSetCustomizer(api, new NamingContext("locator-set", "locator-set-context"),
+                lispStateCheckService);
     }
 
     @Test(expected = NullPointerException.class)
@@ -197,6 +201,30 @@ public class LocatorSetCustomizerTest extends WriterCustomizerTest {
         fail("testDeleteReferenced should have failed");
     }
 
+    @Test
+    public void testWriteLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.writeCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
+
+    @Test
+    public void testDeleteLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.deleteCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
+
     private static Optional<EidTable> eidTableData() {
         return Optional.of(new EidTableBuilder()
                 .setVniTable(
index 0eb5d11..30ab07c 100644 (file)
 package io.fd.hc2vpp.lisp.translate.write;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
 import static org.mockito.Mockito.when;
 
-import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
 import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
+import io.fd.honeycomb.translate.write.WriteFailedException;
 import io.fd.vpp.jvpp.core.dto.LispMapRegisterEnableDisable;
 import io.fd.vpp.jvpp.core.dto.LispMapRegisterEnableDisableReply;
 import org.junit.Test;
@@ -33,7 +35,7 @@ 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.map.register.grouping.MapRegisterBuilder;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class MapRegisterCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator {
+public class MapRegisterCustomizerTest extends LispWriterCustomizerTest implements ByteDataTranslator {
 
     private static final InstanceIdentifier<MapRegister> ID = InstanceIdentifier.create(MapRegister.class);
     private MapRegisterCustomizer customizer;
@@ -42,10 +44,13 @@ public class MapRegisterCustomizerTest extends WriterCustomizerTest implements B
 
     @Captor
     private ArgumentCaptor<LispMapRegisterEnableDisable> requestCaptor;
+    private InstanceIdentifier<MapRegister> EMPTY_ID = InstanceIdentifier.create(MapRegister.class);
+    private MapRegister EMPTY_DATA = new MapRegisterBuilder().setEnabled(false).build();
+
 
     @Override
     protected void setUpTest() throws Exception {
-        customizer = new MapRegisterCustomizer(api);
+        customizer = new MapRegisterCustomizer(api, lispStateCheckService);
 
         enabledRegister = new MapRegisterBuilder()
                 .setEnabled(true)
@@ -83,6 +88,42 @@ public class MapRegisterCustomizerTest extends WriterCustomizerTest implements B
         verifyRequest(false);
     }
 
+    @Test
+    public void testWriteLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.writeCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
+
+    @Test
+    public void testUpdateLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.updateCurrentAttributes(EMPTY_ID, EMPTY_DATA,EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
+
+    @Test
+    public void testDeleteLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.deleteCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
+
     private void verifyRequest(final boolean enabled) {
         verify(api, times(1)).lispMapRegisterEnableDisable(requestCaptor.capture());
 
index d66097a..66384a4 100644 (file)
 package io.fd.hc2vpp.lisp.translate.write;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
 import static org.mockito.Mockito.when;
 import static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.MapRequestMode.DestinationOnly;
 import static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.MapRequestMode.SourceDestination;
 
-import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.honeycomb.translate.write.WriteFailedException;
 import io.fd.vpp.jvpp.core.dto.LispMapRequestMode;
 import io.fd.vpp.jvpp.core.dto.LispMapRequestModeReply;
 import org.junit.Test;
@@ -34,7 +36,7 @@ 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.map.request.mode.grouping.MapRequestModeBuilder;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class MapRequestModeCustomizerTest extends WriterCustomizerTest {
+public class MapRequestModeCustomizerTest extends LispWriterCustomizerTest {
 
     private static final InstanceIdentifier<MapRequestMode> ID = InstanceIdentifier.create(MapRequestMode.class);
     private MapRequestModeCustomizer customizer;
@@ -43,10 +45,12 @@ public class MapRequestModeCustomizerTest extends WriterCustomizerTest {
 
     @Captor
     private ArgumentCaptor<LispMapRequestMode> requestCaptor;
+    private InstanceIdentifier<MapRequestMode> EMPTY_ID = InstanceIdentifier.create(MapRequestMode.class);
+    private MapRequestMode EMPTY_DATA = new MapRequestModeBuilder().build();
 
     @Override
     protected void setUpTest() throws Exception {
-        customizer = new MapRequestModeCustomizer(api);
+        customizer = new MapRequestModeCustomizer(api, lispStateCheckService);
         sourceDestinationMode = new MapRequestModeBuilder()
                 .setMode(SourceDestination)
                 .build();
@@ -73,6 +77,30 @@ public class MapRequestModeCustomizerTest extends WriterCustomizerTest {
         verify(api, times(0)).lispMapRequestMode(any());
     }
 
+    @Test
+    public void testWriteLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.writeCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
+
+    @Test
+    public void testUpdateLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.updateCurrentAttributes(EMPTY_ID, EMPTY_DATA,EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
+
     private void verifyModeRequest(
             final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.MapRequestMode mode) {
         verify(api, times(1)).lispMapRequestMode(requestCaptor.capture());
index 474e20f..76017a4 100755 (executable)
 package io.fd.hc2vpp.lisp.translate.write;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
 import static org.mockito.Mockito.when;
 
-import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
 import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
 import io.fd.honeycomb.translate.write.WriteFailedException;
 import io.fd.vpp.jvpp.core.dto.LispAddDelMapResolver;
@@ -34,15 +35,18 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 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.MapResolverBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 
-public class MapResolverCustomizerTest extends WriterCustomizerTest implements Ipv4Translator {
+public class MapResolverCustomizerTest extends LispWriterCustomizerTest implements Ipv4Translator {
 
     private MapResolverCustomizer customizer;
+    private InstanceIdentifier<MapResolver> EMPTY_ID = InstanceIdentifier.create(MapResolver.class);
+    private MapResolver EMPTY_DATA = new MapResolverBuilder().build();
 
     @Override
     public void setUpTest() {
-        customizer = new MapResolverCustomizer(api);
+        customizer = new MapResolverCustomizer(api, lispStateCheckService);
     }
 
     private void whenLispAddDelMapResolverThenSuccess() {
@@ -100,4 +104,27 @@ public class MapResolverCustomizerTest extends WriterCustomizerTest implements I
         assertEquals("192.168.2.1", arrayToIpv4AddressNoZone(request.ipAddress).getValue());
     }
 
+    @Test
+    public void testWriteLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.writeCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
+
+    @Test
+    public void testDeleteLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.deleteCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
 }
index b69a44e..a139058 100644 (file)
@@ -18,12 +18,13 @@ package io.fd.hc2vpp.lisp.translate.write;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
 import static org.mockito.Mockito.when;
 
-import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
 import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
 import io.fd.honeycomb.translate.write.WriteFailedException;
 import io.fd.vpp.jvpp.core.dto.LispAddDelMapServer;
@@ -40,7 +41,7 @@ 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.map.servers.grouping.map.servers.MapServerKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class MapServerCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator {
+public class MapServerCustomizerTest extends LispWriterCustomizerTest implements ByteDataTranslator {
 
     private static final MapServerKey MAP_SERVER_KEY = new MapServerKey(
             new IpAddress(new Ipv4Address("192.168.2.1")));
@@ -49,13 +50,15 @@ public class MapServerCustomizerTest extends WriterCustomizerTest implements Byt
 
     private MapServerCustomizer customizer;
     private MapServer data;
+    private InstanceIdentifier<MapServer> EMPTY_ID = InstanceIdentifier.create(MapServer.class);
+    private MapServer EMPTY_DATA = new MapServerBuilder().build();
 
     @Captor
     private ArgumentCaptor<LispAddDelMapServer> requestCaptor;
 
     @Override
     protected void setUpTest() throws Exception {
-        customizer = new MapServerCustomizer(api);
+        customizer = new MapServerCustomizer(api, lispStateCheckService);
         data = new MapServerBuilder()
                 .setIpAddress(MAP_SERVER_KEY.getIpAddress())
                 .build();
@@ -86,6 +89,30 @@ public class MapServerCustomizerTest extends WriterCustomizerTest implements Byt
         verifyRequest(false);
     }
 
+    @Test
+    public void testWriteLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.writeCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
+
+    @Test
+    public void testDeleteLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.deleteCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
+
     private void verifyRequest(final boolean add) {
         verify(api, times(1)).lispAddDelMapServer(requestCaptor.capture());
 
index bd7475b..40660a7 100644 (file)
@@ -19,12 +19,14 @@ package io.fd.hc2vpp.lisp.translate.write;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
 import static org.mockito.Mockito.when;
 
-import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.honeycomb.translate.write.WriteFailedException;
 import io.fd.vpp.jvpp.core.dto.LispUsePetr;
 import io.fd.vpp.jvpp.core.dto.LispUsePetrReply;
 import java.util.Arrays;
@@ -37,7 +39,7 @@ 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.use.petr.cfg.grouping.PetrCfgBuilder;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class PetrCfgCustomizerTest extends WriterCustomizerTest {
+public class PetrCfgCustomizerTest extends LispWriterCustomizerTest {
 
     private static final InstanceIdentifier<PetrCfg> ID = InstanceIdentifier.create(PetrCfg.class);
 
@@ -47,10 +49,12 @@ public class PetrCfgCustomizerTest extends WriterCustomizerTest {
 
     @Captor
     private ArgumentCaptor<LispUsePetr> requestCaptor;
+    private InstanceIdentifier<PetrCfg> EMPTY_ID = InstanceIdentifier.create(PetrCfg.class);
+    private PetrCfg EMPTY_DATA = new PetrCfgBuilder().build();
 
     @Override
     public void setUpTest() throws Exception {
-        customizer = new PetrCfgCustomizer(api);
+        customizer = new PetrCfgCustomizer(api, lispStateCheckService);
         enabledCfg = new PetrCfgBuilder().setPetrAddress(new IpAddress(new Ipv4Address("192.168.2.1"))).build();
         disabledCfg = new PetrCfgBuilder().build();
         when(api.lispUsePetr(any(LispUsePetr.class))).thenReturn(future(new LispUsePetrReply()));
@@ -80,6 +84,42 @@ public class PetrCfgCustomizerTest extends WriterCustomizerTest {
         verifyDisabledInvoked();
     }
 
+    @Test
+    public void testWriteLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.writeCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
+
+    @Test
+    public void testUpdateLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.updateCurrentAttributes(EMPTY_ID, EMPTY_DATA,EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
+
+    @Test
+    public void testDeleteLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.deleteCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
+
     private void verifyEnabledInvoked() {
         verify(api, times(1)).lispUsePetr(requestCaptor.capture());
 
index 4775091..ae1b145 100755 (executable)
 package io.fd.hc2vpp.lisp.translate.write;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
 import static org.mockito.Mockito.when;
 
-import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
 import io.fd.honeycomb.translate.write.WriteFailedException;
 import io.fd.vpp.jvpp.core.dto.LispPitrSetLocatorSet;
 import io.fd.vpp.jvpp.core.dto.LispPitrSetLocatorSetReply;
@@ -32,15 +33,18 @@ import org.junit.Test;
 import org.mockito.ArgumentCaptor;
 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;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 
-public class PitrCfgCustomizerTest extends WriterCustomizerTest {
+public class PitrCfgCustomizerTest extends LispWriterCustomizerTest {
 
     private PitrCfgCustomizer customizer;
+    private InstanceIdentifier<PitrCfg> EMPTY_ID = InstanceIdentifier.create(PitrCfg.class);
+    private PitrCfg EMPTY_DATA = new PitrCfgBuilder().build();
 
     @Override
     public void setUpTest() {
-        customizer = new PitrCfgCustomizer(api);
+        customizer = new PitrCfgCustomizer(api, lispStateCheckService);
     }
 
     private void whenLispPitrSetLocatorSetThenSuccess() {
@@ -114,4 +118,40 @@ public class PitrCfgCustomizerTest extends WriterCustomizerTest {
         assertEquals("Locator", new String(request.lsName));
     }
 
+    @Test
+    public void testWriteLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.writeCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
+
+    @Test
+    public void testUpdateLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.updateCurrentAttributes(EMPTY_ID, EMPTY_DATA,EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
+
+    @Test
+    public void testDeleteLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.deleteCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
+
 }
index 829853e..e2a6b3e 100644 (file)
 package io.fd.hc2vpp.lisp.translate.write;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
 import static org.mockito.Mockito.when;
 
-import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
 import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
+import io.fd.honeycomb.translate.write.WriteFailedException;
 import io.fd.vpp.jvpp.core.dto.LispRlocProbeEnableDisable;
 import io.fd.vpp.jvpp.core.dto.LispRlocProbeEnableDisableReply;
 import org.junit.Test;
@@ -33,7 +35,7 @@ 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.rloc.probing.grouping.RlocProbeBuilder;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class RlocProbeCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator {
+public class RlocProbeCustomizerTest extends LispWriterCustomizerTest implements ByteDataTranslator {
 
     private static final InstanceIdentifier<RlocProbe> ID = InstanceIdentifier.create(RlocProbe.class);
     private RlocProbeCustomizer customizer;
@@ -42,10 +44,12 @@ public class RlocProbeCustomizerTest extends WriterCustomizerTest implements Byt
 
     @Captor
     private ArgumentCaptor<LispRlocProbeEnableDisable> requestCaptor;
+    private InstanceIdentifier<RlocProbe> EMPTY_ID = InstanceIdentifier.create(RlocProbe.class);
+    private RlocProbe EMPTY_DATA = new RlocProbeBuilder().build();
 
     @Override
     protected void setUpTest() throws Exception {
-        customizer = new RlocProbeCustomizer(api);
+        customizer = new RlocProbeCustomizer(api, lispStateCheckService);
         enabledProbe = rlocProbe(true);
         disabledProbe = rlocProbe(false);
         when(api.lispRlocProbeEnableDisable(any(LispRlocProbeEnableDisable.class)))
@@ -76,6 +80,42 @@ public class RlocProbeCustomizerTest extends WriterCustomizerTest implements Byt
         verifyRequest(false);
     }
 
+    @Test
+    public void testWriteLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.writeCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
+
+    @Test
+    public void testUpdateLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.updateCurrentAttributes(EMPTY_ID, EMPTY_DATA,EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
+
+    @Test
+    public void testDeleteLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.deleteCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
+
     private static RlocProbe rlocProbe(final boolean enabled) {
         return new RlocProbeBuilder().setEnabled(enabled).build();
     }
index 5319070..1bf4b77 100644 (file)
@@ -18,12 +18,12 @@ package io.fd.hc2vpp.lisp.translate.write;
 
 
 import static org.junit.Assert.fail;
+import static org.mockito.Mockito.verifyZeroInteractions;
 import static org.mockito.Mockito.when;
 import static org.mockito.MockitoAnnotations.initMocks;
 
 import com.google.common.base.Optional;
 import io.fd.honeycomb.translate.write.WriteFailedException;
-import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.eid.table.grouping.eid.table.VniTable;
@@ -31,16 +31,18 @@ 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.eid.table.grouping.eid.table.vni.table.VrfSubtableBuilder;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class VniTableCustomizerTest extends WriterCustomizerTest {
+public class VniTableCustomizerTest extends LispWriterCustomizerTest {
 
     private VniTableCustomizer customizer;
     private InstanceIdentifier<VniTable> validId;
     private VniTable validData;
+    private InstanceIdentifier<VniTable> EMPTY_ID = InstanceIdentifier.create(VniTable.class);
+    private VniTable EMPTY_DATA = new VniTableBuilder().build();
 
     @Before
     public void init() {
         initMocks(this);
-        customizer = new VniTableCustomizer(api);
+        customizer = new VniTableCustomizer(api, lispStateCheckService);
 
         validId = InstanceIdentifier.create(VniTable.class);
         validData = new VniTableBuilder()
@@ -85,6 +87,30 @@ public class VniTableCustomizerTest extends WriterCustomizerTest {
         customizer.deleteCurrentAttributes(validId, validData, writeContext);
     }
 
+    @Test
+    public void testWriteLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.writeCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
+
+    @Test
+    public void testDeleteLispDisabled() throws WriteFailedException {
+        mockLispDisabled();
+        try {
+            customizer.deleteCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext);
+        } catch (IllegalArgumentException e) {
+            verifyZeroInteractions(api);
+            return;
+        }
+        fail("Test should have thrown IllegalArgumentException");
+    }
+
     private void whenReadBeforeReturnValid() {
         when(writeContext.readBefore(validId)).thenReturn(Optional.of(validData));
     }