74b8dc7683af8ff86fc6701142b4af43ae7a9860
[hc2vpp.git] /
1 /*
2  * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17
18 package io.fd.hc2vpp.fib.management.write;
19
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.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv6;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.Table;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableKey;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31
32 class FibTableCustomizer extends FutureJVppCustomizer implements ListWriterCustomizer<Table, TableKey> {
33     FibTableCustomizer(@Nonnull final FutureJVppCore vppApi) {
34         super(vppApi);
35     }
36
37     @Override
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);
42     }
43
44     @Override
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);
49     }
50
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;
57     }
58 }