docs: change code blocks from "shell" to "console"
[vpp.git] / extras / japi / java / jvpp-ioampot / io / fd / vpp / jvpp / ioampot / examples / IoamPotApiExample.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.ioampot.examples;
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.ioampot.JVppIoampotImpl;
24 import io.fd.vpp.jvpp.ioampot.callback.PotProfileAddReplyCallback;
25 import io.fd.vpp.jvpp.ioampot.dto.PotProfileAdd;
26 import io.fd.vpp.jvpp.ioampot.dto.PotProfileAddReply;
27 import java.nio.charset.StandardCharsets;
28
29 public class IoamPotApiExample {
30
31     static class IoamPotTestCallback implements PotProfileAddReplyCallback {
32
33         @Override
34         public void onPotProfileAddReply(final PotProfileAddReply reply) {
35             System.out.printf("Received PotProfileAddReply 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         ioamPotTestApi();
48     }
49
50     private static void ioamPotTestApi() throws Exception {
51         System.out.println("Testing Java API for ioam pot plugin");
52         try (final JVppRegistry registry = new JVppRegistryImpl("ioamPotApiExample");
53              final JVpp jvpp = new JVppIoampotImpl()) {
54             registry.register(jvpp, new IoamPotTestCallback());
55
56             System.out.println("Sending ioam pot profile add request...");
57             PotProfileAdd request = new PotProfileAdd();
58             request.id = 0;
59             request.validator = 4;
60             request.secretKey = 1;
61             request.secretShare = 2;
62             request.prime = 1234;
63             request.maxBits = 53;
64             request.lpc = 1234;
65             request.polynomialPublic = 1234;
66             request.listNameLen = (byte)"test pot profile".getBytes(StandardCharsets.UTF_8).length;
67             request.listName = "test pot profile".getBytes(StandardCharsets.UTF_8);
68             final int result = jvpp.send(request);
69             System.out.printf("PotProfileAdd send result = %d%n", result);
70
71             Thread.sleep(1000);
72
73             System.out.println("Disconnecting...");
74         }
75     }
76 }