2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
9 package org.opendaylight.netvirt.dhcpservice;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
13 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.genius.mdsalutil.AbstractDataChangeListener;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs;
21 import org.opendaylight.yangtools.concepts.ListenerRegistration;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class DhcpInterfaceConfigListener extends AbstractDataChangeListener<Interface> implements AutoCloseable {
28 private static final Logger logger = LoggerFactory.getLogger(DhcpInterfaceConfigListener.class);
30 private ListenerRegistration<DataChangeListener> listenerRegistration;
32 private final DataBroker dataBroker;
33 private final DhcpExternalTunnelManager dhcpExternalTunnelManager;
35 public DhcpInterfaceConfigListener(DataBroker dataBroker, DhcpExternalTunnelManager dhcpExternalTunnelManager) {
36 super(Interface.class);
37 this.dataBroker = dataBroker;
38 this.dhcpExternalTunnelManager = dhcpExternalTunnelManager;
45 private void registerListener() {
47 listenerRegistration = dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
48 getWildCardPath(), DhcpInterfaceConfigListener.this, DataChangeScope.SUBTREE);
49 } catch (final Exception e) {
50 logger.error("DhcpInterfaceEventListener DataChange listener registration fail!", e);
51 throw new IllegalStateException("DhcpInterfaceEventListener registration Listener failed.", e);
55 private InstanceIdentifier<Interface> getWildCardPath() {
56 return InstanceIdentifier.create(Interfaces.class).child(Interface.class);
60 public void close() throws Exception {
61 if (listenerRegistration != null) {
62 listenerRegistration.close();
64 logger.info("DhcpInterfaceConfigListener Closed");
68 protected void remove(InstanceIdentifier<Interface> identifier, Interface del) {
69 IfTunnel tunnelInterface = del.getAugmentation(IfTunnel.class);
70 if (tunnelInterface != null && !tunnelInterface.isInternal()) {
71 IpAddress tunnelIp = tunnelInterface.getTunnelDestination();
72 ParentRefs interfce = del.getAugmentation(ParentRefs.class);
73 if (interfce != null) {
74 dhcpExternalTunnelManager.handleTunnelStateDown(tunnelIp, interfce.getDatapathNodeIdentifier());
80 protected void update(InstanceIdentifier<Interface> identifier, Interface original, Interface update) {
81 // Handled in update () DhcpInterfaceEventListener
85 protected void add(InstanceIdentifier<Interface> identifier, Interface add) {
86 // Handled in add() DhcpInterfaceEventListener