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.math.BigDecimal;
12 import java.util.ArrayList;
13 import java.util.Arrays;
14 import java.util.BitSet;
15 import java.util.HashMap;
16 import java.util.List;
18 import java.util.Optional;
19 import java.util.TreeMap;
20 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
21 import org.opendaylight.transportpce.common.mapping.PortMapping;
22 import org.opendaylight.transportpce.pce.SortPortsByName;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.path.computation.reroute.request.input.Endpoints;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.Mapping;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.TerminationPoint1;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.Node1;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmNodeType;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmTpType;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.available.freq.map.AvailFreqMapsKey;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.IfOCH;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.IfOCHOTU4ODU4;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.IfOtsiOtsigroup;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.SupportedIfCapability;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev191129.ServiceFormat;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
39 import org.opendaylight.yangtools.yang.common.Uint16;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
43 public class PceOpticalNode implements PceNode {
44 private static final Logger LOG = LoggerFactory.getLogger(PceOpticalNode.class);
46 private boolean valid = true;
49 private NodeId nodeId;
50 private String deviceNodeId;
51 private OpenroadmNodeType nodeType;
52 private AdminStates adminStates;
54 private String serviceType;
55 private PortMapping portMapping;
57 private Map<String, OpenroadmTpType> availableSrgPp = new TreeMap<>();
58 private Map<String, OpenroadmTpType> availableSrgCp = new TreeMap<>();
59 private List<String> usedXpndrNWTps = new ArrayList<>();
60 private List<PceLink> outgoingLinks = new ArrayList<>();
61 private Map<String, String> clientPerNwTp = new HashMap<>();
62 private final AvailFreqMapsKey freqMapKey = new AvailFreqMapsKey(GridConstant.C_BAND);
63 private BitSet frequenciesBitSet;
64 private String version;
65 private BigDecimal slotWidthGranularity;
66 private BigDecimal centralFreqGranularity;
67 private Endpoints endpoints;
69 public PceOpticalNode(String deviceNodeId, String serviceType, PortMapping portMapping, Node node,
70 OpenroadmNodeType nodeType, String version, BigDecimal slotWidthGranularity,
71 BigDecimal centralFreqGranularity) {
73 if (deviceNodeId != null
74 && serviceType != null
75 && portMapping != null
77 && node.getNodeId() != null
80 && slotWidthGranularity != null) {
81 this.deviceNodeId = deviceNodeId;
82 this.serviceType = serviceType;
83 this.portMapping = portMapping;
85 this.nodeId = node.getNodeId();
86 this.nodeType = nodeType;
87 this.version = version;
88 this.slotWidthGranularity = slotWidthGranularity;
89 this.centralFreqGranularity = centralFreqGranularity;
90 this.adminStates = node.augmentation(org.opendaylight.yang.gen.v1.http
91 .org.openroadm.common.network.rev211210.Node1.class).getAdministrativeState();
92 this.state = node.augmentation(org.opendaylight.yang.gen.v1.http
93 .org.openroadm.common.network.rev211210.Node1.class).getOperationalState();
95 LOG.error("PceNode {} : one of parameters is not populated : nodeId, node type, slot width granularity",
101 public void initSrgTps() {
102 this.availableSrgPp.clear();
103 this.availableSrgCp.clear();
107 LOG.debug("initSrgTpList: getting SRG tps from ROADM node {}", this.nodeId);
108 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
109 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
110 .ietf.network.topology.rev180226.Node1.class);
111 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
112 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
113 if (allTps.isEmpty()) {
114 LOG.error("initSrgTpList: ROADM TerminationPoint list is empty for node {}", this);
118 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
119 .node.TerminationPoint tp : allTps) {
120 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
121 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.TerminationPoint1 nttp1 = tp
122 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210
123 .TerminationPoint1.class);
124 OpenroadmTpType type = cntp1.getTpType();
125 LOG.debug("type = {} for tp {}", type.getName(), tp);
131 if (State.InService.equals(cntp1.getOperationalState())) {
132 LOG.debug("initSrgTpList: adding SRG-CP tp = {} ", tp.getTpId().getValue());
133 this.availableSrgCp.put(tp.getTpId().getValue(), cntp1.getTpType());
139 LOG.debug("initSrgTpList: SRG-PP tp = {} found", tp.getTpId().getValue());
140 if (isTerminationPointAvailable(nttp1)) {
141 LOG.debug("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
142 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
143 if (State.InService.equals(cntp1.getOperationalState())) {
144 LOG.debug("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
145 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
148 LOG.warn("initSrgTpList: SRG-PP tp = {} found is busy !!", tp.getTpId().getValue());
155 if (this.availableSrgPp.isEmpty() || this.availableSrgCp.isEmpty()) {
156 LOG.error("initSrgTpList: ROADM SRG TerminationPoint list is empty for node {}", this);
160 LOG.debug("initSrgTpList: availableSrgPp size = {} && availableSrgCp size = {} in {}",
161 this.availableSrgPp.size(), this.availableSrgCp.size(), this);
164 private boolean isTerminationPointAvailable(
165 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.TerminationPoint1 nttp1) {
166 byte[] availableByteArray = new byte[GridConstant.NB_OCTECTS];
167 Arrays.fill(availableByteArray, (byte) GridConstant.AVAILABLE_SLOT_VALUE);
168 return nttp1 == null || nttp1.getPpAttributes() == null
169 || nttp1.getPpAttributes().getAvailFreqMaps() == null
170 || !nttp1.getPpAttributes().getAvailFreqMaps().containsKey(freqMapKey)
171 || nttp1.getPpAttributes().getAvailFreqMaps().get(freqMapKey).getFreqMap() == null
172 || Arrays.equals(nttp1.getPpAttributes().getAvailFreqMaps().get(freqMapKey).getFreqMap(),
176 private boolean isTpWithGoodCapabilities(
177 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node
178 .TerminationPoint tp) {
179 Mapping mapping = this.portMapping.getMapping(deviceNodeId, tp.getTpId().getValue());
180 if (mapping == null || mapping.getSupportedInterfaceCapability() == null) {
183 switch (this.serviceType) {
185 for (SupportedIfCapability ifCap : mapping.getSupportedInterfaceCapability()) {
186 if (ifCap.equals(IfOtsiOtsigroup.VALUE)) {
192 return mapping.getSupportedInterfaceCapability().contains(IfOCH.VALUE)
193 || mapping.getSupportedInterfaceCapability().contains(IfOCHOTU4ODU4.VALUE);
199 public void initFrequenciesBitSet() {
203 Node1 node1 = this.node.augmentation(Node1.class);
204 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Node1 node11 =
205 this.node.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Node1
207 switch (this.nodeType) {
209 if (!State.InService.equals(node11.getOperationalState())) {
211 LOG.error("initWLlist: SRG node {} is OOS/degraded", this);
214 if (!node1.getSrgAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
215 LOG.error("initFrequenciesBitSet: SRG no cband available freq maps for node {}", this);
219 this.frequenciesBitSet = BitSet.valueOf(node1.getSrgAttributes()
220 .nonnullAvailFreqMaps().get(freqMapKey).getFreqMap());
223 if (!State.InService.equals(node11.getOperationalState())) {
225 LOG.error("initWLlist: Degree node {} is OOS/degraded", this);
228 if (!node1.getDegreeAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
229 LOG.error("initFrequenciesBitSet: DEG no cband available freq maps for node {}", this);
233 this.frequenciesBitSet = BitSet.valueOf(node1.getDegreeAttributes()
234 .nonnullAvailFreqMaps().get(freqMapKey).getFreqMap());
237 // at init all bits are set to false (unavailable)
238 this.frequenciesBitSet = new BitSet(GridConstant.EFFECTIVE_BITS);
239 //set all bits to true (available)
240 this.frequenciesBitSet.set(0, GridConstant.EFFECTIVE_BITS);
241 if (!State.InService.equals(node11.getOperationalState())) {
243 LOG.error("initWLlist: XPDR node {} is OOS/degraded", this);
247 LOG.error("initFrequenciesBitSet: unsupported node type {} in node {}", this.nodeType, this);
252 public void initXndrTps(ServiceFormat serviceFormat) {
253 LOG.debug("PceNod: initXndrTps for node : {}", this.nodeId);
258 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
259 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
260 .ietf.network.topology.rev180226.Node1.class);
261 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
262 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
263 if (allTps.isEmpty()) {
264 LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this);
267 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
268 .node.TerminationPoint tp : allTps) {
269 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
271 LOG.error("initXndrTps: {} - {} has no tp type", this.nodeId, tp.getTpId().toString());
274 if (cntp1.getTpType() != OpenroadmTpType.XPONDERNETWORK) {
275 LOG.debug("initXndrTps: {} is not an Xponder network port", cntp1.getTpType().getName());
278 if (!isTpWithGoodCapabilities(tp)) {
279 LOG.warn("initXndrTps: {} network port has not correct if-capabilities", tp.getTpId().getValue());
282 if (!State.InService.equals(cntp1.getOperationalState())) {
283 LOG.warn("initXndrTps: XPONDER tp = {} is OOS/degraded", tp.getTpId().getValue());
286 if (endpoints == null
287 || (!endpoints.getAEndTp().equals(tp.getTpId().getValue())
288 && !endpoints.getZEndTp().equals(tp.getTpId().getValue()))) {
289 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.TerminationPoint1 nttp1 =
290 tp.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210
291 .TerminationPoint1.class);
292 if (nttp1 != null && nttp1.getXpdrNetworkAttributes().getWavelength() != null) {
293 this.usedXpndrNWTps.add(tp.getTpId().getValue());
294 LOG.debug("initXndrTps: XPONDER tp = {} is used", tp.getTpId().getValue());
298 // find Client of this network TP
299 if (cntp1.getAssociatedConnectionMapTp() != null) {
300 String client = cntp1.getAssociatedConnectionMapTp().iterator().next().getValue();
301 if (client != null) {
302 this.clientPerNwTp.put(tp.getTpId().getValue(), client);
305 LOG.error("Service Format {} not managed yet", serviceFormat.getName());
312 LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node {}", this);
317 public String getRdmSrgClient(String tp, String direction) {
318 LOG.debug("getRdmSrgClient: Getting PP client for tp '{}' on node : {}", tp, this.nodeId);
319 OpenroadmTpType srgType = null;
320 OpenroadmTpType cpType = this.availableSrgCp.get(tp);
321 if (cpType == null) {
322 LOG.error("getRdmSrgClient: tp {} not existed in SRG CPterminationPoint list", tp);
327 LOG.debug("getRdmSrgClient: Getting BI Directional PP port ...");
328 // Take the first-element in the available PP key set
329 if (availableSrgPp.entrySet().iterator().next().getKey()
330 // and check if the port is bidirectional
332 srgType = OpenroadmTpType.SRGTXRXPP;
333 } else if (direction.equalsIgnoreCase("aToz")) {
334 srgType = OpenroadmTpType.SRGRXPP;
336 srgType = OpenroadmTpType.SRGTXPP;
340 LOG.debug("getRdmSrgClient: Getting UNI Rx PP port ...");
341 srgType = OpenroadmTpType.SRGRXPP;
344 LOG.debug("getRdmSrgClient: Getting UNI Tx PP port ...");
345 srgType = OpenroadmTpType.SRGTXPP;
350 LOG.debug("getRdmSrgClient: Getting client PP for CP '{}'", tp);
351 if (this.availableSrgPp.isEmpty()) {
352 LOG.error("getRdmSrgClient: SRG TerminationPoint PP list is not available for node {}", this);
355 final OpenroadmTpType openType = srgType;
356 Optional<String> client = this.availableSrgPp.entrySet()
357 .stream().filter(pp -> pp.getValue().getName().equals(openType.getName()))
358 .map(Map.Entry::getKey).min(new SortPortsByName());
359 if (client.isEmpty()) {
360 LOG.error("getRdmSrgClient: ROADM {} doesn't have PP Client for CP {}", this, tp);
363 LOG.debug("getRdmSrgClient: client PP {} for CP {} found !", client, tp);
368 public void validateAZxponder(String anodeId, String znodeId, ServiceFormat serviceFormat) {
369 if (!isValid() || this.nodeType != OpenroadmNodeType.XPONDER) {
373 if (anodeId.contains(this.getSupNetworkNodeId()) || (znodeId.contains(this.getSupNetworkNodeId()))) {
374 LOG.info("validateAZxponder: A or Z node detected == {}", nodeId.getValue());
375 initXndrTps(serviceFormat);
378 LOG.debug("validateAZxponder: XPONDER is ignored == {}", nodeId.getValue());
383 public boolean checkTP(String tp) {
384 return !this.usedXpndrNWTps.contains(tp);
387 public boolean isValid() {
388 if (node == null || nodeId == null || nodeType == null || this.getSupNetworkNodeId() == null
389 || this.getSupClliNodeId() == null || adminStates == null || state == null) {
390 LOG.error("PceNode {}, nodeId {} NodeType {} : one of parameters is not populated : nodeId, node type,"
391 + " supporting nodeId, admin state, operational state", deviceNodeId, nodeId, nodeType);
398 public List<PceLink> getOutgoingLinks() {
399 return outgoingLinks;
403 public AdminStates getAdminStates() {
408 public State getState() {
413 public NodeId getNodeId() {
418 public String toString() {
419 return "PceNode type=" + nodeType + " ID=" + nodeId.getValue() + " CLLI=" + this.getSupClliNodeId();
423 public String getPceNodeType() {
428 public String getSupNetworkNodeId() {
429 return MapUtils.getSupNetworkNode(this.node);
433 public String getSupClliNodeId() {
434 return MapUtils.getSupClliNode(this.node);
438 public void addOutgoingLink(PceLink outLink) {
439 this.outgoingLinks.add(outLink);
443 public String getXpdrClient(String tp) {
444 return this.clientPerNwTp.get(tp);
448 public Map<String, List<Uint16>> getAvailableTribPorts() {
453 public Map<String, List<Uint16>> getAvailableTribSlots() {
460 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getBitSetData()
463 public BitSet getBitSetData() {
464 return this.frequenciesBitSet;
470 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getVersion()
473 public String getVersion() {
480 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getSlotWidthGranularity()
483 public BigDecimal getSlotWidthGranularity() {
484 return slotWidthGranularity;
490 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getCentralFreqGranularity()
493 public BigDecimal getCentralFreqGranularity() {
494 return centralFreqGranularity;
497 public void setEndpoints(Endpoints endpoints) {
498 this.endpoints = endpoints;