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.List;
13 import java.util.TreeMap;
15 import org.opendaylight.transportpce.common.NetworkUtils;
16 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attributes.LinkConcatenation;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.networks.network.link.oms.attributes.Span;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmLinkType;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.node.SupportingNode;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 public final class MapUtils {
30 private static final Logger LOG = LoggerFactory.getLogger(MapUtils.class);
35 public static void mapDiversityConstraints(List<Node> allNodes, List<Link> allLinks,
36 PceConstraints pceHardConstraints) {
37 List<String> excClliNodes = pceHardConstraints.getExcludeClliNodes();
38 List<String> excNodes = pceHardConstraints.getExcludeNodes();
39 List<String> excSrlgLinks = pceHardConstraints.getExcludeSrlgLinks();
41 LOG.info("mapDiversityConstraints before : ExcludeClliNodes {} \n ExcludeNodes {} \n ExcludeSrlgLinks {}",
42 excClliNodes, excNodes, excSrlgLinks);
44 for (Node node : allNodes) {
45 if (excClliNodes.contains(node.getNodeId().getValue())) {
46 LOG.debug("mapDiversityConstraints setExcludeCLLI for node {}", node.getNodeId().getValue());
47 pceHardConstraints.setExcludeCLLI(Arrays.asList(getCLLI(node)));
50 if (excNodes.contains(node.getNodeId().getValue())) {
51 LOG.debug("mapDiversityConstraints setExcludeSupNodes for node {}", node.getNodeId().getValue());
52 pceHardConstraints.setExcludeSupNodes(Arrays.asList(getSupNetworkNode(node)));
56 for (Link link : allLinks) {
57 if (excSrlgLinks.contains(link.getLinkId().getValue())) {
58 // zero SRLG means not populated as not OMS link
59 List<Long> srlg = null;
60 if (calcType(link) == OpenroadmLinkType.ROADMTOROADM) {
62 if (!srlg.isEmpty()) {
63 pceHardConstraints.setExcludeSRLG(srlg);
64 LOG.debug("mapDiversityConstraints setExcludeSRLG {} for link {}",
65 srlg, link.getLinkId().getValue());
71 LOG.info("mapDiversityConstraints after : ExcludeCLLI {} \n ExcludeSupNodes {} \n ExcludeSRLG {}",
72 pceHardConstraints.getExcludeCLLI(),
73 pceHardConstraints.getExcludeSupNodes(),
74 pceHardConstraints.getExcludeSRLG());
78 public static String getCLLI(Node node) {
79 // TODO STUB retrieve CLLI from node. for now it is supporting node ID of the first supp node
80 return node.getSupportingNode().get(0).getNodeRef().getValue();
83 public static List<Long> getSRLG(Link link) {
84 List<Long> srlgList = new ArrayList<>();
86 List<LinkConcatenation> linkList = getOmsAttributesSpan(link).getLinkConcatenation();
87 for (LinkConcatenation lc : linkList) {
88 srlgList.add(lc.getSRLGId().toJava());
90 } catch (NullPointerException e) {
91 LOG.debug("No concatenation for this link");
96 public static List<Long> getSRLGfromLink(Link link) {
97 List<Long> srlgList = new ArrayList<>();
98 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1 linkC =
99 link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1.class);
101 LOG.error("MapUtils: No Link augmentation available. {}", link.getLinkId().getValue());
105 List<org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.networks.network.link
106 .LinkConcatenation> linkConcatenation = linkC.getLinkConcatenation();
109 for (org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.networks.network.link
110 .LinkConcatenation lc : linkConcatenation) {
111 srlgList.add(lc.getSRLGId().toJava());
113 } catch (NullPointerException e) {
114 LOG.debug("No concatenation for this link");
120 public static String getSupNetworkNode(Node node) {
121 List<SupportingNode> supNodes = node.getSupportingNode();
122 for (SupportingNode snode : supNodes) {
123 if (NetworkUtils.UNDERLAY_NETWORK_ID.equals(snode.getNetworkRef().getValue())) {
124 return snode.getNodeRef().getValue();
130 public static String getSupClliNode(Node node) {
131 List<SupportingNode> supNodes = node.getSupportingNode();
132 for (SupportingNode snode : supNodes) {
133 if (NetworkUtils.CLLI_NETWORK_ID.equals(snode.getNetworkRef().getValue())) {
134 return snode.getNodeRef().getValue();
140 public static TreeMap<String, String> getAllSupNode(Node node) {
141 TreeMap<String, String> allSupNodes = new TreeMap<>();
142 List<SupportingNode> supNodes = new ArrayList<>();
144 supNodes = node.getSupportingNode();
145 } catch (NullPointerException e) {
146 LOG.debug("No Supporting Node for the node {}", node);
148 for (SupportingNode supnode :supNodes) {
149 allSupNodes.put(supnode.getNetworkRef().getValue(),
150 supnode.getNodeRef().getValue());
155 public static String getSupLink(Link link) {
158 supLink = link.getSupportingLink().get(0).getLinkRef().toString();
159 } catch (NullPointerException e) {
160 LOG.debug("No Supporting Link for the link {}", link);
166 public static Long getAvailableBandwidth(Link link) {
167 if (link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130
168 .Link1.class) != null
169 && link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130
170 .Link1.class).getAvailableBandwidth() != null) {
171 return link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130
172 .Link1.class).getAvailableBandwidth().toJava();
174 LOG.warn("MapUtils: no Available Bandwidth available for link {}", link.getLinkId());
179 public static Long getUsedBandwidth(Link link) {
180 if (link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130
181 .Link1.class) != null
182 && link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130
183 .Link1.class).getUsedBandwidth() != null) {
184 return link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130
185 .Link1.class).getUsedBandwidth().toJava();
187 LOG.warn("MapUtils: no Available Bandwidth available for link {}", link.getLinkId());
192 public static OpenroadmLinkType calcType(Link link) {
194 OpenroadmLinkType tmplType = null;
196 link1 = link.augmentation(Link1.class);
198 LOG.error("MapUtils: No Link augmentation available. {}", link.getLinkId().getValue());
202 tmplType = link1.getLinkType();
204 if (tmplType == null) {
205 LOG.error("MapUtils: No Link type available. {}", link.getLinkId().getValue());
211 public static Span getOmsAttributesSpan(Link link) {
212 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Link1 link1 = null;
213 Span tempSpan = null;
215 link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Link1.class);
218 LOG.error("MapUtils: No Link augmentation available. {}", link.getLinkId().getValue());
221 tempSpan = link1.getOMSAttributes().getSpan();
223 catch (NullPointerException e) {
224 LOG.error("MapUtils: No Link getOMSAttributes available. {}", link.getLinkId().getValue());
230 public static LinkId extractOppositeLink(Link link) {
231 LinkId tmpoppositeLink = null;
232 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1 linkOpposite
233 = link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1.class);
234 tmpoppositeLink = linkOpposite.getOppositeLink();
235 LOG.debug("PceLink: reading oppositeLink. {}", linkOpposite);
236 if (tmpoppositeLink == null) {
237 LOG.error("PceLink: Error reading oppositeLink. Link is ignored {}", link.getLinkId().getValue());
240 return tmpoppositeLink;