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