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.mdsal.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.rev200128.PathComputationRequestOutput;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutputBuilder;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.ServicePathRpcResult;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.TransportpcePceListener;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.service.path.rpc.result.PathDescription;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.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.rev200128.RpcStatusEx;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParameters;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.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 /* path-computation-request. */
64 LOG.info("PCE '{}' Notification received : {}",servicePathRpcResult.getNotificationType().getName(),
66 if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) {
67 LOG.info("PCE calculation done OK !");
68 if (servicePathRpcResult.getPathDescription() != null) {
69 pathDescription = new PathDescriptionBuilder()
70 .setAToZDirection(servicePathRpcResult.getPathDescription().getAToZDirection())
71 .setZToADirection(servicePathRpcResult.getPathDescription().getZToADirection()).build();
72 LOG.info("PathDescription gets : {}", pathDescription);
73 if (!serviceFeasiblity) {
75 LOG.error("Input is null !");
78 OperationResult operationResult = null;
80 operationResult = this.serviceDataStoreOperations
81 .createTempService(input.getTempServiceCreateInput());
82 if (!operationResult.isSuccess()) {
83 LOG.error("Temp Service not created in datastore !");
86 operationResult = this.serviceDataStoreOperations
87 .createService(input.getServiceCreateInput());
88 if (!operationResult.isSuccess()) {
89 LOG.error("Service not created in datastore !");
92 ResponseParameters responseParameters = new ResponseParametersBuilder()
93 .setPathDescription(new org.opendaylight.yang.gen.v1.http.org
94 .transportpce.b.c._interface.service.types.rev200128
95 .response.parameters.sp.response.parameters
96 .PathDescriptionBuilder(pathDescription).build())
98 PathComputationRequestOutput pceResponse = new PathComputationRequestOutputBuilder()
99 .setResponseParameters(responseParameters).build();
100 OperationResult operationServicePathSaveResult =
101 this.serviceDataStoreOperations.createServicePath(input, pceResponse);
102 if (!operationServicePathSaveResult.isSuccess()) {
103 LOG.error("Service Path not created in datastore !");
105 ServiceImplementationRequestInput serviceImplementationRequest =
106 ModelMappingUtils.createServiceImplementationRequest(input, pathDescription);
107 LOG.info("Sending serviceImplementation request : {}", serviceImplementationRequest);
108 this.rendererServiceOperations.serviceImplementation(serviceImplementationRequest);
110 LOG.warn("service-feasibility-check RPC ");
113 LOG.error("'PathDescription' parameter is null ");
116 } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
117 LOG.error("PCE path computation failed !");
121 /* cancel-resource-reserve. */
123 if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) {
124 LOG.info("PCE cancel resource done OK !");
125 OperationResult deleteServicePathOperationResult =
126 this.serviceDataStoreOperations.deleteServicePath(input.getServiceName());
127 if (!deleteServicePathOperationResult.isSuccess()) {
128 LOG.warn("Service path was not removed from datastore!");
130 OperationResult deleteServiceOperationResult = null;
132 deleteServiceOperationResult =
133 this.serviceDataStoreOperations.deleteTempService(input.getServiceName());
134 if (!deleteServiceOperationResult.isSuccess()) {
135 LOG.warn("Service was not removed from datastore!");
138 deleteServiceOperationResult =
139 this.serviceDataStoreOperations.deleteService(input.getServiceName());
140 if (!deleteServiceOperationResult.isSuccess()) {
141 LOG.warn("Service was not removed from datastore!");
145 * if it was an RPC serviceReconfigure, re-launch PCR.
147 if (this.serviceReconfigure) {
148 LOG.info("cancel resource reserve done, relaunching PCE path computation ...");
149 this.pceServiceWrapper.performPCE(input.getServiceCreateInput(), true);
150 this.serviceReconfigure = false;
152 } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
153 LOG.info("PCE cancel resource failed !");
160 LOG.warn("ServicePathRpcResult already wired !");
164 private Boolean compareServicePathRpcResult(ServicePathRpcResult notification) {
165 Boolean result = true;
166 if (servicePathRpcResult == null) {
169 if (servicePathRpcResult.getNotificationType() != notification.getNotificationType()) {
172 if (servicePathRpcResult.getServiceName() != notification.getServiceName()) {
175 if (servicePathRpcResult.getStatus() != notification.getStatus()) {
178 if (servicePathRpcResult.getStatusMessage() != notification.getStatusMessage()) {
185 public void setInput(ServiceInput serviceInput) {
186 this.input = serviceInput;
189 public void setServiceReconfigure(Boolean serv) {
190 this.serviceReconfigure = serv;
193 public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) {
194 this.serviceDataStoreOperations = serviceData;
197 public void setTempService(Boolean tempService) {
198 this.tempService = tempService;
201 public void setServiceFeasiblity(Boolean serviceFeasiblity) {
202 this.serviceFeasiblity = serviceFeasiblity;