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.InstanceIdentifier;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
39 final class TunelProgrammingUtil {
40 public static final ListenableFuture<OperationResult> RESULT = Futures.immediateFuture(new OperationResult() {
42 public Class<OperationResult> implementedInterface() {
43 return OperationResult.class;
47 public FailureType getFailure() {
48 return FailureType.Unsent;
52 public List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev181109
53 .operation.result.Error> getError() {
54 return Collections.emptyList();
57 private static final Logger LOG = LoggerFactory.getLogger(TunelProgrammingUtil.class);
59 private TunelProgrammingUtil() {
60 throw new UnsupportedOperationException();
63 public static Ero buildEro(final List<ExplicitHops> explicitHops) {
64 final EroBuilder b = new EroBuilder();
66 if (!explicitHops.isEmpty()) {
67 final List<Subobject> subobjs = new ArrayList<>(explicitHops.size());
68 for (final ExplicitHops h : explicitHops) {
70 final ExplicitHops1 h1 = h.augmentation(ExplicitHops1.class);
72 final SubobjectBuilder sb = new SubobjectBuilder();
74 sb.setLoose(h.isLoose());
75 subobjs.add(sb.build());
77 LOG.debug("Ignoring unhandled explicit hop {}", h);
80 b.setSubobject(subobjs);
85 public static NodeId supportingNode(final Node node) {
86 for (final SupportingNode n : node.getSupportingNode()) {
87 final SupportingNode1 n1 = n.augmentation(SupportingNode1.class);
88 if (n1 != null && n1.getPathComputationClient().isControlling()) {
89 return n.key().getNodeRef();
96 public static Optional<Node> sourceNode(final ReadTransaction rt, final InstanceIdentifier<Topology> topology,
97 final Link link) throws InterruptedException, ExecutionException {
98 return rt.read(LogicalDatastoreType.OPERATIONAL,
99 topology.child(Node.class, new NodeKey(link.getSource().getSourceNode()))).get();