X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=common%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fcommon%2Fcrossconnect%2FCrossConnectImpl121.java;h=d26ff95c7e648ce977bc69da1b076a9dc6c005c2;hb=b1b3bafd549bb501937cea5c976d5344608b6ed3;hp=8ee2350d0c82e4e12d48f6022c1b69b202f19034;hpb=d54521c9f9ca2289cdcd0aff2883a1f241d5451a;p=transportpce.git diff --git a/common/src/main/java/org/opendaylight/transportpce/common/crossconnect/CrossConnectImpl121.java b/common/src/main/java/org/opendaylight/transportpce/common/crossconnect/CrossConnectImpl121.java index 8ee2350d0..d26ff95c7 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/crossconnect/CrossConnectImpl121.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/crossconnect/CrossConnectImpl121.java @@ -8,7 +8,6 @@ package org.opendaylight.transportpce.common.crossconnect; import com.google.common.util.concurrent.FluentFuture; -import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -17,18 +16,21 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.mdsal.binding.api.MountPoint; -import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry; +import org.opendaylight.mdsal.binding.api.RpcService; import org.opendaylight.mdsal.common.api.CommitInfo; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.transportpce.common.Timeouts; import org.opendaylight.transportpce.common.device.DeviceTransaction; import org.opendaylight.transportpce.common.device.DeviceTransactionManager; +import org.opendaylight.transportpce.common.fixedflex.GridConstant; +import org.opendaylight.transportpce.common.fixedflex.SpectrumInformation; import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.OpticalControlMode; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.PowerDBm; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.GetConnectionPortTrail; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.GetConnectionPortTrailInputBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.GetConnectionPortTrailOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OrgOpenroadmDeviceService; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OrgOpenroadmDeviceData; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.connection.DestinationBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.connection.SourceBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.get.connection.port.trail.output.Ports; @@ -37,6 +39,7 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.open import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnectionsBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnectionsKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.Decimal64; import org.opendaylight.yangtools.yang.common.RpcResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,23 +59,29 @@ public class CrossConnectImpl121 { Timeouts.DEVICE_READ_TIMEOUT_UNIT); } - public Optional postCrossConnect(String deviceId, Long waveNumber, String srcTp, String destTp) { + public Optional postCrossConnect(String deviceId, String srcTp, String destTp, + SpectrumInformation spectrumInformation) { RoadmConnectionsBuilder rdmConnBldr = new RoadmConnectionsBuilder(); - String connectionNumber = generateConnectionNumber(srcTp, destTp, waveNumber); + String connectionNumber = spectrumInformation.getIdentifierFromParams(srcTp, destTp); rdmConnBldr.setConnectionNumber(connectionNumber); - rdmConnBldr.setWavelengthNumber(waveNumber); + rdmConnBldr.setWavelengthNumber(spectrumInformation.getWaveLength()); rdmConnBldr.setOpticalControlMode(OpticalControlMode.Off); - rdmConnBldr.setSource(new SourceBuilder().setSrcIf(srcTp + "-" + waveNumber.toString()).build()); - rdmConnBldr.setDestination(new DestinationBuilder().setDstIf(destTp + "-" + waveNumber.toString()).build()); - InstanceIdentifier rdmConnectionIID = InstanceIdentifier.create(OrgOpenroadmDevice.class) - .child(RoadmConnections.class, new RoadmConnectionsKey(rdmConnBldr.getConnectionNumber())); + rdmConnBldr.setSource(new SourceBuilder().setSrcIf(spectrumInformation.getIdentifierFromParams(srcTp)) + .build()); + rdmConnBldr.setDestination(new DestinationBuilder() + .setDstIf(spectrumInformation.getIdentifierFromParams(destTp)) + .build()); + InstanceIdentifier rdmConnectionIID = InstanceIdentifier + .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class) + .child(RoadmConnections.class, new RoadmConnectionsKey(rdmConnBldr.getConnectionNumber())) + .build(); Future> deviceTxFuture = deviceTransactionManager.getDeviceTransaction(deviceId); DeviceTransaction deviceTx; try { Optional deviceTxOpt = deviceTxFuture.get(); if (deviceTxOpt.isPresent()) { - deviceTx = deviceTxOpt.get(); + deviceTx = deviceTxOpt.orElseThrow(); } else { LOG.error("Device transaction for device {} was not found!", deviceId); return Optional.empty(); @@ -83,12 +92,14 @@ public class CrossConnectImpl121 { } // post the cross connect on the device - deviceTx.put(LogicalDatastoreType.CONFIGURATION, rdmConnectionIID, rdmConnBldr.build()); + deviceTx.merge(LogicalDatastoreType.CONFIGURATION, rdmConnectionIID, rdmConnBldr.build()); FluentFuture commit = deviceTx.commit(Timeouts.DEVICE_WRITE_TIMEOUT, Timeouts.DEVICE_WRITE_TIMEOUT_UNIT); try { commit.get(); - LOG.info("Roadm-connection successfully created: {}-{}-{}", srcTp, destTp, waveNumber); + LOG.info("Roadm-connection successfully created: {}-{}-{}-{}", srcTp, destTp, + spectrumInformation.getLowerSpectralSlotNumber(), + spectrumInformation.getHigherSpectralSlotNumber()); return Optional.of(connectionNumber); } catch (InterruptedException | ExecutionException e) { LOG.warn("Failed to post {}. Exception: ", rdmConnBldr.build(), e); @@ -101,8 +112,8 @@ public class CrossConnectImpl121 { Optional xc = getCrossConnect(deviceId, connectionNumber); //Check if cross connect exists before delete if (xc.isPresent()) { - interfList.add(xc.get().getSource().getSrcIf()); - interfList.add(xc.get().getDestination().getDstIf()); + interfList.add(xc.orElseThrow().getSource().getSrcIf()); + interfList.add(xc.orElseThrow().getDestination().getDstIf()); } else { LOG.warn("Cross connect does not exist, halting delete"); return null; @@ -112,7 +123,7 @@ public class CrossConnectImpl121 { try { Optional deviceTxOpt = deviceTxFuture.get(); if (deviceTxOpt.isPresent()) { - deviceTx = deviceTxOpt.get(); + deviceTx = deviceTxOpt.orElseThrow(); } else { LOG.error("Device transaction for device {} was not found!", deviceId); return null; @@ -137,27 +148,29 @@ public class CrossConnectImpl121 { } - public List getConnectionPortTrail(String nodeId, Long waveNumber, String srcTp, String destTp) - throws OpenRoadmInterfaceException { - String connectionName = generateConnectionNumber(srcTp, destTp, waveNumber); + public List getConnectionPortTrail(String nodeId, String srcTp, String destTp, + int lowerSpectralSlotNumber, int higherSpectralSlotNumber) throws OpenRoadmInterfaceException { + String spectralSlotName = String.join(GridConstant.SPECTRAL_SLOT_SEPARATOR, + String.valueOf(lowerSpectralSlotNumber), String.valueOf(higherSpectralSlotNumber)); + String connectionName = generateConnectionNumber(srcTp, destTp, spectralSlotName); Optional mountPointOpt = deviceTransactionManager.getDeviceMountPoint(nodeId); List ports = null; MountPoint mountPoint; if (mountPointOpt.isPresent()) { - mountPoint = mountPointOpt.get(); + mountPoint = mountPointOpt.orElseThrow(); } else { LOG.error("Failed to obtain mount point for device {}!", nodeId); return Collections.emptyList(); } - final Optional service = mountPoint.getService(RpcConsumerRegistry.class); + final Optional service = mountPoint.getService(RpcService.class); if (!service.isPresent()) { LOG.error("Failed to get RpcService for node {}", nodeId); } - final OrgOpenroadmDeviceService rpcService = service.get().getRpcService(OrgOpenroadmDeviceService.class); - final GetConnectionPortTrailInputBuilder portTrainInputBuilder = new GetConnectionPortTrailInputBuilder(); - portTrainInputBuilder.setConnectionNumber(connectionName); - final Future> portTrailOutput = rpcService.getConnectionPortTrail( - portTrainInputBuilder.build()); + final GetConnectionPortTrail rpcService = service.orElseThrow().getRpc(GetConnectionPortTrail.class); + final Future> portTrailOutput = rpcService.invoke( + new GetConnectionPortTrailInputBuilder() + .setConnectionNumber(connectionName) + .build()); if (portTrailOutput != null) { try { RpcResult connectionPortTrailOutputRpcResult = portTrailOutput.get(); @@ -181,19 +194,20 @@ public class CrossConnectImpl121 { } private InstanceIdentifier generateRdmConnectionIID(String connectionNumber) { - return InstanceIdentifier.create(OrgOpenroadmDevice.class) - .child(RoadmConnections.class, new RoadmConnectionsKey(connectionNumber)); + return InstanceIdentifier.builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class) + .child(RoadmConnections.class, new RoadmConnectionsKey(connectionNumber)) + .build(); } - private String generateConnectionNumber(String srcTp, String destTp, Long waveNumber) { - return srcTp + "-" + destTp + "-" + waveNumber; + private String generateConnectionNumber(String srcTp, String destTp, String spectralSlotName) { + return String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, srcTp, destTp, spectralSlotName); } - public boolean setPowerLevel(String deviceId, OpticalControlMode mode, BigDecimal powerValue, String ctNumber) { + public boolean setPowerLevel(String deviceId, OpticalControlMode mode, Decimal64 powerValue, String ctNumber) { Optional rdmConnOpt = getCrossConnect(deviceId, ctNumber); if (rdmConnOpt.isPresent()) { - RoadmConnectionsBuilder rdmConnBldr = new RoadmConnectionsBuilder(rdmConnOpt.get()) + RoadmConnectionsBuilder rdmConnBldr = new RoadmConnectionsBuilder(rdmConnOpt.orElseThrow()) .setOpticalControlMode(mode); if (powerValue != null) { rdmConnBldr.setTargetOutputPower(new PowerDBm(powerValue)); @@ -206,7 +220,7 @@ public class CrossConnectImpl121 { try { Optional deviceTxOpt = deviceTxFuture.get(); if (deviceTxOpt.isPresent()) { - deviceTx = deviceTxOpt.get(); + deviceTx = deviceTxOpt.orElseThrow(); } else { LOG.error("Transaction for device {} was not found!", deviceId); return false; @@ -217,9 +231,11 @@ public class CrossConnectImpl121 { } // post the cross connect on the device - InstanceIdentifier roadmConnIID = InstanceIdentifier.create(OrgOpenroadmDevice.class) - .child(RoadmConnections.class, new RoadmConnectionsKey(ctNumber)); - deviceTx.put(LogicalDatastoreType.CONFIGURATION, roadmConnIID, newRdmConn); + InstanceIdentifier roadmConnIID = InstanceIdentifier + .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class) + .child(RoadmConnections.class, new RoadmConnectionsKey(ctNumber)) + .build(); + deviceTx.merge(LogicalDatastoreType.CONFIGURATION, roadmConnIID, newRdmConn); FluentFuture commit = deviceTx.commit(Timeouts.DEVICE_WRITE_TIMEOUT, Timeouts.DEVICE_WRITE_TIMEOUT_UNIT); try {