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.service;
10 import org.opendaylight.transportpce.pce.service.PathComputationService;
11 import org.opendaylight.transportpce.servicehandler.MappingConstraints;
12 import org.opendaylight.transportpce.servicehandler.ModelMappingUtils;
13 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.CancelResourceReserveInput;
14 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.CancelResourceReserveInputBuilder;
15 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.PathComputationRequestInput;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.PathComputationRequestInputBuilder;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.PathComputationRequestOutput;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeader;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput;
20 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.RoutingConstraintsSp;
21 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.routing.constraints.sp.HardConstraints;
22 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.routing.constraints.sp.SoftConstraints;
23 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.service.handler.header.ServiceHandlerHeaderBuilder;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public class PCEServiceWrapper {
29 private static final Logger LOG = LoggerFactory.getLogger(PCEServiceWrapper.class);
31 private final PathComputationService pathComputationService;
33 public PCEServiceWrapper(PathComputationService pathComputationService) {
34 this.pathComputationService = pathComputationService;
37 public PathComputationRequestOutput performPCE(ServiceCreateInput serviceCreateInput, boolean reserveResource) {
38 MappingConstraints mappingConstraints = new MappingConstraints(serviceCreateInput.getHardConstraints(),
39 serviceCreateInput.getSoftConstraints());
40 mappingConstraints.serviceToServicePathConstarints();
41 PathComputationRequestInput pathComputationRequestInput =
42 createPceRequestInput(serviceCreateInput, mappingConstraints.getServicePathHardConstraints(),
43 mappingConstraints.getServicePathSoftConstraints(), reserveResource);
44 LOG.debug("Calling path computation.");
45 PathComputationRequestOutput pathComputationRequestOutput
46 = this.pathComputationService.pathComputationRequest(pathComputationRequestInput);
47 LOG.debug("Path computation done.");
48 return pathComputationRequestOutput;
51 private PathComputationRequestInput createPceRequestInput(ServiceCreateInput serviceCreateInput,
52 HardConstraints hardConstraints,
53 SoftConstraints softConstraints,
54 Boolean reserveResource) {
55 LOG.info("Mapping ServiceCreateInput or ServiceFeasibilityCheckInput or serviceReconfigureInput to PCE"
57 ServiceHandlerHeaderBuilder serviceHandlerHeader = new ServiceHandlerHeaderBuilder();
58 if (serviceCreateInput.getSdncRequestHeader() != null) {
59 serviceHandlerHeader.setRequestId(serviceCreateInput.getSdncRequestHeader().getRequestId());
61 return new PathComputationRequestInputBuilder()
62 .setServiceName(serviceCreateInput.getServiceName())
63 .setResourceReserve(reserveResource)
64 .setServiceHandlerHeader(serviceHandlerHeader.build())
65 .setHardConstraints(hardConstraints)
66 .setSoftConstraints(softConstraints)
67 .setPceMetric(RoutingConstraintsSp.PceMetric.TEMetric)
68 .setServiceAEnd(ModelMappingUtils.createServiceAEnd(serviceCreateInput.getServiceAEnd()))
69 .setServiceZEnd(ModelMappingUtils.createServiceZEnd(serviceCreateInput.getServiceZEnd()))
73 private CancelResourceReserveInput mappingCancelResourceReserve(String serviceName,
74 SdncRequestHeader sdncRequestHeader) {
75 LOG.debug("Mapping ServiceCreateInput or ServiceFeasibilityCheckInput or serviceReconfigureInput to PCE"
77 ServiceHandlerHeaderBuilder serviceHandlerHeader = new ServiceHandlerHeaderBuilder();
78 if (sdncRequestHeader != null) {
79 serviceHandlerHeader.setRequestId(sdncRequestHeader.getRequestId());
81 CancelResourceReserveInputBuilder cancelResourceReserveInput = new CancelResourceReserveInputBuilder()
82 .setServiceName(serviceName)
83 .setServiceHandlerHeader(serviceHandlerHeader.build());
84 return cancelResourceReserveInput.build();