2 * Copyright (c) 2018 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.examples;
19 import io.fd.vpp.jvpp.JVpp;
20 import io.fd.vpp.jvpp.JVppRegistry;
21 import io.fd.vpp.jvpp.JVppRegistryImpl;
22 import io.fd.vpp.jvpp.VppCallbackException;
23 import io.fd.vpp.jvpp.core.JVppCoreImpl;
24 import io.fd.vpp.jvpp.core.callback.CliInbandReplyCallback;
25 import io.fd.vpp.jvpp.core.dto.CliInband;
26 import io.fd.vpp.jvpp.core.dto.CliInbandReply;
28 import java.nio.charset.StandardCharsets;
30 public class CallbackCliApiExample {
32 public static void main(String[] args) throws Exception {
36 private static void testCallbackApi() throws Exception {
37 System.out.println("Testing Java callback API for Cli with JVppRegistry");
38 try (final JVppRegistry registry = new JVppRegistryImpl("CallbackCliApiExample");
39 final JVpp jvpp = new JVppCoreImpl()) {
40 registry.register(jvpp, new TestCallback());
42 System.out.println("Sending CliInband request...");
43 CliInband req = new CliInband();
44 req.cmd = "create loopback interface";
45 final int result = jvpp.send(req);
46 System.out.printf("CliInband send result = %d%n", result);
49 System.out.println("Disconnecting...");
54 static class TestCallback implements CliInbandReplyCallback {
57 public void onCliInbandReply(final CliInbandReply msg) {
58 System.out.printf("Received CliInbandReply: context=%d, reply=%s", msg.context, msg.reply);
62 public void onError(VppCallbackException ex) {
63 System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(),
64 ex.getCtxId(), ex.getErrorCode());