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
8 package org.opendaylight.transportpce.servicehandler.listeners;
10 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
11 import org.opendaylight.transportpce.common.OperationResult;
12 import org.opendaylight.transportpce.pce.service.PathComputationService;
13 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
14 import org.opendaylight.transportpce.servicehandler.ModelMappingUtils;
15 import org.opendaylight.transportpce.servicehandler.ServiceInput;
16 import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper;
17 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.PathComputationRequestOutput;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.PathComputationRequestOutputBuilder;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.ServicePathRpcResult;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.TransportpcePceListener;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.service.path.rpc.result.PathDescription;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.service.path.rpc.result.PathDescriptionBuilder;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestInput;
25 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.RpcStatusEx;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.response.parameters.sp.ResponseParameters;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.response.parameters.sp.ResponseParametersBuilder;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public class PceListenerImpl implements TransportpcePceListener {
33 private static final Logger LOG = LoggerFactory.getLogger(PceListenerImpl.class);
35 private ServicePathRpcResult servicePathRpcResult;
36 private RendererServiceOperations rendererServiceOperations;
37 private ServiceDataStoreOperations serviceDataStoreOperations;
38 private PCEServiceWrapper pceServiceWrapper;
39 private ServiceInput input;
40 private Boolean serviceReconfigure;
41 private Boolean tempService;
42 private Boolean serviceFeasiblity;
44 public PceListenerImpl(RendererServiceOperations rendererServiceOperations,
45 PathComputationService pathComputationService, NotificationPublishService notificationPublishService,
46 ServiceDataStoreOperations serviceDataStoreOperations) {
47 this.rendererServiceOperations = rendererServiceOperations;
48 this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService, notificationPublishService);
49 this.serviceDataStoreOperations = serviceDataStoreOperations;
50 setServiceReconfigure(false);
52 setTempService(false);
53 setServiceFeasiblity(false);
57 public void onServicePathRpcResult(ServicePathRpcResult notification) {
58 if (!compareServicePathRpcResult(notification)) {
59 servicePathRpcResult = notification;
60 PathDescription pathDescription = null;
61 switch (servicePathRpcResult.getNotificationType().getIntValue()) {
62 case 1: /** path-computation-request. */
63 LOG.info("PCE '{}' Notification received : {}",servicePathRpcResult.getNotificationType().getName(),
65 if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) {
66 LOG.info("PCE calculation done OK !");
67 if (servicePathRpcResult.getPathDescription() != null) {
68 pathDescription = new PathDescriptionBuilder()
69 .setAToZDirection(servicePathRpcResult.getPathDescription().getAToZDirection())
70 .setZToADirection(servicePathRpcResult.getPathDescription().getZToADirection()).build();
71 LOG.info("PathDescription gets : {}", pathDescription);
72 if (!serviceFeasiblity) {
74 LOG.error("Input is null !");
77 OperationResult operationResult = null;
79 operationResult = this.serviceDataStoreOperations
80 .createTempService(input.getTempServiceCreateInput());
81 if (!operationResult.isSuccess()) {
82 LOG.error("Temp Service not created in datastore !");
85 operationResult = this.serviceDataStoreOperations
86 .createService(input.getServiceCreateInput());
87 if (!operationResult.isSuccess()) {
88 LOG.error("Service not created in datastore !");
91 ResponseParameters responseParameters = new ResponseParametersBuilder()
92 .setPathDescription(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c
93 ._interface.service.types.rev171016.response.parameters.sp.response
94 .parameters.PathDescriptionBuilder(pathDescription).build())
96 PathComputationRequestOutput pceResponse = new PathComputationRequestOutputBuilder()
97 .setResponseParameters(responseParameters).build();
98 OperationResult operationServicePathSaveResult =
99 this.serviceDataStoreOperations.createServicePath(input, pceResponse);
100 if (!operationServicePathSaveResult.isSuccess()) {
101 LOG.error("Service Path not created in datastore !");
103 ServiceImplementationRequestInput serviceImplementationRequest =
104 ModelMappingUtils.createServiceImplementationRequest(input, pathDescription);
105 LOG.info("Sending serviceImplementation request : {}", serviceImplementationRequest);
106 this.rendererServiceOperations.serviceImplementation(serviceImplementationRequest);
108 LOG.warn("service-feasibility-check RPC ");
111 LOG.error("'PathDescription' parameter is null ");
114 } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
115 LOG.error("PCE path computation failed !");
119 case 2: /** cancel-resource-reserve. */
120 if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) {
121 LOG.info("PCE cancel resource done OK !");
122 OperationResult deleteServicePathOperationResult =
123 this.serviceDataStoreOperations.deleteServicePath(input.getServiceName());
124 if (!deleteServicePathOperationResult.isSuccess()) {
125 LOG.warn("Service path was not removed from datastore!");
127 OperationResult deleteServiceOperationResult = null;
129 deleteServiceOperationResult =
130 this.serviceDataStoreOperations.deleteTempService(input.getServiceName());
131 if (!deleteServiceOperationResult.isSuccess()) {
132 LOG.warn("Service was not removed from datastore!");
135 deleteServiceOperationResult =
136 this.serviceDataStoreOperations.deleteService(input.getServiceName());
137 if (!deleteServiceOperationResult.isSuccess()) {
138 LOG.warn("Service was not removed from datastore!");
142 * if it was an RPC serviceReconfigure, re-launch PCR.
144 if (this.serviceReconfigure) {
145 LOG.info("cancel resource reserve done, relaunching PCE path computation ...");
146 this.pceServiceWrapper.performPCE(input.getServiceCreateInput(), true);
147 this.serviceReconfigure = false;
149 } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
150 LOG.info("PCE cancel resource failed !");
157 LOG.warn("ServicePathRpcResult already wired !");
161 private Boolean compareServicePathRpcResult(ServicePathRpcResult notification) {
162 Boolean result = true;
163 if (servicePathRpcResult == null) {
166 if (servicePathRpcResult.getNotificationType() != notification.getNotificationType()) {
169 if (servicePathRpcResult.getServiceName() != notification.getServiceName()) {
172 if (servicePathRpcResult.getStatus() != notification.getStatus()) {
175 if (servicePathRpcResult.getStatusMessage() != notification.getStatusMessage()) {
182 public void setInput(ServiceInput serviceInput) {
183 this.input = serviceInput;
186 public void setServiceReconfigure(Boolean serv) {
187 this.serviceReconfigure = serv;
190 public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) {
191 this.serviceDataStoreOperations = serviceData;
194 public void setTempService(Boolean tempService) {
195 this.tempService = tempService;
198 public void setServiceFeasiblity(Boolean serviceFeasiblity) {
199 this.serviceFeasiblity = serviceFeasiblity;