2 * Copyright (c) 2016 Cisco 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.vpp.jvpp.core.test;
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;
39 public class FutureApiTest {
41 private static final Logger LOG = Logger.getLogger(FutureApiTest.class.getName());
43 public static void main(String[] args) throws Exception {
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");
53 testEmptyBridgeDomainDump(jvppFacade);
55 LOG.info("Disconnecting...");
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
64 final CompletableFuture<BridgeDomainDetailsReplyDump>
65 replyFuture = jvpp.bridgeDomainDump(request).toCompletableFuture();
66 final BridgeDomainDetailsReplyDump reply = replyFuture.get();
68 if (reply == null || reply.bridgeDomainDetails == null) {
69 throw new IllegalStateException("Received null response for empty dump: " + reply);
73 "Received bridge-domain dump reply with list of bridge-domains: %s",
74 reply.bridgeDomainDetails));