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.common.NetworkUtils;
19 import org.opendaylight.transportpce.pce.SortPortsByName;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.TerminationPoint1;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Node1;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.networks.network.node.termination.point.pp.attributes.UsedWavelength;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmNodeType;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmTpType;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class PceNode {
32 private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
33 ////////////////////////// NODES ///////////////////////////
37 private boolean valid = true;
39 protected final Node node;
40 protected final NodeId nodeId;
41 protected final OpenroadmNodeType nodeType;
42 private final String supNodeId;
43 private final String supNetworkNodeId;
44 private final String clli;
46 // wavelength calculation per node type
47 private List<Long> availableWLindex = new ArrayList<Long>();
48 private Map<String, OpenroadmTpType> availableSrgPp = new TreeMap<String, OpenroadmTpType>();
49 private Map<String, OpenroadmTpType> availableSrgCp = new TreeMap<String, OpenroadmTpType>();
50 private List<String> usedXpndrNWTps = new ArrayList<String>();
51 private List<PceLink> outgoingLinks = new ArrayList<PceLink>();
52 private Map<String, String> clientPerNwTp = new HashMap<String, String>();
53 private Map<String,List<Integer>> tpAvailableTribPort = new TreeMap<String,List<Integer>>();
54 private Map<String,List<Integer>> tpAvailableTribSlot = new TreeMap<String,List<Integer>>();
56 public PceNode(Node node, OpenroadmNodeType nodeType, NodeId nodeId) {
59 this.nodeType = nodeType;
60 this.supNodeId = getSupNodeId(node);
61 this.supNetworkNodeId = getNetworkSupNodeId(node);
62 //this.clli = MapUtils.getCLLI(node);
63 this.clli = getClliSupNodeId(node);
64 this.tpAvailableTribPort.clear();
65 this.tpAvailableTribSlot.clear();
67 if ((node == null) || (nodeId == null) || (nodeType == null)) {
68 LOG.error("PceNode: one of parameters is not populated : nodeId, node type");
73 public void initSrgTps() {
74 this.availableSrgPp.clear();
75 this.availableSrgCp.clear();
79 LOG.info("initSrgTpList: getting SRG tps from ROADM node {}", this.nodeId);
80 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
81 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology
82 .rev180226.Node1.class);
83 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
84 .node.TerminationPoint> allTps =
85 nodeTp.getTerminationPoint();
87 LOG.error("initSrgTpList: ROADM TerminationPoint list is empty for node {}", this.toString());
91 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
92 .node.TerminationPoint tp : allTps) {
93 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
94 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.TerminationPoint1 nttp1 = tp
95 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130
96 .TerminationPoint1.class);
97 OpenroadmTpType type = cntp1.getTpType();
98 LOG.info("type = {} for tp {}", type.getName(), tp.toString());
104 LOG.info("initSrgTpList: adding SRG-CP tp = {} ", tp.getTpId().getValue());
105 this.availableSrgCp.put(tp.getTpId().getValue(), cntp1.getTpType());
111 LOG.info("initSrgTpList: SRG-PP tp = {} found", tp.getTpId().getValue());
113 List<UsedWavelength> usedWavelengths = nttp1.getPpAttributes().getUsedWavelength();
114 if (usedWavelengths.isEmpty()) {
117 } catch (NullPointerException e) {
118 LOG.warn("initSrgTpList: 'usedWavelengths' for tp={} is null !", tp.getTpId().getValue());
122 LOG.info("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
123 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
125 LOG.warn("initSrgTpList: SRG-PP tp = {} found is busy !!");
132 if (this.availableSrgPp.isEmpty() && this.availableSrgCp.isEmpty()) {
133 LOG.error("initSrgTpList: ROADM SRG TerminationPoint list is empty for node {}", this.toString());
137 LOG.info("initSrgTpList: availableSrgPp size = {} && availableSrgCp size = {} in {}", this.availableSrgPp
138 .size(), this.availableSrgCp.size(), this.toString());
142 public void initWLlist() {
143 this.availableWLindex.clear();
147 Node1 node1 = this.node.augmentation(Node1.class);
148 switch (this.nodeType) {
150 List<org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev181130.srg.node.attributes
151 .AvailableWavelengths> srgAvailableWL =
152 node1.getSrgAttributes().getAvailableWavelengths();
153 if (srgAvailableWL == null) {
155 LOG.error("initWLlist: SRG AvailableWavelengths is empty for node {}", this.toString());
158 for (org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev181130.srg.node.attributes
159 .AvailableWavelengths awl : srgAvailableWL) {
160 this.availableWLindex.add(awl.getIndex());
161 LOG.debug("initWLlist: SRG next = {} in {}", awl.getIndex(), this.toString());
165 List<org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev181130.degree.node.attributes
166 .AvailableWavelengths> degAvailableWL = node1.getDegreeAttributes().getAvailableWavelengths();
167 if (degAvailableWL == null) {
169 LOG.error("initWLlist: DEG AvailableWavelengths is empty for node {}", this.toString());
172 for (org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev181130.degree.node.attributes
173 .AvailableWavelengths awl : degAvailableWL) {
174 this.availableWLindex.add(awl.getIndex());
175 LOG.debug("initWLlist: DEGREE next = {} in {}", awl.getIndex(), this.toString());
180 for (long i = 1; i <= 96; i++) {
181 this.availableWLindex.add(i);
185 LOG.error("initWLlist: unsupported node type {} in node {}", this.nodeType, this.toString());
188 if (this.availableWLindex.size() == 0) {
189 LOG.debug("initWLlist: There are no available wavelengths in node {}", this.toString());
192 LOG.debug("initWLlist: availableWLindex size = {} in {}", this.availableWLindex.size(), this.toString());
196 public void initXndrTps() {
197 LOG.info("initXndrTps for node : {}", this.nodeId);
201 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
202 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology
203 .rev180226.Node1.class);
204 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
205 .node.TerminationPoint> allTps = nodeTp.getTerminationPoint();
206 if (allTps == null) {
208 LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this.toString());
212 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
213 .node.TerminationPoint tp : allTps) {
214 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
215 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.TerminationPoint1 nttp1 = tp
216 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130
217 .TerminationPoint1.class);
218 if (cntp1.getTpType() == OpenroadmTpType.XPONDERNETWORK) {
219 if (nttp1 != null && nttp1.getXpdrNetworkAttributes().getWavelength() != null) {
220 this.usedXpndrNWTps.add(tp.getTpId().getValue());
221 LOG.info("initXndrTps: XPONDER tp = {} is used", tp.getTpId().getValue());
225 // find Client of this network TP
226 org.opendaylight.yang.gen.v1.http.transportpce.topology.rev200123.TerminationPoint1 tpceTp1 =
227 tp.augmentation(org.opendaylight.yang.gen.v1.http.transportpce.topology.rev200123
228 .TerminationPoint1.class);
229 String client = tpceTp1.getAssociatedConnectionMapPort();
230 if ((client.equals("")) || (client == null)) {
231 LOG.error("initXndrTps: XPONDER {} NW TP doesn't have defined Client {}", this.toString(), tp
232 .getTpId().getValue());
235 this.clientPerNwTp.put(tp.getTpId().getValue(), client);
239 LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node {}", this.toString());
244 public String getRdmSrgClient(String tp, Boolean aend) {
245 LOG.info("getRdmSrgClient: Getting PP client for tp '{}' on node : {}", tp, this.nodeId);
246 OpenroadmTpType srgType = null;
247 OpenroadmTpType cpType = this.availableSrgCp.get(tp);
248 if (cpType == null) {
249 LOG.error("getRdmSrgClient: tp {} not existed in SRG CPterminationPoint list");
254 LOG.info("getRdmSrgClient: Getting BI Directional PP port ...");
255 srgType = OpenroadmTpType.SRGTXRXPP;
258 LOG.info("getRdmSrgClient: Getting UNI Rx PP port ...");
259 srgType = OpenroadmTpType.SRGRXPP;
262 LOG.info("getRdmSrgClient: Getting UNI Tx PP port ...");
263 srgType = OpenroadmTpType.SRGTXPP;
268 LOG.info("getRdmSrgClient: Getting client PP for CP '{}'", tp);
269 if (!this.availableSrgPp.isEmpty()) {
270 Optional<String> client = null;
271 final OpenroadmTpType openType = srgType;
272 client = this.availableSrgPp.entrySet()
273 .stream().filter(pp -> pp.getValue().getName().equals(openType.getName()))
274 .map(Map.Entry::getKey)
275 .sorted(new SortPortsByName())
277 if (!client.isPresent()) {
278 LOG.error("getRdmSrgClient: ROADM {} doesn't have PP Client for CP {}", this.toString(), tp);
281 LOG.info("getRdmSrgClient: client PP {} for CP {} found !", client, tp);
284 LOG.error("getRdmSrgClient: SRG TerminationPoint PP list is not available for node {}", this.toString());
289 private String getSupNodeId(Node inputNode) {
290 // TODO: supporting IDs exist as a List. this code takes just the
292 if (MapUtils.getSupNode(inputNode) != null) {
293 return MapUtils.getSupNode(inputNode);
295 LOG.error("getSupNodeId: Empty Supporting node for node: [{}]. Node is ignored", inputNode.getNodeId());
300 private String getClliSupNodeId(Node inputNode) {
301 TreeMap<String, String> allSupNodes = new TreeMap<String, String>();
302 String tempNetworkSupNodeId = "";
303 allSupNodes = MapUtils.getAllSupNode(inputNode);
304 if (allSupNodes.get(NetworkUtils.CLLI_NETWORK_ID) == null) {
305 LOG.error("getClliSupNodeId: No Supporting node at CLLI layer for node: [{}].", inputNode.getNodeId());
307 tempNetworkSupNodeId = allSupNodes.get(NetworkUtils.CLLI_NETWORK_ID);
309 return tempNetworkSupNodeId;
312 public String getClliSupNodeId() {
316 private String getNetworkSupNodeId(Node inputNode) {
317 TreeMap<String, String> allSupNodes = new TreeMap<String, String>();
318 String tempNetworkSupNodeId = "";
319 allSupNodes = MapUtils.getAllSupNode(inputNode);
320 if (allSupNodes.get(NetworkUtils.UNDERLAY_NETWORK_ID) == null) {
322 "getNetworkSupNodeId: No Supporting node at NETWORK layer for node: [{}].", inputNode.getNodeId());
324 tempNetworkSupNodeId = allSupNodes.get(NetworkUtils.UNDERLAY_NETWORK_ID);
326 return tempNetworkSupNodeId;
330 public void validateAZxponder(String anodeId, String znodeId) {
334 if (this.nodeType != OpenroadmNodeType.XPONDER) {
338 if (this.supNetworkNodeId.equals(anodeId) || (this.supNetworkNodeId.equals(znodeId))) {
339 LOG.info("validateAZxponder: A or Z node detected == {}", nodeId.getValue());
343 LOG.debug("validateAZxponder: XPONDER is ignored == {}", nodeId.getValue());
347 public String getXpdrClient(String tp) {
348 return this.clientPerNwTp.get(tp);
351 public boolean checkTP(String tp) {
352 return !(this.usedXpndrNWTps.contains(tp));
355 public boolean checkWL(long index) {
356 return (this.availableWLindex.contains(index));
359 public boolean isValid() {
360 if ((node == null) || (nodeId == null) || (nodeType == null) || (supNetworkNodeId == null) || (clli == null)) {
361 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, supporting nodeId");
367 public List<Long> getAvailableWLs() {
368 return availableWLindex;
371 public void addOutgoingLink(PceLink outLink) {
372 this.outgoingLinks.add(outLink);
375 public List<PceLink> getOutgoingLinks() {
376 return outgoingLinks;
379 public String getClient(String tp) {
380 return clientPerNwTp.get(tp);
383 public NodeId getNodeId() {
387 public String getSupNodeIdPceNode() {
391 public String getSupNetworkNodeIdPceNode() {
392 return supNetworkNodeId;
395 public String getCLLI() {
399 public String toString() {
400 return "PceNode type=" + nodeType + " ID=" + nodeId.getValue() + " CLLI=" + clli;
403 public void printLinksOfNode() {
404 LOG.info(" outgoing links of node {} : {} ", nodeId.getValue(), this.getOutgoingLinks().toString());
407 public Map<String,List<Integer>> getAvailableTribPorts() {
408 return tpAvailableTribPort;
411 public Map<String,List<Integer>> getAvailableTribSlots() {
412 return tpAvailableTribSlot;