X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=tapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Ftapi%2Ftopology%2FTapiTopologyImpl.java;h=09054272846b8d08e0cb761190b7c495ed46fc00;hb=268165cb2822b6ce4c55f00cac63eed2bb222ec7;hp=e9f97530d1e6bd31969ce3b4a7e601c6b1ee8b44;hpb=28f2a7aea63e35dd31dd883aa796d11838959324;p=transportpce.git diff --git a/tapi/src/main/java/org/opendaylight/transportpce/tapi/topology/TapiTopologyImpl.java b/tapi/src/main/java/org/opendaylight/transportpce/tapi/topology/TapiTopologyImpl.java index e9f97530d..090542728 100644 --- a/tapi/src/main/java/org/opendaylight/transportpce/tapi/topology/TapiTopologyImpl.java +++ b/tapi/src/main/java/org/opendaylight/transportpce/tapi/topology/TapiTopologyImpl.java @@ -10,6 +10,7 @@ package org.opendaylight.transportpce.tapi.topology; import com.google.common.util.concurrent.FluentFuture; import com.google.common.util.concurrent.ListenableFuture; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -27,15 +28,18 @@ import org.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.transportpce.common.InstanceIdentifiers; import org.opendaylight.transportpce.common.NetworkUtils; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210310.network.Nodes; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210310.network.NodesKey; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210310.network.nodes.Mapping; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210310.network.nodes.MappingKey; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.TerminationPoint1; -import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmLinkType; -import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmNodeType; -import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmTpType; +import org.opendaylight.transportpce.tapi.TapiStringConstants; +import org.opendaylight.transportpce.tapi.utils.TapiContext; +import org.opendaylight.transportpce.tapi.utils.TapiLink; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.Mapping; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.MappingKey; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network.Nodes; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network.NodesKey; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Link1; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.TerminationPoint1; +import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmLinkType; +import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmNodeType; +import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmTpType; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node; @@ -44,27 +48,49 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.top import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPoint; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.AdministrativeState; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Context; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.GetServiceInterfacePointDetailsInput; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.GetServiceInterfacePointDetailsOutput; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.GetServiceInterfacePointDetailsOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.GetServiceInterfacePointListInput; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.GetServiceInterfacePointListOutput; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.GetServiceInterfacePointListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LayerProtocolName; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LifecycleState; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.OperationalState; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.TapiCommonService; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.UpdateServiceInterfacePointInput; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.UpdateServiceInterfacePointOutput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.get.service._interface.point.list.output.Sip; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.get.service._interface.point.list.output.SipBuilder; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.get.service._interface.point.list.output.SipKey; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.Name; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameBuilder; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameKey; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.tapi.context.ServiceInterfacePoint; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.tapi.context.ServiceInterfacePointKey; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.ForwardingRule; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetLinkDetailsInput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetLinkDetailsOutput; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetLinkDetailsOutputBuilder; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetNodeDetailsInput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetNodeDetailsOutput; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetNodeDetailsOutputBuilder; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetNodeEdgePointDetailsInput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetNodeEdgePointDetailsOutput; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetNodeEdgePointDetailsOutputBuilder; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsInput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsOutput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsOutputBuilder; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyListInput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyListOutput; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.RuleType; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.TapiTopologyService; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.get.link.details.output.LinkBuilder; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.get.node.edge.point.details.output.NodeEdgePointBuilder; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.get.topology.details.output.Topology; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.get.topology.details.output.TopologyBuilder; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.NodeRuleGroup; @@ -78,65 +104,111 @@ import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.no import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.LinkKey; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.NodeBuilder; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.NodeKey; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.TopologyKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; +import org.opendaylight.yangtools.yang.common.RpcError; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class TapiTopologyImpl implements TapiTopologyService { +public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService { private static final Logger LOG = LoggerFactory.getLogger(TapiTopologyImpl.class); private final DataBroker dataBroker; + private final TapiContext tapiContext; + private final TopologyUtils topologyUtils; + private final TapiLink tapiLink; - public TapiTopologyImpl(DataBroker dataBroker) { + public TapiTopologyImpl(DataBroker dataBroker, TapiContext tapiContext, TopologyUtils topologyUtils, + TapiLink tapiLink) { this.dataBroker = dataBroker; + this.tapiContext = tapiContext; + this.topologyUtils = topologyUtils; + this.tapiLink = tapiLink; } @Override public ListenableFuture> getNodeDetails(GetNodeDetailsInput input) { // TODO Auto-generated method stub - return null; + // TODO -> maybe we get errors when having CEPs? + Uuid topoUuid = getUuidFromIput(input.getTopologyIdOrName()); + // Node id: if roadm -> ROADM+PHOTONIC_MEDIA. if xpdr -> XPDR-XPDR+DSR/OTSi + Uuid nodeUuid = getUuidFromIput(input.getNodeIdOrName()); + org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node node = this.tapiContext + .getTapiNode(topoUuid, nodeUuid); + if (node == null) { + LOG.error("Invalid TAPI node name"); + return RpcResultBuilder.failed().withError(RpcError.ErrorType.RPC, + "Invalid Tapi Node name").buildFuture(); + } + return RpcResultBuilder.success(new GetNodeDetailsOutputBuilder() + .setNode(new org.opendaylight.yang.gen.v1.urn + .onf.otcc.yang.tapi.topology.rev181210.get.node.details.output.NodeBuilder(node).build()) + .build()).buildFuture(); } @Override public ListenableFuture> getTopologyDetails(GetTopologyDetailsInput input) { - if (!TopologyUtils.T0_MULTILAYER.equals(input.getTopologyIdOrName()) - && !TopologyUtils.TPDR_100G.equals(input.getTopologyIdOrName())) { + // TODO -> Add check for Full T0 Multilayer + if (!TapiStringConstants.T0_MULTILAYER.equals(input.getTopologyIdOrName()) + && !TapiStringConstants.TPDR_100G.equals(input.getTopologyIdOrName())) { + if (TapiStringConstants.T0_FULL_MULTILAYER.equals(input.getTopologyIdOrName())) { + Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes(input.getTopologyIdOrName() + .getBytes(Charset.forName("UTF-8"))).toString()); + Context context = this.tapiContext.getTapiContext(); + Map + topologyMap = context.augmentation(Context1.class).getTopologyContext().getTopology(); + if (!(topologyMap != null && topologyMap.containsKey(new TopologyKey(topoUuid)))) { + LOG.error("Topology {} not found in datastore", input.getTopologyIdOrName()); + return RpcResultBuilder.failed() + .withError(RpcError.ErrorType.RPC, "Invalid Topology name").buildFuture(); + } + org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.Topology + topology = topologyMap.get(new TopologyKey(topoUuid)); + return RpcResultBuilder.success(new GetTopologyDetailsOutputBuilder() + .setTopology(this.topologyUtils.transformTopology(topology)) + .build()) + .buildFuture(); + } LOG.error("Invalid TAPI topology name"); - return RpcResultBuilder.success(new GetTopologyDetailsOutputBuilder().build()).buildFuture(); + return RpcResultBuilder.failed() + .withError(RpcError.ErrorType.RPC, "Invalid Topology name").buildFuture(); } try { LOG.info("Building TAPI Topology abstraction for {}", input.getTopologyIdOrName()); Topology topology = createAbstractedOtnTopology(); - if (TopologyUtils.TPDR_100G.equals(input.getTopologyIdOrName())) { + if (TapiStringConstants.TPDR_100G.equals(input.getTopologyIdOrName())) { topology = createAbstracted100GTpdrTopology(topology); } return RpcResultBuilder.success(new GetTopologyDetailsOutputBuilder().setTopology(topology).build()) .buildFuture(); } catch (TapiTopologyException e) { LOG.error("error building TAPI topology"); - return RpcResultBuilder.success(new GetTopologyDetailsOutputBuilder().build()).buildFuture(); + return RpcResultBuilder.failed() + .withError(RpcError.ErrorType.RPC, "Error building topology").buildFuture(); } } private Topology createAbstracted100GTpdrTopology(Topology topology) { - List dsrNodes - = topology.nonnullNode().values().stream() + List dsrNodes = + topology.nonnullNode().values().stream() .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR)) .collect(Collectors.toList()); List nep100GTpdrList = new ArrayList<>(); - for (org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node node2 : dsrNodes) { + for (org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node node2: dsrNodes) { List nepList = node2.getOwnedNodeEdgePoint().values().stream() .filter(nep -> nep.getName().containsKey(new NameKey("100G-tpdr"))).collect(Collectors.toList()); nep100GTpdrList.addAll(nepList); } - Name topoName = new NameBuilder().setValue(TopologyUtils.TPDR_100G).setValueName("TAPI Topology Name").build(); - Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes(TopologyUtils.TPDR_100G.getBytes(Charset.forName("UTF-8"))) - .toString()); - org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node node - = createTapiNode(nep100GTpdrList, topoUuid); + Name topoName = new NameBuilder().setValue(TapiStringConstants.TPDR_100G) + .setValueName("TAPI Topology Name").build(); + Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes( + TapiStringConstants.TPDR_100G.getBytes(Charset.forName("UTF-8"))).toString()); + org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node node = + createTapiNode(nep100GTpdrList, topoUuid); return new TopologyBuilder() .setName(Map.of(topoName.key(), topoName)) .setUuid(topoUuid) @@ -144,8 +216,7 @@ public class TapiTopologyImpl implements TapiTopologyService { .build(); } - private Network readTopology(InstanceIdentifier networkIID) - throws TapiTopologyException { + private Network readTopology(InstanceIdentifier networkIID) throws TapiTopologyException { Network topology = null; FluentFuture> topologyFuture = dataBroker.newReadOnlyTransaction() .read(LogicalDatastoreType.CONFIGURATION, networkIID); @@ -189,10 +260,10 @@ public class TapiTopologyImpl implements TapiTopologyService { .findFirst() .get().getNodeRef().getValue(); List networkPortList = new ArrayList<>(); - for (TerminationPoint tp : entry.getValue().augmentation(Node1.class).getTerminationPoint().values()) { + for (TerminationPoint tp: entry.getValue().augmentation(Node1.class).getTerminationPoint().values()) { if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK) - && - checkTp(entry.getKey().getValue(), portMappingNodeId, tp, xponderOutLinkList, xponderInLinkList)) { + && checkTp(entry.getKey().getValue(), portMappingNodeId, tp, xponderOutLinkList, + xponderInLinkList)) { networkPortList.add(tp.getTpId().getValue()); } } @@ -204,9 +275,9 @@ public class TapiTopologyImpl implements TapiTopologyService { tapiNodeList = new HashMap<>(); Map tapiLinkList = new HashMap<>(); - Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes(TopologyUtils.T0_MULTILAYER.getBytes(Charset.forName("UTF-8"))) - .toString()); - ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topoUuid); + Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes(TapiStringConstants.T0_MULTILAYER + .getBytes(Charset.forName("UTF-8"))).toString()); + ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topoUuid, this.tapiLink); Iterator>> it = networkPortMap.entrySet().iterator(); while (it.hasNext()) { String nodeId = it.next().getKey(); @@ -215,8 +286,8 @@ public class TapiTopologyImpl implements TapiTopologyService { tapiLinkList.putAll(tapiFactory.getTapiLinks()); } if (openroadmTopo.nonnullNode().values().stream().filter(nt -> - nt.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Node1.class) - .getNodeType().equals(OpenroadmNodeType.SRG)).count() > 0) { + nt.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Node1.class) + .getNodeType().equals(OpenroadmNodeType.SRG)).count() > 0) { tapiFactory.convertRoadmInfrastructure(); tapiNodeList.putAll(tapiFactory.getTapiNodes()); tapiLinkList.putAll(tapiFactory.getTapiLinks()); @@ -224,12 +295,16 @@ public class TapiTopologyImpl implements TapiTopologyService { LOG.warn("Unable to abstract an ROADM infrasctructure from openroadm-topology"); } if (otnTopo.augmentation(Network1.class) != null) { - Map otnLinkMap = otnTopo.augmentation(Network1.class).getLink(); + Map otnLinkMap = + otnTopo.augmentation(Network1.class).getLink(); tapiFactory.convertLinks(otnLinkMap); tapiLinkList.putAll(tapiFactory.getTapiLinks()); } - Name name = new NameBuilder().setValue(TopologyUtils.T0_MULTILAYER).setValueName("TAPI Topology Name").build(); + Name name = new NameBuilder() + .setValue(TapiStringConstants.T0_MULTILAYER) + .setValueName("TAPI Topology Name") + .build(); return new TopologyBuilder() .setName(Map.of(name.key(), name)) .setUuid(topoUuid) @@ -239,28 +314,73 @@ public class TapiTopologyImpl implements TapiTopologyService { @Override public ListenableFuture> getNodeEdgePointDetails( - GetNodeEdgePointDetailsInput input) { + GetNodeEdgePointDetailsInput input) { // TODO Auto-generated method stub - return null; + // TODO -> maybe we get errors when having CEPs? + Uuid topoUuid = getUuidFromIput(input.getTopologyIdOrName()); + // Node id: if roadm -> ROADMid+PHOTONIC_MEDIA. if xpdr -> XPDRid-XPDRnbr+DSR/OTSi + Uuid nodeUuid = getUuidFromIput(input.getNodeIdOrName()); + // NEP id: if roadm -> ROADMid+PHOTONIC_MEDIA/MC/OTSiMC+TPid. + // if xpdr -> XPDRid-XPDRnbr+DSR/eODU/iODU/iOTSi/eOTSi/PHOTONIC_MEDIA+TPid + Uuid nepUuid = getUuidFromIput(input.getEpIdOrName()); + OwnedNodeEdgePoint nep = this.tapiContext.getTapiNEP(topoUuid, nodeUuid, nepUuid); + if (nep == null) { + LOG.error("Invalid TAPI nep name"); + return RpcResultBuilder.failed().withError(RpcError.ErrorType.RPC, + "Invalid NEP name").buildFuture(); + } + return RpcResultBuilder.success(new GetNodeEdgePointDetailsOutputBuilder() + .setNodeEdgePoint(new NodeEdgePointBuilder(nep).build()).build()).buildFuture(); } @Override public ListenableFuture> getLinkDetails(GetLinkDetailsInput input) { // TODO Auto-generated method stub - return null; + Uuid topoUuid = getUuidFromIput(input.getTopologyIdOrName()); + // Link id: same as OR link id + Uuid linkUuid = getUuidFromIput(input.getLinkIdOrName()); + org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Link link = this.tapiContext + .getTapiLink(topoUuid, linkUuid); + if (link == null) { + LOG.error("Invalid TAPI link name"); + return RpcResultBuilder.failed().withError(RpcError.ErrorType.RPC, + "Invalid Link name").buildFuture(); + } + return RpcResultBuilder.success(new GetLinkDetailsOutputBuilder().setLink(new LinkBuilder(link).build()) + .build()).buildFuture(); } @Override public ListenableFuture> getTopologyList(GetTopologyListInput input) { // TODO Auto-generated method stub - return null; + // TODO -> maybe we get errors when having CEPs? + Map + topologyMap = this.tapiContext.getTopologyContext(); + if (topologyMap.isEmpty()) { + LOG.error("No topologies exist in tapi context"); + return RpcResultBuilder.failed().withError(RpcError.ErrorType.APPLICATION, + "No topologies exist in tapi context").buildFuture(); + } + Map + newTopoMap = new HashMap<>(); + for (org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.Topology + topo:topologyMap.values()) { + org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.get.topology.list.output.Topology + newTopo = new org.opendaylight.yang.gen.v1.urn + .onf.otcc.yang.tapi.topology.rev181210.get.topology.list.output.TopologyBuilder(topo).build(); + newTopoMap.put(newTopo.key(), newTopo); + } + return RpcResultBuilder.success(new GetTopologyListOutputBuilder().setTopology(newTopoMap).build()) + .buildFuture(); } private org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node createTapiNode(List nepList, Uuid topoUuid) { Name name = new NameBuilder().setValueName("Tpdr100g node name").setValue("Tpdr100g over WDM node").build(); Map onepMap = new HashMap<>(); - for (OwnedNodeEdgePoint ownedNodeEdgePoint : nepList) { + for (OwnedNodeEdgePoint ownedNodeEdgePoint: nepList) { onepMap.put(ownedNodeEdgePoint.key(), ownedNodeEdgePoint); } Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes(name.getValue().getBytes(Charset.forName("UTF-8"))).toString()); @@ -276,19 +396,19 @@ public class TapiTopologyImpl implements TapiTopologyService { .build(); } - private boolean checkTp(String nodeIdTopo, String nodeIdPortMap, TerminationPoint tp, List xpdOut, List< - Link> xpdIn) { + private boolean checkTp(String nodeIdTopo, String nodeIdPortMap, TerminationPoint tp, List xpdOut, + List xpdIn) { String networkLcp; if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERCLIENT)) { networkLcp = tp.augmentation( - org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.TerminationPoint1.class) + org.opendaylight.yang.gen.v1.http.transportpce.topology.rev220123.TerminationPoint1.class) .getAssociatedConnectionMapPort(); } else { networkLcp = tp.getTpId().getValue(); } @NonNull KeyedInstanceIdentifier pmIID = InstanceIdentifier.create( - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210310.Network.class) + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.Network.class) .child(Nodes.class, new NodesKey(nodeIdPortMap)).child(Mapping.class, new MappingKey(networkLcp)); @NonNull FluentFuture> mappingOpt = dataBroker.newReadOnlyTransaction().read( @@ -298,7 +418,7 @@ public class TapiTopologyImpl implements TapiTopologyService { try { mapping = mappingOpt.get().get(); } catch (InterruptedException | ExecutionException e) { - LOG.error("Error getting mapping for {}", networkLcp,e); + LOG.error("Error getting mapping for {}", networkLcp, e); return false; } } else { @@ -310,10 +430,10 @@ public class TapiTopologyImpl implements TapiTopologyService { long count = 0; switch (networkPortDirection) { case "bidirectional": - count += xpdOut.stream().filter(lk -> lk.getSource().getSourceNode().getValue().equals(nodeIdTopo) && lk - .getSource().getSourceTp().equals(networkLcp)).count(); + count += xpdOut.stream().filter(lk -> lk.getSource().getSourceNode().getValue().equals(nodeIdTopo) + && lk.getSource().getSourceTp().getValue().equals(networkLcp)).count(); count += xpdIn.stream().filter(lk -> lk.getDestination().getDestNode().getValue().equals(nodeIdTopo) - && lk.getDestination().getDestTp().equals(networkLcp)).count(); + && lk.getDestination().getDestTp().getValue().equals(networkLcp)).count(); return (count == 2); case "tx": case "rx": @@ -321,15 +441,15 @@ public class TapiTopologyImpl implements TapiTopologyService { String partnerLcp = mapping.getPartnerLcp(); if (mapping.getPortQual().equals("tx")) { count += xpdOut.stream().filter(lk -> lk.getSource().getSourceNode().getValue().equals(nodeIdTopo) - && lk.getSource().getSourceTp().equals(networkLcp)).count(); + && lk.getSource().getSourceTp().getValue().equals(networkLcp)).count(); count += xpdIn.stream().filter(lk -> lk.getDestination().getDestNode().getValue().equals(nodeIdTopo) - && lk.getDestination().getDestTp().equals(partnerLcp)).count(); + && lk.getDestination().getDestTp().getValue().equals(partnerLcp)).count(); } if (mapping.getPortQual().equals("rx")) { count += xpdIn.stream().filter(lk -> lk.getDestination().getDestNode().getValue().equals(nodeIdTopo) - && lk.getDestination().getDestTp().equals(networkLcp)).count(); + && lk.getDestination().getDestTp().getValue().equals(networkLcp)).count(); count += xpdOut.stream().filter(lk -> lk.getSource().getSourceNode().getValue().equals(nodeIdTopo) - && lk.getSource().getSourceTp().equals(partnerLcp)).count(); + && lk.getSource().getSourceTp().getValue().equals(partnerLcp)).count(); } return (count == 2); default: @@ -338,19 +458,20 @@ public class TapiTopologyImpl implements TapiTopologyService { } } - private Map createNodeRuleGroupFor100gTpdrNode(Uuid topoUuid, Uuid nodeUuid, - Collection onepl) { + private Map createNodeRuleGroupFor100gTpdrNode( + Uuid topoUuid, Uuid nodeUuid, Collection onepl) { + Map nepMap = new HashMap<>(); - for (OwnedNodeEdgePoint onep : onepl) { - org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePoint - nep = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group + for (OwnedNodeEdgePoint onep: onepl) { + org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePoint nep = + new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group .NodeEdgePointBuilder() - .setTopologyUuid(topoUuid) - .setNodeUuid(nodeUuid) - .setNodeEdgePointUuid(onep.key().getUuid()) - .build(); + .setTopologyUuid(topoUuid) + .setNodeUuid(nodeUuid) + .setNodeEdgePointUuid(onep.key().getUuid()) + .build(); nepMap.put(nep.key(), nep); } Map nodeRuleGroupMap = new HashMap<>(); @@ -370,4 +491,64 @@ public class TapiTopologyImpl implements TapiTopologyService { nodeRuleGroupMap.put(nodeRuleGroup.key(), nodeRuleGroup); return nodeRuleGroupMap; } + + @Override + public ListenableFuture> + getServiceInterfacePointDetails(GetServiceInterfacePointDetailsInput input) { + Uuid sipUuid = getUuidFromIput(input.getSipIdOrName()); + Map sips = + this.tapiContext.getTapiContext().getServiceInterfacePoint(); + if (sips == null || sips.isEmpty()) { + return RpcResultBuilder.failed().withError(RpcError.ErrorType.RPC, + "No sips in datastore").buildFuture(); + } + if (!sips.containsKey(new ServiceInterfacePointKey(sipUuid))) { + return RpcResultBuilder.failed().withError(RpcError.ErrorType.RPC, + "Sip doesnt exist in datastore").buildFuture(); + } + org.opendaylight.yang.gen.v1.urn + .onf.otcc.yang.tapi.common.rev181210.get.service._interface.point.details.output.Sip outSip = + new org.opendaylight.yang.gen.v1.urn + .onf.otcc.yang.tapi.common.rev181210.get.service._interface.point.details.output.SipBuilder( + sips.get(new ServiceInterfacePointKey(sipUuid))) + .build(); + return RpcResultBuilder.success(new GetServiceInterfacePointDetailsOutputBuilder().setSip(outSip).build()) + .buildFuture(); + } + + @Override + public ListenableFuture> + getServiceInterfacePointList(GetServiceInterfacePointListInput input) { + Map sips = + this.tapiContext.getTapiContext().getServiceInterfacePoint(); + if (sips == null || sips.isEmpty()) { + return RpcResultBuilder.failed().withError(RpcError.ErrorType.RPC, + "No sips in datastore").buildFuture(); + } + Map outSipMap = new HashMap<>(); + for (ServiceInterfacePoint sip : sips.values()) { + Sip si = new SipBuilder(sip).build(); + outSipMap.put(si.key(), si); + } + return RpcResultBuilder.success(new GetServiceInterfacePointListOutputBuilder().setSip(outSipMap).build()) + .buildFuture(); + } + + @Override + public ListenableFuture> + updateServiceInterfacePoint(UpdateServiceInterfacePointInput input) { + // TODO --> not yet implemented + return null; + } + + private Uuid getUuidFromIput(String serviceIdOrName) { + try { + UUID.fromString(serviceIdOrName); + LOG.info("Given attribute {} is a UUID", serviceIdOrName); + return new Uuid(serviceIdOrName); + } catch (IllegalArgumentException e) { + LOG.info("Given attribute {} is not a UUID", serviceIdOrName); + return new Uuid(UUID.nameUUIDFromBytes(serviceIdOrName.getBytes(StandardCharsets.UTF_8)).toString()); + } + } }