Repair Doxygen build infrastructure
[vpp.git] / src / vpp-api / java / jvpp-core / io / fd / vpp / jvpp / core / test / CallbackNotificationApiTest.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 static io.fd.vpp.jvpp.core.test.NotificationUtils.getChangeInterfaceState;
20 import static io.fd.vpp.jvpp.core.test.NotificationUtils.getDisableInterfaceNotificationsReq;
21 import static io.fd.vpp.jvpp.core.test.NotificationUtils.getEnableInterfaceNotificationsReq;
22 import static io.fd.vpp.jvpp.core.test.NotificationUtils.printNotification;
23
24 import io.fd.vpp.jvpp.JVpp;
25 import io.fd.vpp.jvpp.JVppRegistry;
26 import io.fd.vpp.jvpp.JVppRegistryImpl;
27 import io.fd.vpp.jvpp.VppCallbackException;
28 import io.fd.vpp.jvpp.core.JVppCoreImpl;
29 import io.fd.vpp.jvpp.core.callback.SwInterfaceSetFlagsCallback;
30 import io.fd.vpp.jvpp.core.callback.SwInterfaceSetFlagsNotificationCallback;
31 import io.fd.vpp.jvpp.core.callback.WantInterfaceEventsCallback;
32 import io.fd.vpp.jvpp.core.dto.SwInterfaceSetFlagsNotification;
33 import io.fd.vpp.jvpp.core.dto.SwInterfaceSetFlagsReply;
34 import io.fd.vpp.jvpp.core.dto.WantInterfaceEventsReply;
35
36 public class CallbackNotificationApiTest {
37
38     private static void testCallbackApi() throws Exception {
39         System.out.println("Testing Java callback API for notifications");
40         try (final JVppRegistry registry = new JVppRegistryImpl("CallbackNotificationTest");
41              final JVpp jvpp = new JVppCoreImpl()) {
42             registry.register(jvpp, new TestCallback());
43             System.out.println("Successfully connected to VPP");
44
45             getEnableInterfaceNotificationsReq().send(jvpp);
46             System.out.println("Interface notifications started");
47             // TODO test ifc dump which also triggers interface flags send
48
49             System.out.println("Changing interface configuration");
50             getChangeInterfaceState().send(jvpp);
51
52             // Notifications are received
53             Thread.sleep(500);
54
55             getDisableInterfaceNotificationsReq().send(jvpp);
56             System.out.println("Interface events stopped");
57
58             Thread.sleep(2000);
59             System.out.println("Disconnecting...");
60         }
61         Thread.sleep(1000);
62     }
63
64     public static void main(String[] args) throws Exception {
65         testCallbackApi();
66     }
67
68     private static class TestCallback implements SwInterfaceSetFlagsNotificationCallback,
69         WantInterfaceEventsCallback, SwInterfaceSetFlagsCallback {
70
71         @Override
72         public void onSwInterfaceSetFlagsNotification(
73             final SwInterfaceSetFlagsNotification msg) {
74             printNotification(msg);
75         }
76
77         @Override
78         public void onWantInterfaceEventsReply(final WantInterfaceEventsReply wantInterfaceEventsReply) {
79             System.out.println("Interface notification stream updated");
80         }
81
82         @Override
83         public void onSwInterfaceSetFlagsReply(final SwInterfaceSetFlagsReply swInterfaceSetFlagsReply) {
84             System.out.println("Interface flags set successfully");
85         }
86
87         @Override
88         public void onError(VppCallbackException ex) {
89             System.out.printf("Received onError exception in getNodeIndexCallback: call=%s, reply=%d, context=%d%n",
90                 ex.getMethodName(), ex.getErrorCode(), ex.getCtxId());
91
92         }
93     }
94 }