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.
17 package io.fd.hc2vpp.fib.management.request;
19 import static com.google.common.base.Preconditions.checkArgument;
20 import static com.google.common.base.Preconditions.checkNotNull;
22 import io.fd.hc2vpp.common.translate.util.AddressTranslator;
23 import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
24 import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
25 import io.fd.honeycomb.translate.write.WriteFailedException;
26 import io.fd.vpp.jvpp.core.dto.IpTableAddDel;
27 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
28 import java.nio.charset.StandardCharsets;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 public class FibTableRequest implements AddressTranslator, JvppReplyConsumer {
33 private final FutureJVppCore api;
37 private String fibName;
40 * FIB table id to be installed
45 * Whether to write IPv6 FIB table or IPv4
47 private boolean isIpv6;
49 public FibTableRequest(FutureJVppCore api) {
53 public void checkValid() {
54 checkNotNull(getFibName(), "Fib table name not set");
55 checkArgument(!getFibName().isEmpty(), "Fib table name must not be empty");
58 public void write(InstanceIdentifier<?> identifier) throws WriteFailedException {
59 sendRequest(identifier, ByteDataTranslator.BYTE_TRUE);
62 public void delete(InstanceIdentifier<?> identifier) throws WriteFailedException {
63 sendRequest(identifier, ByteDataTranslator.BYTE_FALSE);
66 private void sendRequest(final InstanceIdentifier<?> identifier, final byte isAdd)
67 throws WriteFailedException {
68 IpTableAddDel tableAddDel = new IpTableAddDel();
69 tableAddDel.tableId = getFibTable();
70 tableAddDel.isIpv6 = booleanToByte(isIpv6());
71 tableAddDel.isAdd = isAdd;
72 if (getFibName() != null) {
73 // FIB table name is optional
74 tableAddDel.name = getFibName().getBytes(StandardCharsets.UTF_8);
76 getReplyForWrite(api.ipTableAddDel(tableAddDel).toCompletableFuture(), identifier);
79 public int getFibTable() {
83 public void setFibTable(int fibTable) {
84 this.fibTable = fibTable;
87 public boolean isIpv6() {
91 public void setIpv6(boolean ipv6) {
95 public String getFibName() {
99 public void setFibName(String fibName) {
100 this.fibName = fibName;