- }
-
- @Override
- public ListenableFuture<RpcResult<GetNodeDetailsOutput>> getNodeDetails(GetNodeDetailsInput input) {
- // TODO Auto-generated method stub
- // TODO -> maybe we get errors when having CEPs?
- Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes(input.getTopologyIdOrName().getBytes(Charset.forName("UTF-8")))
- .toString());
- // Node id: if roadm -> ROADM+PHOTONIC_MEDIA. if xpdr -> XPDR-XPDR+DSR/OTSi
- Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes(input.getNodeIdOrName().getBytes(Charset.forName("UTF-8")))
- .toString());
- 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.<GetNodeDetailsOutput>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<RpcResult<GetTopologyDetailsOutput>> getTopologyDetails(GetTopologyDetailsInput input) {
- // TODO -> Add check for Full T0 Multilayer
- if (!TopologyUtils.T0_MULTILAYER.equals(input.getTopologyIdOrName())
- && !TopologyUtils.TPDR_100G.equals(input.getTopologyIdOrName())) {
- if (TopologyUtils.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<TopologyKey,
- org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.Topology>
- 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.<GetTopologyDetailsOutput>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.<GetTopologyDetailsOutput>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())) {
- topology = createAbstracted100GTpdrTopology(topology);
- }
- return RpcResultBuilder.success(new GetTopologyDetailsOutputBuilder().setTopology(topology).build())
- .buildFuture();
- } catch (TapiTopologyException e) {
- LOG.error("error building TAPI topology");
- return RpcResultBuilder.<GetTopologyDetailsOutput>failed()
- .withError(RpcError.ErrorType.RPC, "Error building topology").buildFuture();
- }
- }
-
- private Topology createAbstracted100GTpdrTopology(Topology topology) {
- List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node> dsrNodes =
- topology.nonnullNode().values().stream()
- .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
- .collect(Collectors.toList());
- List<OwnedNodeEdgePoint> nep100GTpdrList = new ArrayList<>();
- for (org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node node2: dsrNodes) {
- List<OwnedNodeEdgePoint> 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);
- return new TopologyBuilder()
- .setName(Map.of(topoName.key(), topoName))
- .setUuid(topoUuid)
- .setNode(Map.of(node.key(), node))
- .build();
- }
-
- private Network readTopology(InstanceIdentifier<Network> networkIID) throws TapiTopologyException {
- Network topology = null;
- FluentFuture<Optional<Network>> topologyFuture = dataBroker.newReadOnlyTransaction()
- .read(LogicalDatastoreType.CONFIGURATION, networkIID);
- try {
- topology = topologyFuture.get().get();
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- throw new TapiTopologyException("Unable to get from mdsal topology: " + networkIID
- .firstKeyOf(Network.class).getNetworkId().getValue(), e);
- } catch (ExecutionException e) {
- throw new TapiTopologyException("Unable to get from mdsal topology: " + networkIID
- .firstKeyOf(Network.class).getNetworkId().getValue(), e);
- }
- return topology;
- }
-
- private Topology createAbstractedOtnTopology() throws TapiTopologyException {
- // read openroadm-topology
- Network openroadmTopo = readTopology(InstanceIdentifiers.OVERLAY_NETWORK_II);
- List<Link> linkList = new ArrayList<>();
- if (openroadmTopo.augmentation(Network1.class) != null) {
- linkList.addAll(openroadmTopo.augmentation(Network1.class).getLink().values());
- }
- List<Link> xponderOutLinkList = linkList.stream()
- .filter(lk -> lk.augmentation(Link1.class).getLinkType().equals(OpenroadmLinkType.XPONDEROUTPUT))
- .collect(Collectors.toList());
- List<Link> xponderInLinkList = linkList.stream()
- .filter(lk -> lk.augmentation(Link1.class).getLinkType().equals(OpenroadmLinkType.XPONDERINPUT))
- .collect(Collectors.toList());
- // read otn-topology
- Network otnTopo = readTopology(InstanceIdentifiers.OTN_NETWORK_II);
- Map<NodeId, Node> otnNodeMap = otnTopo.nonnullNode().values().stream()
- .collect(Collectors.toMap(Node::getNodeId, node -> node));
-
- Map<String, List<String>> networkPortMap = new HashMap<>();
- Iterator<Entry<NodeId, Node>> itOtnNodeMap = otnNodeMap.entrySet().iterator();
- while (itOtnNodeMap.hasNext()) {
- Entry<NodeId, Node> entry = itOtnNodeMap.next();
- String portMappingNodeId = entry.getValue().getSupportingNode().values().stream()
- .filter(sn -> sn.getNetworkRef().getValue().equals(NetworkUtils.UNDERLAY_NETWORK_ID))
- .findFirst()
- .get().getNodeRef().getValue();
- List<String> networkPortList = new ArrayList<>();
- 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)) {
- networkPortList.add(tp.getTpId().getValue());
- }
- }
- if (!networkPortList.isEmpty()) {
- networkPortMap.put(entry.getKey().getValue(), networkPortList);
- }
- }
- Map<NodeKey, org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node>
- tapiNodeList = new HashMap<>();
- Map<LinkKey, org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Link>
- tapiLinkList = new HashMap<>();
- Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes(TopologyUtils.T0_MULTILAYER.getBytes(Charset.forName("UTF-8")))
- .toString());
- ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topoUuid);
- Iterator<Entry<String, List<String>>> it = networkPortMap.entrySet().iterator();
- while (it.hasNext()) {
- String nodeId = it.next().getKey();
- tapiFactory.convertNode(otnNodeMap.get(new NodeId(nodeId)), networkPortMap.get(nodeId));
- tapiNodeList.putAll(tapiFactory.getTapiNodes());
- 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) {
- tapiFactory.convertRoadmInfrastructure();
- tapiNodeList.putAll(tapiFactory.getTapiNodes());
- tapiLinkList.putAll(tapiFactory.getTapiLinks());
- } else {
- LOG.warn("Unable to abstract an ROADM infrasctructure from openroadm-topology");
- }
- if (otnTopo.augmentation(Network1.class) != null) {
- Map<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
- .ietf.network.topology.rev180226.networks.network.LinkKey, Link> 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();
- return new TopologyBuilder()
- .setName(Map.of(name.key(), name))
- .setUuid(topoUuid)
- .setNode(tapiNodeList)
- .setLink(tapiLinkList).build();
- }