- @Override
- public ListenableFuture<RpcResult<InitRoadmRoadmTapiLinkOutput>> initRoadmRoadmTapiLink(
- InitRoadmRoadmTapiLinkInput input) {
- // TODO --> need to check if the nodes and neps exist in the topology
- String sourceNode = input.getRdmANode();
- String sourceTp = input.getDegATp();
- String destNode = input.getRdmZNode();
- String destTp = input.getDegZTp();
- String linkId = String.join("-", sourceNode, sourceTp.split("-")[0], sourceTp)
- + "to" + String.join("-", destNode, destTp.split("-")[0], destTp);
- Link link = createTapiLink(sourceNode, sourceTp, destNode, destTp, linkId, "OMS link name", PHTNC_MEDIA);
- InitRoadmRoadmTapiLinkOutputBuilder output = new InitRoadmRoadmTapiLinkOutputBuilder();
- if (link == null) {
- LOG.error("Error creating link object");
- return RpcResultBuilder.<InitRoadmRoadmTapiLinkOutput>failed().withError(RpcError.ErrorType.RPC,
- "Failed to create link in topology").buildFuture();
- }
- if (putLinkInTopology(link)) {
- output = new InitRoadmRoadmTapiLinkOutputBuilder()
- .setResult("Link created in tapi topology. Link-uuid = " + link.getUuid());
- }
- return RpcResultBuilder.success(output.build()).buildFuture();
- }
-
- @Override
- public ListenableFuture<RpcResult<InitXpdrRdmTapiLinkOutput>> initXpdrRdmTapiLink(InitXpdrRdmTapiLinkInput input) {
- // TODO --> need to check if the nodes and neps exist in the topology
- String destNode = input.getRdmNode();
- String destTp = input.getAddDropTp();
- String sourceNode = input.getXpdrNode();
- String sourceTp = input.getNetworkTp();
- String linkId = String.join("-", sourceNode, sourceTp)
- + "to" + String.join("-", destNode, destTp.split("-")[0], destTp);
- Link link = createTapiLink(sourceNode, sourceTp, destNode, destTp, linkId, "XPDR-RDM link name", OTSI);
- InitXpdrRdmTapiLinkOutputBuilder output = new InitXpdrRdmTapiLinkOutputBuilder();
- if (link == null) {
- LOG.error("Error creating link object");
- return RpcResultBuilder.<InitXpdrRdmTapiLinkOutput>failed().withError(RpcError.ErrorType.RPC,
- "Failed to create link in topology").buildFuture();
- }
- if (putLinkInTopology(link)) {
- output = new InitXpdrRdmTapiLinkOutputBuilder()
- .setResult("Link created in tapi topology. Link-uuid = " + link.getUuid());
- }
- return RpcResultBuilder.success(output.build()).buildFuture();
- }
-
- @Override
- public ListenableFuture<RpcResult<DeleteTapiLinkOutput>> deleteTapiLink(DeleteTapiLinkInput input) {
- // TODO: check if this IID is correct
- // TODO --> need to check if the link exists in the topology
- try {
- InstanceIdentifier<Link> linkIID = InstanceIdentifier.builder(Context.class)
- .augmentation(Context1.class).child(TopologyContext.class).child(Topology.class,
- new TopologyKey(tapiTopoUuid)).child(Link.class, new LinkKey(input.getUuid())).build();
- this.networkTransactionService.delete(LogicalDatastoreType.OPERATIONAL, linkIID);
- this.networkTransactionService.commit().get();
- LOG.info("TAPI link deleted successfully.");
- return RpcResultBuilder.success(new DeleteTapiLinkOutputBuilder()
- .setResult("Link successfully deleted from tapi topology").build()).buildFuture();
- } catch (InterruptedException | ExecutionException e) {
- LOG.error("Failed to delete TAPI link", e);
- return RpcResultBuilder.<DeleteTapiLinkOutput>failed().withError(RpcError.ErrorType.RPC,
- "Failed to delete link from topology").buildFuture();
- }
- }
-
- private Link createTapiLink(String sourceNode, String sourceTp, String destNode, String destTp, String linkId,
- String valueName, String sourceNodeQual) {
- Map<NodeEdgePointKey, NodeEdgePoint> nepList = new HashMap<>();
- Uuid sourceUuidNode = new Uuid(UUID.nameUUIDFromBytes((String.join("+", sourceNode,
- sourceNodeQual)).getBytes(Charset.forName("UTF-8"))).toString());
- Uuid sourceUuidTp = new Uuid(UUID.nameUUIDFromBytes((String.join("+", sourceNode, PHTNC_MEDIA,
- sourceTp)).getBytes(Charset.forName("UTF-8"))).toString());
- Uuid destUuidNode = new Uuid(UUID.nameUUIDFromBytes((String.join("+", destNode,
- PHTNC_MEDIA)).getBytes(Charset.forName("UTF-8"))).toString());
- Uuid destUuidTp = new Uuid(UUID.nameUUIDFromBytes((String.join("+", destNode, PHTNC_MEDIA,
- destTp)).getBytes(Charset.forName("UTF-8"))).toString());
- if (!(nodeExists(sourceUuidNode) && nodeExists(destUuidNode)
- && nepExists(sourceUuidTp, sourceUuidNode) && nepExists(destUuidTp, destUuidNode))) {
- LOG.error("Verify the input data. No link can be created, "
- + "as either the node or the tp doesnt exist in the TAPI topology");
- return null;
- }
-
- NodeEdgePoint sourceNep = new NodeEdgePointBuilder()
- .setTopologyUuid(this.tapiTopoUuid)
- .setNodeUuid(sourceUuidNode)
- .setNodeEdgePointUuid(sourceUuidTp)
- .build();
- nepList.put(sourceNep.key(), sourceNep);
- NodeEdgePoint destNep = new NodeEdgePointBuilder()
- .setTopologyUuid(this.tapiTopoUuid)
- .setNodeUuid(destUuidNode)
- .setNodeEdgePointUuid(destUuidTp)
- .build();
- nepList.put(destNep.key(), destNep);
- OperationalState sourceOperState = getOperState(sourceUuidTp, sourceUuidNode);
- OperationalState destOperState = getOperState(destUuidTp, destUuidNode);
- if (sourceOperState == null || destOperState == null) {
- LOG.error("No link can be created, as the operational state was not found in the TAPI topology");
- return null;
- }
- AdministrativeState sourceAdminState = getAdminState(sourceUuidTp, sourceUuidNode);
- AdministrativeState destAdminState = getAdminState(destUuidTp, destUuidNode);
- if (sourceAdminState == null || destAdminState == null) {
- LOG.error("No link can be created, as the administrative state was not found in the TAPI topology");
- return null;
- }
- OperationalState operState = (OperationalState.ENABLED.equals(sourceOperState)
- && OperationalState.ENABLED.equals(destOperState))
- ? OperationalState.ENABLED : OperationalState.DISABLED;
- AdministrativeState adminState = (AdministrativeState.UNLOCKED.equals(sourceAdminState)
- && AdministrativeState.UNLOCKED.equals(destAdminState))
- ? AdministrativeState.UNLOCKED : AdministrativeState.LOCKED;
- Name linkName = new NameBuilder().setValueName(valueName)
- .setValue(linkId)
- .build();
- CostCharacteristic costCharacteristic = new CostCharacteristicBuilder()
- .setCostAlgorithm("Restricted Shortest Path - RSP")
- .setCostName("HOP_COUNT")
- .setCostValue("12345678")
- .build();
- LatencyCharacteristic latencyCharacteristic = new LatencyCharacteristicBuilder()
- .setFixedLatencyCharacteristic("12345678")
- .setQueingLatencyCharacteristic("12345678")
- .setJitterCharacteristic("12345678")
- .setWanderCharacteristic("12345678")
- .setTrafficPropertyName("FIXED_LATENCY")
- .build();
- RiskCharacteristic riskCharacteristic = new RiskCharacteristicBuilder()
- .setRiskCharacteristicName("risk characteristic")
- .setRiskIdentifierList(List.of("risk identifier1", "risk identifier2"))
- .build();
- ValidationMechanism validationMechanism = new ValidationMechanismBuilder()
- .setValidationMechanism("validation mechanism")
- .setValidationRobustness("validation robustness")
- .setLayerProtocolAdjacencyValidated("layer protocol adjacency")
- .build();
- return new LinkBuilder()
- .setUuid(new Uuid(
- UUID.nameUUIDFromBytes(linkId.getBytes(Charset.forName("UTF-8")))
- .toString()))
- .setName(Map.of(linkName.key(), linkName))
- .setLayerProtocolName(List.of(LayerProtocolName.PHOTONICMEDIA))
- .setNodeEdgePoint(nepList)
- .setDirection(ForwardingDirection.BIDIRECTIONAL)
- .setTransitionedLayerProtocolName(new ArrayList<>())
- .setResilienceType(new ResilienceTypeBuilder().setProtectionType(ProtectionType.NOPROTECTON)
- .setRestorationPolicy(RestorationPolicy.NA)
- .build())
- .setAdministrativeState(adminState)
- .setOperationalState(operState)
- .setLifecycleState(LifecycleState.INSTALLED)
- .setTotalPotentialCapacity(new TotalPotentialCapacityBuilder().setTotalSize(
- new TotalSizeBuilder().setUnit(CapacityUnit.GBPS)
- .setValue(Uint64.valueOf(100)).build()).build())
- .setAvailableCapacity(new AvailableCapacityBuilder().setTotalSize(
- new TotalSizeBuilder().setUnit(CapacityUnit.MBPS)
- .setValue(Uint64.valueOf(100)).build())
- .build())
- .setCostCharacteristic(Map.of(costCharacteristic.key(), costCharacteristic))
- .setLatencyCharacteristic(Map.of(latencyCharacteristic.key(), latencyCharacteristic))
- .setRiskCharacteristic(Map.of(riskCharacteristic.key(), riskCharacteristic))
- .setErrorCharacteristic("error")
- .setLossCharacteristic("loss")
- .setRepeatDeliveryCharacteristic("repeat delivery")
- .setDeliveryOrderCharacteristic("delivery order")
- .setUnavailableTimeCharacteristic("unavailable time")
- .setServerIntegrityProcessCharacteristic("server integrity process")
- .setValidationMechanism(Map.of(validationMechanism.key(), validationMechanism))
- .build();
- }
-
- private boolean nepExists(Uuid nepUuid, Uuid nodeUuid) {
- LOG.info("Checking if nep with uuid {} existis in tapi topology", nepUuid);
- try {
- InstanceIdentifier<OwnedNodeEdgePoint> onepIID = InstanceIdentifier.builder(Context.class)
- .augmentation(Context1.class).child(TopologyContext.class)
- .child(Topology.class, new TopologyKey(tapiTopoUuid)).child(Node.class, new NodeKey(nodeUuid))
- .child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(nepUuid))
- .build();
- Optional<OwnedNodeEdgePoint> optionalOnep = this.networkTransactionService.read(
- LogicalDatastoreType.OPERATIONAL, onepIID).get();
- if (!optionalOnep.isPresent()) {
- LOG.error("ONEP is not present in datastore");
- return false;
- }
- return true;
- } catch (InterruptedException | ExecutionException e) {
- LOG.error("Couldnt retrieve nep from datastore");
- return false;
- }