summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/dump/AddressDumpExecutor.java
blob: a94e47c91334f1a620243dd1a0d49a983fa9e3c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump;


import static com.google.common.base.Preconditions.checkNotNull;

import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor;
import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException;
import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpCallFailedException;
import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpTimeoutException;
import io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.params.AddressDumpParams;
import io.fd.honeycomb.translate.v3po.util.ByteDataTranslator;
import io.fd.honeycomb.translate.v3po.util.JvppReplyConsumer;
import java.util.concurrent.TimeoutException;
import javax.annotation.Nonnull;
import org.openvpp.jvpp.VppBaseCallException;
import org.openvpp.jvpp.core.dto.IpAddressDetailsReplyDump;
import org.openvpp.jvpp.core.dto.IpAddressDump;
import org.openvpp.jvpp.core.future.FutureJVppCore;

public class AddressDumpExecutor
        implements EntityDumpExecutor<IpAddressDetailsReplyDump, AddressDumpParams>, ByteDataTranslator,
        JvppReplyConsumer {

    private FutureJVppCore vppApi;

    public AddressDumpExecutor(@Nonnull final FutureJVppCore vppApi) {
        this.vppApi = checkNotNull(vppApi, "Vpp api refference cannot be null");
    }

    @Override
    public IpAddressDetailsReplyDump executeDump(final AddressDumpParams params) throws DumpExecutionFailedException {
        checkNotNull(params, "Address dump params cannot be null");

        IpAddressDump dumpRequest = new IpAddressDump();
        dumpRequest.isIpv6 = booleanToByte(params.isIpv6());
        dumpRequest.swIfIndex = params.getInterfaceIndex();

        try {
            return getReply(vppApi.ipAddressDump(dumpRequest).toCompletableFuture());
        } catch (TimeoutException e) {
            throw DumpTimeoutException
                    .wrapTimeoutException("Dumping or addresses ended in timeout[params : ]" + params, e);
        } catch (VppBaseCallException e) {
            throw DumpCallFailedException.wrapFailedCallException("Dumping of addresses failed[params : ]" + params, e);
        }
    }
}