2 * Copyright (c) 2015 Cisco Systems, Inc. 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
8 package org.opendaylight.openflowplugin.applications.topology.manager;
10 import com.google.common.base.Optional;
11 import java.util.Collections;
12 import java.util.List;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
15 import org.opendaylight.openflowplugin.common.txchain.TransactionChainManager;
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 class TopologyManagerUtil {
26 private static final Logger LOG = LoggerFactory.getLogger(TopologyManagerUtil.class);
28 private TopologyManagerUtil() {}
30 static void removeAffectedLinks(final NodeId id, final TransactionChainManager manager, InstanceIdentifier<Topology> topology) {
31 Optional<Topology> topologyOptional = Optional.absent();
33 topologyOptional = manager.readFromTransaction(LogicalDatastoreType.OPERATIONAL, topology).checkedGet();
34 } catch (ReadFailedException e) {
35 LOG.warn("Error reading topology data for topology {}: {}", topology, e.getMessage());
36 LOG.debug("Error reading topology data for topology.. ", e);
38 if (topologyOptional.isPresent()) {
39 removeAffectedLinks(id, topologyOptional, manager, topology);
43 private static void removeAffectedLinks(final NodeId id, Optional<Topology> topologyOptional, TransactionChainManager manager, final InstanceIdentifier<Topology> topology) {
44 if (!topologyOptional.isPresent()) {
48 List<Link> linkList = topologyOptional.get().getLink() != null ?
49 topologyOptional.get().getLink() : Collections.emptyList();
50 for (Link link : linkList) {
51 if (id.equals(link.getSource().getSourceNode()) ||
52 id.equals(link.getDestination().getDestNode())) {
53 manager.addDeleteOperationTotTxChain(LogicalDatastoreType.OPERATIONAL, linkPath(link, topology));
58 static void removeAffectedLinks(final TpId id, final TransactionChainManager manager, final InstanceIdentifier<Topology> topology) {
59 Optional<Topology> topologyOptional = Optional.absent();
61 topologyOptional = manager.readFromTransaction(LogicalDatastoreType.OPERATIONAL, topology).checkedGet();
62 } catch (ReadFailedException e) {
63 LOG.warn("Error reading topology data for topology {}: {}", topology, e.getMessage());
64 LOG.debug("Error reading topology data for topology..", e);
66 if (topologyOptional.isPresent()) {
67 removeAffectedLinks(id, topologyOptional, manager, topology);
71 private static void removeAffectedLinks(final TpId id, Optional<Topology> topologyOptional, TransactionChainManager manager, final InstanceIdentifier<Topology> topology) {
72 if (!topologyOptional.isPresent()) {
76 List<Link> linkList = topologyOptional.get().getLink() != null
77 ? topologyOptional.get().getLink() : Collections.<Link> emptyList();
78 for (Link link : linkList) {
79 if (id.equals(link.getSource().getSourceTp()) ||
80 id.equals(link.getDestination().getDestTp())) {
81 manager.addDeleteOperationTotTxChain(LogicalDatastoreType.OPERATIONAL, linkPath(link, topology));
86 static InstanceIdentifier<Link> linkPath(final Link link, final InstanceIdentifier<Topology> topology) {
87 return topology.child(Link.class, link.getKey());