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.common.fixedflex.FixedGridConstant;
18 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
19 import org.opendaylight.transportpce.pce.SortPortsByName;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.TerminationPoint1;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.Node1;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.networks.network.node.termination.point.pp.attributes.UsedWavelength;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmNodeType;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmTpType;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.available.freq.map.AvailFreqMapsKey;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.ServiceFormat;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
29 import org.opendaylight.yangtools.yang.common.Uint16;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 public class PceOpticalNode implements PceNode {
34 private static final Logger LOG = LoggerFactory.getLogger(PceOpticalNode.class);
36 private boolean valid = true;
38 private final Node node;
39 private final NodeId nodeId;
40 private final OpenroadmNodeType nodeType;
41 private final ServiceFormat serviceFormat;
42 private final String pceNodeType;
44 // wavelength calculation per node type
45 private List<Long> availableWLindex = new ArrayList<>();
46 private Map<String, OpenroadmTpType> availableSrgPp = new TreeMap<>();
47 private Map<String, OpenroadmTpType> availableSrgCp = new TreeMap<>();
48 private List<String> usedXpndrNWTps = new ArrayList<>();
49 private List<PceLink> outgoingLinks = new ArrayList<>();
50 private Map<String, String> clientPerNwTp = new HashMap<>();
51 private final AvailFreqMapsKey freqMapKey = new AvailFreqMapsKey(GridConstant.C_BAND);
53 public PceOpticalNode(Node node, OpenroadmNodeType nodeType, NodeId nodeId, ServiceFormat serviceFormat,
57 this.nodeType = nodeType;
58 this.serviceFormat = serviceFormat;
59 this.pceNodeType = pceNodeType;
61 if ((node == null) || (nodeId == null) || (nodeType == null)) {
62 LOG.error("PceNode: one of parameters is not populated : nodeId, node type");
67 public void initSrgTps() {
68 this.availableSrgPp.clear();
69 this.availableSrgCp.clear();
73 LOG.info("initSrgTpList: getting SRG tps from ROADM node {}", this.nodeId);
74 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
75 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
76 .ietf.network.topology.rev180226.Node1.class);
77 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
78 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
79 if (allTps.isEmpty()) {
80 LOG.error("initSrgTpList: ROADM TerminationPoint list is empty for node {}", this);
84 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
85 .node.TerminationPoint tp : allTps) {
86 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
87 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.TerminationPoint1 nttp1 = tp
88 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529
89 .TerminationPoint1.class);
90 OpenroadmTpType type = cntp1.getTpType();
91 LOG.info("type = {} for tp {}", type.getName(), tp);
97 LOG.info("initSrgTpList: adding SRG-CP tp = {} ", tp.getTpId().getValue());
98 this.availableSrgCp.put(tp.getTpId().getValue(), cntp1.getTpType());
104 LOG.info("initSrgTpList: SRG-PP tp = {} found", tp.getTpId().getValue());
106 List<UsedWavelength> usedWavelengths =
107 new ArrayList<>(nttp1.getPpAttributes().getUsedWavelength().values());
108 if (usedWavelengths.isEmpty()) {
111 } catch (NullPointerException e) {
112 LOG.warn("initSrgTpList: 'usedWavelengths' for tp={} is null !", tp.getTpId().getValue());
116 LOG.info("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
117 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
119 LOG.warn("initSrgTpList: SRG-PP tp = {} found is busy !!", tp.getTpId().getValue());
126 if (this.availableSrgPp.isEmpty() || this.availableSrgCp.isEmpty()) {
127 LOG.error("initSrgTpList: ROADM SRG TerminationPoint list is empty for node {}", this);
131 LOG.info("initSrgTpList: availableSrgPp size = {} && availableSrgCp size = {} in {}",
132 this.availableSrgPp.size(), this.availableSrgCp.size(), this);
135 public void initWLlist() {
136 this.availableWLindex.clear();
140 Node1 node1 = this.node.augmentation(Node1.class);
143 switch (this.nodeType) {
145 if (!node1.getSrgAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
146 LOG.error("initWLlist: SRG no cband available freq maps for node {}", this);
150 freqMap = node1.getSrgAttributes().nonnullAvailFreqMaps().get(freqMapKey).getFreqMap();
151 updateAvailableWlIndex(freqMap);
154 if (!node1.getDegreeAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
155 LOG.error("initWLlist: DEG no cband available freq maps for node {}", this);
159 freqMap = node1.getDegreeAttributes().nonnullAvailFreqMaps().get(freqMapKey).getFreqMap();
160 updateAvailableWlIndex(freqMap);
164 for (long i = 1; i <= FixedGridConstant.NB_CHANNELS; i++) {
165 this.availableWLindex.add(i);
169 LOG.error("initWLlist: unsupported node type {} in node {}", this.nodeType, this);
172 if (this.availableWLindex.isEmpty()) {
173 LOG.debug("initWLlist: There are no available wavelengths in node {}", this);
176 LOG.debug("initWLlist: availableWLindex size = {} in {}", this.availableWLindex.size(), this);
179 public void initXndrTps() {
180 LOG.info("PceNod: initXndrTps for node : {}", this.nodeId);
184 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
185 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
186 .ietf.network.topology.rev180226.Node1.class);
187 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
188 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
189 if (allTps.isEmpty()) {
191 LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this);
195 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
196 .node.TerminationPoint tp : allTps) {
197 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
198 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.TerminationPoint1 nttp1 = tp
199 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529
200 .TerminationPoint1.class);
201 if (cntp1.getTpType() == OpenroadmTpType.XPONDERNETWORK) {
202 if (nttp1 != null && nttp1.getXpdrNetworkAttributes().getWavelength() != null) {
203 this.usedXpndrNWTps.add(tp.getTpId().getValue());
204 LOG.info("initXndrTps: XPONDER tp = {} is used", tp.getTpId().getValue());
208 // find Client of this network TP
210 org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.TerminationPoint1 tpceTp1 =
211 tp.augmentation(org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019
212 .TerminationPoint1.class);
213 if (tpceTp1 != null) {
214 client = tpceTp1.getAssociatedConnectionMapPort();
215 if (client != null) {
216 this.clientPerNwTp.put(tp.getTpId().getValue(), client);
219 LOG.error("initXndrTps: XPONDER {} NW TP doesn't have defined Client {}",
220 this, tp.getTpId().getValue());
222 } else if (ServiceFormat.OTU.equals(this.serviceFormat)) {
223 LOG.info("Infrastructure OTU4 connection");
226 LOG.error("Service Format {} not managed yet", this.serviceFormat.getName());
231 LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node {}", this);
236 public String getRdmSrgClient(String tp) {
237 LOG.info("getRdmSrgClient: Getting PP client for tp '{}' on node : {}", tp, this.nodeId);
238 OpenroadmTpType srgType = null;
239 OpenroadmTpType cpType = this.availableSrgCp.get(tp);
240 if (cpType == null) {
241 LOG.error("getRdmSrgClient: tp {} not existed in SRG CPterminationPoint list", tp);
246 LOG.info("getRdmSrgClient: Getting BI Directional PP port ...");
247 srgType = OpenroadmTpType.SRGTXRXPP;
250 LOG.info("getRdmSrgClient: Getting UNI Rx PP port ...");
251 srgType = OpenroadmTpType.SRGRXPP;
254 LOG.info("getRdmSrgClient: Getting UNI Tx PP port ...");
255 srgType = OpenroadmTpType.SRGTXPP;
260 LOG.info("getRdmSrgClient: Getting client PP for CP '{}'", tp);
261 if (!this.availableSrgPp.isEmpty()) {
262 Optional<String> client = null;
263 final OpenroadmTpType openType = srgType;
264 client = this.availableSrgPp.entrySet()
265 .stream().filter(pp -> pp.getValue().getName().equals(openType.getName()))
266 .map(Map.Entry::getKey)
267 .sorted(new SortPortsByName())
269 if (!client.isPresent()) {
270 LOG.error("getRdmSrgClient: ROADM {} doesn't have PP Client for CP {}", this, tp);
273 LOG.info("getRdmSrgClient: client PP {} for CP {} found !", client, tp);
276 LOG.error("getRdmSrgClient: SRG TerminationPoint PP list is not available for node {}", this);
282 public void validateAZxponder(String anodeId, String znodeId) {
286 if (this.nodeType != OpenroadmNodeType.XPONDER) {
290 if (this.getSupNetworkNodeId().equals(anodeId) || (this.getSupNetworkNodeId().equals(znodeId))) {
291 LOG.info("validateAZxponder: A or Z node detected == {}", nodeId.getValue());
295 LOG.debug("validateAZxponder: XPONDER is ignored == {}", nodeId.getValue());
300 public boolean checkTP(String tp) {
301 return !this.usedXpndrNWTps.contains(tp);
305 public boolean checkWL(long index) {
306 return (this.availableWLindex.contains(index));
309 public boolean isValid() {
310 if (node == null || nodeId == null || nodeType == null || this.getSupNetworkNodeId() == null
311 || this.getSupClliNodeId() == null) {
312 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, supporting nodeId");
319 public List<PceLink> getOutgoingLinks() {
320 return outgoingLinks;
324 public NodeId getNodeId() {
329 public String toString() {
330 return "PceNode type=" + nodeType + " ID=" + nodeId.getValue() + " CLLI=" + this.getSupClliNodeId();
334 public String getPceNodeType() {
335 return this.pceNodeType;
339 public String getSupNetworkNodeId() {
340 return MapUtils.getSupNetworkNode(this.node);
344 public String getSupClliNodeId() {
345 return MapUtils.getSupClliNode(this.node);
349 public void addOutgoingLink(PceLink outLink) {
350 this.outgoingLinks.add(outLink);
354 public String getXpdrClient(String tp) {
355 return this.clientPerNwTp.get(tp);
359 public Map<String, List<Uint16>> getAvailableTribPorts() {
364 public Map<String, List<Uint16>> getAvailableTribSlots() {
369 * Get available wave length from frequency map array.
370 * @param freqMap byte[]
372 private void updateAvailableWlIndex(byte[] freqMap) {
373 if (freqMap == null) {
374 LOG.warn("No frequency map for node {}", node);
379 for (int i = 0; i < freqMap.length; i++) {
380 if (freqMap[i] == (byte)GridConstant.AVAILABLE_SLOT_VALUE) {
381 LOG.debug("Adding channel {} to available wave length index",wlIndex);
382 this.availableWLindex.add(wlIndex);