fix deprecated openroadm interfaces/objects
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / networkanalyzer / MapUtils.java
1 /*
2  * Copyright © 2017 AT&T, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.transportpce.pce.networkanalyzer;
9
10 import java.util.ArrayList;
11 import java.util.Arrays;
12 import java.util.List;
13
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;
17
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;
25
26 public final class MapUtils {
27     /* Logging. */
28     private static final Logger LOG = LoggerFactory.getLogger(MapUtils.class);
29
30     private MapUtils() {
31     }
32
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();
38
39         LOG.info("mapDiversityConstraints before : ExcludeClliNodes {} \n ExcludeNodes {} \n ExcludeSrlgLinks {}",
40                 excClliNodes.toString(), excNodes.toString(), excSrlgLinks.toString());
41
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)));
46             }
47
48             if (excNodes.contains(node.getNodeId().getValue())) {
49                 LOG.debug("mapDiversityConstraints setExcludeSupNodes for node {}", node.getNodeId().getValue());
50                 pceHardConstraints.setExcludeSupNodes(Arrays.asList(getSupNode(node)));
51             }
52         }
53
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) {
59                     srlg = getSRLG(link);
60                     if (!srlg.isEmpty()) {
61                         pceHardConstraints.setExcludeSRLG(srlg);
62                         LOG.debug("mapDiversityConstraints setExcludeSRLG {} for link {}",
63                                 srlg.toString(), link.getLinkId().getValue());
64                     }
65                 }
66             }
67         }
68
69         LOG.info("mapDiversityConstraints after : ExcludeCLLI {} \n ExcludeSupNodes {} \n ExcludeSRLG {}",
70                 pceHardConstraints.getExcludeCLLI().toString(),
71                 pceHardConstraints.getExcludeSupNodes().toString(),
72                 pceHardConstraints.getExcludeSRLG().toString());
73
74     }
75
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();
79     }
80
81     public static List<Long> getSRLG(Link link) {
82         List<Long> srlgList = new ArrayList<Long>();
83         try {
84             List<LinkConcatenation> linkList = getOmsAttributesSpan(link).getLinkConcatenation();
85             for (LinkConcatenation lc : linkList) {
86                 srlgList.add(lc.getSRLGId());
87             }
88         } catch (NullPointerException e) {
89             LOG.debug("No concatenation for this link");
90         }
91         return srlgList;
92     }
93
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();
97     }
98
99     public static OpenroadmLinkType calcType(Link link) {
100         Link1 link1 = null;
101         OpenroadmLinkType tmplType = null;
102         // ID and type
103         link1 = link.augmentation(Link1.class);
104         if (link1 == null) {
105             LOG.error("MapUtils: No Link augmentation available. {}", link.getLinkId().getValue());
106             return null;
107         }
108
109         tmplType = link1.getLinkType();
110
111         if (tmplType == null) {
112             LOG.error("MapUtils: No Link type available. {}", link.getLinkId().getValue());
113             return null;
114         }
115         return tmplType;
116     }
117
118     public static Span getOmsAttributesSpan(Link link) {
119         org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Link1 link1 = null;
120         Span tempSpan = null;
121         link1 =
122             link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Link1.class);
123
124         if (link1 == null) {
125             LOG.error("MapUtils: No Link augmentation available. {}", link.getLinkId().getValue());
126         }
127         try {
128             tempSpan = link1.getOMSAttributes().getSpan();
129         }
130         catch (NullPointerException e) {
131             LOG.error("MapUtils: No Link getOMSAttributes available. {}", link.getLinkId().getValue());
132         }
133
134         return tempSpan;
135     }
136
137     public static LinkId extractOppositeLink(Link link) {
138         LinkId tmpoppositeLink = null;
139         org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1 linkOpposite
140             = link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1.class);
141         tmpoppositeLink = linkOpposite.getOppositeLink();
142         LOG.debug("PceLink: reading oppositeLink.  {}", linkOpposite.toString());
143         if (tmpoppositeLink == null) {
144             LOG.error("PceLink: Error reading oppositeLink. Link is ignored {}", link.getLinkId().getValue());
145             return null;
146         }
147         return tmpoppositeLink;
148     }
149
150
151 }