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 org.opendaylight.transportpce.common.NetworkUtils;
14 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attributes.LinkConcatenation;
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.rev180226.networks.network.node.SupportingNode;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public final class MapUtils {
29 private static final Logger LOG = LoggerFactory.getLogger(MapUtils.class);
34 public static void mapDiversityConstraints(List<Node> allNodes, List<Link> allLinks,
35 PceConstraints pceHardConstraints) {
36 List<String> excClliNodes = pceHardConstraints.getExcludeClliNodes();
37 List<String> excNodes = pceHardConstraints.getExcludeNodes();
38 List<String> excSrlgLinks = pceHardConstraints.getExcludeSrlgLinks();
40 LOG.info("mapDiversityConstraints before : ExcludeClliNodes {} \n ExcludeNodes {} \n ExcludeSrlgLinks {}",
41 excClliNodes.toString(), excNodes.toString(), excSrlgLinks.toString());
43 for (Node node : allNodes) {
44 if (excClliNodes.contains(node.getNodeId().getValue())) {
45 LOG.debug("mapDiversityConstraints setExcludeCLLI for node {}", node.getNodeId().getValue());
46 pceHardConstraints.setExcludeCLLI(Arrays.asList(getCLLI(node)));
49 if (excNodes.contains(node.getNodeId().getValue())) {
50 LOG.debug("mapDiversityConstraints setExcludeSupNodes for node {}", node.getNodeId().getValue());
51 pceHardConstraints.setExcludeSupNodes(Arrays.asList(getSupNode(node)));
55 for (Link link : allLinks) {
56 if (excSrlgLinks.contains(link.getLinkId().getValue())) {
57 // zero SRLG means not populated as not OMS link
58 List<Long> srlg = null;
59 if (calcType(link) == OpenroadmLinkType.ROADMTOROADM) {
61 if (!srlg.isEmpty()) {
62 pceHardConstraints.setExcludeSRLG(srlg);
63 LOG.debug("mapDiversityConstraints setExcludeSRLG {} for link {}",
64 srlg.toString(), link.getLinkId().getValue());
70 LOG.info("mapDiversityConstraints after : ExcludeCLLI {} \n ExcludeSupNodes {} \n ExcludeSRLG {}",
71 pceHardConstraints.getExcludeCLLI().toString(),
72 pceHardConstraints.getExcludeSupNodes().toString(),
73 pceHardConstraints.getExcludeSRLG().toString());
77 public static String getCLLI(Node node) {
78 // TODO STUB retrieve CLLI from node. for now it is supporting node ID of the first supp node
79 return node.getSupportingNode().get(0).getNodeRef().getValue();
82 public static List<Long> getSRLG(Link link) {
83 List<Long> srlgList = new ArrayList<Long>();
85 List<LinkConcatenation> linkList = getOmsAttributesSpan(link).getLinkConcatenation();
86 for (LinkConcatenation lc : linkList) {
87 srlgList.add(lc.getSRLGId());
89 } catch (NullPointerException e) {
90 LOG.debug("No concatenation for this link");
95 public static String getSupNode(Node node) {
96 List<SupportingNode> supNodes = node.getSupportingNode();
97 for (SupportingNode snode : supNodes) {
98 if (NetworkUtils.UNDERLAY_NETWORK_ID.equals(snode.getNetworkRef().getValue())) {
99 return snode.getNodeRef().getValue();
105 public static OpenroadmLinkType calcType(Link link) {
107 OpenroadmLinkType tmplType = null;
109 link1 = link.augmentation(Link1.class);
111 LOG.error("MapUtils: No Link augmentation available. {}", link.getLinkId().getValue());
115 tmplType = link1.getLinkType();
117 if (tmplType == null) {
118 LOG.error("MapUtils: No Link type available. {}", link.getLinkId().getValue());
124 public static Span getOmsAttributesSpan(Link link) {
125 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Link1 link1 = null;
126 Span tempSpan = null;
128 link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Link1.class);
131 LOG.error("MapUtils: No Link augmentation available. {}", link.getLinkId().getValue());
134 tempSpan = link1.getOMSAttributes().getSpan();
136 catch (NullPointerException e) {
137 LOG.error("MapUtils: No Link getOMSAttributes available. {}", link.getLinkId().getValue());
143 public static LinkId extractOppositeLink(Link link) {
144 LinkId tmpoppositeLink = null;
145 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1 linkOpposite
146 = link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1.class);
147 tmpoppositeLink = linkOpposite.getOppositeLink();
148 LOG.debug("PceLink: reading oppositeLink. {}", linkOpposite.toString());
149 if (tmpoppositeLink == null) {
150 LOG.error("PceLink: Error reading oppositeLink. Link is ignored {}", link.getLinkId().getValue());
153 return tmpoppositeLink;