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
9 package org.opendaylight.transportpce.pce.networkanalyzer;
11 import java.util.ArrayList;
12 import java.util.HashMap;
13 import java.util.List;
15 import java.util.Optional;
16 import java.util.TreeMap;
18 import org.opendaylight.transportpce.pce.SortPortsByName;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Node1;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.TerminationPoint1;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.networks.network.node.termination.point.pp.attributes.UsedWavelength;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmNodeType;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmTpType;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 public class PceNode {
31 private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
32 ////////////////////////// NODES ///////////////////////////
36 private boolean valid = true;
38 private final Node node;
39 private final NodeId nodeId;
40 private final OpenroadmNodeType nodeType;
41 private final String supNodeId;
42 private final String clli;
44 // wavelength calculation per node type
45 private List<Long> availableWLindex = new ArrayList<Long>();
46 private Map<String, OpenroadmTpType> availableSrgPp = new TreeMap<String, OpenroadmTpType>();
47 private Map<String, OpenroadmTpType> availableSrgCp = new TreeMap<String, OpenroadmTpType>();
48 private List<String> usedXpndrNWTps = new ArrayList<String>();
49 private List<PceLink> outgoingLinks = new ArrayList<PceLink>();
50 private Map<String, String> clientPerNwTp = new HashMap<String, String>();
52 public PceNode(Node node, OpenroadmNodeType nodeType, NodeId nodeId) {
55 this.nodeType = nodeType;
56 this.supNodeId = getSupNodeId(node);
57 this.clli = MapUtils.getCLLI(node);
59 if ((node == null) || (nodeId == null) || (nodeType == null)) {
60 LOG.error("PceNode: one of parameters is not populated : nodeId, node type");
65 public void initSrgTps() {
66 this.availableSrgPp.clear();
67 this.availableSrgCp.clear();
71 LOG.info("initSrgTpList: getting SRG tps from ROADM node {}", this.nodeId);
72 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
73 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology
74 .rev180226.Node1.class);
75 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
76 .node.TerminationPoint> allTps =
77 nodeTp.getTerminationPoint();
79 LOG.error("initSrgTpList: ROADM TerminationPoint list is empty for node {}", this.toString());
83 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
84 .node.TerminationPoint tp : allTps) {
85 TerminationPoint1 tp1 = tp.augmentation(TerminationPoint1.class);
86 OpenroadmTpType type = tp1.getTpType();
91 LOG.info("initSrgTpList: adding SRG-CP tp = {} ", tp.getTpId().getValue());
92 this.availableSrgCp.put(tp.getTpId().getValue(), tp1.getTpType());
98 LOG.info("initSrgTpList: SRG-PP tp = {} found", tp.getTpId().getValue());
100 List<UsedWavelength> usedWavelengths = tp1.getPpAttributes().getUsedWavelength();
101 if (usedWavelengths.isEmpty()) {
104 } catch (NullPointerException e) {
105 LOG.warn("initSrgTpList: 'usedWavelengths' for tp={} is null !", tp.getTpId().getValue());
109 LOG.info("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
110 this.availableSrgPp.put(tp.getTpId().getValue(), tp1.getTpType());
112 LOG.warn("initSrgTpList: SRG-PP tp = {} found is busy !!");
119 if (this.availableSrgPp.isEmpty() && this.availableSrgCp.isEmpty()) {
120 LOG.error("initSrgTpList: ROADM SRG TerminationPoint list is empty for node {}", this.toString());
124 LOG.info("initSrgTpList: availableSrgPp size = {} && availableSrgCp size = {} in {}", this.availableSrgPp
125 .size(), this.availableSrgCp.size(), this.toString());
129 public void initWLlist() {
130 this.availableWLindex.clear();
134 Node1 node1 = this.node.augmentation(Node1.class);
135 switch (this.nodeType) {
137 List<org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev181130.srg.node.attributes
138 .AvailableWavelengths> srgAvailableWL =
139 node1.getSrgAttributes().getAvailableWavelengths();
140 if (srgAvailableWL == null) {
142 LOG.error("initWLlist: SRG AvailableWavelengths is empty for node {}", this.toString());
145 for (org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev181130.srg.node.attributes
146 .AvailableWavelengths awl : srgAvailableWL) {
147 this.availableWLindex.add(awl.getIndex());
148 LOG.debug("initWLlist: SRG next = {} in {}", awl.getIndex(), this.toString());
152 List<org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev181130.degree.node.attributes
153 .AvailableWavelengths> degAvailableWL = node1.getDegreeAttributes().getAvailableWavelengths();
154 if (degAvailableWL == null) {
156 LOG.error("initWLlist: DEG AvailableWavelengths is empty for node {}", this.toString());
159 for (org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev181130.degree.node.attributes
160 .AvailableWavelengths awl : degAvailableWL) {
161 this.availableWLindex.add(awl.getIndex());
162 LOG.debug("initWLlist: DEGREE next = {} in {}", awl.getIndex(), this.toString());
167 for (long i = 1; i <= 96; i++) {
168 this.availableWLindex.add(i);
172 LOG.error("initWLlist: unsupported node type {} in node {}", this.nodeType, this.toString());
175 if (this.availableWLindex.size() == 0) {
176 LOG.debug("initWLlist: There are no available wavelengths in node {}", this.toString());
179 LOG.debug("initWLlist: availableWLindex size = {} in {}", this.availableWLindex.size(), this.toString());
183 public void initXndrTps() {
184 LOG.info("initXndrTps for node : {}", this.nodeId);
188 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
189 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology
190 .rev180226.Node1.class);
191 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
192 .node.TerminationPoint> allTps = nodeTp.getTerminationPoint();
193 if (allTps == null) {
195 LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this.toString());
199 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
200 .node.TerminationPoint tp : allTps) {
201 TerminationPoint1 tp1 = tp.augmentation(TerminationPoint1.class);
202 if (tp1.getTpType() == OpenroadmTpType.XPONDERNETWORK) {
203 if (tp1.getXpdrNetworkAttributes().getWavelength() != null) {
204 this.usedXpndrNWTps.add(tp.getTpId().getValue());
205 LOG.debug("initXndrTps: XPONDER tp = {} is used", tp.getTpId().getValue());
209 // find Client of this network TP
210 String client = tp1.getXpdrNetworkAttributes().getTailEquipmentId();
211 if ((client.equals("")) || (client == null)) {
212 LOG.error("initXndrTps: XPONDER {} NW TP doesn't have defined Client {}", this.toString(), tp
213 .getTpId().getValue());
216 this.clientPerNwTp.put(tp.getTpId().getValue(), client);
220 LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node {}", this.toString());
225 public String getRdmSrgClient(String tp, Boolean aend) {
226 LOG.info("getRdmSrgClient: Getting PP client for tp '{}' on node : {}", tp, this.nodeId);
227 OpenroadmTpType srgType = null;
228 OpenroadmTpType cpType = this.availableSrgCp.get(tp);
229 if (cpType == null) {
230 LOG.error("getRdmSrgClient: tp {} not existed in SRG CPterminationPoint list");
235 LOG.info("getRdmSrgClient: Getting BI Directional PP port ...");
236 srgType = OpenroadmTpType.SRGTXRXPP;
239 LOG.info("getRdmSrgClient: Getting UNI Rx PP port ...");
240 srgType = OpenroadmTpType.SRGRXPP;
243 LOG.info("getRdmSrgClient: Getting UNI Tx PP port ...");
244 srgType = OpenroadmTpType.SRGTXPP;
249 LOG.info("getRdmSrgClient: Getting client PP for CP '{}'", tp);
250 if (!this.availableSrgPp.isEmpty()) {
251 Optional<String> client = null;
252 final OpenroadmTpType openType = srgType;
253 client = this.availableSrgPp.entrySet()
254 .stream().filter(pp -> pp.getValue().getName().equals(openType.getName()))
255 .map(Map.Entry::getKey)
256 .sorted(new SortPortsByName())
258 if (!client.isPresent()) {
259 LOG.error("getRdmSrgClient: ROADM {} doesn't have PP Client for CP {}", this.toString(), tp);
262 LOG.info("getRdmSrgClient: client PP {} for CP {} found !", client, tp);
265 LOG.error("getRdmSrgClient: SRG TerminationPoint PP list is not available for node {}", this.toString());
270 private String getSupNodeId(Node inputNode) {
271 String tempSupId = "";
272 // TODO: supporting IDs exist as a List. this code takes just the
274 tempSupId = MapUtils.getSupNode(inputNode);
275 if (tempSupId.equals("")) {
276 LOG.error("getSupNodeId: Empty Supporting node for node: [{}]. Node is ignored", inputNode.getNodeId());
281 public void validateAZxponder(String anodeId, String znodeId) {
286 if (this.nodeType != OpenroadmNodeType.XPONDER) {
291 if (this.supNodeId.equals(anodeId) || (this.supNodeId.equals(znodeId))) {
293 LOG.info("validateAZxponder: A or Z node detected == {}", nodeId.getValue());
298 LOG.debug("validateAZxponder: XPONDER is ignored == {}", nodeId.getValue());
302 public String getXpdrClient(String tp) {
303 return this.clientPerNwTp.get(tp);
306 public boolean checkTP(String tp) {
307 return !(this.usedXpndrNWTps.contains(tp));
310 public boolean checkWL(long index) {
311 return (this.availableWLindex.contains(index));
314 public boolean isValid() {
315 if ((node == null) || (nodeId == null) || (nodeType == null) || (supNodeId == null) || (clli == null)) {
316 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, supporting nodeId");
322 public List<Long> getAvailableWLs() {
323 return availableWLindex;
326 public void addOutgoingLink(PceLink outLink) {
327 this.outgoingLinks.add(outLink);
330 public List<PceLink> getOutgoingLinks() {
331 return outgoingLinks;
334 public String getClient(String tp) {
335 return clientPerNwTp.get(tp);
338 public NodeId getNodeId() {
342 public String getSupNodeIdPceNode() {
346 public String getCLLI() {
350 public String toString() {
351 return "PceNode type=" + nodeType + " ID=" + nodeId.getValue() + " CLLI=" + clli;
354 public void printLinksOfNode() {
355 LOG.info(" outgoing links of node {} : {} ", nodeId.getValue(), this.getOutgoingLinks().toString());