+
+ @Override
+ public void createOtnLinks(String nodeA, String tpA, String nodeZ, String tpZ, OtnLinkType linkType) {
+ TopologyShard otnTopologyShard;
+ switch (linkType) {
+ case OTU4:
+ otnTopologyShard = OpenRoadmOtnTopology.createOtnLinks(nodeA, tpA, nodeZ, tpZ, linkType);
+ break;
+ case ODTU4:
+ String nodeTopoA = new StringBuilder(nodeA).append("-").append(tpA.split("-")[0]).toString();
+ String nodeTopoZ = new StringBuilder(nodeZ).append("-").append(tpZ.split("-")[0]).toString();
+ List<LinkId> linkIdList = new ArrayList<>();
+ linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoA, tpA, nodeTopoZ, tpZ, "OTU4"));
+ linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoZ, tpZ, nodeTopoA, tpA, "OTU4"));
+ List<Link> supportedOtu4links = getOtnLinks(linkIdList);
+ List<TerminationPoint> tps = getOtnNodeTps(nodeTopoA, tpA, nodeTopoZ, tpZ);
+
+ otnTopologyShard = OpenRoadmOtnTopology.createOtnLinks(supportedOtu4links, tps);
+ 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, CREATE_MISSING_PARENTS);
+ }
+ }
+ if (otnTopologyShard.getTps() != null) {
+ for (TerminationPoint otnTopologyTp : otnTopologyShard.getTps()) {
+ LOG.info("updating otn nodes TP {} in otn-topology", otnTopologyTp.getTpId().getValue());
+ InstanceIdentifier<TerminationPoint> iiOtnTopologyTp = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+ .child(Node.class, new NodeKey(otnTopologyTp.getSupportingTerminationPoint().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> otu4Links;
+ List<LinkId> linkIdList = new ArrayList<>();
+ switch (linkType) {
+ case OTU4:
+ linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoA, tpA, nodeTopoZ, tpZ, "OTU4"));
+ linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoZ, tpZ, nodeTopoA, tpA, "OTU4"));
+ otu4Links = getOtnLinks(linkIdList);
+ if (checkLinks(otu4Links)) {
+ deleteLinks(otu4Links);
+ } else {
+ LOG.error("Error deleting OTU4 links");
+ }
+ otnTopologyShard = new TopologyShard(null, null);
+ break;
+ case ODTU4:
+ linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoA, tpA, nodeTopoZ, tpZ, "ODU4"));
+ linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoZ, tpZ, nodeTopoA, tpA, "ODU4"));
+ List<Link> odu4Links = getOtnLinks(linkIdList);
+ List<TerminationPoint> tps = getOtnNodeTps(nodeTopoA, tpA, nodeTopoZ, tpZ);
+ if (checkLinks(odu4Links) && checkTerminationPoints(tps)) {
+ deleteLinks(odu4Links);
+ linkIdList.clear();
+ linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoA, tpA, nodeTopoZ, tpZ, "OTU4"));
+ linkIdList.add(LinkIdUtil.buildOtnLinkId(nodeTopoZ, tpZ, nodeTopoA, tpA, "OTU4"));
+ otu4Links = getOtnLinks(linkIdList);
+ otnTopologyShard = OpenRoadmOtnTopology.deleteOtnLinks(otu4Links, tps);
+ } 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,
+ CREATE_MISSING_PARENTS);
+ }
+ }
+ if (otnTopologyShard.getTps() != null) {
+ for (TerminationPoint otnTopologyTp : otnTopologyShard.getTps()) {
+ LOG.info("updating otn nodes TP {} in otn-topology", otnTopologyTp.getTpId().getValue());
+ InstanceIdentifier<TerminationPoint> iiOtnTopologyTp = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+ .child(Node.class, new NodeKey(otnTopologyTp.getSupportingTerminationPoint().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(List<String> nodeTps, String serviceRate, Short tribPortNb, Short tribSoltNb,
+ boolean isDeletion) {
+ List<Link> supportedOdu4Links = getSupportingOdu4Links(nodeTps);
+ List<TerminationPoint> tps = getOtnNodeTps(nodeTps);
+ TopologyShard otnTopologyShard;
+ otnTopologyShard = OpenRoadmOtnTopology.updateOtnLinks(supportedOdu4Links, tps, serviceRate, tribPortNb,
+ tribSoltNb, 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, CREATE_MISSING_PARENTS);
+ }
+ }
+ if (otnTopologyShard.getTps() != null) {
+ for (TerminationPoint otnTopologyTp : otnTopologyShard.getTps()) {
+ LOG.info("updating otn nodes TP {} in otn-topology", otnTopologyTp.getTpId().getValue());
+ InstanceIdentifier<TerminationPoint> iiOtnTopologyTp = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+ .child(Node.class, new NodeKey(otnTopologyTp.getSupportingTerminationPoint().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);
+ }
+ }
+
+ 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) {
+ boolean canBeDeleted = true;
+ if (links.isEmpty()) {
+ return false;
+ } else {
+ for (Link link : links) {
+ if (link.augmentation(Link1.class) != null
+ && !link.augmentation(Link1.class).getUsedBandwidth().equals(Uint32.valueOf(0))) {
+ canBeDeleted = false;
+ }
+ }
+ }
+ return canBeDeleted;
+ }
+
+ private boolean checkTerminationPoints(List<TerminationPoint> tps) {
+ boolean canBeDeleted = true;
+ if (tps.isEmpty()) {
+ return false;
+ } else {
+ 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) {
+ canBeDeleted = false;
+ }
+ }
+ }
+ return canBeDeleted;
+ }
+
+ 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<String> nodeTopoTps) {
+ List<TerminationPoint> tps = new ArrayList<>();
+ for (String str : nodeTopoTps) {
+ String nodeId = str.split("--")[0];
+ String tp = str.split("--")[1];
+ 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<String> nodesTopoTps) {
+ 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().getLink().stream().filter(lk -> lk.getLinkId().getValue().startsWith("ODU4"))
+ .collect(Collectors.toList());
+ }
+ List<Link> links = new ArrayList<>();
+ if (odu4links != null) {
+ for (String str : nodesTopoTps) {
+ String[] nodeAndTp = str.split("--");
+ if (nodeAndTp.length >= 2) {
+ String nodeId = nodeAndTp[0];
+ String tp = nodeAndTp[1];
+ Link slink = odu4links.stream().filter(lk -> lk.getSource().getSourceNode().getValue()
+ .equals(nodeId) && lk.getSource().getSourceTp().toString().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().toString().equals(tp))
+ .findFirst().get();
+ if (!links.contains(dlink)) {
+ links.add(dlink);
+ }
+ }
+ }
+ LOG.debug("odu4links = {}", links.toString());
+ return links;
+ } else {
+ return null;
+ }
+ }
+
+ 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, CREATE_MISSING_PARENTS);
+ }
+ } else {
+ LOG.error("Unable to create OTN topology shard for node {}!", nodeId);
+ }
+
+ }