+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void updateOpenRoadmTopologies(String nodeId, Mapping mapping) {
+ LOG.info("update OpenRoadm topologies after change update from: {} ", nodeId);
+ this.topologyChanges.clear();
+ Network openroadmTopology = null;
+ Network otnTopology = null;
+ Map<LinkKey, Link> openroadmTopologyLinks = null;
+ Map<LinkKey, Link> otnTopologyLinks = null;
+ try {
+ openroadmTopology = this.networkTransactionService
+ .read(LogicalDatastoreType.CONFIGURATION, InstanceIdentifiers.OVERLAY_NETWORK_II)
+ .get().get();
+ if (openroadmTopology.augmentation(Network1.class) != null) {
+ openroadmTopologyLinks = openroadmTopology.augmentation(Network1.class).getLink();
+ }
+ otnTopology = this.networkTransactionService
+ .read(LogicalDatastoreType.CONFIGURATION, InstanceIdentifiers.OTN_NETWORK_II)
+ .get().get();
+ if (otnTopology.augmentation(Network1.class) != null) {
+ otnTopologyLinks = otnTopology.augmentation(Network1.class).getLink();
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Error when trying to update node : {}", nodeId, e);
+ }
+ if (openroadmTopology == null || otnTopology == null) {
+ LOG.warn("Error getting topologies from datastore");
+ return;
+ }
+ String abstractNodeid = String.join("-", nodeId, mapping.getLogicalConnectionPoint().split("-")[0]);
+ // nodes/links update in openroadm-topology
+ if (openroadmTopology.getNode() != null) {
+ TopologyShard topologyShard = TopologyUtils.updateTopologyShard(abstractNodeid, mapping,
+ openroadmTopology.getNode(), openroadmTopologyLinks);
+ if (topologyShard.getLinks() != null) {
+ for (Link link : topologyShard.getLinks()) {
+ LOG.info("updating links {} in {}", link.getLinkId().getValue(),
+ NetworkUtils.OVERLAY_NETWORK_ID);
+ InstanceIdentifier<Link> iiTopologyLink = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
+ .augmentation(Network1.class)
+ .child(Link.class, link.key())
+ .build();
+ networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiTopologyLink, link);
+ }
+ }
+ if (topologyShard.getTps() != null) {
+ for (TerminationPoint tp : topologyShard.getTps()) {
+ LOG.info("updating TP {} in openroadm-topology", tp.getTpId().getValue());
+ InstanceIdentifier<TerminationPoint> iiTopologyTp = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
+ .child(Node.class, new NodeKey(new NodeId(abstractNodeid)))
+ .augmentation(Node1.class)
+ .child(TerminationPoint.class, new TerminationPointKey(tp.getTpId()))
+ .build();
+ networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiTopologyTp, tp);
+ TopologyChanges tc = new TopologyChangesBuilder()
+ .withKey(new TopologyChangesKey(abstractNodeid, tp.getTpId().getValue()))
+ .setNodeId(abstractNodeid)
+ .setTpId(tp.getTpId().getValue())
+ .setState(tp.augmentation(
+ org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.TerminationPoint1
+ .class).getOperationalState())
+ .build();
+ if (!this.topologyChanges.containsKey(tc.key())) {
+ this.topologyChanges.put(tc.key(), tc);
+ }
+ }
+ }
+ }
+ // nodes/links update in otn-topology
+ if (otnTopology.getNode() != null
+ && otnTopology.getNode().containsKey(new NodeKey(new NodeId(abstractNodeid)))) {
+ TopologyShard otnShard = TopologyUtils.updateTopologyShard(abstractNodeid, mapping,
+ otnTopology.getNode(), otnTopologyLinks);
+ if (otnShard.getLinks() != null) {
+ for (Link link : otnShard.getLinks()) {
+ LOG.info("updating links {} in {}", link.getLinkId().getValue(),
+ NetworkUtils.OVERLAY_NETWORK_ID);
+ InstanceIdentifier<Link> iiTopologyLink = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+ .augmentation(Network1.class)
+ .child(Link.class, link.key())
+ .build();
+ networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiTopologyLink, link);
+ }
+ }
+ if (otnShard.getTps() != null) {
+ for (TerminationPoint tp : otnShard.getTps()) {
+ LOG.info("updating TP {} in otn-topology", tp.getTpId().getValue());
+ InstanceIdentifier<TerminationPoint> iiTopologyTp = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+ .child(Node.class, new NodeKey(new NodeId(abstractNodeid)))
+ .augmentation(Node1.class)
+ .child(TerminationPoint.class, new TerminationPointKey(tp.getTpId()))
+ .build();
+ networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiTopologyTp, tp);
+ TopologyChanges tc = new TopologyChangesBuilder()
+ .withKey(new TopologyChangesKey(abstractNodeid, tp.getTpId().getValue()))
+ .setNodeId(abstractNodeid)
+ .setTpId(tp.getTpId().getValue())
+ .setState(tp.augmentation(
+ org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.TerminationPoint1
+ .class).getOperationalState())
+ .build();
+ if (!this.topologyChanges.containsKey(tc.key())) {
+ this.topologyChanges.put(tc.key(), tc);
+ }
+ }
+ }
+ }
+ // commit datastore updates
+ try {
+ networkTransactionService.commit().get();
+ sendNotification();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Error updating openroadm-topology", e);
+ }
+ }
+
+ @Override
+ public void createOtnLinks(String nodeA, String tpA, String nodeZ, String tpZ, OtnLinkType linkType) {
+ TopologyShard otnTopologyShard;
+ switch (linkType) {
+ case OTU4:
+ case OTUC4:
+ otnTopologyShard = OpenRoadmOtnTopology.createOtnLinks(nodeA, tpA, nodeZ, tpZ, linkType);
+ break;
+ case ODTU4:
+ case ODUC4:
+ List<LinkId> linkIdList = new ArrayList<>();
+ String prefix;
+ if (OtnLinkType.ODTU4.equals(linkType)) {
+ prefix = OtnLinkType.OTU4.getName();
+ } else {
+ prefix = OtnLinkType.OTUC4.getName();
+ }
+ linkIdList.add(LinkIdUtil.buildOtnLinkId(convertNetconfNodeIdToTopoNodeId(nodeA, tpA), tpA,
+ convertNetconfNodeIdToTopoNodeId(nodeZ, tpZ), tpZ, prefix));
+ linkIdList.add(LinkIdUtil.buildOtnLinkId(convertNetconfNodeIdToTopoNodeId(nodeZ, tpZ), tpZ,
+ convertNetconfNodeIdToTopoNodeId(nodeA, tpA), tpA, prefix));
+ List<Link> supportedOtu4links = getOtnLinks(linkIdList);
+ List<TerminationPoint> tps = getOtnNodeTps(convertNetconfNodeIdToTopoNodeId(nodeA, tpA), tpA,
+ convertNetconfNodeIdToTopoNodeId(nodeZ, tpZ), tpZ);
+ otnTopologyShard = OpenRoadmOtnTopology.createOtnLinks(supportedOtu4links, tps, linkType);
+ break;
+ default:
+ LOG.error("unknown otn link type {}", linkType);
+ otnTopologyShard = new TopologyShard(null, null);
+ }
+ if (otnTopologyShard.getLinks() != null) {
+ for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
+ LOG.info("creating and updating otn links {} in {}", otnTopologyLink.getLinkId().getValue(),
+ NetworkUtils.OVERLAY_NETWORK_ID);
+ InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+ .augmentation(Network1.class)
+ .child(Link.class, otnTopologyLink.key())
+ .build();
+ networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
+ }
+ }
+ if (otnTopologyShard.getTps() != null) {
+ for (TerminationPoint otnTopologyTp : otnTopologyShard.getTps()) {
+ LOG.info("updating otn nodes TP {} in otn-topology", otnTopologyTp.getTpId().getValue());
+ List<SupportingTerminationPoint> supportingTerminationPoint =
+ new ArrayList<>(otnTopologyTp.nonnullSupportingTerminationPoint().values());
+ InstanceIdentifier<TerminationPoint> iiOtnTopologyTp = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+ .child(Node.class, new NodeKey(supportingTerminationPoint.get(0).getNodeRef()))
+ .augmentation(Node1.class)
+ .child(TerminationPoint.class, new TerminationPointKey(otnTopologyTp.getTpId()))
+ .build();
+ networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
+ }
+ }
+ try {
+ networkTransactionService.commit().get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Error adding OTN links in otn-topology", e);
+ }
+ LOG.info("OTN links created");
+ }
+
+ @Override
+ public void deleteOtnLinks(String nodeA, String tpA, String nodeZ, String tpZ, OtnLinkType linkType) {
+ TopologyShard otnTopologyShard;
+ String nodeTopoA = new StringBuilder(nodeA).append("-").append(tpA.split("-")[0]).toString();
+ String nodeTopoZ = new StringBuilder(nodeZ).append("-").append(tpZ.split("-")[0]).toString();
+ List<Link> otuLinks;
+ List<LinkId> linkIdList = new ArrayList<>();
+ String prefix;
+ switch (linkType) {
+ case OTU4:
+ case OTUC4:
+ if (OtnLinkType.OTU4.equals(linkType)) {
+ prefix = OtnLinkType.OTU4.getName();
+ } else {
+ prefix = OtnLinkType.OTUC4.getName();
+ }
+ linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoA, tpA, nodeTopoZ, tpZ, prefix));
+ linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoZ, tpZ, nodeTopoA, tpA, prefix));
+ otuLinks = getOtnLinks(linkIdList);
+ if (checkLinks(otuLinks)) {
+ deleteLinks(otuLinks);
+ } else {
+ LOG.error("Error deleting OTU4 links");
+ }
+ otnTopologyShard = new TopologyShard(null, null);
+ break;
+ case ODTU4:
+ case ODUC4:
+ String prefix2;
+ if (OtnLinkType.ODTU4.equals(linkType)) {
+ prefix = OtnLinkType.ODTU4.getName();
+ prefix2 = OtnLinkType.OTU4.getName();
+ } else {
+ prefix = OtnLinkType.ODUC4.getName();
+ prefix2 = OtnLinkType.OTUC4.getName();
+ }
+ linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoA, tpA, nodeTopoZ, tpZ, prefix));
+ linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoZ, tpZ, nodeTopoA, tpA, prefix));
+ List<Link> oduLinks = getOtnLinks(linkIdList);
+ List<TerminationPoint> tps = getOtnNodeTps(nodeTopoA, tpA, nodeTopoZ, tpZ);
+ if (checkLinks(oduLinks) && checkTerminationPoints(tps)) {
+ deleteLinks(oduLinks);
+ linkIdList.clear();
+ linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoA, tpA, nodeTopoZ, tpZ, prefix2));
+ linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoZ, tpZ, nodeTopoA, tpA, prefix2));
+ otuLinks = getOtnLinks(linkIdList);
+ otnTopologyShard = OpenRoadmOtnTopology.deleteOtnLinks(otuLinks, tps, linkType);
+ } else {
+ LOG.error("Error deleting ODU4 links");
+ otnTopologyShard = new TopologyShard(null, null);
+ }
+ break;
+ default:
+ LOG.error("unknown otn link type {}", linkType);
+ otnTopologyShard = new TopologyShard(null, null);
+ }
+ if (otnTopologyShard.getLinks() != null) {
+ for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
+ LOG.info("deleting and updating otn links {} in {}", otnTopologyLink.getLinkId().getValue(),
+ NetworkUtils.OVERLAY_NETWORK_ID);
+ InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+ .augmentation(Network1.class)
+ .child(Link.class, otnTopologyLink.key())
+ .build();
+ networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
+ }
+ }
+ if (otnTopologyShard.getTps() != null) {
+ for (TerminationPoint otnTopologyTp : otnTopologyShard.getTps()) {
+ LOG.info("updating otn nodes TP {} in otn-topology", otnTopologyTp.getTpId().getValue());
+ List<SupportingTerminationPoint> supportingTerminationPoint =
+ new ArrayList<>(otnTopologyTp.nonnullSupportingTerminationPoint().values());
+ InstanceIdentifier<TerminationPoint> iiOtnTopologyTp = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+ .child(Node.class, new NodeKey(supportingTerminationPoint.get(0).getNodeRef()))
+ .augmentation(Node1.class)
+ .child(TerminationPoint.class, new TerminationPointKey(otnTopologyTp.getTpId()))
+ .build();
+ networkTransactionService.put(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
+ }
+ }
+ try {
+ networkTransactionService.commit().get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Error deleting OTN links in otn-topology", e);
+ }
+ LOG.info("OTN links deletion terminated");
+ }
+
+ @Override
+ public void updateOtnLinks(
+ org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.renderer.rpc.result.sp.Link
+ notifLink, Uint32 serviceRate, Short tribPortNb, Short minTribSoltNb, Short maxTribSlotNb,
+ boolean isDeletion) {
+
+ LinkTp atermination = new LinkTpBuilder()
+ .setNodeId(notifLink.getATermination().getNodeId())
+ .setTpId(notifLink.getATermination().getTpId())
+ .build();
+ LinkTp ztermination = new LinkTpBuilder()
+ .setNodeId(notifLink.getZTermination().getNodeId())
+ .setTpId(notifLink.getZTermination().getTpId())
+ .build();
+ List<LinkTp> linkTerminations = new ArrayList<>();
+ linkTerminations.add(atermination);
+ linkTerminations.add(ztermination);
+
+ List<Link> supportedOdu4Links = getSupportingOdu4Links(linkTerminations, serviceRate);
+ List<TerminationPoint> tps = getOtnNodeTps(linkTerminations);
+ TopologyShard otnTopologyShard;
+ otnTopologyShard = OpenRoadmOtnTopology.updateOtnLinks(supportedOdu4Links, tps, serviceRate, tribPortNb,
+ minTribSoltNb, maxTribSlotNb, isDeletion);
+ if (otnTopologyShard.getLinks() != null) {
+ for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
+ LOG.info("creating and updating otn links {} in {}", otnTopologyLink.getLinkId().getValue(),
+ NetworkUtils.OVERLAY_NETWORK_ID);
+ InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+ .augmentation(Network1.class)
+ .child(Link.class, new LinkKey(new LinkId(otnTopologyLink.getLinkId().getValue())))
+ .build();
+ networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
+ }
+ }
+ if (otnTopologyShard.getTps() != null) {
+ for (TerminationPoint otnTopologyTp : otnTopologyShard.getTps()) {
+ LOG.info("updating otn nodes TP {} in otn-topology", otnTopologyTp.getTpId().getValue());
+ List<SupportingTerminationPoint> supportingTerminationPoint =
+ new ArrayList<>(otnTopologyTp.nonnullSupportingTerminationPoint().values());
+ InstanceIdentifier<TerminationPoint> iiOtnTopologyTp = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+ .child(Node.class, new NodeKey(supportingTerminationPoint.get(0).getNodeRef()))
+ .augmentation(Node1.class)
+ .child(TerminationPoint.class, new TerminationPointKey(new TpId(otnTopologyTp.getTpId()
+ .getValue())))
+ .build();
+ if (isDeletion) {
+ networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
+ } else {
+ networkTransactionService.put(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyTp, otnTopologyTp);
+ }
+ }
+ }
+ try {
+ networkTransactionService.commit().get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Error updating OTN links in otn-topology", e);
+ }
+ }
+
+ @Override
+ public void updateOtnLinks(
+ org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.renderer.rpc.result.sp.Link
+ notifLink, List<String> suppLinks, boolean isDeletion) {
+
+ List<LinkId> linkIdList = new ArrayList<>();
+ if (notifLink != null) {
+ String nodeTopoA = convertNetconfNodeIdToTopoNodeId(notifLink.getATermination().getNodeId(),
+ notifLink.getATermination().getTpId());
+ String nodeTopoZ = convertNetconfNodeIdToTopoNodeId(notifLink.getZTermination().getNodeId(),
+ notifLink.getZTermination().getTpId());
+ linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoA, notifLink.getATermination().getTpId(),
+ nodeTopoZ, notifLink.getZTermination().getTpId(), OtnLinkType.OTU4.getName()));
+ linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoZ, notifLink.getZTermination().getTpId(),
+ nodeTopoA, notifLink.getATermination().getTpId(), OtnLinkType.OTU4.getName()));
+ } else if (suppLinks != null) {
+ suppLinks.forEach(lk -> linkIdList.add(new LinkId(lk)));
+ } else {
+ LOG.error("Impossible to determine supported otn links without correct input data");
+ }
+ List<Link> supportedOtu4links = getOtnLinks(linkIdList);
+
+ TopologyShard otnTopologyShard = OpenRoadmOtnTopology.updateOtnLinks(supportedOtu4links, isDeletion);
+ if (otnTopologyShard.getLinks() != null) {
+ for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
+ LOG.info("creating and updating otn links {} in {}", otnTopologyLink.getLinkId().getValue(),
+ NetworkUtils.OVERLAY_NETWORK_ID);
+ InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+ .augmentation(Network1.class)
+ .child(Link.class, otnTopologyLink.key())
+ .build();
+ networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
+ }
+ }
+ try {
+ networkTransactionService.commit().get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Error adding OTN links in otn-topology", e);
+ }
+ LOG.info("OTN links updated");
+ }
+
+ private List<Link> getOtnLinks(List<LinkId> linkIds) {
+ List<Link> links = new ArrayList<>();
+ for (LinkId linkId : linkIds) {
+ InstanceIdentifier<Link> iiLink = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+ .augmentation(Network1.class)
+ .child(Link.class, new LinkKey(linkId))
+ .build();
+ ListenableFuture<Optional<Link>> linkOptLf = networkTransactionService
+ .read(LogicalDatastoreType.CONFIGURATION, iiLink);
+ if (linkOptLf.isDone()) {
+ try {
+ if (linkOptLf.get().isPresent()) {
+ links.add(linkOptLf.get().get());
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Error retreiving OTN links from otn-topology", e);
+ }
+ } else {
+ LOG.error("Error retreiving link {} from otn-topology", linkId.getValue());
+ }
+ }
+ return links;
+ }
+
+ private boolean checkLinks(List<Link> links) {
+ if (links.isEmpty()) {
+ return false;
+ }
+ for (Link link : links) {
+ if (link.augmentation(Link1.class) != null
+ && !link.augmentation(Link1.class).getUsedBandwidth().equals(Uint32.valueOf(0))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private boolean checkTerminationPoints(List<TerminationPoint> tps) {
+ if (tps.isEmpty()) {
+ return false;
+ }
+ for (TerminationPoint tp : tps) {
+ if (tp.augmentation(TerminationPoint1.class) != null && tp.augmentation(TerminationPoint1.class)
+ .getXpdrTpPortConnectionAttributes().getTsPool() != null && tp.augmentation(TerminationPoint1.class)
+ .getXpdrTpPortConnectionAttributes().getTsPool().size() != 80) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private List<TerminationPoint> getOtnNodeTps(String nodeTopoA, String tpA, String nodeTopoZ, String tpZ) {
+ List<TerminationPoint> tps = new ArrayList<>();
+ InstanceIdentifier<TerminationPoint> iiTpA = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+ .child(Node.class, new NodeKey(new NodeId(nodeTopoA)))
+ .augmentation(Node1.class)
+ .child(TerminationPoint.class, new TerminationPointKey(new TpId(tpA)))
+ .build();
+ Optional<TerminationPoint> tpAOpt = Optional.empty();
+ InstanceIdentifier<TerminationPoint> iiTpZ = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+ .child(Node.class, new NodeKey(new NodeId(nodeTopoZ)))
+ .augmentation(Node1.class)
+ .child(TerminationPoint.class, new TerminationPointKey(new TpId(tpZ)))
+ .build();
+ Optional<TerminationPoint> tpZOpt = Optional.empty();
+
+ if (networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpA).isDone()
+ && networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpZ).isDone()) {
+ try {
+ tpAOpt = networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpA).get();
+ tpZOpt = networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTpZ).get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Error retreiving tp {} of node {} or tp {} from node {} from otn-topology", tpA, nodeTopoA,
+ tpZ, nodeTopoZ, e);
+ }
+ } else {
+ LOG.error("error getting node termination points from the datastore");
+ }
+
+ if (tpAOpt.isPresent() && tpZOpt.isPresent()) {
+ tps.add(tpAOpt.get());
+ tps.add(tpZOpt.get());
+ }
+ return tps;
+ }
+
+ private List<TerminationPoint> getOtnNodeTps(List<LinkTp> linkTerminations) {
+ List<TerminationPoint> tps = new ArrayList<>();
+ for (LinkTp linkTp : linkTerminations) {
+ String tp = linkTp.getTpId();
+ String nodeId = new StringBuilder(linkTp.getNodeId()).append("-")
+ .append(tp.split("-")[0]).toString();
+ InstanceIdentifier<TerminationPoint> iiTp = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+ .child(Node.class, new NodeKey(new NodeId(nodeId)))
+ .augmentation(Node1.class)
+ .child(TerminationPoint.class, new TerminationPointKey(new TpId(tp)))
+ .build();
+ Optional<TerminationPoint> tpOpt;
+ if (networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTp).isDone()) {
+ try {
+ tpOpt = networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, iiTp).get();
+ if (tpOpt.isPresent()) {
+ tps.add(tpOpt.get());
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Error retreiving tp {} of node {} from otn-topology", tp, nodeId, e);
+ }
+ } else {
+ LOG.error("error getting node termination points from the datastore");
+ }
+ }
+ if (tps.isEmpty()) {
+ LOG.warn("returning null");
+ return null;
+ } else {
+ LOG.info("returning tps = {}", tps.toString());
+ return tps;
+ }
+ }
+
+ private void deleteLinks(List<Link> links) {
+ for (Link otnTopologyLink : links) {
+ LOG.info("deleting link {} from {}", otnTopologyLink.getLinkId().getValue(),
+ NetworkUtils.OVERLAY_NETWORK_ID);
+ InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+ .augmentation(Network1.class)
+ .child(Link.class, otnTopologyLink.key())
+ .build();
+ networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink);
+ }
+ try {
+ networkTransactionService.commit().get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Error deleting OTN links from otn-topology", e);
+ }
+ }
+
+ private List<Link> getSupportingOdu4Links(List<LinkTp> nodesTopoTps, Uint32 serviceRate) {
+ InstanceIdentifier<Network1> iiOtnTopologyLinks = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+ .augmentation(Network1.class)
+ .build();
+ ListenableFuture<Optional<Network1>> netw1Fl = networkTransactionService
+ .read(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLinks);
+ Optional<Network1> netw1Opt = Optional.empty();
+ if (netw1Fl.isDone()) {
+ try {
+ netw1Opt = netw1Fl.get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Error retreiving list of links from otn-topology", e);
+ }
+ }
+ List<Link> odu4links = null;
+ if (netw1Opt.isPresent() && netw1Opt.get().getLink() != null) {
+ odu4links = netw1Opt
+ .get()
+ .nonnullLink().values()
+ .stream().filter(lk -> lk.getLinkId().getValue()
+ .startsWith(Uint32.valueOf(100).equals(serviceRate) ? "ODUC4" : "ODTU4"))
+ .collect(Collectors.toList());
+ }
+ if (odu4links == null) {
+ return null;
+ }
+ List<Link> links = new ArrayList<>();
+ for (LinkTp linkTp : nodesTopoTps) {
+ String tp = linkTp.getTpId();
+ String nodeId = new StringBuilder(linkTp.getNodeId()).append("-")
+ .append(tp.split("-")[0]).toString();
+ Link slink = odu4links.stream().filter(lk -> lk.getSource().getSourceNode().getValue()
+ .equals(nodeId) && lk.getSource().getSourceTp().getValue().equals(tp)).findFirst().get();
+ if (!links.contains(slink)) {
+ links.add(slink);
+ }
+ Link dlink = odu4links.stream().filter(lk -> lk.getDestination().getDestNode().getValue()
+ .equals(nodeId) && lk.getDestination().getDestTp().getValue().equals(tp)).findFirst().get();
+ if (!links.contains(dlink)) {
+ links.add(dlink);
+ }
+ }
+ LOG.debug("odu4oduC4links = {}", links);
+ return links;
+ }
+
+ private void createOpenRoadmOtnNode(String nodeId) {
+ TopologyShard otnTopologyShard = OpenRoadmOtnTopology.createTopologyShard(portMapping.getNode(nodeId));
+ if (otnTopologyShard != null) {
+ this.otnTopologyShardMountedDevice.put(nodeId, otnTopologyShard);
+ for (Node otnTopologyNode : otnTopologyShard.getNodes()) {
+ LOG.info("creating otn node {} in {}", otnTopologyNode.getNodeId().getValue(),
+ NetworkUtils.OTN_NETWORK_ID);
+ InstanceIdentifier<Node> iiOtnTopologyNode = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+ .child(Node.class, otnTopologyNode.key())
+ .build();
+ networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyNode, otnTopologyNode);
+ }
+ for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
+ LOG.info("creating otn link {} in {}", otnTopologyLink.getLinkId().getValue(),
+ NetworkUtils.OVERLAY_NETWORK_ID);
+ InstanceIdentifier<Link> iiOtnTopologyLink = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+ .augmentation(Network1.class)
+ .child(Link.class, otnTopologyLink.key())
+ .build();
+ networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
+ }
+ } else {
+ LOG.error("Unable to create OTN topology shard for node {}!", nodeId);
+ }
+ }
+
+ private String convertNetconfNodeIdToTopoNodeId(String nodeId, String tpId) {
+ return new StringBuilder(nodeId).append("-").append(tpId.split("-")[0]).toString();
+ }
+
+ @SuppressFBWarnings(
+ value = "UPM_UNCALLED_PRIVATE_METHOD",
+ justification = "false positive, this method is used by public updateOpenRoadmNetworkTopology")
+ private void sendNotification() {
+ if (topologyChanges.isEmpty()) {
+ LOG.warn("Empty Topology Change List. No updates in topology");
+ return;
+ }
+ this.notification = new TopologyUpdateResultBuilder()
+ .setTopologyChanges(topologyChanges)
+ .build();
+ try {
+ notificationPublishService.putNotification(this.notification);
+ } catch (InterruptedException e) {
+ LOG.error("Notification offer rejected. Error={}", e.getMessage());