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;
16 import org.apache.aries.blueprint.annotation.service.Reference;
17 import org.opendaylight.genius.interfacemanager.commons.InterfaceMetaUtils;
18 import org.opendaylight.mdsal.binding.api.ClusteredDataTreeChangeListener;
19 import org.opendaylight.mdsal.binding.api.DataBroker;
20 import org.opendaylight.mdsal.binding.api.DataObjectModification;
21 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
22 import org.opendaylight.mdsal.binding.api.DataTreeModification;
23 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.BridgeRefInfo;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.bridge.ref.info.BridgeRefEntry;
26 import org.opendaylight.yangtools.concepts.ListenerRegistration;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * This class listens for bridgeRefEntry creation/removal/update in Operational
33 * DS and update the bridgeRefEntryCache as per changes in DS.
37 public class CacheBridgeRefEntryListener implements ClusteredDataTreeChangeListener<BridgeRefEntry> {
38 private static final Logger LOG = LoggerFactory.getLogger(CacheBridgeRefEntryListener.class);
40 private final InterfaceMetaUtils interfaceMetaUtils;
41 private final ListenerRegistration<CacheBridgeRefEntryListener> registration;
42 private final DataTreeIdentifier<BridgeRefEntry> treeId =
43 DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
44 InstanceIdentifier.create(BridgeRefInfo.class).child(BridgeRefEntry.class));
47 public CacheBridgeRefEntryListener(@Reference DataBroker dataBroker, InterfaceMetaUtils interfaceMetaUtils) {
48 LOG.trace("Registering on path: {}", treeId);
49 this.interfaceMetaUtils = interfaceMetaUtils;
50 registration = dataBroker.registerDataTreeChangeListener(treeId, CacheBridgeRefEntryListener.this);
55 if (registration != null) {
61 public void onDataTreeChanged(Collection<DataTreeModification<BridgeRefEntry>> changes) {
62 for (DataTreeModification<BridgeRefEntry> change : changes) {
63 final DataObjectModification<BridgeRefEntry> mod = change.getRootNode();
64 switch (mod.getModificationType()) {
67 * Note: Do we want to retain entry in cache? Ref Entry missing
68 * means OVS being disconnected for now. It will either come
69 * back, or will require config to be deleted.
71 * Removing for now, can consider this as future optimization.
74 if (mod.getDataBefore() != null) {
75 interfaceMetaUtils.removeFromBridgeRefEntryCache(mod.getDataBefore());
78 case SUBTREE_MODIFIED:
80 interfaceMetaUtils.addBridgeRefEntryToCache(mod.getDataAfter());
83 throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());