Merge "ROADM To ROADM Path Calculation"
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / service / PCEServiceWrapper.java
1 /*
2  * Copyright © 2017 Orange, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.transportpce.servicehandler.service;
9
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.rev171017.CancelResourceReserveInput;
14 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.CancelResourceReserveInputBuilder;
15 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestInput;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestInputBuilder;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.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.rev171017.RoutingConstraintsSp.PceMetric;
21 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.HardConstraints;
22 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.SoftConstraints;
23 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.service.handler.header.ServiceHandlerHeaderBuilder;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 public class PCEServiceWrapper {
28
29     private static final Logger LOG = LoggerFactory.getLogger(PCEServiceWrapper.class);
30
31     private final PathComputationService pathComputationService;
32
33     public PCEServiceWrapper(PathComputationService pathComputationService) {
34         this.pathComputationService = pathComputationService;
35     }
36
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;
49     }
50
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"
56                 + "requests");
57         ServiceHandlerHeaderBuilder serviceHandlerHeader = new ServiceHandlerHeaderBuilder();
58         if (serviceCreateInput.getSdncRequestHeader() != null) {
59             serviceHandlerHeader.setRequestId(serviceCreateInput.getSdncRequestHeader().getRequestId());
60         }
61         return new PathComputationRequestInputBuilder()
62                 .setServiceName(serviceCreateInput.getServiceName())
63                 .setResourceReserve(reserveResource)
64                 .setServiceHandlerHeader(serviceHandlerHeader.build())
65                 .setHardConstraints(hardConstraints)
66                 .setSoftConstraints(softConstraints)
67                 .setPceMetric(PceMetric.TEMetric)
68                 .setServiceAEnd(ModelMappingUtils.createServiceAEnd(serviceCreateInput.getServiceAEnd()))
69                 .setServiceZEnd(ModelMappingUtils.createServiceZEnd(serviceCreateInput.getServiceZEnd()))
70                 .build();
71     }
72
73     private CancelResourceReserveInput mappingCancelResourceReserve(String serviceName,
74                                                                     SdncRequestHeader sdncRequestHeader) {
75         LOG.debug("Mapping ServiceCreateInput or ServiceFeasibilityCheckInput or serviceReconfigureInput to PCE"
76                 + "requests");
77         ServiceHandlerHeaderBuilder serviceHandlerHeader = new ServiceHandlerHeaderBuilder();
78         if (sdncRequestHeader != null) {
79             serviceHandlerHeader.setRequestId(sdncRequestHeader.getRequestId());
80         }
81         CancelResourceReserveInputBuilder cancelResourceReserveInput = new CancelResourceReserveInputBuilder()
82                 .setServiceName(serviceName)
83                 .setServiceHandlerHeader(serviceHandlerHeader.build());
84         return cancelResourceReserveInput.build();
85     }
86
87 }