Move java api to extras/
[vpp.git] / extras / japi / java / jvpp-core / io / fd / vpp / jvpp / core / test / FutureApiTest.java
1 /*
2  * Copyright (c) 2016 Cisco 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 package io.fd.vpp.jvpp.core.test;
18
19 import io.fd.vpp.jvpp.JVppRegistry;
20 import io.fd.vpp.jvpp.JVppRegistryImpl;
21 import io.fd.vpp.jvpp.core.JVppCoreImpl;
22 import io.fd.vpp.jvpp.core.dto.BridgeDomainDetailsReplyDump;
23 import io.fd.vpp.jvpp.core.dto.BridgeDomainDump;
24 import io.fd.vpp.jvpp.core.dto.GetNodeIndex;
25 import io.fd.vpp.jvpp.core.dto.GetNodeIndexReply;
26 import io.fd.vpp.jvpp.core.dto.ShowVersion;
27 import io.fd.vpp.jvpp.core.dto.ShowVersionReply;
28 import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails;
29 import io.fd.vpp.jvpp.core.dto.SwInterfaceDetailsReplyDump;
30 import io.fd.vpp.jvpp.core.dto.SwInterfaceDump;
31 import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade;
32 import java.nio.charset.StandardCharsets;
33 import java.util.Objects;
34 import java.util.concurrent.CompletableFuture;
35 import java.util.concurrent.Future;
36 import java.util.logging.Level;
37 import java.util.logging.Logger;
38
39 public class FutureApiTest {
40
41     private static final Logger LOG = Logger.getLogger(FutureApiTest.class.getName());
42
43     public static void main(String[] args) throws Exception {
44         testFutureApi(args);
45     }
46
47     private static void testFutureApi(String[] args) throws Exception {
48         LOG.info("Testing Java future API for core plugin");
49         try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiTest", args[0]);
50              final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, new JVppCoreImpl())) {
51             LOG.info("Successfully connected to VPP");
52
53             testEmptyBridgeDomainDump(jvppFacade);
54
55             LOG.info("Disconnecting...");
56         }
57     }
58
59     private static void testEmptyBridgeDomainDump(final FutureJVppCoreFacade jvpp) throws Exception {
60         LOG.info("Sending BridgeDomainDump request...");
61         final BridgeDomainDump request = new BridgeDomainDump();
62         request.bdId = -1; // dump call
63
64         final CompletableFuture<BridgeDomainDetailsReplyDump>
65             replyFuture = jvpp.bridgeDomainDump(request).toCompletableFuture();
66         final BridgeDomainDetailsReplyDump reply = replyFuture.get();
67
68         if (reply == null || reply.bridgeDomainDetails == null) {
69             throw new IllegalStateException("Received null response for empty dump: " + reply);
70         } else {
71             LOG.info(
72                 String.format(
73                     "Received bridge-domain dump reply with list of bridge-domains: %s",
74                     reply.bridgeDomainDetails));
75         }
76     }
77
78
79 }