+ private InstanceIdentifier<OduConnection> generateOduConnectionIID(String connectionNumber) {
+ return InstanceIdentifier
+ .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
+ .child(OduConnection.class, new OduConnectionKey(connectionNumber))
+ .build();
+ }
+
+ private String generateConnectionName(String srcTp, String destTp, String spectralSlotName) {
+ return String.join(GridConstant.NAME_PARAMETERS_SEPARATOR,srcTp, destTp, spectralSlotName);
+ }
+
+ public Optional<String> postOtnCrossConnect(List<String> createdOduInterfaces, Nodes node) {
+ String deviceId = node.getNodeId();
+ List<String> sortedCreatedOduInterfaces = new ArrayList<>(createdOduInterfaces);
+ sortedCreatedOduInterfaces.sort((s1,s2) -> s1.compareTo(s2));
+ String srcTp = sortedCreatedOduInterfaces.get(0);
+ String dstTp = sortedCreatedOduInterfaces.get(1);
+ OduConnectionBuilder oduConnectionBuilder = new OduConnectionBuilder()
+ .setConnectionName(srcTp + "-x-" + dstTp)
+ .setDestination(new org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.odu.connection
+ .DestinationBuilder().setDstIf(dstTp).build())
+ .setSource(new org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.odu.connection
+ .SourceBuilder().setSrcIf(srcTp).build())
+ .setDirection(Direction.Bidirectional);
+
+ InstanceIdentifier<OduConnection> oduConnectionIID = InstanceIdentifier
+ .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
+ .child(OduConnection.class, new OduConnectionKey(oduConnectionBuilder.getConnectionName()))
+ .build();
+
+ Future<Optional<DeviceTransaction>> deviceTxFuture = deviceTransactionManager.getDeviceTransaction(deviceId);
+ DeviceTransaction deviceTx;
+ try {
+ Optional<DeviceTransaction> deviceTxOpt = deviceTxFuture.get();
+ if (deviceTxOpt.isPresent()) {
+ deviceTx = deviceTxOpt.get();
+ } else {
+ LOG.error(DEV_TRANSACTION_NOT_FOUND, deviceId);
+ return Optional.empty();
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error(UNABLE_DEV_TRANSACTION, deviceId, e);
+ return Optional.empty();
+ }
+
+ // post the cross connect on the device
+ deviceTx.merge(LogicalDatastoreType.CONFIGURATION, oduConnectionIID, oduConnectionBuilder.build());
+ FluentFuture<? extends @NonNull CommitInfo> commit =
+ deviceTx.commit(Timeouts.DEVICE_WRITE_TIMEOUT, Timeouts.DEVICE_WRITE_TIMEOUT_UNIT);
+ try {
+ commit.get();
+ LOG.info("Otn-connection successfully created: {}-{}", srcTp, dstTp);
+ return Optional.of(srcTp + "-x-" + dstTp);
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.warn("Failed to post {}.", oduConnectionBuilder.build(), e);
+ }
+ return Optional.empty();