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
9 package org.opendaylight.transportpce.servicehandler.validation.checks;
11 import org.opendaylight.transportpce.servicehandler.ServiceEndpointType;
12 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ServiceEndpoint;
13 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.RxDirection;
14 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.TxDirection;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.lgx.Lgx;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.port.Port;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.ServiceFormat;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 * Class for checking missing info on Tx/Rx for A/Z end.
25 public final class ServicehandlerTxRxCheck {
27 private static final Logger LOG = LoggerFactory.getLogger(ServicehandlerTxRxCheck.class);
30 * Check if a String is not null and not equal to ''.
34 * @return true if String ok false if not
36 public static boolean checkString(String value) {
37 return ((value != null) && (value.compareTo("") != 0));
41 * check if Port info is compliant.
45 * @return true if String ok false if not
47 public static boolean checkPort(Port port) {
48 boolean result = false;
50 String portDeviceName = port.getPortDeviceName();
51 String portType = port.getPortType();
52 String portName = port.getPortName();
53 String portRack = port.getPortRack();
54 String portShelf = port.getPortShelf();
56 if (checkString(portDeviceName) && checkString(portType) && checkString(portName) && checkString(portRack)
57 && checkString(portShelf)) {
65 * Check if lgx info is compliant.
69 * @return true if String ok false if not
71 public static boolean checkLgx(Lgx lgx) {
72 boolean result = false;
74 String lgxDeviceName = lgx.getLgxDeviceName();
75 String lgxPortName = lgx.getLgxPortName();
76 String lgxPortRack = lgx.getLgxPortRack();
77 String lgxPortShelf = lgx.getLgxPortShelf();
78 if (checkString(lgxDeviceName) && checkString(lgxPortName) && checkString(lgxPortRack)
79 && checkString(lgxPortShelf)) {
87 * Check if Tx/Rx Direction complaincy info.
94 * @return <code>true</code> if check is ok <code>false</code> else
96 public static ComplianceCheckResult checkTxOrRxInfo(TxDirection txDirection, RxDirection rxDirection) {
97 boolean result = true;
99 if (txDirection != null) {
100 if (!checkPort(txDirection.getPort())) {
102 message = "Service TxDirection Port is not correctly set";
103 } else if (!checkLgx(txDirection.getLgx())) {
105 message = "Service TxDirection Lgx is not correctly set";
106 } else if (rxDirection != null) {
107 if (!checkPort(rxDirection.getPort())) {
109 message = "Service RxDirection Port is not correctly set";
110 } else if (!checkLgx(rxDirection.getLgx())) {
112 message = "Service RxDirection Lgx is not correctly set";
116 message = "Service RxDirection is not correctly set";
120 message = "Service TxDirection is not correctly set";
122 return new ComplianceCheckResult(result, message);
126 * Check Compliancy of Service TxRx info.
127 * @param serviceEnd Service Endpoint
128 * @param endpointType Endpoint type
130 * @return true if String ok false if not
132 public static ComplianceCheckResult check(ServiceEndpoint serviceEnd, ServiceEndpointType endpointType) {
133 boolean result = true;
135 if (serviceEnd != null) {
137 Long serviceRate = serviceEnd.getServiceRate();
138 ServiceFormat serviceformat = serviceEnd.getServiceFormat();
139 String clli = serviceEnd.getClli();
140 if ((serviceRate == null) || (serviceRate <= 0)) {
142 message = "Service " + endpointType + " rate is not set";
144 } else if (serviceformat == null) {
146 message = "Service " + endpointType + " format is not set";
148 } else if (!checkString(clli)) {
150 message = "Service" + endpointType + " clli format is not set";
153 ComplianceCheckResult complianceCheckResult
154 = checkTxOrRxInfo(serviceEnd.getTxDirection(), serviceEnd.getRxDirection());
155 if (!complianceCheckResult.hasPassed()) {
157 message = complianceCheckResult.getMessage();
160 } catch (NullPointerException e) {
161 message = "Service " + endpointType + " rate, format or clli is not set";
162 LOG.error(message, e);
163 return new ComplianceCheckResult(false, message);
167 message = endpointType + " is not set";
170 return new ComplianceCheckResult(result, message);
173 private ServicehandlerTxRxCheck() {