2 * Copyright (c) 2016 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.openvpp.jvpp.test;
19 import org.openvpp.jvpp.JVpp;
20 import org.openvpp.jvpp.JVppImpl;
21 import org.openvpp.jvpp.VppCallbackException;
22 import org.openvpp.jvpp.VppJNIConnection;
23 import org.openvpp.jvpp.callback.WantInterfaceEventsCallback;
24 import org.openvpp.jvpp.callfacade.CallbackJVppFacade;
25 import org.openvpp.jvpp.dto.WantInterfaceEventsReply;
27 public class CallbackJVppFacadeNotificationTest {
29 private static void testCallbackFacade() throws Exception {
30 System.out.println("Testing CallbackJVppFacade for notifications");
32 JVpp jvpp = new JVppImpl(new VppJNIConnection("CallbackApiTest"));
34 CallbackJVppFacade jvppCallbackFacade = new CallbackJVppFacade(jvpp);
35 System.out.println("Successfully connected to VPP");
37 final AutoCloseable notificationListenerReg =
38 jvppCallbackFacade.getNotificationRegistry().registerSwInterfaceSetFlagsNotificationCallback(
39 NotificationUtils::printNotification
42 jvppCallbackFacade.wantInterfaceEvents(NotificationUtils.getEnableInterfaceNotificationsReq(),
43 new WantInterfaceEventsCallback() {
45 public void onWantInterfaceEventsReply(final WantInterfaceEventsReply reply) {
46 System.out.println("Interface events started");
50 public void onError(final VppCallbackException ex) {
51 System.out.printf("Received onError exception: call=%s, context=%d, retval=%d\n",
52 ex.getMethodName(), ex.getCtxId(), ex.getErrorCode());
56 System.out.println("Changing interface configuration");
57 NotificationUtils.getChangeInterfaceState().send(jvpp);
61 jvppCallbackFacade.wantInterfaceEvents(NotificationUtils.getDisableInterfaceNotificationsReq(),
62 new WantInterfaceEventsCallback() {
64 public void onWantInterfaceEventsReply(final WantInterfaceEventsReply reply) {
65 System.out.println("Interface events stopped");
69 public void onError(final VppCallbackException ex) {
70 System.out.printf("Received onError exception: call=%s, context=%d, retval=%d\n",
71 ex.getMethodName(), ex.getCtxId(), ex.getErrorCode());
75 notificationListenerReg.close();
79 System.out.println("Disconnecting...");
84 public static void main(String[] args) throws Exception {