2 * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.
18 package io.fd.hc2vpp.fib.management.write;
20 import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
21 import io.fd.hc2vpp.fib.management.request.FibTableRequest;
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.future.FutureJVppCore;
26 import javax.annotation.Nonnull;
27 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.Ipv6;
28 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.Table;
29 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableKey;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 class FibTableCustomizer extends FutureJVppCustomizer implements ListWriterCustomizer<Table, TableKey> {
33 FibTableCustomizer(@Nonnull final FutureJVppCore vppApi) {
38 public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Table> instanceIdentifier,
39 @Nonnull final Table table,
40 @Nonnull final WriteContext writeContext) throws WriteFailedException {
41 bindFibTableRequest(table).write(instanceIdentifier);
45 public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Table> instanceIdentifier,
46 @Nonnull final Table table,
47 @Nonnull final WriteContext writeContext) throws WriteFailedException {
48 bindFibTableRequest(table).delete(instanceIdentifier);
51 private FibTableRequest bindFibTableRequest(final @Nonnull Table table) {
52 FibTableRequest fibTableRequest = new FibTableRequest(getFutureJVpp());
53 fibTableRequest.setFibName(table.getName());
54 fibTableRequest.setFibTable(table.getTableId().getValue().intValue());
55 fibTableRequest.setIpv6(table.getAddressFamily().equals(Ipv6.class));
56 return fibTableRequest;