summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xlisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/LispStateCustomizer.java57
-rwxr-xr-xlisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/LocatorSetCustomizer.java20
-rwxr-xr-xlisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/LispStateReaderFactory.java2
-rwxr-xr-xlisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/LocatorSetReaderFactory.java2
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LispStateCustomizerTest.java92
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LocatorSetCustomizerTest.java3
6 files changed, 140 insertions, 36 deletions
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/LispStateCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/LispStateCustomizer.java
index 529eb78dd..336accc0c 100755
--- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/LispStateCustomizer.java
+++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/LispStateCustomizer.java
@@ -17,17 +17,26 @@
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.common.translate.util.NamingContext;
+import io.fd.hc2vpp.lisp.translate.read.trait.LocatorSetReader;
import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.read.ReadFailedException;
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.vpp.jvpp.VppBaseCallException;
+import io.fd.vpp.jvpp.core.dto.LispLocatorSetDetailsReplyDump;
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 java.util.concurrent.TimeoutException;
+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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.LispState;
@@ -38,20 +47,27 @@ 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 that handles reads of {@code LispState}
*/
public class LispStateCustomizer extends FutureJVppCustomizer
- implements InitializingReaderCustomizer<LispState, LispStateBuilder>, JvppReplyConsumer, ByteDataTranslator {
+ implements InitializingReaderCustomizer<LispState, LispStateBuilder>, JvppReplyConsumer, ByteDataTranslator,
+ LocatorSetReader {
private static final Logger LOG = LoggerFactory.getLogger(LispStateCustomizer.class);
- public LispStateCustomizer(FutureJVppCore futureJvpp) {
+ private final NamingContext locatorSetContext;
+ private final DumpCacheManager<LispLocatorSetDetailsReplyDump, Void> dumpManager;
+
+ public LispStateCustomizer(@Nonnull final FutureJVppCore futureJvpp,
+ @Nonnull final NamingContext locatorSetContext) {
super(futureJvpp);
+ this.locatorSetContext = locatorSetContext;
+ this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder<LispLocatorSetDetailsReplyDump, Void>()
+ .withExecutor(createExecutor(futureJvpp))
+ .acceptOnly(LispLocatorSetDetailsReplyDump.class)
+ .build();
}
@Override
@@ -82,8 +98,37 @@ public class LispStateCustomizer extends FutureJVppCustomizer
public Initialized<Lisp> init(
@Nonnull final InstanceIdentifier<LispState> id, @Nonnull final LispState readValue,
@Nonnull final ReadContext ctx) {
- return Initialized.create(InstanceIdentifier.create(Lisp.class),
+ /* TODO - HONEYCOMB-354 - must be done here(most upper node), because of ordering issues
+ In this case it will work fully, locator sets are not referenced from any outside model
+ */
+ final Optional<LispLocatorSetDetailsReplyDump> dumpOptional;
+ try {
+ dumpOptional = dumpManager.getDump(id, ctx.getModificationCache(), NO_PARAMS);
+ } catch (ReadFailedException e) {
+ throw new IllegalStateException("Unable to initialize locator set context mapping", e);
+ }
+ if (dumpOptional.isPresent() && !dumpOptional.get().lispLocatorSetDetails.isEmpty()) {
+ LOG.debug("Initializing locator set context for {}", dumpOptional.get());
+ dumpOptional.get().lispLocatorSetDetails
+ .forEach(set -> {
+ final String locatorSetName = toString(set.lsName);
+ //creates mapping for existing locator-set(if it is'nt already existing one)
+ synchronized (locatorSetContext) {
+ if (!locatorSetContext.containsIndex(locatorSetName, ctx.getMappingContext())) {
+ locatorSetContext.addName(set.lsIndex, locatorSetName, ctx.getMappingContext());
+ }
+ }
+
+ LOG.trace("Locator Set with name: {}, VPP name: {} and index: {} found in VPP",
+ locatorSetContext.getName(set.lsIndex, ctx.getMappingContext()),
+ locatorSetName,
+ set.lsIndex);
+ });
+ LOG.debug("Locator set context initialized");
+ }
+
+ return Initialized.create(InstanceIdentifier.create(Lisp.class),
// set everything from LispState to LispBuilder
// this is necessary in cases, when HC connects to a running VPP with some LISP configuration. HC needs to
// reconstruct configuration based on what's present in VPP in order to support subsequent configuration changes
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/LocatorSetCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/LocatorSetCustomizer.java
index 4e23347c9..75bf078f9 100755
--- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/LocatorSetCustomizer.java
+++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/LocatorSetCustomizer.java
@@ -16,12 +16,10 @@
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.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;
@@ -55,13 +53,10 @@ public class LocatorSetCustomizer extends CheckedLispCustomizer
private static final Logger LOG = LoggerFactory.getLogger(LocatorSetCustomizer.class);
private final DumpCacheManager<LispLocatorSetDetailsReplyDump, Void> dumpManager;
- private final NamingContext locatorSetContext;
public LocatorSetCustomizer(@Nonnull final FutureJVppCore 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))
.acceptOnly(LispLocatorSetDetailsReplyDump.class)
@@ -125,21 +120,6 @@ public class LocatorSetCustomizer extends CheckedLispCustomizer
}
return dumpOptional.get().lispLocatorSetDetails.stream()
- .map(set -> {
-
- final String locatorSetName = toString(set.lsName);
- //creates mapping for existing locator-set(if it is'nt already existing one)
- if (!locatorSetContext.containsIndex(locatorSetName, context.getMappingContext())) {
- locatorSetContext.addName(set.lsIndex, locatorSetName, context.getMappingContext());
- }
-
- LOG.trace("Locator Set with name: {}, VPP name: {} and index: {} found in VPP",
- locatorSetContext.getName(set.lsIndex, context.getMappingContext()),
- locatorSetName,
- set.lsIndex);
-
- return set;
- })
.map(set -> new LocatorSetKey(toString(set.lsName)))
.collect(Collectors.toList());
}
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/LispStateReaderFactory.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/LispStateReaderFactory.java
index 7757d0822..cf452bec5 100755
--- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/LispStateReaderFactory.java
+++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/LispStateReaderFactory.java
@@ -50,7 +50,7 @@ public class LispStateReaderFactory extends AbstractLispInfraFactoryBase impleme
@Override
public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) {
- registry.add(new GenericInitReader<>(lispStateId, new LispStateCustomizer(vppApi)));
+ registry.add(new GenericInitReader<>(lispStateId, new LispStateCustomizer(vppApi, locatorSetContext)));
registry.addStructuralReader(lispStateId.child(LispFeatureData.class), LispFeatureDataBuilder.class);
registry.add(new GenericInitReader<>(LISP_FEATURE_ID.child(PitrCfg.class),
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/LocatorSetReaderFactory.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/LocatorSetReaderFactory.java
index 75faf0b8f..24e5ed9f5 100755
--- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/LocatorSetReaderFactory.java
+++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/factory/LocatorSetReaderFactory.java
@@ -47,7 +47,7 @@ public class LocatorSetReaderFactory extends AbstractLispInfraFactoryBase implem
registry.addStructuralReader(locatorSetsInstanceIdentifier, LocatorSetsBuilder.class);
registry.add(new GenericInitListReader<>(locatorSetInstanceIdentifier,
- new LocatorSetCustomizer(vppApi, locatorSetContext, lispStateCheckService)));
+ new LocatorSetCustomizer(vppApi, lispStateCheckService)));
registry.add(new GenericInitListReader<>(locatorSetInstanceIdentifier.child(Interface.class),
new InterfaceCustomizer(vppApi, interfaceContext, locatorSetContext)));
}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LispStateCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LispStateCustomizerTest.java
index 06eda220f..e253b324a 100644
--- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LispStateCustomizerTest.java
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LispStateCustomizerTest.java
@@ -16,32 +16,54 @@
package io.fd.hc2vpp.lisp.translate.read;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet;
import io.fd.hc2vpp.common.test.read.InitializingReaderCustomizerTest;
+import io.fd.hc2vpp.common.test.util.NamingContextHelper;
+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.read.ReadFailedException;
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 io.fd.vpp.jvpp.core.dto.ShowLispStatusReply;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.Contexts;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContextKey;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.MappingsBuilder;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingBuilder;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingKey;
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.LispStateBuilder;
import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.when;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
@RunWith(HoneycombTestRunner.class)
public class LispStateCustomizerTest extends InitializingReaderCustomizerTest<LispState, LispStateBuilder>
- implements InjectablesProcessor{
+ implements InjectablesProcessor, NamingContextHelper {
+
+
+ private NamingContext locatorSetContext;
private InstanceIdentifier<LispState> identifier;
@@ -49,13 +71,15 @@ public class LispStateCustomizerTest extends InitializingReaderCustomizerTest<Li
super(LispState.class, null);
}
+ @Override
@Before
- public void init() {
+ public void setUp() {
identifier = InstanceIdentifier.create(LispState.class);
final ShowLispStatusReply reply = new ShowLispStatusReply();
reply.featureStatus = 1;
when(api.showLispStatus(Mockito.any())).thenReturn(future(reply));
+ locatorSetContext = new NamingContext("loc-set", "locator-set-context");
}
@Test
@@ -79,12 +103,68 @@ public class LispStateCustomizerTest extends InitializingReaderCustomizerTest<Li
final InstanceIdentifier<LispState> operationalPath = InstanceIdentifier.create(LispState.class);
final InstanceIdentifier<Lisp> configPath = InstanceIdentifier.create(Lisp.class);
+ when(api.lispLocatorSetDump(any())).thenReturn(future(new LispLocatorSetDetailsReplyDump()));
+
+ invokeInitTest(operationalPath, operational, configPath, config);
+ }
+
+ @Test
+ public void testInitWithLocatorSetContextInit(@InjectTestData(resourcePath = "/lisp-config.json") Lisp config,
+ @InjectTestData(resourcePath = "/lisp-operational.json") LispState operational) {
+ mockLocatorSetDump();
+ final InstanceIdentifier<LispState> operationalPath = InstanceIdentifier.create(LispState.class);
+ final InstanceIdentifier<Lisp> configPath = InstanceIdentifier.create(Lisp.class);
+
+ final KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContext, NamingContextKey>
+ namingContextId = InstanceIdentifier.create(Contexts.class).child(
+ org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContext.class,
+ new NamingContextKey("locator-set-context"));
+ final KeyedInstanceIdentifier<Mapping, MappingKey> loc1Key = namingContextId
+ .child(Mappings.class).child(Mapping.class, new MappingKey("loc_1"));
+
+ final Mapping loc1Data = new MappingBuilder().setIndex(0).setName("loc_1").build();
+
+ final KeyedInstanceIdentifier<Mapping, MappingKey> loc2Key = namingContextId
+ .child(Mappings.class).child(Mapping.class, new MappingKey("loc_2"));
+
+ final Mapping loc2Data = new MappingBuilder().setIndex(1).setName("loc_2").build();
+
+ when(mappingContext.read(namingContextId.child(Mappings.class)))
+ .thenReturn(Optional.of(new MappingsBuilder().setMapping(Arrays.asList(loc1Data, loc2Data)).build()));
+ when(mappingContext.read(loc1Key)).thenReturn(Optional.absent())
+ .thenReturn(Optional.of(loc1Data)).thenReturn(Optional.of(loc1Data));
+ when(mappingContext.read(loc2Key)).thenReturn(Optional.absent())
+ .thenReturn(Optional.of(loc2Data)).thenReturn(Optional.of(loc2Data));
+
+
invokeInitTest(operationalPath, operational, configPath, config);
+
+ // first read is inside contains,second one is for logger,and its x 2 locator sets
+ verify(mappingContext, times(4)).read(namingContextId.child(Mappings.class));
+ verify(mappingContext, times(1)).put(loc1Key, loc1Data);
+ verify(mappingContext, times(1)).read(loc1Key);
+ verify(mappingContext, times(1)).put(loc2Key, loc2Data);
+ verify(mappingContext, times(1)).read(loc2Key);
+ verifyNoMoreInteractions(mappingContext);
+ }
+
+ private void mockLocatorSetDump() {
+ LispLocatorSetDetailsReplyDump replyDump = new LispLocatorSetDetailsReplyDump();
+ LispLocatorSetDetails locator1 = new LispLocatorSetDetails();
+ locator1.lsIndex = 0;
+ locator1.lsName = "loc_1".getBytes(StandardCharsets.UTF_8);
+ LispLocatorSetDetails locator2 = new LispLocatorSetDetails();
+ locator2.lsIndex = 1;
+ locator2.lsName = "loc_2".getBytes(StandardCharsets.UTF_8);
+
+ replyDump.lispLocatorSetDetails = Arrays.asList(locator1, locator2);
+
+ when(api.lispLocatorSetDump(any())).thenReturn(future(replyDump));
}
@Override
protected ReaderCustomizer<LispState, LispStateBuilder> initCustomizer() {
- return new LispStateCustomizer(api);
+ return new LispStateCustomizer(api, locatorSetContext);
}
@Override
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LocatorSetCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LocatorSetCustomizerTest.java
index 82c4ceff2..419173857 100644
--- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LocatorSetCustomizerTest.java
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LocatorSetCustomizerTest.java
@@ -22,7 +22,6 @@ import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableList;
-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.translate.spi.read.ReaderCustomizer;
@@ -119,6 +118,6 @@ public class LocatorSetCustomizerTest
@Override
protected ReaderCustomizer<LocatorSet, LocatorSetBuilder> initCustomizer() {
- return new LocatorSetCustomizer(api, new NamingContext("loc", "locator-set-context"), lispStateCheckService);
+ return new LocatorSetCustomizer(api, lispStateCheckService);
}
} \ No newline at end of file