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;
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;
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;
Timeouts.DEVICE_READ_TIMEOUT_UNIT);
}
- public Optional<String> postCrossConnect(String deviceId, Long waveNumber, String srcTp, String destTp) {
+ public Optional<String> 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<RoadmConnections> 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<RoadmConnections> rdmConnectionIID = InstanceIdentifier
+ .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
+ .child(RoadmConnections.class, new RoadmConnectionsKey(rdmConnBldr.getConnectionNumber()))
+ .build();
Future<Optional<DeviceTransaction>> deviceTxFuture = deviceTransactionManager.getDeviceTransaction(deviceId);
DeviceTransaction deviceTx;
try {
Optional<DeviceTransaction> 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();
}
// post the cross connect on the device
- deviceTx.put(LogicalDatastoreType.CONFIGURATION, rdmConnectionIID, rdmConnBldr.build());
+ deviceTx.merge(LogicalDatastoreType.CONFIGURATION, rdmConnectionIID, rdmConnBldr.build());
FluentFuture<? extends @NonNull CommitInfo> 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);
Optional<RoadmConnections> 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;
try {
Optional<DeviceTransaction> 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;
}
- public List<Ports> getConnectionPortTrail(String nodeId, Long waveNumber, String srcTp, String destTp)
- throws OpenRoadmInterfaceException {
- String connectionName = generateConnectionNumber(srcTp, destTp, waveNumber);
+ public List<Ports> 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<MountPoint> mountPointOpt = deviceTransactionManager.getDeviceMountPoint(nodeId);
List<Ports> 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<RpcConsumerRegistry> service = mountPoint.getService(RpcConsumerRegistry.class);
+ final Optional<RpcService> 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<RpcResult<GetConnectionPortTrailOutput>> portTrailOutput = rpcService.getConnectionPortTrail(
- portTrainInputBuilder.build());
+ final GetConnectionPortTrail rpcService = service.orElseThrow().getRpc(GetConnectionPortTrail.class);
+ final Future<RpcResult<GetConnectionPortTrailOutput>> portTrailOutput = rpcService.invoke(
+ new GetConnectionPortTrailInputBuilder()
+ .setConnectionNumber(connectionName)
+ .build());
if (portTrailOutput != null) {
try {
RpcResult<GetConnectionPortTrailOutput> connectionPortTrailOutputRpcResult = portTrailOutput.get();
}
private InstanceIdentifier<RoadmConnections> 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<RoadmConnections> 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));
try {
Optional<DeviceTransaction> deviceTxOpt = deviceTxFuture.get();
if (deviceTxOpt.isPresent()) {
- deviceTx = deviceTxOpt.get();
+ deviceTx = deviceTxOpt.orElseThrow();
} else {
LOG.error("Transaction for device {} was not found!", deviceId);
return false;
}
// post the cross connect on the device
- InstanceIdentifier<RoadmConnections> roadmConnIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
- .child(RoadmConnections.class, new RoadmConnectionsKey(ctNumber));
- deviceTx.put(LogicalDatastoreType.CONFIGURATION, roadmConnIID, newRdmConn);
+ InstanceIdentifier<RoadmConnections> roadmConnIID = InstanceIdentifier
+ .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
+ .child(RoadmConnections.class, new RoadmConnectionsKey(ctNumber))
+ .build();
+ deviceTx.merge(LogicalDatastoreType.CONFIGURATION, roadmConnIID, newRdmConn);
FluentFuture<? extends @NonNull CommitInfo> commit =
deviceTx.commit(Timeouts.DEVICE_WRITE_TIMEOUT, Timeouts.DEVICE_WRITE_TIMEOUT_UNIT);
try {