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
9 package org.opendaylight.bgpcep.pcep.tunnel.provider;
11 import com.google.common.util.concurrent.Futures;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import java.util.ArrayList;
14 import java.util.Collections;
15 import java.util.List;
16 import java.util.Optional;
17 import java.util.concurrent.ExecutionException;
18 import org.opendaylight.mdsal.binding.api.ReadTransaction;
19 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.Ero;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.EroBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev181109.FailureType;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev181109.OperationResult;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.p2p.rev130819.tunnel.p2p.path.cfg.attributes.ExplicitHops;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.rev181109.ExplicitHops1;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.rev181109.SupportingNode1;
29 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
30 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
31 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
32 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
33 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
34 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.node.attributes.SupportingNode;
35 import org.opendaylight.yangtools.yang.binding.DataContainer;
36 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
40 final class TunelProgrammingUtil {
41 public static final ListenableFuture<OperationResult> RESULT = Futures.immediateFuture(new OperationResult() {
43 public Class<? extends DataContainer> getImplementedInterface() {
44 return OperationResult.class;
48 public FailureType getFailure() {
49 return FailureType.Unsent;
53 public List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev181109
54 .operation.result.Error> getError() {
55 return Collections.emptyList();
58 private static final Logger LOG = LoggerFactory.getLogger(TunelProgrammingUtil.class);
60 private TunelProgrammingUtil() {
61 throw new UnsupportedOperationException();
64 public static Ero buildEro(final List<ExplicitHops> explicitHops) {
65 final EroBuilder b = new EroBuilder();
67 if (!explicitHops.isEmpty()) {
68 final List<Subobject> subobjs = new ArrayList<>(explicitHops.size());
69 for (final ExplicitHops h : explicitHops) {
71 final ExplicitHops1 h1 = h.augmentation(ExplicitHops1.class);
73 final SubobjectBuilder sb = new SubobjectBuilder();
75 sb.setLoose(h.isLoose());
76 subobjs.add(sb.build());
78 LOG.debug("Ignoring unhandled explicit hop {}", h);
81 b.setSubobject(subobjs);
86 public static NodeId supportingNode(final Node node) {
87 for (final SupportingNode n : node.getSupportingNode()) {
88 final SupportingNode1 n1 = n.augmentation(SupportingNode1.class);
89 if (n1 != null && n1.getPathComputationClient().isControlling()) {
90 return n.key().getNodeRef();
97 public static Optional<Node> sourceNode(final ReadTransaction rt, final InstanceIdentifier<Topology> topology,
98 final Link link) throws InterruptedException, ExecutionException {
99 return rt.read(LogicalDatastoreType.OPERATIONAL,
100 topology.child(Node.class, new NodeKey(link.getSource().getSourceNode()))).get();