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 /* 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.transportpce.b.c
94 ._interface.service.types.rev171016.response.parameters.sp.response
95 .parameters.PathDescriptionBuilder(pathDescription).build())
97 PathComputationRequestOutput pceResponse = new PathComputationRequestOutputBuilder()
98 .setResponseParameters(responseParameters).build();
99 OperationResult operationServicePathSaveResult =
100 this.serviceDataStoreOperations.createServicePath(input, pceResponse);
101 if (!operationServicePathSaveResult.isSuccess()) {
102 LOG.error("Service Path not created in datastore !");
104 ServiceImplementationRequestInput serviceImplementationRequest =
105 ModelMappingUtils.createServiceImplementationRequest(input, pathDescription);
106 LOG.info("Sending serviceImplementation request : {}", serviceImplementationRequest);
107 this.rendererServiceOperations.serviceImplementation(serviceImplementationRequest);
109 LOG.warn("service-feasibility-check RPC ");
112 LOG.error("'PathDescription' parameter is null ");
115 } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
116 LOG.error("PCE path computation failed !");
120 /* cancel-resource-reserve. */
122 if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) {
123 LOG.info("PCE cancel resource done OK !");
124 OperationResult deleteServicePathOperationResult =
125 this.serviceDataStoreOperations.deleteServicePath(input.getServiceName());
126 if (!deleteServicePathOperationResult.isSuccess()) {
127 LOG.warn("Service path was not removed from datastore!");
129 OperationResult deleteServiceOperationResult = null;
131 deleteServiceOperationResult =
132 this.serviceDataStoreOperations.deleteTempService(input.getServiceName());
133 if (!deleteServiceOperationResult.isSuccess()) {
134 LOG.warn("Service was not removed from datastore!");
137 deleteServiceOperationResult =
138 this.serviceDataStoreOperations.deleteService(input.getServiceName());
139 if (!deleteServiceOperationResult.isSuccess()) {
140 LOG.warn("Service was not removed from datastore!");
144 * if it was an RPC serviceReconfigure, re-launch PCR.
146 if (this.serviceReconfigure) {
147 LOG.info("cancel resource reserve done, relaunching PCE path computation ...");
148 this.pceServiceWrapper.performPCE(input.getServiceCreateInput(), true);
149 this.serviceReconfigure = false;
151 } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
152 LOG.info("PCE cancel resource failed !");
159 LOG.warn("ServicePathRpcResult already wired !");
163 private Boolean compareServicePathRpcResult(ServicePathRpcResult notification) {
164 Boolean result = true;
165 if (servicePathRpcResult == null) {
168 if (servicePathRpcResult.getNotificationType() != notification.getNotificationType()) {
171 if (servicePathRpcResult.getServiceName() != notification.getServiceName()) {
174 if (servicePathRpcResult.getStatus() != notification.getStatus()) {
177 if (servicePathRpcResult.getStatusMessage() != notification.getStatusMessage()) {
184 public void setInput(ServiceInput serviceInput) {
185 this.input = serviceInput;
188 public void setServiceReconfigure(Boolean serv) {
189 this.serviceReconfigure = serv;
192 public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) {
193 this.serviceDataStoreOperations = serviceData;
196 public void setTempService(Boolean tempService) {
197 this.tempService = tempService;
200 public void setServiceFeasiblity(Boolean serviceFeasiblity) {
201 this.serviceFeasiblity = serviceFeasiblity;