ef1ca0438070296d97256ad2c2dc09ef5a52491c
[honeycomb.git] / lisp / lisp2vpp / src / main / java / io / fd / honeycomb / lisp / translate / read / trait / MappingFilterProvider.java
1 package io.fd.honeycomb.lisp.translate.read.trait;
2
3 import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV4;
4 import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV6;
5 import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.MAC;
6
7 import java.util.function.Predicate;
8 import javax.annotation.Nonnull;
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMapping;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMapping;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable;
13 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
14 import io.fd.vpp.jvpp.core.dto.LispEidTableDetails;
15
16 /**
17  * Trait providing predicates to filter mappings to respective subtables
18  */
19 public interface MappingFilterProvider {
20
21     Predicate<LispEidTableDetails> BRIDGE_DOMAIN_MAPPINGS_ONLY =
22             (LispEidTableDetails detail) -> detail.eidType == MAC.getValue();
23
24     Predicate<LispEidTableDetails> VRF_MAPPINGS_ONLY =
25             (LispEidTableDetails detail) -> detail.eidType == IPV4.getValue() || detail.eidType == IPV6.getValue();
26
27     default Predicate<LispEidTableDetails> subtableFilterForLocalMappings(
28             @Nonnull final InstanceIdentifier<LocalMapping> identifier) {
29
30         if (identifier.firstIdentifierOf(VrfSubtable.class) != null) {
31             return VRF_MAPPINGS_ONLY;
32         } else if (identifier.firstIdentifierOf(BridgeDomainSubtable.class) != null) {
33             return BRIDGE_DOMAIN_MAPPINGS_ONLY;
34         } else {
35             throw new IllegalArgumentException("Cannot determine mappings predicate for " + identifier);
36         }
37     }
38
39     default Predicate<LispEidTableDetails> subtableFilterForRemoteMappings(
40             @Nonnull final InstanceIdentifier<RemoteMapping> identifier) {
41
42         if (identifier.firstIdentifierOf(VrfSubtable.class) != null) {
43             return VRF_MAPPINGS_ONLY;
44         } else if (identifier.firstIdentifierOf(BridgeDomainSubtable.class) != null) {
45             return BRIDGE_DOMAIN_MAPPINGS_ONLY;
46         } else {
47             throw new IllegalArgumentException("Cannot determine mappings predicate for " + identifier);
48         }
49     }
50 }