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.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class PceOpticalNode implements PceNode {
31 private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.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<Long>();
43 private Map<String, OpenroadmTpType> availableSrgPp = new TreeMap<String, OpenroadmTpType>();
44 private Map<String, OpenroadmTpType> availableSrgCp = new TreeMap<String, OpenroadmTpType>();
45 private List<String> usedXpndrNWTps = new ArrayList<String>();
46 private List<PceLink> outgoingLinks = new ArrayList<PceLink>();
47 private Map<String, String> clientPerNwTp = new HashMap<String, String>();
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.toString());
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.toString());
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 !!");
121 if (this.availableSrgPp.isEmpty() && this.availableSrgCp.isEmpty()) {
122 LOG.error("initSrgTpList: ROADM SRG TerminationPoint list is empty for node {}", this.toString());
126 LOG.info("initSrgTpList: availableSrgPp size = {} && availableSrgCp size = {} in {}",
127 this.availableSrgPp.size(), this.availableSrgCp.size(), this.toString());
131 public void initWLlist() {
132 this.availableWLindex.clear();
136 Node1 node1 = this.node.augmentation(Node1.class);
137 switch (this.nodeType) {
139 List<org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev181130.srg.node.attributes
140 .AvailableWavelengths> srgAvailableWL =
141 node1.getSrgAttributes().getAvailableWavelengths();
142 if (srgAvailableWL == null) {
144 LOG.error("initWLlist: SRG AvailableWavelengths is empty for node {}", this.toString());
147 for (org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev181130.srg.node.attributes
148 .AvailableWavelengths awl : srgAvailableWL) {
149 this.availableWLindex.add(awl.getIndex());
150 LOG.debug("initWLlist: SRG next = {} in {}", awl.getIndex(), this.toString());
154 List<org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev181130.degree.node.attributes
155 .AvailableWavelengths> degAvailableWL = node1.getDegreeAttributes().getAvailableWavelengths();
156 if (degAvailableWL == null) {
158 LOG.error("initWLlist: DEG AvailableWavelengths is empty for node {}", this.toString());
161 for (org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev181130.degree.node.attributes
162 .AvailableWavelengths awl : degAvailableWL) {
163 this.availableWLindex.add(awl.getIndex());
164 LOG.debug("initWLlist: DEGREE next = {} in {}", awl.getIndex(), this.toString());
169 for (long i = 1; i <= 96; i++) {
170 this.availableWLindex.add(i);
174 LOG.error("initWLlist: unsupported node type {} in node {}", this.nodeType, this.toString());
177 if (this.availableWLindex.size() == 0) {
178 LOG.debug("initWLlist: There are no available wavelengths in node {}", this.toString());
181 LOG.debug("initWLlist: availableWLindex size = {} in {}", this.availableWLindex.size(), this.toString());
185 public void initXndrTps() {
186 LOG.info("PceNod: initXndrTps for node : {}", this.nodeId);
190 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
191 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
192 .ietf.network.topology.rev180226.Node1.class);
193 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
194 .node.TerminationPoint> allTps = nodeTp.getTerminationPoint();
195 if (allTps == null) {
197 LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this.toString());
201 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
202 .node.TerminationPoint tp : allTps) {
203 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
204 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.TerminationPoint1 nttp1 = tp
205 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130
206 .TerminationPoint1.class);
207 if (cntp1.getTpType() == OpenroadmTpType.XPONDERNETWORK) {
208 if (nttp1 != null && nttp1.getXpdrNetworkAttributes().getWavelength() != null) {
209 this.usedXpndrNWTps.add(tp.getTpId().getValue());
210 LOG.info("initXndrTps: XPONDER tp = {} is used", tp.getTpId().getValue());
214 // find Client of this network TP
216 org.opendaylight.yang.gen.v1.http.transportpce.topology.rev200129.TerminationPoint1 tpceTp1 =
217 tp.augmentation(org.opendaylight.yang.gen.v1.http.transportpce.topology.rev200129
218 .TerminationPoint1.class);
219 if (tpceTp1 != null) {
220 client = tpceTp1.getAssociatedConnectionMapPort();
221 if (client != null) {
222 this.clientPerNwTp.put(tp.getTpId().getValue(), client);
225 LOG.error("initXndrTps: XPONDER {} NW TP doesn't have defined Client {}", this.toString(),
226 tp.getTpId().getValue());
228 } else if (ServiceFormat.OTU.equals(this.serviceFormat)) {
229 LOG.info("Infrastructure OTU4 connection");
232 LOG.error("Service Format {} not managed yet", this.serviceFormat.getName());
237 LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node {}", this.toString());
243 public String getRdmSrgClient(String tp) {
244 LOG.info("getRdmSrgClient: Getting PP client for tp '{}' on node : {}", tp, this.nodeId);
245 OpenroadmTpType srgType = null;
246 OpenroadmTpType cpType = this.availableSrgCp.get(tp);
247 if (cpType == null) {
248 LOG.error("getRdmSrgClient: tp {} not existed in SRG CPterminationPoint list");
253 LOG.info("getRdmSrgClient: Getting BI Directional PP port ...");
254 srgType = OpenroadmTpType.SRGTXRXPP;
257 LOG.info("getRdmSrgClient: Getting UNI Rx PP port ...");
258 srgType = OpenroadmTpType.SRGRXPP;
261 LOG.info("getRdmSrgClient: Getting UNI Tx PP port ...");
262 srgType = OpenroadmTpType.SRGTXPP;
267 LOG.info("getRdmSrgClient: Getting client PP for CP '{}'", tp);
268 if (!this.availableSrgPp.isEmpty()) {
269 Optional<String> client = null;
270 final OpenroadmTpType openType = srgType;
271 client = this.availableSrgPp.entrySet()
272 .stream().filter(pp -> pp.getValue().getName().equals(openType.getName()))
273 .map(Map.Entry::getKey)
274 .sorted(new SortPortsByName())
276 if (!client.isPresent()) {
277 LOG.error("getRdmSrgClient: ROADM {} doesn't have PP Client for CP {}", this.toString(), tp);
280 LOG.info("getRdmSrgClient: client PP {} for CP {} found !", client, tp);
283 LOG.error("getRdmSrgClient: SRG TerminationPoint PP list is not available for node {}", this.toString());
289 public void validateAZxponder(String anodeId, String znodeId) {
293 if (this.nodeType != OpenroadmNodeType.XPONDER) {
297 if (this.getSupNetworkNodeId().equals(anodeId) || (this.getSupNetworkNodeId().equals(znodeId))) {
298 LOG.info("validateAZxponder: A or Z node detected == {}", nodeId.getValue());
302 LOG.debug("validateAZxponder: XPONDER is ignored == {}", nodeId.getValue());
307 public boolean checkTP(String tp) {
308 return !this.usedXpndrNWTps.contains(tp);
312 public boolean checkWL(long index) {
313 return (this.availableWLindex.contains(index));
316 public boolean isValid() {
317 if (node == null || nodeId == null || nodeType == null || this.getSupNetworkNodeId() == null
318 || this.getSupClliNodeId() == null) {
319 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, supporting nodeId");
326 public List<PceLink> getOutgoingLinks() {
327 return outgoingLinks;
331 public NodeId getNodeId() {
335 public String toString() {
336 return "PceNode type=" + nodeType + " ID=" + nodeId.getValue() + " CLLI=" + this.getSupClliNodeId();
340 public String getPceNodeType() {
341 return this.pceNodeType;
345 public String getSupNetworkNodeId() {
346 return MapUtils.getSupNetworkNode(this.node);
350 public String getSupClliNodeId() {
351 return MapUtils.getSupClliNode(this.node);
355 public void addOutgoingLink(PceLink outLink) {
356 this.outgoingLinks.add(outLink);
360 public String getXpdrClient(String tp) {
361 return this.clientPerNwTp.get(tp);
365 public Map<String, List<Integer>> getAvailableTribPorts() {
366 // TODO Auto-generated method stub
371 public Map<String, List<Integer>> getAvailableTribSlots() {
372 // TODO Auto-generated method stub