Merge changes I04980c0b,Ib74e699a,I6ca86692,Ida6061da,Iea661424, ...
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / validation / ServiceCreateValidation.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
9 package org.opendaylight.transportpce.servicehandler.validation;
10
11 import org.opendaylight.transportpce.common.OperationResult;
12 import org.opendaylight.transportpce.servicehandler.ServiceEndpointType;
13 import org.opendaylight.transportpce.servicehandler.ServiceInput;
14 import org.opendaylight.transportpce.servicehandler.validation.checks.CheckCoherencyHardSoft;
15 import org.opendaylight.transportpce.servicehandler.validation.checks.ComplianceCheckResult;
16 import org.opendaylight.transportpce.servicehandler.validation.checks.ServicehandlerComplianceCheck;
17 import org.opendaylight.transportpce.servicehandler.validation.checks.ServicehandlerServiceResiliencyCheck;
18 import org.opendaylight.transportpce.servicehandler.validation.checks.ServicehandlerTxRxCheck;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.ConnectionType;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.RpcActions;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.sdnc.request.header.SdncRequestHeader;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 public final class ServiceCreateValidation {
26     private static final Logger LOG = LoggerFactory.getLogger(ServiceCreateValidation.class);
27
28     public static OperationResult validateServiceCreateRequest(ServiceInput input, RpcActions rpcActions) {
29         /*
30          * Upon receipt of service
31          * -create RPC, service header and sdnc
32          * -request header compliancy are verified.
33          */
34         LOG.debug("checking Service Compliance ...");
35         String serviceNmame = input.getServiceName();
36         SdncRequestHeader sdncRequestHeader = input.getSdncRequestHeader();
37         ConnectionType conType = input.getConnectionType();
38         ComplianceCheckResult serviceHandlerCheckResult = ServicehandlerComplianceCheck.check(
39                 serviceNmame, sdncRequestHeader, conType, rpcActions, true, true);
40         if (serviceHandlerCheckResult.hasPassed()) {
41             LOG.debug("Service request compliant !");
42         } else {
43             return OperationResult.failed(serviceHandlerCheckResult.getMessage());
44         }
45         /*
46          * If compliant, service-request parameters are verified in order to
47          * check if there is no missing parameter that prevents calculating
48          * a path and implement a service.
49          */
50         LOG.debug("checking Tx/Rx Info for AEnd ...");
51         ComplianceCheckResult txrxCheckAEnd = ServicehandlerTxRxCheck.check(input.getServiceAEnd(),
52                 ServiceEndpointType.SERVICEAEND);
53         if (txrxCheckAEnd.hasPassed()) {
54             LOG.debug("Tx/Rx Info for AEnd checked !");
55         } else {
56             return OperationResult.failed(txrxCheckAEnd.getMessage());
57         }
58
59         LOG.debug("checking Tx/Rx Info for ZEnd ...");
60         ComplianceCheckResult txrxCheckZEnd = ServicehandlerTxRxCheck.check(input.getServiceZEnd(),
61                 ServiceEndpointType.SERVICEZEND);
62         if (txrxCheckZEnd.hasPassed()) {
63             LOG.debug("Tx/Rx Info for ZEnd checked");
64             /*
65              * If OK, common-id is verified in order to see if there is
66              * no routing policy provided. If yes, the routing
67              * constraints of the policy are recovered and coherency
68              * with hard/soft constraints provided in the input of the
69              * RPC.
70              */
71         } else {
72             return OperationResult.failed(txrxCheckZEnd.getMessage());
73         }
74
75         if (input.getCommonId() != null) {
76             LOG.debug("Common-id specified");
77             // Check coherency with hard/soft constraints
78             if (CheckCoherencyHardSoft.check(input.getHardConstraints(), input.getSoftConstraints())) {
79                 LOG.debug("hard/soft constraints coherent !");
80             } else {
81                 return OperationResult.failed("hard/soft constraints are not coherent !");
82             }
83         } else {
84             LOG.warn("Common-id not specified !");
85         }
86
87         if (input.getServiceResiliency() != null) {
88             LOG.debug("Service-resiliency specified");
89             ComplianceCheckResult complianceCheckResult = ServicehandlerServiceResiliencyCheck
90                     .check(input.getServiceResiliency());
91             if (complianceCheckResult.hasPassed()) {
92                 LOG.debug("Service-resiliency checked !");
93             } else {
94                 return OperationResult.failed(complianceCheckResult.getMessage());
95             }
96         }
97
98         return OperationResult.ok("Validation successful.");
99     }
100
101     private ServiceCreateValidation() {
102     }
103
104 }