Repair Doxygen build infrastructure
[vpp.git] / src / vpp-api / java / jvpp-core / io / fd / vpp / jvpp / core / test / CallbackApiTest.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.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.GetNodeIndexCallback;
25 import io.fd.vpp.jvpp.core.callback.ShowVersionCallback;
26 import io.fd.vpp.jvpp.core.callback.SwInterfaceCallback;
27 import io.fd.vpp.jvpp.core.dto.GetNodeIndex;
28 import io.fd.vpp.jvpp.core.dto.GetNodeIndexReply;
29 import io.fd.vpp.jvpp.core.dto.ShowVersion;
30 import io.fd.vpp.jvpp.core.dto.ShowVersionReply;
31 import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails;
32 import io.fd.vpp.jvpp.core.dto.SwInterfaceDump;
33
34 public class CallbackApiTest {
35
36     public static void main(String[] args) throws Exception {
37         testCallbackApi();
38     }
39
40     private static void testCallbackApi() throws Exception {
41         System.out.println("Testing Java callback API with JVppRegistry");
42         try (final JVppRegistry registry = new JVppRegistryImpl("CallbackApiTest");
43              final JVpp jvpp = new JVppCoreImpl()) {
44             registry.register(jvpp, new TestCallback());
45
46             System.out.println("Sending ShowVersion request...");
47             final int result = jvpp.send(new ShowVersion());
48             System.out.printf("ShowVersion send result = %d%n", result);
49
50             System.out.println("Sending GetNodeIndex request...");
51             GetNodeIndex getNodeIndexRequest = new GetNodeIndex();
52             getNodeIndexRequest.nodeName = "non-existing-node".getBytes();
53             jvpp.send(getNodeIndexRequest);
54
55             System.out.println("Sending SwInterfaceDump request...");
56             SwInterfaceDump swInterfaceDumpRequest = new SwInterfaceDump();
57             swInterfaceDumpRequest.nameFilterValid = 0;
58             swInterfaceDumpRequest.nameFilter = "".getBytes();
59             jvpp.send(swInterfaceDumpRequest);
60
61             Thread.sleep(1000);
62             System.out.println("Disconnecting...");
63         }
64         Thread.sleep(1000);
65     }
66
67     static class TestCallback implements GetNodeIndexCallback, ShowVersionCallback, SwInterfaceCallback {
68
69         @Override
70         public void onGetNodeIndexReply(final GetNodeIndexReply msg) {
71             System.out.printf("Received GetNodeIndexReply: %s%n", msg);
72         }
73
74         @Override
75         public void onShowVersionReply(final ShowVersionReply msg) {
76             System.out.printf("Received ShowVersionReply: context=%d, program=%s, version=%s, "
77                     + "buildDate=%s, buildDirectory=%s%n",
78                 msg.context, new String(msg.program), new String(msg.version),
79                 new String(msg.buildDate), new String(msg.buildDirectory));
80         }
81
82         @Override
83         public void onSwInterfaceDetails(final SwInterfaceDetails msg) {
84             System.out.printf("Received SwInterfaceDetails: interfaceName=%s, l2AddressLength=%d, adminUpDown=%d, "
85                     + "linkUpDown=%d, linkSpeed=%d, linkMtu=%d%n",
86                 new String(msg.interfaceName), msg.l2AddressLength, msg.adminUpDown,
87                 msg.linkUpDown, msg.linkSpeed, (int) msg.linkMtu);
88         }
89
90         @Override
91         public void onError(VppCallbackException ex) {
92             System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(),
93                 ex.getCtxId(), ex.getErrorCode());
94         }
95     }
96 }