2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.lisp.translate.read.trait;
19 import static com.google.common.base.Preconditions.checkNotNull;
20 import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV4;
21 import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV6;
22 import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.MAC;
24 import io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams;
25 import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor;
26 import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer;
27 import io.fd.vpp.jvpp.core.dto.LispEidTableDetails;
28 import io.fd.vpp.jvpp.core.dto.LispEidTableDetailsReplyDump;
29 import io.fd.vpp.jvpp.core.dto.LispEidTableDump;
30 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
31 import java.util.function.Predicate;
32 import javax.annotation.Nonnull;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.local.mappings.LocalMapping;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.RemoteMapping;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.VrfSubtable;
37 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
40 * Trait providing predicates to filter mappings to respective subtables
42 public interface MappingReader extends JvppReplyConsumer {
44 Predicate<LispEidTableDetails> BRIDGE_DOMAIN_MAPPINGS_ONLY =
45 (LispEidTableDetails detail) -> detail.eidType == MAC.getValue();
47 Predicate<LispEidTableDetails> VRF_MAPPINGS_ONLY =
48 (LispEidTableDetails detail) -> detail.eidType == IPV4.getValue() || detail.eidType == IPV6.getValue();
50 default Predicate<LispEidTableDetails> subtableFilterForLocalMappings(
51 @Nonnull final InstanceIdentifier<LocalMapping> identifier) {
53 if (identifier.firstIdentifierOf(VrfSubtable.class) != null) {
54 return VRF_MAPPINGS_ONLY;
55 } else if (identifier.firstIdentifierOf(BridgeDomainSubtable.class) != null) {
56 return BRIDGE_DOMAIN_MAPPINGS_ONLY;
58 throw new IllegalArgumentException("Cannot determine mappings predicate for " + identifier);
62 default Predicate<LispEidTableDetails> subtableFilterForRemoteMappings(
63 @Nonnull final InstanceIdentifier<RemoteMapping> identifier) {
65 if (identifier.firstIdentifierOf(VrfSubtable.class) != null) {
66 return VRF_MAPPINGS_ONLY;
67 } else if (identifier.firstIdentifierOf(BridgeDomainSubtable.class) != null) {
68 return BRIDGE_DOMAIN_MAPPINGS_ONLY;
70 throw new IllegalArgumentException("Cannot determine mappings predicate for " + identifier);
74 default EntityDumpExecutor<LispEidTableDetailsReplyDump, MappingsDumpParams> createMappingDumpExecutor(
75 @Nonnull final FutureJVppCore vppApi) {
76 return (identifier, params) -> {
77 checkNotNull(params, "Params for dump request not present");
79 LispEidTableDump request = new LispEidTableDump();
80 request.eid = params.getEid();
81 request.eidSet = params.getEidSet();
82 request.eidType = params.getEidType();
83 request.prefixLength = params.getPrefixLength();
84 request.vni = params.getVni();
85 request.filter = params.getFilter();
87 return getReplyForRead(vppApi.lispEidTableDump(request).toCompletableFuture(), identifier);