import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutput;
import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.TransportpceOlmService;
import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.get.pm.output.Measurements;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220114.mapping.Mapping;
import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.RendererRpcResultSp;
import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.RendererRpcResultSpBuilder;
import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput;
OPERATION_FAILED);
}
PathDescription pathDescription = pathDescriptionOpt.get();
- Mapping mapping = portMapping.getMapping(service.getServiceAEnd().getNodeId().getValue(),
- service.getServiceAEnd().getTxDirection().getPort().getPortName());
- String serviceType = ServiceTypes.getServiceType(service.getServiceAEnd().getServiceFormat().getName(),
- service.getServiceAEnd().getServiceRate(), mapping);
+ String serviceType =
+ ServiceTypes.getServiceType(
+ service.getServiceAEnd().getServiceFormat().getName(),
+ service.getServiceAEnd().getServiceRate(),
+ service.getServiceAEnd().getTxDirection() == null
+ || service.getServiceAEnd().getTxDirection().getPort() == null
+ || service.getServiceAEnd().getTxDirection().getPort().getPortName() == null
+ ? null
+ : portMapping.getMapping(
+ service.getServiceAEnd().getNodeId().getValue(),
+ service.getServiceAEnd().getTxDirection().getPort().getPortName()));
switch (serviceType) {
case StringConstants.SERVICE_TYPE_100GE_T:
case StringConstants.SERVICE_TYPE_400GE:
import org.opendaylight.transportpce.servicehandler.ServiceEndpointType;
import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ServiceEndpoint;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.RxDirection;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.TxDirection;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.lgx.Lgx;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.port.Port;
import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.ServiceFormat;
/**
return SERVICE + endpointType + " is not set";
}
+ public static String rateNull(ServiceEndpointType endpointType) {
+ return "Something wrong when accessing " + SERVICE + endpointType + " rate, format or clli";
+ }
+
public static String rateNotSet(ServiceEndpointType endpointType) {
return SERVICE + endpointType + " rate is not set";
}
}
}
-
/**
* Check if a String is not null and not equal to ''.
*
return (value != null && !value.isEmpty());
}
- /**
- * check if Port info is compliant.
- *
- * @param port
- * port info
- * @return true if String ok false if not
- */
- @SuppressWarnings("java:S1067")
- //sonar issue Reduce the number of conditional operators (4) used in the expression (maximum allowed 3)
- //won't be fixed because of functional checks needed
- public static boolean checkPort(Port port) {
- if (port == null) {
- return false;
- }
- String portDeviceName = port.getPortDeviceName();
- String portType = port.getPortType();
- String portName = port.getPortName();
- String portRack = port.getPortRack();
- String portShelf = port.getPortShelf();
-
- return checkString(portDeviceName)
- && checkString(portType)
- && checkString(portName)
- && checkString(portRack)
- && checkString(portShelf);
- }
-
- /**
- * Check if lgx info is compliant.
- *
- * @param lgx
- * lgx info
- * @return true if String ok false if not
- */
- public static boolean checkLgx(Lgx lgx) {
- if (lgx == null) {
- return false;
- }
- String lgxDeviceName = lgx.getLgxDeviceName();
- String lgxPortName = lgx.getLgxPortName();
- String lgxPortRack = lgx.getLgxPortRack();
- String lgxPortShelf = lgx.getLgxPortShelf();
- return checkString(lgxDeviceName)
- && checkString(lgxPortName)
- && checkString(lgxPortRack)
- && checkString(lgxPortShelf);
- }
-
- /**
- * Check if Tx/Rx Direction complaincy info.
- *
- * @param txDirection
- * TxDirection
- * @param rxDirection
- * RxDirection
- *
- * @return <code>true</code> if check is ok <code>false</code> else
- */
- public static ComplianceCheckResult checkTxOrRxInfo(TxDirection txDirection, RxDirection rxDirection) {
- if (txDirection == null) {
- return new ComplianceCheckResult(false, LogMessages.TXDIR_NOT_SET);
- }
- if (rxDirection == null) {
- return new ComplianceCheckResult(false, LogMessages.RXDIR_NOT_SET);
- }
- if (!checkPort(txDirection.getPort())) {
- return new ComplianceCheckResult(false, LogMessages.TXDIR_PORT_NOT_SET);
- }
- if (!checkLgx(txDirection.getLgx())) {
- return new ComplianceCheckResult(false, LogMessages.TXDIR_LGX_NOT_SET);
- }
- if (!checkPort(rxDirection.getPort())) {
- return new ComplianceCheckResult(false, LogMessages.RXDIR_PORT_NOT_SET);
- }
- if (!checkLgx(rxDirection.getLgx())) {
- return new ComplianceCheckResult(false, LogMessages.RXDIR_LGX_NOT_SET);
- }
- return new ComplianceCheckResult(true, "");
- }
/**
* Check Compliance of Service TxRx info.
return new ComplianceCheckResult(false, LogMessages.clliNotSet(endpointType));
}
- ComplianceCheckResult complianceCheckResult
- = checkTxOrRxInfo(serviceEnd.getTxDirection(), serviceEnd.getRxDirection());
- if (!complianceCheckResult.hasPassed()) {
- return new ComplianceCheckResult(false, complianceCheckResult.getMessage());
- }
-
return new ComplianceCheckResult(true, "");
}
import static org.opendaylight.transportpce.servicehandler.validation.checks.ServicehandlerTxRxCheck.LogMessages;
import org.junit.Assert;
-import org.junit.Ignore;
import org.junit.Test;
import org.opendaylight.transportpce.servicehandler.ServiceEndpointType;
import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.ServiceAEndBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.RxDirectionBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.TxDirectionBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.lgx.LgxBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.port.PortBuilder;
import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.ServiceFormat;
import org.opendaylight.yangtools.yang.common.Uint32;
public class ServicehandlerTxRxCheckTest {
- @Test
- public void checkPortShouldBeFalseForNullPort() {
- Assert.assertFalse(ServicehandlerTxRxCheck.checkPort(null));
- }
-
- @Test
- public void checkLgxShouldBeFalseForNullLgx() {
- Assert.assertFalse(ServicehandlerTxRxCheck.checkLgx(null));
- }
-
- @Test
- public void checkTxOrRxInfoForNullTx() {
- ComplianceCheckResult result = ServicehandlerTxRxCheck.checkTxOrRxInfo(
- null,
- new RxDirectionBuilder()
- .setPort(new PortBuilder().setPortDeviceName("q")
- .setPortName("n").setPortRack("r").setPortShelf("s").setPortType("t").build())
- .setLgx(new LgxBuilder().setLgxDeviceName("l")
- .setLgxPortName("p").setLgxPortRack("r").setLgxPortShelf("s").build())
- .build());
-
- Assert.assertFalse(result.hasPassed());
- Assert.assertEquals(LogMessages.TXDIR_NOT_SET, result.getMessage());
- }
-
- @Test
- public void checkTxOrRxInfoForNullTxPort() {
- ComplianceCheckResult result = ServicehandlerTxRxCheck.checkTxOrRxInfo(
- new TxDirectionBuilder()
- .setLgx(new LgxBuilder().setLgxDeviceName("l")
- .setLgxPortName("p").setLgxPortRack("r").setLgxPortShelf("s").build())
- .build(),
- new RxDirectionBuilder()
- .setPort(new PortBuilder().setPortDeviceName("q")
- .setPortName("n").setPortRack("r").setPortShelf("s").setPortType("t").build())
- .setLgx(new LgxBuilder().setLgxDeviceName("l")
- .setLgxPortName("p").setLgxPortRack("r").setLgxPortShelf("s").build())
- .build());
-
- Assert.assertFalse(result.hasPassed());
- Assert.assertEquals(LogMessages.TXDIR_PORT_NOT_SET, result.getMessage());
- }
-
- @Test
- public void checkTxOrRxInfoForNullTxLgx() {
- ComplianceCheckResult result = ServicehandlerTxRxCheck.checkTxOrRxInfo(
- new TxDirectionBuilder()
- .setPort(new PortBuilder().setPortDeviceName("q")
- .setPortName("n").setPortRack("r").setPortShelf("s").setPortType("t").build()).build(),
- new RxDirectionBuilder()
- .setPort(new PortBuilder().setPortDeviceName("q")
- .setPortName("n").setPortRack("r").setPortShelf("s").setPortType("t").build())
- .setLgx(new LgxBuilder().setLgxDeviceName("l")
- .setLgxPortName("p").setLgxPortRack("r").setLgxPortShelf("s").build())
- .build());
-
- Assert.assertFalse(result.hasPassed());
- Assert.assertEquals(LogMessages.TXDIR_LGX_NOT_SET, result.getMessage());
- }
-
- @Test
- public void checkTxOrRxInfoForNullRx() {
- ComplianceCheckResult result = ServicehandlerTxRxCheck.checkTxOrRxInfo(
- new TxDirectionBuilder()
- .setPort(new PortBuilder().setPortDeviceName("q")
- .setPortName("n").setPortRack("r").setPortShelf("s").setPortType("t").build())
- .setLgx(new LgxBuilder().setLgxDeviceName("l")
- .setLgxPortName("p").setLgxPortRack("r").setLgxPortShelf("s").build())
- .build(),
- null);
-
- Assert.assertFalse(result.hasPassed());
- Assert.assertEquals(LogMessages.RXDIR_NOT_SET, result.getMessage());
- }
-
- @Test
- public void checkTxOrRxInfoForNullRxPort() {
- ComplianceCheckResult result = ServicehandlerTxRxCheck.checkTxOrRxInfo(
- new TxDirectionBuilder()
- .setPort(new PortBuilder().setPortDeviceName("q")
- .setPortName("n").setPortRack("r").setPortShelf("s").setPortType("t").build())
- .setLgx(new LgxBuilder().setLgxDeviceName("l")
- .setLgxPortName("p").setLgxPortRack("r").setLgxPortShelf("s").build())
- .build(),
- new RxDirectionBuilder()
- .setLgx(new LgxBuilder().setLgxDeviceName("l")
- .setLgxPortName("p").setLgxPortRack("r").setLgxPortShelf("s").build())
- .build());
-
- Assert.assertFalse(result.hasPassed());
- Assert.assertEquals(LogMessages.RXDIR_PORT_NOT_SET, result.getMessage());
- }
-
- @Test
- public void checkTxOrRxInfoForNullRxLgx() {
- ComplianceCheckResult result = ServicehandlerTxRxCheck.checkTxOrRxInfo(
- new TxDirectionBuilder()
- .setPort(new PortBuilder().setPortDeviceName("q")
- .setPortName("n").setPortRack("r").setPortShelf("s").setPortType("t").build())
- .setLgx(new LgxBuilder().setLgxDeviceName("l")
- .setLgxPortName("p").setLgxPortRack("r").setLgxPortShelf("s").build())
- .build(),
- new RxDirectionBuilder()
- .setPort(new PortBuilder().setPortDeviceName("q")
- .setPortName("n").setPortRack("r").setPortShelf("s").setPortType("t").build())
- .build());
-
- Assert.assertFalse(result.hasPassed());
- Assert.assertEquals(LogMessages.RXDIR_LGX_NOT_SET, result.getMessage());
- }
-
@Test
public void checkForServiceEndNull() {
ComplianceCheckResult result = ServicehandlerTxRxCheck.check(null, ServiceEndpointType.SERVICEAEND);
Assert.assertEquals(LogMessages.endpointTypeNotSet(ServiceEndpointType.SERVICEAEND), result.getMessage());
}
- @Ignore
@Test
public void checkForServiceRateNull() {
ComplianceCheckResult result =
ServicehandlerTxRxCheck.check(new ServiceAEndBuilder().build(), ServiceEndpointType.SERVICEAEND);
Assert.assertFalse(result.hasPassed());
- Assert.assertEquals(LogMessages.rateNotSet(ServiceEndpointType.SERVICEAEND), result.getMessage());
+ Assert.assertEquals(LogMessages.rateNull(ServiceEndpointType.SERVICEAEND), result.getMessage());
}
@Test
Assert.assertFalse(result.hasPassed());
Assert.assertEquals(LogMessages.clliNotSet(ServiceEndpointType.SERVICEAEND), result.getMessage());
}
-
- @Test
- public void checkForFailTxOrRx() {
- ComplianceCheckResult result = ServicehandlerTxRxCheck.check(new ServiceAEndBuilder()
- .setServiceRate(Uint32.valueOf(3)).setClli("cc").setServiceFormat(ServiceFormat.Ethernet).build(),
- ServiceEndpointType.SERVICEAEND);
-
- Assert.assertFalse(result.hasPassed());
- Assert.assertEquals(LogMessages.TXDIR_NOT_SET, result.getMessage());
- }
}