diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2016-08-31 07:46:41 +0200 |
---|---|---|
committer | Maros Marsalek <mmarsale@cisco.com> | 2016-08-31 12:41:23 +0200 |
commit | 293ef1967dc6b523f8cf2ea4618bd39ca9a70b56 (patch) | |
tree | 5166ab138511cf4188d789cfd714889a5d6da26b /lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read | |
parent | 6d43491e197a5cb5a70adbbd7c63f458f852c38b (diff) |
HONEYCOMB-75 - Lisp implemetation
Rebased on final minimal distro
Change-Id: Ib71fc59e62dda4633f4f79c5c7417a4aaf02a177
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Signed-off-by: Florin Coras <fcoras@cisco.com>
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read')
27 files changed, 2361 insertions, 0 deletions
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 new file mode 100755 index 000000000..1a9721ca0 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/AdjacencyCustomizer.java @@ -0,0 +1,72 @@ +/* + * 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 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.v3po.util.FutureJVppCustomizer; +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.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.core.future.FutureJVppCore; + + +public class AdjacencyCustomizer extends FutureJVppCustomizer + implements ListReaderCustomizer<Adjacency, AdjacencyKey, AdjacencyBuilder> { + + public AdjacencyCustomizer(@Nonnull final FutureJVppCore futureJvpp) { + super(futureJvpp); + } + + @Nonnull + @Override + public List<AdjacencyKey> getAllIds(@Nonnull final InstanceIdentifier<Adjacency> id, + @Nonnull final ReadContext context) throws ReadFailedException { + + //does not throw exception to not disturb lisp state reading + return Collections.emptyList(); + } + + @Override + public void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<Adjacency> readData) { + ((AdjacenciesBuilder) builder).setAdjacency(readData); + } + + @Nonnull + @Override + public AdjacencyBuilder getBuilder(@Nonnull final InstanceIdentifier<Adjacency> id) { + return new AdjacencyBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier<Adjacency> id, + @Nonnull final AdjacencyBuilder builder, @Nonnull final ReadContext ctx) + throws ReadFailedException { + //TODO - finish after https://jira.fd.io/browse/VPP-362 + throw new ReadFailedException(id, new OperationNotSupportedException("Operation not supported")); + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/InterfaceCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/InterfaceCustomizer.java new file mode 100755 index 000000000..6d5abae8b --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/InterfaceCustomizer.java @@ -0,0 +1,157 @@ +/* + * 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.translate.read; + + +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.lisp.translate.read.dump.check.LocatorDumpCheck; +import io.fd.honeycomb.lisp.translate.read.dump.executor.LocatorDumpExecutor; +import io.fd.honeycomb.lisp.translate.read.dump.executor.params.LocatorDumpParams; +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.v3po.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.v3po.util.NamingContext; +import io.fd.honeycomb.translate.v3po.util.cache.DumpCacheManager; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.execution.DumpExecutionFailedException; +import java.util.Collections; +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.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.LocatorSetBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.locator.set.Interface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.locator.set.InterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.locator.set.InterfaceKey; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.core.dto.LispLocatorDetails; +import org.openvpp.jvpp.core.dto.LispLocatorDetailsReplyDump; +import org.openvpp.jvpp.core.future.FutureJVppCore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Customizer for reading {@code Interface}<br> Currently not supported by jvpp + */ +public class InterfaceCustomizer + extends FutureJVppCustomizer + implements ListReaderCustomizer<Interface, InterfaceKey, InterfaceBuilder> { + + private static final Logger LOG = LoggerFactory.getLogger(InterfaceCustomizer.class); + private static final String KEY_BASE = InterfaceCustomizer.class.getName(); + + private final NamingContext interfaceContext; + private final NamingContext locatorSetContext; + private final DumpCacheManager<LispLocatorDetailsReplyDump, LocatorDumpParams> dumpCacheManager; + + public InterfaceCustomizer( + @Nonnull final FutureJVppCore futureJvpp, + @Nonnull final NamingContext interfaceContext, + @Nonnull final NamingContext locatorSetContext) { + super(futureJvpp); + this.interfaceContext = checkNotNull(interfaceContext, "Interface context cannot be null"); + this.locatorSetContext = checkNotNull(locatorSetContext, "Locator set context cannot be null"); + this.dumpCacheManager = + new DumpCacheManager.DumpCacheManagerBuilder<LispLocatorDetailsReplyDump, LocatorDumpParams>() + .withExecutor(new LocatorDumpExecutor(futureJvpp)) + .withNonEmptyPredicate(new LocatorDumpCheck()) + .build(); + } + + @Override + public InterfaceBuilder getBuilder(InstanceIdentifier<Interface> id) { + return new InterfaceBuilder(); + } + + @Override + public void readCurrentAttributes(InstanceIdentifier<Interface> id, InterfaceBuilder builder, ReadContext ctx) + throws ReadFailedException { + checkState(id.firstKeyOf(LocatorSet.class) != null, "Cannot find reference to parent locator set"); + final String name = id.firstKeyOf(LocatorSet.class).getName(); + + checkState(locatorSetContext.containsIndex(name, ctx.getMappingContext())); + final int interfaceIndex = locatorSetContext.getIndex(name, ctx.getMappingContext()); + final LocatorDumpParams params = new LocatorDumpParams.LocatorDumpParamsBuilder() + .setFilter(LocatorDumpParams.LocatorDumpFilter.LOCAL) + .setLocatorSetIndex(interfaceIndex) + .build(); + + Optional<LispLocatorDetailsReplyDump> reply; + try { + reply = dumpCacheManager.getDump(KEY_BASE, ctx.getModificationCache(), params); + } catch (DumpExecutionFailedException e) { + throw new ReadFailedException(id, e); + } + + if (reply.isPresent()) { + final LispLocatorDetails details = reply.get() + .lispLocatorDetails + .stream() + .filter(a -> a.swIfIndex == interfaceIndex) + .collect(RWUtils.singleItemCollector()); + + builder.setPriority(Byte.valueOf(details.priority).shortValue()); + builder.setWeight(Byte.valueOf(details.weight).shortValue()); + builder.setInterfaceRef(name); + builder.setKey(new InterfaceKey(name)); + } + } + + @Override + public List<InterfaceKey> getAllIds(InstanceIdentifier<Interface> id, ReadContext context) + throws ReadFailedException { + + checkState(id.firstKeyOf(LocatorSet.class) != null, "Cannot find reference to parent locator set"); + final String name = id.firstKeyOf(LocatorSet.class).getName(); + + checkState(locatorSetContext.containsIndex(name, context.getMappingContext()), "No mapping for %s", name); + final LocatorDumpParams params = new LocatorDumpParams.LocatorDumpParamsBuilder() + .setFilter(LocatorDumpParams.LocatorDumpFilter.LOCAL) + .setLocatorSetIndex(locatorSetContext.getIndex(name, context.getMappingContext())) + .build(); + + + Optional<LispLocatorDetailsReplyDump> reply; + try { + reply = dumpCacheManager.getDump(KEY_BASE, context.getModificationCache(), params); + } catch (DumpExecutionFailedException e) { + throw new ReadFailedException(id, e); + } + + if (reply.isPresent()) { + return reply.get() + .lispLocatorDetails + .stream() + .map(a -> new InterfaceKey(interfaceContext.getName(a.swIfIndex, context.getMappingContext()))) + .collect(Collectors.toList()); + } else { + return Collections.emptyList(); + } + } + + @Override + public void merge(Builder<? extends DataObject> builder, List<Interface> readData) { + ((LocatorSetBuilder) builder).setInterface(readData); + } +}
\ No newline at end of file diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LispStateCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LispStateCustomizer.java new file mode 100755 index 000000000..90e0a491a --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LispStateCustomizer.java @@ -0,0 +1,75 @@ +/* + * 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.translate.read; + + +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.v3po.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.v3po.util.TranslateUtils; +import java.util.concurrent.TimeoutException; +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.LispStateBuilder; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.VppBaseCallException; +import org.openvpp.jvpp.core.dto.ShowLispStatus; +import org.openvpp.jvpp.core.dto.ShowLispStatusReply; +import org.openvpp.jvpp.core.future.FutureJVppCore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Customizer that handles reads of {@code LispState} + */ +public class LispStateCustomizer extends FutureJVppCustomizer + implements ReaderCustomizer<LispState, LispStateBuilder> { + + private static final Logger LOG = LoggerFactory.getLogger(LispStateCustomizer.class); + + public LispStateCustomizer(FutureJVppCore futureJvpp) { + super(futureJvpp); + } + + @Override + public LispStateBuilder getBuilder(InstanceIdentifier<LispState> id) { + return new LispStateBuilder(); + } + + @Override + public void readCurrentAttributes(InstanceIdentifier<LispState> id, LispStateBuilder builder, ReadContext ctx) + throws ReadFailedException { + + ShowLispStatusReply reply; + try { + reply = TranslateUtils.getReply(getFutureJVpp().showLispStatus(new ShowLispStatus()).toCompletableFuture()); + } catch (TimeoutException | VppBaseCallException e) { + throw new ReadFailedException(id, e); + } + + builder.setEnable(TranslateUtils.byteToBoolean(reply.featureStatus)); + } + + @Override + public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final LispState readValue) { + LOG.warn("Merge is unsupported for data roots"); + } +} 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 new file mode 100755 index 000000000..0381df05d --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LocalMappingCustomizer.java @@ -0,0 +1,194 @@ +/* + * 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.translate.read; + +import static com.google.common.base.Preconditions.checkNotNull; +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 io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.QuantityType; +import static io.fd.honeycomb.lisp.translate.util.EidConverter.compareAddresses; +import static io.fd.honeycomb.lisp.translate.util.EidConverter.getArrayAsEidLocal; +import static io.fd.honeycomb.lisp.translate.util.EidConverter.getEidAsByteArray; +import static io.fd.honeycomb.lisp.translate.util.EidConverter.getEidType; +import static io.fd.honeycomb.lisp.translate.util.EidConverter.getPrefixLength; + +import com.google.common.base.Optional; +import io.fd.honeycomb.lisp.context.util.EidMappingContext; +import io.fd.honeycomb.lisp.translate.read.dump.check.MappingsDumpCheck; +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.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.v3po.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.v3po.util.NamingContext; +import io.fd.honeycomb.translate.v3po.util.cache.DumpCacheManager; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.execution.DumpExecutionFailedException; +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.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.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 org.openvpp.jvpp.core.dto.LispEidTableDetails; +import org.openvpp.jvpp.core.dto.LispEidTableDetailsReplyDump; +import org.openvpp.jvpp.core.future.FutureJVppCore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Customizer for reading {@code LocalMapping}<br> Currently unsupported by jvpp + */ +public class LocalMappingCustomizer + extends FutureJVppCustomizer + implements ListReaderCustomizer<LocalMapping, LocalMappingKey, LocalMappingBuilder> { + + 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; + private final EidMappingContext localMappingContext; + + public LocalMappingCustomizer(@Nonnull FutureJVppCore futureJvpp, @Nonnull NamingContext locatorSetContext, + @Nonnull EidMappingContext localMappingsContext) { + super(futureJvpp); + this.locatorSetContext = checkNotNull(locatorSetContext, "Locator Set Mapping Context cannot be null"); + this.localMappingContext = checkNotNull(localMappingsContext, "Local mappings context cannot be null"); + this.dumpExecutor = new MappingsDumpExecutor(futureJvpp); + this.dumpManager = + new DumpCacheManager.DumpCacheManagerBuilder<LispEidTableDetailsReplyDump, MappingsDumpParams>() + .withExecutor(dumpExecutor) + .withNonEmptyPredicate(new MappingsDumpCheck()) + .build(); + } + + + @Override + public LocalMappingBuilder getBuilder(InstanceIdentifier<LocalMapping> id) { + return new LocalMappingBuilder(); + } + + @Override + public void readCurrentAttributes(InstanceIdentifier<LocalMapping> id, LocalMappingBuilder builder, + ReadContext ctx) throws ReadFailedException { + checkState(id.firstKeyOf(LocalMapping.class) != null, "No key present for id({})", id); + checkState(id.firstKeyOf(VniTable.class) != null, "Parent VNI table not specified"); + + //checks whether there is an existing mapping + final MappingId mappingId = id.firstKeyOf(LocalMapping.class).getId(); + checkState(localMappingContext.containsEid(mappingId, ctx.getMappingContext())); + + final long vni = id.firstKeyOf(VniTable.class).getVirtualNetworkIdentifier(); + + final String localMappingId = id.firstKeyOf(LocalMapping.class).getId().getValue(); + final Eid eid = localMappingContext.getEid(mappingId, ctx.getMappingContext()); + + //Requesting for specific mapping dump,only from local mappings with specified eid/vni/eid type + final MappingsDumpParams dumpParams = new MappingsDumpParams.MappingsDumpParamsBuilder() + .setEidSet(QuantityType.SPECIFIC) + .setVni(Long.valueOf(vni).intValue()) + .setEid(getEidAsByteArray(eid)) + .setEidType(getEidType(eid)) + .setPrefixLength(getPrefixLength(eid)) + .build(); + + LOG.debug("Dumping data for LocalMappings(id={})", id); + Optional<LispEidTableDetailsReplyDump> replyOptional; + + try { + replyOptional = + dumpManager.getDump(bindKey("SPECIFIC_" + localMappingId), ctx.getModificationCache(), dumpParams); + } catch (DumpExecutionFailedException e) { + throw new ReadFailedException(id, e); + } + + if (replyOptional.isPresent()) { + LOG.debug("Valid dump loaded"); + + LispEidTableDetails details = replyOptional.get().lispEidTableDetails.stream() + .filter(a -> compareAddresses(eid.getAddress(), + getArrayAsEidLocal(valueOf(a.eidType), a.eid).getAddress())) + .collect( + RWUtils.singleItemCollector()); + + //in case of local mappings,locator_set_index stands for interface index + checkState(locatorSetContext.containsName(details.locatorSetIndex, ctx.getMappingContext())); + 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)); + } else { + LOG.debug("No data dumped"); + } + } + + @Override + public List<LocalMappingKey> getAllIds(InstanceIdentifier<LocalMapping> id, ReadContext context) + throws ReadFailedException { + + checkState(id.firstKeyOf(VniTable.class) != null, "Parent VNI table not specified"); + + //request for all local mappings + final MappingsDumpParams dumpParams = new MappingsDumpParamsBuilder() + .setVni(Long.valueOf(id.firstKeyOf(VniTable.class).getVirtualNetworkIdentifier()).intValue()) + .setFilter(FilterType.LOCAL) + .setEidSet(QuantityType.ALL) + .build(); + + LOG.debug("Dumping data for LocalMappings(id={})", id); + Optional<LispEidTableDetailsReplyDump> replyOptional; + try { + replyOptional = dumpManager.getDump(bindKey("ALL_LOCAL"), context.getModificationCache(), dumpParams); + } catch (DumpExecutionFailedException e) { + throw new ReadFailedException(id, e); + } + + if (replyOptional.isPresent()) { + LOG.debug("Valid dump loaded"); + return replyOptional.get().lispEidTableDetails.stream().map(a -> new LocalMappingKey( + new MappingId( + localMappingContext.getId( + getArrayAsEidLocal(valueOf(a.eidType), a.eid), + context.getMappingContext())))) + .collect(Collectors.toList()); + } else { + LOG.debug("No data dumped"); + return Collections.emptyList(); + } + } + + @Override + public void merge(Builder<? extends DataObject> builder, List<LocalMapping> readData) { + ((LocalMappingsBuilder) builder).setLocalMapping(readData); + } + + private static String bindKey(String prefix) { + return prefix + "_" + KEY; + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LocatorSetCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LocatorSetCustomizer.java new file mode 100755 index 000000000..f8da94f1a --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/LocatorSetCustomizer.java @@ -0,0 +1,130 @@ +/* + * 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.translate.read; + +import static io.fd.honeycomb.translate.v3po.util.cache.EntityDumpExecutor.NO_PARAMS; + +import com.google.common.base.Optional; +import io.fd.honeycomb.lisp.translate.read.dump.check.LocatorSetsDumpCheck; +import io.fd.honeycomb.lisp.translate.read.dump.executor.LocatorSetsDumpExecutor; +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.v3po.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.v3po.util.TranslateUtils; +import io.fd.honeycomb.translate.v3po.util.cache.DumpCacheManager; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.execution.DumpExecutionFailedException; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +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; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.LocatorSetBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.LocatorSetKey; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.core.dto.LispLocatorSetDetails; +import org.openvpp.jvpp.core.dto.LispLocatorSetDetailsReplyDump; +import org.openvpp.jvpp.core.future.FutureJVppCore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class LocatorSetCustomizer extends FutureJVppCustomizer + implements ListReaderCustomizer<LocatorSet, LocatorSetKey, LocatorSetBuilder> { + + //TODO - temporary as public because of hack in write customizer in *.write.LocatorSetCustomizer + public static final String LOCATOR_SETS_CACHE_ID = LocatorSetCustomizer.class.getName(); + private static final Logger LOG = LoggerFactory.getLogger(LocatorSetCustomizer.class); + + private final DumpCacheManager<LispLocatorSetDetailsReplyDump, Void> dumpManager; + + public LocatorSetCustomizer(FutureJVppCore futureJvpp) { + super(futureJvpp); + this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder<LispLocatorSetDetailsReplyDump, Void>() + .withExecutor(new LocatorSetsDumpExecutor(futureJvpp)) + .withNonEmptyPredicate(new LocatorSetsDumpCheck()) + .build(); + } + + @Override + public LocatorSetBuilder getBuilder(InstanceIdentifier<LocatorSet> id) { + return new LocatorSetBuilder(); + } + + @Override + public void readCurrentAttributes(InstanceIdentifier<LocatorSet> id, LocatorSetBuilder builder, ReadContext ctx) + throws ReadFailedException { + LOG.debug("Reading attributes for Locator Set {}", id); + + Optional<LispLocatorSetDetailsReplyDump> dumpOptional; + + try { + dumpOptional = dumpManager.getDump(LOCATOR_SETS_CACHE_ID, ctx.getModificationCache(), NO_PARAMS); + } catch (DumpExecutionFailedException e) { + throw new ReadFailedException(id, e); + } + if (!dumpOptional.isPresent()) { + LOG.warn("No dump present for Locator Set {}", id); + return; + } + + String keyName = id.firstKeyOf(LocatorSet.class).getName(); + LispLocatorSetDetailsReplyDump dump = dumpOptional.get(); + + java.util.Optional<LispLocatorSetDetails> details = dump.lispLocatorSetDetails.stream() + .filter(n -> keyName.equals(TranslateUtils.toString(n.locatorSetName))) + .findFirst(); + + if (details.isPresent()) { + final String name = TranslateUtils.toString(details.get().locatorSetName); + + builder.setName(name); + builder.setKey(new LocatorSetKey(name)); + } else { + LOG.warn("Locator Set {} not found in dump", id); + } + } + + @Override + public List<LocatorSetKey> getAllIds(InstanceIdentifier<LocatorSet> id, ReadContext context) + throws ReadFailedException { + LOG.debug("Dumping Locator Set {}", id); + + Optional<LispLocatorSetDetailsReplyDump> dumpOptional = null; + try { + dumpOptional = dumpManager.getDump(LOCATOR_SETS_CACHE_ID, context.getModificationCache(), NO_PARAMS); + } catch (DumpExecutionFailedException e) { + LOG.error("Error dumping Locator Set {}", e, id); + return Collections.emptyList(); + } + + if (dumpOptional.isPresent()) { + return dumpOptional.get().lispLocatorSetDetails.stream() + .map(set -> new LocatorSetKey(TranslateUtils.toString(set.locatorSetName))) + .collect(Collectors.toList()); + } else { + LOG.warn("No data dumped for Locator Set {}", id); + return Collections.emptyList(); + } + } + + @Override + public void merge(Builder<? extends DataObject> builder, List<LocatorSet> readData) { + ((LocatorSetsBuilder) builder).setLocatorSet(readData); + } +} 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 new file mode 100755 index 000000000..0b1269648 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/MapResolverCustomizer.java @@ -0,0 +1,132 @@ +/* + * 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.translate.read; + +import static io.fd.honeycomb.translate.v3po.util.cache.EntityDumpExecutor.NO_PARAMS; + +import com.google.common.base.Optional; +import io.fd.honeycomb.lisp.translate.read.dump.check.MapResolverDumpCheck; +import io.fd.honeycomb.lisp.translate.read.dump.executor.MapResolversDumpExecutor; +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.v3po.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.v3po.util.TranslateUtils; +import io.fd.honeycomb.translate.v3po.util.cache.DumpCacheManager; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.execution.DumpExecutionFailedException; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +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; +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.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.core.dto.LispMapResolverDetails; +import org.openvpp.jvpp.core.dto.LispMapResolverDetailsReplyDump; +import org.openvpp.jvpp.core.future.FutureJVppCore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class MapResolverCustomizer extends FutureJVppCustomizer + implements ListReaderCustomizer<MapResolver, MapResolverKey, MapResolverBuilder> { + + private static final Logger LOG = LoggerFactory.getLogger(MapResolverCustomizer.class); + private static final String MAP_RESOLVERS_CACHE_ID = MapResolverCustomizer.class.getName(); + + private final DumpCacheManager<LispMapResolverDetailsReplyDump, Void> dumpManager; + + public MapResolverCustomizer(FutureJVppCore futureJvpp) { + super(futureJvpp); + this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder<LispMapResolverDetailsReplyDump, Void>() + .withExecutor(new MapResolversDumpExecutor((futureJvpp))) + .withNonEmptyPredicate(new MapResolverDumpCheck()) + .build(); + } + + @Override + public MapResolverBuilder getBuilder(InstanceIdentifier<MapResolver> id) { + return new MapResolverBuilder(); + } + + @Override + public void readCurrentAttributes(InstanceIdentifier<MapResolver> id, MapResolverBuilder builder, ReadContext ctx) + throws ReadFailedException { + LOG.debug("Reading attributes..."); + + Optional<LispMapResolverDetailsReplyDump> dumpOptional = null; + try { + dumpOptional = dumpManager.getDump(MAP_RESOLVERS_CACHE_ID, ctx.getModificationCache(), NO_PARAMS); + } catch (DumpExecutionFailedException e) { + throw new ReadFailedException(id, e); + } + + if (!dumpOptional.isPresent()) { + LOG.warn("No data dumped"); + return; + } + + MapResolverKey key = id.firstKeyOf(MapResolver.class); + LispMapResolverDetailsReplyDump dump = dumpOptional.get(); + + //cannot use RWUtils.singleItemCollector(),there is some problem with generic params binding + java.util.Optional<LispMapResolverDetails> mapResolverOptional = + dump.lispMapResolverDetails.stream().filter(key::equals).findFirst(); + + if (mapResolverOptional.isPresent()) { + LispMapResolverDetails details = mapResolverOptional.get(); + + builder.setKey(key); + builder.setIpAddress( + TranslateUtils.arrayToIpAddress(TranslateUtils.byteToBoolean(details.isIpv6), details.ipAddress)); + } else { + LOG.warn("No data found with matching key"); + } + + } + + @Override + public List<MapResolverKey> getAllIds(InstanceIdentifier<MapResolver> id, ReadContext context) + throws ReadFailedException { + LOG.debug("Dumping MapResolver..."); + + Optional<LispMapResolverDetailsReplyDump> dumpOptional = null; + try { + dumpOptional = dumpManager.getDump(MAP_RESOLVERS_CACHE_ID, context.getModificationCache(), NO_PARAMS); + } catch (DumpExecutionFailedException e) { + throw new ReadFailedException(id, e); + } + + if (!dumpOptional.isPresent()) { + LOG.warn("No data dumped"); + return Collections.emptyList(); + } + + return dumpOptional.get().lispMapResolverDetails.stream() + .map(resolver -> new MapResolverKey( + TranslateUtils + .arrayToIpAddress(TranslateUtils.byteToBoolean(resolver.isIpv6), resolver.ipAddress))) + .collect(Collectors.toList()); + } + + @Override + public void merge(Builder<? extends DataObject> builder, List<MapResolver> readData) { + ((MapResolversBuilder) builder).setMapResolver(readData); + } +} 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 new file mode 100755 index 000000000..effeb9674 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/PitrCfgCustomizer.java @@ -0,0 +1,83 @@ +/* + * 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.translate.read; + + +import static io.fd.honeycomb.translate.v3po.util.TranslateUtils.getReply; + +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.v3po.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.v3po.util.TranslateUtils; +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.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; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.VppBaseCallException; +import org.openvpp.jvpp.core.dto.ShowLispPitr; +import org.openvpp.jvpp.core.dto.ShowLispPitrReply; +import org.openvpp.jvpp.core.future.FutureJVppCore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Customizer for reading {@link PitrCfg}<br> Currently unsupported in jvpp + */ +public class PitrCfgCustomizer extends FutureJVppCustomizer implements ReaderCustomizer<PitrCfg, PitrCfgBuilder> { + + private static final Logger LOG = LoggerFactory.getLogger(PitrCfgCustomizer.class); + + public PitrCfgCustomizer(FutureJVppCore futureJvpp) { + super(futureJvpp); + } + + @Override + public PitrCfgBuilder getBuilder(InstanceIdentifier<PitrCfg> id) { + return new PitrCfgBuilder(); + } + + @Override + public void readCurrentAttributes(InstanceIdentifier<PitrCfg> id, PitrCfgBuilder builder, ReadContext ctx) + throws ReadFailedException { + LOG.debug("Reading status for Lisp Pitr node {}", id); + + ShowLispPitrReply reply; + + try { + reply = getPitrStatus(); + } catch (TimeoutException | VppBaseCallException e) { + throw new ReadFailedException(id, e); + } + + builder.setLocatorSet(TranslateUtils.toString(reply.locatorSetName)); + LOG.debug("Reading status for Lisp Pitr node {} successfull", id); + } + + @Override + public void merge(Builder<? extends DataObject> parentBuilder, PitrCfg readValue) { + ((LispStateBuilder) parentBuilder).setPitrCfg(readValue); + } + + public ShowLispPitrReply getPitrStatus() throws TimeoutException, VppBaseCallException { + return getReply(getFutureJVpp().showLispPitr(new ShowLispPitr()).toCompletableFuture()); + } +} 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 new file mode 100755 index 000000000..81405ecec --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/RemoteMappingCustomizer.java @@ -0,0 +1,203 @@ +/* + * 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.translate.read; + +import static com.google.common.base.Preconditions.checkNotNull; +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 io.fd.honeycomb.lisp.translate.util.EidConverter.compareAddresses; +import static io.fd.honeycomb.lisp.translate.util.EidConverter.getArrayAsEidLocal; + +import com.google.common.base.Optional; +import io.fd.honeycomb.lisp.context.util.EidMappingContext; +import io.fd.honeycomb.lisp.translate.read.dump.check.MappingsDumpCheck; +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.dump.executor.params.MappingsDumpParams.QuantityType; +import io.fd.honeycomb.lisp.translate.util.EidConverter; +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.v3po.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.v3po.util.TranslateUtils; +import io.fd.honeycomb.translate.v3po.util.cache.DumpCacheManager; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.execution.DumpExecutionFailedException; +import java.util.Collections; +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.MappingId; +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 org.openvpp.jvpp.core.dto.LispEidTableDetails; +import org.openvpp.jvpp.core.dto.LispEidTableDetailsReplyDump; +import org.openvpp.jvpp.core.future.FutureJVppCore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Customizer for reading {@code RemoteMapping}<br> + */ +public class RemoteMappingCustomizer extends FutureJVppCustomizer + implements ListReaderCustomizer<RemoteMapping, RemoteMappingKey, RemoteMappingBuilder> { + + 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 EidMappingContext remoteMappingContext; + + public RemoteMappingCustomizer(@Nonnull FutureJVppCore futureJvpp, + @Nonnull EidMappingContext remoteMappingContext) { + super(futureJvpp); + this.remoteMappingContext = checkNotNull(remoteMappingContext, "Remote mappings not present"); + this.dumpManager = + new DumpCacheManager.DumpCacheManagerBuilder<LispEidTableDetailsReplyDump, MappingsDumpParams>() + .withExecutor(new MappingsDumpExecutor(futureJvpp)) + .withNonEmptyPredicate(new MappingsDumpCheck()) + .build(); + } + + + @Override + public RemoteMappingBuilder getBuilder(InstanceIdentifier<RemoteMapping> id) { + return new RemoteMappingBuilder(); + } + + private Eid copyEid( + org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid eid) { + return new EidBuilder().setAddress(eid.getAddress()).setAddressType(eid.getAddressType()) + .setVirtualNetworkId(eid.getVirtualNetworkId()).build(); + } + + @Override + public void readCurrentAttributes(InstanceIdentifier<RemoteMapping> id, RemoteMappingBuilder builder, + ReadContext ctx) + throws ReadFailedException { + checkState(id.firstKeyOf(RemoteMapping.class) != null, "No key present for id({})", id); + checkState(id.firstKeyOf(VniTable.class) != null, "Parent VNI table not specified"); + + final MappingId mappingId = id.firstKeyOf(RemoteMapping.class).getId(); + checkState(remoteMappingContext.containsEid(mappingId, ctx.getMappingContext()), + "No mapping stored for id %s", mappingId); + + final long vni = id.firstKeyOf(VniTable.class).getVirtualNetworkIdentifier(); + final String remoteMappingId = id.firstKeyOf(RemoteMapping.class).getId().getValue(); + final Eid eid = copyEid(remoteMappingContext.getEid(mappingId, ctx.getMappingContext())); + final MappingsDumpParams dumpParams = new MappingsDumpParamsBuilder() + .setVni(Long.valueOf(vni).intValue()) + .setEidSet(QuantityType.SPECIFIC) + .setEidType(EidConverter.getEidType(eid)) + .setEid(EidConverter.getEidAsByteArray(eid)) + .setPrefixLength(EidConverter.getPrefixLength(eid)) + .build(); + + LOG.debug("Dumping data for LocalMappings(id={})", id); + Optional<LispEidTableDetailsReplyDump> replyOptional; + try { + replyOptional = + dumpManager.getDump(bindKey("SPECIFIC_" + remoteMappingId), ctx.getModificationCache(), dumpParams); + } catch (DumpExecutionFailedException e) { + throw new ReadFailedException(id, e); + } + + if (replyOptional.isPresent()) { + LOG.debug("Valid dump loaded"); + + LispEidTableDetails details = replyOptional.get().lispEidTableDetails.stream() + .filter(a -> compareAddresses(eid.getAddress(), + getArrayAsEidLocal(valueOf(a.eidType), a.eid).getAddress())) + .collect( + RWUtils.singleItemCollector()); + + builder.setEid(EidConverter.getArrayAsEidRemote(valueOf(details.eidType), details.eid)); + builder.setKey(new RemoteMappingKey(new MappingId(id.firstKeyOf(RemoteMapping.class).getId()))); + builder.setTtl(resolveTtl(details.ttl)); + builder.setAuthoritative( + new RemoteMapping.Authoritative(TranslateUtils.byteToBoolean(details.authoritative))); + + } else { + LOG.debug("No data dumped"); + } + } + + //compensate ~0 as default value of ttl + private static long resolveTtl(final int ttlValue) { + return ttlValue == -1 + ? Integer.MAX_VALUE + : ttlValue; + } + + @Override + public List<RemoteMappingKey> getAllIds(InstanceIdentifier<RemoteMapping> id, ReadContext context) + throws ReadFailedException { + + checkState(id.firstKeyOf(VniTable.class) != null, "Parent VNI table not specified"); + + //requesting all remote with specific vni + final MappingsDumpParams dumpParams = new MappingsDumpParamsBuilder() + .setVni(Long.valueOf(id.firstKeyOf(VniTable.class).getVirtualNetworkIdentifier()).intValue()) + .setEidSet(QuantityType.ALL) + .setFilter(FilterType.REMOTE) + .build(); + + LOG.debug("Dumping data for LocalMappings(id={})", id); + Optional<LispEidTableDetailsReplyDump> replyOptional; + try { + replyOptional = dumpManager.getDump(bindKey("ALL_REMOTE"), context.getModificationCache(), dumpParams); + } catch (DumpExecutionFailedException e) { + throw new ReadFailedException(id, e); + } + + if (replyOptional.isPresent()) { + LOG.debug("Valid dump loaded"); + return replyOptional.get() + .lispEidTableDetails + .stream() + .map(detail -> new RemoteMappingKey( + new MappingId( + remoteMappingContext.getId( + EidConverter.getArrayAsEidRemote( + valueOf(detail.eidType), detail.eid), + context.getMappingContext())))) + .collect(Collectors.toList()); + } else { + LOG.debug("No data dumped"); + return Collections.emptyList(); + } + } + + @Override + public void merge(Builder<? extends DataObject> builder, List<RemoteMapping> readData) { + ((RemoteMappingsBuilder) builder).setRemoteMapping(readData); + } + + private String bindKey(String prefix) { + return prefix + "_" + KEY; + } +} 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 new file mode 100755 index 000000000..60d6b9dc3 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/VniTableCustomizer.java @@ -0,0 +1,139 @@ +/* + * 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.checkState; +import static io.fd.honeycomb.translate.v3po.util.cache.EntityDumpExecutor.NO_PARAMS; + +import com.google.common.base.Optional; +import io.fd.honeycomb.lisp.translate.read.dump.check.VniTableDumpCheck; +import io.fd.honeycomb.lisp.translate.read.dump.executor.VniTableDumpExecutor; +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.v3po.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.v3po.util.cache.DumpCacheManager; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.execution.DumpExecutionFailedException; +import java.util.Collections; +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.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.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.core.dto.LispEidTableMapDetails; +import org.openvpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump; +import org.openvpp.jvpp.core.future.FutureJVppCore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Handles the reads of {@link VniTable} nodes + */ +public class VniTableCustomizer extends FutureJVppCustomizer + implements ListReaderCustomizer<VniTable, VniTableKey, VniTableBuilder> { + + 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; + + public VniTableCustomizer(@Nonnull final FutureJVppCore futureJvpp) { + super(futureJvpp); + this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder<LispEidTableMapDetailsReplyDump, Void>() + .withExecutor(new VniTableDumpExecutor(futureJvpp)) + .withNonEmptyPredicate(new VniTableDumpCheck()) + .build(); + } + + private static VniTableKey detailsToKey(final LispEidTableMapDetails lispEidTableMapDetails) { + return new VniTableKey(Integer.valueOf(lispEidTableMapDetails.vni).longValue()); + + } + + @Override + public void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<VniTable> readData) { + ((EidTableBuilder) builder).setVniTable(readData); + } + + @Nonnull + @Override + public VniTableBuilder getBuilder(@Nonnull final InstanceIdentifier<VniTable> id) { + return new VniTableBuilder(); + } + + @Nonnull + @Override + public List<VniTableKey> getAllIds(@Nonnull final InstanceIdentifier<VniTable> id, + @Nonnull final ReadContext context) + throws ReadFailedException { + LOG.trace("Reading all IDS..."); + + Optional<LispEidTableMapDetailsReplyDump> optionalReply; + try { + optionalReply = dumpManager.getDump(LISP_TABLE_ID_DUMP, context.getModificationCache(), NO_PARAMS); + } catch (DumpExecutionFailedException e) { + throw new ReadFailedException(id, e); + } + + if (!optionalReply.isPresent()) { + return Collections.emptyList(); + } + + LispEidTableMapDetailsReplyDump reply = optionalReply.get(); + LOG.debug("Dumped ..."); + + // Just transform received details into a list of keys + final List<VniTableKey> collect = reply.lispEidTableMapDetails.stream().map(VniTableCustomizer::detailsToKey) + .collect(Collectors.toList()); + LOG.debug("All IDs found: {} ...", collect); + return collect; + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier<VniTable> id, + @Nonnull final VniTableBuilder builder, @Nonnull final ReadContext ctx) + throws ReadFailedException { + + checkState(id.firstKeyOf(VniTable.class) != null, "No VNI present"); + VniTableKey key = new VniTableKey(id.firstKeyOf(VniTable.class).getVirtualNetworkIdentifier()); + + Optional<LispEidTableMapDetailsReplyDump> optionalReply; + try { + optionalReply = dumpManager.getDump(LISP_TABLE_ID_DUMP, ctx.getModificationCache(), NO_PARAMS); + } catch (DumpExecutionFailedException e) { + throw new ReadFailedException(id, e); + } + + if (!optionalReply.isPresent()) { + return; + } + + //transforming right away to single detail(specific request should do the magic) + LispEidTableMapDetails details = + optionalReply.get().lispEidTableMapDetails.stream().filter(a -> detailsToKey(a).equals(key)) + .collect(RWUtils.singleItemCollector()); + + builder.setVirtualNetworkIdentifier((long) details.vni); + builder.setTableId((long) details.vrf); + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorDumpCheck.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorDumpCheck.java new file mode 100644 index 000000000..530be98ed --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorDumpCheck.java @@ -0,0 +1,37 @@ +/* + * 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.translate.read.dump.check; + +import io.fd.honeycomb.translate.v3po.util.cache.EntityDumpNonEmptyCheck; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.check.DumpCheckFailedException; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.check.i.DumpEmptyException; +import org.openvpp.jvpp.core.dto.LispLocatorDetailsReplyDump; + +public class LocatorDumpCheck implements EntityDumpNonEmptyCheck<LispLocatorDetailsReplyDump> { + + @Override + public void assertNotEmpty(final LispLocatorDetailsReplyDump data) throws DumpCheckFailedException { + + if (data == null) { + throw new DumpEmptyException("Locator dump is null"); + } + + if (data.lispLocatorDetails == null) { + throw new DumpEmptyException("Locator dump is empty"); + } + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorSetsDumpCheck.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorSetsDumpCheck.java new file mode 100755 index 000000000..eac757d50 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/LocatorSetsDumpCheck.java @@ -0,0 +1,38 @@ +/* + * 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.translate.read.dump.check; + + +import io.fd.honeycomb.translate.v3po.util.cache.EntityDumpNonEmptyCheck; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.check.DumpCheckFailedException; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.check.i.DumpEmptyException; +import org.openvpp.jvpp.core.dto.LispLocatorSetDetailsReplyDump; + +public class LocatorSetsDumpCheck implements EntityDumpNonEmptyCheck<LispLocatorSetDetailsReplyDump> { + + @Override + public void assertNotEmpty(final LispLocatorSetDetailsReplyDump data) throws DumpCheckFailedException { + + if (data == null) { + throw new DumpEmptyException("Locator sets dump is null"); + } + + if (data.lispLocatorSetDetails == null) { + throw new DumpEmptyException("Locator sets dump is empty"); + } + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/MapResolverDumpCheck.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/MapResolverDumpCheck.java new file mode 100755 index 000000000..e018702ee --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/MapResolverDumpCheck.java @@ -0,0 +1,37 @@ +/* + * 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.translate.read.dump.check; + + +import io.fd.honeycomb.translate.v3po.util.cache.EntityDumpNonEmptyCheck; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.check.DumpCheckFailedException; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.check.i.DumpEmptyException; +import org.openvpp.jvpp.core.dto.LispMapResolverDetailsReplyDump; + +public class MapResolverDumpCheck implements EntityDumpNonEmptyCheck<LispMapResolverDetailsReplyDump> { + + @Override + public void assertNotEmpty(final LispMapResolverDetailsReplyDump data) throws DumpCheckFailedException { + if (data == null) { + throw new DumpEmptyException("Map resolvers dump is null"); + } + + if (data.lispMapResolverDetails == null) { + throw new DumpEmptyException("Map resolvers dump is empty"); + } + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/MappingsDumpCheck.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/MappingsDumpCheck.java new file mode 100755 index 000000000..f34ea1b8e --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/MappingsDumpCheck.java @@ -0,0 +1,40 @@ +/* + * 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.translate.read.dump.check; + + +import io.fd.honeycomb.translate.v3po.util.cache.EntityDumpNonEmptyCheck; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.check.DumpCheckFailedException; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.check.i.DumpEmptyException; +import org.openvpp.jvpp.core.dto.LispEidTableDetailsReplyDump; + +/** + * Common dump check for both local and remote mappings + */ +public class MappingsDumpCheck implements EntityDumpNonEmptyCheck<LispEidTableDetailsReplyDump> { + + @Override + public void assertNotEmpty(final LispEidTableDetailsReplyDump data) throws DumpCheckFailedException { + if (data == null) { + throw new DumpEmptyException("Mappings dump is null"); + } + + if (data.lispEidTableDetails == null) { + throw new DumpEmptyException("Mappings dump is empty"); + } + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/VniTableDumpCheck.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/VniTableDumpCheck.java new file mode 100755 index 000000000..942d974e6 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/check/VniTableDumpCheck.java @@ -0,0 +1,37 @@ +/* + * 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.translate.read.dump.check; + + +import io.fd.honeycomb.translate.v3po.util.cache.EntityDumpNonEmptyCheck; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.check.DumpCheckFailedException; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.check.i.DumpEmptyException; +import org.openvpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump; + +public class VniTableDumpCheck implements EntityDumpNonEmptyCheck<LispEidTableMapDetailsReplyDump> { + + @Override + public void assertNotEmpty(final LispEidTableMapDetailsReplyDump data) throws DumpCheckFailedException { + if (data == null) { + throw new DumpEmptyException("Vni table dump is null"); + } + + if (data.lispEidTableMapDetails == null) { + throw new DumpEmptyException("Bni table dump is empty"); + } + } +} 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/AbstractDumpExecutor.java new file mode 100644 index 000000000..fbd2003e8 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/AbstractDumpExecutor.java @@ -0,0 +1,35 @@ +/* + * 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.translate.read.dump.executor; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.annotation.Nonnull; +import org.openvpp.jvpp.core.future.FutureJVppCore; + + +/** + * Abstract holder for jvpp refference + */ +public abstract class AbstractDumpExecutor { + + protected final FutureJVppCore vppApi; + + protected AbstractDumpExecutor(@Nonnull final FutureJVppCore vppApi) { + this.vppApi = checkNotNull(vppApi, "VPP Api refference cannot be null"); + } +} 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 new file mode 100644 index 000000000..16e6deaab --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/LocatorDumpExecutor.java @@ -0,0 +1,64 @@ +/* + * 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.translate.read.dump.executor; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.honeycomb.lisp.translate.read.dump.executor.params.LocatorDumpParams; +import io.fd.honeycomb.translate.v3po.util.TranslateUtils; +import io.fd.honeycomb.translate.v3po.util.cache.EntityDumpExecutor; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.execution.DumpExecutionFailedException; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.execution.i.DumpCallFailedException; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.execution.i.DumpTimeoutException; +import java.util.concurrent.TimeoutException; +import javax.annotation.Nonnull; +import org.openvpp.jvpp.VppBaseCallException; +import org.openvpp.jvpp.core.dto.LispLocatorDetailsReplyDump; +import org.openvpp.jvpp.core.dto.LispLocatorDump; +import org.openvpp.jvpp.core.future.FutureJVppCore; + + +/** + * Executor for dumping of locators + */ +public class LocatorDumpExecutor extends AbstractDumpExecutor + implements EntityDumpExecutor<LispLocatorDetailsReplyDump, LocatorDumpParams> { + + + public LocatorDumpExecutor(@Nonnull final FutureJVppCore vppApi) { + super(vppApi); + } + + @Override + public LispLocatorDetailsReplyDump executeDump(final LocatorDumpParams params) throws DumpExecutionFailedException { + checkNotNull(params, "Params for dump request not present"); + + LispLocatorDump request = new LispLocatorDump(); + request.locatorSetIndex = params.getLocatorSetIndex(); + request.filter = params.getFilter(); + + try { + return TranslateUtils.getReply(vppApi.lispLocatorDump(request).toCompletableFuture()); + } catch (TimeoutException e) { + throw DumpTimeoutException + .wrapTimeoutException("Locator dump ended in timeout with params" + params.toString(), e); + } catch (VppBaseCallException e) { + throw DumpCallFailedException + .wrapFailedCallException("Locator dump failed with params" + params.toString(), e); + } + } +} 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 new file mode 100755 index 000000000..d074bae52 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/LocatorSetsDumpExecutor.java @@ -0,0 +1,55 @@ +/* + * 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.translate.read.dump.executor; + + +import io.fd.honeycomb.translate.v3po.util.TranslateUtils; +import io.fd.honeycomb.translate.v3po.util.cache.EntityDumpExecutor; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.execution.DumpExecutionFailedException; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.execution.i.DumpCallFailedException; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.execution.i.DumpTimeoutException; +import java.util.concurrent.TimeoutException; +import javax.annotation.Nonnull; +import org.openvpp.jvpp.VppBaseCallException; +import org.openvpp.jvpp.core.dto.LispLocatorSetDetailsReplyDump; +import org.openvpp.jvpp.core.dto.LispLocatorSetDump; +import org.openvpp.jvpp.core.future.FutureJVppCore; + + +public class LocatorSetsDumpExecutor extends AbstractDumpExecutor + implements EntityDumpExecutor<LispLocatorSetDetailsReplyDump, Void> { + + public LocatorSetsDumpExecutor(@Nonnull FutureJVppCore api) { + super(api); + } + + @Override + public LispLocatorSetDetailsReplyDump executeDump(final Void params) throws DumpExecutionFailedException { + + LispLocatorSetDump request = new LispLocatorSetDump(); + request.filter = 0; + + try { + return TranslateUtils + .getReply(vppApi.lispLocatorSetDump(request).toCompletableFuture()); + } catch (TimeoutException e) { + throw DumpTimeoutException.wrapTimeoutException("Locator sets dump ended in timeout", e); + } catch (VppBaseCallException e) { + throw DumpCallFailedException.wrapFailedCallException("Locator sets dump failed", e); + } + } +} 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 new file mode 100755 index 000000000..ec1cabd54 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/MapResolversDumpExecutor.java @@ -0,0 +1,51 @@ +/* + * 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.translate.read.dump.executor; + + +import io.fd.honeycomb.translate.v3po.util.TranslateUtils; +import io.fd.honeycomb.translate.v3po.util.cache.EntityDumpExecutor; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.execution.DumpExecutionFailedException; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.execution.i.DumpCallFailedException; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.execution.i.DumpTimeoutException; +import java.util.concurrent.TimeoutException; +import javax.annotation.Nonnull; +import org.openvpp.jvpp.VppBaseCallException; +import org.openvpp.jvpp.core.dto.LispMapResolverDetailsReplyDump; +import org.openvpp.jvpp.core.dto.LispMapResolverDump; +import org.openvpp.jvpp.core.future.FutureJVppCore; + + +public class MapResolversDumpExecutor extends AbstractDumpExecutor + implements EntityDumpExecutor<LispMapResolverDetailsReplyDump, Void> { + + public MapResolversDumpExecutor(@Nonnull FutureJVppCore api) { + super(api); + } + + @Override + public LispMapResolverDetailsReplyDump executeDump(final Void params) throws DumpExecutionFailedException { + try { + return TranslateUtils.getReply(vppApi.lispMapResolverDump(new LispMapResolverDump()).toCompletableFuture()); + } catch (TimeoutException e) { + throw DumpTimeoutException + .wrapTimeoutException("Map resolver dump execution ended in timeout", e); + } catch (VppBaseCallException e) { + throw DumpCallFailedException.wrapFailedCallException("Map resolver dump execution failed", e); + } + } +} 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 new file mode 100755 index 000000000..d43713967 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/MappingsDumpExecutor.java @@ -0,0 +1,70 @@ +/* + * 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.translate.read.dump.executor; + + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams; +import io.fd.honeycomb.translate.v3po.util.TranslateUtils; +import io.fd.honeycomb.translate.v3po.util.cache.EntityDumpExecutor; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.execution.DumpExecutionFailedException; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.execution.i.DumpCallFailedException; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.execution.i.DumpTimeoutException; +import java.util.concurrent.TimeoutException; +import javax.annotation.Nonnull; +import org.openvpp.jvpp.VppBaseCallException; +import org.openvpp.jvpp.core.dto.LispEidTableDetailsReplyDump; +import org.openvpp.jvpp.core.dto.LispEidTableDump; +import org.openvpp.jvpp.core.future.FutureJVppCore; + + +/** + * Common dump executor for both local and remote mappings + */ +public class MappingsDumpExecutor extends AbstractDumpExecutor + implements EntityDumpExecutor<LispEidTableDetailsReplyDump, MappingsDumpParams> { + + public MappingsDumpExecutor(@Nonnull FutureJVppCore vppApi) { + super(vppApi); + } + + + @Override + public LispEidTableDetailsReplyDump executeDump(final MappingsDumpParams params) + throws DumpExecutionFailedException { + checkNotNull(params, "Params for dump request not present"); + + LispEidTableDump request = new LispEidTableDump(); + request.eid = params.getEid(); + request.eidSet = params.getEidSet(); + request.eidType = params.getEidType(); + request.prefixLength = params.getPrefixLength(); + request.vni = params.getVni(); + request.filter = params.getFilter(); + + try { + return TranslateUtils.getReply(vppApi.lispEidTableDump(request).toCompletableFuture()); + } catch (TimeoutException e) { + throw DumpTimeoutException + .wrapTimeoutException("Mappings dump execution timed out with params " + params.toString(), e); + } catch (VppBaseCallException e) { + throw DumpCallFailedException + .wrapFailedCallException("Mappings dump execution failed with params " + params.toString(), 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 new file mode 100755 index 000000000..cb5f06393 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/VniTableDumpExecutor.java @@ -0,0 +1,50 @@ +/* + * 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.translate.read.dump.executor; + + +import io.fd.honeycomb.translate.v3po.util.TranslateUtils; +import io.fd.honeycomb.translate.v3po.util.cache.EntityDumpExecutor; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.execution.DumpExecutionFailedException; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.execution.i.DumpCallFailedException; +import io.fd.honeycomb.translate.v3po.util.cache.exceptions.execution.i.DumpTimeoutException; +import java.util.concurrent.TimeoutException; +import javax.annotation.Nonnull; +import org.openvpp.jvpp.VppBaseCallException; +import org.openvpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump; +import org.openvpp.jvpp.core.dto.LispEidTableMapDump; +import org.openvpp.jvpp.core.future.FutureJVppCore; + + +public class VniTableDumpExecutor extends AbstractDumpExecutor + implements EntityDumpExecutor<LispEidTableMapDetailsReplyDump, Void> { + + public VniTableDumpExecutor(@Nonnull FutureJVppCore api) { + super(api); + } + + @Override + public LispEidTableMapDetailsReplyDump executeDump(Void params) throws DumpExecutionFailedException { + try { + return TranslateUtils.getReply(vppApi.lispEidTableMapDump(new LispEidTableMapDump()).toCompletableFuture()); + } catch (TimeoutException e) { + throw DumpTimeoutException.wrapTimeoutException("Eid table map dump ended in timeout", e); + } catch (VppBaseCallException e) { + throw DumpCallFailedException.wrapFailedCallException("Eid table map dump failed", e); + } + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/params/LocatorDumpParams.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/params/LocatorDumpParams.java new file mode 100644 index 000000000..eda1e9771 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/params/LocatorDumpParams.java @@ -0,0 +1,82 @@ +/* + * 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.translate.read.dump.executor.params; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Params for dumping locators + */ +public final class LocatorDumpParams { + + private final int locatorSetIndex; + private final byte filter; + + private LocatorDumpParams(LocatorDumpParamsBuilder builder) { + this.locatorSetIndex = builder.locatorSetIndex; + this.filter = builder.filter; + } + + public int getLocatorSetIndex() { + return locatorSetIndex; + } + + public byte getFilter() { + return filter; + } + + /** + * Enum for filtering which locators to dump + */ + public enum LocatorDumpFilter { + + ALL(0), + LOCAL(1), + REMOTE(2); + + private final int value; + + private LocatorDumpFilter(int value) { + this.value = value; + } + + public final int getValue() { + return value; + } + } + + public static final class LocatorDumpParamsBuilder { + + public int locatorSetIndex; + public byte filter; + + + public LocatorDumpParamsBuilder setLocatorSetIndex(final int locatorSetIndex) { + this.locatorSetIndex = locatorSetIndex; + return this; + } + + public LocatorDumpParamsBuilder setFilter(final LocatorDumpFilter filter) { + this.filter = Integer.valueOf(checkNotNull(filter, "Cannot set null filter").getValue()).byteValue(); + return this; + } + + public LocatorDumpParams build() { + return new LocatorDumpParams(this); + } + } +} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/params/MappingsDumpParams.java b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/params/MappingsDumpParams.java new file mode 100755 index 000000000..1f7990c9b --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/params/MappingsDumpParams.java @@ -0,0 +1,192 @@ +/* + * 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.translate.read.dump.executor.params; + +import io.fd.honeycomb.lisp.translate.read.dump.executor.MappingsDumpExecutor; +import java.util.Arrays; + +/** + * Parameters for executing {@link MappingsDumpExecutor} + */ +public final class MappingsDumpParams { + + private final byte eidSet; + private final byte prefixLength; + private final int vni; + private final byte eidType; + private final byte[] eid; + private final byte filter; + + private MappingsDumpParams(MappingsDumpParamsBuilder builder) { + this.eidSet = builder.eidSet; + this.prefixLength = builder.prefixLength; + this.vni = builder.vni; + this.eidType = builder.eidType; + this.eid = builder.eid; + this.filter = builder.filter; + } + + + public byte getEidSet() { + return eidSet; + } + + public byte getPrefixLength() { + return prefixLength; + } + + public int getVni() { + return vni; + } + + public byte getEidType() { + return eidType; + } + + public byte[] getEid() { + return eid; + } + + public final byte getFilter() { + return filter; + } + + @Override + public String toString() { + return "MappingsDumpParams{" + + "eidSet=" + eidSet + + ", prefixLength=" + prefixLength + + ", vni=" + vni + + ", eidType=" + eidType + + ", eid=" + Arrays.toString(eid) + + ", filter=" + filter + + '}'; + } + + /** + * Type of requested mapping eid + */ + public enum EidType { + IPV4(0), + IPV6(1), + MAC(2); + + private final int value; + + private EidType(final int value) { + this.value = value; + } + + public static final EidType valueOf(int value) { + switch (value) { + case 0: + return IPV4; + case 1: + return IPV6; + case 2: + return MAC; + default: + throw new IllegalArgumentException("Illegal value"); + } + } + + public final int getValue() { + return this.value; + } + } + + /** + * Type of requested mapping + */ + public enum FilterType { + ALL(0), + LOCAL(1), + REMOTE(2); + + private final int value; + + private FilterType(final int value) { + this.value = value; + } + + public final int getValue() { + return this.value; + } + } + + public enum QuantityType { + ALL(0), + SPECIFIC(1); + + private final int value; + + private QuantityType(final int value) { + this.value = value; + } + + public final int getValue() { + return this.value; + } + } + + public static final class MappingsDumpParamsBuilder { + private byte eidSet; + private byte prefixLength; + private int vni; + private byte eidType; + private byte[] eid; + private byte filter; + + public static final MappingsDumpParamsBuilder newInstance() { + return new MappingsDumpParamsBuilder(); + } + + public MappingsDumpParamsBuilder setEidSet(final QuantityType quantityType) { + this.eidSet = (byte) quantityType.getValue(); + return this; + } + + public MappingsDumpParamsBuilder setPrefixLength(final byte prefixLength) { + this.prefixLength = prefixLength; + return this; + } + + public MappingsDumpParamsBuilder setVni(final int vni) { + this.vni = vni; + return this; + } + + public MappingsDumpParamsBuilder setEidType(final EidType eidType) { + this.eidType = (byte) eidType.getValue(); + return this; + } + + public MappingsDumpParamsBuilder setEid(final byte[] eid) { + this.eid = eid; + return this; + } + + public MappingsDumpParamsBuilder setFilter(final FilterType filterType) { + this.filter = (byte) filterType.getValue(); + return this; + } + + public MappingsDumpParams build() { + return new MappingsDumpParams(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 new file mode 100644 index 000000000..318b6f2f1 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/AbstractLispReaderFactoryBase.java @@ -0,0 +1,79 @@ +/* + * 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.factory; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.honeycomb.lisp.context.util.EidMappingContext; +import io.fd.honeycomb.translate.v3po.util.NamingContext; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.LispState; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.core.future.FutureJVppCore; + + +/** + * Basic attributes for lisp reader factories + */ +abstract class AbstractLispReaderFactoryBase { + + protected final InstanceIdentifier<LispState> lispStateId; + protected final FutureJVppCore vppApi; + protected NamingContext interfaceContext; + protected NamingContext locatorSetContext; + protected EidMappingContext localMappingContext; + protected EidMappingContext remoteMappingContext; + + protected AbstractLispReaderFactoryBase(@Nonnull final InstanceIdentifier<LispState> lispStateId, + @Nonnull final FutureJVppCore vppApi) { + this.lispStateId = checkNotNull(lispStateId, "Lisp state identifier is null"); + this.vppApi = checkNotNull(vppApi, "VPP api refference is null"); + } + + protected AbstractLispReaderFactoryBase(@Nonnull final InstanceIdentifier<LispState> lispStateId, + @Nonnull final FutureJVppCore vppApi, + @Nonnull final NamingContext interfaceContext, + @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.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"); + } + + protected AbstractLispReaderFactoryBase(@Nonnull final InstanceIdentifier<LispState> lispStateId, + @Nonnull final FutureJVppCore vppApi, + @Nonnull final NamingContext interfaceContext, + @Nonnull final NamingContext locatorSetContext, + @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.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 new file mode 100755 index 000000000..905d0faff --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/EidTableReaderFactory.java @@ -0,0 +1,112 @@ +/* + * 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.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.LocalMappingCustomizer; +import io.fd.honeycomb.lisp.translate.read.RemoteMappingCustomizer; +import io.fd.honeycomb.lisp.translate.read.VniTableCustomizer; +import io.fd.honeycomb.translate.impl.read.GenericListReader; +import io.fd.honeycomb.translate.read.ReaderFactory; +import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; +import io.fd.honeycomb.translate.v3po.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.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.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.core.future.FutureJVppCore; + + +/** + * Factory that produces {@code Reader} for {@code EidTable}<br> with all its inhired child readers + */ +final class EidTableReaderFactory extends AbstractLispReaderFactoryBase implements ReaderFactory { + + private EidTableReaderFactory(final InstanceIdentifier<LispState> lispStateId, + final FutureJVppCore vppApi, + final NamingContext interfaceContext, + final NamingContext locatorSetContext, + final EidMappingContext localMappingContext, + final EidMappingContext remoteMappingContext) { + super(lispStateId, vppApi,interfaceContext, locatorSetContext, 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 EidMappingContext localMappingContext, + @Nonnull final EidMappingContext remoteMappingContext) { + return new EidTableReaderFactory(lispStateId, vppApi, interfaceContext, locatorSetContext, 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); + + registry.addStructuralReader(eidTableInstanceIdentifier, EidTableBuilder.class); + registry.add(new GenericListReader<>(vniTableInstanceIdentifier, new VniTableCustomizer(vppApi))); + + registry.addStructuralReader(localMappingsInstanceIdentifier, LocalMappingsBuilder.class); + + 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 GenericListReader<>(localMappingsInstanceIdentifier.child(LocalMapping.class), + new LocalMappingCustomizer(vppApi, locatorSetContext, localMappingContext))); + + registry.addStructuralReader(remoteMappingsInstanceIdentifier, 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), + new RemoteMappingCustomizer(vppApi, remoteMappingContext))); + + registry.addStructuralReader(adjacenciesInstanceIdentifier, 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 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 new file mode 100755 index 000000000..8444066d7 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/LispStateReaderFactory.java @@ -0,0 +1,71 @@ +/* + * 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.translate.read.factory; + +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; +import static io.fd.honeycomb.lisp.cfgattrs.LispConfiguration.REMOTE_MAPPING_CONTEXT; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.honeycomb.lisp.context.util.EidMappingContext; +import io.fd.honeycomb.lisp.translate.read.LispStateCustomizer; +import io.fd.honeycomb.lisp.translate.read.PitrCfgCustomizer; +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.v3po.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.pitr.cfg.grouping.PitrCfg; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.core.future.FutureJVppCore; + + +/** + * Initialize readers for {@link LispState} + */ +public class LispStateReaderFactory extends AbstractLispReaderFactoryBase implements ReaderFactory { + + @Inject + public LispStateReaderFactory(final FutureJVppCore vppApi, + @Named(INTERFACE_CONTEXT) final NamingContext interfaceContext, + @Named(LOCATOR_SET_CONTEXT) final NamingContext locatorSetContext, + @Named(LOCAL_MAPPING_CONTEXT) final EidMappingContext localMappingContext, + @Named(REMOTE_MAPPING_CONTEXT) final EidMappingContext remoteMappingContext) { + super(InstanceIdentifier.create(LispState.class), vppApi, interfaceContext, locatorSetContext, + localMappingContext, + remoteMappingContext); + } + + + @Override + public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { + + registry.add(new GenericReader<>(lispStateId, new LispStateCustomizer(vppApi))); + + LocatorSetsReaderFactory.newInstance(lispStateId, vppApi, interfaceContext, locatorSetContext).init(registry); + MapResolversReaderFactory.newInstance(lispStateId, vppApi).init(registry); + EidTableReaderFactory + .newInstance(lispStateId, vppApi, interfaceContext, locatorSetContext, localMappingContext, + remoteMappingContext) + .init(registry); + + registry.add(new GenericReader<>(lispStateId.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 new file mode 100755 index 000000000..053f3d858 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/LocatorSetsReaderFactory.java @@ -0,0 +1,70 @@ +/* + * 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.translate.read.factory; + + +import io.fd.honeycomb.lisp.translate.read.InterfaceCustomizer; +import io.fd.honeycomb.lisp.translate.read.LocatorSetCustomizer; +import io.fd.honeycomb.translate.impl.read.GenericListReader; +import io.fd.honeycomb.translate.read.ReaderFactory; +import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; +import io.fd.honeycomb.translate.v3po.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.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; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.locator.set.Interface; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.core.future.FutureJVppCore; + + +/** + * Produces reader for {@link LocatorSets} <br> and all its inhired child readers + */ +public class LocatorSetsReaderFactory extends AbstractLispReaderFactoryBase implements ReaderFactory { + + + private LocatorSetsReaderFactory(final InstanceIdentifier<LispState> lispStateId, + final FutureJVppCore vppApi, + final NamingContext interfaceContext, + final NamingContext locatorSetContext + ) { + super(lispStateId, vppApi); + this.interfaceContext=interfaceContext; + this.locatorSetContext = locatorSetContext; + } + + public static final LocatorSetsReaderFactory newInstance(@Nonnull final InstanceIdentifier<LispState> lispStateId, + @Nonnull final FutureJVppCore vppApi, + final NamingContext interfaceContext, + @Nonnull final NamingContext locatorSetContext) { + return new LocatorSetsReaderFactory(lispStateId, vppApi, interfaceContext,locatorSetContext); + } + + @Override + public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { + InstanceIdentifier<LocatorSets> locatorSetsInstanceIdentifier = lispStateId.child(LocatorSets.class); + InstanceIdentifier<LocatorSet> locatorSetInstanceIdentifier = + locatorSetsInstanceIdentifier.child(LocatorSet.class); + + registry.addStructuralReader(locatorSetsInstanceIdentifier, LocatorSetsBuilder.class); + registry.add(new GenericListReader<>(locatorSetInstanceIdentifier, new LocatorSetCustomizer(vppApi))); + registry.add(new GenericListReader<>(locatorSetInstanceIdentifier.child(Interface.class), + new InterfaceCustomizer(vppApi, interfaceContext, locatorSetContext))); + } +} 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 new file mode 100755 index 000000000..c26f17234 --- /dev/null +++ b/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/factory/MapResolversReaderFactory.java @@ -0,0 +1,56 @@ +/* + * 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.translate.read.factory; + + +import io.fd.honeycomb.lisp.translate.read.MapResolverCustomizer; +import io.fd.honeycomb.translate.impl.read.GenericListReader; +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.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; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.core.future.FutureJVppCore; + + +/** + * Builds reader for {@link MapResolvers}<br> and all its inhired child readers + */ +public class MapResolversReaderFactory extends AbstractLispReaderFactoryBase implements ReaderFactory { + + private MapResolversReaderFactory(final InstanceIdentifier<LispState> lispStateId, final FutureJVppCore vppApi) { + super(lispStateId, vppApi); + } + + public static MapResolversReaderFactory newInstance(@Nonnull final InstanceIdentifier<LispState> lispStateId, + @Nonnull final FutureJVppCore vppApi) { + return new MapResolversReaderFactory(lispStateId, vppApi); + } + + @Override + public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { + + InstanceIdentifier<MapResolvers> mapResolversInstanceIdentifier = lispStateId.child(MapResolvers.class); + + registry.addStructuralReader(mapResolversInstanceIdentifier, MapResolversBuilder.class); + registry.add(new GenericListReader<>(mapResolversInstanceIdentifier.child(MapResolver.class), + new MapResolverCustomizer(vppApi))); + } +} |