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 org.openvpp.jvpp.test;
19 import org.openvpp.jvpp.JVpp;
20 import org.openvpp.jvpp.JVppImpl;
21 import org.openvpp.jvpp.VppCallbackException;
22 import org.openvpp.jvpp.VppJNIConnection;
23 import org.openvpp.jvpp.callback.GetNodeIndexCallback;
24 import org.openvpp.jvpp.callback.ShowVersionCallback;
25 import org.openvpp.jvpp.callback.SwInterfaceCallback;
26 import org.openvpp.jvpp.dto.*;
28 public class CallbackApiTest {
30 private static class TestCallback implements GetNodeIndexCallback, ShowVersionCallback, SwInterfaceCallback {
33 public void onGetNodeIndexReply(final GetNodeIndexReply msg) {
34 System.out.printf("Received GetNodeIndexReply: context=%d, nodeIndex=%d\n",
35 msg.context, msg.nodeIndex);
38 public void onShowVersionReply(final ShowVersionReply msg) {
39 System.out.printf("Received ShowVersionReply: context=%d, program=%s, version=%s, " +
40 "buildDate=%s, buildDirectory=%s\n",
41 msg.context, new String(msg.program), new String(msg.version),
42 new String(msg.buildDate), new String(msg.buildDirectory));
46 public void onSwInterfaceDetails(final SwInterfaceDetails msg) {
47 System.out.printf("Received SwInterfaceDetails: interfaceName=%s, l2AddressLength=%d, adminUpDown=%d, " +
48 "linkUpDown=%d, linkSpeed=%d, linkMtu=%d\n",
49 new String(msg.interfaceName), msg.l2AddressLength, msg.adminUpDown,
50 msg.linkUpDown, msg.linkSpeed, (int)msg.linkMtu);
54 public void onError(VppCallbackException ex) {
55 System.out.printf("Received onError exception: call=%s, context=%d, retval=%d\n", ex.getMethodName(), ex.getCtxId(), ex.getErrorCode());
59 private static void testCallbackApi() throws Exception {
60 System.out.println("Testing Java callback API");
61 JVpp jvpp = new JVppImpl(new VppJNIConnection("CallbackApiTest"));
62 jvpp.connect(new TestCallback());
63 System.out.println("Successfully connected to VPP");
65 System.out.println("Sending ShowVersion request...");
66 jvpp.send(new ShowVersion());
68 System.out.println("Sending GetNodeIndex request...");
69 GetNodeIndex getNodeIndexRequest = new GetNodeIndex();
70 getNodeIndexRequest.nodeName = "node0".getBytes();
71 jvpp.send(getNodeIndexRequest);
73 System.out.println("Sending SwInterfaceDump request...");
74 SwInterfaceDump swInterfaceDumpRequest = new SwInterfaceDump();
75 swInterfaceDumpRequest.nameFilterValid = 0;
76 swInterfaceDumpRequest.nameFilter = "".getBytes();
77 jvpp.send(swInterfaceDumpRequest);
81 System.out.println("Disconnecting...");
86 public static void main(String[] args) throws Exception {