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;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
35 * Uses api to create gpe interfaces, which creates fib table as by-product.
36 * There is currently no other lisp-specific way to define fib table, as native paths expects existing table id
38 public class NativeForwardPathsTableCustomizer extends FutureJVppCustomizer
39 implements ListWriterCustomizer<NativeForwardPathsTable, NativeForwardPathsTableKey>, ByteDataTranslator,
42 private static final Logger LOG = LoggerFactory.getLogger(NativeForwardPathsTableCustomizer.class);
44 public NativeForwardPathsTableCustomizer(@Nonnull final FutureJVppCore futureJVppCore) {
45 super(futureJVppCore);
49 public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<NativeForwardPathsTable> id,
50 @Nonnull final NativeForwardPathsTable dataAfter,
51 @Nonnull final WriteContext writeContext)
52 throws WriteFailedException {
53 createFibTable(id, dataAfter);
58 public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<NativeForwardPathsTable> id,
59 @Nonnull final NativeForwardPathsTable dataBefore,
60 @Nonnull final NativeForwardPathsTable dataAfter,
61 @Nonnull final WriteContext writeContext)
62 throws WriteFailedException {
63 // not sure if update makes sense, but just in case
65 createFibTable(id, dataAfter);
69 public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<NativeForwardPathsTable> id,
70 @Nonnull final NativeForwardPathsTable dataBefore,
71 @Nonnull final WriteContext writeContext)
72 throws WriteFailedException {
76 private void createFibTable(final InstanceIdentifier<NativeForwardPathsTable> id,
77 final NativeForwardPathsTable data) throws WriteFailedException {
78 getReplyForCreate(getFutureJVpp().gpeAddDelIface(getRequest(true, id)).toCompletableFuture(), id, data);
81 private void deleteFibTable(final InstanceIdentifier<NativeForwardPathsTable> id) throws WriteFailedException {
82 getReplyForDelete(getFutureJVpp().gpeAddDelIface(getRequest(false, id)).toCompletableFuture(), id);
86 * Maps dpTable and vni to tableId,this also allows to dump lisp specific tables by dumping vni's
88 private GpeAddDelIface getRequest(final boolean add, final InstanceIdentifier<NativeForwardPathsTable> id) {
89 GpeAddDelIface request = new GpeAddDelIface();
91 // expects reversed order
92 request.dpTable = tableId(id);
93 request.vni = request.dpTable; // vni must be unique for every table
94 request.isAdd = booleanToByte(add);
98 static int tableId(final InstanceIdentifier<?> id) {
99 return id.firstKeyOf(NativeForwardPathsTable.class).getTableId().intValue();