diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2017-05-02 10:41:35 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2017-05-02 11:31:10 +0000 |
commit | 9faea02da937dc9468f557a00ed5c9dacec7f2e2 (patch) | |
tree | 08d7ee5d4ce09d0d5669cd04eacd7c17f3f6f9c7 /lisp/lisp2vpp/src/main/java | |
parent | d8b2e9bf2db11dec21a8ebd27c038c4ab6bd1473 (diff) |
HC2VPP-131 - checking of lisp state before/after according to operation
Change-Id: I190562527c68d022a9b16fc76ad6a011161f4308
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'lisp/lisp2vpp/src/main/java')
13 files changed, 47 insertions, 25 deletions
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/VrfSubtableCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/VrfSubtableCustomizer.java index 80d6cbd83..99923cf73 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/VrfSubtableCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/VrfSubtableCustomizer.java @@ -29,7 +29,6 @@ import io.fd.honeycomb.translate.spi.read.Initialized; import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager.DumpCacheManagerBuilder; -import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump; import io.fd.vpp.jvpp.core.dto.OneEidTableMapDetails; import io.fd.vpp.jvpp.core.dto.OneEidTableMapDetailsReplyDump; import io.fd.vpp.jvpp.core.future.FutureJVppCore; @@ -57,7 +56,7 @@ public class VrfSubtableCustomizer extends FutureJVppCustomizer super(futureJvpp); dumpManager = new DumpCacheManagerBuilder<OneEidTableMapDetailsReplyDump, SubtableDumpParams>() .withExecutor(createExecutor(futureJvpp)) - .acceptOnly(LispEidTableMapDetailsReplyDump.class) + .acceptOnly(OneEidTableMapDetailsReplyDump.class) .build(); } 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 index ab0ea797c..81256a3c5 100644 --- 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 @@ -26,9 +26,18 @@ import javax.annotation.Nonnull; public interface LispStateCheckService { /** + * Checks whether lisp is enabled while operating inside {@link WriteContext}. + * Covers cases when removing lisp data + * @throws IllegalStateException if lisp feature is disabled + */ + void checkLispEnabledBefore(@Nonnull final WriteContext ctx); + + /** * Checks whether lisp is enabled while operating inside {@link WriteContext} + * Covers cases when creating/updating lisp data + * @throws IllegalStateException if lisp feature is disabled */ - void checkLispEnabled(@Nonnull final WriteContext ctx); + void checkLispEnabledAfter(@Nonnull final WriteContext ctx); /** * Checks whether lisp is enabled while operating inside {@link ReadContext} 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 index a93f08349..65e409d53 100644 --- 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 @@ -52,7 +52,15 @@ public final class LispStateCheckServiceImpl implements LispStateCheckService, J .build(); } - public void checkLispEnabled(@Nonnull final WriteContext ctx) { + @Override + public void checkLispEnabledBefore(@Nonnull final WriteContext ctx) { + // no need to dump here, can be read directly from context + checkState(ctx.readBefore(InstanceIdentifier.create(Lisp.class)) + .or(STATIC_LISP_INSTANCE).isEnable(), "Lisp feature not enabled"); + } + + @Override + public void checkLispEnabledAfter(@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"); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/ItrRemoteLocatorSetCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/ItrRemoteLocatorSetCustomizer.java index 90dc0efb6..2674aa489 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/ItrRemoteLocatorSetCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/ItrRemoteLocatorSetCustomizer.java @@ -75,7 +75,11 @@ public class ItrRemoteLocatorSetCustomizer extends CheckedLispCustomizer impleme private void addDelItrRemoteLocatorSet(final boolean add, @Nonnull final ItrRemoteLocatorSet data, @Nonnull final WriteContext context) throws TimeoutException, VppBaseCallException { - lispStateCheckService.checkLispEnabled(context); + if (add) { + lispStateCheckService.checkLispEnabledAfter(context); + } else { + lispStateCheckService.checkLispEnabledBefore(context); + } OneAddDelMapRequestItrRlocs request = new OneAddDelMapRequestItrRlocs(); request.isAdd = booleanToByte(add); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizer.java index 04ca7262e..f8babdfcf 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizer.java @@ -72,7 +72,7 @@ public class LocatorSetCustomizer extends CheckedLispCustomizer public void writeCurrentAttributes(@Nonnull InstanceIdentifier<LocatorSet> id, @Nonnull LocatorSet dataAfter, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); checkState(isNonEmptyLocatorSet(writeContext.readAfter(id).get()), "Creating empty locator-sets is not allowed"); final String locatorSetName = dataAfter.getName(); @@ -99,7 +99,7 @@ public class LocatorSetCustomizer extends CheckedLispCustomizer public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<LocatorSet> id, @Nonnull LocatorSet dataBefore, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledBefore(writeContext); final String locatorSetName = dataBefore.getName(); final Optional<EidTable> eidTableData = writeContext.readAfter(InstanceIdentifier.create(Lisp.class) diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRegisterCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRegisterCustomizer.java index ff306e51c..cfa5618f9 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRegisterCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRegisterCustomizer.java @@ -41,6 +41,7 @@ public class MapRegisterCustomizer extends CheckedLispCustomizer public void writeCurrentAttributes(@Nonnull InstanceIdentifier<MapRegister> instanceIdentifier, @Nonnull MapRegister mapRegister, @Nonnull WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabledAfter(writeContext); enableDisableMapRegister(mapRegister.isEnabled(), instanceIdentifier, writeContext); } @@ -49,6 +50,7 @@ public class MapRegisterCustomizer extends CheckedLispCustomizer @Nonnull MapRegister mapRegisterBefore, @Nonnull MapRegister mapRegisterAfter, @Nonnull WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabledAfter(writeContext); enableDisableMapRegister(mapRegisterAfter.isEnabled(), instanceIdentifier, writeContext); } @@ -56,12 +58,12 @@ public class MapRegisterCustomizer extends CheckedLispCustomizer public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<MapRegister> instanceIdentifier, @Nonnull MapRegister mapRegister, @Nonnull WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabledBefore(writeContext); enableDisableMapRegister(false, instanceIdentifier, writeContext); } private void enableDisableMapRegister(final boolean enable, @Nonnull final InstanceIdentifier<MapRegister> id, @Nonnull final WriteContext context) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(context); OneMapRegisterEnableDisable request = new OneMapRegisterEnableDisable(); request.isEnabled = booleanToByte(enable); getReplyForWrite(getFutureJVpp().oneMapRegisterEnableDisable(request).toCompletableFuture(), id); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRequestModeCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRequestModeCustomizer.java index 64e66b2d4..1acfec7b6 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRequestModeCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRequestModeCustomizer.java @@ -44,7 +44,7 @@ public class MapRequestModeCustomizer extends CheckedLispCustomizer public void writeCurrentAttributes(@Nonnull InstanceIdentifier<MapRequestMode> instanceIdentifier, @Nonnull MapRequestMode mapRequestMode, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); getReplyForWrite(mapRequestModeRequestFuture(mapRequestMode), instanceIdentifier); } @@ -53,7 +53,7 @@ public class MapRequestModeCustomizer extends CheckedLispCustomizer @Nonnull MapRequestMode mapRequestModeBefore, @Nonnull MapRequestMode mapRequestModeAfter, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); getReplyForUpdate(mapRequestModeRequestFuture(mapRequestModeAfter), instanceIdentifier, mapRequestModeBefore, mapRequestModeAfter); } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizer.java index 934cc218a..b2d08700f 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizer.java @@ -51,7 +51,7 @@ public class MapResolverCustomizer extends CheckedLispCustomizer public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<MapResolver> id, @Nonnull final MapResolver dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); checkNotNull(dataAfter, "Data is null"); checkNotNull(dataAfter.getIpAddress(), "Address is null"); @@ -73,7 +73,7 @@ public class MapResolverCustomizer extends CheckedLispCustomizer public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<MapResolver> id, @Nonnull final MapResolver dataBefore, @Nonnull final WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledBefore(writeContext); checkNotNull(dataBefore, "Data is null"); checkNotNull(dataBefore.getIpAddress(), "Address is null"); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapServerCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapServerCustomizer.java index 6dc201516..306788a31 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapServerCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapServerCustomizer.java @@ -44,7 +44,7 @@ public class MapServerCustomizer extends CheckedLispCustomizer public void writeCurrentAttributes(@Nonnull InstanceIdentifier<MapServer> instanceIdentifier, @Nonnull MapServer mapServer, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); addDelMapServer(true, instanceIdentifier, mapServer); } @@ -59,7 +59,7 @@ public class MapServerCustomizer extends CheckedLispCustomizer @Override public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<MapServer> instanceIdentifier, @Nonnull MapServer mapServer, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledBefore(writeContext); addDelMapServer(false, instanceIdentifier, mapServer); } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PetrCfgCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PetrCfgCustomizer.java index 6c985ff0e..9d25c5fd7 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PetrCfgCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PetrCfgCustomizer.java @@ -44,7 +44,7 @@ public class PetrCfgCustomizer extends CheckedLispCustomizer public void writeCurrentAttributes(@Nonnull InstanceIdentifier<PetrCfg> instanceIdentifier, @Nonnull PetrCfg petrCfg, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); enablePetrCfg(instanceIdentifier, petrCfg); } @@ -53,7 +53,7 @@ public class PetrCfgCustomizer extends CheckedLispCustomizer @Nonnull PetrCfg petrCfgBefore, @Nonnull PetrCfg petrCfgAfter, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); if (petrCfgAfter.getPetrAddress() != null) { enablePetrCfg(instanceIdentifier, petrCfgAfter); } else { @@ -63,7 +63,7 @@ public class PetrCfgCustomizer extends CheckedLispCustomizer @Override public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<PetrCfg> instanceIdentifier, @Nonnull PetrCfg petrCfg, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledBefore(writeContext); disablePetrCfg(instanceIdentifier); } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizer.java index 6944940c1..1597fe4eb 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizer.java @@ -51,7 +51,7 @@ public class PitrCfgCustomizer extends CheckedLispCustomizer @Override public void writeCurrentAttributes(InstanceIdentifier<PitrCfg> id, PitrCfg dataAfter, WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); checkNotNull(dataAfter, "PitrCfg is null"); checkNotNull(dataAfter.getLocatorSet(), "Locator set name is null"); @@ -65,7 +65,7 @@ public class PitrCfgCustomizer extends CheckedLispCustomizer @Override public void updateCurrentAttributes(InstanceIdentifier<PitrCfg> id, PitrCfg dataBefore, PitrCfg dataAfter, WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); checkNotNull(dataAfter, "PitrCfg is null"); checkNotNull(dataAfter.getLocatorSet(), "Locator set name is null"); @@ -79,7 +79,7 @@ public class PitrCfgCustomizer extends CheckedLispCustomizer @Override public void deleteCurrentAttributes(InstanceIdentifier<PitrCfg> id, PitrCfg dataBefore, WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledBefore(writeContext); checkNotNull(dataBefore, "PitrCfg is null"); checkNotNull(dataBefore.getLocatorSet(), "Locator set name is null"); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/RlocProbeCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/RlocProbeCustomizer.java index e984a16d1..ebe00ec03 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/RlocProbeCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/RlocProbeCustomizer.java @@ -41,7 +41,7 @@ public class RlocProbeCustomizer extends CheckedLispCustomizer public void writeCurrentAttributes(@Nonnull InstanceIdentifier<RlocProbe> instanceIdentifier, @Nonnull RlocProbe rlocProbe, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); enableDisableRlocProbe(rlocProbe.isEnabled(), instanceIdentifier); } @@ -50,7 +50,7 @@ public class RlocProbeCustomizer extends CheckedLispCustomizer @Nonnull RlocProbe rlocProbeBefore, @Nonnull RlocProbe rlocProbeAfter, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); enableDisableRlocProbe(rlocProbeAfter.isEnabled(), instanceIdentifier); } @@ -58,7 +58,7 @@ public class RlocProbeCustomizer extends CheckedLispCustomizer public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<RlocProbe> instanceIdentifier, @Nonnull RlocProbe rlocProbe, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledBefore(writeContext); enableDisableRlocProbe(false, instanceIdentifier); } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizer.java index e6fe3db45..0cc939392 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizer.java @@ -46,7 +46,7 @@ public class VniTableCustomizer extends CheckedLispCustomizer implements ListWri @Override public void writeCurrentAttributes(InstanceIdentifier<VniTable> id, VniTable dataAfter, WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); checkAtLeastOnChildExists(id, writeContext, false); } @@ -59,7 +59,7 @@ public class VniTableCustomizer extends CheckedLispCustomizer implements ListWri @Override public void deleteCurrentAttributes(InstanceIdentifier<VniTable> id, VniTable dataBefore, WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledBefore(writeContext); checkAtLeastOnChildExists(id, writeContext, true); } |