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.SortedMap;
16 import java.util.TreeMap;
17 import org.opendaylight.transportpce.common.NetworkUtils;
18 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attributes.LinkConcatenation;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attributes.LinkConcatenationKey;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.networks.network.link.oms.attributes.Span;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmLinkType;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.node.SupportingNode;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.link.SupportingLink;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public final class MapUtils {
33 private static final String MAP_UTILS_NO_LINK_AUGMENTATION_AVAILABLE_MSG =
34 "MapUtils: No Link augmentation available. {}";
36 private static final Logger LOG = LoggerFactory.getLogger(MapUtils.class);
41 public static void mapDiversityConstraints(List<Node> allNodes, List<Link> allLinks,
42 PceConstraints pceHardConstraints) {
43 List<String> excClliNodes = pceHardConstraints.getExcludeClliNodes();
44 List<String> excNodes = pceHardConstraints.getExcludeNodes();
45 List<String> excSrlgLinks = pceHardConstraints.getExcludeSrlgLinks();
47 LOG.info("mapDiversityConstraints before : ExcludeClliNodes {} \n ExcludeNodes {} \n ExcludeSrlgLinks {}",
48 excClliNodes, excNodes, excSrlgLinks);
50 for (Node node : allNodes) {
51 if (excClliNodes.contains(node.getNodeId().getValue())) {
52 LOG.debug("mapDiversityConstraints setExcludeCLLI for node {}", node.getNodeId().getValue());
53 pceHardConstraints.setExcludeCLLI(Arrays.asList(getCLLI(node)));
56 if (excNodes.contains(node.getNodeId().getValue())) {
57 LOG.debug("mapDiversityConstraints setExcludeSupNodes for node {}", node.getNodeId().getValue());
58 pceHardConstraints.setExcludeSupNodes(Arrays.asList(getSupNetworkNode(node)));
62 for (Link link : allLinks) {
63 if (excSrlgLinks.contains(link.getLinkId().getValue())) {
64 // zero SRLG means not populated as not OMS link
65 List<Long> srlg = null;
66 if (calcType(link) == OpenroadmLinkType.ROADMTOROADM) {
68 if (!srlg.isEmpty()) {
69 pceHardConstraints.setExcludeSRLG(srlg);
70 LOG.debug("mapDiversityConstraints setExcludeSRLG {} for link {}",
71 srlg, link.getLinkId().getValue());
77 LOG.info("mapDiversityConstraints after : ExcludeCLLI {} \n ExcludeSupNodes {} \n ExcludeSRLG {}",
78 pceHardConstraints.getExcludeCLLI(),
79 pceHardConstraints.getExcludeSupNodes(),
80 pceHardConstraints.getExcludeSRLG());
84 public static String getCLLI(Node node) {
85 // TODO STUB retrieve CLLI from node. for now it is supporting node ID of the first supp node
86 return node.nonnullSupportingNode().values().iterator().next().getNodeRef().getValue();
89 public static List<Long> getSRLG(Link link) {
90 Span omsAttributesSpan = getOmsAttributesSpan(link);
91 if (omsAttributesSpan == null) {
92 LOG.debug("No concatenation for this link");
93 return new ArrayList<>();
95 List<Long> srlgList = new ArrayList<>();
96 Map<LinkConcatenationKey, LinkConcatenation> linkList = omsAttributesSpan.nonnullLinkConcatenation();
97 for (LinkConcatenation lc : linkList.values()) {
98 if (lc != null && lc.getSRLGId() != null) {
99 srlgList.add(lc.getSRLGId().toJava());
105 public static List<Long> getSRLGfromLink(Link link) {
106 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1 linkC = link
107 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1.class);
109 LOG.error(MAP_UTILS_NO_LINK_AUGMENTATION_AVAILABLE_MSG, link.getLinkId().getValue());
110 return new ArrayList<>();
112 List<Long> srlgList = new ArrayList<>();
113 for (org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130
114 .networks.network.link.LinkConcatenation lc : linkC.nonnullLinkConcatenation().values()) {
115 if (lc != null && lc.getSRLGId() != null) {
116 srlgList.add(lc.getSRLGId().toJava());
118 LOG.debug("No concatenation or SLRG id for this link");
124 public static String getSupNetworkNode(Node node) {
125 for (SupportingNode snode : node.nonnullSupportingNode().values()) {
126 if (NetworkUtils.UNDERLAY_NETWORK_ID.equals(snode.getNetworkRef().getValue())) {
127 return snode.getNodeRef().getValue();
133 public static String getSupClliNode(Node node) {
134 for (SupportingNode snode : node.nonnullSupportingNode().values()) {
135 if (NetworkUtils.CLLI_NETWORK_ID.equals(snode.getNetworkRef().getValue())) {
136 return snode.getNodeRef().getValue();
142 public static SortedMap<String, String> getAllSupNode(Node node) {
143 TreeMap<String, String> allSupNodes = new TreeMap<>();
144 for (SupportingNode supnode : node.nonnullSupportingNode().values()) {
145 allSupNodes.put(supnode.getNetworkRef().getValue(),
146 supnode.getNodeRef().getValue());
151 public static String getSupLink(Link link) {
152 Iterator<SupportingLink> supportingLinkIterator = link.nonnullSupportingLink().values().iterator();
153 if (!supportingLinkIterator.hasNext()) {
156 SupportingLink first = supportingLinkIterator.next();
157 if (first == null || first.getLinkRef() == null) {
160 return first.getLinkRef().toString();
164 public static Long getAvailableBandwidth(Link link) {
165 if (link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130
166 .Link1.class) != null
167 && link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130
168 .Link1.class).getAvailableBandwidth() != null) {
169 return link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130
170 .Link1.class).getAvailableBandwidth().toJava();
172 LOG.warn("MapUtils: no Available Bandwidth available for link {}", link.getLinkId());
177 public static Long getUsedBandwidth(Link link) {
178 if (link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130
179 .Link1.class) != null
180 && link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130
181 .Link1.class).getUsedBandwidth() != null) {
182 return link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130
183 .Link1.class).getUsedBandwidth().toJava();
185 LOG.warn("MapUtils: no Available Bandwidth available for link {}", link.getLinkId());
190 public static OpenroadmLinkType calcType(Link link) {
192 OpenroadmLinkType tmplType = null;
194 link1 = link.augmentation(Link1.class);
196 LOG.error(MAP_UTILS_NO_LINK_AUGMENTATION_AVAILABLE_MSG, link.getLinkId().getValue());
200 tmplType = link1.getLinkType();
202 if (tmplType == null) {
203 LOG.error("MapUtils: No Link type available. {}", link.getLinkId().getValue());
209 public static Span getOmsAttributesSpan(Link link) {
210 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Link1 link1 = null;
212 link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Link1.class);
215 LOG.error(MAP_UTILS_NO_LINK_AUGMENTATION_AVAILABLE_MSG, link.getLinkId().getValue());
218 if (link1.getOMSAttributes() == null) {
219 LOG.error("MapUtils: No Link getOMSAttributes available. {}", link.getLinkId().getValue());
222 return link1.getOMSAttributes().getSpan();
225 public static LinkId extractOppositeLink(Link link) {
226 LinkId tmpoppositeLink = null;
227 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1 linkOpposite
228 = link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1.class);
229 tmpoppositeLink = linkOpposite.getOppositeLink();
230 LOG.debug("PceLink: reading oppositeLink. {}", linkOpposite);
231 if (tmpoppositeLink == null) {
232 LOG.error("PceLink: Error reading oppositeLink. Link is ignored {}", link.getLinkId().getValue());
235 return tmpoppositeLink;