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) {
89 boolean result = false;
91 String portDeviceName = port.getPortDeviceName();
92 String portType = port.getPortType();
93 String portName = port.getPortName();
94 String portRack = port.getPortRack();
95 String portShelf = port.getPortShelf();
97 return checkString(portDeviceName)
98 && checkString(portType)
99 && checkString(portName)
100 && checkString(portRack)
101 && checkString(portShelf);
107 * Check if lgx info is compliant.
111 * @return true if String ok false if not
113 public static boolean checkLgx(Lgx lgx) {
114 boolean result = false;
116 String lgxDeviceName = lgx.getLgxDeviceName();
117 String lgxPortName = lgx.getLgxPortName();
118 String lgxPortRack = lgx.getLgxPortRack();
119 String lgxPortShelf = lgx.getLgxPortShelf();
120 if (checkString(lgxDeviceName) && checkString(lgxPortName) && checkString(lgxPortRack)
121 && checkString(lgxPortShelf)) {
129 * Check if Tx/Rx Direction complaincy info.
136 * @return <code>true</code> if check is ok <code>false</code> else
138 public static ComplianceCheckResult checkTxOrRxInfo(TxDirection txDirection, RxDirection rxDirection) {
139 if (txDirection == null) {
140 return new ComplianceCheckResult(false, LogMessages.TXDIR_NOT_SET);
142 if (rxDirection == null) {
143 return new ComplianceCheckResult(false, LogMessages.RXDIR_NOT_SET);
145 if (!checkPort(txDirection.getPort())) {
146 return new ComplianceCheckResult(false, LogMessages.TXDIR_PORT_NOT_SET);
148 if (!checkLgx(txDirection.getLgx())) {
149 return new ComplianceCheckResult(false, LogMessages.TXDIR_LGX_NOT_SET);
151 if (!checkPort(rxDirection.getPort())) {
152 return new ComplianceCheckResult(false, LogMessages.RXDIR_PORT_NOT_SET);
154 if (!checkLgx(rxDirection.getLgx())) {
155 return new ComplianceCheckResult(false, LogMessages.RXDIR_LGX_NOT_SET);
157 return new ComplianceCheckResult(true, "");
161 * Check Compliance of Service TxRx info.
162 * @param serviceEnd Service Endpoint
163 * @param endpointType Endpoint type
165 * @return true if String ok false if not
167 public static ComplianceCheckResult check(ServiceEndpoint serviceEnd, ServiceEndpointType endpointType) {
168 if (serviceEnd == null) {
169 return new ComplianceCheckResult(false, LogMessages.endpointTypeNotSet(endpointType));
172 if (serviceEnd.getServiceRate() == null) {
173 String message = "Something wrong when accessing Service " + endpointType + " rate, format or clli";
174 return new ComplianceCheckResult(false, message);
176 Long serviceRate = serviceEnd.getServiceRate().toJava();
177 ServiceFormat serviceformat = serviceEnd.getServiceFormat();
178 String clli = serviceEnd.getClli();
179 if (serviceRate <= 0) {
180 return new ComplianceCheckResult(false, LogMessages.rateNotSet(endpointType));
182 if (serviceformat == null) {
183 return new ComplianceCheckResult(false, LogMessages.formatNotSet(endpointType));
185 if (!checkString(clli)) {
186 return new ComplianceCheckResult(false, LogMessages.clliNotSet(endpointType));
189 ComplianceCheckResult complianceCheckResult
190 = checkTxOrRxInfo(serviceEnd.getTxDirection(), serviceEnd.getRxDirection());
191 if (!complianceCheckResult.hasPassed()) {
192 return new ComplianceCheckResult(false, complianceCheckResult.getMessage());
195 return new ComplianceCheckResult(true, "");
198 private ServicehandlerTxRxCheck() {