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.binding.api.ReadWriteTransaction;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
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 public class TopologyManagerUtil {
26 private static final Logger LOG = LoggerFactory.getLogger(TopologyManagerUtil.class);
28 static void removeAffectedLinks(final NodeId id, final ReadWriteTransaction transaction, InstanceIdentifier<Topology> topology) {
29 Optional<Topology> topologyOptional = Optional.absent();
31 topologyOptional = transaction.read(LogicalDatastoreType.OPERATIONAL, topology).checkedGet();
32 } catch (ReadFailedException e) {
33 LOG.warn("Error reading topology data for topology {}: {}", topology, e.getMessage());
34 LOG.debug("Error reading topology data for topology.. ", e);
36 if (topologyOptional.isPresent()) {
37 removeAffectedLinks(id, topologyOptional, transaction, topology);
41 static void removeAffectedLinks(final NodeId id, Optional<Topology> topologyOptional, ReadWriteTransaction transaction, final InstanceIdentifier<Topology> topology) {
42 if (!topologyOptional.isPresent()) {
46 List<Link> linkList = topologyOptional.get().getLink() != null ?
47 topologyOptional.get().getLink() : Collections.<Link> emptyList();
48 for (Link link : linkList) {
49 if (id.equals(link.getSource().getSourceNode()) ||
50 id.equals(link.getDestination().getDestNode())) {
51 transaction.delete(LogicalDatastoreType.OPERATIONAL, linkPath(link, topology));
56 static void removeAffectedLinks(final TpId id, final ReadWriteTransaction transaction, final InstanceIdentifier<Topology> topology) {
57 Optional<Topology> topologyOptional = Optional.absent();
59 topologyOptional = transaction.read(LogicalDatastoreType.OPERATIONAL, topology).checkedGet();
60 } catch (ReadFailedException e) {
61 LOG.warn("Error reading topology data for topology {}: {}", topology, e.getMessage());
62 LOG.debug("Error reading topology data for topology..", e);
64 if (topologyOptional.isPresent()) {
65 removeAffectedLinks(id, topologyOptional, transaction, topology);
69 static void removeAffectedLinks(final TpId id, Optional<Topology> topologyOptional, ReadWriteTransaction transaction, final InstanceIdentifier<Topology> topology) {
70 if (!topologyOptional.isPresent()) {
74 List<Link> linkList = topologyOptional.get().getLink() != null
75 ? topologyOptional.get().getLink() : Collections.<Link> emptyList();
76 for (Link link : linkList) {
77 if (id.equals(link.getSource().getSourceTp()) ||
78 id.equals(link.getDestination().getDestTp())) {
79 transaction.delete(LogicalDatastoreType.OPERATIONAL, linkPath(link, topology));
84 static InstanceIdentifier<Link> linkPath(final Link link, final InstanceIdentifier<Topology> topology) {
85 return topology.child(Link.class, link.getKey());