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.rev170426.CancelResourceReserveInput;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.CancelResourceReserveOutput;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.CancelResourceReserveOutputBuilder;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.PathComputationRequestInput;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.PathComputationRequestOutput;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.PathComputationRequestOutputBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.ServicePathRpcResult;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.ServicePathRpcResultBuilder;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.service.path.rpc.result.PathDescription;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.AToZDirection;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ZToADirection;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.RpcStatusEx;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.ServicePathNotificationTypes;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.response.parameters.sp.ResponseParametersBuilder;
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.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();
134 LOG.info("PCE response: {} {}", message, responseCode);
135 if ((sendingPCE.getSuccess() == false) || (path == null)) {
136 configurationResponseCommon
137 .setAckFinalIndicator("Yes")
138 .setRequestId(input.getServiceHandlerHeader().getRequestId())
139 .setResponseCode(responseCode)
140 .setResponseMessage(message);
142 output.setConfigurationResponseCommon(configurationResponseCommon.build());
143 return output.build();
146 // Path calculator returned Success
147 configurationResponseCommon
148 .setAckFinalIndicator("Yes")
149 .setRequestId(input.getServiceHandlerHeader().getRequestId())
150 .setResponseCode(responseCode)
151 .setResponseMessage(message);
153 ServicePathRpcResultBuilder tmp = new ServicePathRpcResultBuilder()
154 .setNotificationType(ServicePathNotificationTypes.PathComputationRequest)
155 .setServiceName(input.getServiceName())
156 .setStatus(RpcStatusEx.Successful)
157 .setStatusMessage(message);
158 PathDescription pathDescription = new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
159 .pce.rev170426.service.path.rpc.result.PathDescriptionBuilder()
160 .setAToZDirection(path.getAToZDirection())
161 .setZToADirection(path.getZToADirection())
163 tmp.setPathDescription(pathDescription);
165 notification = tmp.build();
167 notificationPublishService.putNotification(notification);
168 } catch (InterruptedException e) {
169 LOG.error("notification offer rejected : {}", e.getMessage());
172 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types
173 .rev170426.response.parameters.sp.response.parameters.PathDescription pathDescription1
174 = new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types
175 .rev170426.response.parameters.sp.response.parameters.PathDescriptionBuilder()
176 .setAToZDirection(path.getAToZDirection())
177 .setZToADirection(path.getZToADirection())
179 ResponseParametersBuilder rpb = new ResponseParametersBuilder()
180 .setPathDescription(pathDescription1);
182 output.setConfigurationResponseCommon(configurationResponseCommon.build())
183 .setResponseParameters(rpb.build());
186 AToZDirection atoz = pathDescription.getAToZDirection();
187 if (atoz != null && atoz.getAToZ() != null) {
188 LOG.info("Impl AtoZ Notification: [{}] elements in description", atoz.getAToZ().size());
189 for (int i = 0; i < atoz.getAToZ().size(); i++) {
190 LOG.info("Impl AtoZ Notification: [{}] {}", i, atoz.getAToZ().get(i));
193 ZToADirection ztoa = pathDescription.getZToADirection();
194 if (ztoa != null && ztoa.getZToA() != null) {
195 LOG.info("Impl ZtoA Notification: [{}] elements in description", ztoa.getZToA().size());
196 for (int i = 0; i < ztoa.getZToA().size(); i++) {
197 LOG.info("Impl ZtoA Notification: [{}] {}", i, ztoa.getZToA().get(i));
201 return output.build();