+ return nodeid.matches("[A-Z]{5}-[A-Z0-9]{2}-.*") ? String.join("-", nodeid.split("-")[0],
+ nodeid.split("-")[1]) : nodeid.split("-")[0];
+ }
+
+ public ServiceCreateInput createORServiceInput(CreateConnectivityServiceInput input, Uuid serviceUuid) {
+ // TODO: not taking into account all the constraints. Only using EndPoints and Connectivity Constraint.
+ Map<org.opendaylight.yang.gen.v1.urn
+ .onf.otcc.yang.tapi.connectivity.rev181210.create.connectivity.service.input.EndPointKey,
+ org.opendaylight.yang.gen.v1.urn
+ .onf.otcc.yang.tapi.connectivity.rev181210.create.connectivity.service.input.EndPoint>
+ endPointMap = input.getEndPoint();
+ ConnectivityConstraint constraint = input.getConnectivityConstraint();
+ ConnectionType connType = null;
+ ServiceFormat serviceFormat = null;
+ String nodeAid = String.join("+", endPointMap.values().stream().findFirst().get().getLocalId(),
+ TapiStringConstants.DSR);
+ String nodeZid = String.join("+", endPointMap.values().stream().skip(1).findFirst().get().getLocalId(),
+ TapiStringConstants.DSR);
+ LOG.debug("Node a = {}", nodeAid);
+ LOG.debug("Node z = {}", nodeZid);
+ switch (constraint.getServiceLayer().getIntValue()) {
+ case 0:
+ LOG.info("ODU");
+ connType = ConnectionType.Infrastructure;
+ serviceFormat = ServiceFormat.ODU;
+ break;
+ case 1:
+ LOG.info("ETH, no need to create OTU and ODU");
+ connType = ConnectionType.Service;
+ serviceFormat = ServiceFormat.Ethernet;
+ break;
+ case 2:
+ LOG.info("DSR, need to create OTU and ODU");
+ connType = ConnectionType.Service;
+ serviceFormat = ServiceFormat.Ethernet;
+ break;
+ case 3:
+ LOG.info("PHOTONIC");
+ connType = getConnectionTypePhtnc(endPointMap.values());
+ serviceFormat = getServiceFormatPhtnc(endPointMap.values());
+ if (serviceFormat.equals(ServiceFormat.OC)) {
+ nodeAid = String.join("+", endPointMap.values().stream().findFirst().get().getLocalId(),
+ TapiStringConstants.PHTNC_MEDIA);
+ nodeZid = String.join("+", endPointMap.values().stream().skip(1).findFirst().get().getLocalId(),
+ TapiStringConstants.PHTNC_MEDIA);
+ } else {
+ nodeAid = String.join("+", endPointMap.values().stream().findFirst().get().getLocalId(),
+ TapiStringConstants.OTSI);
+ nodeZid = String.join("+", endPointMap.values().stream().skip(1).findFirst().get().getLocalId(),
+ TapiStringConstants.OTSI);
+ }
+ LOG.debug("Node a photonic = {}", nodeAid);
+ LOG.debug("Node z photonic = {}", nodeZid);
+ break;
+ default:
+ LOG.info("Service type {} not supported", constraint.getServiceLayer().getName());
+ }
+ // Requested Capacity for connectivity service
+ Uint64 capacity = input.getConnectivityConstraint().getRequestedCapacity().getTotalSize().getValue();
+ // map endpoints into service end points. Map the type of service from TAPI to OR
+ ServiceAEnd serviceAEnd = tapiEndPointToServiceAPoint(endPointMap.values().stream().findFirst().get(),
+ serviceFormat, nodeAid, capacity, constraint.getServiceLayer());
+ ServiceZEnd serviceZEnd = tapiEndPointToServiceZPoint(endPointMap.values().stream().skip(1).findFirst().get(),
+ serviceFormat, nodeZid, capacity, constraint.getServiceLayer());
+ if (serviceAEnd == null || serviceZEnd == null) {
+ LOG.error("Couldnt map endpoints to service end");
+ return null;
+ }
+ LOG.info("Service a end = {}", serviceAEnd);
+ LOG.info("Service z end = {}", serviceZEnd);
+ return new ServiceCreateInputBuilder()
+ .setServiceAEnd(serviceAEnd)
+ .setServiceZEnd(serviceZEnd)
+ .setConnectionType(connType)
+ .setServiceName(serviceUuid.getValue())
+ .setCommonId("common id")
+ .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("request-1")
+ .setRpcAction(RpcActions.ServiceCreate).setNotificationUrl("notification url")
+ .setRequestSystemId("appname")
+ .build())
+ .setCustomer("customer")
+ .setDueDate(DateAndTime.getDefaultInstance("2018-06-15T00:00:01Z"))
+ .setOperatorContact("pw1234")
+ .build();
+ }
+
+ private ServiceZEnd tapiEndPointToServiceZPoint(
+ org.opendaylight.yang.gen.v1.urn
+ .onf.otcc.yang.tapi.connectivity.rev181210.create.connectivity.service.input.EndPoint endPoint,
+ ServiceFormat serviceFormat, String nodeZid, Uint64 capacity, LayerProtocolName serviceLayer) {
+ // TODO -> change way this is being created. The name includes only SPDR-SA1-XPDR1.
+ // Not the rest which is needed in the txPortDeviceName.
+ // It could be obtained from the SIP which has the NEP and includes all the OR name.
+ Uuid sipUuid = endPoint.getServiceInterfacePoint().getServiceInterfacePointUuid();
+ // Todo -> need to find the NEP associated to that SIP
+ Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes(nodeZid.getBytes(Charset.forName("UTF-8"))).toString());
+ org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node node =
+ this.tapiContext.getTapiNode(this.tapiTopoUuid, nodeUuid);
+ if (node == null) {
+ LOG.error("Node not found in datastore");
+ return null;
+ }
+ // TODO -> in case of a DSR service, for some requests we need the NETWORK PORT and not the CLIENT although the
+ // connection is between 2 CLIENT ports. Otherwise it will not work...
+ OwnedNodeEdgePoint nep = null;
+ for (OwnedNodeEdgePoint onep : node.getOwnedNodeEdgePoint().values()) {
+ if (onep.getMappedServiceInterfacePoint() == null) {
+ continue;
+ }
+ if (onep.getMappedServiceInterfacePoint().containsKey(new MappedServiceInterfacePointKey(sipUuid))) {
+ nep = onep;
+ break;
+ }
+ }
+ if (nep == null) {
+ LOG.error("Nep not found in datastore");
+ return null;
+ }
+ String nodeName = endPoint.getName().values().stream().findFirst().get().getValue();
+ String nodeid = String.join("-", nodeName.split("-")[0], nodeName.split("-")[1]);
+ String nepName = nep.getName().values().stream().findFirst().get().getValue();
+ String txPortDeviceName = nepName.split("\\+")[0];
+ String txPortName = nepName.split("\\+")[2];
+ String rxPortDeviceName = txPortDeviceName;
+ String rxPortName = txPortName;
+ LOG.debug("Node z id = {}, txportDeviceName = {}, txPortName = {}", nodeid, txPortDeviceName, txPortName);
+ LOG.debug("Node z id = {}, rxportDeviceName = {}, rxPortName = {}", nodeid, rxPortDeviceName, rxPortName);
+ // TODO --> get clli from datastore?
+ String clli = "NodeSC";
+ LOG.info("Node z id = {}, txportDeviceName = {}, txPortName = {}", nodeid, txPortDeviceName, txPortName);
+ LOG.info("Node z id = {}, rxportDeviceName = {}, rxPortName = {}", nodeid, rxPortDeviceName, rxPortName);
+ ServiceZEndBuilder serviceZEndBuilder = new ServiceZEndBuilder()
+ .setClli(clli)
+ .setNodeId(new NodeIdType(nodeid))
+ .setOpticType(OpticTypes.Gray)
+ .setServiceFormat(serviceFormat)
+ .setServiceRate(Uint32.valueOf(capacity))
+ .setEthernetAttributes(new EthernetAttributesBuilder().setSubrateEthSla(new SubrateEthSlaBuilder()
+ .setCommittedBurstSize(Uint16.valueOf(64))
+ .setCommittedInfoRate(Uint32.valueOf(100000))
+ .build())
+ .build())
+ .setTxDirection(Map.of(new TxDirectionKey(Uint8.ZERO), new TxDirectionBuilder()
+ .setPort(new PortBuilder()
+ .setPortDeviceName(txPortDeviceName)
+ .setPortName(txPortName)
+ .setPortRack(TapiStringConstants.PORT_RACK_VALUE)
+ .setPortShelf("00")
+ .setPortType(TapiStringConstants.PORT_TYPE)
+ .build())
+ .setLgx(new LgxBuilder()
+ .setLgxDeviceName(TapiStringConstants.LGX_DEVICE_NAME)
+ .setLgxPortName(TapiStringConstants.LGX_PORT_NAME)
+ .setLgxPortRack(TapiStringConstants.PORT_RACK_VALUE)
+ .setLgxPortShelf("00")
+ .build())
+ .setIndex(Uint8.ZERO)
+ .build()))
+ .setRxDirection(Map.of(new RxDirectionKey(Uint8.ZERO), new RxDirectionBuilder()
+ .setPort(new PortBuilder()
+ .setPortDeviceName(rxPortDeviceName)
+ .setPortName(rxPortName)
+ .setPortRack(TapiStringConstants.PORT_RACK_VALUE)
+ .setPortShelf("00")
+ .setPortType(TapiStringConstants.PORT_TYPE)
+ .build())
+ .setLgx(new LgxBuilder()
+ .setLgxDeviceName(TapiStringConstants.LGX_DEVICE_NAME)
+ .setLgxPortName(TapiStringConstants.LGX_PORT_NAME)
+ .setLgxPortRack(TapiStringConstants.PORT_RACK_VALUE)
+ .setLgxPortShelf("00")
+ .build())
+ .setIndex(Uint8.ZERO)
+ .build()));
+ if (serviceFormat.equals(ServiceFormat.ODU)) {
+ serviceZEndBuilder.setOduServiceRate(ODU4.class);
+ }
+ if (serviceFormat.equals(ServiceFormat.OTU)) {
+ serviceZEndBuilder.setOtuServiceRate(OTU4.class);
+ }
+ if (!serviceLayer.equals(LayerProtocolName.ETH)) {
+ serviceZEndBuilder
+ .setEthernetAttributes(new EthernetAttributesBuilder().setSubrateEthSla(new SubrateEthSlaBuilder()
+ .setCommittedBurstSize(Uint16.valueOf(64))
+ .setCommittedInfoRate(Uint32.valueOf(100000))
+ .build())
+ .build());
+ }
+ return serviceZEndBuilder.build();
+ }
+
+ private ServiceAEnd tapiEndPointToServiceAPoint(
+ org.opendaylight.yang.gen.v1.urn
+ .onf.otcc.yang.tapi.connectivity.rev181210.create.connectivity.service.input.EndPoint endPoint,
+ ServiceFormat serviceFormat, String nodeAid, Uint64 capacity, LayerProtocolName serviceLayer) {
+ // TODO -> change way this is being created. The name includes only SPDR-SA1-XPDR1.
+ // Not the rest which is needed in the txPortDeviceName.
+ // It could be obtained from the SIP which has the NEP and includes all the OR name.
+ Uuid sipUuid = endPoint.getServiceInterfacePoint().getServiceInterfacePointUuid();
+ // Todo -> need to find the NEP associated to that SIP
+ Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes(nodeAid.getBytes(Charset.forName("UTF-8"))).toString());
+ org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node node =
+ this.tapiContext.getTapiNode(this.tapiTopoUuid, nodeUuid);
+ if (node == null) {
+ LOG.error("Node not found in datastore");
+ return null;
+ }
+ // TODO -> in case of a DSR service, for some requests we need the NETWORK PORT and not the CLIENT although the
+ // connection is between 2 CLIENT ports. Otherwise it will not work...
+ OwnedNodeEdgePoint nep = null;
+ for (OwnedNodeEdgePoint onep : node.getOwnedNodeEdgePoint().values()) {
+ if (onep.getMappedServiceInterfacePoint() == null) {
+ continue;
+ }
+ if (onep.getMappedServiceInterfacePoint().containsKey(new MappedServiceInterfacePointKey(sipUuid))) {
+ nep = onep;
+ break;
+ }
+ }
+ if (nep == null) {
+ LOG.error("Nep not found in datastore");
+ return null;
+ }
+ String nodeName = endPoint.getName().values().stream().findFirst().get().getValue();
+ String nodeid = String.join("-", nodeName.split("-")[0], nodeName.split("-")[1]);
+ String nepName = nep.getName().values().stream().findFirst().get().getValue();
+ String txPortDeviceName = nepName.split("\\+")[0];
+ String txPortName = nepName.split("\\+")[2];
+ String rxPortDeviceName = txPortDeviceName;
+ String rxPortName = txPortName;
+ LOG.debug("Node a id = {}, txportDeviceName = {}, txPortName = {}", nodeid, txPortDeviceName, txPortName);
+ LOG.debug("Node a id = {}, rxportDeviceName = {}, rxPortName = {}", nodeid, rxPortDeviceName, rxPortName);
+ // TODO --> get clli from datastore?
+ String clli = "NodeSA";
+ LOG.info("Node a id = {}, txportDeviceName = {}, txPortName = {}", nodeid, txPortDeviceName, txPortName);
+ LOG.info("Node a id = {}, rxportDeviceName = {}, rxPortName = {}", nodeid, rxPortDeviceName, rxPortName);
+ ServiceAEndBuilder serviceAEndBuilder = new ServiceAEndBuilder()
+ .setClli(clli)
+ .setNodeId(new NodeIdType(nodeid))
+ .setOpticType(OpticTypes.Gray)
+ .setServiceFormat(serviceFormat)
+ .setServiceRate(Uint32.valueOf(capacity))
+ .setEthernetAttributes(new EthernetAttributesBuilder().setSubrateEthSla(
+ new org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.subrate.eth
+ .sla.SubrateEthSlaBuilder()
+ .setCommittedBurstSize(Uint16.valueOf(64))
+ .setCommittedInfoRate(Uint32.valueOf(100000))
+ .build())
+ .build())
+ .setTxDirection(Map.of(new TxDirectionKey(Uint8.ZERO), new TxDirectionBuilder()
+ .setPort(new PortBuilder()
+ .setPortDeviceName(txPortDeviceName)
+ .setPortName(txPortName)
+ .setPortRack(TapiStringConstants.PORT_RACK_VALUE)
+ .setPortShelf("00")
+ .setPortType(TapiStringConstants.PORT_TYPE)
+ .build())
+ .setLgx(new LgxBuilder()
+ .setLgxDeviceName(TapiStringConstants.LGX_DEVICE_NAME)
+ .setLgxPortName(TapiStringConstants.LGX_PORT_NAME)
+ .setLgxPortRack(TapiStringConstants.PORT_RACK_VALUE)
+ .setLgxPortShelf("00")
+ .build())
+ .setIndex(Uint8.ZERO)
+ .build()))
+ .setRxDirection(Map.of(new RxDirectionKey(Uint8.ZERO), new RxDirectionBuilder()
+ .setPort(new PortBuilder()
+ .setPortDeviceName(rxPortDeviceName)
+ .setPortName(rxPortName)
+ .setPortRack(TapiStringConstants.PORT_RACK_VALUE)
+ .setPortShelf("00")
+ .setPortType(TapiStringConstants.PORT_TYPE)
+ .build())
+ .setLgx(new LgxBuilder()
+ .setLgxDeviceName(TapiStringConstants.LGX_DEVICE_NAME)
+ .setLgxPortName(TapiStringConstants.LGX_PORT_NAME)
+ .setLgxPortRack(TapiStringConstants.PORT_RACK_VALUE)
+ .setLgxPortShelf("00")
+ .build())
+ .setIndex(Uint8.ZERO)
+ .build()));
+ if (serviceFormat.equals(ServiceFormat.ODU)) {
+ serviceAEndBuilder.setOduServiceRate(ODU4.class);
+ }
+ if (serviceFormat.equals(ServiceFormat.OTU)) {
+ serviceAEndBuilder.setOtuServiceRate(OTU4.class);
+ }
+ if (!serviceLayer.equals(LayerProtocolName.ETH)) {
+ serviceAEndBuilder
+ .setEthernetAttributes(new EthernetAttributesBuilder().setSubrateEthSla(new SubrateEthSlaBuilder()
+ .setCommittedBurstSize(Uint16.valueOf(64))
+ .setCommittedInfoRate(Uint32.valueOf(100000))
+ .build())
+ .build());
+ }
+ return serviceAEndBuilder.build();
+ }
+
+ private ConnectionType getConnectionTypePhtnc(Collection<org.opendaylight.yang.gen.v1.urn
+ .onf.otcc.yang.tapi.connectivity.rev181210.create.connectivity.service.input.EndPoint> endPoints) {
+ if (endPoints.stream().anyMatch(ep -> ep.getName().values().stream()
+ .anyMatch(name -> name.getValue().contains("ROADM")))) {
+ // EndPoints are ROADMs
+ return ConnectionType.RoadmLine;
+ }
+ // EndPoints ar not ROADMs -> XPDR, MUXPDR, SWTICHPDR
+ return ConnectionType.Infrastructure;
+ }
+
+ private ServiceFormat getServiceFormatPhtnc(Collection<org.opendaylight.yang.gen.v1.urn
+ .onf.otcc.yang.tapi.connectivity.rev181210.create.connectivity.service.input.EndPoint> endPoints) {
+ if (endPoints.stream().anyMatch(ep -> ep.getName().values().stream()
+ .anyMatch(name -> name.getValue().contains("ROADM")))) {
+ // EndPoints are ROADMs
+ return ServiceFormat.OC;
+ }
+ // EndPoints ar not ROADMs -> XPDR, MUXPDR, SWTICHPDR
+ return ServiceFormat.OTU;
+ }
+
+ private ConnectionEndPoint getAssociatediODUCep(String spcXpdrNetwork) {
+ Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", spcXpdrNetwork.split("\\+")[0],
+ TapiStringConstants.DSR).getBytes(Charset.forName("UTF-8")))).toString());
+ Uuid nepUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", spcXpdrNetwork.split("\\+")[0],
+ TapiStringConstants.I_ODU, spcXpdrNetwork.split("\\+")[1]).getBytes(Charset.forName("UTF-8"))))
+ .toString());
+ Uuid cepUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", "CEP",
+ spcXpdrNetwork.split("\\+")[0], TapiStringConstants.I_ODU, spcXpdrNetwork.split("\\+")[1]))
+ .getBytes(Charset.forName("UTF-8"))).toString());
+ return this.tapiContext.getTapiCEP(this.tapiTopoUuid, nodeUuid, nepUuid, cepUuid);
+ }
+
+ private String getAssociatedNetworkPort(String spcXpdrClient, List<String> xpdrNetworkTplist) {
+ for (String networkPort:xpdrNetworkTplist) {
+ if (networkPort.split("\\+")[0].equals(spcXpdrClient.split("\\+")[0])) {
+ return networkPort;
+ }
+ }
+ return null;
+ }
+
+ private List<String> getAssociatedClientsPort(List<String> xpdrNetworkTplist) {
+ List<String> clientPortList = new ArrayList<>();
+ for (String networkPort:xpdrNetworkTplist) {
+ String nodeId = String.join("-", networkPort.split("\\+")[0].split("-")[0],
+ networkPort.split("\\+")[0].split("-")[1]);
+ String tpId = networkPort.split("\\+")[1];
+ InstanceIdentifier<Mapping> mapIID = InstanceIdentifier.builder(Network.class)
+ .child(Nodes.class, new NodesKey(nodeId))
+ .child(Mapping.class, new MappingKey(tpId)).build();
+ try {
+ Optional<Mapping> optMapping = this.networkTransactionService.read(LogicalDatastoreType.CONFIGURATION,
+ mapIID).get();
+ if (!optMapping.isPresent()) {
+ LOG.error("Couldnt find mapping for port {} of node {}", tpId, nodeId);
+ }
+ Mapping mapping = optMapping.get();
+ LOG.info("Mapping for node+port {}+{} = {}", nodeId, tpId, mapping);
+ String key = String.join("+", String.join("-", nodeId, tpId.split("\\-")[0]),
+ mapping.getConnectionMapLcp());
+ LOG.info("Key to be added to list = {}", key);
+ if (!clientPortList.contains(key)) {
+ clientPortList.add(key);
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Couldnt read mapping from datastore", e);
+ return null;
+ }
+
+ }
+ return clientPortList;
+ }
+
+ private OpenroadmNodeType getOpenRoadmNodeType(List<String> xpdrNodelist) {
+ List<OpenroadmNodeType> openroadmNodeTypeList = new ArrayList<>();
+ for (String xpdrNode:xpdrNodelist) {
+ Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+",xpdrNode, TapiStringConstants.DSR))
+ .getBytes(Charset.forName("UTF-8"))).toString());
+ InstanceIdentifier<org.opendaylight.yang.gen.v1.urn
+ .onf.otcc.yang.tapi.topology.rev181210.topology.Node> nodeIID = InstanceIdentifier.builder(
+ Context.class).augmentation(org.opendaylight.yang.gen.v1.urn
+ .onf.otcc.yang.tapi.topology.rev181210.Context1.class).child(TopologyContext.class)
+ .child(Topology.class, new TopologyKey(this.tapiTopoUuid))
+ .child(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node.class,
+ new NodeKey(nodeUuid)).build();
+ try {
+ Optional<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node> optNode
+ = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, nodeIID).get();
+ if (!optNode.isPresent()) {
+ return null;
+ }
+ OpenroadmNodeType openroadmNodeType = OpenroadmNodeType.forName(optNode.get().getName().get(
+ new NameKey("Node Type")).getValue()).get();
+ if (!openroadmNodeTypeList.contains(openroadmNodeType)) {
+ openroadmNodeTypeList.add(openroadmNodeType);
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Couldnt read node in topology", e);
+ return null;
+ }
+ }
+ // TODO for now check that there is only one type, otherwise error
+ if (openroadmNodeTypeList.size() != 1) {
+ LOG.error("More than one xpdr type. List = {}", openroadmNodeTypeList);
+ return null;
+ }
+ return openroadmNodeTypeList.get(0);