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 :
48 * - path-computation-request
49 * - cancelCresource-reserve.
50 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
53 public class MappingAndSendingPCRequest {
55 private static final Logger LOG = LoggerFactory.getLogger(MappingAndSendingPCRequest.class);
56 /* Permit to call PCE RPCs. */
57 private StubpceService service;
58 /* define procedure success (or not ). */
59 private Boolean success;
60 /* permit to call bundle service (PCE, Renderer, Servicehandler. */
61 private RpcProviderRegistry rpcRegistry;
62 PathComputationRequestInput pathComputationRequestInput = null;
63 CancelResourceReserveInput cancelResourceReserveInput = null;
64 HardConstraints hard = null;
65 SoftConstraints soft = null;
66 /* store all error messages. */
68 private final ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(5));
71 * MappingAndSendingPCRequest Class constructor for RPC serviceReconfigure.
75 * @param serviceReconfigureInput
76 * serviceReconfigureInput
78 * Boolean to define resource reserve
80 public MappingAndSendingPCRequest(RpcProviderRegistry rpcRegistry, ServiceReconfigureInput serviceReconfigureInput,
81 Boolean resvResource) {
82 this.rpcRegistry = rpcRegistry;
83 if (rpcRegistry != null) {
84 service = rpcRegistry.getRpcService(StubpceService.class);
86 SdncRequestHeader head = new SdncRequestHeaderBuilder().build();
87 MappingConstraints map = new MappingConstraints(serviceReconfigureInput.getHardConstraints(),
88 serviceReconfigureInput.getSoftConstraints());
89 map.serviceToServicePathConstarints();
91 * mappingPCRequest(serviceReconfigureInput.getNewServiceName(),
92 * serviceReconfigureInput.getHardConstraints(),
93 * serviceReconfigureInput.getSoftConstraints(),head ,resvResource);
95 mappingPCRequest(serviceReconfigureInput.getNewServiceName(), map.getServicePathHardConstraints(),
96 map.getServicePathSoftConstraints(), head, resvResource);
102 * MappingAndSendingPCRequest Class constructor for RPC
103 * serviceFeasibilityCheck.
106 * RpcProviderRegistry
107 * @param serviceFeasibilityCheckInput
108 * ServiceFeasibilityCheckInput
109 * @param resvResource
110 * Boolean to reserve resource
112 public MappingAndSendingPCRequest(RpcProviderRegistry rpcRegistry,
113 ServiceFeasibilityCheckInput serviceFeasibilityCheckInput, Boolean resvResource) {
114 this.rpcRegistry = rpcRegistry;
115 if (rpcRegistry != null) {
116 service = rpcRegistry.getRpcService(StubpceService.class);
118 MappingConstraints map = new MappingConstraints(serviceFeasibilityCheckInput.getHardConstraints(),
119 serviceFeasibilityCheckInput.getSoftConstraints());
120 map.serviceToServicePathConstarints();
121 mappingPCRequest("no name", map.getServicePathHardConstraints(), map.getServicePathSoftConstraints(),
122 serviceFeasibilityCheckInput.getSdncRequestHeader(), resvResource);
128 * MappingAndSendingPCRequest Class constructor for RPC serviceCreate.
131 * RpcProviderRegistry
132 * @param serviceCreateInput
134 * @param resvResource
135 * Boolean to reserve resource
137 public MappingAndSendingPCRequest(RpcProviderRegistry rpcRegistry, ServiceCreateInput serviceCreateInput,
138 Boolean resvResource) {
139 this.rpcRegistry = rpcRegistry;
140 if (rpcRegistry != null) {
141 service = rpcRegistry.getRpcService(StubpceService.class);
143 MappingConstraints map = new MappingConstraints(serviceCreateInput.getHardConstraints(),
144 serviceCreateInput.getSoftConstraints());
145 map.serviceToServicePathConstarints();
146 mappingPCRequest(serviceCreateInput.getServiceName(), map.getServicePathHardConstraints(),
147 map.getServicePathSoftConstraints(), serviceCreateInput.getSdncRequestHeader(), resvResource);
153 * MappingAndSendingPCRequest Class constructor for modify Service in ODL
157 * RpcProviderRegistry
160 * @param resvResource
161 * Boolean to reserve resource
163 public MappingAndSendingPCRequest(RpcProviderRegistry rpcRegistry, Services input, Boolean resvResource) {
164 this.rpcRegistry = rpcRegistry;
165 if (rpcRegistry != null) {
166 service = rpcRegistry.getRpcService(StubpceService.class);
168 MappingConstraints map = new MappingConstraints(input.getHardConstraints(), input.getSoftConstraints());
169 map.serviceToServicePathConstarints();
170 mappingPCRequest(input.getServiceName(), map.getServicePathHardConstraints(),
171 map.getServicePathSoftConstraints(), input.getSdncRequestHeader(), resvResource);
177 * Build pathComputationRequestInput or cancelResourceReserveInput with
178 * input parameters (serviceReconfigureInput or serviceFeasibilityCheckInput.
182 * @param HardConstraints
184 * @param SoftConstraints
186 * @param SdncRequestHeader
191 private void mappingPCRequest(String serviceName, HardConstraints hardConstraints, SoftConstraints softConstraints,
192 org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header
193 .SdncRequestHeader sdncRequestHeader, Boolean resvResource) {
195 LOG.info("Mapping ServiceCreateInput or ServiceFeasibilityCheckInput or serviceReconfigureInput "
196 + "to PCE requests");
198 HardConstraints serviceCreateHard = hardConstraints;
199 SoftConstraints serviceCreateSoft = softConstraints;
200 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.routing
201 .constraints.sp.HardConstraints pceHardConstraints = null;
202 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.routing
203 .constraints.sp.SoftConstraints pceSoftConstraints = null;
204 if (serviceCreateHard != null) {
205 pceHardConstraints = serviceCreateHard;
207 if (serviceCreateSoft != null) {
208 pceSoftConstraints = serviceCreateSoft;
211 ServiceHandlerHeaderBuilder serviceHandlerHeader = new ServiceHandlerHeaderBuilder();
212 if (sdncRequestHeader != null) {
213 serviceHandlerHeader.setRequestId(sdncRequestHeader.getRequestId());
216 /* PathComputationRequestInput build */
217 pathComputationRequestInput = new PathComputationRequestInputBuilder().setServiceName(serviceName)
218 .setResourceReserve(resvResource).setServiceHandlerHeader(serviceHandlerHeader.build())
219 .setHardConstraints(pceHardConstraints).setSoftConstraints(pceSoftConstraints)
220 .setPceMetric(PceMetric.TEMetric).build();
222 /* CancelResourceReserveInput build */
223 cancelResourceReserveInput = new CancelResourceReserveInputBuilder().setServiceName(serviceName)
224 .setServiceHandlerHeader(serviceHandlerHeader.build()).build();
228 * Send cancelResourceReserve request to PCE.
230 * @return CancelResourceReserveOutput data response from PCE
232 public ListenableFuture<CancelResourceReserveOutput> cancelResourceReserve() {
234 return executor.submit(new Callable<CancelResourceReserveOutput>() {
237 public CancelResourceReserveOutput call() throws Exception {
238 CancelResourceReserveOutput output = null;
239 if (cancelResourceReserveInput != null) {
241 RpcResult<CancelResourceReserveOutput> pceOutputResult = null;
242 Future<RpcResult<CancelResourceReserveOutput>> pceOutputFuture = service
243 .cancelResourceReserve(cancelResourceReserveInput);
246 pceOutputResult = pceOutputFuture.get();
247 } catch (InterruptedException | CancellationException | ExecutionException e) {
248 setError("Did not receive the expected response from pce to cancelResourceReserve RPC "
251 pceOutputFuture.cancel(true);
254 if (pceOutputResult != null && pceOutputResult.isSuccessful()) {
255 LOG.info("PCE replied to CancelResource request !");
256 CancelResourceReserveOutput pceOutput = pceOutputResult.getResult();
257 output = new CancelResourceReserveOutputBuilder()
258 .setConfigurationResponseCommon(pceOutput.getConfigurationResponseCommon()).build();
262 LOG.info("cancelResourceReserveInput parameter not valid !");
270 public Boolean getSuccess() {
274 public void setSuccess(Boolean success) {
275 this.success = success;
278 public String getError() {
282 public void setError(String error) {
287 * Send pathComputationRequest request to PCE.
289 * @return PathComputationRequestOutput data response from PCE
291 public ListenableFuture<PathComputationRequestOutput> pathComputationRequest() {
292 LOG.info("In pathComputationRequest ...");
294 return executor.submit(new Callable<PathComputationRequestOutput>() {
296 public PathComputationRequestOutput call() throws Exception {
297 RpcResult<PathComputationRequestOutput> pceOutputResult = null;
298 PathComputationRequestOutput output = null;
299 if (pathComputationRequestInput != null) {
300 Future<RpcResult<PathComputationRequestOutput>> pceOutputFuture = service
301 .pathComputationRequest(pathComputationRequestInput);
303 pceOutputResult = pceOutputFuture.get();// wait to get
305 } catch (InterruptedException | CancellationException | ExecutionException e) {
306 setError("Did not receive the expected response from pce to pathComputationRequest RPC "
309 pceOutputFuture.cancel(true);
312 if (pceOutputResult != null && pceOutputResult.isSuccessful()) {
314 LOG.info("PCE replied to pathComputation request !");
315 PathComputationRequestOutput pceOutput = pceOutputResult.getResult();
316 output = new PathComputationRequestOutputBuilder()
317 .setConfigurationResponseCommon(pceOutput.getConfigurationResponseCommon())
318 .setResponseParameters(pceOutput.getResponseParameters()).build();
321 LOG.info("pathComputationRequestInput parameter not valid !");