Fix vpp-plugins rpms
[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.JVppIoamtraceImpl;
24 import io.fd.vpp.jvpp.ioamtrace.callback.TraceProfileAddCallback;
25 import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAdd;
26 import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAddReply;
27
28 public class ioamTraceApiTest {
29
30
31     static class ioamTraceTestCallback implements TraceProfileAddCallback {
32
33         @Override
34         public void onTraceProfileAddReply(final TraceProfileAddReply reply) {
35             System.out.printf("Received TraceProfileAddReply reply: context=%d%n",
36                 reply.context);
37         }
38
39         @Override
40         public void onError(VppCallbackException ex) {
41             System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(),
42                 ex.getCtxId(), ex.getErrorCode());
43         }
44     }
45
46     public static void main(String[] args) throws Exception {
47         ioamTraceTestApi();
48     }
49
50     private static void ioamTraceTestApi() throws Exception {
51
52         System.out.println("Testing Java API for ioam trace plugin");
53         final JVppRegistry registry = new JVppRegistryImpl("ioamTraceApiTest");
54         final JVpp jvpp = new JVppIoamtraceImpl();
55
56         registry.register(jvpp, new ioamTraceTestCallback());
57         try{
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         finally {
71             System.out.println("Disconnecting...");
72             registry.close();
73             Thread.sleep(1000);
74         }
75     }
76 }