2 * Copyright © 2017 Orange, 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.transportpce.servicehandler;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import com.google.common.util.concurrent.ListeningExecutorService;
13 import com.google.common.util.concurrent.MoreExecutors;
15 import java.util.concurrent.Callable;
16 import java.util.concurrent.CancellationException;
17 import java.util.concurrent.ExecutionException;
18 import java.util.concurrent.Executors;
19 import java.util.concurrent.Future;
21 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceCreateInput;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceFeasibilityCheckInput;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceReconfigureInput;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.service.list.Services;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.CancelResourceReserveInput;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.CancelResourceReserveInputBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.CancelResourceReserveOutput;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.CancelResourceReserveOutputBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.PathComputationRequestInput;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.PathComputationRequestInputBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.PathComputationRequestOutput;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.PathComputationRequestOutputBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.StubpceService;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeader;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeaderBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.RoutingConstraintsSp.PceMetric;
38 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.routing.constraints.sp.HardConstraints;
39 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.routing.constraints.sp.SoftConstraints;
40 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.service.handler.header.ServiceHandlerHeaderBuilder;
41 import org.opendaylight.yangtools.yang.common.RpcResult;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
47 * class for Mapping and Sending PCE requests : - path-computation-request -
48 * cancel-resource-reserve.
49 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
52 public class MappingAndSendingPCRequest {
54 private static final Logger LOG = LoggerFactory.getLogger(MappingAndSendingPCRequest.class);
55 /* Permit to call PCE RPCs. */
56 private StubpceService service;
57 /* define procedure success (or not ). */
58 private Boolean success;
59 /* permit to call bundle service (PCE, Renderer, Servicehandler. */
60 private RpcProviderRegistry rpcRegistry;
61 PathComputationRequestInput pathComputationRequestInput = null;
62 CancelResourceReserveInput cancelResourceReserveInput = null;
63 HardConstraints hard = null;
64 SoftConstraints soft = null;
65 /* store all error messages. */
67 private final ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(5));
70 * MappingAndSendingPCRequest Class constructor for RPC serviceReconfigure.
74 * @param serviceReconfigureInput
75 * serviceReconfigureInput
77 * Boolean to define resource reserve
79 public MappingAndSendingPCRequest(RpcProviderRegistry rpcRegistry, ServiceReconfigureInput serviceReconfigureInput,
80 Boolean resvResource) {
81 this.rpcRegistry = rpcRegistry;
82 if (rpcRegistry != null) {
83 service = rpcRegistry.getRpcService(StubpceService.class);
85 SdncRequestHeader head = new SdncRequestHeaderBuilder().build();
86 MappingConstraints map = new MappingConstraints(serviceReconfigureInput.getHardConstraints(),
87 serviceReconfigureInput.getSoftConstraints());
88 map.serviceToServicePathConstarints();
90 * mappingPCRequest(serviceReconfigureInput.getNewServiceName(),
91 * serviceReconfigureInput.getHardConstraints(),
92 * serviceReconfigureInput.getSoftConstraints(),head ,resvResource);
94 mappingPCRequest(serviceReconfigureInput.getNewServiceName(), map.getServicePathHardConstraints(),
95 map.getServicePathSoftConstraints(), head, resvResource);
101 * MappingAndSendingPCRequest Class constructor for RPC
102 * serviceFeasibilityCheck.
105 * RpcProviderRegistry
106 * @param serviceFeasibilityCheckInput
107 * ServiceFeasibilityCheckInput
108 * @param resvResource
109 * Boolean to reserve resource
111 public MappingAndSendingPCRequest(RpcProviderRegistry rpcRegistry,
112 ServiceFeasibilityCheckInput serviceFeasibilityCheckInput, Boolean resvResource) {
113 this.rpcRegistry = rpcRegistry;
114 if (rpcRegistry != null) {
115 service = rpcRegistry.getRpcService(StubpceService.class);
117 MappingConstraints map = new MappingConstraints(serviceFeasibilityCheckInput.getHardConstraints(),
118 serviceFeasibilityCheckInput.getSoftConstraints());
119 map.serviceToServicePathConstarints();
120 mappingPCRequest("no name", map.getServicePathHardConstraints(), map.getServicePathSoftConstraints(),
121 serviceFeasibilityCheckInput.getSdncRequestHeader(), resvResource);
127 * MappingAndSendingPCRequest Class constructor for RPC serviceCreate.
130 * RpcProviderRegistry
131 * @param serviceCreateInput
133 * @param resvResource
134 * Boolean to reserve resource
136 public MappingAndSendingPCRequest(RpcProviderRegistry rpcRegistry, ServiceCreateInput serviceCreateInput,
137 Boolean resvResource) {
138 this.rpcRegistry = rpcRegistry;
139 if (rpcRegistry != null) {
140 service = rpcRegistry.getRpcService(StubpceService.class);
142 MappingConstraints map = new MappingConstraints(serviceCreateInput.getHardConstraints(),
143 serviceCreateInput.getSoftConstraints());
144 map.serviceToServicePathConstarints();
145 mappingPCRequest(serviceCreateInput.getServiceName(), map.getServicePathHardConstraints(),
146 map.getServicePathSoftConstraints(), serviceCreateInput.getSdncRequestHeader(), resvResource);
152 * MappingAndSendingPCRequest Class constructor for modify Service in ODL
156 * RpcProviderRegistry
159 * @param resvResource
160 * Boolean to reserve resource
162 public MappingAndSendingPCRequest(RpcProviderRegistry rpcRegistry, Services input, Boolean resvResource) {
163 this.rpcRegistry = rpcRegistry;
164 if (rpcRegistry != null) {
165 service = rpcRegistry.getRpcService(StubpceService.class);
167 MappingConstraints map = new MappingConstraints(input.getHardConstraints(), input.getSoftConstraints());
168 map.serviceToServicePathConstarints();
169 mappingPCRequest(input.getServiceName(), map.getServicePathHardConstraints(),
170 map.getServicePathSoftConstraints(), input.getSdncRequestHeader(), resvResource);
176 * Build pathComputationRequestInput or cancelResourceReserveInput with
177 * input parameters (serviceReconfigureInput or serviceFeasibilityCheckInput.
181 * @param HardConstraints
183 * @param SoftConstraints
185 * @param SdncRequestHeader
190 private void mappingPCRequest(String serviceName, HardConstraints hardConstraints, SoftConstraints softConstraints,
191 org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header
192 .SdncRequestHeader sdncRequestHeader, Boolean resvResource) {
194 LOG.info("Mapping ServiceCreateInput or ServiceFeasibilityCheckInput or serviceReconfigureInput "
195 + "to PCE requests");
197 HardConstraints serviceCreateHard = hardConstraints;
198 SoftConstraints serviceCreateSoft = softConstraints;
199 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.routing
200 .constraints.sp.HardConstraints pceHardConstraints = null;
201 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.routing
202 .constraints.sp.SoftConstraints pceSoftConstraints = null;
203 if (serviceCreateHard != null) {
204 pceHardConstraints = serviceCreateHard;
206 if (serviceCreateSoft != null) {
207 pceSoftConstraints = serviceCreateSoft;
210 ServiceHandlerHeaderBuilder serviceHandlerHeader = new ServiceHandlerHeaderBuilder();
211 if (sdncRequestHeader != null) {
212 serviceHandlerHeader.setRequestId(sdncRequestHeader.getRequestId());
215 /* PathComputationRequestInput build */
216 pathComputationRequestInput = new PathComputationRequestInputBuilder().setServiceName(serviceName)
217 .setResourceReserve(resvResource).setServiceHandlerHeader(serviceHandlerHeader.build())
218 .setHardConstraints(pceHardConstraints).setSoftConstraints(pceSoftConstraints)
219 .setPceMetric(PceMetric.TEMetric).build();
221 /* CancelResourceReserveInput build */
222 cancelResourceReserveInput = new CancelResourceReserveInputBuilder().setServiceName(serviceName)
223 .setServiceHandlerHeader(serviceHandlerHeader.build()).build();
226 /* Send cancelResourceReserve request to PCE.
228 * @return CancelResourceReserveOutput data response from PCE
230 public ListenableFuture<CancelResourceReserveOutput> cancelResourceReserve() {
232 return executor.submit(new Callable<CancelResourceReserveOutput>() {
235 public CancelResourceReserveOutput call() throws Exception {
236 CancelResourceReserveOutput output = null;
237 if (cancelResourceReserveInput != null) {
239 RpcResult<CancelResourceReserveOutput> pceOutputResult = null;
240 Future<RpcResult<CancelResourceReserveOutput>> pceOutputFuture = service
241 .cancelResourceReserve(cancelResourceReserveInput);
244 pceOutputResult = pceOutputFuture.get();
245 } catch (InterruptedException | CancellationException | ExecutionException e) {
246 setError("Did not receive the expected response from pce to cancelResourceReserve RPC "
249 pceOutputFuture.cancel(true);
252 if (pceOutputResult != null && pceOutputResult.isSuccessful()) {
253 LOG.info("PCE replied to CancelResource request !");
254 CancelResourceReserveOutput pceOutput = pceOutputResult.getResult();
255 output = new CancelResourceReserveOutputBuilder()
256 .setConfigurationResponseCommon(pceOutput.getConfigurationResponseCommon()).build();
260 LOG.info("cancelResourceReserveInput parameter not valid !");
268 public Boolean getSuccess() {
272 public void setSuccess(Boolean success) {
273 this.success = success;
276 public String getError() {
280 public void setError(String error) {
284 /*Send pathComputationRequest request to PCE.
286 * @return PathComputationRequestOutput data response from PCE
288 public ListenableFuture<PathComputationRequestOutput> pathComputationRequest() {
289 LOG.info("In pathComputationRequest ...");
291 return executor.submit(new Callable<PathComputationRequestOutput>() {
293 public PathComputationRequestOutput call() throws Exception {
294 RpcResult<PathComputationRequestOutput> pceOutputResult = null;
295 PathComputationRequestOutput output = null;
296 if (pathComputationRequestInput != null) {
297 Future<RpcResult<PathComputationRequestOutput>> pceOutputFuture = service
298 .pathComputationRequest(pathComputationRequestInput);
300 pceOutputResult = pceOutputFuture.get();// wait to get
302 } catch (InterruptedException | CancellationException | ExecutionException e) {
303 setError("Did not receive the expected response from pce to pathComputationRequest RPC "
306 pceOutputFuture.cancel(true);
309 if (pceOutputResult != null && pceOutputResult.isSuccessful()) {
311 LOG.info("PCE replied to pathComputation request !");
312 PathComputationRequestOutput pceOutput = pceOutputResult.getResult();
313 output = new PathComputationRequestOutputBuilder()
314 .setConfigurationResponseCommon(pceOutput.getConfigurationResponseCommon())
315 .setResponseParameters(pceOutput.getResponseParameters()).build();
318 LOG.info("pathComputationRequestInput parameter not valid !");