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 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;
32 * Trait that verifies data for mappings
34 public interface MappingProducer {
37 * Checks whether provided {@link LocalMapping} can be written under subtree idenfied by {@link InstanceIdentifier}
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();
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"));
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"));
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();
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"));
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"));