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;
12 import java.util.Collection;
14 import java.util.concurrent.ConcurrentHashMap;
15 import javax.annotation.Nonnull;
16 import javax.annotation.concurrent.GuardedBy;
18 import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
19 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
20 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
21 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
22 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vbridge.topology.rev160129.network.topology.topology.topology.types.VbridgeTopology;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
26 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * Created by Shakib Ahmed on 1/19/17.
33 public class VbridgeTopologyListener implements ClusteredDataTreeChangeListener<VbridgeTopology>, AutoCloseable {
34 private static final Logger LOG = LoggerFactory.getLogger(VbridgeTopologyListener.class);
36 private DataBroker dataBroker;
37 private MountPointService mountPointService;
40 private final Map<TopologyKey, VppEndpointListener> domains = new ConcurrentHashMap<>();
42 public VbridgeTopologyListener(final DataBroker dataBroker,
43 final MountPointService mountPointService) {
44 this.dataBroker = Preconditions.checkNotNull(dataBroker);
45 this.mountPointService = Preconditions.checkNotNull(mountPointService);
49 public synchronized void onDataTreeChanged(@Nonnull Collection<DataTreeModification<VbridgeTopology>> changes) {
50 for (DataTreeModification<VbridgeTopology> topologyData : changes) {
51 final KeyedInstanceIdentifier<Topology, TopologyKey> topologyInstanceIdentifier =
52 (KeyedInstanceIdentifier<Topology, TopologyKey>) topologyData
55 .firstIdentifierOf(Topology.class);
57 Preconditions.checkArgument(!topologyInstanceIdentifier
58 .isWildcarded(), "Wildcard topology %s is not supported",
59 topologyInstanceIdentifier);
61 final DataObjectModification<VbridgeTopology> modification = topologyData.getRootNode();
63 switch (modification.getModificationType()) {
65 handleVbridgeTopologyDelete(topologyInstanceIdentifier);
68 handleVbridgeTopologyWrite(topologyInstanceIdentifier);
71 LOG.warn("Ignoring unhandled modification type {}", modification.getModificationType());
78 private void handleVbridgeTopologyDelete(KeyedInstanceIdentifier<Topology, TopologyKey> topology) {
79 VppEndpointListener endpointListener = domains.get(topology.getKey());
80 endpointListener.close();
81 domains.remove(topology.getKey());
84 private void handleVbridgeTopologyWrite(KeyedInstanceIdentifier<Topology, TopologyKey> topology) {
85 if (domains.containsKey(topology.getKey())) {
86 domains.get(topology.getKey()).close();
87 domains.remove(topology.getKey());
89 domains.put(topology.getKey(), new VppEndpointListener(dataBroker, mountPointService, topology));
94 domains.forEach((topologyKey, vppEndpointListener) -> {
95 vppEndpointListener.close();