2 * Copyright © 2020 Orange, 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;
17 import org.opendaylight.transportpce.pce.SortPortsByName;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.TerminationPoint1;
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.networks.network.node.termination.point.pp.attributes.UsedWavelength;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmNodeType;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmTpType;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.ServiceFormat;
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.opendaylight.yangtools.yang.common.Uint16;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class PceOpticalNode implements PceNode {
31 private static final Logger LOG = LoggerFactory.getLogger(PceOpticalNode.class);
33 private boolean valid = true;
35 private final Node node;
36 private final NodeId nodeId;
37 private final OpenroadmNodeType nodeType;
38 private final ServiceFormat serviceFormat;
39 private final String pceNodeType;
41 // wavelength calculation per node type
42 private List<Long> availableWLindex = new ArrayList<>();
43 private Map<String, OpenroadmTpType> availableSrgPp = new TreeMap<>();
44 private Map<String, OpenroadmTpType> availableSrgCp = new TreeMap<>();
45 private List<String> usedXpndrNWTps = new ArrayList<>();
46 private List<PceLink> outgoingLinks = new ArrayList<>();
47 private Map<String, String> clientPerNwTp = new HashMap<>();
49 public PceOpticalNode(Node node, OpenroadmNodeType nodeType, NodeId nodeId, ServiceFormat serviceFormat,
53 this.nodeType = nodeType;
54 this.serviceFormat = serviceFormat;
55 this.pceNodeType = pceNodeType;
57 if ((node == null) || (nodeId == null) || (nodeType == null)) {
58 LOG.error("PceNode: one of parameters is not populated : nodeId, node type");
63 public void initSrgTps() {
64 this.availableSrgPp.clear();
65 this.availableSrgCp.clear();
69 LOG.info("initSrgTpList: getting SRG tps from ROADM node {}", this.nodeId);
70 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
71 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
72 .ietf.network.topology.rev180226.Node1.class);
73 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
74 .node.TerminationPoint> allTps = nodeTp.getTerminationPoint();
76 LOG.error("initSrgTpList: ROADM TerminationPoint list is empty for node {}", this);
80 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
81 .node.TerminationPoint tp : allTps) {
82 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
83 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.TerminationPoint1 nttp1 = tp
84 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130
85 .TerminationPoint1.class);
86 OpenroadmTpType type = cntp1.getTpType();
87 LOG.info("type = {} for tp {}", type.getName(), tp);
93 LOG.info("initSrgTpList: adding SRG-CP tp = {} ", tp.getTpId().getValue());
94 this.availableSrgCp.put(tp.getTpId().getValue(), cntp1.getTpType());
100 LOG.info("initSrgTpList: SRG-PP tp = {} found", tp.getTpId().getValue());
102 List<UsedWavelength> usedWavelengths = nttp1.getPpAttributes().getUsedWavelength();
103 if (usedWavelengths.isEmpty()) {
106 } catch (NullPointerException e) {
107 LOG.warn("initSrgTpList: 'usedWavelengths' for tp={} is null !", tp.getTpId().getValue());
111 LOG.info("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
112 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
114 LOG.warn("initSrgTpList: SRG-PP tp = {} found is busy !!", tp.getTpId().getValue());
121 if (this.availableSrgPp.isEmpty() && this.availableSrgCp.isEmpty()) {
122 LOG.error("initSrgTpList: ROADM SRG TerminationPoint list is empty for node {}", this);
126 LOG.info("initSrgTpList: availableSrgPp size = {} && availableSrgCp size = {} in {}",
127 this.availableSrgPp.size(), this.availableSrgCp.size(), this);
130 public void initWLlist() {
131 this.availableWLindex.clear();
135 Node1 node1 = this.node.augmentation(Node1.class);
136 switch (this.nodeType) {
138 List<org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev181130.srg.node.attributes
139 .AvailableWavelengths> srgAvailableWL =
140 node1.getSrgAttributes().getAvailableWavelengths();
141 if (srgAvailableWL == null) {
143 LOG.error("initWLlist: SRG AvailableWavelengths is empty for node {}", this);
146 for (org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev181130.srg.node.attributes
147 .AvailableWavelengths awl : srgAvailableWL) {
148 this.availableWLindex.add(awl.getIndex().toJava());
149 LOG.debug("initWLlist: SRG next = {} in {}", awl.getIndex(), this);
153 List<org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev181130.degree.node.attributes
154 .AvailableWavelengths> degAvailableWL = node1.getDegreeAttributes().getAvailableWavelengths();
155 if (degAvailableWL == null) {
157 LOG.error("initWLlist: DEG AvailableWavelengths is empty for node {}", this);
160 for (org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev181130.degree.node.attributes
161 .AvailableWavelengths awl : degAvailableWL) {
162 this.availableWLindex.add(awl.getIndex().toJava());
163 LOG.debug("initWLlist: DEGREE next = {} in {}", awl.getIndex(), this);
168 for (long i = 1; i <= 96; i++) {
169 this.availableWLindex.add(i);
173 LOG.error("initWLlist: unsupported node type {} in node {}", this.nodeType, this);
176 if (this.availableWLindex.isEmpty()) {
177 LOG.debug("initWLlist: There are no available wavelengths in node {}", this);
180 LOG.debug("initWLlist: availableWLindex size = {} in {}", this.availableWLindex.size(), this);
183 public void initXndrTps() {
184 LOG.info("PceNod: 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
190 .ietf.network.topology.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);
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 cntp1 = tp.augmentation(TerminationPoint1.class);
202 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.TerminationPoint1 nttp1 = tp
203 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130
204 .TerminationPoint1.class);
205 if (cntp1.getTpType() == OpenroadmTpType.XPONDERNETWORK) {
206 if (nttp1 != null && nttp1.getXpdrNetworkAttributes().getWavelength() != null) {
207 this.usedXpndrNWTps.add(tp.getTpId().getValue());
208 LOG.info("initXndrTps: XPONDER tp = {} is used", tp.getTpId().getValue());
212 // find Client of this network TP
214 org.opendaylight.yang.gen.v1.http.transportpce.topology.rev200129.TerminationPoint1 tpceTp1 =
215 tp.augmentation(org.opendaylight.yang.gen.v1.http.transportpce.topology.rev200129
216 .TerminationPoint1.class);
217 if (tpceTp1 != null) {
218 client = tpceTp1.getAssociatedConnectionMapPort();
219 if (client != null) {
220 this.clientPerNwTp.put(tp.getTpId().getValue(), client);
223 LOG.error("initXndrTps: XPONDER {} NW TP doesn't have defined Client {}",
224 this, tp.getTpId().getValue());
226 } else if (ServiceFormat.OTU.equals(this.serviceFormat)) {
227 LOG.info("Infrastructure OTU4 connection");
230 LOG.error("Service Format {} not managed yet", this.serviceFormat.getName());
235 LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node {}", this);
240 public String getRdmSrgClient(String tp) {
241 LOG.info("getRdmSrgClient: Getting PP client for tp '{}' on node : {}", tp, this.nodeId);
242 OpenroadmTpType srgType = null;
243 OpenroadmTpType cpType = this.availableSrgCp.get(tp);
244 if (cpType == null) {
245 LOG.error("getRdmSrgClient: tp {} not existed in SRG CPterminationPoint list", tp);
250 LOG.info("getRdmSrgClient: Getting BI Directional PP port ...");
251 srgType = OpenroadmTpType.SRGTXRXPP;
254 LOG.info("getRdmSrgClient: Getting UNI Rx PP port ...");
255 srgType = OpenroadmTpType.SRGRXPP;
258 LOG.info("getRdmSrgClient: Getting UNI Tx PP port ...");
259 srgType = OpenroadmTpType.SRGTXPP;
264 LOG.info("getRdmSrgClient: Getting client PP for CP '{}'", tp);
265 if (!this.availableSrgPp.isEmpty()) {
266 Optional<String> client = null;
267 final OpenroadmTpType openType = srgType;
268 client = this.availableSrgPp.entrySet()
269 .stream().filter(pp -> pp.getValue().getName().equals(openType.getName()))
270 .map(Map.Entry::getKey)
271 .sorted(new SortPortsByName())
273 if (!client.isPresent()) {
274 LOG.error("getRdmSrgClient: ROADM {} doesn't have PP Client for CP {}", this, tp);
277 LOG.info("getRdmSrgClient: client PP {} for CP {} found !", client, tp);
280 LOG.error("getRdmSrgClient: SRG TerminationPoint PP list is not available for node {}", this);
286 public void validateAZxponder(String anodeId, String znodeId) {
290 if (this.nodeType != OpenroadmNodeType.XPONDER) {
294 if (this.getSupNetworkNodeId().equals(anodeId) || (this.getSupNetworkNodeId().equals(znodeId))) {
295 LOG.info("validateAZxponder: A or Z node detected == {}", nodeId.getValue());
299 LOG.debug("validateAZxponder: XPONDER is ignored == {}", nodeId.getValue());
304 public boolean checkTP(String tp) {
305 return !this.usedXpndrNWTps.contains(tp);
309 public boolean checkWL(long index) {
310 return (this.availableWLindex.contains(index));
313 public boolean isValid() {
314 if (node == null || nodeId == null || nodeType == null || this.getSupNetworkNodeId() == null
315 || this.getSupClliNodeId() == null) {
316 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, supporting nodeId");
323 public List<PceLink> getOutgoingLinks() {
324 return outgoingLinks;
328 public NodeId getNodeId() {
333 public String toString() {
334 return "PceNode type=" + nodeType + " ID=" + nodeId.getValue() + " CLLI=" + this.getSupClliNodeId();
338 public String getPceNodeType() {
339 return this.pceNodeType;
343 public String getSupNetworkNodeId() {
344 return MapUtils.getSupNetworkNode(this.node);
348 public String getSupClliNodeId() {
349 return MapUtils.getSupClliNode(this.node);
353 public void addOutgoingLink(PceLink outLink) {
354 this.outgoingLinks.add(outLink);
358 public String getXpdrClient(String tp) {
359 return this.clientPerNwTp.get(tp);
363 public Map<String, List<Uint16>> getAvailableTribPorts() {
368 public Map<String, List<Uint16>> getAvailableTribSlots() {