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 javax.annotation.Nonnull;
15 import org.checkerframework.checker.lock.qual.GuardedBy;
16 import org.opendaylight.mdsal.binding.api.ClusteredDataTreeChangeListener;
17 import org.opendaylight.mdsal.binding.api.DataBroker;
18 import org.opendaylight.mdsal.binding.api.DataObjectModification;
19 import org.opendaylight.mdsal.binding.api.DataTreeModification;
20 import org.opendaylight.mdsal.binding.api.MountPointService;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vbridge.topology.rev160129.network.topology.topology.topology.types.VbridgeTopology;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
24 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * Created by Shakib Ahmed on 1/19/17.
31 public class VbridgeTopologyListener implements ClusteredDataTreeChangeListener<VbridgeTopology>, AutoCloseable {
32 private static final Logger LOG = LoggerFactory.getLogger(VbridgeTopologyListener.class);
34 private final DataBroker dataBroker;
35 private final MountPointService mountPointService;
38 private final Map<TopologyKey, VppEndpointListener> domains = new ConcurrentHashMap<>();
40 public VbridgeTopologyListener(final DataBroker dataBroker,
41 final MountPointService mountPointService) {
42 this.dataBroker = Preconditions.checkNotNull(dataBroker);
43 this.mountPointService = Preconditions.checkNotNull(mountPointService);
47 public synchronized void onDataTreeChanged(@Nonnull Collection<DataTreeModification<VbridgeTopology>> changes) {
48 for (DataTreeModification<VbridgeTopology> topologyData : changes) {
49 final KeyedInstanceIdentifier<Topology, TopologyKey> topologyInstanceIdentifier =
50 (KeyedInstanceIdentifier<Topology, TopologyKey>) topologyData
53 .firstIdentifierOf(Topology.class);
55 Preconditions.checkArgument(!topologyInstanceIdentifier
56 .isWildcarded(), "Wildcard topology %s is not supported",
57 topologyInstanceIdentifier);
59 final DataObjectModification<VbridgeTopology> modification = topologyData.getRootNode();
61 switch (modification.getModificationType()) {
63 handleVbridgeTopologyDelete(topologyInstanceIdentifier);
66 handleVbridgeTopologyWrite(topologyInstanceIdentifier);
69 LOG.warn("Ignoring unhandled modification type {}", modification.getModificationType());
76 private void handleVbridgeTopologyDelete(KeyedInstanceIdentifier<Topology, TopologyKey> topology) {
77 VppEndpointListener endpointListener = domains.get(topology.getKey());
78 endpointListener.close();
79 domains.remove(topology.getKey());
82 private void handleVbridgeTopologyWrite(KeyedInstanceIdentifier<Topology, TopologyKey> topology) {
83 if (domains.containsKey(topology.getKey())) {
84 domains.get(topology.getKey()).close();
85 domains.remove(topology.getKey());
87 domains.put(topology.getKey(), new VppEndpointListener(dataBroker, mountPointService, topology));
92 domains.forEach((topologyKey, vppEndpointListener) -> {
93 vppEndpointListener.close();