Merge "BUG-4117: add support of Old Notif. for Statistics"
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginTestNodeConnectorNotification.java
1 /**
2  * Copyright (c) 2014, 2015 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.openflowplugin.test;
9
10 import java.util.ArrayList;
11 import java.util.List;
12
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
15 import org.opendaylight.controller.sal.binding.api.NotificationService;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.OpendaylightInventoryListener;
21 import org.opendaylight.yangtools.concepts.Registration;
22 import org.osgi.framework.BundleContext;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 public class OpenflowpluginTestNodeConnectorNotification {
27
28     private static final Logger LOG = LoggerFactory.getLogger(OpenflowpluginTestNodeConnectorNotification.class);
29
30     private DataBroker dataBroker;
31     private ProviderContext pc;
32     private final BundleContext ctx;
33     private final PortEventListener portEventListener = new PortEventListener();
34     private static NotificationService notificationService;
35     private Registration listenerReg;
36
37     public OpenflowpluginTestNodeConnectorNotification(BundleContext ctx) {
38         this.ctx = ctx;
39     }
40
41     public void onSessionInitiated(ProviderContext session) {
42         pc = session;
43         notificationService = session.getSALService(NotificationService.class);
44         // For switch events
45         listenerReg = notificationService.registerNotificationListener(portEventListener);
46         dataBroker = session.getSALService(DataBroker.class);
47     }
48
49     final class PortEventListener implements OpendaylightInventoryListener {
50
51         List<NodeUpdated> nodeUpdated = new ArrayList<>();
52         List<NodeRemoved> nodeRemoved = new ArrayList<>();
53         List<NodeConnectorUpdated> nodeConnectorUpdated = new ArrayList<>();
54         List<NodeConnectorRemoved> nodeConnectorRemoved = new ArrayList<>();
55
56         @Override
57         public void onNodeConnectorRemoved(NodeConnectorRemoved notification) {
58             LOG.debug("NodeConnectorRemoved Notification ...................");
59             LOG.debug("NodeConnectorRef " + notification.getNodeConnectorRef());
60             LOG.debug("----------------------------------------------------------------------");
61             nodeConnectorRemoved.add(notification);
62         }
63
64         @Override
65         public void onNodeConnectorUpdated(NodeConnectorUpdated notification) {
66             LOG.debug("NodeConnectorUpdated Notification...................");
67             LOG.debug("NodeConnectorRef " + notification.getNodeConnectorRef());
68             LOG.debug("----------------------------------------------------------------------");
69             nodeConnectorUpdated.add(notification);
70         }
71
72         @Override
73         public void onNodeRemoved(NodeRemoved notification) {
74             LOG.debug("NodeRemoved Notification ...................");
75             LOG.debug("NodeRef " + notification.getNodeRef());
76             LOG.debug("----------------------------------------------------------------------");
77             nodeRemoved.add(notification);
78         }
79
80         @Override
81         public void onNodeUpdated(NodeUpdated notification) {
82             LOG.debug("NodeUpdated Notification ...................");
83             LOG.debug("NodeRef " + notification.getNodeRef());
84             LOG.debug("----------------------------------------------------------------------");
85             nodeUpdated.add(notification);
86         }
87     }
88 }