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
10 package org.opendaylight.transportpce.stubpce.impl;
12 import java.util.concurrent.Future;
14 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
15 import org.opendaylight.transportpce.stubpce.CompliancyCheck;
16 import org.opendaylight.transportpce.stubpce.SendingPceRPCs;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.CancelResourceReserveInput;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.CancelResourceReserveOutput;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.CancelResourceReserveOutputBuilder;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.PathComputationRequestInput;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.PathComputationRequestOutput;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.PathComputationRequestOutputBuilder;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.ServicePathRpcResult;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.ServicePathRpcResultBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.StubpceService;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.service.path.rpc.result.PathDescription;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.RpcStatusEx;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.ServicePathNotificationTypes;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.response.parameters.sp.response.parameters.PathDescriptionBuilder;
31 import org.opendaylight.yangtools.yang.common.RpcResult;
32 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
42 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
46 public class StubpceImpl implements StubpceService {
49 private static final Logger LOG = LoggerFactory.getLogger(StubpceImpl.class);
51 private CompliancyCheck compliancyCheck;
52 /* send notification. */
53 private NotificationPublishService notificationPublishService;
54 private ServicePathRpcResult notification;
56 public StubpceImpl(NotificationPublishService notificationPublishService) {
57 this.notificationPublishService = notificationPublishService;
61 public Future<RpcResult<CancelResourceReserveOutput>> cancelResourceReserve(CancelResourceReserveInput input) {
62 LOG.info("RPC cancelResourceReserve request received");
65 notification = new ServicePathRpcResultBuilder()
66 .setNotificationType(ServicePathNotificationTypes.CancelResourceReserve)
67 .setServiceName(input.getServiceName())
68 .setStatus(RpcStatusEx.Pending)
69 .setStatusMessage("Service compliant, submitting cancelResourceReserve Request ...")
72 notificationPublishService.putNotification(notification);
73 } catch (InterruptedException e) {
74 LOG.info("notification offer rejected : " + e);
77 SendingPceRPCs sendingPCE = new SendingPceRPCs();
78 sendingPCE.cancelResourceReserve();
79 if (sendingPCE.getSuccess()) {
80 message = "ResourceReserve cancelled ! ";
82 message = "Cancelling ResourceReserve failed ! ";
85 ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder();
86 configurationResponseCommon
87 .setAckFinalIndicator("Yes")
88 .setRequestId(input.getServiceHandlerHeader().getRequestId())
89 .setResponseCode("200")
90 .setResponseMessage("")
91 .setResponseMessage(message);
92 CancelResourceReserveOutputBuilder output = new CancelResourceReserveOutputBuilder();
94 .setConfigurationResponseCommon(configurationResponseCommon.build());
95 return RpcResultBuilder.success(output.build()).buildFuture();
100 public Future<RpcResult<PathComputationRequestOutput>> pathComputationRequest(PathComputationRequestInput input) {
101 LOG.info("RPC pathcomputation request received");
103 PathComputationRequestOutputBuilder output = new PathComputationRequestOutputBuilder();
104 ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder();
106 compliancyCheck = new CompliancyCheck(input);
107 if (!compliancyCheck.check()) {
108 configurationResponseCommon
109 .setAckFinalIndicator("Yes")
110 .setRequestId(input.getServiceHandlerHeader().getRequestId())
111 .setResponseCode("Path not calculated")
112 .setResponseMessage(compliancyCheck.getMessage());
115 .setConfigurationResponseCommon(configurationResponseCommon.build())
116 .setResponseParameters(null);
118 return RpcResultBuilder.success(output.build()).buildFuture();
120 notification = new ServicePathRpcResultBuilder()
121 .setNotificationType(ServicePathNotificationTypes.PathComputationRequest)
122 .setServiceName(input.getServiceName())
123 .setStatus(RpcStatusEx.Pending)
124 .setStatusMessage("Service compliant, submitting pathComputation Request ...")
127 notificationPublishService.putNotification(notification);
128 } catch (InterruptedException e) {
129 LOG.info("notification offer rejected : " + e);
132 SendingPceRPCs sendingPCE = new SendingPceRPCs();
133 sendingPCE.pathComputation();
134 if (sendingPCE.getSuccess()) {
135 message = "Path Computated !";
136 ServicePathRpcResultBuilder tmp = new ServicePathRpcResultBuilder()
137 .setNotificationType(ServicePathNotificationTypes.PathComputationRequest)
138 .setServiceName(input.getServiceName())
139 .setStatus(RpcStatusEx.Successful)
140 .setStatusMessage(message);
141 PathDescriptionBuilder path = sendingPCE.getPathDescription();
143 PathDescription pathDescription = new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
144 .stubpce.rev170426.service.path.rpc.result.PathDescriptionBuilder()
145 .setAToZDirection(path.getAToZDirection())
146 .setZToADirection(path.getZToADirection())
148 tmp.setPathDescription(pathDescription);
150 notification = tmp.build();
152 notificationPublishService.putNotification(notification);
153 } catch (InterruptedException e) {
154 LOG.info("notification offer rejected : " + e);
157 message = "Path Computating failed !";
160 configurationResponseCommon
161 .setAckFinalIndicator("Yes")
162 .setRequestId(input.getServiceHandlerHeader().getRequestId())
163 .setResponseCode("200")
164 .setResponseMessage(message);
167 .setConfigurationResponseCommon(configurationResponseCommon.build());
168 return RpcResultBuilder.success(output.build()).buildFuture();