2 * Copyright © 2017 AT&T, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.transportpce.pce.networkanalyzer;
10 import java.util.ArrayList;
11 import java.util.Arrays;
12 import java.util.Iterator;
13 import java.util.List;
15 import java.util.TreeMap;
16 import org.opendaylight.transportpce.common.NetworkUtils;
17 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attributes.LinkConcatenation;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attributes.LinkConcatenationKey;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.networks.network.link.oms.attributes.Span;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmLinkType;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.node.SupportingNode;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.link.SupportingLink;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public final class MapUtils {
33 private static final Logger LOG = LoggerFactory.getLogger(MapUtils.class);
38 public static void mapDiversityConstraints(List<Node> allNodes, List<Link> allLinks,
39 PceConstraints pceHardConstraints) {
40 List<String> excClliNodes = pceHardConstraints.getExcludeClliNodes();
41 List<String> excNodes = pceHardConstraints.getExcludeNodes();
42 List<String> excSrlgLinks = pceHardConstraints.getExcludeSrlgLinks();
44 LOG.info("mapDiversityConstraints before : ExcludeClliNodes {} \n ExcludeNodes {} \n ExcludeSrlgLinks {}",
45 excClliNodes, excNodes, excSrlgLinks);
47 for (Node node : allNodes) {
48 if (excClliNodes.contains(node.getNodeId().getValue())) {
49 LOG.debug("mapDiversityConstraints setExcludeCLLI for node {}", node.getNodeId().getValue());
50 pceHardConstraints.setExcludeCLLI(Arrays.asList(getCLLI(node)));
53 if (excNodes.contains(node.getNodeId().getValue())) {
54 LOG.debug("mapDiversityConstraints setExcludeSupNodes for node {}", node.getNodeId().getValue());
55 pceHardConstraints.setExcludeSupNodes(Arrays.asList(getSupNetworkNode(node)));
59 for (Link link : allLinks) {
60 if (excSrlgLinks.contains(link.getLinkId().getValue())) {
61 // zero SRLG means not populated as not OMS link
62 List<Long> srlg = null;
63 if (calcType(link) == OpenroadmLinkType.ROADMTOROADM) {
65 if (!srlg.isEmpty()) {
66 pceHardConstraints.setExcludeSRLG(srlg);
67 LOG.debug("mapDiversityConstraints setExcludeSRLG {} for link {}",
68 srlg, link.getLinkId().getValue());
74 LOG.info("mapDiversityConstraints after : ExcludeCLLI {} \n ExcludeSupNodes {} \n ExcludeSRLG {}",
75 pceHardConstraints.getExcludeCLLI(),
76 pceHardConstraints.getExcludeSupNodes(),
77 pceHardConstraints.getExcludeSRLG());
81 public static String getCLLI(Node node) {
82 // TODO STUB retrieve CLLI from node. for now it is supporting node ID of the first supp node
83 return node.nonnullSupportingNode().values().iterator().next().getNodeRef().getValue();
86 public static List<Long> getSRLG(Link link) {
87 List<Long> srlgList = new ArrayList<>();
89 Map<LinkConcatenationKey, LinkConcatenation> linkList = getOmsAttributesSpan(link).getLinkConcatenation();
90 for (LinkConcatenation lc : linkList.values()) {
91 srlgList.add(lc.getSRLGId().toJava());
93 } catch (NullPointerException e) {
94 LOG.debug("No concatenation for this link");
99 public static List<Long> getSRLGfromLink(Link link) {
100 List<Long> srlgList = new ArrayList<>();
101 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1 linkC =
102 link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1.class);
104 LOG.error("MapUtils: No Link augmentation available. {}", link.getLinkId().getValue());
108 for (org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.networks.network.link
109 .LinkConcatenation lc : linkC.nonnullLinkConcatenation().values()) {
110 srlgList.add(lc.getSRLGId().toJava());
112 } catch (NullPointerException e) {
113 LOG.debug("No concatenation for this link");
119 public static String getSupNetworkNode(Node node) {
120 for (SupportingNode snode : node.nonnullSupportingNode().values()) {
121 if (NetworkUtils.UNDERLAY_NETWORK_ID.equals(snode.getNetworkRef().getValue())) {
122 return snode.getNodeRef().getValue();
128 public static String getSupClliNode(Node node) {
129 for (SupportingNode snode : node.nonnullSupportingNode().values()) {
130 if (NetworkUtils.CLLI_NETWORK_ID.equals(snode.getNetworkRef().getValue())) {
131 return snode.getNodeRef().getValue();
137 public static TreeMap<String, String> getAllSupNode(Node node) {
138 TreeMap<String, String> allSupNodes = new TreeMap<>();
139 for (SupportingNode supnode : node.nonnullSupportingNode().values()) {
140 allSupNodes.put(supnode.getNetworkRef().getValue(),
141 supnode.getNodeRef().getValue());
146 public static String getSupLink(Link link) {
147 Iterator<SupportingLink> supportingLinkIterator = link.nonnullSupportingLink().values().iterator();
148 if (!supportingLinkIterator.hasNext()) {
151 SupportingLink first = supportingLinkIterator.next();
152 if (first == null || first.getLinkRef() == null) {
155 return first.getLinkRef().toString();
159 public static Long getAvailableBandwidth(Link link) {
160 if (link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130
161 .Link1.class) != null
162 && link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130
163 .Link1.class).getAvailableBandwidth() != null) {
164 return link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130
165 .Link1.class).getAvailableBandwidth().toJava();
167 LOG.warn("MapUtils: no Available Bandwidth available for link {}", link.getLinkId());
172 public static Long getUsedBandwidth(Link link) {
173 if (link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130
174 .Link1.class) != null
175 && link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130
176 .Link1.class).getUsedBandwidth() != null) {
177 return link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130
178 .Link1.class).getUsedBandwidth().toJava();
180 LOG.warn("MapUtils: no Available Bandwidth available for link {}", link.getLinkId());
185 public static OpenroadmLinkType calcType(Link link) {
187 OpenroadmLinkType tmplType = null;
189 link1 = link.augmentation(Link1.class);
191 LOG.error("MapUtils: No Link augmentation available. {}", link.getLinkId().getValue());
195 tmplType = link1.getLinkType();
197 if (tmplType == null) {
198 LOG.error("MapUtils: No Link type available. {}", link.getLinkId().getValue());
204 public static Span getOmsAttributesSpan(Link link) {
205 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Link1 link1 = null;
206 Span tempSpan = null;
208 link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Link1.class);
211 LOG.error("MapUtils: No Link augmentation available. {}", link.getLinkId().getValue());
214 tempSpan = link1.getOMSAttributes().getSpan();
216 catch (NullPointerException e) {
217 LOG.error("MapUtils: No Link getOMSAttributes available. {}", link.getLinkId().getValue());
223 public static LinkId extractOppositeLink(Link link) {
224 LinkId tmpoppositeLink = null;
225 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1 linkOpposite
226 = link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1.class);
227 tmpoppositeLink = linkOpposite.getOppositeLink();
228 LOG.debug("PceLink: reading oppositeLink. {}", linkOpposite);
229 if (tmpoppositeLink == null) {
230 LOG.error("PceLink: Error reading oppositeLink. Link is ignored {}", link.getLinkId().getValue());
233 return tmpoppositeLink;