diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2017-04-10 16:11:03 +0200 |
---|---|---|
committer | Jan Srnicek <jsrnicek@cisco.com> | 2017-04-10 14:18:06 +0000 |
commit | 222fbb843a17606b48f24974fdb6399dc0e9ce4e (patch) | |
tree | 2b64952a04def954f4935ec39a3045f2324e6f89 /lisp | |
parent | c0b6df8bc6bde942acd29fe426ab90e7edec4443 (diff) |
HC2VPP-126 - Eid context artificial prefix
Artificial prefix for mappings that are not present
Change-Id: I789750e3877918b2e15ba19871da1bf8bc4e207b
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'lisp')
5 files changed, 30 insertions, 20 deletions
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/LispModule.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/LispModule.java index 5324eec2d..3c09f9b1b 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/LispModule.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/LispModule.java @@ -67,12 +67,12 @@ public class LispModule extends AbstractModule { LOG.info("Binding Eid context[{}]", LOCAL_MAPPING_CONTEXT); bind(EidMappingContext.class) .annotatedWith(Names.named(LOCAL_MAPPING_CONTEXT)) - .toInstance(new EidMappingContext(LOCAL_MAPPING_CONTEXT)); + .toInstance(new EidMappingContext(LOCAL_MAPPING_CONTEXT, "local-mapping-")); LOG.info("Binding Eid context[{}]", REMOTE_MAPPING_CONTEXT); bind(EidMappingContext.class) .annotatedWith(Names.named(REMOTE_MAPPING_CONTEXT)) - .toInstance(new EidMappingContext(REMOTE_MAPPING_CONTEXT)); + .toInstance(new EidMappingContext(REMOTE_MAPPING_CONTEXT, "remote-mapping-")); LOG.info("Binding Adjacencies context"); bind(AdjacenciesMappingContext.class) diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/context/util/EidMappingContext.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/context/util/EidMappingContext.java index e32138b47..5288a609d 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/context/util/EidMappingContext.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/context/util/EidMappingContext.java @@ -17,7 +17,6 @@ package io.fd.hc2vpp.lisp.context.util; import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkState; import com.google.common.base.Optional; import io.fd.hc2vpp.lisp.translate.util.EidTranslator; @@ -36,8 +35,6 @@ import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.MappingId; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Utility class allowing {@link MappingId} to {@link Eid} mapping @@ -48,16 +45,18 @@ public class EidMappingContext implements EidTranslator { private final KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.EidMappingContext, EidMappingContextKey> namingContextIid; + private final String artificialPrefix; /** * Create new naming context * * @param instanceName name of this context instance. Will be used as list item identifier within context data tree */ - public EidMappingContext(@Nonnull final String instanceName) { + public EidMappingContext(@Nonnull final String instanceName, @Nonnull final String artificialPrefix) { namingContextIid = InstanceIdentifier.create(Contexts.class).child( org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.EidMappingContext.class, new EidMappingContextKey(instanceName)); + this.artificialPrefix = artificialPrefix; } /** @@ -73,7 +72,11 @@ public class EidMappingContext implements EidTranslator { @Nonnull final MappingContext mappingContext) { final Optional<Mappings> read = mappingContext.read(namingContextIid.child(Mappings.class)); - checkState(read.isPresent(), "Mapping for eid: %s is not present. But should be", remoteEid); + if (!read.isPresent()) { + final MappingId artificialMappingId = getMappingId(remoteEid.toString(), artificialPrefix); + addEid(artificialMappingId, remoteEid, mappingContext); + return artificialMappingId; + } return read.get().getMapping() .stream() @@ -82,6 +85,10 @@ public class EidMappingContext implements EidTranslator { .collect(SINGLE_ITEM_COLLECTOR).getId(); } + private static MappingId getMappingId(final String eidValue, final String artificialPrefix) { + return new MappingId(artificialPrefix.concat(eidValue)); + } + /** * Retrieve name for mapping stored provided mappingContext instance. * @@ -95,8 +102,11 @@ public class EidMappingContext implements EidTranslator { @Nonnull final MappingContext mappingContext) { final Optional<Mappings> read = mappingContext.read(namingContextIid.child(Mappings.class)); - //don't create artificial name as naming context, to not create reference to some artificial(in vpp non-existing)eid - checkState(read.isPresent(), "Mapping for eid: %s is not present. But should be", eid); + if (!read.isPresent()) { + final MappingId artificialMappingId = getMappingId(eid.toString(), artificialPrefix); + addEid(artificialMappingId, eid, mappingContext); + return artificialMappingId; + } return read.get().getMapping().stream() .filter(mapping -> compareEids(mapping.getEid(), eid)) diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/context/util/EidMappingContextTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/context/util/EidMappingContextTest.java index bb70bd358..f4325b00c 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/context/util/EidMappingContextTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/context/util/EidMappingContextTest.java @@ -17,6 +17,9 @@ package io.fd.hc2vpp.lisp.context.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import io.fd.hc2vpp.lisp.util.EidMappingContextHelper; import io.fd.honeycomb.translate.MappingContext; import org.junit.Before; @@ -30,9 +33,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.dp.subtable.grouping.local.mappings.local.mapping.Eid; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class EidMappingContextTest implements EidMappingContextHelper { private static final String EID_MAPPING_CONTEXT_NAME = "eidMappingContext"; @@ -51,7 +51,7 @@ public class EidMappingContextTest implements EidMappingContextHelper { @Before public void init() { MockitoAnnotations.initMocks(this); - eidMappingContext = new EidMappingContext(EID_MAPPING_CONTEXT_NAME); + eidMappingContext = new EidMappingContext(EID_MAPPING_CONTEXT_NAME, "eid-ctx-"); localEid = new EidBuilder().setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build()).build(); diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/AdjacencyCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/AdjacencyCustomizerTest.java index 8a78c6e76..264fe6ccb 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/AdjacencyCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/AdjacencyCustomizerTest.java @@ -29,14 +29,14 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Mockito.when; +import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; import io.fd.hc2vpp.lisp.context.util.AdjacenciesMappingContext; import io.fd.hc2vpp.lisp.context.util.EidMappingContext; import io.fd.hc2vpp.lisp.translate.util.EidMetadataProvider; import io.fd.hc2vpp.lisp.util.AdjacencyMappingContextTestHelper; import io.fd.hc2vpp.lisp.util.EidMappingContextHelper; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; import io.fd.vpp.jvpp.core.dto.LispAdjacenciesGetReply; import io.fd.vpp.jvpp.core.types.LispAdjacency; import java.util.List; @@ -115,8 +115,8 @@ public class AdjacencyCustomizerTest @Override protected ReaderCustomizer<Adjacency, AdjacencyBuilder> initCustomizer() { - return new AdjacencyCustomizer(api, new EidMappingContext("local-mapping-context"), - new EidMappingContext("remote-mapping-context"), + return new AdjacencyCustomizer(api, new EidMappingContext("local-mapping-context", "local-mapping-"), + new EidMappingContext("remote-mapping-context", "remote-mapping-"), new AdjacenciesMappingContext("adjacencies-mapping-context")); } diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizerTest.java index ae5cd351c..91087a879 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizerTest.java @@ -30,10 +30,10 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; import io.fd.hc2vpp.lisp.context.util.AdjacenciesMappingContext; import io.fd.hc2vpp.lisp.context.util.EidMappingContext; import io.fd.hc2vpp.lisp.util.EidMappingContextHelper; -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; import io.fd.vpp.jvpp.core.dto.LispAddDelAdjacency; import io.fd.vpp.jvpp.core.dto.LispAddDelAdjacencyReply; import org.junit.Before; @@ -87,8 +87,8 @@ public class AdjacencyCustomizerTest extends WriterCustomizerTest implements Eid @Before public void init() { - localMappingContext = new EidMappingContext("local-mapping-context"); - remoteMappingContext = new EidMappingContext("remote-mapping-context"); + localMappingContext = new EidMappingContext("local-mapping-context", "local-mapping-"); + remoteMappingContext = new EidMappingContext("remote-mapping-context", "remote-mapping-"); customizer = new AdjacencyCustomizer(api, localMappingContext, remoteMappingContext, adjacenciesMappingContext); emptyId = InstanceIdentifier.create(Adjacency.class); |