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.rev171017.PathComputationRequestOutput;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutputBuilder;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.ServicePathRpcResult;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.TransportpcePceListener;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.service.path.rpc.result.PathDescription;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.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;
43 public PceListenerImpl(RendererServiceOperations rendererServiceOperations,
44 PathComputationService pathComputationService, NotificationPublishService notificationPublishService,
45 ServiceDataStoreOperations serviceDataStoreOperations) {
46 this.rendererServiceOperations = rendererServiceOperations;
47 this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService, notificationPublishService);
48 this.serviceDataStoreOperations = serviceDataStoreOperations;
49 setServiceReconfigure(false);
51 setTempService(false);
55 public void onServicePathRpcResult(ServicePathRpcResult notification) {
56 if (!compareServicePathRpcResult(notification)) {
57 servicePathRpcResult = notification;
58 PathDescription pathDescription = null;
59 switch (servicePathRpcResult.getNotificationType().getIntValue()) {
60 case 1: /** path-computation-request. */
61 LOG.info("PCE '{}' Notification received : {}",servicePathRpcResult.getNotificationType().getName(),
63 if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) {
64 LOG.info("PCE calculation done OK !");
65 if (servicePathRpcResult.getPathDescription() != null) {
66 pathDescription = new PathDescriptionBuilder()
67 .setAToZDirection(servicePathRpcResult.getPathDescription().getAToZDirection())
68 .setZToADirection(servicePathRpcResult.getPathDescription().getZToADirection()).build();
69 LOG.info("PathDescription gets : {}", pathDescription);
71 LOG.error("Input is null !");
74 OperationResult operationResult = null;
76 operationResult = this.serviceDataStoreOperations
77 .createTempService(input.getTempServiceCreateInput());
78 if (!operationResult.isSuccess()) {
79 LOG.error("Temp Service not created in datastore !");
82 operationResult = this.serviceDataStoreOperations
83 .createService(input.getServiceCreateInput());
84 if (!operationResult.isSuccess()) {
85 LOG.error("Service not created in datastore !");
88 ResponseParameters responseParameters = new ResponseParametersBuilder()
89 .setPathDescription(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c
90 ._interface.service.types.rev171016.response.parameters.sp.response
91 .parameters.PathDescriptionBuilder(pathDescription).build())
93 PathComputationRequestOutput pceResponse = new PathComputationRequestOutputBuilder()
94 .setResponseParameters(responseParameters).build();
95 OperationResult operationServicePathSaveResult =
96 this.serviceDataStoreOperations.createServicePath(input, pceResponse);
97 if (!operationServicePathSaveResult.isSuccess()) {
98 LOG.error("Service Path not created in datastore !");
100 ServiceImplementationRequestInput serviceImplementationRequest =
101 ModelMappingUtils.createServiceImplementationRequest(input, pathDescription);
102 LOG.info("Sending serviceImplementation request : {}", serviceImplementationRequest);
103 this.rendererServiceOperations.serviceImplementation(serviceImplementationRequest);
105 LOG.error("'PathDescription' parameter is null ");
108 } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
109 LOG.error("PCE path computation failed !");
113 case 2: /** cancel-resource-reserve. */
114 if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) {
115 LOG.info("PCE cancel resource done OK !");
116 OperationResult deleteServicePathOperationResult =
117 this.serviceDataStoreOperations.deleteServicePath(input.getServiceName());
118 if (!deleteServicePathOperationResult.isSuccess()) {
119 LOG.warn("Service path was not removed from datastore!");
121 OperationResult deleteServiceOperationResult = null;
123 deleteServiceOperationResult =
124 this.serviceDataStoreOperations.deleteTempService(input.getServiceName());
125 if (!deleteServiceOperationResult.isSuccess()) {
126 LOG.warn("Service was not removed from datastore!");
129 deleteServiceOperationResult =
130 this.serviceDataStoreOperations.deleteService(input.getServiceName());
131 if (!deleteServiceOperationResult.isSuccess()) {
132 LOG.warn("Service was not removed from datastore!");
136 * if it was an RPC serviceReconfigure, re-launch PCR.
138 if (this.serviceReconfigure) {
139 LOG.info("cancel resource reserve done, relaunching PCE path computation ...");
140 this.pceServiceWrapper.performPCE(input.getServiceCreateInput(), true);
141 this.serviceReconfigure = false;
143 } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
144 LOG.info("PCE cancel resource failed !");
151 LOG.warn("ServicePathRpcResult already wired !");
155 private Boolean compareServicePathRpcResult(ServicePathRpcResult notification) {
156 Boolean result = true;
157 if (servicePathRpcResult == null) {
160 if (servicePathRpcResult.getNotificationType() != notification.getNotificationType()) {
163 if (servicePathRpcResult.getServiceName() != notification.getServiceName()) {
166 if (servicePathRpcResult.getStatus() != notification.getStatus()) {
169 if (servicePathRpcResult.getStatusMessage() != notification.getStatusMessage()) {
176 public void setInput(ServiceInput serviceInput) {
177 this.input = serviceInput;
180 public void setServiceReconfigure(Boolean serv) {
181 this.serviceReconfigure = serv;
184 public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) {
185 this.serviceDataStoreOperations = serviceData;
188 public void setTempService(Boolean tempService) {
189 this.tempService = tempService;