2 * Copyright (c) 2015 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.write.trait;
20 import static com.google.common.base.Preconditions.checkNotNull;
22 import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator;
23 import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer;
24 import java.util.concurrent.TimeoutException;
25 import javax.annotation.Nonnull;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.VniTable;
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.ChildOf;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import io.fd.vpp.jvpp.VppBaseCallException;
32 import io.fd.vpp.jvpp.core.dto.LispEidTableAddDelMap;
33 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
34 import org.slf4j.Logger;
37 * Trait providing logic for writing subtables
39 public interface SubtableWriter extends ByteDataTranslator, JvppReplyConsumer {
43 * Writes mapping from {@link VniTable}
44 * to {@link VrfSubtable} or
45 * {@link BridgeDomainSubtable}
47 * @param addDel true if add,delete otherwise
48 * @param vni {@link VniTable} ID
49 * @param tableId if <b>isL2</b> is true, than bridge domain subtable id,else vrf subtable id
50 * @param isL2 indicates whether (false) writing to L3 vrfSubtrable of (true) L2 bridgeDomainSubtrable
52 default void addDelSubtableMapping(@Nonnull final FutureJVppCore vppApi, final boolean addDel, final int vni,
55 final Logger logger) throws TimeoutException, VppBaseCallException {
57 if (vni == DEFAULT_VNI) {
58 // attempt to write subtable with default vni mapping(it does'nt make sense and it should'nt be possible)
59 // also allows to enable lisp without defining default mapping in request
60 logger.info("An attempt to write subtable[id = {}] with default vni {} was detected, ignoring write",
61 tableId, DEFAULT_VNI);
65 checkNotNull(vppApi, "VPP Api refference cannot be null");
67 LispEidTableAddDelMap request = new LispEidTableAddDelMap();
69 request.isAdd = booleanToByte(addDel);
71 request.dpTable = tableId;
72 request.isL2 = booleanToByte(isL2);
74 getReply(vppApi.lispEidTableAddDelMap(request).toCompletableFuture());
77 default int extractVni(@Nonnull final InstanceIdentifier<? extends ChildOf<VniTable>> id) {
79 checkNotNull(id, "Identifier cannot be null").firstKeyOf(VniTable.class),
80 "Parent VNI id not defined").getVirtualNetworkIdentifier().intValue();