HONEYCOMB-154: update revison of models that changed since 16.09
[honeycomb.git] / lisp / lisp2vpp / src / main / java / io / fd / honeycomb / lisp / translate / read / trait / MappingProducer.java
1 package io.fd.honeycomb.lisp.translate.read.trait;
2
3 import io.fd.honeycomb.translate.write.WriteFailedException;
4 import javax.annotation.Nonnull;
5 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi;
6 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6Afi;
7 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddressFamily;
8 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi;
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.local.mappings.LocalMapping;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.RemoteMapping;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.VrfSubtable;
13 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
14
15 /**
16  * Trait that verifies data for mappings
17  */
18 public interface MappingProducer {
19
20     /**
21      * Checks whether provided {@link LocalMapping} can be written under subtree idenfied by {@link InstanceIdentifier}
22      */
23     default void checkAllowedCombination(@Nonnull final InstanceIdentifier<LocalMapping> identifier,
24                                          @Nonnull final LocalMapping data) throws WriteFailedException {
25         final Class<? extends LispAddressFamily> eidAddressType = data.getEid().getAddressType();
26
27         if (identifier.firstIdentifierOf(VrfSubtable.class) != null) {
28             if (Ipv4Afi.class != eidAddressType && Ipv6Afi.class != eidAddressType) {
29                 throw new WriteFailedException.CreateFailedException(identifier, data,
30                         new IllegalArgumentException("Only Ipv4/Ipv6 eid's are allowed for Vrf Subtable"));
31             }
32         } else if (identifier.firstIdentifierOf(BridgeDomainSubtable.class) != null) {
33             if (MacAfi.class != eidAddressType) {
34                 throw new WriteFailedException.CreateFailedException(identifier, data,
35                         new IllegalArgumentException("Only Mac eid's are allowed for Bridge Domain Subtable"));
36             }
37         }
38     }
39
40     default void checkAllowedCombination(@Nonnull final InstanceIdentifier<RemoteMapping> identifier,
41                                          @Nonnull final RemoteMapping data) throws WriteFailedException {
42         final Class<? extends LispAddressFamily> eidAddressType = data.getEid().getAddressType();
43
44         if (identifier.firstIdentifierOf(VrfSubtable.class) != null) {
45             if (Ipv4Afi.class != eidAddressType && Ipv6Afi.class != eidAddressType) {
46                 throw new WriteFailedException.CreateFailedException(identifier, data,
47                         new IllegalArgumentException("Only Ipv4/Ipv6 eid's are allowed for Vrf Subtable"));
48             }
49         } else if (identifier.firstIdentifierOf(BridgeDomainSubtable.class) != null) {
50             if (MacAfi.class != eidAddressType) {
51                 throw new WriteFailedException.CreateFailedException(identifier, data,
52                         new IllegalArgumentException("Only Mac eid's are allowed for Bridge Domain Subtable"));
53             }
54         }
55     }
56 }