2 * Copyright (c) 2017 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.hc2vpp.lisp.gpe.translate.write;
19 import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
20 import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
21 import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
22 import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer;
23 import io.fd.honeycomb.translate.write.WriteContext;
24 import io.fd.honeycomb.translate.write.WriteFailedException;
25 import io.fd.vpp.jvpp.core.dto.GpeAddDelIface;
26 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
27 import javax.annotation.Nonnull;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170801._native.forward.paths.tables.NativeForwardPathsTable;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170801._native.forward.paths.tables.NativeForwardPathsTableKey;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 * Uses api to create gpe interfaces, which creates fib table as by-product.
34 * There is currently no other lisp-specific way to define fib table, as native paths expects existing table id
36 public class NativeForwardPathsTableCustomizer extends FutureJVppCustomizer
37 implements ListWriterCustomizer<NativeForwardPathsTable, NativeForwardPathsTableKey>, ByteDataTranslator,
40 public NativeForwardPathsTableCustomizer(@Nonnull final FutureJVppCore futureJVppCore) {
41 super(futureJVppCore);
45 public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<NativeForwardPathsTable> id,
46 @Nonnull final NativeForwardPathsTable dataAfter,
47 @Nonnull final WriteContext writeContext)
48 throws WriteFailedException {
49 createFibTable(id, dataAfter);
53 public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<NativeForwardPathsTable> id,
54 @Nonnull final NativeForwardPathsTable dataBefore,
55 @Nonnull final WriteContext writeContext)
56 throws WriteFailedException {
60 private void createFibTable(final InstanceIdentifier<NativeForwardPathsTable> id,
61 final NativeForwardPathsTable data) throws WriteFailedException {
62 getReplyForCreate(getFutureJVpp().gpeAddDelIface(getRequest(true, id)).toCompletableFuture(), id, data);
65 private void deleteFibTable(final InstanceIdentifier<NativeForwardPathsTable> id) throws WriteFailedException {
66 getReplyForDelete(getFutureJVpp().gpeAddDelIface(getRequest(false, id)).toCompletableFuture(), id);
70 * Maps dpTable and vni to tableId,this also allows to dump lisp specific tables by dumping vni's
72 private GpeAddDelIface getRequest(final boolean add, final InstanceIdentifier<NativeForwardPathsTable> id) {
73 GpeAddDelIface request = new GpeAddDelIface();
75 // expects reversed order
76 request.dpTable = tableId(id);
77 request.vni = request.dpTable; // vni must be unique for every table
78 request.isAdd = booleanToByte(add);
82 static int tableId(final InstanceIdentifier<?> id) {
83 return id.firstKeyOf(NativeForwardPathsTable.class).getTableId().intValue();