a94e47c91334f1a620243dd1a0d49a983fa9e3c6
[hc2vpp.git] /
1 package io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump;
2
3
4 import static com.google.common.base.Preconditions.checkNotNull;
5
6 import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor;
7 import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException;
8 import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpCallFailedException;
9 import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpTimeoutException;
10 import io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.params.AddressDumpParams;
11 import io.fd.honeycomb.translate.v3po.util.ByteDataTranslator;
12 import io.fd.honeycomb.translate.v3po.util.JvppReplyConsumer;
13 import java.util.concurrent.TimeoutException;
14 import javax.annotation.Nonnull;
15 import org.openvpp.jvpp.VppBaseCallException;
16 import org.openvpp.jvpp.core.dto.IpAddressDetailsReplyDump;
17 import org.openvpp.jvpp.core.dto.IpAddressDump;
18 import org.openvpp.jvpp.core.future.FutureJVppCore;
19
20 public class AddressDumpExecutor
21         implements EntityDumpExecutor<IpAddressDetailsReplyDump, AddressDumpParams>, ByteDataTranslator,
22         JvppReplyConsumer {
23
24     private FutureJVppCore vppApi;
25
26     public AddressDumpExecutor(@Nonnull final FutureJVppCore vppApi) {
27         this.vppApi = checkNotNull(vppApi, "Vpp api refference cannot be null");
28     }
29
30     @Override
31     public IpAddressDetailsReplyDump executeDump(final AddressDumpParams params) throws DumpExecutionFailedException {
32         checkNotNull(params, "Address dump params cannot be null");
33
34         IpAddressDump dumpRequest = new IpAddressDump();
35         dumpRequest.isIpv6 = booleanToByte(params.isIpv6());
36         dumpRequest.swIfIndex = params.getInterfaceIndex();
37
38         try {
39             return getReply(vppApi.ipAddressDump(dumpRequest).toCompletableFuture());
40         } catch (TimeoutException e) {
41             throw DumpTimeoutException
42                     .wrapTimeoutException("Dumping or addresses ended in timeout[params : ]" + params, e);
43         } catch (VppBaseCallException e) {
44             throw DumpCallFailedException.wrapFailedCallException("Dumping of addresses failed[params : ]" + params, e);
45         }
46     }
47 }