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.types.rev200529.OpenroadmNodeType;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmTpType;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.available.freq.map.AvailFreqMapsKey;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.ServiceFormat;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
28 import org.opendaylight.yangtools.yang.common.Uint16;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class PceOpticalNode implements PceNode {
33 private static final Logger LOG = LoggerFactory.getLogger(PceOpticalNode.class);
35 private boolean valid = true;
38 private NodeId nodeId;
39 private OpenroadmNodeType nodeType;
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<>();
48 private final AvailFreqMapsKey freqMapKey = new AvailFreqMapsKey(GridConstant.C_BAND);
50 public PceOpticalNode(Node node, OpenroadmNodeType nodeType) {
51 if (node != null && node.getNodeId() != null && nodeType != null) {
53 this.nodeId = node.getNodeId();
54 this.nodeType = nodeType;
56 LOG.error("PceNode: one of parameters is not populated : nodeId, node type");
61 public void initSrgTps() {
62 this.availableSrgPp.clear();
63 this.availableSrgCp.clear();
67 LOG.info("initSrgTpList: getting SRG tps from ROADM node {}", this.nodeId);
68 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
69 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
70 .ietf.network.topology.rev180226.Node1.class);
71 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
72 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
73 if (allTps.isEmpty()) {
74 LOG.error("initSrgTpList: ROADM TerminationPoint list is empty for node {}", this);
78 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
79 .node.TerminationPoint tp : allTps) {
80 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
81 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.TerminationPoint1 nttp1 = tp
82 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529
83 .TerminationPoint1.class);
84 OpenroadmTpType type = cntp1.getTpType();
85 LOG.info("type = {} for tp {}", type.getName(), tp);
91 LOG.info("initSrgTpList: adding SRG-CP tp = {} ", tp.getTpId().getValue());
92 this.availableSrgCp.put(tp.getTpId().getValue(), cntp1.getTpType());
97 LOG.info("initSrgTpList: SRG-PP tp = {} found", tp.getTpId().getValue());
98 if (nttp1 == null || nttp1.getPpAttributes() == null
99 || nttp1.getPpAttributes().getUsedWavelength() == null
100 || nttp1.getPpAttributes().getUsedWavelength().values().isEmpty()) {
101 LOG.info("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
102 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
104 LOG.warn("initSrgTpList: SRG-PP tp = {} found is busy !!", tp.getTpId().getValue());
111 if (this.availableSrgPp.isEmpty() || this.availableSrgCp.isEmpty()) {
112 LOG.error("initSrgTpList: ROADM SRG TerminationPoint list is empty for node {}", this);
116 LOG.info("initSrgTpList: availableSrgPp size = {} && availableSrgCp size = {} in {}",
117 this.availableSrgPp.size(), this.availableSrgCp.size(), this);
120 public void initWLlist() {
121 this.availableWLindex.clear();
125 Node1 node1 = this.node.augmentation(Node1.class);
128 switch (this.nodeType) {
130 if (!node1.getSrgAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
131 LOG.error("initWLlist: SRG no cband available freq maps for node {}", this);
135 freqMap = node1.getSrgAttributes().nonnullAvailFreqMaps().get(freqMapKey).getFreqMap();
136 updateAvailableWlIndex(freqMap);
139 if (!node1.getDegreeAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
140 LOG.error("initWLlist: DEG no cband available freq maps for node {}", this);
144 freqMap = node1.getDegreeAttributes().nonnullAvailFreqMaps().get(freqMapKey).getFreqMap();
145 updateAvailableWlIndex(freqMap);
149 for (long i = 1; i <= FixedGridConstant.NB_CHANNELS; i++) {
150 this.availableWLindex.add(i);
154 LOG.error("initWLlist: unsupported node type {} in node {}", this.nodeType, this);
157 if (this.availableWLindex.isEmpty()) {
158 LOG.debug("initWLlist: There are no available wavelengths in node {}", this);
161 LOG.debug("initWLlist: availableWLindex size = {} in {}", this.availableWLindex.size(), this);
164 public void initXndrTps(ServiceFormat serviceFormat) {
165 LOG.info("PceNod: initXndrTps for node : {}", this.nodeId);
169 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
170 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
171 .ietf.network.topology.rev180226.Node1.class);
172 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
173 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
174 if (allTps.isEmpty()) {
176 LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this);
180 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
181 .node.TerminationPoint tp : allTps) {
182 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
183 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.TerminationPoint1 nttp1 = tp
184 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529
185 .TerminationPoint1.class);
186 if (cntp1.getTpType() == OpenroadmTpType.XPONDERNETWORK) {
187 if (nttp1 != null && nttp1.getXpdrNetworkAttributes().getWavelength() != null) {
188 this.usedXpndrNWTps.add(tp.getTpId().getValue());
189 LOG.info("initXndrTps: XPONDER tp = {} is used", tp.getTpId().getValue());
193 // find Client of this network TP
195 org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.TerminationPoint1 tpceTp1 =
196 tp.augmentation(org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019
197 .TerminationPoint1.class);
198 if (tpceTp1 != null) {
199 client = tpceTp1.getAssociatedConnectionMapPort();
200 if (client != null) {
201 this.clientPerNwTp.put(tp.getTpId().getValue(), client);
204 LOG.error("initXndrTps: XPONDER {} NW TP doesn't have defined Client {}",
205 this, tp.getTpId().getValue());
207 } else if (ServiceFormat.OTU.equals(serviceFormat)) {
208 LOG.info("Infrastructure OTU4 connection");
211 LOG.error("Service Format {} not managed yet", serviceFormat.getName());
216 LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node {}", this);
221 public String getRdmSrgClient(String tp) {
222 LOG.info("getRdmSrgClient: Getting PP client for tp '{}' on node : {}", tp, this.nodeId);
223 OpenroadmTpType srgType = null;
224 OpenroadmTpType cpType = this.availableSrgCp.get(tp);
225 if (cpType == null) {
226 LOG.error("getRdmSrgClient: tp {} not existed in SRG CPterminationPoint list", tp);
231 LOG.info("getRdmSrgClient: Getting BI Directional PP port ...");
232 srgType = OpenroadmTpType.SRGTXRXPP;
235 LOG.info("getRdmSrgClient: Getting UNI Rx PP port ...");
236 srgType = OpenroadmTpType.SRGRXPP;
239 LOG.info("getRdmSrgClient: Getting UNI Tx PP port ...");
240 srgType = OpenroadmTpType.SRGTXPP;
245 LOG.info("getRdmSrgClient: Getting client PP for CP '{}'", tp);
246 if (!this.availableSrgPp.isEmpty()) {
247 Optional<String> client = null;
248 final OpenroadmTpType openType = srgType;
249 client = this.availableSrgPp.entrySet()
250 .stream().filter(pp -> pp.getValue().getName().equals(openType.getName()))
251 .map(Map.Entry::getKey)
252 .sorted(new SortPortsByName())
254 if (!client.isPresent()) {
255 LOG.error("getRdmSrgClient: ROADM {} doesn't have PP Client for CP {}", this, tp);
258 LOG.info("getRdmSrgClient: client PP {} for CP {} found !", client, tp);
261 LOG.error("getRdmSrgClient: SRG TerminationPoint PP list is not available for node {}", this);
267 public void validateAZxponder(String anodeId, String znodeId, ServiceFormat serviceFormat) {
271 if (this.nodeType != OpenroadmNodeType.XPONDER) {
275 if (this.getSupNetworkNodeId().equals(anodeId) || (this.getSupNetworkNodeId().equals(znodeId))) {
276 LOG.info("validateAZxponder: A or Z node detected == {}", nodeId.getValue());
277 initXndrTps(serviceFormat);
280 LOG.debug("validateAZxponder: XPONDER is ignored == {}", nodeId.getValue());
285 public boolean checkTP(String tp) {
286 return !this.usedXpndrNWTps.contains(tp);
290 public boolean checkWL(long index) {
291 return (this.availableWLindex.contains(index));
294 public boolean isValid() {
295 if (node == null || nodeId == null || nodeType == null || this.getSupNetworkNodeId() == null
296 || this.getSupClliNodeId() == null) {
297 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, supporting nodeId");
304 public List<PceLink> getOutgoingLinks() {
305 return outgoingLinks;
309 public NodeId getNodeId() {
314 public String toString() {
315 return "PceNode type=" + nodeType + " ID=" + nodeId.getValue() + " CLLI=" + this.getSupClliNodeId();
319 public String getPceNodeType() {
324 public String getSupNetworkNodeId() {
325 return MapUtils.getSupNetworkNode(this.node);
329 public String getSupClliNodeId() {
330 return MapUtils.getSupClliNode(this.node);
334 public void addOutgoingLink(PceLink outLink) {
335 this.outgoingLinks.add(outLink);
339 public String getXpdrClient(String tp) {
340 return this.clientPerNwTp.get(tp);
344 public Map<String, List<Uint16>> getAvailableTribPorts() {
349 public Map<String, List<Uint16>> getAvailableTribSlots() {
354 * Get available wave length from frequency map array.
355 * @param freqMap byte[]
357 private void updateAvailableWlIndex(byte[] freqMap) {
358 if (freqMap == null) {
359 LOG.warn("No frequency map for node {}", node);
364 for (int i = 0; i < freqMap.length; i++) {
365 if (freqMap[i] == (byte)GridConstant.AVAILABLE_SLOT_VALUE) {
366 LOG.debug("Adding channel {} to available wave length index",wlIndex);
367 this.availableWLindex.add(wlIndex);