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.InterfaceMetaUtils;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.BridgeRefInfo;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.bridge.ref.info.BridgeRefEntry;
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 bridgeRefEntry creation/removal/update in Operational
31 * DS and update the bridgeRefEntryCache as per changes in DS.
35 public class CacheBridgeRefEntryListener implements ClusteredDataTreeChangeListener<BridgeRefEntry> {
36 private static final Logger LOG = LoggerFactory.getLogger(CacheBridgeRefEntryListener.class);
38 private final ListenerRegistration<CacheBridgeRefEntryListener> registration;
39 private final DataTreeIdentifier<BridgeRefEntry> treeId = new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
43 public CacheBridgeRefEntryListener(DataBroker dataBroker) {
44 LOG.trace("Registering on path: {}", treeId);
45 registration = dataBroker.registerDataTreeChangeListener(treeId, CacheBridgeRefEntryListener.this);
50 if (registration != null) {
55 protected InstanceIdentifier<BridgeRefEntry> getWildcardPath() {
56 return InstanceIdentifier.create(BridgeRefInfo.class).child(BridgeRefEntry.class);
60 public void onDataTreeChanged(Collection<DataTreeModification<BridgeRefEntry>> changes) {
61 for (DataTreeModification<BridgeRefEntry> change : changes) {
62 final DataObjectModification<BridgeRefEntry> mod = change.getRootNode();
63 switch (mod.getModificationType()) {
66 * Note: Do we want to retain entry in cache? Ref Entry missing
67 * means OVS being disconnected for now. It will either come
68 * back, or will require config to be deleted.
70 * Removing for now, can consider this as future optimization.
73 InterfaceMetaUtils.removeFromBridgeRefEntryCache(mod.getDataBefore());
75 case SUBTREE_MODIFIED:
77 InterfaceMetaUtils.addBridgeRefEntryToCache(mod.getDataAfter());
80 throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());