2 * Copyright (c) 2017 Cisco Systems, Inc. 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
8 package org.opendaylight.lispflowmapping.neutron.intenthandler.listener;
10 import com.google.common.base.Preconditions;
11 import java.util.Collection;
13 import java.util.concurrent.ConcurrentHashMap;
14 import org.checkerframework.checker.lock.qual.GuardedBy;
15 import org.opendaylight.mdsal.binding.api.ClusteredDataTreeChangeListener;
16 import org.opendaylight.mdsal.binding.api.DataBroker;
17 import org.opendaylight.mdsal.binding.api.DataObjectModification;
18 import org.opendaylight.mdsal.binding.api.DataTreeModification;
19 import org.opendaylight.mdsal.binding.api.MountPointService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vbridge.topology.rev160129.network.topology.topology.topology.types.VbridgeTopology;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
23 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 * Created by Shakib Ahmed on 1/19/17.
30 public class VbridgeTopologyListener implements ClusteredDataTreeChangeListener<VbridgeTopology>, AutoCloseable {
31 private static final Logger LOG = LoggerFactory.getLogger(VbridgeTopologyListener.class);
33 private final DataBroker dataBroker;
34 private final MountPointService mountPointService;
37 private final Map<TopologyKey, VppEndpointListener> domains = new ConcurrentHashMap<>();
39 public VbridgeTopologyListener(final DataBroker dataBroker,
40 final MountPointService mountPointService) {
41 this.dataBroker = Preconditions.checkNotNull(dataBroker);
42 this.mountPointService = Preconditions.checkNotNull(mountPointService);
46 public synchronized void onDataTreeChanged(Collection<DataTreeModification<VbridgeTopology>> changes) {
47 for (DataTreeModification<VbridgeTopology> topologyData : changes) {
48 final KeyedInstanceIdentifier<Topology, TopologyKey> topologyInstanceIdentifier =
49 (KeyedInstanceIdentifier<Topology, TopologyKey>) topologyData
52 .firstIdentifierOf(Topology.class);
54 Preconditions.checkArgument(!topologyInstanceIdentifier
55 .isWildcarded(), "Wildcard topology %s is not supported",
56 topologyInstanceIdentifier);
58 final DataObjectModification<VbridgeTopology> modification = topologyData.getRootNode();
60 switch (modification.getModificationType()) {
62 handleVbridgeTopologyDelete(topologyInstanceIdentifier);
65 handleVbridgeTopologyWrite(topologyInstanceIdentifier);
68 LOG.warn("Ignoring unhandled modification type {}", modification.getModificationType());
75 private void handleVbridgeTopologyDelete(KeyedInstanceIdentifier<Topology, TopologyKey> topology) {
76 VppEndpointListener endpointListener = domains.get(topology.getKey());
77 endpointListener.close();
78 domains.remove(topology.getKey());
81 private void handleVbridgeTopologyWrite(KeyedInstanceIdentifier<Topology, TopologyKey> topology) {
82 if (domains.containsKey(topology.getKey())) {
83 domains.get(topology.getKey()).close();
84 domains.remove(topology.getKey());
86 domains.put(topology.getKey(), new VppEndpointListener(dataBroker, mountPointService, topology));
91 domains.forEach((topologyKey, vppEndpointListener) -> {
92 vppEndpointListener.close();