1 package org.opendaylight.vpnservice;
3 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
4 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
5 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
6 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
7 import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
8 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
9 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
10 import org.opendaylight.yangtools.concepts.ListenerRegistration;
11 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
12 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
16 public class InterfaceChangeListener extends AbstractDataChangeListener<Interface> implements AutoCloseable {
17 private static final Logger LOG = LoggerFactory.getLogger(InterfaceChangeListener.class);
19 private ListenerRegistration<DataChangeListener> listenerRegistration;
20 private final DataBroker broker;
21 private VpnInterfaceManager vpnInterfaceManager;
24 public InterfaceChangeListener(final DataBroker db, VpnInterfaceManager vpnInterfaceManager) {
25 super(Interface.class);
27 this.vpnInterfaceManager = vpnInterfaceManager;
32 public void close() throws Exception {
33 if (listenerRegistration != null) {
35 listenerRegistration.close();
36 } catch (final Exception e) {
37 LOG.error("Error when cleaning up DataChangeListener.", e);
39 listenerRegistration = null;
41 LOG.info("Interface listener Closed");
45 private void registerListener(final DataBroker db) {
47 listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
48 getWildCardPath(), InterfaceChangeListener.this, DataChangeScope.SUBTREE);
49 } catch (final Exception e) {
50 LOG.error("Interface DataChange listener registration failed", e);
51 throw new IllegalStateException("Nexthop Manager registration Listener failed.", e);
56 protected void add(InstanceIdentifier<Interface> identifier, Interface intrf) {
57 LOG.trace("Adding Interface : key: " + identifier + ", value=" + intrf );
62 private InstanceIdentifier<Interface> getWildCardPath() {
63 return InstanceIdentifier.create(Interfaces.class).child(Interface.class);
67 protected void remove(InstanceIdentifier<Interface> identifier, Interface intrf) {
68 LOG.trace("Remove interface event - key: {}, value: {}", identifier, intrf );
69 VpnInterface vpnInterface = vpnInterfaceManager.getVpnInterface(intrf.getName());
70 InstanceIdentifier<VpnInterface> id = VpnUtil.getVpnInterfaceIdentifier(intrf.getName());
71 LOG.debug("Removing VPN Interface associated with Interface {}", intrf.getName());
72 vpnInterfaceManager.remove(id, vpnInterface);
76 protected void update(InstanceIdentifier<Interface> identifier,
77 Interface original, Interface update) {
78 // TODO Auto-generated method stub