2 * Copyright © 2017 AT&T, 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.transportpce.pce.service;
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
12 import org.opendaylight.transportpce.pce.PceComplianceCheck;
13 import org.opendaylight.transportpce.pce.PceComplianceCheckResult;
14 import org.opendaylight.transportpce.pce.PceSendingPceRPCs;
15 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.CancelResourceReserveInput;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.CancelResourceReserveOutput;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.CancelResourceReserveOutputBuilder;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestInput;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutput;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutputBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.ServicePathRpcResult;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.ServicePathRpcResultBuilder;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.service.path.rpc.result.PathDescription;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.service.path.rpc.result.PathDescriptionBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.AToZDirection;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ZToADirection;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.RpcStatusEx;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.ServicePathNotificationTypes;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.response.parameters.sp.ResponseParametersBuilder;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public class PathComputationServiceImpl implements PathComputationService {
36 private static final Logger LOG = LoggerFactory.getLogger(PathComputationServiceImpl.class);
38 private final NotificationPublishService notificationPublishService;
39 private final DataBroker dataBroker;
41 public PathComputationServiceImpl(DataBroker dataBroker,
42 NotificationPublishService notificationPublishService) {
43 this.notificationPublishService = notificationPublishService;
44 this.dataBroker = dataBroker;
56 public CancelResourceReserveOutput cancelResourceReserve(CancelResourceReserveInput input) {
57 LOG.info("cancelResourceReserve");
60 ServicePathRpcResult notification = new ServicePathRpcResultBuilder()
61 .setNotificationType(ServicePathNotificationTypes.CancelResourceReserve)
62 .setServiceName(input.getServiceName())
63 .setStatus(RpcStatusEx.Pending)
64 .setStatusMessage("Service compliant, submitting cancelResourceReserve Request ...")
67 notificationPublishService.putNotification(notification);
68 } catch (InterruptedException e) {
69 LOG.info("notification offer rejected : ", e.getMessage());
72 PceSendingPceRPCs sendingPCE = new PceSendingPceRPCs();
73 sendingPCE.cancelResourceReserve();
74 if (sendingPCE.getSuccess()) {
75 message = "ResourceReserve cancelled !";
77 message = "Cancelling ResourceReserve failed !";
80 ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder();
81 configurationResponseCommon
82 .setAckFinalIndicator("Yes")
83 .setRequestId(input.getServiceHandlerHeader().getRequestId())
84 .setResponseCode("200")
85 .setResponseMessage("")
86 .setResponseMessage(message);
87 CancelResourceReserveOutputBuilder output = new CancelResourceReserveOutputBuilder();
88 output.setConfigurationResponseCommon(configurationResponseCommon.build());
89 return output.build();
93 public PathComputationRequestOutput pathComputationRequest(PathComputationRequestInput input) {
94 LOG.info("pathComputationRequest");
96 PathComputationRequestOutputBuilder output = new PathComputationRequestOutputBuilder();
97 ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder();
99 PceComplianceCheckResult check = PceComplianceCheck.check(input);
100 if (!check.hasPassed()) {
101 configurationResponseCommon
102 .setAckFinalIndicator("Yes")
103 .setRequestId(input.getServiceHandlerHeader().getRequestId())
104 .setResponseCode("Path not calculated")
105 .setResponseMessage(check.getMessage());
108 output.setConfigurationResponseCommon(configurationResponseCommon.build())
109 .setResponseParameters(null);
111 return output.build();
113 ServicePathRpcResult notification = new ServicePathRpcResultBuilder()
114 .setNotificationType(ServicePathNotificationTypes.PathComputationRequest)
115 .setServiceName(input.getServiceName())
116 .setStatus(RpcStatusEx.Pending)
117 .setStatusMessage("Service compliant, submitting pathComputation Request ...")
120 notificationPublishService.putNotification(notification);
121 } catch (InterruptedException e) {
122 LOG.info("notification offer rejected : ", e.getMessage());
126 String responseCode = "";
127 PceSendingPceRPCs sendingPCE = new PceSendingPceRPCs(input, dataBroker);
128 sendingPCE.pathComputation();
129 message = sendingPCE.getMessage();
130 responseCode = sendingPCE.getResponseCode();
131 PathDescriptionBuilder path = null;
132 path = sendingPCE.getPathDescription();
135 LOG.info("PCE response: {} {}", message, responseCode);
136 if ((sendingPCE.getSuccess() == false) || (path == null)) {
137 configurationResponseCommon
138 .setAckFinalIndicator("Yes")
139 .setRequestId(input.getServiceHandlerHeader().getRequestId())
140 .setResponseCode(responseCode)
141 .setResponseMessage(message);
143 output.setConfigurationResponseCommon(configurationResponseCommon.build());
144 return output.build();
147 // Path calculator returned Success
148 configurationResponseCommon
149 .setAckFinalIndicator("Yes")
150 .setRequestId(input.getServiceHandlerHeader().getRequestId())
151 .setResponseCode(responseCode)
152 .setResponseMessage(message);
154 ServicePathRpcResultBuilder tmp = new ServicePathRpcResultBuilder()
155 .setNotificationType(ServicePathNotificationTypes.PathComputationRequest)
156 .setServiceName(input.getServiceName())
157 .setStatus(RpcStatusEx.Successful)
158 .setStatusMessage(message);
159 PathDescription pathDescription = new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
160 .pce.rev171017.service.path.rpc.result.PathDescriptionBuilder()
161 .setAToZDirection(path.getAToZDirection())
162 .setZToADirection(path.getZToADirection())
164 tmp.setPathDescription(pathDescription);
166 notification = tmp.build();
168 notificationPublishService.putNotification(notification);
169 } catch (InterruptedException e) {
170 LOG.error("notification offer rejected : {}", e.getMessage());
173 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types
174 .rev171016.response.parameters.sp.response.parameters.PathDescription pathDescription1
175 = new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types
176 .rev171016.response.parameters.sp.response.parameters.PathDescriptionBuilder()
177 .setAToZDirection(path.getAToZDirection())
178 .setZToADirection(path.getZToADirection())
180 ResponseParametersBuilder rpb = new ResponseParametersBuilder()
181 .setPathDescription(pathDescription1);
183 output.setConfigurationResponseCommon(configurationResponseCommon.build())
184 .setResponseParameters(rpb.build());
187 AToZDirection atoz = pathDescription.getAToZDirection();
188 if ((atoz != null) && (atoz.getAToZ() != null)) {
189 LOG.info("Impl AtoZ Notification: [{}] elements in description", atoz.getAToZ().size());
190 for (int i = 0; i < atoz.getAToZ().size(); i++) {
191 LOG.info("Impl AtoZ Notification: [{}] {}", i, atoz.getAToZ().get(i));
194 ZToADirection ztoa = pathDescription.getZToADirection();
195 if ((ztoa != null) && (ztoa.getZToA() != null)) {
196 LOG.info("Impl ZtoA Notification: [{}] elements in description", ztoa.getZToA().size());
197 for (int i = 0; i < ztoa.getZToA().size(); i++) {
198 LOG.info("Impl ZtoA Notification: [{}] {}", i, ztoa.getZToA().get(i));
202 return output.build();