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);
49 public PceOpticalNode(Node node, OpenroadmNodeType nodeType) {
50 if (node != null && node.getNodeId() != null && nodeType != null) {
52 this.nodeId = node.getNodeId();
53 this.nodeType = nodeType;
55 LOG.error("PceNode: one of parameters is not populated : nodeId, node type");
60 public void initSrgTps() {
61 this.availableSrgPp.clear();
62 this.availableSrgCp.clear();
66 LOG.info("initSrgTpList: getting SRG tps from ROADM node {}", this.nodeId);
67 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
68 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
69 .ietf.network.topology.rev180226.Node1.class);
70 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
71 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
72 if (allTps.isEmpty()) {
73 LOG.error("initSrgTpList: ROADM TerminationPoint list is empty for node {}", this);
77 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
78 .node.TerminationPoint tp : allTps) {
79 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
80 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.TerminationPoint1 nttp1 = tp
81 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529
82 .TerminationPoint1.class);
83 OpenroadmTpType type = cntp1.getTpType();
84 LOG.info("type = {} for tp {}", type.getName(), tp);
90 LOG.info("initSrgTpList: adding SRG-CP tp = {} ", tp.getTpId().getValue());
91 this.availableSrgCp.put(tp.getTpId().getValue(), cntp1.getTpType());
96 LOG.info("initSrgTpList: SRG-PP tp = {} found", tp.getTpId().getValue());
97 if (nttp1 == null || nttp1.getPpAttributes() == null
98 || nttp1.getPpAttributes().getUsedWavelength() == null
99 || nttp1.getPpAttributes().getUsedWavelength().values().isEmpty()) {
100 LOG.info("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
101 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
103 LOG.warn("initSrgTpList: SRG-PP tp = {} found is busy !!", tp.getTpId().getValue());
110 if (this.availableSrgPp.isEmpty() || this.availableSrgCp.isEmpty()) {
111 LOG.error("initSrgTpList: ROADM SRG TerminationPoint list is empty for node {}", this);
115 LOG.info("initSrgTpList: availableSrgPp size = {} && availableSrgCp size = {} in {}",
116 this.availableSrgPp.size(), this.availableSrgCp.size(), this);
119 public void initWLlist() {
120 this.availableWLindex.clear();
124 Node1 node1 = this.node.augmentation(Node1.class);
127 switch (this.nodeType) {
129 if (!node1.getSrgAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
130 LOG.error("initWLlist: SRG no cband available freq maps for node {}", this);
134 freqMap = node1.getSrgAttributes().nonnullAvailFreqMaps().get(freqMapKey).getFreqMap();
135 updateAvailableWlIndex(freqMap);
138 if (!node1.getDegreeAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
139 LOG.error("initWLlist: DEG no cband available freq maps for node {}", this);
143 freqMap = node1.getDegreeAttributes().nonnullAvailFreqMaps().get(freqMapKey).getFreqMap();
144 updateAvailableWlIndex(freqMap);
148 for (long i = 1; i <= GridConstant.NB_OCTECTS; i++) {
149 this.availableWLindex.add(i);
153 LOG.error("initWLlist: unsupported node type {} in node {}", this.nodeType, this);
156 if (this.availableWLindex.isEmpty()) {
157 LOG.debug("initWLlist: There are no available wavelengths in node {}", this);
160 LOG.debug("initWLlist: availableWLindex size = {} in {}", this.availableWLindex.size(), this);
163 public void initXndrTps(ServiceFormat serviceFormat) {
164 LOG.info("PceNod: initXndrTps for node : {}", this.nodeId);
168 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
169 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
170 .ietf.network.topology.rev180226.Node1.class);
171 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
172 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
173 if (allTps.isEmpty()) {
175 LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this);
179 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
180 .node.TerminationPoint tp : allTps) {
181 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
182 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.TerminationPoint1 nttp1 = tp
183 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529
184 .TerminationPoint1.class);
185 if (cntp1.getTpType() == OpenroadmTpType.XPONDERNETWORK) {
186 if (nttp1 != null && nttp1.getXpdrNetworkAttributes().getWavelength() != null) {
187 this.usedXpndrNWTps.add(tp.getTpId().getValue());
188 LOG.info("initXndrTps: XPONDER tp = {} is used", tp.getTpId().getValue());
192 // find Client of this network TP
194 org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.TerminationPoint1 tpceTp1 =
195 tp.augmentation(org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019
196 .TerminationPoint1.class);
197 if (tpceTp1 != null) {
198 client = tpceTp1.getAssociatedConnectionMapPort();
199 if (client != null) {
200 this.clientPerNwTp.put(tp.getTpId().getValue(), client);
203 LOG.error("initXndrTps: XPONDER {} NW TP doesn't have defined Client {}",
204 this, tp.getTpId().getValue());
206 } else if (ServiceFormat.OTU.equals(serviceFormat)) {
207 LOG.info("Infrastructure OTU4 connection");
210 LOG.error("Service Format {} not managed yet", serviceFormat.getName());
215 LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node {}", this);
220 public String getRdmSrgClient(String tp) {
221 LOG.info("getRdmSrgClient: Getting PP client for tp '{}' on node : {}", tp, this.nodeId);
222 OpenroadmTpType srgType = null;
223 OpenroadmTpType cpType = this.availableSrgCp.get(tp);
224 if (cpType == null) {
225 LOG.error("getRdmSrgClient: tp {} not existed in SRG CPterminationPoint list", tp);
230 LOG.info("getRdmSrgClient: Getting BI Directional PP port ...");
231 srgType = OpenroadmTpType.SRGTXRXPP;
234 LOG.info("getRdmSrgClient: Getting UNI Rx PP port ...");
235 srgType = OpenroadmTpType.SRGRXPP;
238 LOG.info("getRdmSrgClient: Getting UNI Tx PP port ...");
239 srgType = OpenroadmTpType.SRGTXPP;
244 LOG.info("getRdmSrgClient: Getting client PP for CP '{}'", tp);
245 if (!this.availableSrgPp.isEmpty()) {
246 Optional<String> client = null;
247 final OpenroadmTpType openType = srgType;
248 client = this.availableSrgPp.entrySet()
249 .stream().filter(pp -> pp.getValue().getName().equals(openType.getName()))
250 .map(Map.Entry::getKey)
251 .sorted(new SortPortsByName())
253 if (!client.isPresent()) {
254 LOG.error("getRdmSrgClient: ROADM {} doesn't have PP Client for CP {}", this, tp);
257 LOG.info("getRdmSrgClient: client PP {} for CP {} found !", client, tp);
260 LOG.error("getRdmSrgClient: SRG TerminationPoint PP list is not available for node {}", this);
266 public void validateAZxponder(String anodeId, String znodeId, ServiceFormat serviceFormat) {
270 if (this.nodeType != OpenroadmNodeType.XPONDER) {
274 if (this.getSupNetworkNodeId().equals(anodeId) || (this.getSupNetworkNodeId().equals(znodeId))) {
275 LOG.info("validateAZxponder: A or Z node detected == {}", nodeId.getValue());
276 initXndrTps(serviceFormat);
279 LOG.debug("validateAZxponder: XPONDER is ignored == {}", nodeId.getValue());
284 public boolean checkTP(String tp) {
285 return !this.usedXpndrNWTps.contains(tp);
289 public boolean checkWL(long index) {
290 return (this.availableWLindex.contains(index));
293 public boolean isValid() {
294 if (node == null || nodeId == null || nodeType == null || this.getSupNetworkNodeId() == null
295 || this.getSupClliNodeId() == null) {
296 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, supporting nodeId");
303 public List<PceLink> getOutgoingLinks() {
304 return outgoingLinks;
308 public NodeId getNodeId() {
313 public String toString() {
314 return "PceNode type=" + nodeType + " ID=" + nodeId.getValue() + " CLLI=" + this.getSupClliNodeId();
318 public String getPceNodeType() {
323 public String getSupNetworkNodeId() {
324 return MapUtils.getSupNetworkNode(this.node);
328 public String getSupClliNodeId() {
329 return MapUtils.getSupClliNode(this.node);
333 public void addOutgoingLink(PceLink outLink) {
334 this.outgoingLinks.add(outLink);
338 public String getXpdrClient(String tp) {
339 return this.clientPerNwTp.get(tp);
343 public Map<String, List<Uint16>> getAvailableTribPorts() {
348 public Map<String, List<Uint16>> getAvailableTribSlots() {
353 * Get available wave length from frequency map array.
354 * @param freqMap byte[]
356 private void updateAvailableWlIndex(byte[] freqMap) {
357 if (freqMap == null) {
358 LOG.warn("No frequency map for node {}", node);
363 for (int i = 0; i < freqMap.length; i++) {
364 if (freqMap[i] == (byte)GridConstant.AVAILABLE_SLOT_VALUE) {
365 LOG.debug("Adding channel {} to available wave length index",wlIndex);
366 this.availableWLindex.add(wlIndex);