X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pce%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fpce%2Fnetworkanalyzer%2FMapUtils.java;h=cd3fe88e1a3ffeadb7533b01631cbec8b71fc8c6;hb=bc9a08be9d7cdeb30ecffd3c82ddd656a3a23043;hp=6ee3043d8a722afc95772a70d47a556426f4a491;hpb=7c90be243c9c65418b81768e1e0ed6ac58bad4a8;p=transportpce.git diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/networkanalyzer/MapUtils.java b/pce/src/main/java/org/opendaylight/transportpce/pce/networkanalyzer/MapUtils.java index 6ee3043d8..cd3fe88e1 100644 --- a/pce/src/main/java/org/opendaylight/transportpce/pce/networkanalyzer/MapUtils.java +++ b/pce/src/main/java/org/opendaylight/transportpce/pce/networkanalyzer/MapUtils.java @@ -9,21 +9,29 @@ package org.opendaylight.transportpce.pce.networkanalyzer; import java.util.ArrayList; import java.util.Arrays; +import java.util.Iterator; import java.util.List; - +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; +import org.opendaylight.transportpce.common.NetworkUtils; import org.opendaylight.transportpce.pce.constraints.PceConstraints; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1; import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attributes.LinkConcatenation; -import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Link1; - +import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attributes.LinkConcatenationKey; import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.networks.network.link.oms.attributes.Span; import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmLinkType; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.node.SupportingNode; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId; 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.link.SupportingLink; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public final class MapUtils { + private static final String MAP_UTILS_NO_LINK_AUGMENTATION_AVAILABLE_MSG = + "MapUtils: No Link augmentation available. {}"; /* Logging. */ private static final Logger LOG = LoggerFactory.getLogger(MapUtils.class); @@ -37,7 +45,7 @@ public final class MapUtils { List excSrlgLinks = pceHardConstraints.getExcludeSrlgLinks(); LOG.info("mapDiversityConstraints before : ExcludeClliNodes {} \n ExcludeNodes {} \n ExcludeSrlgLinks {}", - excClliNodes.toString(), excNodes.toString(), excSrlgLinks.toString()); + excClliNodes, excNodes, excSrlgLinks); for (Node node : allNodes) { if (excClliNodes.contains(node.getNodeId().getValue())) { @@ -47,7 +55,7 @@ public final class MapUtils { if (excNodes.contains(node.getNodeId().getValue())) { LOG.debug("mapDiversityConstraints setExcludeSupNodes for node {}", node.getNodeId().getValue()); - pceHardConstraints.setExcludeSupNodes(Arrays.asList(getSupNode(node))); + pceHardConstraints.setExcludeSupNodes(Arrays.asList(getSupNetworkNode(node))); } } @@ -60,40 +68,123 @@ public final class MapUtils { if (!srlg.isEmpty()) { pceHardConstraints.setExcludeSRLG(srlg); LOG.debug("mapDiversityConstraints setExcludeSRLG {} for link {}", - srlg.toString(), link.getLinkId().getValue()); + srlg, link.getLinkId().getValue()); } } } } LOG.info("mapDiversityConstraints after : ExcludeCLLI {} \n ExcludeSupNodes {} \n ExcludeSRLG {}", - pceHardConstraints.getExcludeCLLI().toString(), - pceHardConstraints.getExcludeSupNodes().toString(), - pceHardConstraints.getExcludeSRLG().toString()); + pceHardConstraints.getExcludeCLLI(), + pceHardConstraints.getExcludeSupNodes(), + pceHardConstraints.getExcludeSRLG()); } public static String getCLLI(Node node) { // TODO STUB retrieve CLLI from node. for now it is supporting node ID of the first supp node - return node.getSupportingNode().get(0).getNodeRef().getValue(); + return node.nonnullSupportingNode().values().iterator().next().getNodeRef().getValue(); } public static List getSRLG(Link link) { - List srlgList = new ArrayList(); - try { - List linkList = getOmsAttributesSpan(link).getLinkConcatenation(); - for (LinkConcatenation lc : linkList) { - srlgList.add(lc.getSRLGId()); - } - } catch (NullPointerException e) { + Span omsAttributesSpan = getOmsAttributesSpan(link); + if (omsAttributesSpan == null) { LOG.debug("No concatenation for this link"); + return new ArrayList<>(); + } + List srlgList = new ArrayList<>(); + Map linkList = omsAttributesSpan.nonnullLinkConcatenation(); + for (LinkConcatenation lc : linkList.values()) { + if (lc != null && lc.getSRLGId() != null) { + srlgList.add(lc.getSRLGId().toJava()); + } + } + return srlgList; + } + + public static List getSRLGfromLink(Link link) { + org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1 linkC = link + .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1.class); + if (linkC == null) { + LOG.error(MAP_UTILS_NO_LINK_AUGMENTATION_AVAILABLE_MSG, link.getLinkId().getValue()); + return new ArrayList<>(); + } + List srlgList = new ArrayList<>(); + for (org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130 + .networks.network.link.LinkConcatenation lc : linkC.nonnullLinkConcatenation().values()) { + if (lc != null && lc.getSRLGId() != null) { + srlgList.add(lc.getSRLGId().toJava()); + } else { + LOG.debug("No concatenation or SLRG id for this link"); + } } return srlgList; } - public static String getSupNode(Node node) { - // TODO: supporting IDs exist as a List. this code takes just the first element - return node.getSupportingNode().get(0).getNodeRef().getValue(); + public static String getSupNetworkNode(Node node) { + for (SupportingNode snode : node.nonnullSupportingNode().values()) { + if (NetworkUtils.UNDERLAY_NETWORK_ID.equals(snode.getNetworkRef().getValue())) { + return snode.getNodeRef().getValue(); + } + } + return null; + } + + public static String getSupClliNode(Node node) { + for (SupportingNode snode : node.nonnullSupportingNode().values()) { + if (NetworkUtils.CLLI_NETWORK_ID.equals(snode.getNetworkRef().getValue())) { + return snode.getNodeRef().getValue(); + } + } + return null; + } + + public static SortedMap getAllSupNode(Node node) { + TreeMap allSupNodes = new TreeMap<>(); + for (SupportingNode supnode : node.nonnullSupportingNode().values()) { + allSupNodes.put(supnode.getNetworkRef().getValue(), + supnode.getNodeRef().getValue()); + } + return allSupNodes; + } + + public static String getSupLink(Link link) { + Iterator supportingLinkIterator = link.nonnullSupportingLink().values().iterator(); + if (!supportingLinkIterator.hasNext()) { + return ""; + } + SupportingLink first = supportingLinkIterator.next(); + if (first == null || first.getLinkRef() == null) { + return ""; + } + return first.getLinkRef().toString(); + } + + + public static Long getAvailableBandwidth(Link link) { + if (link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130 + .Link1.class) != null + && link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130 + .Link1.class).getAvailableBandwidth() != null) { + return link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130 + .Link1.class).getAvailableBandwidth().toJava(); + } else { + LOG.warn("MapUtils: no Available Bandwidth available for link {}", link.getLinkId()); + return 0L; + } + } + + public static Long getUsedBandwidth(Link link) { + if (link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130 + .Link1.class) != null + && link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130 + .Link1.class).getUsedBandwidth() != null) { + return link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130 + .Link1.class).getUsedBandwidth().toJava(); + } else { + LOG.warn("MapUtils: no Available Bandwidth available for link {}", link.getLinkId()); + return 0L; + } } public static OpenroadmLinkType calcType(Link link) { @@ -102,11 +193,12 @@ public final class MapUtils { // ID and type link1 = link.augmentation(Link1.class); if (link1 == null) { - LOG.error("MapUtils: No Link augmentation available. {}", link.getLinkId().getValue()); + LOG.error(MAP_UTILS_NO_LINK_AUGMENTATION_AVAILABLE_MSG, link.getLinkId().getValue()); return null; } tmplType = link1.getLinkType(); + if (tmplType == null) { LOG.error("MapUtils: No Link type available. {}", link.getLinkId().getValue()); return null; @@ -115,20 +207,19 @@ public final class MapUtils { } public static Span getOmsAttributesSpan(Link link) { - Link1 link1 = null; - Span tempSpan = null; - link1 = link.augmentation(Link1.class); + org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Link1 link1 = null; + link1 = + link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Link1.class); + if (link1 == null) { - LOG.error("MapUtils: No Link augmentation available. {}", link.getLinkId().getValue()); - } - try { - tempSpan = link1.getOMSAttributes().getSpan(); + LOG.error(MAP_UTILS_NO_LINK_AUGMENTATION_AVAILABLE_MSG, link.getLinkId().getValue()); + return null; } - catch (NullPointerException e) { + if (link1.getOMSAttributes() == null) { LOG.error("MapUtils: No Link getOMSAttributes available. {}", link.getLinkId().getValue()); + return null; } - - return tempSpan; + return link1.getOMSAttributes().getSpan(); } public static LinkId extractOppositeLink(Link link) { @@ -136,7 +227,7 @@ public final class MapUtils { org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1 linkOpposite = link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1.class); tmpoppositeLink = linkOpposite.getOppositeLink(); - LOG.debug("PceLink: reading oppositeLink. {}", linkOpposite.toString()); + LOG.debug("PceLink: reading oppositeLink. {}", linkOpposite); if (tmpoppositeLink == null) { LOG.error("PceLink: Error reading oppositeLink. Link is ignored {}", link.getLinkId().getValue()); return null;