2 * Copyright (c) 2013 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;
11 import org.opendaylight.bgpcep.pcep.topology.spi.AbstractTopologyProgrammingExecutor;
12 import org.opendaylight.bgpcep.programming.spi.InstructionExecutor;
13 import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
14 import org.opendaylight.bgpcep.programming.spi.SuccessfulRpcResult;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.submit.instruction.output.result.FailureBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.submit.instruction.output.result.failure.Failure;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspInputBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspOutput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.NetworkTopologyPcepService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspInputBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspOutput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspInputBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspOutput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.programming.rev131030.PcepCreateP2pTunnelInput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.programming.rev131030.PcepCreateP2pTunnelOutput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.programming.rev131030.PcepCreateP2pTunnelOutputBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.programming.rev131030.PcepDestroyTunnelInput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.programming.rev131030.PcepDestroyTunnelOutput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.programming.rev131030.PcepDestroyTunnelOutputBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.programming.rev131030.PcepUpdateTunnelInput;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.programming.rev131030.PcepUpdateTunnelOutput;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.programming.rev131030.PcepUpdateTunnelOutputBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.programming.rev131030.TopologyTunnelPcepProgrammingService;
35 import org.opendaylight.yangtools.yang.common.RpcResult;
37 import com.google.common.base.Function;
38 import com.google.common.base.Preconditions;
39 import com.google.common.util.concurrent.Futures;
40 import com.google.common.util.concurrent.ListenableFuture;
42 final class TunnelProgramming implements TopologyTunnelPcepProgrammingService {
43 private final NetworkTopologyPcepService pcepTopology;
44 private final InstructionScheduler scheduler;
46 TunnelProgramming(final InstructionScheduler scheduler, final NetworkTopologyPcepService pcepTopology) {
47 this.scheduler = Preconditions.checkNotNull(scheduler);
48 this.pcepTopology = Preconditions.checkNotNull(pcepTopology);
52 public ListenableFuture<RpcResult<PcepCreateP2pTunnelOutput>> pcepCreateP2pTunnel(final PcepCreateP2pTunnelInput input) {
53 Preconditions.checkNotNull(input.getLinkId());
54 Preconditions.checkNotNull(input.getSourceTp());
55 Preconditions.checkNotNull(input.getDestinationTp());
57 final AddLspInputBuilder ab = new AddLspInputBuilder();
60 final InstructionExecutor e = new AbstractTopologyProgrammingExecutor() {
62 protected ListenableFuture<OperationResult> executeImpl() {
63 final ListenableFuture<RpcResult<AddLspOutput>> s =
64 (ListenableFuture<RpcResult<AddLspOutput>>) pcepTopology.addLsp(ab.build());
66 return Futures.transform(s, new Function<RpcResult<AddLspOutput>, OperationResult>() {
68 public OperationResult apply(final RpcResult<AddLspOutput> input) {
69 return input.getResult();
75 final Failure f = this.scheduler.submitInstruction(input, e);
76 final PcepCreateP2pTunnelOutputBuilder b = new PcepCreateP2pTunnelOutputBuilder();
78 b.setResult(new FailureBuilder().setFailure(f).build());
81 final RpcResult<PcepCreateP2pTunnelOutput> res = SuccessfulRpcResult.create(b.build());
82 return Futures.immediateFuture(res);
86 public ListenableFuture<RpcResult<PcepDestroyTunnelOutput>> pcepDestroyTunnel(final PcepDestroyTunnelInput input) {
87 Preconditions.checkNotNull(input.getLinkId());
89 final RemoveLspInputBuilder ab = new RemoveLspInputBuilder();
92 final InstructionExecutor e = new AbstractTopologyProgrammingExecutor() {
94 protected ListenableFuture<OperationResult> executeImpl() {
95 final ListenableFuture<RpcResult<RemoveLspOutput>> s =
96 (ListenableFuture<RpcResult<RemoveLspOutput>>) pcepTopology.removeLsp(ab.build());
98 return Futures.transform(s, new Function<RpcResult<RemoveLspOutput>, OperationResult>() {
100 public OperationResult apply(final RpcResult<RemoveLspOutput> input) {
101 return input.getResult();
107 final Failure f = this.scheduler.submitInstruction(input, e);
108 final PcepDestroyTunnelOutputBuilder b = new PcepDestroyTunnelOutputBuilder();
110 b.setResult(new FailureBuilder().setFailure(f).build());
113 final RpcResult<PcepDestroyTunnelOutput> res = SuccessfulRpcResult.create(b.build());
114 return Futures.immediateFuture(res);
118 public ListenableFuture<RpcResult<PcepUpdateTunnelOutput>> pcepUpdateTunnel(final PcepUpdateTunnelInput input) {
119 Preconditions.checkNotNull(input.getLinkId());
121 final UpdateLspInputBuilder ab = new UpdateLspInputBuilder();
122 ab.fieldsFrom(input);
124 final InstructionExecutor e = new AbstractTopologyProgrammingExecutor() {
126 protected ListenableFuture<OperationResult> executeImpl() {
127 final ListenableFuture<RpcResult<UpdateLspOutput>> s =
128 (ListenableFuture<RpcResult<UpdateLspOutput>>) pcepTopology.updateLsp(ab.build());
130 return Futures.transform(s, new Function<RpcResult<UpdateLspOutput>, OperationResult>() {
132 public OperationResult apply(final RpcResult<UpdateLspOutput> input) {
133 return input.getResult();
139 final Failure f = this.scheduler.submitInstruction(input, e);
140 final PcepUpdateTunnelOutputBuilder b = new PcepUpdateTunnelOutputBuilder();
142 b.setResult(new FailureBuilder().setFailure(f).build());
145 final RpcResult<PcepUpdateTunnelOutput> res = SuccessfulRpcResult.create(b.build());
146 return Futures.immediateFuture(res);