diff options
Diffstat (limited to 'lisp/lisp2vpp/src/main/java')
-rw-r--r-- | lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/LispModule.java | 4 | ||||
-rw-r--r-- | lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/context/util/EidMappingContext.java | 24 |
2 files changed, 19 insertions, 9 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)) |