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 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
12 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15 import com.google.common.base.Optional;
16 import java.util.Collections;
17 import java.util.List;
18 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
19 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
20 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
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.topology.Link;
25 public class TopologyManagerUtil {
27 private static final Logger LOG = LoggerFactory.getLogger(TopologyManagerUtil.class);
29 static void removeAffectedLinks(final NodeId id, final ReadWriteTransaction transaction, InstanceIdentifier<Topology> topology) {
30 Optional<Topology> topologyOptional = Optional.absent();
32 topologyOptional = transaction.read(LogicalDatastoreType.OPERATIONAL, topology).checkedGet();
33 } catch (ReadFailedException e) {
34 LOG.error("Error reading topology data for topology {}", 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.error("Error reading topology data for topology {}", topology, e);
63 if (topologyOptional.isPresent()) {
64 removeAffectedLinks(id, topologyOptional, transaction, topology);
68 static void removeAffectedLinks(final TpId id, Optional<Topology> topologyOptional, ReadWriteTransaction transaction, final InstanceIdentifier<Topology> topology) {
69 if (!topologyOptional.isPresent()) {
73 List<Link> linkList = topologyOptional.get().getLink() != null
74 ? topologyOptional.get().getLink() : Collections.<Link> emptyList();
75 for (Link link : linkList) {
76 if (id.equals(link.getSource().getSourceTp()) ||
77 id.equals(link.getDestination().getDestTp())) {
78 transaction.delete(LogicalDatastoreType.OPERATIONAL, linkPath(link, topology));
83 static InstanceIdentifier<Link> linkPath(final Link link, final InstanceIdentifier<Topology> topology) {
84 return topology.child(Link.class, link.getKey());