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;
20 * Class for checking missing info on Tx/Rx for A/Z end.
23 public final class ServicehandlerTxRxCheck {
25 // This is class is public so that these messages can be accessed from Junit (avoid duplications).
26 public static final class LogMessages {
28 private static final String SERVICE = "Service ";
29 public static final String TXDIR_NOT_SET;
30 public static final String TXDIR_PORT_NOT_SET;
31 public static final String TXDIR_LGX_NOT_SET;
32 public static final String RXDIR_NOT_SET;
33 public static final String RXDIR_PORT_NOT_SET;
34 public static final String RXDIR_LGX_NOT_SET;
36 // Static blocks are generated once and spare memory.
38 TXDIR_NOT_SET = "Service TxDirection is not correctly set";
39 RXDIR_NOT_SET = "Service RxDirection is not correctly set";
40 TXDIR_PORT_NOT_SET = "Service TxDirection Port is not correctly set";
41 TXDIR_LGX_NOT_SET = "Service TxDirection Lgx is not correctly set";
42 RXDIR_PORT_NOT_SET = "Service RxDirection Port is not correctly set";
43 RXDIR_LGX_NOT_SET = "Service RxDirection Lgx is not correctly set";
46 public static String endpointTypeNotSet(ServiceEndpointType endpointType) {
47 return SERVICE + endpointType + " is not set";
50 public static String rateNotSet(ServiceEndpointType endpointType) {
51 return SERVICE + endpointType + " rate is not set";
54 public static String formatNotSet(ServiceEndpointType endpointType) {
55 return SERVICE + endpointType + " format is not set";
58 public static String clliNotSet(ServiceEndpointType endpointType) {
59 return SERVICE + endpointType + " clli is not set";
62 private LogMessages() {
68 * Check if a String is not null and not equal to ''.
72 * @return true if String ok false if not
74 public static boolean checkString(String value) {
75 return (value != null && !value.isEmpty());
79 * check if Port info is compliant.
83 * @return true if String ok false if not
85 @SuppressWarnings("java:S1067")
86 //sonar issue Reduce the number of conditional operators (4) used in the expression (maximum allowed 3)
87 //won't be fixed because of functional checks needed
88 public static boolean checkPort(Port port) {
92 String portDeviceName = port.getPortDeviceName();
93 String portType = port.getPortType();
94 String portName = port.getPortName();
95 String portRack = port.getPortRack();
96 String portShelf = port.getPortShelf();
98 return checkString(portDeviceName)
99 && checkString(portType)
100 && checkString(portName)
101 && checkString(portRack)
102 && checkString(portShelf);
106 * Check if lgx info is compliant.
110 * @return true if String ok false if not
112 public static boolean checkLgx(Lgx lgx) {
116 String lgxDeviceName = lgx.getLgxDeviceName();
117 String lgxPortName = lgx.getLgxPortName();
118 String lgxPortRack = lgx.getLgxPortRack();
119 String lgxPortShelf = lgx.getLgxPortShelf();
120 return checkString(lgxDeviceName)
121 && checkString(lgxPortName)
122 && checkString(lgxPortRack)
123 && checkString(lgxPortShelf);
127 * Check if Tx/Rx Direction complaincy info.
134 * @return <code>true</code> if check is ok <code>false</code> else
136 public static ComplianceCheckResult checkTxOrRxInfo(TxDirection txDirection, RxDirection rxDirection) {
137 if (txDirection == null) {
138 return new ComplianceCheckResult(false, LogMessages.TXDIR_NOT_SET);
140 if (rxDirection == null) {
141 return new ComplianceCheckResult(false, LogMessages.RXDIR_NOT_SET);
143 if (!checkPort(txDirection.getPort())) {
144 return new ComplianceCheckResult(false, LogMessages.TXDIR_PORT_NOT_SET);
146 if (!checkLgx(txDirection.getLgx())) {
147 return new ComplianceCheckResult(false, LogMessages.TXDIR_LGX_NOT_SET);
149 if (!checkPort(rxDirection.getPort())) {
150 return new ComplianceCheckResult(false, LogMessages.RXDIR_PORT_NOT_SET);
152 if (!checkLgx(rxDirection.getLgx())) {
153 return new ComplianceCheckResult(false, LogMessages.RXDIR_LGX_NOT_SET);
155 return new ComplianceCheckResult(true, "");
159 * Check Compliance of Service TxRx info.
160 * @param serviceEnd Service Endpoint
161 * @param endpointType Endpoint type
163 * @return true if String ok false if not
165 public static ComplianceCheckResult check(ServiceEndpoint serviceEnd, ServiceEndpointType endpointType) {
166 if (serviceEnd == null) {
167 return new ComplianceCheckResult(false, LogMessages.endpointTypeNotSet(endpointType));
170 if (serviceEnd.getServiceRate() == null) {
171 String message = "Something wrong when accessing Service " + endpointType + " rate, format or clli";
172 return new ComplianceCheckResult(false, message);
174 Long serviceRate = serviceEnd.getServiceRate().toJava();
175 ServiceFormat serviceformat = serviceEnd.getServiceFormat();
176 String clli = serviceEnd.getClli();
177 if (serviceRate <= 0) {
178 return new ComplianceCheckResult(false, LogMessages.rateNotSet(endpointType));
180 if (serviceformat == null) {
181 return new ComplianceCheckResult(false, LogMessages.formatNotSet(endpointType));
183 if (!checkString(clli)) {
184 return new ComplianceCheckResult(false, LogMessages.clliNotSet(endpointType));
187 ComplianceCheckResult complianceCheckResult
188 = checkTxOrRxInfo(serviceEnd.getTxDirection(), serviceEnd.getRxDirection());
189 if (!complianceCheckResult.hasPassed()) {
190 return new ComplianceCheckResult(false, complianceCheckResult.getMessage());
193 return new ComplianceCheckResult(true, "");
196 private ServicehandlerTxRxCheck() {