diff options
Diffstat (limited to 'lisp/lisp2vpp')
75 files changed, 3335 insertions, 506 deletions
diff --git a/lisp/lisp2vpp/pom.xml b/lisp/lisp2vpp/pom.xml index 7506f1e0c..38f569a32 100755 --- a/lisp/lisp2vpp/pom.xml +++ b/lisp/lisp2vpp/pom.xml @@ -106,5 +106,6 @@ <version>${project.version}</version> <scope>test</scope> </dependency> + </dependencies> </project> diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/LispModule.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/LispModule.java index 5344dfc7f..2317b49f7 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/LispModule.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/LispModule.java @@ -23,10 +23,12 @@ import static io.fd.honeycomb.lisp.cfgattrs.LispConfiguration.LOCATOR_SET_CONTEX import static io.fd.honeycomb.lisp.cfgattrs.LispConfiguration.REMOTE_MAPPING_CONTEXT; import com.google.inject.AbstractModule; +import com.google.inject.Singleton; import com.google.inject.multibindings.Multibinder; import com.google.inject.name.Names; import io.fd.honeycomb.data.init.DataTreeInitializer; import io.fd.honeycomb.lisp.cfgattrs.LispConfiguration; +import io.fd.honeycomb.lisp.context.util.ContextsReaderFactoryProvider; import io.fd.honeycomb.lisp.context.util.EidMappingContext; import io.fd.honeycomb.lisp.translate.initializers.LispInitializer; import io.fd.honeycomb.lisp.translate.read.factory.LispStateReaderFactory; @@ -44,10 +46,8 @@ public class LispModule extends AbstractModule { @Override protected void configure() { - LOG.info("Installing configuration module"); + LOG.info("Configuring module Lisp"); install(ConfigurationModule.create()); - - LOG.info("Injecting Lisp configuration"); requestInjection(LispConfiguration.class); LOG.info("Binding Naming context[{}]", LOCATOR_SET_CONTEXT); @@ -67,26 +67,23 @@ public class LispModule extends AbstractModule { LOG.info("Binding reader factories"); final Multibinder<ReaderFactory> readerFactoryBinder = Multibinder.newSetBinder(binder(), ReaderFactory.class); - - LOG.info("Binding [{}]", LispStateReaderFactory.class.getName()); readerFactoryBinder.addBinding().to(LispStateReaderFactory.class); LOG.info("Reader factories binded"); LOG.info("Binding writer factories"); final Multibinder<WriterFactory> writerFactoryBinder = Multibinder.newSetBinder(binder(), WriterFactory.class); - - LOG.info("Binding [{}]", LispWriterFactory.class.getName()); writerFactoryBinder.addBinding().to(LispWriterFactory.class); LOG.info("Writer factories binded"); LOG.info("Binding initializers"); final Multibinder<DataTreeInitializer> initializerBinder = Multibinder.newSetBinder(binder(), DataTreeInitializer.class); - - LOG.info("Binding [{}]", LispInitializer.class.getName()); initializerBinder.addBinding().to(LispInitializer.class); LOG.info("Initializers binded"); + final Multibinder<ReaderFactory> readerBinder = Multibinder.newSetBinder(binder(), ReaderFactory.class); + readerBinder.addBinding().toProvider(ContextsReaderFactoryProvider.class).in(Singleton.class); + LOG.info("Module Lisp successfully configured"); } } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/cfgattrs/LispConfiguration.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/cfgattrs/LispConfiguration.java index dae41cebd..75083468c 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/cfgattrs/LispConfiguration.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/cfgattrs/LispConfiguration.java @@ -53,11 +53,6 @@ public class LispConfiguration { public static final String HONEYCOMB_INITIALIZER = "honeycomb-initializer"; /** - * Unique prefix for naming context of interfaces. - **/ - public static final String INTERFACE_CONTEXT_PREFIX = "interface-"; - - /** * Unique prefix for naming context of locator sets. **/ public static final String LOCATOR_SET_CONTEXT_PREFIX = "locator-set-"; diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/context/util/ContextsReaderFactory.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/context/util/ContextsReaderFactory.java new file mode 100644 index 000000000..29a5e3fd4 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/context/util/ContextsReaderFactory.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2016 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.honeycomb.lisp.context.util; + +import io.fd.honeycomb.translate.read.ReaderFactory; +import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; +import io.fd.honeycomb.translate.util.read.BindingBrokerReader; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.Contexts; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.ContextsBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * {@link ReaderFactory} initiating reader providing data from context data store for eid's. + * Making them available over RESTCONF/NETCONF. + */ +public class ContextsReaderFactory implements ReaderFactory { + + private final DataBroker contextBindingBrokerDependency; + + public ContextsReaderFactory(final DataBroker contextBindingBrokerDependency) { + this.contextBindingBrokerDependency = contextBindingBrokerDependency; + } + + @Override + public void init(final ModifiableReaderRegistryBuilder registry) { + registry.add(new BindingBrokerReader<>(InstanceIdentifier.create(Contexts.class), + contextBindingBrokerDependency, + LogicalDatastoreType.OPERATIONAL, ContextsBuilder.class)); + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/context/util/ContextsReaderFactoryProvider.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/context/util/ContextsReaderFactoryProvider.java new file mode 100644 index 000000000..d023b3e9f --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/context/util/ContextsReaderFactoryProvider.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2016 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.honeycomb.lisp.context.util; + +import com.google.inject.Inject; +import com.google.inject.Provider; +import com.google.inject.name.Named; +import io.fd.honeycomb.translate.read.ReaderFactory; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; + + +public class ContextsReaderFactoryProvider implements Provider<ReaderFactory> { + + @Inject + @Named("honeycomb-context") + private DataBroker contextDataBroker; + + @Override + public ReaderFactory get() { + return new ContextsReaderFactory(contextDataBroker); + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/context/util/EidMappingContext.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/context/util/EidMappingContext.java index 153061ef5..d9513e10e 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/context/util/EidMappingContext.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/context/util/EidMappingContext.java @@ -17,6 +17,7 @@ package io.fd.honeycomb.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.honeycomb.lisp.translate.util.EidTranslator; @@ -35,12 +36,15 @@ 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.rev160520.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 */ public class EidMappingContext implements EidTranslator { + private static final Logger LOG = LoggerFactory.getLogger(EidMappingContext.class); private static final Collector<Mapping, ?, Mapping> SINGLE_ITEM_COLLECTOR = RWUtils.singleItemCollector(); private final KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.EidMappingContext, EidMappingContextKey> @@ -60,22 +64,22 @@ public class EidMappingContext implements EidTranslator { /** * Retrieve name for mapping stored provided mappingContext instance. * - * @param eid eid of a mapped item + * @param remoteEid eid of a mapped item * @param mappingContext mapping context providing context data for current transaction * @return name mapped to provided index */ @Nonnull public synchronized MappingId getId( - @Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.Eid eid, + @Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid remoteEid, @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); - //dont create artificial name as naming context, to not create refference to some artificial(in vpp non-existing)eid - checkArgument(read.isPresent(), "No mapping stored for eid: %s", eid); - - return read.get().getMapping().stream() - .filter(mapping -> compareEids(mapping.getEid(), eid)) + return read.get().getMapping() + .stream() + //cannot split to map + filtering,because its collecting mappings,not eid's + .filter(mapping -> compareEids(mapping.getEid(), remoteEid)) .collect(SINGLE_ITEM_COLLECTOR).getId(); } @@ -88,21 +92,13 @@ public class EidMappingContext implements EidTranslator { */ @Nonnull public synchronized MappingId getId( - @Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.Eid eid, + @Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid eid, @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); - //dont create artificial name as naming context, to not create refference to some artificial(in vpp non-existing)eid - checkArgument(read.isPresent(), "No mapping stored for eid: %s", eid); - - //this kind of comparing is needed ,because yang generated containers does not override equals,unless they are defined as types - //in this hierarchy the first that define proper equals is Ipv4Address/Ipv6Address/MacAddress - // - // From official javadoc - // The equals method for class Object implements the most discriminating possible equivalence relation on objects; - // that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object - // (x == y has the value true). return read.get().getMapping().stream() .filter(mapping -> compareEids(mapping.getEid(), eid)) .collect(SINGLE_ITEM_COLLECTOR).getId(); @@ -116,16 +112,14 @@ public class EidMappingContext implements EidTranslator { * @return true if present, false otherwise */ public synchronized boolean containsId( - @Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.Eid eid, + @Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid eid, @Nonnull final MappingContext mappingContext) { final Optional<Mappings> read = mappingContext.read(namingContextIid.child(Mappings.class)); - //dont create artificial name as naming context, to not create refference to some artificial(in vpp non-existing)eid - checkArgument(read.isPresent(), "No mapping stored for eid: %s", eid); - - return read.isPresent() - ? read.get().getMapping().stream().anyMatch(mapping -> compareEids(mapping.getEid(), eid)) - : false; + return read.isPresent() && + read.get().getMapping() + .stream() + .anyMatch(mapping -> compareEids(mapping.getEid(), eid)); } /** @@ -136,15 +130,14 @@ public class EidMappingContext implements EidTranslator { * @return true if present, false otherwise */ public synchronized boolean containsId( - @Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.Eid eid, + @Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid eid, @Nonnull final MappingContext mappingContext) { final Optional<Mappings> read = mappingContext.read(namingContextIid.child(Mappings.class)); - checkArgument(read.isPresent(), "No mapping stored for eid: %s", eid); - - return read.isPresent() - ? read.get().getMapping().stream().anyMatch(mapping -> compareEids(mapping.getEid(), eid)) - : false; + return read.isPresent() && + read.get().getMapping() + .stream() + .anyMatch(mapping -> compareEids(mapping.getEid(), eid)); } @@ -157,11 +150,10 @@ public class EidMappingContext implements EidTranslator { */ public synchronized void addEid( @Nonnull final MappingId index, - @Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.Eid eid, + @Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid eid, final MappingContext mappingContext) { final KeyedInstanceIdentifier<Mapping, MappingKey> mappingIid = getMappingIid(index); - //this copy is needed (type of eid in mapping is different that in local mapping,they only have same ancestor) mappingContext.put(mappingIid, new MappingBuilder().setId(index).setEid(copyEid(eid)).build()); } @@ -174,7 +166,7 @@ public class EidMappingContext implements EidTranslator { */ public synchronized void addEid( @Nonnull final MappingId index, - @Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.Eid eid, + @Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid eid, final MappingContext mappingContext) { final KeyedInstanceIdentifier<Mapping, MappingKey> mappingIid = getMappingIid(index); @@ -186,13 +178,13 @@ public class EidMappingContext implements EidTranslator { } private Eid copyEid( - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.Eid eid) { + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid eid) { return new EidBuilder().setAddress(eid.getAddress()).setAddressType(eid.getAddressType()) .setVirtualNetworkId(eid.getVirtualNetworkId()).build(); } private Eid copyEid( - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.Eid eid) { + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid eid) { return new EidBuilder().setAddress(eid.getAddress()).setAddressType(eid.getAddressType()) .setVirtualNetworkId(eid.getVirtualNetworkId()).build(); } @@ -218,7 +210,7 @@ public class EidMappingContext implements EidTranslator { public synchronized Eid getEid(@Nonnull final MappingId index, final MappingContext mappingContext) { final Optional<Mapping> read = mappingContext.read(getMappingIid(index)); checkArgument(read.isPresent(), "No mapping stored for index: %s", index); - return mappingContext.read(getMappingIid(index)).get().getEid(); + return read.get().getEid(); } /** diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/initializers/LispInitializer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/initializers/LispInitializer.java index 105ee0aec..690d2a91a 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/initializers/LispInitializer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/initializers/LispInitializer.java @@ -58,11 +58,7 @@ public class LispInitializer extends AbstractDataTreeConverter<LispState, Lisp> // configuration can fail) return lispBuilder.setEnable(operationalData.isEnable()) - .setEidTable(operationalData.getEidTable()) - .setLocatorSets(operationalData.getLocatorSets()) - .setMapResolvers(operationalData.getMapResolvers()) - .setPitrCfg(operationalData.getPitrCfg()) + .setLispFeatureData(operationalData.getLispFeatureData()) .build(); } - } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/AdjacencyCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/AdjacencyCustomizer.java index 373de70b3..ef5de97f2 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/AdjacencyCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/AdjacencyCustomizer.java @@ -25,10 +25,10 @@ import java.util.Collections; import java.util.List; import javax.annotation.Nonnull; import javax.naming.OperationNotSupportedException; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.AdjacenciesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.Adjacency; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.AdjacencyBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.AdjacencyKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.AdjacenciesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.Adjacency; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.AdjacencyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.AdjacencyKey; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/BridgeDomainSubtableCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/BridgeDomainSubtableCustomizer.java new file mode 100644 index 000000000..e75562651 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/BridgeDomainSubtableCustomizer.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2015 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.honeycomb.lisp.translate.read; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.Optional; +import io.fd.honeycomb.lisp.translate.read.dump.executor.SubtableDumpExecutor; +import io.fd.honeycomb.lisp.translate.read.dump.executor.params.SubtableDumpParams; +import io.fd.honeycomb.lisp.translate.read.trait.SubtableReader; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.vpp.util.NamingContext; +import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetails; +import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +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.rev160520.eid.table.grouping.eid.table.VniTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtableBuilder; +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 BridgeDomainSubtableCustomizer extends FutureJVppCustomizer implements + ReaderCustomizer<BridgeDomainSubtable, BridgeDomainSubtableBuilder>, SubtableReader { + + private static final Logger LOG = LoggerFactory.getLogger(BridgeDomainSubtableCustomizer.class); + private static final String CACHE_KEY = BridgeDomainSubtableCustomizer.class.getName(); + + private final DumpCacheManager<LispEidTableMapDetailsReplyDump, SubtableDumpParams> dumpManager; + private final SubtableDumpExecutor dumpExecutor; + private final NamingContext bridgeDomainContext; + + public BridgeDomainSubtableCustomizer(@Nonnull final FutureJVppCore futureJvppCore, + @Nonnull final NamingContext bridgeDomainContext) { + super(futureJvppCore); + dumpExecutor = new SubtableDumpExecutor(futureJvppCore); + dumpManager = + new DumpCacheManager.DumpCacheManagerBuilder<LispEidTableMapDetailsReplyDump, SubtableDumpParams>() + .withExecutor(dumpExecutor) + .build(); + this.bridgeDomainContext = checkNotNull(bridgeDomainContext, "Bridge domain context cannot be null"); + } + + @Nonnull + @Override + public BridgeDomainSubtableBuilder getBuilder(@Nonnull final InstanceIdentifier<BridgeDomainSubtable> id) { + return new BridgeDomainSubtableBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier<BridgeDomainSubtable> id, + @Nonnull final BridgeDomainSubtableBuilder builder, + @Nonnull final ReadContext ctx) throws ReadFailedException { + final int vni = checkNotNull(id.firstKeyOf(VniTable.class), "Cannot find parent VNI Table") + .getVirtualNetworkIdentifier().intValue(); + LOG.debug("Read attributes for id {}", id); + //dumps only L2(bridge domains) + final Optional<LispEidTableMapDetailsReplyDump> reply = + readSubtable(dumpManager, CACHE_KEY, ctx.getModificationCache(), id, L2_PARAMS); + + if (!reply.isPresent() || reply.get().lispEidTableMapDetails.isEmpty()) { + return; + } + + // Single item collector cant be used in this case,because bridge-domain-subtable is container + // so read is invoked every time parent is defined + final List<LispEidTableMapDetails> + details = reply.get().lispEidTableMapDetails.stream().filter(a -> a.vni == vni) + .collect(Collectors.toList()); + if (details.size() == 1) { + final LispEidTableMapDetails detail = details.get(0); + builder.setBridgeDomainRef(bridgeDomainContext.getName(detail.dpTable, ctx.getMappingContext())); + LOG.debug("Attributes for {} successfully loaded", id); + } + } + + @Override + public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, + @Nonnull final BridgeDomainSubtable readValue) { + ((VniTableBuilder) parentBuilder).setBridgeDomainSubtable(readValue); + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/ItrRemoteLocatorSetCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/ItrRemoteLocatorSetCustomizer.java new file mode 100644 index 000000000..48e559ddc --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/ItrRemoteLocatorSetCustomizer.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2015 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.honeycomb.lisp.translate.read; + + +import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS; + +import com.google.common.base.Optional; +import io.fd.honeycomb.lisp.translate.read.dump.executor.ItrRemoteLocatorSetDumpExecutor; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager.DumpCacheManagerBuilder; +import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException; +import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator; +import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.itr.remote.locator.sets.grouping.ItrRemoteLocatorSet; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.itr.remote.locator.sets.grouping.ItrRemoteLocatorSetBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.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 io.fd.vpp.jvpp.core.dto.LispGetMapRequestItrRlocsReply; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; + +public class ItrRemoteLocatorSetCustomizer extends FutureJVppCustomizer + implements ReaderCustomizer<ItrRemoteLocatorSet, ItrRemoteLocatorSetBuilder>, ByteDataTranslator { + + private static final String CACHE_KEY = ItrRemoteLocatorSetCustomizer.class.getName(); + + private final DumpCacheManager<LispGetMapRequestItrRlocsReply, Void> dumpCacheManager; + + public ItrRemoteLocatorSetCustomizer(@Nonnull final FutureJVppCore futureJVppCore) { + super(futureJVppCore); + dumpCacheManager = new DumpCacheManagerBuilder<LispGetMapRequestItrRlocsReply, Void>() + .withExecutor(new ItrRemoteLocatorSetDumpExecutor(futureJVppCore)).build(); + } + + @Nonnull + @Override + public ItrRemoteLocatorSetBuilder getBuilder(@Nonnull final InstanceIdentifier<ItrRemoteLocatorSet> id) { + return new ItrRemoteLocatorSetBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier<ItrRemoteLocatorSet> id, + @Nonnull final ItrRemoteLocatorSetBuilder builder, @Nonnull final ReadContext ctx) + throws ReadFailedException { + + Optional<LispGetMapRequestItrRlocsReply> reply; + try { + reply = dumpCacheManager.getDump(CACHE_KEY, ctx.getModificationCache(), NO_PARAMS); + } catch (DumpExecutionFailedException e) { + throw new ReadFailedException(id, e); + } + + if (!reply.isPresent() || reply.get().locatorSetName == null) { + return; + } + + builder.setRemoteLocatorSetName(toString(reply.get().locatorSetName)); + } + + @Override + public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, + @Nonnull final ItrRemoteLocatorSet readValue) { + ((LispFeatureDataBuilder) parentBuilder).setItrRemoteLocatorSet(readValue); + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LocalMappingCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LocalMappingCustomizer.java index 0290aa086..52135def3 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LocalMappingCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LocalMappingCustomizer.java @@ -27,6 +27,7 @@ import com.google.common.base.Optional; import io.fd.honeycomb.lisp.context.util.EidMappingContext; import io.fd.honeycomb.lisp.translate.read.dump.executor.MappingsDumpExecutor; import io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams; +import io.fd.honeycomb.lisp.translate.read.trait.MappingFilterProvider; import io.fd.honeycomb.lisp.translate.util.EidTranslator; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; @@ -36,23 +37,24 @@ import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException; import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer; import io.fd.honeycomb.translate.vpp.util.NamingContext; +import io.fd.vpp.jvpp.core.dto.LispEidTableDetails; +import io.fd.vpp.jvpp.core.dto.LispEidTableDetailsReplyDump; +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.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MappingId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.LocalMappingsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMappingKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.LocalMappingsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMapping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMappingBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMappingKey; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.LispEidTableDetails; -import io.fd.vpp.jvpp.core.dto.LispEidTableDetailsReplyDump; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,11 +63,13 @@ import org.slf4j.LoggerFactory; */ public class LocalMappingCustomizer extends FutureJVppCustomizer - implements ListReaderCustomizer<LocalMapping, LocalMappingKey, LocalMappingBuilder>, EidTranslator { + implements ListReaderCustomizer<LocalMapping, LocalMappingKey, LocalMappingBuilder>, EidTranslator, + MappingFilterProvider { private static final Logger LOG = LoggerFactory.getLogger(LocalMappingCustomizer.class); private static final String KEY = LocalMappingCustomizer.class.getName(); + private final DumpCacheManager<LispEidTableDetailsReplyDump, MappingsDumpParams> dumpManager; private final MappingsDumpExecutor dumpExecutor; private final NamingContext locatorSetContext; @@ -83,7 +87,6 @@ public class LocalMappingCustomizer .build(); } - @Override public LocalMappingBuilder getBuilder(InstanceIdentifier<LocalMapping> id) { return new LocalMappingBuilder(); @@ -128,17 +131,20 @@ public class LocalMappingCustomizer } LispEidTableDetails details = replyOptional.get().lispEidTableDetails.stream() - .filter(a -> compareAddresses(eid.getAddress(), - getArrayAsEidLocal(valueOf(a.eidType), a.eid).getAddress())) - .collect( - RWUtils.singleItemCollector()); + .filter(subtableFilterForLocalMappings(id)) + .filter(detail -> compareAddresses(eid.getAddress(), getAddressFromDumpDetail(detail))) + .collect(RWUtils.singleItemCollector()); //in case of local mappings,locator_set_index stands for interface index checkState(locatorSetContext.containsName(details.locatorSetIndex, ctx.getMappingContext()), "No Locator Set name found for index %s", details.locatorSetIndex); builder.setLocatorSet(locatorSetContext.getName(details.locatorSetIndex, ctx.getMappingContext())); builder.setKey(new LocalMappingKey(new MappingId(id.firstKeyOf(LocalMapping.class).getId()))); - builder.setEid(getArrayAsEidLocal(valueOf(details.eidType), details.eid)); + builder.setEid(getArrayAsEidLocal(valueOf(details.eidType), details.eid, details.vni)); + } + + private Address getAddressFromDumpDetail(final LispEidTableDetails detail) { + return getArrayAsEidLocal(valueOf(detail.eidType), detail.eid, detail.vni).getAddress(); } @Override @@ -173,14 +179,14 @@ public class LocalMappingCustomizer return Collections.emptyList(); } + return replyOptional.get().lispEidTableDetails.stream() - //filtering with vni to skip help local mappings that are created in vpp to handle remote mappings(vpp feature) .filter(a -> a.vni == vni) - .map(a -> new LocalMappingKey( - new MappingId( - localMappingContext.getId( - getArrayAsEidLocal(valueOf(a.eidType), a.eid), - context.getMappingContext())))) + .filter(subtableFilterForLocalMappings(id)) + .map(detail -> getArrayAsEidLocal(valueOf(detail.eidType), detail.eid, detail.vni)) + .map(localEid -> localMappingContext.getId(localEid, context.getMappingContext())) + .map(MappingId::new) + .map(LocalMappingKey::new) .collect(Collectors.toList()); } @@ -192,4 +198,5 @@ public class LocalMappingCustomizer private static String bindKey(String prefix) { return prefix + "_" + KEY; } + } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/MapResolverCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/MapResolverCustomizer.java index d4e0ef60e..21281c75b 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/MapResolverCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/MapResolverCustomizer.java @@ -28,6 +28,10 @@ import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException; import io.fd.honeycomb.translate.vpp.util.AddressTranslator; import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer; +import io.fd.vpp.jvpp.core.dto.LispMapResolverDetails; +import io.fd.vpp.jvpp.core.dto.LispMapResolverDetailsReplyDump; +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; @@ -39,9 +43,6 @@ 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 io.fd.vpp.jvpp.core.dto.LispMapResolverDetails; -import io.fd.vpp.jvpp.core.dto.LispMapResolverDetailsReplyDump; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -83,12 +84,10 @@ public class MapResolverCustomizer extends FutureJVppCustomizer } final MapResolverKey key = id.firstKeyOf(MapResolver.class); - //revert searched key to match vpp's reversed order ip's - final IpAddress address = reverseAddress(key.getIpAddress()); final LispMapResolverDetails mapResolverDetails = dumpOptional.get().lispMapResolverDetails.stream() - .filter(a -> address - .equals(arrayToIpAddress(byteToBoolean(a.isIpv6), a.ipAddress))) + .filter(a -> addressesEqual(key.getIpAddress(), + arrayToIpAddressReversed(byteToBoolean(a.isIpv6), a.ipAddress))) .collect(RWUtils.singleItemCollector()); builder.setKey(key); @@ -96,6 +95,12 @@ public class MapResolverCustomizer extends FutureJVppCustomizer arrayToIpAddress(byteToBoolean(mapResolverDetails.isIpv6), mapResolverDetails.ipAddress)); } + // safest way to compare addresses - prevents returning false while using different types from hierarchy + // Ex. Key for MapResolver contains Ipv4Address as value but we translate addresses from binary data to Ipv4AddressNoZone + private boolean addressesEqual(final IpAddress left, final IpAddress right) { + return Arrays.equals(left.getValue(), right.getValue()); + } + @Override public List<MapResolverKey> getAllIds(InstanceIdentifier<MapResolver> id, ReadContext context) throws ReadFailedException { @@ -114,7 +119,7 @@ public class MapResolverCustomizer extends FutureJVppCustomizer return dumpOptional.get().lispMapResolverDetails.stream() .map(resolver -> new MapResolverKey( - arrayToIpAddress(byteToBoolean(resolver.isIpv6), resolver.ipAddress))) + arrayToIpAddressReversed(byteToBoolean(resolver.isIpv6), resolver.ipAddress))) .collect(Collectors.toList()); } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/PitrCfgCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/PitrCfgCustomizer.java index 6e97216bc..4d8bbede0 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/PitrCfgCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/PitrCfgCustomizer.java @@ -24,7 +24,7 @@ import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator; import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer; import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer; import java.util.concurrent.TimeoutException; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.LispStateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureDataBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.pitr.cfg.grouping.PitrCfg; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.pitr.cfg.grouping.PitrCfgBuilder; import org.opendaylight.yangtools.concepts.Builder; @@ -74,7 +74,7 @@ public class PitrCfgCustomizer extends FutureJVppCustomizer @Override public void merge(Builder<? extends DataObject> parentBuilder, PitrCfg readValue) { - ((LispStateBuilder) parentBuilder).setPitrCfg(readValue); + ((LispFeatureDataBuilder) parentBuilder).setPitrCfg(readValue); } public ShowLispPitrReply getPitrStatus() throws TimeoutException, VppBaseCallException { diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/RemoteMappingCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/RemoteMappingCustomizer.java index 230c8766d..5d092f988 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/RemoteMappingCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/RemoteMappingCustomizer.java @@ -21,38 +21,57 @@ import static com.google.common.base.Preconditions.checkState; import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.valueOf; import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.FilterType; import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.MappingsDumpParamsBuilder; +import static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MapReplyAction.NoAction; import com.google.common.base.Optional; import io.fd.honeycomb.lisp.context.util.EidMappingContext; +import io.fd.honeycomb.lisp.translate.read.dump.executor.LocatorDumpExecutor; import io.fd.honeycomb.lisp.translate.read.dump.executor.MappingsDumpExecutor; +import io.fd.honeycomb.lisp.translate.read.dump.executor.params.LocatorDumpParams; +import io.fd.honeycomb.lisp.translate.read.dump.executor.params.LocatorDumpParams.LocatorDumpParamsBuilder; import io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams; import io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.QuantityType; +import io.fd.honeycomb.lisp.translate.read.trait.MappingFilterProvider; import io.fd.honeycomb.lisp.translate.util.EidTranslator; +import io.fd.honeycomb.translate.ModificationCache; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; import io.fd.honeycomb.translate.util.RWUtils; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException; +import io.fd.honeycomb.translate.vpp.util.AddressTranslator; +import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator; import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer; +import io.fd.vpp.jvpp.core.dto.LispEidTableDetails; +import io.fd.vpp.jvpp.core.dto.LispEidTableDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.LispLocatorDetails; +import io.fd.vpp.jvpp.core.dto.LispLocatorDetailsReplyDump; +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.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MapReplyAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MappingId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.RemoteMappingsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMappingKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.NegativeMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.PositiveMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.negative.mapping.MapReplyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.positive.mapping.RlocsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.positive.mapping.rlocs.Locator; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.positive.mapping.rlocs.LocatorBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.positive.mapping.rlocs.LocatorKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.RemoteMappingsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMapping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMappingBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMappingKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.Eid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.EidBuilder; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.LispEidTableDetails; -import io.fd.vpp.jvpp.core.dto.LispEidTableDetailsReplyDump; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,12 +80,13 @@ import org.slf4j.LoggerFactory; */ public class RemoteMappingCustomizer extends FutureJVppCustomizer implements ListReaderCustomizer<RemoteMapping, RemoteMappingKey, RemoteMappingBuilder>, - EidTranslator { + EidTranslator, AddressTranslator, ByteDataTranslator, MappingFilterProvider { private static final Logger LOG = LoggerFactory.getLogger(RemoteMappingCustomizer.class); private static final String KEY = RemoteMappingCustomizer.class.getName(); private final DumpCacheManager<LispEidTableDetailsReplyDump, MappingsDumpParams> dumpManager; + private final DumpCacheManager<LispLocatorDetailsReplyDump, LocatorDumpParams> locatorsDumpManager; private final EidMappingContext remoteMappingContext; public RemoteMappingCustomizer(@Nonnull FutureJVppCore futureJvpp, @@ -77,6 +97,10 @@ public class RemoteMappingCustomizer extends FutureJVppCustomizer new DumpCacheManager.DumpCacheManagerBuilder<LispEidTableDetailsReplyDump, MappingsDumpParams>() .withExecutor(new MappingsDumpExecutor(futureJvpp)) .build(); + this.locatorsDumpManager = + new DumpCacheManager.DumpCacheManagerBuilder<LispLocatorDetailsReplyDump, LocatorDumpParams>() + .withExecutor(new LocatorDumpExecutor(futureJvpp)) + .build(); } @@ -130,16 +154,18 @@ public class RemoteMappingCustomizer extends FutureJVppCustomizer LOG.debug("Valid dump loaded"); LispEidTableDetails details = replyOptional.get().lispEidTableDetails.stream() + .filter(subtableFilterForRemoteMappings(id)) .filter(a -> compareAddresses(eid.getAddress(), - getArrayAsEidLocal(valueOf(a.eidType), a.eid).getAddress())) + getArrayAsEidLocal(valueOf(a.eidType), a.eid, a.vni).getAddress())) .collect( RWUtils.singleItemCollector()); - builder.setEid(getArrayAsEidRemote(valueOf(details.eidType), details.eid)); + builder.setEid(getArrayAsEidRemote(valueOf(details.eidType), details.eid, details.vni)); builder.setKey(new RemoteMappingKey(new MappingId(id.firstKeyOf(RemoteMapping.class).getId()))); builder.setTtl(resolveTtl(details.ttl)); builder.setAuthoritative( new RemoteMapping.Authoritative(byteToBoolean(details.authoritative))); + resolverMappings(id, builder, details, ctx.getModificationCache()); } //compensate ~0 as default value of ttl @@ -185,12 +211,11 @@ public class RemoteMappingCustomizer extends FutureJVppCustomizer .lispEidTableDetails .stream() .filter(a -> a.vni == vni) - .map(detail -> new RemoteMappingKey( - new MappingId( - remoteMappingContext.getId( - getArrayAsEidRemote( - valueOf(detail.eidType), detail.eid), - context.getMappingContext())))) + .filter(subtableFilterForRemoteMappings(id)) + .map(detail -> getArrayAsEidRemote(valueOf(detail.eidType), detail.eid, detail.vni)) + .map(remoteEid -> remoteMappingContext.getId(remoteEid, context.getMappingContext())) + .map(MappingId::new) + .map(RemoteMappingKey::new) .collect(Collectors.toList()); } @@ -202,4 +227,68 @@ public class RemoteMappingCustomizer extends FutureJVppCustomizer private String bindKey(String prefix) { return prefix + "_" + KEY; } + + private void resolverMappings(final InstanceIdentifier id, final RemoteMappingBuilder builder, + final LispEidTableDetails details, + final ModificationCache cache) throws ReadFailedException { + + if (details.action != 0) { + // in this case ,negative action was defined + bindNegativeMapping(builder, MapReplyAction.forValue(details.action)); + } else { + // in this case, there is no clear determination whether negative action with NO_ACTION(value == 0) was defined, + // or if its default value and remote locators, are defined, so only chance to determine so, is to dump locators for this mapping + + // cache key needs to have locator set scope to not mix with cached data + final Optional<LispLocatorDetailsReplyDump> reply; + try { + reply = locatorsDumpManager.getDump(KEY + "_locator_set_" + details.locatorSetIndex, cache, + new LocatorDumpParamsBuilder().setLocatorSetIndex(details.locatorSetIndex).build()); + } catch (DumpExecutionFailedException e) { + throw new ReadFailedException(id, + new IllegalStateException("Unable to resolve Positive/Negative mapping for RemoteMapping", e)); + } + + if (!reply.isPresent() || reply.get().lispLocatorDetails.isEmpty()) { + // no remote locators exist, therefore there was NO_ACTION defined + bindNegativeMapping(builder, NoAction); + } else { + // bind remote locators + bindPositiveMapping(builder, reply.get()); + } + } + } + + private void bindNegativeMapping(final RemoteMappingBuilder builder, + final MapReplyAction action) { + builder.setLocatorList( + new NegativeMappingBuilder().setMapReply(new MapReplyBuilder().setMapReplyAction(action).build()) + .build()); + } + + private void bindPositiveMapping(final RemoteMappingBuilder builder, final LispLocatorDetailsReplyDump reply) { + builder.setLocatorList( + new PositiveMappingBuilder() + .setRlocs( + new RlocsBuilder() + .setLocator(reply + .lispLocatorDetails + .stream() + .map(this::detailsToLocator) + .collect(Collectors.toList())) + .build() + ) + .build() + ); + } + + private Locator detailsToLocator(final LispLocatorDetails details) { + final IpAddress address = arrayToIpAddressReversed(byteToBoolean(details.isIpv6), details.ipAddress); + return new LocatorBuilder() + .setAddress(address) + .setKey(new LocatorKey(address)) + .setPriority((short) details.priority) + .setWeight((short) details.weight) + .build(); + } } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/VniTableCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/VniTableCustomizer.java index 3e26de47d..e8a28cc1b 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/VniTableCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/VniTableCustomizer.java @@ -28,6 +28,11 @@ import io.fd.honeycomb.translate.util.RWUtils; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException; import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer; +import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetails; +import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.LispEidTableVniDetails; +import io.fd.vpp.jvpp.core.dto.LispEidTableVniDetailsReplyDump; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -39,9 +44,6 @@ 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 io.fd.vpp.jvpp.core.dto.LispEidTableMapDetails; -import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,16 +56,16 @@ public class VniTableCustomizer extends FutureJVppCustomizer private static final Logger LOG = LoggerFactory.getLogger(VniTableCustomizer.class); private static final String LISP_TABLE_ID_DUMP = VniTableCustomizer.class.getName(); - private final DumpCacheManager<LispEidTableMapDetailsReplyDump, Void> dumpManager; + private final DumpCacheManager<LispEidTableVniDetailsReplyDump, Void> dumpManager; public VniTableCustomizer(@Nonnull final FutureJVppCore futureJvpp) { super(futureJvpp); - this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder<LispEidTableMapDetailsReplyDump, Void>() + this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder<LispEidTableVniDetailsReplyDump, Void>() .withExecutor(new VniTableDumpExecutor(futureJvpp)) .build(); } - private static VniTableKey detailsToKey(final LispEidTableMapDetails lispEidTableMapDetails) { + private static VniTableKey detailsToKey(final LispEidTableVniDetails lispEidTableMapDetails) { return new VniTableKey(Integer.valueOf(lispEidTableMapDetails.vni).longValue()); } @@ -86,18 +88,18 @@ public class VniTableCustomizer extends FutureJVppCustomizer throws ReadFailedException { LOG.trace("Reading all IDS..."); - Optional<LispEidTableMapDetailsReplyDump> optionalReply; + Optional<LispEidTableVniDetailsReplyDump> optionalReply; try { optionalReply = dumpManager.getDump(LISP_TABLE_ID_DUMP, context.getModificationCache(), NO_PARAMS); } catch (DumpExecutionFailedException e) { throw new ReadFailedException(id, e); } - if (!optionalReply.isPresent() || optionalReply.get().lispEidTableMapDetails.isEmpty()) { + if (!optionalReply.isPresent() || optionalReply.get().lispEidTableVniDetails.isEmpty()) { return Collections.emptyList(); } - return optionalReply.get().lispEidTableMapDetails.stream().map(VniTableCustomizer::detailsToKey) + return optionalReply.get().lispEidTableVniDetails.stream().map(VniTableCustomizer::detailsToKey) .collect(Collectors.toList()); } @@ -109,23 +111,25 @@ public class VniTableCustomizer extends FutureJVppCustomizer checkState(id.firstKeyOf(VniTable.class) != null, "No VNI present"); VniTableKey key = new VniTableKey(id.firstKeyOf(VniTable.class).getVirtualNetworkIdentifier()); - Optional<LispEidTableMapDetailsReplyDump> optionalReply; + Optional<LispEidTableVniDetailsReplyDump> optionalReply; try { optionalReply = dumpManager.getDump(LISP_TABLE_ID_DUMP, ctx.getModificationCache(), NO_PARAMS); } catch (DumpExecutionFailedException e) { throw new ReadFailedException(id, e); } - if (!optionalReply.isPresent() || optionalReply.get().lispEidTableMapDetails.isEmpty()) { + if (!optionalReply.isPresent() || optionalReply.get().lispEidTableVniDetails.isEmpty()) { return; } //transforming right away to single detail(specific request should do the magic) - final LispEidTableMapDetails details = - optionalReply.get().lispEidTableMapDetails.stream().filter(a -> detailsToKey(a).equals(key)) - .collect(RWUtils.singleItemCollector()); + final LispEidTableVniDetails details = optionalReply.get() + .lispEidTableVniDetails + .stream() + .filter(a -> a.vni == key.getVirtualNetworkIdentifier().intValue()) + .collect(RWUtils.singleItemCollector()); builder.setVirtualNetworkIdentifier((long) details.vni); - builder.setTableId((long) details.dpTable); + builder.setKey(new VniTableKey(Long.valueOf(details.vni))); } } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/VrfSubtableCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/VrfSubtableCustomizer.java new file mode 100644 index 000000000..5072c37c2 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/VrfSubtableCustomizer.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2015 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.honeycomb.lisp.translate.read; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.Optional; +import io.fd.honeycomb.lisp.translate.read.dump.executor.SubtableDumpExecutor; +import io.fd.honeycomb.lisp.translate.read.dump.executor.params.SubtableDumpParams; +import io.fd.honeycomb.lisp.translate.read.trait.SubtableReader; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer; +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.rev160520.eid.table.grouping.eid.table.VniTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtableBuilder; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetails; +import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class VrfSubtableCustomizer extends FutureJVppCustomizer + implements ReaderCustomizer<VrfSubtable, VrfSubtableBuilder>, SubtableReader { + + private static final Logger LOG = LoggerFactory.getLogger(VrfSubtableCustomizer.class); + private static final String CACHE_KEY = VrfSubtableCustomizer.class.getName(); + + private final DumpCacheManager<LispEidTableMapDetailsReplyDump, SubtableDumpParams> dumpManager; + private final SubtableDumpExecutor dumpExecutor; + + public VrfSubtableCustomizer(@Nonnull final FutureJVppCore futureJvpp) { + super(futureJvpp); + dumpExecutor = new SubtableDumpExecutor(futureJvpp); + dumpManager = + new DumpCacheManager.DumpCacheManagerBuilder<LispEidTableMapDetailsReplyDump, SubtableDumpParams>() + .withExecutor(dumpExecutor) + .build(); + } + + @Nonnull + @Override + public VrfSubtableBuilder getBuilder(@Nonnull final InstanceIdentifier<VrfSubtable> id) { + return new VrfSubtableBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier<VrfSubtable> id, + @Nonnull final VrfSubtableBuilder builder, @Nonnull final ReadContext ctx) + throws ReadFailedException { + LOG.debug("Read attributes for {}", id); + final int vni = checkNotNull(id.firstKeyOf(VniTable.class), "Cannot find parent VNI Table") + .getVirtualNetworkIdentifier().intValue(); + + final Optional<LispEidTableMapDetailsReplyDump> reply = + readSubtable(dumpManager, CACHE_KEY, ctx.getModificationCache(), id, L3_PARAMS); + + if (!reply.isPresent() || reply.get().lispEidTableMapDetails.isEmpty()) { + return; + } + + // Single item collector cant be used in this case,because vrf-subtable is container + // so read is invoked every time parent is defined + final List<LispEidTableMapDetails> details = + reply.get().lispEidTableMapDetails.stream().filter(a -> a.vni == vni) + .collect(Collectors.toList()); + if (details.size() == 1) { + final LispEidTableMapDetails detail = details.get(0); + builder.setTableId(Integer.valueOf(detail.dpTable).longValue()); + + LOG.debug("Attributes for {} successfully loaded", id); + } + } + + @Override + public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, + @Nonnull final VrfSubtable readValue) { + ((VniTableBuilder) parentBuilder).setVrfSubtable(readValue); + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/AbstractDumpExecutor.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/AbstractJvppDumpExecutor.java index d1aea12b0..65f41443c 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/AbstractDumpExecutor.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/AbstractJvppDumpExecutor.java @@ -23,13 +23,13 @@ import io.fd.vpp.jvpp.core.future.FutureJVppCore; /** - * Abstract holder for jvpp refference + * Abstract holder for jvpp reference */ -public abstract class AbstractDumpExecutor { +public abstract class AbstractJvppDumpExecutor { protected final FutureJVppCore vppApi; - protected AbstractDumpExecutor(@Nonnull final FutureJVppCore vppApi) { - this.vppApi = checkNotNull(vppApi, "VPP Api refference cannot be null"); + public AbstractJvppDumpExecutor(@Nonnull final FutureJVppCore vppApi) { + this.vppApi = checkNotNull(vppApi, "VPP Api reference cannot be null"); } } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/ItrRemoteLocatorSetDumpExecutor.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/ItrRemoteLocatorSetDumpExecutor.java new file mode 100644 index 000000000..391fa7668 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/ItrRemoteLocatorSetDumpExecutor.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015 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.honeycomb.lisp.translate.read.dump.executor; + +import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor; +import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException; +import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpCallFailedException; +import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpTimeoutException; +import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer; +import java.util.concurrent.TimeoutException; +import javax.annotation.Nonnull; +import io.fd.vpp.jvpp.VppBaseCallException; +import io.fd.vpp.jvpp.core.dto.LispGetMapRequestItrRlocs; +import io.fd.vpp.jvpp.core.dto.LispGetMapRequestItrRlocsReply; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; + +public class ItrRemoteLocatorSetDumpExecutor extends AbstractJvppDumpExecutor + implements EntityDumpExecutor<LispGetMapRequestItrRlocsReply, Void>, JvppReplyConsumer { + + public ItrRemoteLocatorSetDumpExecutor(@Nonnull final FutureJVppCore vppApi) { + super(vppApi); + } + + @Override + public LispGetMapRequestItrRlocsReply executeDump(final Void params) throws DumpExecutionFailedException { + try { + return getReply(vppApi.lispGetMapRequestItrRlocs(new LispGetMapRequestItrRlocs()).toCompletableFuture()); + } catch (TimeoutException e) { + throw DumpTimeoutException.wrapTimeoutException("Dumping of Itr Remote Locator Sets ended in timeout", e); + } catch (VppBaseCallException e) { + throw DumpCallFailedException.wrapFailedCallException("Dumping of Itr Remote Locator Sets failed", e); + } + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/LocatorDumpExecutor.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/LocatorDumpExecutor.java index ad588e28d..86ac1ac63 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/LocatorDumpExecutor.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/LocatorDumpExecutor.java @@ -35,7 +35,7 @@ import io.fd.vpp.jvpp.core.future.FutureJVppCore; /** * Executor for dumping of locators */ -public class LocatorDumpExecutor extends AbstractDumpExecutor +public class LocatorDumpExecutor extends AbstractJvppDumpExecutor implements EntityDumpExecutor<LispLocatorDetailsReplyDump, LocatorDumpParams>, JvppReplyConsumer { diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/LocatorSetsDumpExecutor.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/LocatorSetsDumpExecutor.java index ec2cb3405..383cb8e78 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/LocatorSetsDumpExecutor.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/LocatorSetsDumpExecutor.java @@ -30,7 +30,7 @@ import io.fd.vpp.jvpp.core.dto.LispLocatorSetDump; import io.fd.vpp.jvpp.core.future.FutureJVppCore; -public class LocatorSetsDumpExecutor extends AbstractDumpExecutor +public class LocatorSetsDumpExecutor extends AbstractJvppDumpExecutor implements EntityDumpExecutor<LispLocatorSetDetailsReplyDump, Void>, JvppReplyConsumer { public LocatorSetsDumpExecutor(@Nonnull FutureJVppCore api) { diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/MapResolversDumpExecutor.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/MapResolversDumpExecutor.java index 9b6f5dec3..7df537040 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/MapResolversDumpExecutor.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/MapResolversDumpExecutor.java @@ -30,7 +30,7 @@ import io.fd.vpp.jvpp.core.dto.LispMapResolverDump; import io.fd.vpp.jvpp.core.future.FutureJVppCore; -public class MapResolversDumpExecutor extends AbstractDumpExecutor +public class MapResolversDumpExecutor extends AbstractJvppDumpExecutor implements EntityDumpExecutor<LispMapResolverDetailsReplyDump, Void>, JvppReplyConsumer { public MapResolversDumpExecutor(@Nonnull FutureJVppCore api) { diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/MappingsDumpExecutor.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/MappingsDumpExecutor.java index bdf84e14d..8e68c143a 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/MappingsDumpExecutor.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/MappingsDumpExecutor.java @@ -36,7 +36,7 @@ import io.fd.vpp.jvpp.core.future.FutureJVppCore; /** * Common dump executor for both local and remote mappings */ -public class MappingsDumpExecutor extends AbstractDumpExecutor +public class MappingsDumpExecutor extends AbstractJvppDumpExecutor implements EntityDumpExecutor<LispEidTableDetailsReplyDump, MappingsDumpParams>, JvppReplyConsumer { public MappingsDumpExecutor(@Nonnull FutureJVppCore vppApi) { diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/SubtableDumpExecutor.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/SubtableDumpExecutor.java new file mode 100644 index 000000000..722cbb182 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/SubtableDumpExecutor.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2015 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.honeycomb.lisp.translate.read.dump.executor; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.honeycomb.lisp.translate.read.dump.executor.params.SubtableDumpParams; +import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor; +import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException; +import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpCallFailedException; +import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpTimeoutException; +import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer; +import java.util.concurrent.TimeoutException; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; +import io.fd.vpp.jvpp.VppBaseCallException; +import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.LispEidTableMapDump; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; + +/** + * Dump executor for {@link VrfSubtable}/{@link BridgeDomainSubtable} + */ +public final class SubtableDumpExecutor extends AbstractJvppDumpExecutor + implements EntityDumpExecutor<LispEidTableMapDetailsReplyDump, SubtableDumpParams>, JvppReplyConsumer { + + private SubtableDumpParams params; + private LispEidTableMapDump request; + + public SubtableDumpExecutor(@Nonnull final FutureJVppCore vppApi) { + super(vppApi); + } + + @Override + public LispEidTableMapDetailsReplyDump executeDump(final SubtableDumpParams params) + throws DumpExecutionFailedException { + this.params = checkNotNull(params, "Cannot bind null params"); + + LispEidTableMapDump request = new LispEidTableMapDump(); + request.isL2 = params.isL2(); + + try { + return getReply(vppApi.lispEidTableMapDump(request).toCompletableFuture()); + } catch (TimeoutException e) { + throw DumpTimeoutException + .wrapTimeoutException("Dumping subtable with params " + params + " timed out", e); + } catch (VppBaseCallException e) { + throw DumpCallFailedException + .wrapFailedCallException("Dumping subtable with params " + params + " timed out", e); + } + } + +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/VniTableDumpExecutor.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/VniTableDumpExecutor.java index 05e33c2e1..6c9a21ef1 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/VniTableDumpExecutor.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/VniTableDumpExecutor.java @@ -22,25 +22,25 @@ import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecut import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpCallFailedException; import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpTimeoutException; import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer; -import java.util.concurrent.TimeoutException; -import javax.annotation.Nonnull; import io.fd.vpp.jvpp.VppBaseCallException; -import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump; -import io.fd.vpp.jvpp.core.dto.LispEidTableMapDump; +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.concurrent.TimeoutException; +import javax.annotation.Nonnull; -public class VniTableDumpExecutor extends AbstractDumpExecutor - implements EntityDumpExecutor<LispEidTableMapDetailsReplyDump, Void>, JvppReplyConsumer { +public class VniTableDumpExecutor extends AbstractJvppDumpExecutor + implements EntityDumpExecutor<LispEidTableVniDetailsReplyDump, Void>, JvppReplyConsumer { public VniTableDumpExecutor(@Nonnull FutureJVppCore api) { super(api); } @Override - public LispEidTableMapDetailsReplyDump executeDump(Void params) throws DumpExecutionFailedException { + public LispEidTableVniDetailsReplyDump executeDump(Void params) throws DumpExecutionFailedException { try { - return getReply(vppApi.lispEidTableMapDump(new LispEidTableMapDump()).toCompletableFuture()); + return getReply(vppApi.lispEidTableVniDump(new LispEidTableVniDump()).toCompletableFuture()); } catch (TimeoutException e) { throw DumpTimeoutException.wrapTimeoutException("Eid table map dump ended in timeout", e); } catch (VppBaseCallException e) { diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/params/SubtableDumpParams.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/params/SubtableDumpParams.java new file mode 100644 index 000000000..a9a19ccf5 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/params/SubtableDumpParams.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2015 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.honeycomb.lisp.translate.read.dump.executor.params; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; + +/** + * Parameters for dumping {@link VrfSubtable}/{@link BridgeDomainSubtable} + */ +public final class SubtableDumpParams { + + private final byte isL2; + + private SubtableDumpParams(SubtableDumpParamsBuilder builder) { + this.isL2 = builder.isL2; + } + + public byte isL2() { + return isL2; + } + + @Override + public String toString() { + return "SubtableDumpParams{" + + "isL2=" + isL2 + + '}'; + } + + public enum MapLevel { + L2(1), + L3(0); + + private final int value; + + private MapLevel(final int value) { + this.value = value; + } + + public int getValue() { + return value; + } + } + + public static final class SubtableDumpParamsBuilder { + + private byte isL2; + + public SubtableDumpParamsBuilder setL2(@Nonnull final MapLevel mapLevel) { + isL2 = Integer.valueOf(checkNotNull(mapLevel, "Cannot set null map level").getValue()).byteValue(); + return this; + } + + public SubtableDumpParams build() { + return new SubtableDumpParams(this); + } + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/AbstractLispReaderFactoryBase.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/AbstractLispReaderFactoryBase.java index 123aba59d..2aec19fcb 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/AbstractLispReaderFactoryBase.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/AbstractLispReaderFactoryBase.java @@ -35,6 +35,7 @@ abstract class AbstractLispReaderFactoryBase { protected final FutureJVppCore vppApi; protected NamingContext interfaceContext; protected NamingContext locatorSetContext; + protected NamingContext bridgeDomainContext; protected EidMappingContext localMappingContext; protected EidMappingContext remoteMappingContext; @@ -76,4 +77,25 @@ abstract class AbstractLispReaderFactoryBase { this.remoteMappingContext = checkNotNull(remoteMappingContext, "Remote mappings reference is null,for readers that don't need this dependency use different constructor"); } + + protected AbstractLispReaderFactoryBase(@Nonnull final InstanceIdentifier<LispState> lispStateId, + @Nonnull final FutureJVppCore vppApi, + @Nonnull final NamingContext interfaceContext, + @Nonnull final NamingContext locatorSetContext, + @Nonnull final NamingContext bridgeDomainContext, + @Nonnull final EidMappingContext localMappingContext, + @Nonnull final EidMappingContext remoteMappingContext) { + this.lispStateId = checkNotNull(lispStateId, "Lisp state identifier is null"); + this.vppApi = checkNotNull(vppApi, "VPP api reference is null"); + this.interfaceContext = checkNotNull(interfaceContext, + "Interface naming context is null,for readers that don't need this dependency,use different constructor"); + this.locatorSetContext = checkNotNull(locatorSetContext, + "Locator set naming context is null,for readers that don't need this dependency,use different constructor"); + this.bridgeDomainContext = checkNotNull(bridgeDomainContext, + "Bridge domain naming context is null,for readers that don't need this dependency,use different constructor"); + this.localMappingContext = checkNotNull(localMappingContext, + "Local mappings reference is null,for readers that don't need this dependency use different constructor"); + this.remoteMappingContext = checkNotNull(remoteMappingContext, + "Remote mappings reference is null,for readers that don't need this dependency use different constructor"); + } } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/EidTableReaderFactory.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/EidTableReaderFactory.java index 6395f29a2..805d6c5bd 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/EidTableReaderFactory.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/EidTableReaderFactory.java @@ -20,31 +20,40 @@ package io.fd.honeycomb.lisp.translate.read.factory; import com.google.common.collect.ImmutableSet; import io.fd.honeycomb.lisp.context.util.EidMappingContext; import io.fd.honeycomb.lisp.translate.read.AdjacencyCustomizer; +import io.fd.honeycomb.lisp.translate.read.BridgeDomainSubtableCustomizer; import io.fd.honeycomb.lisp.translate.read.LocalMappingCustomizer; import io.fd.honeycomb.lisp.translate.read.RemoteMappingCustomizer; import io.fd.honeycomb.lisp.translate.read.VniTableCustomizer; +import io.fd.honeycomb.lisp.translate.read.VrfSubtableCustomizer; import io.fd.honeycomb.translate.impl.read.GenericListReader; +import io.fd.honeycomb.translate.impl.read.GenericReader; import io.fd.honeycomb.translate.read.ReaderFactory; import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; import io.fd.honeycomb.translate.vpp.util.NamingContext; +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.rev160520.LispState; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.Adjacencies; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.AdjacenciesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.Adjacency; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.adjacency.LocalEid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.adjacency.RemoteEid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.LocalMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.LocalMappingsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.RemoteMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.RemoteMappingsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.negative.mapping.MapReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.positive.mapping.Rlocs; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.positive.mapping.rlocs.Locator; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTableBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.Adjacencies; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.AdjacenciesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.LocalMappings; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.LocalMappingsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.RemoteMappings; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.RemoteMappingsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.Adjacency; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.adjacency.LocalEid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.adjacency.RemoteEid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMapping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureData; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; /** @@ -56,57 +65,110 @@ final class EidTableReaderFactory extends AbstractLispReaderFactoryBase implemen final FutureJVppCore vppApi, final NamingContext interfaceContext, final NamingContext locatorSetContext, + final NamingContext bridgeDomainContext, final EidMappingContext localMappingContext, final EidMappingContext remoteMappingContext) { - super(lispStateId, vppApi,interfaceContext, locatorSetContext, localMappingContext, remoteMappingContext); + super(lispStateId, vppApi, interfaceContext, locatorSetContext, bridgeDomainContext, localMappingContext, + remoteMappingContext); } public static EidTableReaderFactory newInstance(@Nonnull final InstanceIdentifier<LispState> lispStateId, @Nonnull final FutureJVppCore vppApi, @Nonnull final NamingContext interfaceContext, @Nonnull final NamingContext locatorSetContext, + @Nonnull final NamingContext bridgeDomainContext, @Nonnull final EidMappingContext localMappingContext, @Nonnull final EidMappingContext remoteMappingContext) { - return new EidTableReaderFactory(lispStateId, vppApi, interfaceContext, locatorSetContext, localMappingContext, + return new EidTableReaderFactory(lispStateId, vppApi, interfaceContext, locatorSetContext, bridgeDomainContext, + localMappingContext, remoteMappingContext); } @Override public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { - InstanceIdentifier<EidTable> eidTableInstanceIdentifier = lispStateId.child(EidTable.class); - InstanceIdentifier<VniTable> vniTableInstanceIdentifier = eidTableInstanceIdentifier.child(VniTable.class); - InstanceIdentifier<LocalMappings> localMappingsInstanceIdentifier = - vniTableInstanceIdentifier.child(LocalMappings.class); - InstanceIdentifier<RemoteMappings> remoteMappingsInstanceIdentifier = - vniTableInstanceIdentifier.child(RemoteMappings.class); - InstanceIdentifier<Adjacencies> adjacenciesInstanceIdentifier = - vniTableInstanceIdentifier.child(Adjacencies.class); + final InstanceIdentifier<EidTable> eidTableInstanceIdentifier = + lispStateId.child(LispFeatureData.class).child(EidTable.class); + final InstanceIdentifier<VniTable> vniTableInstanceIdentifier = + eidTableInstanceIdentifier.child(VniTable.class); + final InstanceIdentifier<VrfSubtable> vrfSubtable = vniTableInstanceIdentifier.child(VrfSubtable.class); + final InstanceIdentifier<BridgeDomainSubtable> bridgeDomainSubtable = + vniTableInstanceIdentifier.child(BridgeDomainSubtable.class); + + final InstanceIdentifier<LocalMappings> vrfTableLocalMappingsInstanceIdentifier = + vrfSubtable.child(LocalMappings.class); + final InstanceIdentifier<RemoteMappings> vrfTableRemoteMappingsInstanceIdentifier = + vrfSubtable.child(RemoteMappings.class); + final InstanceIdentifier<Adjacencies> vrfTableAdjacenciesInstanceIdentifier = + vrfSubtable.child(RemoteMappings.class).child(RemoteMapping.class).child(Adjacencies.class); + final InstanceIdentifier<LocalMappings> bridgeDomainLocalMappingsInstanceIdentifier = + bridgeDomainSubtable.child(LocalMappings.class); + final InstanceIdentifier<RemoteMappings> bridgeDomainRemoteMappingsInstanceIdentifier = + bridgeDomainSubtable.child(RemoteMappings.class); + final InstanceIdentifier<Adjacencies> bridgeDomainAdjacenciesInstanceIdentifier = + bridgeDomainSubtable.child(RemoteMappings.class).child(RemoteMapping.class).child(Adjacencies.class); + + //EidTable registry.addStructuralReader(eidTableInstanceIdentifier, EidTableBuilder.class); + //EidTable -> VniTable registry.add(new GenericListReader<>(vniTableInstanceIdentifier, new VniTableCustomizer(vppApi))); - registry.addStructuralReader(localMappingsInstanceIdentifier, LocalMappingsBuilder.class); + //EidTable -> VniTable -> VrfSubtable + registry.add(new GenericReader<>(vrfSubtable, new VrfSubtableCustomizer(vppApi))); + + //EidTable -> VniTable -> BridgeDomainSubtable + registry.add(new GenericReader<>(bridgeDomainSubtable, + new BridgeDomainSubtableCustomizer(vppApi, bridgeDomainContext))); + + //EidTable -> VniTable -> VrfSubtable -> LocalMappings + registry.addStructuralReader(vrfTableLocalMappingsInstanceIdentifier, LocalMappingsBuilder.class); + //EidTable -> VniTable -> BridgeDomainSubtable -> LocalMappings + registry.addStructuralReader(bridgeDomainLocalMappingsInstanceIdentifier, LocalMappingsBuilder.class); final InstanceIdentifier<LocalMapping> localMappingSubtreeId = InstanceIdentifier.create(LocalMapping.class); + //EidTable -> VniTable -> VrfSubtable -> LocalMappings -> LocalMapping registry.subtreeAdd(ImmutableSet.of(localMappingSubtreeId - .child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.Eid.class)), - new GenericListReader<>(localMappingsInstanceIdentifier.child(LocalMapping.class), + .child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid.class)), + new GenericListReader<>(vrfTableLocalMappingsInstanceIdentifier.child(LocalMapping.class), new LocalMappingCustomizer(vppApi, locatorSetContext, localMappingContext))); - registry.addStructuralReader(remoteMappingsInstanceIdentifier, RemoteMappingsBuilder.class); + //EidTable -> VniTable -> BridgeDomainSubtable -> LocalMappings -> LocalMapping + registry.subtreeAdd(ImmutableSet.of(localMappingSubtreeId + .child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid.class)), + new GenericListReader<>(bridgeDomainLocalMappingsInstanceIdentifier.child(LocalMapping.class), + new LocalMappingCustomizer(vppApi, locatorSetContext, localMappingContext))); + + //EidTable -> VniTable -> VrfSubtable -> RemoteMappings + registry.addStructuralReader(vrfTableRemoteMappingsInstanceIdentifier, RemoteMappingsBuilder.class); + registry.addStructuralReader(bridgeDomainRemoteMappingsInstanceIdentifier, RemoteMappingsBuilder.class); final InstanceIdentifier<RemoteMapping> remoteMappingSubtreeId = InstanceIdentifier.create(RemoteMapping.class); registry.subtreeAdd(ImmutableSet.of(remoteMappingSubtreeId - .child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.Eid.class)), - new GenericListReader<>(remoteMappingsInstanceIdentifier.child(RemoteMapping.class), + .child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid.class), + remoteMappingSubtreeId.child(Rlocs.class), + remoteMappingSubtreeId.child(Rlocs.class).child(Locator.class), + remoteMappingSubtreeId.child(MapReply.class)), + new GenericListReader<>(vrfTableRemoteMappingsInstanceIdentifier.child(RemoteMapping.class), + new RemoteMappingCustomizer(vppApi, remoteMappingContext))); + registry.subtreeAdd(ImmutableSet.of(remoteMappingSubtreeId + .child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid.class), + remoteMappingSubtreeId.child(Rlocs.class), + remoteMappingSubtreeId.child(Rlocs.class).child(Locator.class), + remoteMappingSubtreeId.child(MapReply.class)), + new GenericListReader<>(bridgeDomainRemoteMappingsInstanceIdentifier.child(RemoteMapping.class), new RemoteMappingCustomizer(vppApi, remoteMappingContext))); - registry.addStructuralReader(adjacenciesInstanceIdentifier, AdjacenciesBuilder.class); + registry.addStructuralReader(vrfTableAdjacenciesInstanceIdentifier, AdjacenciesBuilder.class); + registry.addStructuralReader(bridgeDomainAdjacenciesInstanceIdentifier, AdjacenciesBuilder.class); final InstanceIdentifier<Adjacency> adjacencySubtreeId = InstanceIdentifier.create(Adjacency.class); registry.subtreeAdd( ImmutableSet.of(adjacencySubtreeId.child(LocalEid.class), adjacencySubtreeId.child(RemoteEid.class)), - new GenericListReader<>(adjacenciesInstanceIdentifier.child(Adjacency.class), + new GenericListReader<>(vrfTableAdjacenciesInstanceIdentifier.child(Adjacency.class), + new AdjacencyCustomizer(vppApi))); + registry.subtreeAdd( + ImmutableSet.of(adjacencySubtreeId.child(LocalEid.class), adjacencySubtreeId.child(RemoteEid.class)), + new GenericListReader<>(bridgeDomainAdjacenciesInstanceIdentifier.child(Adjacency.class), new AdjacencyCustomizer(vppApi))); } } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/LispStateReaderFactory.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/LispStateReaderFactory.java index 9e710c69f..a2290bda1 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/LispStateReaderFactory.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/LispStateReaderFactory.java @@ -30,11 +30,13 @@ import io.fd.honeycomb.translate.impl.read.GenericReader; import io.fd.honeycomb.translate.read.ReaderFactory; import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; import io.fd.honeycomb.translate.vpp.util.NamingContext; +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.rev160520.LispState; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureData; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureDataBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.pitr.cfg.grouping.PitrCfg; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; /** @@ -46,26 +48,27 @@ public class LispStateReaderFactory extends AbstractLispReaderFactoryBase implem public LispStateReaderFactory(final FutureJVppCore vppApi, @Named(INTERFACE_CONTEXT) final NamingContext interfaceContext, @Named(LOCATOR_SET_CONTEXT) final NamingContext locatorSetContext, + @Named("bridge-domain-context") final NamingContext bridgeDomainContext, @Named(LOCAL_MAPPING_CONTEXT) final EidMappingContext localMappingContext, @Named(REMOTE_MAPPING_CONTEXT) final EidMappingContext remoteMappingContext) { super(InstanceIdentifier.create(LispState.class), vppApi, interfaceContext, locatorSetContext, - localMappingContext, - remoteMappingContext); + bridgeDomainContext, localMappingContext, remoteMappingContext); } - @Override public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { registry.add(new GenericReader<>(lispStateId, new LispStateCustomizer(vppApi))); + registry.addStructuralReader(lispStateId.child(LispFeatureData.class), LispFeatureDataBuilder.class); LocatorSetsReaderFactory.newInstance(lispStateId, vppApi, interfaceContext, locatorSetContext).init(registry); MapResolversReaderFactory.newInstance(lispStateId, vppApi).init(registry); EidTableReaderFactory - .newInstance(lispStateId, vppApi, interfaceContext, locatorSetContext, localMappingContext, - remoteMappingContext) + .newInstance(lispStateId, vppApi, interfaceContext, locatorSetContext, bridgeDomainContext, + localMappingContext, remoteMappingContext) .init(registry); - registry.add(new GenericReader<>(lispStateId.child(PitrCfg.class), new PitrCfgCustomizer(vppApi))); + registry.add(new GenericReader<>(lispStateId.child(LispFeatureData.class).child(PitrCfg.class), + new PitrCfgCustomizer(vppApi))); } } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/LocatorSetsReaderFactory.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/LocatorSetsReaderFactory.java index bc96474f5..9a8e74383 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/LocatorSetsReaderFactory.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/LocatorSetsReaderFactory.java @@ -25,6 +25,7 @@ import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; import io.fd.honeycomb.translate.vpp.util.NamingContext; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.LispState; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureData; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.LocatorSets; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.LocatorSetsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.LocatorSet; @@ -57,7 +58,7 @@ public class LocatorSetsReaderFactory extends AbstractLispReaderFactoryBase impl @Override public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { - InstanceIdentifier<LocatorSets> locatorSetsInstanceIdentifier = lispStateId.child(LocatorSets.class); + InstanceIdentifier<LocatorSets> locatorSetsInstanceIdentifier = lispStateId.child(LispFeatureData.class).child(LocatorSets.class); InstanceIdentifier<LocatorSet> locatorSetInstanceIdentifier = locatorSetsInstanceIdentifier.child(LocatorSet.class); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/MapResolversReaderFactory.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/MapResolversReaderFactory.java index a484f3635..b41f26f81 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/MapResolversReaderFactory.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/MapResolversReaderFactory.java @@ -23,6 +23,7 @@ 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.rev160520.LispState; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureData; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.map.resolvers.grouping.MapResolvers; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.map.resolvers.grouping.MapResolversBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.map.resolvers.grouping.map.resolvers.MapResolver; @@ -47,7 +48,8 @@ public class MapResolversReaderFactory extends AbstractLispReaderFactoryBase imp @Override public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { - InstanceIdentifier<MapResolvers> mapResolversInstanceIdentifier = lispStateId.child(MapResolvers.class); + InstanceIdentifier<MapResolvers> mapResolversInstanceIdentifier = + lispStateId.child(LispFeatureData.class).child(MapResolvers.class); registry.addStructuralReader(mapResolversInstanceIdentifier, MapResolversBuilder.class); registry.add(new GenericListReader<>(mapResolversInstanceIdentifier.child(MapResolver.class), diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/trait/MappingFilterProvider.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/trait/MappingFilterProvider.java new file mode 100644 index 000000000..ef1ca0438 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/trait/MappingFilterProvider.java @@ -0,0 +1,50 @@ +package io.fd.honeycomb.lisp.translate.read.trait; + +import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV4; +import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV6; +import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.MAC; + +import java.util.function.Predicate; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import io.fd.vpp.jvpp.core.dto.LispEidTableDetails; + +/** + * Trait providing predicates to filter mappings to respective subtables + */ +public interface MappingFilterProvider { + + Predicate<LispEidTableDetails> BRIDGE_DOMAIN_MAPPINGS_ONLY = + (LispEidTableDetails detail) -> detail.eidType == MAC.getValue(); + + Predicate<LispEidTableDetails> VRF_MAPPINGS_ONLY = + (LispEidTableDetails detail) -> detail.eidType == IPV4.getValue() || detail.eidType == IPV6.getValue(); + + default Predicate<LispEidTableDetails> subtableFilterForLocalMappings( + @Nonnull final InstanceIdentifier<LocalMapping> identifier) { + + if (identifier.firstIdentifierOf(VrfSubtable.class) != null) { + return VRF_MAPPINGS_ONLY; + } else if (identifier.firstIdentifierOf(BridgeDomainSubtable.class) != null) { + return BRIDGE_DOMAIN_MAPPINGS_ONLY; + } else { + throw new IllegalArgumentException("Cannot determine mappings predicate for " + identifier); + } + } + + default Predicate<LispEidTableDetails> subtableFilterForRemoteMappings( + @Nonnull final InstanceIdentifier<RemoteMapping> identifier) { + + if (identifier.firstIdentifierOf(VrfSubtable.class) != null) { + return VRF_MAPPINGS_ONLY; + } else if (identifier.firstIdentifierOf(BridgeDomainSubtable.class) != null) { + return BRIDGE_DOMAIN_MAPPINGS_ONLY; + } else { + throw new IllegalArgumentException("Cannot determine mappings predicate for " + identifier); + } + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/trait/MappingProducer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/trait/MappingProducer.java new file mode 100644 index 000000000..104e696e3 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/trait/MappingProducer.java @@ -0,0 +1,56 @@ +package io.fd.honeycomb.lisp.translate.read.trait; + +import io.fd.honeycomb.translate.write.WriteFailedException; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6Afi; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddressFamily; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * Trait that verifies data for mappings + */ +public interface MappingProducer { + + /** + * Checks whether provided {@link LocalMapping} can be written under subtree idenfied by {@link InstanceIdentifier} + */ + default void checkAllowedCombination(@Nonnull final InstanceIdentifier<LocalMapping> identifier, + @Nonnull final LocalMapping data) throws WriteFailedException { + final Class<? extends LispAddressFamily> eidAddressType = data.getEid().getAddressType(); + + if (identifier.firstIdentifierOf(VrfSubtable.class) != null) { + if (Ipv4Afi.class != eidAddressType && Ipv6Afi.class != eidAddressType) { + throw new WriteFailedException.CreateFailedException(identifier, data, + new IllegalArgumentException("Only Ipv4/Ipv6 eid's are allowed for Vrf Subtable")); + } + } else if (identifier.firstIdentifierOf(BridgeDomainSubtable.class) != null) { + if (MacAfi.class != eidAddressType) { + throw new WriteFailedException.CreateFailedException(identifier, data, + new IllegalArgumentException("Only Mac eid's are allowed for Bridge Domain Subtable")); + } + } + } + + default void checkAllowedCombination(@Nonnull final InstanceIdentifier<RemoteMapping> identifier, + @Nonnull final RemoteMapping data) throws WriteFailedException { + final Class<? extends LispAddressFamily> eidAddressType = data.getEid().getAddressType(); + + if (identifier.firstIdentifierOf(VrfSubtable.class) != null) { + if (Ipv4Afi.class != eidAddressType && Ipv6Afi.class != eidAddressType) { + throw new WriteFailedException.CreateFailedException(identifier, data, + new IllegalArgumentException("Only Ipv4/Ipv6 eid's are allowed for Vrf Subtable")); + } + } else if (identifier.firstIdentifierOf(BridgeDomainSubtable.class) != null) { + if (MacAfi.class != eidAddressType) { + throw new WriteFailedException.CreateFailedException(identifier, data, + new IllegalArgumentException("Only Mac eid's are allowed for Bridge Domain Subtable")); + } + } + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/trait/SubtableReader.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/trait/SubtableReader.java new file mode 100644 index 000000000..7af6a7e90 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/trait/SubtableReader.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2015 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.honeycomb.lisp.translate.read.trait; + + +import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.SubtableDumpParams.MapLevel.L2; +import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.SubtableDumpParams.MapLevel.L3; +import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.SubtableDumpParams.SubtableDumpParamsBuilder; + +import com.google.common.base.Optional; +import io.fd.honeycomb.lisp.translate.read.dump.executor.params.SubtableDumpParams; +import io.fd.honeycomb.translate.ModificationCache; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; +import org.opendaylight.yangtools.yang.binding.ChildOf; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump; + +/** + * Provides common logic for reading Eid subtables + */ +public interface SubtableReader { + + SubtableDumpParams L2_PARAMS = new SubtableDumpParamsBuilder().setL2(L2).build(); + SubtableDumpParams L3_PARAMS = new SubtableDumpParamsBuilder().setL2(L3).build(); + + default Optional<LispEidTableMapDetailsReplyDump> readSubtable( + @Nonnull final DumpCacheManager<LispEidTableMapDetailsReplyDump, SubtableDumpParams> dumpManager, + @Nonnull final String cacheKey, + @Nonnull final ModificationCache cache, + @Nonnull final InstanceIdentifier<? extends ChildOf<VniTable>> id, + @Nonnull final SubtableDumpParams params) throws ReadFailedException { + try { + return dumpManager.getDump(cacheKey, cache, params); + } catch (DumpExecutionFailedException e) { + throw new ReadFailedException(id, e); + } + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/util/EidMetadataProvider.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/util/EidMetadataProvider.java new file mode 100644 index 000000000..11de4e7b8 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/util/EidMetadataProvider.java @@ -0,0 +1,36 @@ +package io.fd.honeycomb.lisp.translate.util; + +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddressFamily; + +/** + * Trait providing metadata for eid's + */ +public interface EidMetadataProvider { + + /** + * Returns new {@link org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder} + * binded with metadata + */ + default org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder newRemoteEidBuilder( + @Nonnull final Class<? extends LispAddressFamily> eidAddressType, + final int vni) { + return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder() + .setAddressType(eidAddressType) + .setVirtualNetworkId(new InstanceIdType(Long.valueOf(vni))); + } + + /** + * Returns new {@link org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder} + * binded with metadata + */ + default org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder newLocalEidBuilder( + @Nonnull final Class<? extends LispAddressFamily> eidAddressType, + final int vni) { + return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder() + .setAddressType(eidAddressType) + .setVirtualNetworkId(new InstanceIdType(Long.valueOf(vni))); + } + +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/util/EidTranslator.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/util/EidTranslator.java index dcf9a7e27..7bc99e5f2 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/util/EidTranslator.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/util/EidTranslator.java @@ -24,9 +24,13 @@ import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsD import io.fd.honeycomb.translate.vpp.util.AddressTranslator; import java.util.Arrays; +import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6Afi; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder; @@ -35,16 +39,15 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.addres import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Mac; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.MacBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.adjacency.LocalEid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.adjacency.RemoteEid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.Eid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.EidBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.adjacency.LocalEid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.adjacency.RemoteEid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid; /** * Trait providing converting logic for eid's */ -public interface EidTranslator extends AddressTranslator { +public interface EidTranslator extends AddressTranslator, EidMetadataProvider { default byte getPrefixLength(LocalEid address) { @@ -61,12 +64,12 @@ public interface EidTranslator extends AddressTranslator { } default byte getPrefixLength( - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.Eid address) { + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid address) { return resolverPrefixLength(address.getAddress()); } default byte getPrefixLength( - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.Eid address) { + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid address) { return resolverPrefixLength(address.getAddress()); } @@ -84,21 +87,21 @@ public interface EidTranslator extends AddressTranslator { } } - default Eid getArrayAsEidLocal(EidType type, byte[] address) { + default Eid getArrayAsEidLocal(@Nonnull final EidType type, final byte[] address, final int vni) { switch (type) { case IPV4: { - return new EidBuilder().setAddress( + return newLocalEidBuilder(Ipv4Afi.class, vni).setAddress( new Ipv4Builder().setIpv4(arrayToIpv4AddressNoZoneReversed(address)).build()) .build(); } case IPV6: { - return new EidBuilder().setAddress( + return newLocalEidBuilder(Ipv6Afi.class, vni).setAddress( new Ipv6Builder().setIpv6(arrayToIpv6AddressNoZoneReversed(address)).build()) .build(); } case MAC: { - return new EidBuilder().setAddress( + return newLocalEidBuilder(MacAfi.class, vni).setAddress( new MacBuilder().setMac(new MacAddress(byteArrayToMacSeparated(address))) .build()).build(); } @@ -108,26 +111,26 @@ public interface EidTranslator extends AddressTranslator { } } - default org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.Eid getArrayAsEidRemote( - EidType type, byte[] address) { + default org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid getArrayAsEidRemote( + @Nonnull final EidType type, final byte[] address, final int vni) { switch (type) { case IPV4: { - return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.EidBuilder() + return newRemoteEidBuilder(Ipv4Afi.class, vni) .setAddress( new Ipv4Builder().setIpv4(arrayToIpv4AddressNoZoneReversed(address)) .build()) .build(); } case IPV6: { - return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.EidBuilder() + return newRemoteEidBuilder(Ipv6Afi.class, vni) .setAddress( new Ipv6Builder().setIpv6(arrayToIpv6AddressNoZoneReversed(address)) .build()) .build(); } case MAC: { - return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.EidBuilder() + return newRemoteEidBuilder(MacAfi.class, vni) .setAddress( new MacBuilder().setMac(new MacAddress(byteArrayToMacSeparated(address))) .build()).build(); @@ -166,7 +169,7 @@ public interface EidTranslator extends AddressTranslator { } default EidType getEidType( - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.Eid address) { + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid address) { checkNotNull(address, "SimpleAddress cannot be null"); return resolveType(address.getAddress()); @@ -174,7 +177,7 @@ public interface EidTranslator extends AddressTranslator { default EidType getEidType( - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.Eid address) { + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid address) { checkNotNull(address, "Address cannot be null"); return resolveType(address.getAddress()); @@ -215,14 +218,14 @@ public interface EidTranslator extends AddressTranslator { } default byte[] getEidAsByteArray( - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.Eid address) { + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid address) { checkNotNull(address, "Eid cannot be null"); return resolveByteArray(getEidType(address), address.getAddress()); } default byte[] getEidAsByteArray( - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.Eid address) { + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid address) { checkNotNull(address, "Eid cannot be null"); return resolveByteArray(getEidType(address), address.getAddress()); @@ -279,6 +282,6 @@ public interface EidTranslator extends AddressTranslator { return ((Mac) firstAddress).getMac().getValue().equals(((Mac) secondAddress).getMac().getValue()); } - throw new IllegalArgumentException("Unsupported eid type " + firstAddress.getClass()); + return false; } } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/AdjacencyCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/AdjacencyCustomizer.java index 9cd276741..89f398d4d 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/AdjacencyCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/AdjacencyCustomizer.java @@ -18,9 +18,10 @@ package io.fd.honeycomb.lisp.translate.write; import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkState; +import static com.google.common.base.Preconditions.checkNotNull; import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType; +import io.fd.honeycomb.lisp.context.util.EidMappingContext; import io.fd.honeycomb.lisp.translate.util.EidTranslator; import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator; @@ -28,23 +29,33 @@ import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer; import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer; 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.LispAddDelAdjacency; +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.rev160520.adjacencies.grouping.adjacencies.Adjacency; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.AdjacencyKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.adjacency.LocalEid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.adjacency.RemoteEid; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.Adjacency; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.AdjacencyKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.VppBaseCallException; -import io.fd.vpp.jvpp.core.dto.LispAddDelAdjacency; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; - public class AdjacencyCustomizer extends FutureJVppCustomizer implements ListWriterCustomizer<Adjacency, AdjacencyKey>, ByteDataTranslator, EidTranslator, JvppReplyConsumer { - public AdjacencyCustomizer(@Nonnull final FutureJVppCore futureJvpp) { + private final EidMappingContext localEidsMappingContext; + private final EidMappingContext remoteEidsMappingContext; + + public AdjacencyCustomizer(@Nonnull final FutureJVppCore futureJvpp, + @Nonnull EidMappingContext localEidsMappingContext, + @Nonnull EidMappingContext remoteEidsMappingContext) { super(futureJvpp); + this.localEidsMappingContext = + checkNotNull(localEidsMappingContext, "Eid context for local eid's cannot be null"); + this.remoteEidsMappingContext = + checkNotNull(remoteEidsMappingContext, "Eid context for remote eid's cannot be null"); } @Override @@ -53,7 +64,7 @@ public class AdjacencyCustomizer extends FutureJVppCustomizer throws WriteFailedException { try { - addDelAdjacency(true, id, dataAfter); + addDelAdjacency(true, id, dataAfter, writeContext); } catch (TimeoutException | VppBaseCallException e) { throw new WriteFailedException.CreateFailedException(id, dataAfter, e); } @@ -71,20 +82,31 @@ public class AdjacencyCustomizer extends FutureJVppCustomizer @Nonnull final Adjacency dataBefore, @Nonnull final WriteContext writeContext) throws WriteFailedException { try { - addDelAdjacency(false, id, dataBefore); + addDelAdjacency(false, id, dataBefore, writeContext); } catch (TimeoutException | VppBaseCallException e) { throw new WriteFailedException.CreateFailedException(id, dataBefore, e); } } - private void addDelAdjacency(boolean add, final InstanceIdentifier<Adjacency> id, Adjacency data) + private void addDelAdjacency(boolean add, final InstanceIdentifier<Adjacency> id, final Adjacency data, + final WriteContext writeContext) throws TimeoutException, VppBaseCallException { - checkState(id.firstKeyOf(VniTable.class) != null, "Unable to find parent VNI for {}", id); - final int vni = id.firstKeyOf(VniTable.class).getVirtualNetworkIdentifier().intValue(); - - EidType localEidType = getEidType(data.getLocalEid()); - EidType remoteEidType = getEidType(data.getRemoteEid()); + final int vni = checkNotNull(id.firstKeyOf(VniTable.class), "Unable to find parent VNI for {}", id) + .getVirtualNetworkIdentifier().intValue(); + + // both local and remote eids must be referenced to have respective mapping, + // if there is an attempt to add adjacency. + // In our case its enough to check if local/remote mapping exist for respective eid, + // because such mappings are created while creating mappings + final LocalEid localEid = add + ? verifiedLocalEid(data.getLocalEid(), writeContext) + : data.getLocalEid(); + final RemoteEid remoteEid = add + ? verifiedRemoteEid(data.getRemoteEid(), writeContext) + : data.getRemoteEid(); + final EidType localEidType = getEidType(localEid); + final EidType remoteEidType = getEidType(data.getRemoteEid()); checkArgument(localEidType == remoteEidType, "Local[%s] and Remote[%s] eid types must be the same", localEidType, remoteEidType); @@ -92,13 +114,43 @@ public class AdjacencyCustomizer extends FutureJVppCustomizer LispAddDelAdjacency request = new LispAddDelAdjacency(); request.isAdd = booleanToByte(add); - request.leid = getEidAsByteArray(data.getLocalEid()); - request.leidLen = getPrefixLength(data.getLocalEid()); - request.reid = getEidAsByteArray(data.getRemoteEid()); - request.reidLen = getPrefixLength(data.getRemoteEid()); + request.leid = getEidAsByteArray(localEid); + request.leidLen = getPrefixLength(localEid); + request.reid = getEidAsByteArray(remoteEid); + request.reidLen = getPrefixLength(remoteEid); request.eidType = (byte) localEidType.getValue(); request.vni = vni; getReply(getFutureJVpp().lispAddDelAdjacency(request).toCompletableFuture()); } + + private LocalEid verifiedLocalEid(final LocalEid localEid, final WriteContext writeContext) { + if (localEidsMappingContext.containsId(toLocalEid(localEid), writeContext.getMappingContext())) { + return localEid; + } + throw new IllegalStateException( + "Referenced Local Eid[" + localEid + + "] doesn't have local mapping defined, therefore it can't be used in adjacency"); + } + + private RemoteEid verifiedRemoteEid(final RemoteEid remoteEid, final WriteContext writeContext) { + if (remoteEidsMappingContext.containsId(toRemoteEid(remoteEid), writeContext.getMappingContext())) { + return remoteEid; + } + throw new IllegalStateException( + "Referenced Remote Eid[" + remoteEid + + "] doesn't have remote mapping defined, therefore it can't be used in adjacency"); + } + + private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid toRemoteEid( + final RemoteEid remoteEid) { + return newRemoteEidBuilder(remoteEid.getAddressType(), remoteEid.getVirtualNetworkId().getValue().intValue()) + .setAddress(remoteEid.getAddress()).build(); + } + + private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid toLocalEid( + LocalEid localEid) { + return newLocalEidBuilder(localEid.getAddressType(), localEid.getVirtualNetworkId().getValue().intValue()) + .setAddress(localEid.getAddress()).build(); + } } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/BridgeDomainSubtableCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/BridgeDomainSubtableCustomizer.java new file mode 100644 index 000000000..d86957b37 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/BridgeDomainSubtableCustomizer.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2015 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.honeycomb.lisp.translate.write; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +import io.fd.honeycomb.lisp.translate.write.trait.SubtableWriter; +import io.fd.honeycomb.translate.MappingContext; +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; +import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.vpp.util.NamingContext; +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.future.FutureJVppCore; +import java.util.concurrent.TimeoutException; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BridgeDomainSubtableCustomizer extends FutureJVppCustomizer + implements WriterCustomizer<BridgeDomainSubtable>, SubtableWriter { + + private static final Logger LOG = LoggerFactory.getLogger(BridgeDomainSubtableCustomizer.class); + + private final NamingContext bridgeDomainContext; + + public BridgeDomainSubtableCustomizer(@Nonnull final FutureJVppCore futureJvpp, + @Nonnull final NamingContext bridgeDomainContext) { + super(futureJvpp); + this.bridgeDomainContext = checkNotNull(bridgeDomainContext, "Bridge domain context cannot be null"); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<BridgeDomainSubtable> id, + @Nonnull final BridgeDomainSubtable dataAfter, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + LOG.debug("Writing Id {} ", id); + + try { + addDelSubtableMapping(getFutureJVpp(), true, extractVni(id), + extractBridgeDomainId(dataAfter.getBridgeDomainRef(), writeContext.getMappingContext()), true, LOG); + } catch (TimeoutException | VppBaseCallException e) { + throw new WriteFailedException.CreateFailedException(id, dataAfter, e); + } + + LOG.debug("{} successfully written", id); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<BridgeDomainSubtable> id, + @Nonnull final BridgeDomainSubtable dataBefore, + @Nonnull final BridgeDomainSubtable dataAfter, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + throw new UnsupportedOperationException("Operation not supported"); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<BridgeDomainSubtable> id, + @Nonnull final BridgeDomainSubtable dataBefore, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + LOG.debug("Removing Id {}", id); + + try { + addDelSubtableMapping(getFutureJVpp(), false, extractVni(id), + extractBridgeDomainId(dataBefore.getBridgeDomainRef(), writeContext.getMappingContext()), true, + LOG); + } catch (TimeoutException | VppBaseCallException e) { + throw new WriteFailedException.CreateFailedException(id, dataBefore, e); + } + + LOG.debug("{} successfully removed", id); + } + + private int extractBridgeDomainId(final String bridgeDomainName, final MappingContext mappingContext) { + checkState(bridgeDomainContext.containsIndex(bridgeDomainName, mappingContext), + "No mapping for bridge domain name %s", bridgeDomainName); + return bridgeDomainContext.getIndex(bridgeDomainName, mappingContext); + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/ItrRemoteLocatorSetCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/ItrRemoteLocatorSetCustomizer.java new file mode 100644 index 000000000..f57601af0 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/ItrRemoteLocatorSetCustomizer.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2015 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.honeycomb.lisp.translate.write; + + +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; +import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator; +import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +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.rev160520.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 + WriterCustomizer<ItrRemoteLocatorSet>, ByteDataTranslator, JvppReplyConsumer { + + public ItrRemoteLocatorSetCustomizer(@Nonnull final FutureJVppCore futureJVppCore) { + super(futureJVppCore); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<ItrRemoteLocatorSet> id, + @Nonnull final ItrRemoteLocatorSet dataAfter, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + try { + addDelItrRemoteLocatorSet(true, dataAfter); + } catch (TimeoutException | VppBaseCallException e) { + throw new WriteFailedException.CreateFailedException(id, dataAfter, e); + } + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<ItrRemoteLocatorSet> id, + @Nonnull final ItrRemoteLocatorSet dataBefore, + @Nonnull final ItrRemoteLocatorSet dataAfter, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, + new UnsupportedOperationException("Operation not supported")); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<ItrRemoteLocatorSet> id, + @Nonnull final ItrRemoteLocatorSet dataBefore, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + try { + addDelItrRemoteLocatorSet(false, dataBefore); + } catch (TimeoutException | VppBaseCallException e) { + throw new WriteFailedException.DeleteFailedException(id, e); + } + } + + private void addDelItrRemoteLocatorSet(final boolean add, @Nonnull final ItrRemoteLocatorSet data) + throws TimeoutException, VppBaseCallException { + + LispAddDelMapRequestItrRlocs request = new LispAddDelMapRequestItrRlocs(); + request.isAdd = booleanToByte(add); + request.locatorSetName = data.getRemoteLocatorSetName().getBytes(StandardCharsets.UTF_8); + + getReply(getFutureJVpp().lispAddDelMapRequestItrRlocs(request).toCompletableFuture()); + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/LocalMappingCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/LocalMappingCustomizer.java index b5256db06..e181b9a20 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/LocalMappingCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/LocalMappingCustomizer.java @@ -23,6 +23,7 @@ import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsD import static java.nio.charset.StandardCharsets.UTF_8; import io.fd.honeycomb.lisp.context.util.EidMappingContext; +import io.fd.honeycomb.lisp.translate.read.trait.MappingProducer; import io.fd.honeycomb.lisp.translate.util.EidTranslator; import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator; @@ -34,9 +35,9 @@ import java.io.UnsupportedEncodingException; import java.util.concurrent.TimeoutException; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MappingId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMappingKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMapping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMappingKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import io.fd.vpp.jvpp.VppBaseCallException; import io.fd.vpp.jvpp.core.dto.LispAddDelLocalEid; @@ -48,7 +49,7 @@ import io.fd.vpp.jvpp.core.future.FutureJVppCore; */ public class LocalMappingCustomizer extends FutureJVppCustomizer implements ListWriterCustomizer<LocalMapping, LocalMappingKey>, ByteDataTranslator, EidTranslator, - JvppReplyConsumer { + JvppReplyConsumer, MappingProducer { private final EidMappingContext localMappingsContext; @@ -64,9 +65,10 @@ public class LocalMappingCustomizer extends FutureJVppCustomizer checkNotNull(dataAfter.getEid(), "Eid is null"); checkNotNull(dataAfter.getLocatorSet(), "Locator set is null"); checkState(id.firstKeyOf(VniTable.class) != null, "Parent vni table not found"); + checkAllowedCombination(id, dataAfter); //checks whether value with specified mapping-id does not exist in mapping allready - MappingId mappingId = id.firstKeyOf(LocalMapping.class).getId(); + final MappingId mappingId = id.firstKeyOf(LocalMapping.class).getId(); checkState(!localMappingsContext .containsEid(mappingId, writeContext.getMappingContext()), "Local mapping with id %s already defined", id); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/PitrCfgCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/PitrCfgCustomizer.java index ed30623d8..32d0fd3a4 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/PitrCfgCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/PitrCfgCustomizer.java @@ -39,6 +39,8 @@ import io.fd.vpp.jvpp.core.future.FutureJVppCore; public class PitrCfgCustomizer extends FutureJVppCustomizer implements WriterCustomizer<PitrCfg>, JvppReplyConsumer, ByteDataTranslator { + private static final String DEFAULT_LOCATOR_SET_NAME = "N/A"; + public PitrCfgCustomizer(FutureJVppCore futureJvpp) { super(futureJvpp); } @@ -85,6 +87,13 @@ public class PitrCfgCustomizer extends FutureJVppCustomizer private void addDelPitrSetLocatorSetAndReply(boolean add, PitrCfg data) throws VppBaseCallException, TimeoutException { + if (DEFAULT_LOCATOR_SET_NAME.equals(data.getLocatorSet())) { + // ignores attempts to write default locator set + // therefore even while its loaded to config data of honeycomb while starting + // you can still enable/disable Lisp without having to define N/A as default pitr-set + return; + } + LispPitrSetLocatorSet request = new LispPitrSetLocatorSet(); request.isAdd = booleanToByte(add); request.lsName = data.getLocatorSet().getBytes(UTF_8); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/RemoteMappingCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/RemoteMappingCustomizer.java index 01c8548d5..9f51977ab 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/RemoteMappingCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/RemoteMappingCustomizer.java @@ -25,6 +25,7 @@ import static io.fd.honeycomb.lisp.translate.write.RemoteMappingCustomizer.Locat import com.google.common.base.Preconditions; import io.fd.honeycomb.lisp.context.util.EidMappingContext; +import io.fd.honeycomb.lisp.translate.read.trait.MappingProducer; import io.fd.honeycomb.lisp.translate.util.EidTranslator; import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; import io.fd.honeycomb.translate.vpp.util.AddressTranslator; @@ -43,14 +44,14 @@ 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.Ipv6AddressNoZone; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MapReplyAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MappingId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMappingKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.LocatorList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.NegativeMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.PositiveMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.positive.mapping.Rlocs; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.positive.mapping.rlocs.Locator; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMapping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMappingKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.LocatorList; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.locator.list.NegativeMapping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.locator.list.PositiveMapping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.locator.list.positive.mapping.Rlocs; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.locator.list.positive.mapping.rlocs.Locator; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import io.fd.vpp.jvpp.VppBaseCallException; import io.fd.vpp.jvpp.core.dto.LispAddDelRemoteMapping; @@ -62,7 +63,7 @@ import io.fd.vpp.jvpp.core.future.FutureJVppCore; */ public class RemoteMappingCustomizer extends FutureJVppCustomizer implements ListWriterCustomizer<RemoteMapping, RemoteMappingKey>, EidTranslator, - AddressTranslator, JvppReplyConsumer { + AddressTranslator, JvppReplyConsumer, MappingProducer { private final EidMappingContext remoteMappingContext; @@ -78,6 +79,7 @@ public class RemoteMappingCustomizer extends FutureJVppCustomizer checkNotNull(dataAfter, "Mapping is null"); checkNotNull(dataAfter.getEid(), "Eid is null"); checkState(id.firstKeyOf(VniTable.class) != null, "Parent vni table not found"); + checkAllowedCombination(id, dataAfter); //checks whether mapping not already contains such key MappingId mappingId = id.firstKeyOf(RemoteMapping.class).getId(); @@ -167,7 +169,7 @@ public class RemoteMappingCustomizer extends FutureJVppCustomizer Preconditions.checkArgument(NEGATIVE.equals(resolveType(locatorList)), "Action can be extracted only from Negative Mapping"); - return ((NegativeMapping) locatorList).getMapReplyAction(); + return ((NegativeMapping) locatorList).getMapReply().getMapReplyAction(); } private static Rlocs extractRemoteLocators(LocatorList locatorList) { diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/VniTableCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/VniTableCustomizer.java index 7ad8f24c0..92a1564c0 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/VniTableCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/VniTableCustomizer.java @@ -16,30 +16,28 @@ package io.fd.honeycomb.lisp.translate.write; -import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; +import com.google.common.base.Optional; import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; -import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator; +import io.fd.honeycomb.translate.util.RWUtils; + import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer; -import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer; 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.rev160520.eid.table.grouping.eid.table.VniTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.VppBaseCallException; -import io.fd.vpp.jvpp.core.dto.LispEidTableAddDelMap; import io.fd.vpp.jvpp.core.future.FutureJVppCore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Customizer for {@code TableId} + * 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>, ByteDataTranslator, JvppReplyConsumer { +public class VniTableCustomizer extends FutureJVppCustomizer implements ListWriterCustomizer<VniTable, VniTableKey> { private static final Logger LOG = LoggerFactory.getLogger(VniTableCustomizer.class); @@ -50,19 +48,7 @@ public class VniTableCustomizer extends FutureJVppCustomizer @Override public void writeCurrentAttributes(InstanceIdentifier<VniTable> id, VniTable dataAfter, WriteContext writeContext) throws WriteFailedException { - - checkNotNull(dataAfter.getTableId(), "VRF cannot be null"); - checkNotNull(dataAfter.getVirtualNetworkIdentifier(), "VNI cannot be null"); - - LOG.debug("Writing {}", id); - - try { - addDelMap(true, dataAfter.getVirtualNetworkIdentifier().intValue(), dataAfter.getTableId().intValue()); - } catch (TimeoutException | VppBaseCallException e) { - throw new WriteFailedException.CreateFailedException(id, dataAfter, e); - } - - LOG.debug("Write of {} successful", id); + checkAtLeastOnChildExists(id, writeContext, false); } @Override @@ -74,29 +60,24 @@ public class VniTableCustomizer extends FutureJVppCustomizer @Override public void deleteCurrentAttributes(InstanceIdentifier<VniTable> id, VniTable dataBefore, WriteContext writeContext) throws WriteFailedException { - checkNotNull(dataBefore.getTableId(), "VRF cannot be null"); - checkNotNull(dataBefore.getVirtualNetworkIdentifier(), "VNI cannot be null"); - - LOG.debug("Removing {}", id); - - try { - addDelMap(false, dataBefore.getVirtualNetworkIdentifier().intValue(), dataBefore.getTableId().intValue()); - } catch (TimeoutException | VppBaseCallException e) { - throw new WriteFailedException.CreateFailedException(id, dataBefore, e); - } - - LOG.debug("Remove of {} successful", id); + checkAtLeastOnChildExists(id, writeContext, true); } - private void addDelMap(boolean isAdd, int vni, int vrf) throws TimeoutException, VppBaseCallException { + private void checkAtLeastOnChildExists(final InstanceIdentifier<VniTable> id, final WriteContext writeContext, + final boolean before) { - LispEidTableAddDelMap request = new LispEidTableAddDelMap(); + Optional<VniTable> optData; + final InstanceIdentifier<VniTable> trimmedId = RWUtils.cutId(id, InstanceIdentifier.create(VniTable.class)); + if (before) { + optData = writeContext.readBefore(trimmedId); + } else { + optData = writeContext.readAfter(trimmedId); + } - request.isAdd = booleanToByte(isAdd); - request.vni = vni; - request.dpTable = vrf; - request.isL2 = 0; + checkState(optData.isPresent(), "Illegal after-write state"); - getReply(getFutureJVpp().lispEidTableAddDelMap(request).toCompletableFuture()); + final VniTable dataAfter = optData.get(); + checkState(dataAfter.getVrfSubtable() != null || dataAfter.getBridgeDomainSubtable() != null, + "At least one of VrfSubtable/BridgeDomainSubtable must be defined"); } } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/VrfSubtableCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/VrfSubtableCustomizer.java new file mode 100644 index 000000000..a48ec6e22 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/VrfSubtableCustomizer.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2015 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.honeycomb.lisp.translate.write; + +import io.fd.honeycomb.lisp.translate.write.trait.SubtableWriter; +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; +import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import java.util.concurrent.TimeoutException; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import io.fd.vpp.jvpp.VppBaseCallException; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class VrfSubtableCustomizer extends FutureJVppCustomizer + implements WriterCustomizer<VrfSubtable>, SubtableWriter { + + private static final Logger LOG = LoggerFactory.getLogger(VrfSubtableCustomizer.class); + + public VrfSubtableCustomizer(@Nonnull final FutureJVppCore futureJvpp) { + super(futureJvpp); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<VrfSubtable> id, + @Nonnull final VrfSubtable dataAfter, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + + LOG.debug("Writing Id[{}]/Data[{}]", id, dataAfter); + + try { + addDelSubtableMapping(getFutureJVpp(), true, extractVni(id), dataAfter.getTableId().intValue(), false, LOG); + } catch (TimeoutException | VppBaseCallException e) { + throw new WriteFailedException.CreateFailedException(id, dataAfter, e); + } + + LOG.debug("{} successfully written", id); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<VrfSubtable> id, + @Nonnull final VrfSubtable dataBefore, @Nonnull final VrfSubtable dataAfter, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + throw new UnsupportedOperationException("Operation not supported"); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<VrfSubtable> id, + @Nonnull final VrfSubtable dataBefore, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + + LOG.debug("Removing Id[{}]/Data[{}]", id, dataBefore); + + try { + addDelSubtableMapping(getFutureJVpp(), false, extractVni(id), dataBefore.getTableId().intValue(), false, + LOG); + } catch (TimeoutException | VppBaseCallException e) { + throw new WriteFailedException.CreateFailedException(id, dataBefore, e); + } + + LOG.debug("{} successfully removed", id); + } + +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/factory/LispWriterFactory.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/factory/LispWriterFactory.java index aa839ba49..4021cc70c 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/factory/LispWriterFactory.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/factory/LispWriterFactory.java @@ -17,6 +17,7 @@ package io.fd.honeycomb.lisp.translate.write.factory; +import static com.google.common.base.Preconditions.checkNotNull; import static io.fd.honeycomb.lisp.cfgattrs.LispConfiguration.INTERFACE_CONTEXT; import static io.fd.honeycomb.lisp.cfgattrs.LispConfiguration.LOCAL_MAPPING_CONTEXT; import static io.fd.honeycomb.lisp.cfgattrs.LispConfiguration.LOCATOR_SET_CONTEXT; @@ -31,11 +32,12 @@ import io.fd.honeycomb.translate.impl.write.GenericWriter; import io.fd.honeycomb.translate.vpp.util.NamingContext; import io.fd.honeycomb.translate.write.WriterFactory; import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder; +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.rev160520.Lisp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureData; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.pitr.cfg.grouping.PitrCfg; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; /** @@ -43,26 +45,32 @@ import io.fd.vpp.jvpp.core.future.FutureJVppCore; */ public final class LispWriterFactory extends AbstractLispWriterFactoryBase implements WriterFactory { + private final NamingContext bridgeDomainContext; + @Inject public LispWriterFactory(final FutureJVppCore vppApi, @Named(INTERFACE_CONTEXT) final NamingContext interfaceContext, @Named(LOCATOR_SET_CONTEXT) final NamingContext locatorSetContext, + @Named("bridge-domain-context") final NamingContext bridgeDomainContext, @Named(LOCAL_MAPPING_CONTEXT) final EidMappingContext localMappingContext, @Named(REMOTE_MAPPING_CONTEXT) final EidMappingContext remoteMappingContext) { super(InstanceIdentifier.create(Lisp.class), vppApi, interfaceContext, locatorSetContext, localMappingContext, remoteMappingContext); + this.bridgeDomainContext = checkNotNull(bridgeDomainContext, "Bridge domain context cannot be null"); } @Override public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) { registry.add(new GenericWriter<>(lispInstanceIdentifier, new LispCustomizer(vppApi))); - VniTableWriterFactory.newInstance(lispInstanceIdentifier, vppApi, localMappingContext, remoteMappingContext) + VniTableWriterFactory.newInstance(lispInstanceIdentifier, vppApi, localMappingContext, remoteMappingContext, + bridgeDomainContext) .init(registry); LocatorSetsWriterFactory.newInstance(lispInstanceIdentifier, vppApi, interfaceContext, locatorSetContext) .init(registry); MapResolversWriterFactory.newInstance(lispInstanceIdentifier, vppApi).init(registry); - registry.add(new GenericWriter<>(lispInstanceIdentifier.child(PitrCfg.class), new PitrCfgCustomizer(vppApi))); + registry.add(new GenericWriter<>(lispInstanceIdentifier.child(LispFeatureData.class).child(PitrCfg.class), + new PitrCfgCustomizer(vppApi))); } } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/factory/LocatorSetsWriterFactory.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/factory/LocatorSetsWriterFactory.java index d2f70dfda..4ebae0c0f 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/factory/LocatorSetsWriterFactory.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/factory/LocatorSetsWriterFactory.java @@ -24,6 +24,7 @@ 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.opendaylight.params.xml.ns.yang.lisp.rev160520.Lisp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureData; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.LocatorSets; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.LocatorSet; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.locator.set.Interface; @@ -54,7 +55,7 @@ final class LocatorSetsWriterFactory extends AbstractLispWriterFactoryBase imple @Override public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) { InstanceIdentifier<LocatorSet> locatorSetId = - lispInstanceIdentifier.child(LocatorSets.class).child(LocatorSet.class); + lispInstanceIdentifier.child(LispFeatureData.class).child(LocatorSets.class).child(LocatorSet.class); registry.add(new GenericListWriter<>(locatorSetId, new LocatorSetCustomizer(vppApi, locatorSetContext))); registry.add(new GenericListWriter<>(locatorSetId.child(Interface.class), diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/factory/MapResolversWriterFactory.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/factory/MapResolversWriterFactory.java index 6bd251d5b..a4250fb2d 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/factory/MapResolversWriterFactory.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/factory/MapResolversWriterFactory.java @@ -23,6 +23,7 @@ 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.opendaylight.params.xml.ns.yang.lisp.rev160520.Lisp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureData; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.map.resolvers.grouping.MapResolvers; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.map.resolvers.grouping.map.resolvers.MapResolver; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -47,7 +48,8 @@ final class MapResolversWriterFactory extends AbstractLispWriterFactoryBase impl @Override public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) { - registry.add(new GenericListWriter<>(lispInstanceIdentifier.child(MapResolvers.class).child(MapResolver.class), + registry.add(new GenericListWriter<>( + lispInstanceIdentifier.child(LispFeatureData.class).child(MapResolvers.class).child(MapResolver.class), new MapResolverCustomizer(vppApi))); } } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/factory/VniTableWriterFactory.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/factory/VniTableWriterFactory.java index 5fc29845a..4d43b77df 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/factory/VniTableWriterFactory.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/factory/VniTableWriterFactory.java @@ -16,31 +16,41 @@ package io.fd.honeycomb.lisp.translate.write.factory; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.ImmutableSet; import io.fd.honeycomb.lisp.context.util.EidMappingContext; import io.fd.honeycomb.lisp.translate.write.AdjacencyCustomizer; +import io.fd.honeycomb.lisp.translate.write.BridgeDomainSubtableCustomizer; import io.fd.honeycomb.lisp.translate.write.LocalMappingCustomizer; import io.fd.honeycomb.lisp.translate.write.RemoteMappingCustomizer; import io.fd.honeycomb.lisp.translate.write.VniTableCustomizer; +import io.fd.honeycomb.lisp.translate.write.VrfSubtableCustomizer; import io.fd.honeycomb.translate.impl.write.GenericListWriter; +import io.fd.honeycomb.translate.impl.write.GenericWriter; +import io.fd.honeycomb.translate.vpp.util.NamingContext; import io.fd.honeycomb.translate.write.WriterFactory; import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder; +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.rev160520.Lisp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.Adjacencies; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.Adjacency; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.adjacency.LocalEid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.adjacency.RemoteEid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.LocalMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.RemoteMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.negative.mapping.MapReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.positive.mapping.Rlocs; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.positive.mapping.rlocs.Locator; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.Adjacencies; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.LocalMappings; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.RemoteMappings; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.Adjacency; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.adjacency.LocalEid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.adjacency.RemoteEid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMapping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMapping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.locator.list.positive.mapping.Rlocs; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.locator.list.positive.mapping.rlocs.Locator; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureData; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; /** @@ -48,47 +58,91 @@ import io.fd.vpp.jvpp.core.future.FutureJVppCore; */ final class VniTableWriterFactory extends AbstractLispWriterFactoryBase implements WriterFactory { + private final NamingContext bridgeDomainContext; + private VniTableWriterFactory(final InstanceIdentifier<Lisp> lispInstanceIdentifier, final FutureJVppCore vppApi, final EidMappingContext localMappingContext, - final EidMappingContext remoteMappingContext) { + final EidMappingContext remoteMappingContext, + final NamingContext bridgeDomainContext) { super(lispInstanceIdentifier, vppApi, localMappingContext, remoteMappingContext); + this.bridgeDomainContext = checkNotNull(bridgeDomainContext, "Bridge domain context cannot be null"); } public static VniTableWriterFactory newInstance( @Nonnull final InstanceIdentifier<Lisp> lispInstanceIdentifier, @Nonnull final FutureJVppCore vppApi, @Nonnull final EidMappingContext localMappingContext, - @Nonnull final EidMappingContext remoteMappingContext) { - return new VniTableWriterFactory(lispInstanceIdentifier, vppApi, localMappingContext, remoteMappingContext); + @Nonnull final EidMappingContext remoteMappingContext, + @Nonnull final NamingContext bridgeDomainContext) { + return new VniTableWriterFactory(lispInstanceIdentifier, vppApi, localMappingContext, remoteMappingContext, + bridgeDomainContext); } @Override public void init(final ModifiableWriterRegistryBuilder registry) { final InstanceIdentifier<VniTable> vniTableId = - lispInstanceIdentifier.child(EidTable.class).child(VniTable.class); + lispInstanceIdentifier.child(LispFeatureData.class).child(EidTable.class).child(VniTable.class); + + final InstanceIdentifier<VrfSubtable> vrfSubtableId = vniTableId.child(VrfSubtable.class); + final InstanceIdentifier<BridgeDomainSubtable> bridgeDomainSubtableId = + vniTableId.child(BridgeDomainSubtable.class); registry.add(new GenericListWriter<>(vniTableId, new VniTableCustomizer(vppApi))); + registry.add(new GenericWriter<>(vrfSubtableId, new VrfSubtableCustomizer(vppApi))); + registry.add(new GenericWriter<>(bridgeDomainSubtableId, + new BridgeDomainSubtableCustomizer(vppApi, bridgeDomainContext))); + //VniTable - > VrfSubtable -> LocalMappings - > LocalMapping final InstanceIdentifier<LocalMapping> localMappingSubtreeId = InstanceIdentifier.create(LocalMapping.class); registry.subtreeAdd(ImmutableSet.of(localMappingSubtreeId - .child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.Eid.class)), - new GenericListWriter<>(vniTableId.child(LocalMappings.class).child(LocalMapping.class), + .child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid.class)), + new GenericListWriter<>( + vrfSubtableId.child(LocalMappings.class).child(LocalMapping.class), + new LocalMappingCustomizer(vppApi, localMappingContext))); + //VniTable - > BridgeDomainSubtable -> LocalMappings - > LocalMapping + registry.subtreeAdd(ImmutableSet.of(localMappingSubtreeId + .child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid.class)), + new GenericListWriter<>(bridgeDomainSubtableId.child(LocalMappings.class) + .child(LocalMapping.class), new LocalMappingCustomizer(vppApi, localMappingContext))); + //VniTable - > VrfSubtable -> RemoteMappings - > RemoteMapping final InstanceIdentifier<RemoteMapping> remoteMappingSubtreeId = InstanceIdentifier.create(RemoteMapping.class); registry.subtreeAdd(ImmutableSet.of(remoteMappingSubtreeId - .child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.Eid.class), + .child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid.class), + remoteMappingSubtreeId.child(Rlocs.class), + remoteMappingSubtreeId.child(Rlocs.class).child(Locator.class), + remoteMappingSubtreeId.child(MapReply.class)), + new GenericListWriter<>( + vrfSubtableId.child(RemoteMappings.class).child(RemoteMapping.class), + new RemoteMappingCustomizer(vppApi, remoteMappingContext))); + //VniTable - > BridgeDomainSubtable -> RemoteMappings - > RemoteMapping + registry.subtreeAdd(ImmutableSet.of(remoteMappingSubtreeId + .child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid.class), remoteMappingSubtreeId.child(Rlocs.class), - remoteMappingSubtreeId.child(Rlocs.class).child(Locator.class)), - new GenericListWriter<>(vniTableId.child(RemoteMappings.class).child(RemoteMapping.class), + remoteMappingSubtreeId.child(Rlocs.class).child(Locator.class), + remoteMappingSubtreeId.child(MapReply.class)), + new GenericListWriter<>(bridgeDomainSubtableId.child(RemoteMappings.class) + .child(RemoteMapping.class), new RemoteMappingCustomizer(vppApi, remoteMappingContext))); + //VniTable - > VrfSubtable -> RemoteMappings - > RemoteMapping - > Adjacencies - > Adjacency final InstanceIdentifier<Adjacency> adjacencySubtreeId = InstanceIdentifier.create(Adjacency.class); registry.subtreeAdd(ImmutableSet.of(adjacencySubtreeId .child(LocalEid.class), adjacencySubtreeId.child(RemoteEid.class)), - new GenericListWriter<>(vniTableId.child(Adjacencies.class).child(Adjacency.class), - new AdjacencyCustomizer(vppApi))); + new GenericListWriter<>( + vrfSubtableId.child(RemoteMappings.class).child(RemoteMapping.class) + .child(Adjacencies.class).child(Adjacency.class), + new AdjacencyCustomizer(vppApi, localMappingContext, remoteMappingContext))); + //VniTable - > BridgeDomainSubtable -> RemoteMappings - > RemoteMapping - > Adjacencies - > Adjacency + registry.subtreeAdd(ImmutableSet.of(adjacencySubtreeId + .child(LocalEid.class), adjacencySubtreeId.child(RemoteEid.class)), + new GenericListWriter<>( + bridgeDomainSubtableId.child(RemoteMappings.class) + .child(RemoteMapping.class) + .child(Adjacencies.class).child(Adjacency.class), + new AdjacencyCustomizer(vppApi, localMappingContext, remoteMappingContext))); } } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/trait/SubtableWriter.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/trait/SubtableWriter.java new file mode 100644 index 000000000..d7f46ad9b --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/write/trait/SubtableWriter.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2015 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.honeycomb.lisp.translate.write.trait; + + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator; +import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer; +import java.util.concurrent.TimeoutException; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; +import org.opendaylight.yangtools.yang.binding.ChildOf; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import io.fd.vpp.jvpp.VppBaseCallException; +import io.fd.vpp.jvpp.core.dto.LispEidTableAddDelMap; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import org.slf4j.Logger; + +/** + * Trait providing logic for writing subtables + */ +public interface SubtableWriter extends ByteDataTranslator, JvppReplyConsumer { + int DEFAULT_VNI = 0; + + /** + * Writes mapping from {@link VniTable} + * to {@link VrfSubtable} or + * {@link BridgeDomainSubtable} + * + * @param addDel true if add,delete otherwise + * @param vni {@link VniTable} ID + * @param tableId if <b>isL2</b> is true, than bridge domain subtable id,else vrf subtable id + * @param isL2 indicates whether (false) writing to L3 vrfSubtrable of (true) L2 bridgeDomainSubtrable + */ + default void addDelSubtableMapping(@Nonnull final FutureJVppCore vppApi, final boolean addDel, final int vni, + final int tableId, + final boolean isL2, + final Logger logger) throws TimeoutException, VppBaseCallException { + + if (vni == DEFAULT_VNI) { + // attempt to write subtable with default vni mapping(it does'nt make sense and it should'nt be possible) + // also allows to enable lisp without defining default mapping in request + logger.info("An attempt to write subtable[id = {}] with default vni {} was detected, ignoring write", + tableId, DEFAULT_VNI); + return; + } + + checkNotNull(vppApi, "VPP Api refference cannot be null"); + + LispEidTableAddDelMap request = new LispEidTableAddDelMap(); + + request.isAdd = booleanToByte(addDel); + request.vni = vni; + request.dpTable = tableId; + request.isL2 = booleanToByte(isL2); + + getReply(vppApi.lispEidTableAddDelMap(request).toCompletableFuture()); + } + + default int extractVni(@Nonnull final InstanceIdentifier<? extends ChildOf<VniTable>> id) { + return checkNotNull( + checkNotNull(id, "Identifier cannot be null").firstKeyOf(VniTable.class), + "Parent VNI id not defined").getVirtualNetworkIdentifier().intValue(); + } +} diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/LispModuleTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/LispModuleTest.java index 76cebc882..6d1e05ce8 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/LispModuleTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/LispModuleTest.java @@ -47,6 +47,10 @@ public class LispModuleTest { @Bind private NamingContext interfaceContext; + @Named("bridge-domain-context") + @Bind + private NamingContext bridgeDomainContext; + @Named("honeycomb-context") @Bind @Mock @@ -71,6 +75,7 @@ public class LispModuleTest { public void setUp() throws Exception { initMocks(this); interfaceContext = new NamingContext("interfaceContext", "interfaceContext"); + bridgeDomainContext = new NamingContext("bridgeDomainContext", "bridgeDomainContext"); Guice.createInjector(new LispModule(), BoundFieldModule.of(this)).injectMembers(this); } diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/context/util/EidMappingContextTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/context/util/EidMappingContextTest.java index 710477a70..1691a9e87 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/context/util/EidMappingContextTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/context/util/EidMappingContextTest.java @@ -19,62 +19,76 @@ package io.fd.honeycomb.lisp.context.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.when; -import com.google.common.base.Optional; +import io.fd.honeycomb.lisp.util.EidMappingContextHelper; import io.fd.honeycomb.translate.MappingContext; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.MappingBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MappingId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.Eid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.EidBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder; -public class EidMappingContextTest { +public class EidMappingContextTest implements EidMappingContextHelper { - private EidMappingContext eidMappingContext; + private static final String EID_MAPPING_CONTEXT_NAME = "eidMappingContext"; @Mock private MappingContext mappingContext; + private EidMappingContext eidMappingContext; + private Eid localEid; + private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid + remoteEid; + private org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid + mappingEid; + private MappingId mappingId; + @Before public void init() { MockitoAnnotations.initMocks(this); - eidMappingContext = new EidMappingContext("eid-eidMappingContext"); - } + eidMappingContext = new EidMappingContext(EID_MAPPING_CONTEXT_NAME); - @Test - public void testStoreAndGet() { - Eid eid = + localEid = new EidBuilder().setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build()).build(); - MappingId id = new MappingId("first"); - - eidMappingContext.addEid(id, eid, mappingContext); - when(mappingContext.read(Mockito.any(InstanceIdentifier.class))) - .thenReturn(Optional.of( - new MappingBuilder().setId(id).setEid(copyEid(eid)).build() - )); + remoteEid = fromLocalToRemoteEid(localEid); + mappingEid = fromLocalToMappingEid(localEid); + mappingId = new MappingId("mapping"); - Eid sameEid = - new EidBuilder().setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build()).build(); - MappingId sameId = new MappingId("first"); - - assertTrue(eidMappingContext.containsEid(sameId, mappingContext)); + defineMapping(mappingContext, mappingEid, mappingId, EID_MAPPING_CONTEXT_NAME); + } + @Test + public void testContainsEid() { + assertTrue(eidMappingContext.containsEid(mappingId, mappingContext)); org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid - loadedEid = eidMappingContext.getEid(sameId, mappingContext); + loadedEid = eidMappingContext.getEid(mappingId, mappingContext); assertEquals("192.168.2.1", ((Ipv4) (loadedEid.getAddress())).getIpv4().getValue()); } - private org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid copyEid( + @Test + public void testContainsId() { + assertTrue(eidMappingContext.containsId(localEid, mappingContext)); + assertTrue(eidMappingContext.containsId(remoteEid, mappingContext)); + } + + @Test + public void testGetEid() { + assertEquals(mappingEid, eidMappingContext.getEid(mappingId, mappingContext)); + } + + @Test + public void testGetId() { + assertEquals(mappingId, eidMappingContext.getId(localEid, mappingContext)); + assertEquals(mappingId, eidMappingContext.getId(remoteEid, mappingContext)); + } + + private org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid fromLocalToMappingEid( Eid eid) { return new org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.EidBuilder() .setAddress(eid.getAddress()) @@ -82,4 +96,13 @@ public class EidMappingContextTest { .setVirtualNetworkId(eid.getVirtualNetworkId()) .build(); } + + private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid fromLocalToRemoteEid( + Eid eid) { + return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder() + .setAddress(eid.getAddress()) + .setAddressType(eid.getAddressType()) + .setVirtualNetworkId(eid.getVirtualNetworkId()) + .build(); + } } diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/initializers/LispInitializerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/initializers/LispInitializerTest.java index 087f2cdee..4da6593e0 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/initializers/LispInitializerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/initializers/LispInitializerTest.java @@ -9,10 +9,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.Lisp; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.LispState; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.LispStateBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTableBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.LocatorSetsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.map.resolvers.grouping.MapResolversBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.pitr.cfg.grouping.PitrCfgBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureDataBuilder; public class LispInitializerTest { @@ -22,21 +19,14 @@ public class LispInitializerTest { final LispInitializer initializer = new LispInitializer(mock(DataBroker.class)); final LispState state = new LispStateBuilder() .setEnable(true) - .setEidTable(new EidTableBuilder().build()) - .setLocatorSets(new LocatorSetsBuilder().build()) - .setMapResolvers(new MapResolversBuilder().build()) - .setPitrCfg(new PitrCfgBuilder().build()) + .setLispFeatureData(new LispFeatureDataBuilder().build()) .build(); final Lisp operational = initializer.convert(state); assertNotNull(operational); - assertEquals(operational.getPitrCfg(), state.getPitrCfg()); assertEquals(operational.isEnable(), state.isEnable()); - assertEquals(operational.getEidTable(), state.getEidTable()); - assertEquals(operational.getLocatorSets(), state.getLocatorSets()); - assertEquals(operational.getMapResolvers(), state.getMapResolvers()); - + assertEquals(operational.getLispFeatureData(), state.getLispFeatureData()); } }
\ No newline at end of file diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/AdjacencyCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/AdjacencyCustomizerTest.java index 0a88f946c..861fff67c 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/AdjacencyCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/AdjacencyCustomizerTest.java @@ -7,10 +7,10 @@ import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest; import org.junit.Before; import org.junit.Test; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.AdjacenciesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.Adjacency; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.AdjacencyBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.AdjacencyKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.AdjacenciesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.Adjacency; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.AdjacencyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.AdjacencyKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/BridgeDomainSubtableCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/BridgeDomainSubtableCustomizerTest.java new file mode 100644 index 000000000..5902028fe --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/BridgeDomainSubtableCustomizerTest.java @@ -0,0 +1,104 @@ +package io.fd.honeycomb.lisp.translate.read; + + +import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.SubtableDumpParams.MapLevel.L2; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import io.fd.honeycomb.lisp.translate.read.trait.SubtableReaderTestCase; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpCallFailedException; +import io.fd.honeycomb.translate.vpp.util.NamingContext; +import io.fd.vpp.jvpp.VppCallbackException; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtableBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class BridgeDomainSubtableCustomizerTest + extends SubtableReaderTestCase<BridgeDomainSubtable, BridgeDomainSubtableBuilder> { + + private InstanceIdentifier<BridgeDomainSubtable> validId; + private NamingContext bridgeDomainContext; + + public BridgeDomainSubtableCustomizerTest() { + super(BridgeDomainSubtable.class, VniTableBuilder.class); + } + + @Override + protected void setUp() throws Exception { + bridgeDomainContext = new NamingContext("br", "br-domain-context"); + validId = InstanceIdentifier.create(EidTable.class).child(VniTable.class, new VniTableKey(expectedVni)) + .child(BridgeDomainSubtable.class); + + defineMapping(mappingContext, "br-domain", expectedTableId, "br-domain-context"); + } + + @Test + public void testReadCurrentSuccessfull() throws ReadFailedException { + doReturnValidNonEmptyDataOnDump(); + BridgeDomainSubtableBuilder builder = new BridgeDomainSubtableBuilder(); + customizer.readCurrentAttributes(validId, builder, ctx); + + verifyLispEidTableMapDumpCalled(L2); + + final BridgeDomainSubtable subtable = builder.build(); + assertNotNull(subtable); + assertEquals("br-domain", subtable.getBridgeDomainRef()); + } + + + @Test + public void testReadCurrentEmptyDump() throws ReadFailedException { + doReturnEmptyDataOnDump(); + BridgeDomainSubtableBuilder builder = new BridgeDomainSubtableBuilder(); + customizer.readCurrentAttributes(validId, builder, ctx); + + verifyLispEidTableMapDumpCalled(L2); + + final BridgeDomainSubtable subtable = builder.build(); + assertNotNull(subtable); + assertNull(subtable.getBridgeDomainRef()); + } + + @Test + public void testReadCurrentFailed() { + doThrowOnDump(); + BridgeDomainSubtableBuilder builder = new BridgeDomainSubtableBuilder(); + try { + customizer.readCurrentAttributes(validId, builder, ctx); + } catch (ReadFailedException e) { + assertTrue(e.getCause() instanceof DumpCallFailedException); + assertTrue(e.getCause().getCause() instanceof VppCallbackException); + assertNull(builder.getBridgeDomainRef()); + verifyLispEidTableMapDumpNotCalled(); + + return; + } + + fail("Test should throw ReadFailedException"); + } + + @Test + public void testGetBuilder() { + final BridgeDomainSubtableBuilder builder = customizer.getBuilder(validId); + + assertNotNull(builder); + assertNull(builder.getLocalMappings()); + assertNull(builder.getRemoteMappings()); + assertNull(builder.getBridgeDomainRef()); + } + + @Override + protected ReaderCustomizer<BridgeDomainSubtable, BridgeDomainSubtableBuilder> initCustomizer() { + return new BridgeDomainSubtableCustomizer(api, bridgeDomainContext); + } +} diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/ItrRemoteLocatorSetCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/ItrRemoteLocatorSetCustomizerTest.java new file mode 100644 index 000000000..a1688ae35 --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/ItrRemoteLocatorSetCustomizerTest.java @@ -0,0 +1,150 @@ +package io.fd.honeycomb.lisp.translate.read; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +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.when; + +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpCallFailedException; +import io.fd.honeycomb.vpp.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; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.itr.remote.locator.sets.grouping.ItrRemoteLocatorSet; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.itr.remote.locator.sets.grouping.ItrRemoteLocatorSetBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureDataBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + + +public class ItrRemoteLocatorSetCustomizerTest + extends ReaderCustomizerTest<ItrRemoteLocatorSet, ItrRemoteLocatorSetBuilder> { + + private static final String EXPECTED_LOCATOR_SET_NAME = "loc-set"; + + private InstanceIdentifier<ItrRemoteLocatorSet> validId; + private ItrRemoteLocatorSetBuilder builder; + + public ItrRemoteLocatorSetCustomizerTest() { + super(ItrRemoteLocatorSet.class, LispFeatureDataBuilder.class); + } + + @Before + public void setUp() throws Exception { + validId = InstanceIdentifier.create(ItrRemoteLocatorSet.class); + builder = new ItrRemoteLocatorSetBuilder(); + } + + @Override + protected ReaderCustomizer<ItrRemoteLocatorSet, ItrRemoteLocatorSetBuilder> initCustomizer() { + return new ItrRemoteLocatorSetCustomizer(api); + } + + @Test + public void getBuilder() throws Exception { + final ItrRemoteLocatorSetBuilder itrRemoteLocatorSetBuilder = getCustomizer().getBuilder(validId); + + assertNotNull(itrRemoteLocatorSetBuilder); + assertNull(itrRemoteLocatorSetBuilder.getRemoteLocatorSetName()); + } + + @Test + public void readCurrentAttributesSuccess() throws Exception { + doReturnValidDataOnDump(); + + getCustomizer().readCurrentAttributes(validId, builder, ctx); + + assertNotNull(builder); + assertEquals(EXPECTED_LOCATOR_SET_NAME, builder.getRemoteLocatorSetName()); + verifyLispGetMapRequestItrRlocsInvokedOnce(); + } + + @Test + public void readCurrentAttributesEmptyData() throws Exception { + doReturnEmptyDataOnDump(); + getCustomizer().readCurrentAttributes(validId, builder, ctx); + verifyInvalidDataCase(builder); + } + + @Test + public void readCurrentAttributesFailedCallHalted() { + doThrowExceptionOnDump(); + try { + getCustomizer().readCurrentAttributes(validId, builder, ctx); + } catch (ReadFailedException e) { + assertTrue(e.getCause() instanceof DumpCallFailedException); + assertTrue(e.getCause().getCause() instanceof VppCallbackException); + assertNotNull(builder); + assertNull(builder.getRemoteLocatorSetName()); + + verifyLispGetMapRequestItrRlocsInvokedOnce(); + return; + } + + fail("Test should have thrown exception"); + } + + @Test + public void merge() throws Exception { + LispFeatureDataBuilder builder = new LispFeatureDataBuilder(); + ItrRemoteLocatorSet set = new ItrRemoteLocatorSetBuilder().setRemoteLocatorSetName("loc-set").build(); + getCustomizer().merge(builder, set); + + assertNotNull(builder); + assertEquals(set, builder.getItrRemoteLocatorSet()); + } + + + private void doReturnValidDataOnDump() { + LispGetMapRequestItrRlocsReply reply = new LispGetMapRequestItrRlocsReply(); + reply.locatorSetName = EXPECTED_LOCATOR_SET_NAME.getBytes(StandardCharsets.UTF_8); + + when(api.lispGetMapRequestItrRlocs(any(LispGetMapRequestItrRlocs.class))) + .thenReturn(CompletableFuture.completedFuture(reply)); + } + + private void doReturnNullDataOnDump() { + when(api.lispGetMapRequestItrRlocs(any(LispGetMapRequestItrRlocs.class))) + .thenReturn(CompletableFuture.completedFuture(null)); + } + + private void doReturnEmptyDataOnDump() { + when(api.lispGetMapRequestItrRlocs(any(LispGetMapRequestItrRlocs.class))) + .thenReturn(CompletableFuture.completedFuture(new LispGetMapRequestItrRlocsReply())); + } + + private void doThrowExceptionOnDump() { + when(api.lispGetMapRequestItrRlocs(any(LispGetMapRequestItrRlocs.class))). + thenReturn(new CompletableFuture<LispGetMapRequestItrRlocsReply>() { + @Override + public LispGetMapRequestItrRlocsReply get(final long l, final TimeUnit timeUnit) + throws InterruptedException, ExecutionException, TimeoutException { + throw new ExecutionException(new VppCallbackException("lispGetMapRequestItrRlocs", 1, -2)); + } + }); + } + + private void verifyLispGetMapRequestItrRlocsInvokedOnce() { + verify(api, times(1)).lispGetMapRequestItrRlocs(any(LispGetMapRequestItrRlocs.class)); + } + + private void verifyInvalidDataCase(final ItrRemoteLocatorSetBuilder builder) { + assertNotNull(builder); + assertNull(builder.getRemoteLocatorSetName()); + + verifyLispGetMapRequestItrRlocsInvokedOnce(); + } +}
\ No newline at end of file diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/LocalMappingCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/LocalMappingCustomizerTest.java index 3b1506e39..a7317b9cc 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/LocalMappingCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/LocalMappingCustomizerTest.java @@ -1,5 +1,6 @@ package io.fd.honeycomb.lisp.translate.read; +import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV4; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Matchers.any; @@ -7,6 +8,7 @@ import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableList; import io.fd.honeycomb.lisp.context.util.EidMappingContext; +import io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams; import io.fd.honeycomb.lisp.translate.util.EidTranslator; import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; @@ -20,15 +22,17 @@ 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.lisp.address.types.rev151105.lisp.address.address.Ipv4; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MappingId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.LocalMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.LocalMappingsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMappingKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.LocalMappings; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.LocalMappingsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMapping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMappingBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMappingKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.Eid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import io.fd.vpp.jvpp.core.dto.LispEidTableDetails; import io.fd.vpp.jvpp.core.dto.LispEidTableDetailsReplyDump; @@ -53,11 +57,13 @@ public class LocalMappingCustomizerTest extends public void setUp() { emptyIdentifier = InstanceIdentifier.create(EidTable.class) .child(VniTable.class, new VniTableKey(12L)) + .child(VrfSubtable.class) .child(LocalMappings.class) .child(LocalMapping.class); validIdentifier = InstanceIdentifier.create(EidTable.class) .child(VniTable.class, new VniTableKey(12L)) + .child(VrfSubtable.class) .child(LocalMappings.class) .child(LocalMapping.class, new LocalMappingKey(new MappingId("local-mapping"))); @@ -73,6 +79,7 @@ public class LocalMappingCustomizerTest extends detail.context = 4; detail.eid = new byte[]{-64, -88, 2, 1}; detail.eidPrefixLen = 32; + detail.eidType = (byte) IPV4.getValue(); detail.isLocal = 1; detail.locatorSetIndex = 1; detail.ttl = 7; diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/MapResolverCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/MapResolverCustomizerTest.java index 7afd8dd4f..112350676 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/MapResolverCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/MapResolverCustomizerTest.java @@ -8,6 +8,8 @@ import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableList; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest; +import io.fd.vpp.jvpp.core.dto.LispMapResolverDetails; +import io.fd.vpp.jvpp.core.dto.LispMapResolverDetailsReplyDump; import java.util.List; import org.junit.Before; import org.junit.Test; @@ -19,14 +21,11 @@ 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.rev160520.map.resolvers.grouping.map.resolvers.MapResolverBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.map.resolvers.grouping.map.resolvers.MapResolverKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.LispMapResolverDetails; -import io.fd.vpp.jvpp.core.dto.LispMapResolverDetailsReplyDump; public class MapResolverCustomizerTest extends ListReaderCustomizerTest<MapResolver, MapResolverKey, MapResolverBuilder> { - private static final IpAddress IP_ADDRESS = new IpAddress(new Ipv4AddressNoZone("192.168.2.1")); private static final IpAddress IP_ADDRESS_REVERTED = new IpAddress(new Ipv4AddressNoZone("1.2.168.192")); @@ -64,7 +63,7 @@ public class MapResolverCustomizerTest final MapResolverKey key = keys.get(0); assertNotNull(key); - assertEquals("192.168.2.1", new String(key.getIpAddress().getValue())); + assertEquals("1.2.168.192", new String(key.getIpAddress().getValue())); } diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/PitrCfgCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/PitrCfgCustomizerTest.java index c46d1f454..6c345223e 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/PitrCfgCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/PitrCfgCustomizerTest.java @@ -11,6 +11,7 @@ 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.rev160520.LispStateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureDataBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.pitr.cfg.grouping.PitrCfg; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.pitr.cfg.grouping.PitrCfgBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -22,16 +23,14 @@ public class PitrCfgCustomizerTest extends ReaderCustomizerTest<PitrCfg, PitrCfg private static final byte[] LOC_SET_NAME_BYTES = "loc-set".getBytes(StandardCharsets.UTF_8); private InstanceIdentifier<PitrCfg> emptyId; - private PitrCfg validData; public PitrCfgCustomizerTest() { - super(PitrCfg.class, LispStateBuilder.class); + super(PitrCfg.class, LispFeatureDataBuilder.class); } @Before public void init() { emptyId = InstanceIdentifier.create(PitrCfg.class); - validData = new PitrCfgBuilder().setLocatorSet("loc-set").build(); mockDumpData(); } diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/RemoteMappingCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/RemoteMappingCustomizerTest.java index a431d224c..5ab8e5996 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/RemoteMappingCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/RemoteMappingCustomizerTest.java @@ -2,6 +2,7 @@ package io.fd.honeycomb.lisp.translate.read; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Mockito.when; @@ -11,6 +12,11 @@ import io.fd.honeycomb.lisp.translate.util.EidTranslator; import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest; +import io.fd.vpp.jvpp.core.dto.LispEidTableDetails; +import io.fd.vpp.jvpp.core.dto.LispEidTableDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.LispLocatorDetails; +import io.fd.vpp.jvpp.core.dto.LispLocatorDetailsReplyDump; +import java.util.Collections; import java.util.List; import org.junit.Before; import org.junit.Test; @@ -19,19 +25,22 @@ import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MapReplyAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MappingId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.RemoteMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.RemoteMappingsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMappingKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.NegativeMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.PositiveMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.positive.mapping.rlocs.Locator; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.RemoteMappings; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.RemoteMappingsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMapping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMappingBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMappingKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.Eid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.LispEidTableDetails; -import io.fd.vpp.jvpp.core.dto.LispEidTableDetailsReplyDump; public class RemoteMappingCustomizerTest extends ListReaderCustomizerTest<RemoteMapping, RemoteMappingKey, RemoteMappingBuilder> @@ -43,7 +52,6 @@ public class RemoteMappingCustomizerTest @Mock private EidMappingContext eidMappingContext; - private InstanceIdentifier<RemoteMapping> emptyId; private InstanceIdentifier<RemoteMapping> validId; public RemoteMappingCustomizerTest() { @@ -53,22 +61,56 @@ public class RemoteMappingCustomizerTest @Before public void init() { - emptyId = InstanceIdentifier.create(EidTable.class) - .child(VniTable.class, new VniTableKey(12L)) - .child(RemoteMappings.class) - .child(RemoteMapping.class); - validId = InstanceIdentifier.create(EidTable.class) .child(VniTable.class, new VniTableKey(12L)) + .child(VrfSubtable.class) .child(RemoteMappings.class) .child(RemoteMapping.class, new RemoteMappingKey(new MappingId("remote-mapping"))); - - mockDumpData(); mockMappings(); } - private void mockDumpData() { + private void mockDumpDataActionZero() { + LispEidTableDetailsReplyDump replyDump = new LispEidTableDetailsReplyDump(); + LispEidTableDetails detail = new LispEidTableDetails(); + detail.action = 0; + detail.authoritative = 1; + detail.context = 4; + detail.eid = new byte[]{-64, -88, 2, 1}; + detail.eidPrefixLen = 32; + detail.isLocal = 0; + detail.locatorSetIndex = 1; + detail.ttl = 7; + detail.vni = 12; + + replyDump.lispEidTableDetails = ImmutableList.of(detail); + + when(api.lispEidTableDump(any())).thenReturn(future(replyDump)); + + LispLocatorDetailsReplyDump rlocs = new LispLocatorDetailsReplyDump(); + rlocs.lispLocatorDetails = Collections.emptyList(); + when(api.lispLocatorDump(any())).thenReturn(future(rlocs)); + } + + private void mockDumpDataActionOne() { + LispEidTableDetailsReplyDump replyDump = new LispEidTableDetailsReplyDump(); + LispEidTableDetails detail = new LispEidTableDetails(); + detail.action = 1; + detail.authoritative = 1; + detail.context = 4; + detail.eid = new byte[]{-64, -88, 2, 1}; + detail.eidPrefixLen = 32; + detail.isLocal = 0; + detail.locatorSetIndex = 1; + detail.ttl = 7; + detail.vni = 12; + + replyDump.lispEidTableDetails = ImmutableList.of(detail); + + when(api.lispEidTableDump(any())).thenReturn(future(replyDump)); + } + + private void mockDumpDataActionZeroWithRemotes() { LispEidTableDetailsReplyDump replyDump = new LispEidTableDetailsReplyDump(); LispEidTableDetails detail = new LispEidTableDetails(); detail.action = 0; @@ -84,8 +126,20 @@ public class RemoteMappingCustomizerTest replyDump.lispEidTableDetails = ImmutableList.of(detail); when(api.lispEidTableDump(any())).thenReturn(future(replyDump)); + + LispLocatorDetailsReplyDump rlocs = new LispLocatorDetailsReplyDump(); + LispLocatorDetails rloc = new LispLocatorDetails(); + rloc.ipAddress = new byte[]{-64, -88, 2, 1}; + rloc.isIpv6 = 0; + rloc.priority = 1; + rloc.weight = 2; + + rlocs.lispLocatorDetails = ImmutableList.of(rloc); + + when(api.lispLocatorDump(any())).thenReturn(future(rlocs)); } + private void mockMappings() { when(eidMappingContext.getId(any(Eid.class), any(MappingContext.class))) @@ -96,7 +150,41 @@ public class RemoteMappingCustomizerTest } @Test - public void readCurrentAttributes() throws Exception { + public void readCurrentAttributesNegativeMappingOne() throws Exception { + mockDumpDataActionOne(); + RemoteMappingBuilder builder = new RemoteMappingBuilder(); + getCustomizer().readCurrentAttributes(validId, builder, ctx); + + RemoteMapping mapping = builder.build(); + + assertNotNull(mapping); + assertEquals(true, compareAddresses(EID_ADDRESS, mapping.getEid().getAddress())); + assertEquals(true, mapping.getAuthoritative().isA()); + assertEquals(7L, mapping.getTtl().longValue()); + assertTrue(mapping.getLocatorList() instanceof NegativeMapping); + assertEquals(MapReplyAction.NativelyForward, + ((NegativeMapping) mapping.getLocatorList()).getMapReply().getMapReplyAction()); + } + + @Test + public void readCurrentAttributesNegativeMappingZero() throws Exception { + mockDumpDataActionZero(); + RemoteMappingBuilder builder = new RemoteMappingBuilder(); + getCustomizer().readCurrentAttributes(validId, builder, ctx); + + RemoteMapping mapping = builder.build(); + + assertNotNull(mapping); + assertEquals(true, compareAddresses(EID_ADDRESS, mapping.getEid().getAddress())); + assertEquals(true, mapping.getAuthoritative().isA()); + assertEquals(7L, mapping.getTtl().longValue()); + assertEquals(MapReplyAction.NoAction, + ((NegativeMapping) mapping.getLocatorList()).getMapReply().getMapReplyAction()); + } + + @Test + public void readCurrentAttributesPositiveMapping() throws Exception { + mockDumpDataActionZeroWithRemotes(); RemoteMappingBuilder builder = new RemoteMappingBuilder(); getCustomizer().readCurrentAttributes(validId, builder, ctx); @@ -106,11 +194,20 @@ public class RemoteMappingCustomizerTest assertEquals(true, compareAddresses(EID_ADDRESS, mapping.getEid().getAddress())); assertEquals(true, mapping.getAuthoritative().isA()); assertEquals(7L, mapping.getTtl().longValue()); + assertTrue(mapping.getLocatorList() instanceof PositiveMapping); + + final List<Locator> locators = ((PositiveMapping) mapping.getLocatorList()).getRlocs().getLocator(); + assertEquals(1, locators.size()); + final Locator locator = locators.get(0); + assertEquals("192.168.2.1", locator.getAddress().getIpv4Address().getValue()); + assertEquals(1, locator.getPriority().shortValue()); + assertEquals(2, locator.getWeight().shortValue()); } @Test public void getAllIds() throws Exception { + mockDumpDataActionOne(); final List<RemoteMappingKey> keys = getCustomizer().getAllIds(validId, ctx); assertNotNull(keys); diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/VniTableCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/VniTableCustomizerTest.java index f4fe52c5d..fe967e486 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/VniTableCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/VniTableCustomizerTest.java @@ -1,25 +1,34 @@ package io.fd.honeycomb.lisp.translate.read; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; import com.google.common.collect.ImmutableList; +import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpCallFailedException; import io.fd.honeycomb.vpp.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; import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import org.junit.Before; import org.junit.Test; +import org.mockito.Mockito; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTableBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetails; -import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump; - public class VniTableCustomizerTest extends ListReaderCustomizerTest<VniTable, VniTableKey, VniTableBuilder> { @@ -31,41 +40,72 @@ public class VniTableCustomizerTest extends ListReaderCustomizerTest<VniTable, V @Before public void init() { - validId = InstanceIdentifier.create(EidTable.class).child(VniTable.class, new VniTableKey(2L)); - - final LispEidTableMapDetailsReplyDump replyDump = new LispEidTableMapDetailsReplyDump(); - final LispEidTableMapDetails detail = new LispEidTableMapDetails(); - detail.dpTable = 3; - detail.vni = 2; - detail.context = 4; - replyDump.lispEidTableMapDetails = ImmutableList.of(detail); - - when(api.lispEidTableMapDump(any())).thenReturn(future(replyDump)); + validId = InstanceIdentifier.create(EidTable.class).child(VniTable.class, new VniTableKey(12L)); } @Test - public void getAllIds() throws Exception { + public void testReadAllSuccessfull() throws ReadFailedException { + whenLispEidTableVniDumpReturnValid(); final List<VniTableKey> keys = getCustomizer().getAllIds(validId, ctx); - assertEquals(1, keys.size()); + assertNotNull(keys); + assertEquals(3, keys.size()); + assertTrue(keys.contains(new VniTableKey(12L))); + assertTrue(keys.contains(new VniTableKey(14L))); + assertTrue(keys.contains(new VniTableKey(16L))); + } - final VniTableKey key = keys.get(0); - assertNotNull(key); - //due to ambigous call (long,long) vs (Object,Object) - assertEquals(2L, key.getVirtualNetworkIdentifier().longValue()); + @Test + public void testReadAllFailed() { + whenLispEidTableVniDumpThrowException(); + try { + getCustomizer().getAllIds(validId, ctx); + } catch (ReadFailedException e) { + assertTrue(e instanceof ReadFailedException); + assertTrue(e.getCause() instanceof DumpCallFailedException); + assertTrue(e.getCause().getCause() instanceof VppCallbackException); + } } @Test - public void readCurrentAttributes() throws Exception { + public void testReadAttributes() throws ReadFailedException { + whenLispEidTableVniDumpReturnValid(); VniTableBuilder builder = new VniTableBuilder(); - getCustomizer().readCurrentAttributes(validId, builder, ctx); - final VniTable table = builder.build(); + customizer.readCurrentAttributes(validId, builder, ctx); + final VniTable table = builder.build(); assertNotNull(table); - assertEquals(3L, table.getTableId().longValue()); - assertEquals(2L, table.getVirtualNetworkIdentifier().longValue()); + assertEquals(12L, table.getVirtualNetworkIdentifier().longValue()); + } + + private void whenLispEidTableVniDumpReturnValid() { + + LispEidTableVniDetailsReplyDump dump = new LispEidTableVniDetailsReplyDump(); + LispEidTableVniDetails details1 = new LispEidTableVniDetails(); + details1.vni = 14; + + LispEidTableVniDetails details2 = new LispEidTableVniDetails(); + details2.vni = 12; + + LispEidTableVniDetails details3 = new LispEidTableVniDetails(); + details3.vni = 16; + + dump.lispEidTableVniDetails = ImmutableList.of(details1, details2, details3); + + when(api.lispEidTableVniDump(Mockito.any())).thenReturn(CompletableFuture.completedFuture(dump)); + } + + private void whenLispEidTableVniDumpThrowException() { + when(api.lispEidTableVniDump(Mockito.any())) + .thenReturn(new CompletableFuture<LispEidTableVniDetailsReplyDump>() { + @Override + public LispEidTableVniDetailsReplyDump get(final long l, final TimeUnit timeUnit) + throws InterruptedException, ExecutionException, TimeoutException { + throw new ExecutionException(new VppCallbackException("lispEidTableVniDump", 1, -2)); + } + }); } @Override diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/VrfSubtableCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/VrfSubtableCustomizerTest.java new file mode 100644 index 000000000..f18f349d8 --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/VrfSubtableCustomizerTest.java @@ -0,0 +1,107 @@ +package io.fd.honeycomb.lisp.translate.read; + + +import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.SubtableDumpParams.MapLevel.L3; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import io.fd.honeycomb.lisp.translate.read.trait.SubtableReaderTestCase; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpCallFailedException; +import io.fd.vpp.jvpp.VppCallbackException; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtableBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class VrfSubtableCustomizerTest extends SubtableReaderTestCase<VrfSubtable, VrfSubtableBuilder> { + + private InstanceIdentifier<VrfSubtable> validId; + + public VrfSubtableCustomizerTest() { + super(VrfSubtable.class, VrfSubtableBuilder.class); + } + + @Before + public void init() { + validId = InstanceIdentifier.create(EidTable.class).child(VniTable.class, new VniTableKey(expectedVni)) + .child(VrfSubtable.class); + } + + @Test + public void testReadCurrentSuccessfull() throws ReadFailedException { + doReturnValidNonEmptyDataOnDump(); + VrfSubtableBuilder builder = new VrfSubtableBuilder(); + customizer.readCurrentAttributes(validId, builder, ctx); + + verifyLispEidTableMapDumpCalled(L3); + + final VrfSubtable subtable = builder.build(); + assertNotNull(subtable); + assertEquals(expectedTableId, subtable.getTableId().longValue()); + } + + @Test + public void testReadCurrentEmptyDump() throws ReadFailedException { + doReturnEmptyDataOnDump(); + VrfSubtableBuilder builder = new VrfSubtableBuilder(); + customizer.readCurrentAttributes(validId, builder, ctx); + + verifyLispEidTableMapDumpCalled(L3); + + final VrfSubtable subtable = builder.build(); + assertNotNull(subtable); + assertNull(subtable.getTableId()); + } + + @Test + public void testReadCurrentFailed() { + doThrowOnDump(); + VrfSubtableBuilder builder = new VrfSubtableBuilder(); + try { + customizer.readCurrentAttributes(validId, builder, ctx); + } catch (ReadFailedException e) { + assertTrue(e.getCause() instanceof DumpCallFailedException); + assertTrue(e.getCause().getCause() instanceof VppCallbackException); + assertTrue(builder.getTableId() == null); + verifyLispEidTableMapDumpNotCalled(); + + return; + } + + fail("Test should throw ReadFailedException"); + } + + @Override + protected ReaderCustomizer<VrfSubtable, VrfSubtableBuilder> initCustomizer() { + return new VrfSubtableCustomizer(api); + } + + @Test + public void testGetBuilder() { + final VrfSubtableBuilder builder = customizer.getBuilder(validId); + + assertNotNull(builder); + assertNull(builder.getLocalMappings()); + assertNull(builder.getRemoteMappings()); + assertNull(builder.getTableId()); + } + + @Test + public void testMerge() { + VniTableBuilder parentBuilder = new VniTableBuilder(); + VrfSubtable subtable = new VrfSubtableBuilder().build(); + + customizer.merge(parentBuilder, subtable); + assertEquals(subtable, parentBuilder.getVrfSubtable()); + } +} diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/executor/VniTableDumpExecutorTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/executor/VniTableDumpExecutorTest.java index 3bc95d52b..b955609c5 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/executor/VniTableDumpExecutorTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/executor/VniTableDumpExecutorTest.java @@ -12,6 +12,8 @@ import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecut import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpCallFailedException; import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpTimeoutException; import io.fd.honeycomb.vpp.test.read.JvppDumpExecutorTest; +import io.fd.vpp.jvpp.core.dto.LispEidTableVniDetails; +import io.fd.vpp.jvpp.core.dto.LispEidTableVniDetailsReplyDump; import java.util.concurrent.TimeoutException; import org.junit.Before; import org.junit.Test; @@ -22,28 +24,27 @@ import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump; public class VniTableDumpExecutorTest extends JvppDumpExecutorTest<VniTableDumpExecutor> { - private LispEidTableMapDetailsReplyDump validDump; + private LispEidTableVniDetailsReplyDump validDump; @Before public void init() { - validDump = new LispEidTableMapDetailsReplyDump(); - LispEidTableMapDetails detail = new LispEidTableMapDetails(); - detail.dpTable = 1; + validDump = new LispEidTableVniDetailsReplyDump(); + LispEidTableVniDetails detail = new LispEidTableVniDetails(); detail.vni = 2; detail.context = 4; - validDump.lispEidTableMapDetails = ImmutableList.of(detail); + validDump.lispEidTableVniDetails = ImmutableList.of(detail); } @Test(expected = DumpCallFailedException.class) public void testExecuteDumpFail() throws DumpExecutionFailedException { - doThrowFailExceptionWhen().lispEidTableMapDump(Mockito.any()); + doThrowFailExceptionWhen().lispEidTableVniDump(Mockito.any()); getExecutor().executeDump(EntityDumpExecutor.NO_PARAMS); } @Test public void testExecuteDumpTimeout() throws Exception { - doThrowTimeoutExceptionWhen().lispEidTableMapDump(Mockito.any()); + doThrowTimeoutExceptionWhen().lispEidTableVniDump(Mockito.any()); try { getExecutor().executeDump(EntityDumpExecutor.NO_PARAMS); } catch (Exception e) { @@ -57,15 +58,14 @@ public class VniTableDumpExecutorTest extends JvppDumpExecutorTest<VniTableDumpE @Test public void testExecuteDump() throws DumpExecutionFailedException { - doReturnResponseWhen(validDump).lispEidTableMapDump(Mockito.any()); - final LispEidTableMapDetailsReplyDump reply = getExecutor().executeDump(EntityDumpExecutor.NO_PARAMS); + doReturnResponseWhen(validDump).lispEidTableVniDump(Mockito.any()); + final LispEidTableVniDetailsReplyDump reply = getExecutor().executeDump(EntityDumpExecutor.NO_PARAMS); assertNotNull(reply); - assertEquals(1, reply.lispEidTableMapDetails.size()); - final LispEidTableMapDetails detail = reply.lispEidTableMapDetails.get(0); + assertEquals(1, reply.lispEidTableVniDetails.size()); + final LispEidTableVniDetails detail = reply.lispEidTableVniDetails.get(0); assertEquals(4, detail.context); - assertEquals(1, detail.dpTable); assertEquals(2, detail.vni); } diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/trait/MappingFilterProviderTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/trait/MappingFilterProviderTest.java new file mode 100644 index 000000000..6a7c3b7e7 --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/trait/MappingFilterProviderTest.java @@ -0,0 +1,79 @@ +package io.fd.honeycomb.lisp.translate.read.trait; + + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.LocalMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.RemoteMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class MappingFilterProviderTest implements MappingFilterProvider { + + private InstanceIdentifier<LocalMapping> validVrfLocal; + private InstanceIdentifier<LocalMapping> validBdLocal; + private InstanceIdentifier<LocalMapping> invalidLocal; + + private InstanceIdentifier<RemoteMapping> validVrfRemote; + private InstanceIdentifier<RemoteMapping> validBdRemote; + private InstanceIdentifier<RemoteMapping> invalidRemote; + + + @Before + public void init() { + validVrfLocal = InstanceIdentifier.create(VrfSubtable.class) + .child(LocalMappings.class) + .child(LocalMapping.class); + + validBdLocal = InstanceIdentifier.create(BridgeDomainSubtable.class) + .child(LocalMappings.class) + .child(LocalMapping.class); + + invalidLocal = InstanceIdentifier.create(LocalMapping.class); + + validVrfRemote = InstanceIdentifier.create(VrfSubtable.class) + .child(RemoteMappings.class) + .child(RemoteMapping.class); + + validBdRemote = InstanceIdentifier.create(BridgeDomainSubtable.class) + .child(RemoteMappings.class) + .child(RemoteMapping.class); + + invalidRemote = InstanceIdentifier.create(RemoteMapping.class); + } + + @Test + public void testVrfLocalValid() { + assertEquals(VRF_MAPPINGS_ONLY, subtableFilterForLocalMappings(validVrfLocal)); + } + + @Test + public void testBridgeDomainLocalValid() { + assertEquals(BRIDGE_DOMAIN_MAPPINGS_ONLY, subtableFilterForLocalMappings(validBdLocal)); + } + + @Test(expected = IllegalArgumentException.class) + public void testLocalInvalid() { + subtableFilterForLocalMappings(invalidLocal); + } + + @Test + public void testVrfRemoteValid() { + assertEquals(VRF_MAPPINGS_ONLY, subtableFilterForRemoteMappings(validVrfRemote)); + } + + @Test + public void testBridgeDomainRemoteValid() { + assertEquals(BRIDGE_DOMAIN_MAPPINGS_ONLY, subtableFilterForRemoteMappings(validBdRemote)); + } + + @Test(expected = IllegalArgumentException.class) + public void testRemoteInvalid() { + subtableFilterForRemoteMappings(invalidRemote); + } +}
\ No newline at end of file diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/trait/MappingProducerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/trait/MappingProducerTest.java new file mode 100644 index 000000000..89eab3c5e --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/trait/MappingProducerTest.java @@ -0,0 +1,170 @@ +package io.fd.honeycomb.lisp.translate.read.trait; + + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import io.fd.honeycomb.translate.write.WriteFailedException; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6Afi; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.LocalMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.RemoteMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class MappingProducerTest implements MappingProducer { + + private InstanceIdentifier<LocalMapping> validVrfLocalMappingId; + private InstanceIdentifier<LocalMapping> validBridgeDomainLocalMappingId; + private InstanceIdentifier<RemoteMapping> validVrfRemoteMappingId; + private InstanceIdentifier<RemoteMapping> validBridgeDomainRemoteMappingId; + + private LocalMapping ipv4LocalMapping; + private LocalMapping ipv6LocalMapping; + private LocalMapping macLocalMapping; + + private RemoteMapping ipv4RemoteMapping; + private RemoteMapping ipv6RemoteMapping; + private RemoteMapping macRemoteMapping; + + @Before + public void init() { + validVrfLocalMappingId = InstanceIdentifier.create(VrfSubtable.class) + .child(LocalMappings.class) + .child(LocalMapping.class); + + validBridgeDomainLocalMappingId = InstanceIdentifier.create(BridgeDomainSubtable.class) + .child(LocalMappings.class) + .child(LocalMapping.class); + + validVrfRemoteMappingId = InstanceIdentifier.create(VrfSubtable.class) + .child(RemoteMappings.class) + .child(RemoteMapping.class); + + validBridgeDomainRemoteMappingId = InstanceIdentifier.create(BridgeDomainSubtable.class) + .child(RemoteMappings.class) + .child(RemoteMapping.class); + + ipv4LocalMapping = new LocalMappingBuilder() + .setEid(new EidBuilder() + .setAddressType(Ipv4Afi.class) + .build()).build(); + + ipv6LocalMapping = new LocalMappingBuilder() + .setEid(new EidBuilder() + .setAddressType(Ipv6Afi.class) + .build()).build(); + macLocalMapping = new LocalMappingBuilder() + .setEid(new EidBuilder() + .setAddressType(MacAfi.class) + .build()).build(); + + ipv4RemoteMapping = new RemoteMappingBuilder() + .setEid(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder() + .setAddressType(Ipv4Afi.class).build()).build(); + + ipv6RemoteMapping = new RemoteMappingBuilder() + .setEid(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder() + .setAddressType(Ipv6Afi.class).build()).build(); + + macRemoteMapping = new RemoteMappingBuilder() + .setEid(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder() + .setAddressType(MacAfi.class).build()).build(); + } + + @Test + public void testValidVrfLocal() { + testPositiveCase(validVrfLocalMappingId, ipv4LocalMapping); + testPositiveCase(validVrfLocalMappingId, ipv6LocalMapping); + } + + @Test + public void testValidBridgeDomainLocal() { + testPositiveCase(validBridgeDomainLocalMappingId, macLocalMapping); + } + + @Test + public void testInvalidVrfLocal() { + testNegativeCase(validVrfLocalMappingId, macLocalMapping); + } + + @Test + public void testInvalidBridgeDomainLocal() { + testNegativeCase(validBridgeDomainLocalMappingId, ipv4LocalMapping); + testNegativeCase(validBridgeDomainLocalMappingId, ipv6LocalMapping); + } + + + @Test + public void testValidVrfRemote() { + testPositiveCase(validVrfRemoteMappingId, ipv4RemoteMapping); + testPositiveCase(validVrfRemoteMappingId, ipv6RemoteMapping); + } + + @Test + public void testValidBridgeDomainRemote() { + testPositiveCase(validBridgeDomainRemoteMappingId, macRemoteMapping); + } + + @Test + public void testInvalidVrfRemote() { + testNegativeCase(validVrfRemoteMappingId, macRemoteMapping); + } + + @Test + public void testInvalidBridgeDomainRemote() { + testNegativeCase(validBridgeDomainRemoteMappingId, ipv4RemoteMapping); + testNegativeCase(validBridgeDomainRemoteMappingId, ipv6RemoteMapping); + } + + private void testNegativeCase(final InstanceIdentifier<LocalMapping> identifier, final LocalMapping data) { + try { + checkAllowedCombination(identifier, data); + } catch (WriteFailedException e) { + assertTrue(e instanceof WriteFailedException.CreateFailedException); + assertTrue(e.getCause() instanceof IllegalArgumentException); + return; + } + + fail("Test should have failed"); + } + + + private void testPositiveCase(final InstanceIdentifier<LocalMapping> identifier, final LocalMapping data) { + try { + checkAllowedCombination(identifier, data); + } catch (WriteFailedException e) { + fail("Test should have passed"); + } + } + + private void testNegativeCase(final InstanceIdentifier<RemoteMapping> identifier, final RemoteMapping data) { + try { + checkAllowedCombination(identifier, data); + } catch (WriteFailedException e) { + assertTrue(e instanceof WriteFailedException.CreateFailedException); + assertTrue(e.getCause() instanceof IllegalArgumentException); + return; + } + + fail("Test should have failed"); + } + + + private void testPositiveCase(final InstanceIdentifier<RemoteMapping> identifier, final RemoteMapping data) { + try { + checkAllowedCombination(identifier, data); + } catch (WriteFailedException e) { + fail("Test should have passed"); + } + } +} diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/trait/SubtableReaderTestCase.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/trait/SubtableReaderTestCase.java new file mode 100644 index 000000000..f40d72951 --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/trait/SubtableReaderTestCase.java @@ -0,0 +1,81 @@ +package io.fd.honeycomb.lisp.translate.read.trait; + + +import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.SubtableDumpParams.MapLevel; +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import com.google.common.collect.ImmutableList; +import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest; +import io.fd.vpp.jvpp.VppCallbackException; +import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetails; +import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.LispEidTableMapDump; +import java.util.Collections; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import javax.annotation.Nonnull; +import org.junit.Before; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; + +public abstract class SubtableReaderTestCase<D extends DataObject, B extends Builder<D>> + extends ReaderCustomizerTest<D, B> + implements SubtableReader { + + protected final long expectedVni = 12; + protected final int expectedTableId = 14; + + @Captor + protected ArgumentCaptor<LispEidTableMapDump> requestCaptor; + + public SubtableReaderTestCase(final Class<D> dataObjectClass, + final Class<? extends Builder<? extends DataObject>> parentBuilderClass) { + super(dataObjectClass, parentBuilderClass); + } + + protected void doReturnValidNonEmptyDataOnDump() { + LispEidTableMapDetailsReplyDump reply = new LispEidTableMapDetailsReplyDump(); + LispEidTableMapDetails detailFirst = new LispEidTableMapDetails(); + detailFirst.vni = Long.valueOf(expectedVni).intValue(); + detailFirst.dpTable = expectedTableId; + + LispEidTableMapDetails detailSecond = new LispEidTableMapDetails(); + detailSecond.vni = 13; + detailSecond.dpTable = 15; + + reply.lispEidTableMapDetails = ImmutableList.of(detailFirst, detailSecond); + + when(api.lispEidTableMapDump(any(LispEidTableMapDump.class))) + .thenReturn(future(reply)); + } + + protected void doReturnEmptyDataOnDump() { + LispEidTableMapDetailsReplyDump reply = new LispEidTableMapDetailsReplyDump(); + reply.lispEidTableMapDetails = Collections.emptyList(); + when(api.lispEidTableMapDump(any(LispEidTableMapDump.class))) + .thenReturn(future(reply)); + } + + protected void doThrowOnDump() { + when(api.lispEidTableMapDump(any(LispEidTableMapDump.class))) + .thenReturn(failedFuture()); + } + + protected void verifyLispEidTableMapDumpCalled(@Nonnull final MapLevel expectedLevel) { + verify(api, times(1)).lispEidTableMapDump(requestCaptor.capture()); + assertEquals(expectedLevel.getValue(), requestCaptor.getValue().isL2); + } + + protected void verifyLispEidTableMapDumpNotCalled() { + verify(api, times(1)).lispEidTableMapDump(any()); + } +} diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/util/EidTranslatorTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/util/EidTranslatorTest.java index 88ad10970..956a6cabf 100755 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/util/EidTranslatorTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/util/EidTranslatorTest.java @@ -18,7 +18,7 @@ public class EidTranslatorTest implements EidTranslator { @Test public void testGetEidType() { assertEquals(IPV4, getEidType( - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.EidBuilder() + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder() .setAddress( new Ipv4Builder().setIpv4( new Ipv4Address("192.168.2.1")) @@ -26,7 +26,7 @@ public class EidTranslatorTest implements EidTranslator { .build())); assertEquals(IPV6, getEidType( - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.EidBuilder() + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder() .setAddress( new Ipv6Builder().setIpv6( new Ipv6Address("2001:0db8:0a0b:12f0:0000:0000:0000:0001")) @@ -34,7 +34,7 @@ public class EidTranslatorTest implements EidTranslator { .build())); assertEquals(MAC, getEidType( - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.EidBuilder() + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder() .setAddress( new MacBuilder().setMac( new MacAddress("aa:bb:cc:dd:ee:ff")) diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/AdjacencyCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/AdjacencyCustomizerTest.java index b32b0bbe2..30c84cc9f 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/AdjacencyCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/AdjacencyCustomizerTest.java @@ -4,37 +4,53 @@ import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsD import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +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.when; +import io.fd.honeycomb.lisp.context.util.EidMappingContext; +import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; +import io.fd.vpp.jvpp.core.dto.LispAddDelAdjacency; +import io.fd.vpp.jvpp.core.dto.LispAddDelAdjacencyReply; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; +import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.MacBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.Adjacencies; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.Adjacency; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.AdjacencyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.adjacency.LocalEidBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.adjacency.RemoteEidBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.RemoteMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMapping; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.Adjacencies; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.Adjacency; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.AdjacencyBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.adjacency.LocalEidBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.adjacency.RemoteEidBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.LispAddDelAdjacency; -import io.fd.vpp.jvpp.core.dto.LispAddDelAdjacencyReply; public class AdjacencyCustomizerTest extends WriterCustomizerTest { @Captor private ArgumentCaptor<LispAddDelAdjacency> requestCaptor; + @Mock + private EidMappingContext localMappingContext; + + @Mock + private EidMappingContext remoteMappingContext; + private AdjacencyCustomizer customizer; private InstanceIdentifier<Adjacency> emptyId; @@ -46,58 +62,142 @@ public class AdjacencyCustomizerTest extends WriterCustomizerTest { @Before public void init() { - customizer = new AdjacencyCustomizer(api); + customizer = new AdjacencyCustomizer(api, localMappingContext, remoteMappingContext); emptyId = InstanceIdentifier.create(Adjacency.class); validId = InstanceIdentifier.create(EidTable.class) .child(VniTable.class, new VniTableKey(2L)) + .child(BridgeDomainSubtable.class) + .child(RemoteMappings.class) + .child(RemoteMapping.class) .child(Adjacencies.class) .child(Adjacency.class); emptyData = new AdjacencyBuilder().build(); invalidData = new AdjacencyBuilder().setId("ID").setLocalEid( - new LocalEidBuilder().setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build()) + new LocalEidBuilder() + .setVirtualNetworkId(new InstanceIdType(12L)) + .setAddressType(Ipv4Afi.class) + .setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build()) .build()).setRemoteEid( - new RemoteEidBuilder().setAddress(new MacBuilder().setMac(new MacAddress("aa:aa:aa:aa:aa:aa")).build()) + new RemoteEidBuilder() + .setVirtualNetworkId(new InstanceIdType(12L)) + .setAddressType(MacAfi.class) + .setAddress(new MacBuilder().setMac(new MacAddress("aa:aa:aa:aa:aa:aa")).build()) .build()) .build(); validData = new AdjacencyBuilder().setId("ID").setLocalEid( - new LocalEidBuilder().setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build()) + new LocalEidBuilder() + .setVirtualNetworkId(new InstanceIdType(12L)) + .setAddressType(Ipv4Afi.class) + .setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build()) .build()).setRemoteEid( new RemoteEidBuilder() + .setVirtualNetworkId(new InstanceIdType(12L)) + .setAddressType(Ipv4Afi.class) .setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("192.168.5.2")).build()).build()).build(); when(api.lispAddDelAdjacency(any())).thenReturn(future(new LispAddDelAdjacencyReply())); } - @Test(expected = IllegalStateException.class) + @Test public void writeCurrentAttributesNoKey() throws Exception { - customizer.writeCurrentAttributes(emptyId, emptyData, writeContext); + try { + customizer.writeCurrentAttributes(emptyId, emptyData, writeContext); + } catch (NullPointerException e) { + verify(api, times(0)).lispAddDelAdjacency(any()); + return; + } + + fail("Test should have failed while reading parent vni table id"); } - @Test(expected = IllegalStateException.class) + @Test public void writeCurrentAttributesInvalidCombination() throws Exception { - customizer.writeCurrentAttributes(emptyId, invalidData, writeContext); + try { + customizer.writeCurrentAttributes(emptyId, invalidData, writeContext); + } catch (NullPointerException e) { + verify(api, times(0)).lispAddDelAdjacency(any()); + return; + } + + fail("Test should have failed while reading parent vni table id"); } + @Test public void writeCurrentAttributes() throws Exception { + when(localMappingContext.containsId( + any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid.class), + any( + MappingContext.class))).thenReturn(true); + + when(remoteMappingContext.containsId( + any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid.class), + any( + MappingContext.class))).thenReturn(true); + customizer.writeCurrentAttributes(validId, validData, writeContext); verify(api, times(1)).lispAddDelAdjacency(requestCaptor.capture()); verifyRequest(requestCaptor.getValue(), 1, new byte[]{-64, -88, 2, 1}, 32, new byte[]{-64, -88, 5, 2}, 32, IPV4.getValue(), 2); } + @Test + public void writeCurrentAttributesNonExistingLocalMapping() throws Exception { + when(localMappingContext.containsId( + any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid.class), + any(MappingContext.class))).thenReturn(false); + + when(remoteMappingContext.containsId( + any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid.class), + any(MappingContext.class))).thenReturn(true); + try { + customizer.writeCurrentAttributes(validId, validData, writeContext); + } catch (IllegalStateException e) { + verify(api, times(0)).lispAddDelAdjacency(any()); + return; + } + + fail("Test should have failed while verifying local eid"); + } + + @Test + public void writeCurrentAttributesNonExistingRemoteMapping() throws Exception { + when(localMappingContext.containsId( + any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid.class), + any(MappingContext.class))).thenReturn(true); + + when(remoteMappingContext.containsId( + any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid.class), + any(MappingContext.class))).thenReturn(false); + try { + customizer.writeCurrentAttributes(validId, validData, writeContext); + } catch (IllegalStateException e) { + verify(api, times(0)).lispAddDelAdjacency(any()); + return; + } + + fail("Test should have failed while verifying remote eid"); + } + @Test(expected = UnsupportedOperationException.class) public void updateCurrentAttributes() throws Exception { customizer.updateCurrentAttributes(emptyId, emptyData, emptyData, writeContext); } - @Test(expected = IllegalStateException.class) + @Test public void deleteCurrentAttributesNoKey() throws Exception { - customizer.deleteCurrentAttributes(emptyId, emptyData, writeContext); + try { + customizer.deleteCurrentAttributes(emptyId, emptyData, writeContext); + } catch (NullPointerException e) { + verify(api, times(0)).lispAddDelAdjacency(any()); + return; + } + + fail("Test should have failed while reading parent vni table id"); } @Test(expected = IllegalArgumentException.class) diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/BridgeDomainCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/BridgeDomainCustomizerTest.java new file mode 100644 index 000000000..189570cb1 --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/BridgeDomainCustomizerTest.java @@ -0,0 +1,92 @@ +package io.fd.honeycomb.lisp.translate.write; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import io.fd.honeycomb.lisp.translate.write.trait.SubtableWriterTestCase; +import io.fd.honeycomb.translate.vpp.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.VppCallbackException; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtableBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class BridgeDomainCustomizerTest extends SubtableWriterTestCase { + + private BridgeDomainSubtableCustomizer customizer; + private InstanceIdentifier<BridgeDomainSubtable> validId; + private BridgeDomainSubtable validData; + private NamingContext bridgeDomainContext; + + @Before + public void init() { + bridgeDomainContext = new NamingContext("br", "bridge-domain-context"); + customizer = new BridgeDomainSubtableCustomizer(api, bridgeDomainContext); + validId = InstanceIdentifier.create(EidTable.class).child(VniTable.class, new VniTableKey(12L)) + .child(BridgeDomainSubtable.class); + validData = new BridgeDomainSubtableBuilder().setBridgeDomainRef("br-domain").build(); + defineMapping(mappingContext, "br-domain", 10, "bridge-domain-context"); + } + + @Test + public void testWriteSuccessfull() throws WriteFailedException { + whenAddDelEidTableAddDelMapSuccess(); + customizer.writeCurrentAttributes(validId, validData, writeContext); + verifyAddDelEidTableAddDelMapInvokedCorrectly(1, 12, 10, 1); + } + + @Test + public void testWriteFailed() throws WriteFailedException { + whenAddDelEidTableAddDelMapFail(); + + try { + customizer.writeCurrentAttributes(validId, validData, writeContext); + } catch (Exception e) { + assertTrue(e instanceof WriteFailedException); + + final WriteFailedException realException = ((WriteFailedException) e); + assertEquals(validId, realException.getFailedId()); + assertTrue(e.getCause() instanceof VppCallbackException); + return; + } + + fail("Test should throw exception"); + } + + @Test(expected = UnsupportedOperationException.class) + public void testUpdate() throws WriteFailedException { + customizer.updateCurrentAttributes(validId, validData, validData, writeContext); + } + + @Test + public void testDeleteSuccessfull() throws WriteFailedException { + whenAddDelEidTableAddDelMapSuccess(); + customizer.deleteCurrentAttributes(validId, validData, writeContext); + verifyAddDelEidTableAddDelMapInvokedCorrectly(0, 12, 10, 1); + } + + @Test + public void testDeleteFailed() { + whenAddDelEidTableAddDelMapFail(); + + try { + customizer.deleteCurrentAttributes(validId, validData, writeContext); + } catch (Exception e) { + assertTrue(e instanceof WriteFailedException); + + final WriteFailedException realException = ((WriteFailedException) e); + assertEquals(validId, realException.getFailedId()); + assertTrue(e.getCause() instanceof VppCallbackException); + return; + } + + fail("Test should throw exception"); + } + +} diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/InterfaceCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/InterfaceCustomizerTest.java index 8abd07e7e..e68c97674 100755 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/InterfaceCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/InterfaceCustomizerTest.java @@ -32,6 +32,7 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.Lisp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureData; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.LocatorSets; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.LocatorSet; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.LocatorSetKey; @@ -58,6 +59,7 @@ public class InterfaceCustomizerTest extends WriterCustomizerTest implements Byt defineMapping(mappingContext, interfaceName, 5, ifcCtxName); id = InstanceIdentifier.builder(Lisp.class) + .child(LispFeatureData.class) .child(LocatorSets.class) .child(LocatorSet.class, new LocatorSetKey("Locator")) .child(Interface.class, new InterfaceKey(interfaceName)) diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/ItrRemoteLocatorSetCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/ItrRemoteLocatorSetCustomizerTest.java new file mode 100644 index 000000000..97806c542 --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/ItrRemoteLocatorSetCustomizerTest.java @@ -0,0 +1,130 @@ +package io.fd.honeycomb.lisp.translate.write; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +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.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; +import io.fd.vpp.jvpp.VppCallbackException; +import io.fd.vpp.jvpp.core.dto.LispAddDelMapRequestItrRlocs; +import io.fd.vpp.jvpp.core.dto.LispAddDelMapRequestItrRlocsReply; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.itr.remote.locator.sets.grouping.ItrRemoteLocatorSet; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.itr.remote.locator.sets.grouping.ItrRemoteLocatorSetBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class ItrRemoteLocatorSetCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator { + + private static final String VALID_NAME = "loc-set"; + + @Captor + private ArgumentCaptor<LispAddDelMapRequestItrRlocs> requestCaptor; + + private ItrRemoteLocatorSetCustomizer customizer; + private InstanceIdentifier<ItrRemoteLocatorSet> validId; + private ItrRemoteLocatorSet validData; + + @Before + public void setUp() throws Exception { + initMocks(this); + customizer = new ItrRemoteLocatorSetCustomizer(api); + validId = InstanceIdentifier.create(ItrRemoteLocatorSet.class); + validData = new ItrRemoteLocatorSetBuilder().setRemoteLocatorSetName(VALID_NAME).build(); + } + + @Test + public void writeCurrentAttributesSuccess() throws Exception { + onWriteSuccess(); + customizer.writeCurrentAttributes(validId, validData, writeContext); + verifyWriteInvoked(true, VALID_NAME); + } + + @Test + public void writeCurrentAttributesFailed() { + onWriteThrow(); + + try { + customizer.writeCurrentAttributes(validId, validData, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppCallbackException); + verifyWriteInvoked(true, VALID_NAME); + return; + } + + fail("Test should have thrown exception"); + } + + @Test + public void updateCurrentAttributes() { + try { + customizer.updateCurrentAttributes(validId, validData, validData, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof UnsupportedOperationException); + return; + } + + fail("Test should have thrown exception"); + } + + @Test + public void deleteCurrentAttributesSuccess() throws Exception { + onWriteSuccess(); + customizer.deleteCurrentAttributes(validId, validData, writeContext); + verifyWriteInvoked(false, VALID_NAME); + } + + @Test + public void deleteCurrentAttributesFailed() throws Exception { + onWriteThrow(); + + try { + customizer.writeCurrentAttributes(validId, validData, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppCallbackException); + verifyWriteInvoked(true, VALID_NAME); + return; + } + + fail("Test should have thrown exception"); + } + + private void onWriteSuccess() { + when(api.lispAddDelMapRequestItrRlocs(any(LispAddDelMapRequestItrRlocs.class))) + .thenReturn(CompletableFuture.completedFuture(new LispAddDelMapRequestItrRlocsReply())); + } + + private void onWriteThrow() { + when(api.lispAddDelMapRequestItrRlocs(any(LispAddDelMapRequestItrRlocs.class))) + .thenReturn(new CompletableFuture<LispAddDelMapRequestItrRlocsReply>() { + @Override + public LispAddDelMapRequestItrRlocsReply get(final long l, final TimeUnit timeUnit) + throws InterruptedException, ExecutionException, TimeoutException { + throw new ExecutionException(new VppCallbackException("lispAddDelMapRequestItrRlocs", 1, -2)); + } + }); + } + + private void verifyWriteInvoked(final boolean add, final String name) { + verify(api, times(1)).lispAddDelMapRequestItrRlocs(requestCaptor.capture()); + + final LispAddDelMapRequestItrRlocs request = requestCaptor.getValue(); + assertNotNull(request); + assertEquals(booleanToByte(add), request.isAdd); + assertEquals(name, toString(request.locatorSetName)); + } +}
\ No newline at end of file diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LocalMappingCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LocalMappingCustomizerTest.java index 14867f049..4e24b3f3f 100755 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LocalMappingCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LocalMappingCustomizerTest.java @@ -36,18 +36,21 @@ import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.Lisp; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MappingId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.LocalMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMappingKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.LocalMappings; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMapping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMappingBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMappingKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.Eid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.EidBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureData; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import io.fd.vpp.jvpp.core.dto.LispAddDelLocalEid; import io.fd.vpp.jvpp.core.dto.LispAddDelLocalEidReply; @@ -66,10 +69,12 @@ public class LocalMappingCustomizerTest extends WriterCustomizerTest implements @Override public void setUp() { final Eid - eid = new EidBuilder().setAddress( - new Ipv4Builder().setIpv4( - new Ipv4Address("192.168.2.1")) - .build()) + eid = new EidBuilder() + .setAddressType(Ipv4Afi.class) + .setAddress( + new Ipv4Builder().setIpv4( + new Ipv4Address("192.168.2.1")) + .build()) .build(); mapping = new LocalMappingBuilder() @@ -78,8 +83,10 @@ public class LocalMappingCustomizerTest extends WriterCustomizerTest implements .build(); id = InstanceIdentifier.builder(Lisp.class) + .child(LispFeatureData.class) .child(EidTable.class) .child(VniTable.class, new VniTableKey(25L)) + .child(VrfSubtable.class) .child(LocalMappings.class) .child(LocalMapping.class, new LocalMappingKey(new MappingId("local"))) .build(); diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/RemoteMappingCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/RemoteMappingCustomizerTest.java index 6afce0113..a1f0dc792 100755 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/RemoteMappingCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/RemoteMappingCustomizerTest.java @@ -29,28 +29,32 @@ import io.fd.honeycomb.lisp.context.util.EidMappingContext; import io.fd.honeycomb.translate.vpp.util.Ipv4Translator; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; +import io.fd.vpp.jvpp.core.dto.LispAddDelRemoteMapping; +import io.fd.vpp.jvpp.core.dto.LispAddDelRemoteMappingReply; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.Lisp; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MapReplyAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MappingId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.RemoteMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMappingKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.NegativeMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.negative.mapping.MapReplyBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.RemoteMappings; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMapping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMappingBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMappingKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.Eid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.EidBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.locator.list.NegativeMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureData; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.LispAddDelRemoteMapping; -import io.fd.vpp.jvpp.core.dto.LispAddDelRemoteMappingReply; public class RemoteMappingCustomizerTest extends WriterCustomizerTest implements Ipv4Translator { @@ -67,10 +71,12 @@ public class RemoteMappingCustomizerTest extends WriterCustomizerTest implements @Override public void setUp() { - final Eid eid = new EidBuilder().setAddress( - new Ipv4Builder().setIpv4( - new Ipv4Address("192.168.2.1")) - .build()) + final Eid eid = new EidBuilder() + .setAddressType(Ipv4Afi.class) + .setAddress( + new Ipv4Builder().setIpv4( + new Ipv4Address("192.168.2.1")) + .build()) .build(); mappingId = new MappingId("REMOTE"); @@ -79,11 +85,15 @@ public class RemoteMappingCustomizerTest extends WriterCustomizerTest implements intf = new RemoteMappingBuilder() .setEid( eid) - .setLocatorList(new NegativeMappingBuilder().setMapReplyAction(MapReplyAction.Drop).build()) + .setLocatorList(new NegativeMappingBuilder() + .setMapReply(new MapReplyBuilder().setMapReplyAction(MapReplyAction.Drop).build()).build()) .build(); - id = InstanceIdentifier.builder(Lisp.class).child(EidTable.class) + id = InstanceIdentifier.builder(Lisp.class) + .child(LispFeatureData.class) + .child(EidTable.class) .child(VniTable.class, new VniTableKey(25L)) + .child(VrfSubtable.class) .child(RemoteMappings.class) .child(RemoteMapping.class, key).build(); diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/VniTableCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/VniTableCustomizerTest.java index 126498304..4df89dfa3 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/VniTableCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/VniTableCustomizerTest.java @@ -1,86 +1,87 @@ package io.fd.honeycomb.lisp.translate.write; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; + +import static org.junit.Assert.fail; 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.honeycomb.vpp.test.write.WriterCustomizerTest; import org.junit.Before; import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtableBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.LispEidTableAddDelMap; -import io.fd.vpp.jvpp.core.dto.LispEidTableAddDelMapReply; - public class VniTableCustomizerTest extends WriterCustomizerTest { - @Captor - private ArgumentCaptor<LispEidTableAddDelMap> requestCaptor; - private VniTableCustomizer customizer; - private InstanceIdentifier<VniTable> emptyId; - - private VniTable emptyData; + private InstanceIdentifier<VniTable> validId; private VniTable validData; @Before public void init() { + initMocks(this); customizer = new VniTableCustomizer(api); - emptyId = InstanceIdentifier.create(VniTable.class); - - emptyData = new VniTableBuilder().build(); - validData = new VniTableBuilder().setTableId(2L).setVirtualNetworkIdentifier(3L).build(); + validId = InstanceIdentifier.create(VniTable.class); + validData = new VniTableBuilder() + .setVrfSubtable(new VrfSubtableBuilder() + .build()).build(); + } - when(api.lispEidTableAddDelMap(any())).thenReturn(future(new LispEidTableAddDelMapReply())); + @Test + public void testWriteSuccessfull() { + whenReadAfterReturnValid(); + try { + customizer.writeCurrentAttributes(validId, validData, writeContext); + } catch (Exception e) { + fail("Test should pass without exception"); + } } - @Test(expected = NullPointerException.class) - public void testWriteCurrentAttributesEmptyData() throws Exception { - customizer.writeCurrentAttributes(emptyId, emptyData, writeContext); + @Test(expected = IllegalStateException.class) + public void testWriteFailed() throws WriteFailedException { + whenReadAfterReturnInvalid(); + customizer.writeCurrentAttributes(validId, validData, writeContext); } + @Test(expected = UnsupportedOperationException.class) + public void testUpdate() throws WriteFailedException { + customizer.updateCurrentAttributes(validId, validData, validData, writeContext); + } @Test - public void testWriteCurrentAttributes() throws Exception { - customizer.writeCurrentAttributes(emptyId, validData, writeContext); - verify(api, times(1)).lispEidTableAddDelMap(requestCaptor.capture()); - verifyRequest(requestCaptor.getValue(), (byte) 1, 2L, 3L); + public void testDeleteSuccessfull() { + whenReadBeforeReturnValid(); + try { + customizer.deleteCurrentAttributes(validId, validData, writeContext); + } catch (Exception e) { + fail("Test should pass without exception"); + } } - - @Test(expected = UnsupportedOperationException.class) - public void testUpdateCurrentAttributes() throws Exception { - customizer.updateCurrentAttributes(emptyId, emptyData, emptyData, writeContext); + @Test(expected = IllegalStateException.class) + public void testDeleteFailed() throws WriteFailedException { + whenReadBeforeReturnInvalid(); + customizer.deleteCurrentAttributes(validId, validData, writeContext); } - @Test(expected = NullPointerException.class) - public void testDeleteCurrentAttributesEmptyData() throws Exception { - customizer.deleteCurrentAttributes(emptyId, emptyData, writeContext); + private void whenReadBeforeReturnValid() { + when(writeContext.readBefore(validId)).thenReturn(Optional.of(validData)); } - @Test - public void testDeleteCurrentAttributes() throws Exception { - customizer.deleteCurrentAttributes(emptyId, validData, writeContext); - verify(api, times(1)).lispEidTableAddDelMap(requestCaptor.capture()); - verifyRequest(requestCaptor.getValue(), (byte) 0, 2L, 3L); + private void whenReadBeforeReturnInvalid() { + when(writeContext.readBefore(validId)).thenReturn(Optional.absent()); } - private static void verifyRequest(final LispEidTableAddDelMap request, final byte isAdd, - final long dpTable, - final long vni) { - assertNotNull(request); - assertEquals(isAdd, request.isAdd); - assertEquals(dpTable, request.dpTable); - assertEquals(vni, request.vni); - + private void whenReadAfterReturnValid() { + when(writeContext.readAfter(validId)).thenReturn(Optional.of(validData)); } + private void whenReadAfterReturnInvalid() { + when(writeContext.readAfter(validId)).thenReturn(Optional.absent()); + } }
\ No newline at end of file diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/VrfSubtableCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/VrfSubtableCustomizerTest.java new file mode 100644 index 000000000..a6c530430 --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/VrfSubtableCustomizerTest.java @@ -0,0 +1,89 @@ +package io.fd.honeycomb.lisp.translate.write; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import io.fd.honeycomb.lisp.translate.write.trait.SubtableWriterTestCase; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.VppCallbackException; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtableBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class VrfSubtableCustomizerTest extends SubtableWriterTestCase { + + private VrfSubtableCustomizer customizer; + private InstanceIdentifier<VrfSubtable> validId; + private VrfSubtable validData; + + @Before + public void init() { + customizer = new VrfSubtableCustomizer(api); + validId = InstanceIdentifier.create(EidTable.class).child(VniTable.class, new VniTableKey(12L)) + .child(VrfSubtable.class); + validData = new VrfSubtableBuilder().setTableId(10L).build(); + } + + @Test + public void testWriteSuccessfull() throws WriteFailedException { + whenAddDelEidTableAddDelMapSuccess(); + + customizer.writeCurrentAttributes(validId, validData, writeContext); + verifyAddDelEidTableAddDelMapInvokedCorrectly(1, 12, 10, 0); + } + + @Test + public void testWriteFailed() { + whenAddDelEidTableAddDelMapFail(); + + try { + customizer.writeCurrentAttributes(validId, validData, writeContext); + } catch (Exception e) { + assertTrue(e instanceof WriteFailedException); + + final WriteFailedException realException = ((WriteFailedException) e); + assertEquals(validId, realException.getFailedId()); + assertTrue(e.getCause() instanceof VppCallbackException); + return; + } + + fail("Test should throw exception"); + } + + @Test(expected = UnsupportedOperationException.class) + public void testUpdate() throws WriteFailedException { + customizer.updateCurrentAttributes(validId, validData, validData, writeContext); + } + + @Test + public void testDeleteSuccessfull() throws WriteFailedException { + whenAddDelEidTableAddDelMapSuccess(); + + customizer.deleteCurrentAttributes(validId, validData, writeContext); + verifyAddDelEidTableAddDelMapInvokedCorrectly(0, 12, 10, 0); + } + + @Test + public void testDeleteFailed() { + whenAddDelEidTableAddDelMapFail(); + + try { + customizer.deleteCurrentAttributes(validId, validData, writeContext); + } catch (Exception e) { + assertTrue(e instanceof WriteFailedException); + + final WriteFailedException realException = ((WriteFailedException) e); + assertEquals(validId, realException.getFailedId()); + assertTrue(e.getCause() instanceof VppCallbackException); + return; + } + + fail("Test should throw exception"); + } +} diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/trait/SubtableWriterTestCase.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/trait/SubtableWriterTestCase.java new file mode 100644 index 000000000..453add9f0 --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/trait/SubtableWriterTestCase.java @@ -0,0 +1,43 @@ +package io.fd.honeycomb.lisp.translate.write.trait; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; +import io.fd.vpp.jvpp.core.dto.LispEidTableAddDelMap; +import io.fd.vpp.jvpp.core.dto.LispEidTableAddDelMapReply; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mockito; + +public class SubtableWriterTestCase extends WriterCustomizerTest implements SubtableWriter { + @Captor + protected ArgumentCaptor<LispEidTableAddDelMap> requestCaptor; + + + protected void verifyAddDelEidTableAddDelMapInvokedCorrectly(final int addDel, final int vni, final int tableId, + final int isL2) { + verify(api, times(1)).lispEidTableAddDelMap(requestCaptor.capture()); + + final LispEidTableAddDelMap request = requestCaptor.getValue(); + assertNotNull(request); + assertEquals(addDel, request.isAdd); + assertEquals(vni, request.vni); + assertEquals(tableId, request.dpTable); + assertEquals(isL2, request.isL2); + } + + protected void whenAddDelEidTableAddDelMapSuccess() { + when(api.lispEidTableAddDelMap(Mockito.any(LispEidTableAddDelMap.class))) + .thenReturn(future(new LispEidTableAddDelMapReply())); + } + + protected void whenAddDelEidTableAddDelMapFail() { + when(api.lispEidTableAddDelMap(Mockito.any(LispEidTableAddDelMap.class))) + .thenReturn(failedFuture()); + } +} diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/util/EidMappingContextHelper.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/util/EidMappingContextHelper.java new file mode 100644 index 000000000..436cd6c25 --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/util/EidMappingContextHelper.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2016 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.honeycomb.lisp.util; + + +import static org.mockito.Mockito.doReturn; + +import com.google.common.base.Optional; +import com.google.common.collect.Lists; +import io.fd.honeycomb.translate.MappingContext; +import java.util.List; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.Contexts; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.EidMappingContext; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.EidMappingContextKey; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.Mappings; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.MappingsBuilder; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.Mapping; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.MappingBuilder; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.MappingKey; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MappingId; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; + +/** + * Utility class to stub {@link EidMappingContext} + * + * TODO - HONEYCOMB-237 - generalize logic for naming context and eid mapping context helper utils if possible + */ +public interface EidMappingContextHelper { + + /** + * Creates {@link Mapping} for given data. + * + * @param eid to be mapped + * @param id to be mapped @return eid to id mapping + */ + default Optional<Mapping> mapping(@Nonnull final Eid eid, final MappingId id) { + return Optional.of(new MappingBuilder().setEid(eid).setId(id).build()); + } + + /** + * Creates {@link KeyedInstanceIdentifier} for {@link Mapping} in {@link EidMappingContext}. + * + * @param id identificator of the mapping + * @param mappingContextName identificator of the mapping context + * @return identifier for the mapping + */ + default KeyedInstanceIdentifier<Mapping, MappingKey> mappingIid(@Nonnull final MappingId id, + @Nonnull final String mappingContextName) { + return InstanceIdentifier.create(Contexts.class).child(EidMappingContext.class, + new EidMappingContextKey(mappingContextName)).child(Mappings.class) + .child(Mapping.class, new MappingKey(id)); + } + + /** + * Stubs {@link MappingContext#read} to include given mapping in {@link EidMappingContext}. + * + * @param mappingContext mock instance of {@link MappingContext} + * @param eid name of the mapping + * @param mappingName index to be mapped + * @param namingContextName name of the naming context + */ + default void defineMapping(@Nonnull final MappingContext mappingContext, @Nonnull final Eid eid, + final MappingId mappingName, @Nonnull final String namingContextName) { + final KeyedInstanceIdentifier<Mapping, MappingKey> mappingIid = mappingIid(mappingName, namingContextName); + final InstanceIdentifier<Mappings> mappingsIid = mappingIid.firstIdentifierOf(Mappings.class); + + final Optional<Mapping> singleMapping = mapping(eid, mappingName); + final List<Mapping> list = Common.getMappingList(mappingContext, mappingsIid); + list.add(singleMapping.get()); + + doReturn(Optional.of(new MappingsBuilder().setMapping(list).build())).when(mappingContext).read(mappingsIid); + doReturn(singleMapping).when(mappingContext).read(mappingIid); + } + + final class Common { + private static List<Mapping> getMappingList(@Nonnull final MappingContext mappingContext, + @Nonnull final InstanceIdentifier<Mappings> mappingsIid) { + final Optional<Mappings> previousMappings = mappingContext.read(mappingsIid); + final MappingsBuilder mappingsBuilder; + if (previousMappings != null && previousMappings.isPresent()) { + mappingsBuilder = new MappingsBuilder(previousMappings.get()); + } else { + mappingsBuilder = new MappingsBuilder(); + mappingsBuilder.setMapping(Lists.newArrayList()); + } + return mappingsBuilder.getMapping(); + } + } +} |