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;
14 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attributes.LinkConcatenation;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Link1;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.networks.network.link.oms.attributes.Span;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmLinkType;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public final class MapUtils {
28 private static final Logger LOG = LoggerFactory.getLogger(MapUtils.class);
33 public static void mapDiversityConstraints(List<Node> allNodes, List<Link> allLinks,
34 PceConstraints pceHardConstraints) {
35 List<String> excClliNodes = pceHardConstraints.getExcludeClliNodes();
36 List<String> excNodes = pceHardConstraints.getExcludeNodes();
37 List<String> excSrlgLinks = pceHardConstraints.getExcludeSrlgLinks();
39 LOG.info("mapDiversityConstraints before : ExcludeClliNodes {} \n ExcludeNodes {} \n ExcludeSrlgLinks {}",
40 excClliNodes.toString(), excNodes.toString(), excSrlgLinks.toString());
42 for (Node node : allNodes) {
43 if (excClliNodes.contains(node.getNodeId().getValue())) {
44 LOG.debug("mapDiversityConstraints setExcludeCLLI for node {}", node.getNodeId().getValue());
45 pceHardConstraints.setExcludeCLLI(Arrays.asList(getCLLI(node)));
48 if (excNodes.contains(node.getNodeId().getValue())) {
49 LOG.debug("mapDiversityConstraints setExcludeSupNodes for node {}", node.getNodeId().getValue());
50 pceHardConstraints.setExcludeSupNodes(Arrays.asList(getSupNode(node)));
54 for (Link link : allLinks) {
55 if (excSrlgLinks.contains(link.getLinkId().getValue())) {
56 // zero SRLG means not populated as not OMS link
57 List<Long> srlg = null;
58 if (calcType(link) == OpenroadmLinkType.ROADMTOROADM) {
60 if (!srlg.isEmpty()) {
61 pceHardConstraints.setExcludeSRLG(srlg);
62 LOG.debug("mapDiversityConstraints setExcludeSRLG {} for link {}",
63 srlg.toString(), link.getLinkId().getValue());
69 LOG.info("mapDiversityConstraints after : ExcludeCLLI {} \n ExcludeSupNodes {} \n ExcludeSRLG {}",
70 pceHardConstraints.getExcludeCLLI().toString(),
71 pceHardConstraints.getExcludeSupNodes().toString(),
72 pceHardConstraints.getExcludeSRLG().toString());
76 public static String getCLLI(Node node) {
77 // TODO STUB retrieve CLLI from node. for now it is supporting node ID of the first supp node
78 return node.getSupportingNode().get(0).getNodeRef().getValue();
81 public static List<Long> getSRLG(Link link) {
82 List<Long> srlgList = new ArrayList<Long>();
84 List<LinkConcatenation> linkList = getOmsAttributesSpan(link).getLinkConcatenation();
85 for (LinkConcatenation lc : linkList) {
86 srlgList.add(lc.getSRLGId());
88 } catch (NullPointerException e) {
89 LOG.debug("No concatenation for this link");
94 public static String getSupNode(Node node) {
95 // TODO: supporting IDs exist as a List. this code takes just the first element
96 return node.getSupportingNode().get(0).getNodeRef().getValue();
99 public static OpenroadmLinkType calcType(Link link) {
101 OpenroadmLinkType tmplType = null;
103 link1 = link.augmentation(Link1.class);
105 LOG.error("MapUtils: No Link augmentation available. {}", link.getLinkId().getValue());
109 tmplType = link1.getLinkType();
110 if (tmplType == null) {
111 LOG.error("MapUtils: No Link type available. {}", link.getLinkId().getValue());
117 public static Span getOmsAttributesSpan(Link link) {
119 Span tempSpan = null;
120 link1 = link.augmentation(Link1.class);
122 LOG.error("MapUtils: No Link augmentation available. {}", link.getLinkId().getValue());
125 tempSpan = link1.getOMSAttributes().getSpan();
127 catch (NullPointerException e) {
128 LOG.error("MapUtils: No Link getOMSAttributes available. {}", link.getLinkId().getValue());
134 public static LinkId extractOppositeLink(Link link) {
135 LinkId tmpoppositeLink = null;
136 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1 linkOpposite
137 = link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1.class);
138 tmpoppositeLink = linkOpposite.getOppositeLink();
139 LOG.debug("PceLink: reading oppositeLink. {}", linkOpposite.toString());
140 if (tmpoppositeLink == null) {
141 LOG.error("PceLink: Error reading oppositeLink. Link is ignored {}", link.getLinkId().getValue());
144 return tmpoppositeLink;