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;
18 import org.opendaylight.transportpce.pce.SortPortsByName;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.TerminationPoint1;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Node1;
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.http.org.openroadm.service.format.rev190531.ServiceFormat;
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.opendaylight.yangtools.yang.common.Uint16;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public class PceOpticalNode implements PceNode {
32 private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
34 private boolean valid = true;
36 private final Node node;
37 private final NodeId nodeId;
38 private final OpenroadmNodeType nodeType;
39 private final ServiceFormat serviceFormat;
40 private final String pceNodeType;
42 // wavelength calculation per node type
43 private List<Long> availableWLindex = new ArrayList<Long>();
44 private Map<String, OpenroadmTpType> availableSrgPp = new TreeMap<String, OpenroadmTpType>();
45 private Map<String, OpenroadmTpType> availableSrgCp = new TreeMap<String, OpenroadmTpType>();
46 private List<String> usedXpndrNWTps = new ArrayList<String>();
47 private List<PceLink> outgoingLinks = new ArrayList<PceLink>();
48 private Map<String, String> clientPerNwTp = new HashMap<String, String>();
50 public PceOpticalNode(Node node, OpenroadmNodeType nodeType, NodeId nodeId, ServiceFormat serviceFormat,
54 this.nodeType = nodeType;
55 this.serviceFormat = serviceFormat;
56 this.pceNodeType = pceNodeType;
58 if ((node == null) || (nodeId == null) || (nodeType == null)) {
59 LOG.error("PceNode: one of parameters is not populated : nodeId, node type");
64 public void initSrgTps() {
65 this.availableSrgPp.clear();
66 this.availableSrgCp.clear();
70 LOG.info("initSrgTpList: getting SRG tps from ROADM node {}", this.nodeId);
71 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
72 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
73 .ietf.network.topology.rev180226.Node1.class);
74 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
75 .node.TerminationPoint> allTps = nodeTp.getTerminationPoint();
77 LOG.error("initSrgTpList: ROADM TerminationPoint list is empty for node {}", this.toString());
81 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
82 .node.TerminationPoint tp : allTps) {
83 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
84 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.TerminationPoint1 nttp1 = tp
85 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130
86 .TerminationPoint1.class);
87 OpenroadmTpType type = cntp1.getTpType();
88 LOG.info("type = {} for tp {}", type.getName(), tp.toString());
94 LOG.info("initSrgTpList: adding SRG-CP tp = {} ", tp.getTpId().getValue());
95 this.availableSrgCp.put(tp.getTpId().getValue(), cntp1.getTpType());
101 LOG.info("initSrgTpList: SRG-PP tp = {} found", tp.getTpId().getValue());
103 List<UsedWavelength> usedWavelengths = nttp1.getPpAttributes().getUsedWavelength();
104 if (usedWavelengths.isEmpty()) {
107 } catch (NullPointerException e) {
108 LOG.warn("initSrgTpList: 'usedWavelengths' for tp={} is null !", tp.getTpId().getValue());
112 LOG.info("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
113 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
115 LOG.warn("initSrgTpList: SRG-PP tp = {} found is busy !!", tp.getTpId().getValue());
122 if (this.availableSrgPp.isEmpty() && this.availableSrgCp.isEmpty()) {
123 LOG.error("initSrgTpList: ROADM SRG TerminationPoint list is empty for node {}", this.toString());
127 LOG.info("initSrgTpList: availableSrgPp size = {} && availableSrgCp size = {} in {}",
128 this.availableSrgPp.size(), this.availableSrgCp.size(), this.toString());
132 public void initWLlist() {
133 this.availableWLindex.clear();
137 Node1 node1 = this.node.augmentation(Node1.class);
138 switch (this.nodeType) {
140 List<org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev181130.srg.node.attributes
141 .AvailableWavelengths> srgAvailableWL =
142 node1.getSrgAttributes().getAvailableWavelengths();
143 if (srgAvailableWL == null) {
145 LOG.error("initWLlist: SRG AvailableWavelengths is empty for node {}", this.toString());
148 for (org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev181130.srg.node.attributes
149 .AvailableWavelengths awl : srgAvailableWL) {
150 this.availableWLindex.add(awl.getIndex().toJava());
151 LOG.debug("initWLlist: SRG next = {} in {}", awl.getIndex(), this.toString());
155 List<org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev181130.degree.node.attributes
156 .AvailableWavelengths> degAvailableWL = node1.getDegreeAttributes().getAvailableWavelengths();
157 if (degAvailableWL == null) {
159 LOG.error("initWLlist: DEG AvailableWavelengths is empty for node {}", this.toString());
162 for (org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev181130.degree.node.attributes
163 .AvailableWavelengths awl : degAvailableWL) {
164 this.availableWLindex.add(awl.getIndex().toJava());
165 LOG.debug("initWLlist: DEGREE next = {} in {}", awl.getIndex(), this.toString());
170 for (long i = 1; i <= 96; i++) {
171 this.availableWLindex.add(i);
175 LOG.error("initWLlist: unsupported node type {} in node {}", this.nodeType, this.toString());
178 if (this.availableWLindex.size() == 0) {
179 LOG.debug("initWLlist: There are no available wavelengths in node {}", this.toString());
182 LOG.debug("initWLlist: availableWLindex size = {} in {}", this.availableWLindex.size(), this.toString());
186 public void initXndrTps() {
187 LOG.info("PceNod: initXndrTps for node : {}", this.nodeId);
191 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
192 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
193 .ietf.network.topology.rev180226.Node1.class);
194 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
195 .node.TerminationPoint> allTps = nodeTp.getTerminationPoint();
196 if (allTps == null) {
198 LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this.toString());
202 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
203 .node.TerminationPoint tp : allTps) {
204 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
205 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.TerminationPoint1 nttp1 = tp
206 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130
207 .TerminationPoint1.class);
208 if (cntp1.getTpType() == OpenroadmTpType.XPONDERNETWORK) {
209 if (nttp1 != null && nttp1.getXpdrNetworkAttributes().getWavelength() != null) {
210 this.usedXpndrNWTps.add(tp.getTpId().getValue());
211 LOG.info("initXndrTps: XPONDER tp = {} is used", tp.getTpId().getValue());
215 // find Client of this network TP
217 org.opendaylight.yang.gen.v1.http.transportpce.topology.rev200129.TerminationPoint1 tpceTp1 =
218 tp.augmentation(org.opendaylight.yang.gen.v1.http.transportpce.topology.rev200129
219 .TerminationPoint1.class);
220 if (tpceTp1 != null) {
221 client = tpceTp1.getAssociatedConnectionMapPort();
222 if (client != null) {
223 this.clientPerNwTp.put(tp.getTpId().getValue(), client);
226 LOG.error("initXndrTps: XPONDER {} NW TP doesn't have defined Client {}", this.toString(),
227 tp.getTpId().getValue());
229 } else if (ServiceFormat.OTU.equals(this.serviceFormat)) {
230 LOG.info("Infrastructure OTU4 connection");
233 LOG.error("Service Format {} not managed yet", this.serviceFormat.getName());
238 LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node {}", this.toString());
244 public String getRdmSrgClient(String tp) {
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", tp);
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());
290 public void validateAZxponder(String anodeId, String znodeId) {
294 if (this.nodeType != OpenroadmNodeType.XPONDER) {
298 if (this.getSupNetworkNodeId().equals(anodeId) || (this.getSupNetworkNodeId().equals(znodeId))) {
299 LOG.info("validateAZxponder: A or Z node detected == {}", nodeId.getValue());
303 LOG.debug("validateAZxponder: XPONDER is ignored == {}", nodeId.getValue());
308 public boolean checkTP(String tp) {
309 return !this.usedXpndrNWTps.contains(tp);
313 public boolean checkWL(long index) {
314 return (this.availableWLindex.contains(index));
317 public boolean isValid() {
318 if (node == null || nodeId == null || nodeType == null || this.getSupNetworkNodeId() == null
319 || this.getSupClliNodeId() == null) {
320 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, supporting nodeId");
327 public List<PceLink> getOutgoingLinks() {
328 return outgoingLinks;
332 public NodeId getNodeId() {
336 public String toString() {
337 return "PceNode type=" + nodeType + " ID=" + nodeId.getValue() + " CLLI=" + this.getSupClliNodeId();
341 public String getPceNodeType() {
342 return this.pceNodeType;
346 public String getSupNetworkNodeId() {
347 return MapUtils.getSupNetworkNode(this.node);
351 public String getSupClliNodeId() {
352 return MapUtils.getSupClliNode(this.node);
356 public void addOutgoingLink(PceLink outLink) {
357 this.outgoingLinks.add(outLink);
361 public String getXpdrClient(String tp) {
362 return this.clientPerNwTp.get(tp);
366 public Map<String, List<Uint16>> getAvailableTribPorts() {
367 // TODO Auto-generated method stub
372 public Map<String, List<Uint16>> getAvailableTribSlots() {
373 // TODO Auto-generated method stub