Repair Doxygen build infrastructure
[vpp.git] / plugins / ioam-plugin / ioam / jvpp / io / fd / vpp / jvpp / ioamtrace / test / IoamTraceApiTest.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.ioamtrace.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.ioamtrace.future.FutureJVppIoamtraceFacade;
24 import io.fd.vpp.jvpp.ioamtrace.JVppIoamtraceImpl;
25 import io.fd.vpp.jvpp.ioamtrace.callback.TraceProfileAddCallback;
26 import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAdd;
27 import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAddReply;
28 import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileShowConfig;
29 import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileShowConfigReply;
30
31 public class IoamTraceApiTest {
32
33     static class IoamTraceTestCallback implements TraceProfileAddCallback {
34
35         @Override
36         public void onTraceProfileAddReply(final TraceProfileAddReply reply) {
37             System.out.printf("Received TraceProfileAddReply reply: context=%d%n",
38                 reply.context);
39         }
40
41         @Override
42         public void onError(VppCallbackException ex) {
43             System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(),
44                 ex.getCtxId(), ex.getErrorCode());
45         }
46     }
47
48     public static void main(String[] args) throws Exception {
49         ioamTraceTestApi();
50     }
51
52     private static void ioamTraceTestApi() throws Exception {
53         System.out.println("Testing Java API for ioam trace plugin");
54         try (final JVppRegistry registry = new JVppRegistryImpl("ioamTraceApiTest");
55              final JVpp jvpp = new JVppIoamtraceImpl()) {
56             FutureJVppIoamtraceFacade ioamtraceJvpp = new FutureJVppIoamtraceFacade(registry,jvpp);
57
58             System.out.println("Sending ioam trace profile add request...");
59             TraceProfileAdd request = new TraceProfileAdd();
60             request.traceType = 0x1f;
61             request.numElts = 4;
62             request.nodeId = 1;
63             request.traceTsp = 2;
64             request.appData = 1234;
65             final int result = jvpp.send(request);
66             System.out.printf("TraceProfileAdd send result = %d%n", result);
67
68             Thread.sleep(1000);
69
70             TraceProfileShowConfig showRequest = new TraceProfileShowConfig();
71             TraceProfileShowConfigReply reply = ioamtraceJvpp.traceProfileShowConfig(showRequest).toCompletableFuture().get();
72             System.out.printf("TraceProfileShowConfig result = "+ reply.toString());
73
74             System.out.println("Disconnecting...");
75         }
76     }
77 }