2 * Copyright (c) 2016, 2017 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.genius.interfacemanager.listeners;
11 import java.util.Collection;
12 import javax.annotation.PreDestroy;
13 import javax.inject.Inject;
14 import javax.inject.Singleton;
15 import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
18 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
19 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
20 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
21 import org.opendaylight.genius.interfacemanager.commons.InterfaceManagerCommonUtils;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
24 import org.opendaylight.yangtools.concepts.ListenerRegistration;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 * This class listens for interface creation/removal/update in Configuration DS.
31 * This is used to handle interfaces for base of-ports.
34 public class CacheInterfaceConfigListener implements ClusteredDataTreeChangeListener<Interface> {
35 private static final Logger LOG = LoggerFactory.getLogger(CacheInterfaceConfigListener.class);
36 private final ListenerRegistration<CacheInterfaceConfigListener> registration;
37 private final DataTreeIdentifier<Interface> treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
41 public CacheInterfaceConfigListener(final DataBroker dataBroker) {
42 LOG.trace("Registering on path: {}", treeId);
43 registration = dataBroker.registerDataTreeChangeListener(treeId, CacheInterfaceConfigListener.this);
48 if (registration != null) {
53 protected InstanceIdentifier<Interface> getWildcardPath() {
54 return InstanceIdentifier.create(Interfaces.class).child(Interface.class);
58 public void onDataTreeChanged(Collection<DataTreeModification<Interface>> changes) {
59 for (DataTreeModification<Interface> change : changes) {
60 final InstanceIdentifier<Interface> key = change.getRootPath().getRootIdentifier();
61 final DataObjectModification<Interface> mod = change.getRootNode();
62 switch (mod.getModificationType()) {
64 InterfaceManagerCommonUtils.removeFromInterfaceCache(mod.getDataBefore());
66 case SUBTREE_MODIFIED:
68 InterfaceManagerCommonUtils.addInterfaceToCache(mod.getDataAfter());
71 throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());