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.rev230526.Link1;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.networks.network.link.oms.attributes.Span;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmLinkType;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.link.concatenation.LinkConcatenation;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.link.concatenation.LinkConcatenationKey;
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(List.of(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.rev230526.Link1 linkC = link
107 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.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 (LinkConcatenation lc : linkC.nonnullLinkConcatenation().values()) {
114 if (lc != null && lc.getSRLGId() != null) {
115 srlgList.add(lc.getSRLGId().toJava());
117 LOG.debug("No concatenation or SLRG id for this link");
123 public static String getSupNetworkNode(Node node) {
124 for (SupportingNode snode : node.nonnullSupportingNode().values()) {
125 if (NetworkUtils.UNDERLAY_NETWORK_ID.equals(snode.getNetworkRef().getValue())) {
126 return snode.getNodeRef().getValue();
132 public static String getSupClliNode(Node node) {
133 for (SupportingNode snode : node.nonnullSupportingNode().values()) {
134 if (NetworkUtils.CLLI_NETWORK_ID.equals(snode.getNetworkRef().getValue())) {
135 return snode.getNodeRef().getValue();
141 public static SortedMap<String, String> getAllSupNode(Node node) {
142 TreeMap<String, String> allSupNodes = new TreeMap<>();
143 for (SupportingNode supnode : node.nonnullSupportingNode().values()) {
144 allSupNodes.put(supnode.getNetworkRef().getValue(),
145 supnode.getNodeRef().getValue());
150 public static String getSupLink(Link link) {
151 Iterator<SupportingLink> supportingLinkIterator = link.nonnullSupportingLink().values().iterator();
152 if (!supportingLinkIterator.hasNext()) {
155 SupportingLink first = supportingLinkIterator.next();
156 if (first == null || first.getLinkRef() == null) {
159 return first.getLinkRef().toString();
163 public static Long getAvailableBandwidth(Link link) {
164 if (link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev230526
165 .Link1.class) != null
166 && link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev230526
167 .Link1.class).getAvailableBandwidth() != null) {
168 return link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev230526
169 .Link1.class).getAvailableBandwidth().toJava();
171 LOG.warn("MapUtils: no Available Bandwidth available for link {}", link.getLinkId());
176 public static Long getUsedBandwidth(Link link) {
177 if (link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev230526
178 .Link1.class) != null
179 && link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev230526
180 .Link1.class).getUsedBandwidth() != null) {
181 return link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev230526
182 .Link1.class).getUsedBandwidth().toJava();
184 LOG.warn("MapUtils: no Available Bandwidth available for link {}", link.getLinkId());
189 public static OpenroadmLinkType calcType(Link link) {
191 OpenroadmLinkType tmplType = null;
193 link1 = link.augmentation(Link1.class);
195 LOG.error(MAP_UTILS_NO_LINK_AUGMENTATION_AVAILABLE_MSG, link.getLinkId().getValue());
199 tmplType = link1.getLinkType();
201 if (tmplType == null) {
202 LOG.error("MapUtils: No Link type available. {}", link.getLinkId().getValue());
208 public static Span getOmsAttributesSpan(Link link) {
209 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.Link1 link1 = null;
211 link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.Link1.class);
214 LOG.error(MAP_UTILS_NO_LINK_AUGMENTATION_AVAILABLE_MSG, link.getLinkId().getValue());
217 if (link1.getOMSAttributes() == null) {
218 LOG.error("MapUtils: No Link getOMSAttributes available. {}", link.getLinkId().getValue());
221 return link1.getOMSAttributes().getSpan();
224 public static LinkId extractOppositeLink(Link link) {
226 = link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.Link1.class);
227 if (linkOpposite == null) {
228 LOG.error("No opposite link augmentation for network link {}", link);
231 LOG.debug("PceLink: reading oppositeLink. {}", linkOpposite);
232 LinkId tmpoppositeLink = linkOpposite.getOppositeLink();
233 if (tmpoppositeLink == null) {
234 LOG.error("PceLink: Error reading oppositeLink. Link is ignored {}", link.getLinkId().getValue());
237 return tmpoppositeLink;