92e5c319173485d9ba89a191c326c579786322d5
[honeycomb.git] / lisp / lisp2vpp / src / main / java / io / fd / honeycomb / lisp / translate / read / trait / MappingProducer.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package io.fd.honeycomb.lisp.translate.read.trait;
18
19 import io.fd.honeycomb.translate.write.WriteFailedException;
20 import javax.annotation.Nonnull;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6Afi;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddressFamily;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.local.mappings.LocalMapping;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.RemoteMapping;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.VrfSubtable;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30
31 /**
32  * Trait that verifies data for mappings
33  */
34 public interface MappingProducer {
35
36     /**
37      * Checks whether provided {@link LocalMapping} can be written under subtree idenfied by {@link InstanceIdentifier}
38      */
39     default void checkAllowedCombination(@Nonnull final InstanceIdentifier<LocalMapping> identifier,
40                                          @Nonnull final LocalMapping data) throws WriteFailedException {
41         final Class<? extends LispAddressFamily> eidAddressType = data.getEid().getAddressType();
42
43         if (identifier.firstIdentifierOf(VrfSubtable.class) != null) {
44             if (Ipv4Afi.class != eidAddressType && Ipv6Afi.class != eidAddressType) {
45                 throw new WriteFailedException.CreateFailedException(identifier, data,
46                         new IllegalArgumentException("Only Ipv4/Ipv6 eid's are allowed for Vrf Subtable"));
47             }
48         } else if (identifier.firstIdentifierOf(BridgeDomainSubtable.class) != null) {
49             if (MacAfi.class != eidAddressType) {
50                 throw new WriteFailedException.CreateFailedException(identifier, data,
51                         new IllegalArgumentException("Only Mac eid's are allowed for Bridge Domain Subtable"));
52             }
53         }
54     }
55
56     default void checkAllowedCombination(@Nonnull final InstanceIdentifier<RemoteMapping> identifier,
57                                          @Nonnull final RemoteMapping data) throws WriteFailedException {
58         final Class<? extends LispAddressFamily> eidAddressType = data.getEid().getAddressType();
59
60         if (identifier.firstIdentifierOf(VrfSubtable.class) != null) {
61             if (Ipv4Afi.class != eidAddressType && Ipv6Afi.class != eidAddressType) {
62                 throw new WriteFailedException.CreateFailedException(identifier, data,
63                         new IllegalArgumentException("Only Ipv4/Ipv6 eid's are allowed for Vrf Subtable"));
64             }
65         } else if (identifier.firstIdentifierOf(BridgeDomainSubtable.class) != null) {
66             if (MacAfi.class != eidAddressType) {
67                 throw new WriteFailedException.CreateFailedException(identifier, data,
68                         new IllegalArgumentException("Only Mac eid's are allowed for Bridge Domain Subtable"));
69             }
70         }
71     }
72 }