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.GridConstant;
18 import org.opendaylight.transportpce.pce.SortPortsByName;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.TerminationPoint1;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.Node1;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmNodeType;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmTpType;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.available.freq.map.AvailFreqMapsKey;
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(PceOpticalNode.class);
34 private boolean valid = true;
37 private NodeId nodeId;
38 private OpenroadmNodeType nodeType;
40 // wavelength calculation per node type
41 private List<Long> availableWLindex = new ArrayList<>();
42 private Map<String, OpenroadmTpType> availableSrgPp = new TreeMap<>();
43 private Map<String, OpenroadmTpType> availableSrgCp = new TreeMap<>();
44 private List<String> usedXpndrNWTps = new ArrayList<>();
45 private List<PceLink> outgoingLinks = new ArrayList<>();
46 private Map<String, String> clientPerNwTp = new HashMap<>();
47 private final AvailFreqMapsKey freqMapKey = new AvailFreqMapsKey(GridConstant.C_BAND);
48 private String version;
50 public PceOpticalNode(Node node, OpenroadmNodeType nodeType, String version) {
51 if (node != null && node.getNodeId() != null && nodeType != null && version != null) {
53 this.nodeId = node.getNodeId();
54 this.nodeType = nodeType;
55 this.version = version;
57 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, version");
62 public void initSrgTps() {
63 this.availableSrgPp.clear();
64 this.availableSrgCp.clear();
68 LOG.info("initSrgTpList: getting SRG tps from ROADM node {}", this.nodeId);
69 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
70 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
71 .ietf.network.topology.rev180226.Node1.class);
72 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
73 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
74 if (allTps.isEmpty()) {
75 LOG.error("initSrgTpList: ROADM TerminationPoint list is empty for node {}", this);
79 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
80 .node.TerminationPoint tp : allTps) {
81 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
82 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.TerminationPoint1 nttp1 = tp
83 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529
84 .TerminationPoint1.class);
85 OpenroadmTpType type = cntp1.getTpType();
86 LOG.info("type = {} for tp {}", type.getName(), tp);
92 LOG.info("initSrgTpList: adding SRG-CP tp = {} ", tp.getTpId().getValue());
93 this.availableSrgCp.put(tp.getTpId().getValue(), cntp1.getTpType());
98 LOG.info("initSrgTpList: SRG-PP tp = {} found", tp.getTpId().getValue());
99 if (nttp1 == null || nttp1.getPpAttributes() == null
100 || nttp1.getPpAttributes().getUsedWavelength() == null
101 || nttp1.getPpAttributes().getUsedWavelength().values().isEmpty()) {
102 LOG.info("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
103 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
105 LOG.warn("initSrgTpList: SRG-PP tp = {} found is busy !!", tp.getTpId().getValue());
112 if (this.availableSrgPp.isEmpty() || this.availableSrgCp.isEmpty()) {
113 LOG.error("initSrgTpList: ROADM SRG TerminationPoint list is empty for node {}", this);
117 LOG.info("initSrgTpList: availableSrgPp size = {} && availableSrgCp size = {} in {}",
118 this.availableSrgPp.size(), this.availableSrgCp.size(), this);
121 public void initWLlist() {
122 this.availableWLindex.clear();
126 Node1 node1 = this.node.augmentation(Node1.class);
129 switch (this.nodeType) {
131 if (!node1.getSrgAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
132 LOG.error("initWLlist: SRG no cband available freq maps for node {}", this);
136 freqMap = node1.getSrgAttributes().nonnullAvailFreqMaps().get(freqMapKey).getFreqMap();
137 updateAvailableWlIndex(freqMap);
140 if (!node1.getDegreeAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
141 LOG.error("initWLlist: DEG no cband available freq maps for node {}", this);
145 freqMap = node1.getDegreeAttributes().nonnullAvailFreqMaps().get(freqMapKey).getFreqMap();
146 updateAvailableWlIndex(freqMap);
150 for (long i = 1; i <= GridConstant.NB_OCTECTS; i++) {
151 this.availableWLindex.add(i);
155 LOG.error("initWLlist: unsupported node type {} in node {}", this.nodeType, this);
158 if (this.availableWLindex.isEmpty()) {
159 LOG.debug("initWLlist: There are no available wavelengths in node {}", this);
162 LOG.debug("initWLlist: availableWLindex size = {} in {}", this.availableWLindex.size(), this);
165 public void initXndrTps(ServiceFormat serviceFormat) {
166 LOG.info("PceNod: initXndrTps for node : {}", this.nodeId);
170 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
171 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
172 .ietf.network.topology.rev180226.Node1.class);
173 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
174 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
175 if (allTps.isEmpty()) {
177 LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this);
181 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
182 .node.TerminationPoint tp : allTps) {
183 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
184 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.TerminationPoint1 nttp1 = tp
185 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529
186 .TerminationPoint1.class);
187 if (cntp1.getTpType() == OpenroadmTpType.XPONDERNETWORK) {
188 if (nttp1 != null && nttp1.getXpdrNetworkAttributes().getWavelength() != null) {
189 this.usedXpndrNWTps.add(tp.getTpId().getValue());
190 LOG.info("initXndrTps: XPONDER tp = {} is used", tp.getTpId().getValue());
194 // find Client of this network TP
196 org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.TerminationPoint1 tpceTp1 =
197 tp.augmentation(org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019
198 .TerminationPoint1.class);
199 if (tpceTp1 != null) {
200 client = tpceTp1.getAssociatedConnectionMapPort();
201 if (client != null) {
202 this.clientPerNwTp.put(tp.getTpId().getValue(), client);
205 LOG.error("initXndrTps: XPONDER {} NW TP doesn't have defined Client {}",
206 this, tp.getTpId().getValue());
208 } else if (ServiceFormat.OTU.equals(serviceFormat)) {
209 LOG.info("Infrastructure OTU4 connection");
212 LOG.error("Service Format {} not managed yet", serviceFormat.getName());
217 LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node {}", this);
222 public String getRdmSrgClient(String tp) {
223 LOG.info("getRdmSrgClient: Getting PP client for tp '{}' on node : {}", tp, this.nodeId);
224 OpenroadmTpType srgType = null;
225 OpenroadmTpType cpType = this.availableSrgCp.get(tp);
226 if (cpType == null) {
227 LOG.error("getRdmSrgClient: tp {} not existed in SRG CPterminationPoint list", tp);
232 LOG.info("getRdmSrgClient: Getting BI Directional PP port ...");
233 srgType = OpenroadmTpType.SRGTXRXPP;
236 LOG.info("getRdmSrgClient: Getting UNI Rx PP port ...");
237 srgType = OpenroadmTpType.SRGRXPP;
240 LOG.info("getRdmSrgClient: Getting UNI Tx PP port ...");
241 srgType = OpenroadmTpType.SRGTXPP;
246 LOG.info("getRdmSrgClient: Getting client PP for CP '{}'", tp);
247 if (!this.availableSrgPp.isEmpty()) {
248 Optional<String> client = null;
249 final OpenroadmTpType openType = srgType;
250 client = this.availableSrgPp.entrySet()
251 .stream().filter(pp -> pp.getValue().getName().equals(openType.getName()))
252 .map(Map.Entry::getKey)
253 .sorted(new SortPortsByName())
255 if (!client.isPresent()) {
256 LOG.error("getRdmSrgClient: ROADM {} doesn't have PP Client for CP {}", this, tp);
259 LOG.info("getRdmSrgClient: client PP {} for CP {} found !", client, tp);
262 LOG.error("getRdmSrgClient: SRG TerminationPoint PP list is not available for node {}", this);
268 public void validateAZxponder(String anodeId, String znodeId, ServiceFormat serviceFormat) {
272 if (this.nodeType != OpenroadmNodeType.XPONDER) {
276 if (this.getSupNetworkNodeId().equals(anodeId) || (this.getSupNetworkNodeId().equals(znodeId))) {
277 LOG.info("validateAZxponder: A or Z node detected == {}", nodeId.getValue());
278 initXndrTps(serviceFormat);
281 LOG.debug("validateAZxponder: XPONDER is ignored == {}", nodeId.getValue());
286 public boolean checkTP(String tp) {
287 return !this.usedXpndrNWTps.contains(tp);
291 public boolean checkWL(long index) {
292 return (this.availableWLindex.contains(index));
295 public boolean isValid() {
296 if (node == null || nodeId == null || nodeType == null || this.getSupNetworkNodeId() == null
297 || this.getSupClliNodeId() == null) {
298 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, supporting nodeId");
305 public List<PceLink> getOutgoingLinks() {
306 return outgoingLinks;
310 public NodeId getNodeId() {
315 public String toString() {
316 return "PceNode type=" + nodeType + " ID=" + nodeId.getValue() + " CLLI=" + this.getSupClliNodeId();
320 public String getPceNodeType() {
325 public String getSupNetworkNodeId() {
326 return MapUtils.getSupNetworkNode(this.node);
330 public String getSupClliNodeId() {
331 return MapUtils.getSupClliNode(this.node);
335 public void addOutgoingLink(PceLink outLink) {
336 this.outgoingLinks.add(outLink);
340 public String getXpdrClient(String tp) {
341 return this.clientPerNwTp.get(tp);
345 public Map<String, List<Uint16>> getAvailableTribPorts() {
350 public Map<String, List<Uint16>> getAvailableTribSlots() {
355 * Get available wave length from frequency map array.
356 * @param freqMap byte[]
358 private void updateAvailableWlIndex(byte[] freqMap) {
359 if (freqMap == null) {
360 LOG.warn("No frequency map for node {}", node);
365 for (int i = 0; i < freqMap.length; i++) {
366 if (freqMap[i] == (byte)GridConstant.AVAILABLE_SLOT_VALUE) {
367 LOG.debug("Adding channel {} to available wave length index",wlIndex);
368 this.availableWLindex.add(wlIndex);
377 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getVersion()
380 public String getVersion() {