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.StringConstants;
21 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
22 import org.opendaylight.transportpce.common.mapping.PortMapping;
23 import org.opendaylight.transportpce.pce.SortPortsByName;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev240205.path.computation.reroute.request.input.Endpoints;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.mapping.Mapping;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.TerminationPoint1;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.Node1;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.networks.network.node.termination.point.XpdrNetworkAttributes;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmNodeType;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmTpType;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.available.freq.map.AvailFreqMapsKey;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev230526.IfOCH;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev230526.IfOCHOTU4ODU4;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev230526.IfOtsiOtsigroup;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev230526.SupportedIfCapability;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev191129.ServiceFormat;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.xponder.rev230526.xpdr.mode.attributes.supported.operational.modes.OperationalMode;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.xponder.rev230526.xpdr.mode.attributes.supported.operational.modes.OperationalModeKey;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
43 import org.opendaylight.yangtools.yang.common.Uint16;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
47 public class PceOpticalNode implements PceNode {
48 private static final Logger LOG = LoggerFactory.getLogger(PceOpticalNode.class);
50 private boolean valid = true;
53 private NodeId nodeId;
54 private String deviceNodeId;
55 private OpenroadmNodeType nodeType;
56 private AdminStates adminStates;
58 private String serviceType;
59 private PortMapping portMapping;
61 private Map<String, OpenroadmTpType> availableSrgPp = new TreeMap<>();
62 private Map<String, OpenroadmTpType> availableSrgCp = new TreeMap<>();
63 private List<String> usedXpndrNWTps = new ArrayList<>();
64 private List<PceLink> outgoingLinks = new ArrayList<>();
65 private Map<String, String> clientPerNwTp = new HashMap<>();
66 private final AvailFreqMapsKey freqMapKey = new AvailFreqMapsKey(GridConstant.C_BAND);
67 private BitSet frequenciesBitSet;
68 private String version;
69 private BigDecimal slotWidthGranularity;
70 private BigDecimal centralFreqGranularity;
71 private Endpoints endpoints;
73 public PceOpticalNode(String deviceNodeId, String serviceType, PortMapping portMapping, Node node,
74 OpenroadmNodeType nodeType, String version, BigDecimal slotWidthGranularity,
75 BigDecimal centralFreqGranularity) {
77 if (deviceNodeId != null
78 && serviceType != null
79 && portMapping != null
81 && node.getNodeId() != null
84 && slotWidthGranularity != null) {
85 this.deviceNodeId = deviceNodeId;
86 this.serviceType = serviceType;
87 this.portMapping = portMapping;
89 this.nodeId = node.getNodeId();
90 this.nodeType = nodeType;
91 this.version = version;
92 this.slotWidthGranularity = slotWidthGranularity;
93 this.centralFreqGranularity = centralFreqGranularity;
94 this.adminStates = node.augmentation(org.opendaylight.yang.gen.v1.http
95 .org.openroadm.common.network.rev230526.Node1.class).getAdministrativeState();
96 this.state = node.augmentation(org.opendaylight.yang.gen.v1.http
97 .org.openroadm.common.network.rev230526.Node1.class).getOperationalState();
99 LOG.error("PceNode {} : one of parameters is not populated : nodeId, node type, slot width granularity",
105 public void initSrgTps() {
106 this.availableSrgPp.clear();
107 this.availableSrgCp.clear();
111 LOG.debug("initSrgTpList: getting SRG tps from ROADM node {}", this.nodeId);
112 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
113 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
114 .ietf.network.topology.rev180226.Node1.class);
115 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
116 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
117 if (allTps.isEmpty()) {
118 LOG.error("initSrgTpList: ROADM TerminationPoint list is empty for node {}", this);
122 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
123 .node.TerminationPoint tp : allTps) {
124 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
125 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.TerminationPoint1 nttp1 = tp
126 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526
127 .TerminationPoint1.class);
128 OpenroadmTpType type = cntp1.getTpType();
129 LOG.debug("type = {} for tp {}", type.getName(), tp);
135 if (State.InService.equals(cntp1.getOperationalState())) {
136 LOG.debug("initSrgTpList: adding SRG-CP tp = {} ", tp.getTpId().getValue());
137 this.availableSrgCp.put(tp.getTpId().getValue(), cntp1.getTpType());
143 LOG.debug("initSrgTpList: SRG-PP tp = {} found", tp.getTpId().getValue());
144 if (isTerminationPointAvailable(nttp1)) {
145 LOG.debug("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
146 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
147 if (State.InService.equals(cntp1.getOperationalState())) {
148 LOG.debug("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
149 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
152 LOG.warn("initSrgTpList: SRG-PP tp = {} found is busy !!", tp.getTpId().getValue());
159 if (this.availableSrgPp.isEmpty() || this.availableSrgCp.isEmpty()) {
160 LOG.error("initSrgTpList: ROADM SRG TerminationPoint list is empty for node {}", this);
164 LOG.debug("initSrgTpList: availableSrgPp size = {} && availableSrgCp size = {} in {}",
165 this.availableSrgPp.size(), this.availableSrgCp.size(), this);
168 private boolean isTerminationPointAvailable(
169 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.TerminationPoint1 nttp1) {
170 byte[] availableByteArray = new byte[GridConstant.NB_OCTECTS];
171 Arrays.fill(availableByteArray, (byte) GridConstant.AVAILABLE_SLOT_VALUE);
172 return nttp1 == null || nttp1.getPpAttributes() == null
173 || nttp1.getPpAttributes().getAvailFreqMaps() == null
174 || !nttp1.getPpAttributes().getAvailFreqMaps().containsKey(freqMapKey)
175 || nttp1.getPpAttributes().getAvailFreqMaps().get(freqMapKey).getFreqMap() == null
176 || Arrays.equals(nttp1.getPpAttributes().getAvailFreqMaps().get(freqMapKey).getFreqMap(),
180 private boolean isTpWithGoodCapabilities(
181 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node
182 .TerminationPoint tp) {
183 Mapping mapping = this.portMapping.getMapping(deviceNodeId, tp.getTpId().getValue());
184 if (mapping == null || mapping.getSupportedInterfaceCapability() == null) {
187 switch (this.serviceType) {
189 for (SupportedIfCapability ifCap : mapping.getSupportedInterfaceCapability()) {
190 if (ifCap.equals(IfOtsiOtsigroup.VALUE)) {
196 return mapping.getSupportedInterfaceCapability().contains(IfOCH.VALUE)
197 || mapping.getSupportedInterfaceCapability().contains(IfOCHOTU4ODU4.VALUE);
203 public void initFrequenciesBitSet() {
207 Node1 node1 = this.node.augmentation(Node1.class);
208 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.Node1 node11 =
209 this.node.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.Node1
211 switch (this.nodeType) {
213 if (!State.InService.equals(node11.getOperationalState())) {
215 LOG.error("initWLlist: SRG node {} is OOS/degraded", this);
218 if (!node1.getSrgAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
219 LOG.error("initFrequenciesBitSet: SRG no cband available freq maps for node {}", this);
223 this.frequenciesBitSet = BitSet.valueOf(node1.getSrgAttributes()
224 .nonnullAvailFreqMaps().get(freqMapKey).getFreqMap());
227 if (!State.InService.equals(node11.getOperationalState())) {
229 LOG.error("initWLlist: Degree node {} is OOS/degraded", this);
232 if (!node1.getDegreeAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
233 LOG.error("initFrequenciesBitSet: DEG no cband available freq maps for node {}", this);
237 this.frequenciesBitSet = BitSet.valueOf(node1.getDegreeAttributes()
238 .nonnullAvailFreqMaps().get(freqMapKey).getFreqMap());
241 // at init all bits are set to false (unavailable)
242 this.frequenciesBitSet = new BitSet(GridConstant.EFFECTIVE_BITS);
243 //set all bits to true (available)
244 this.frequenciesBitSet.set(0, GridConstant.EFFECTIVE_BITS);
245 if (!State.InService.equals(node11.getOperationalState())) {
247 LOG.error("initWLlist: XPDR node {} is OOS/degraded", this);
251 LOG.error("initFrequenciesBitSet: unsupported node type {} in node {}", this.nodeType, this);
256 public void initXndrTps(ServiceFormat serviceFormat) {
257 LOG.debug("PceNod: initXndrTps for node : {}", this.nodeId);
262 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
263 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
264 .ietf.network.topology.rev180226.Node1.class);
265 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
266 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
267 if (allTps.isEmpty()) {
268 LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this);
271 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
272 .node.TerminationPoint tp : allTps) {
273 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
275 LOG.error("initXndrTps: {} - {} has no tp type", this.nodeId, tp.getTpId().toString());
278 if (cntp1.getTpType() != OpenroadmTpType.XPONDERNETWORK) {
279 LOG.debug("initXndrTps: {} is not an Xponder network port", cntp1.getTpType().getName());
282 if (!isTpWithGoodCapabilities(tp)) {
283 LOG.warn("initXndrTps: {} network port has not correct if-capabilities", tp.getTpId().getValue());
286 if (!State.InService.equals(cntp1.getOperationalState())) {
287 LOG.warn("initXndrTps: XPONDER tp = {} is OOS/degraded", tp.getTpId().getValue());
290 if (endpoints == null
291 || (!endpoints.getAEndTp().equals(tp.getTpId().getValue())
292 && !endpoints.getZEndTp().equals(tp.getTpId().getValue()))) {
293 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.TerminationPoint1 nttp1 =
294 tp.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526
295 .TerminationPoint1.class);
296 if (nttp1 != null && nttp1.getXpdrNetworkAttributes().getWavelength() != null) {
297 this.usedXpndrNWTps.add(tp.getTpId().getValue());
298 LOG.debug("initXndrTps: XPONDER tp = {} is used", tp.getTpId().getValue());
302 // find Client of this network TP
303 if (cntp1.getAssociatedConnectionMapTp() != null) {
304 String client = cntp1.getAssociatedConnectionMapTp().iterator().next().getValue();
305 if (client != null) {
306 this.clientPerNwTp.put(tp.getTpId().getValue(), client);
309 LOG.error("Service Format {} not managed yet", serviceFormat.getName());
316 LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node {}", this);
321 public String getRdmSrgClient(String tp, String direction) {
322 LOG.debug("getRdmSrgClient: Getting PP client for tp '{}' on node : {}", tp, this.nodeId);
323 OpenroadmTpType srgType = null;
324 OpenroadmTpType cpType = this.availableSrgCp.get(tp);
325 if (cpType == null) {
326 LOG.error("getRdmSrgClient: tp {} not existed in SRG CPterminationPoint list", tp);
331 LOG.debug("getRdmSrgClient: Getting BI Directional PP port ...");
332 // Take the first-element in the available PP key set
333 if (availableSrgPp.entrySet().iterator().next().getKey()
334 // and check if the port is bidirectional
336 srgType = OpenroadmTpType.SRGTXRXPP;
337 } else if (direction.equalsIgnoreCase("aToz")) {
338 srgType = OpenroadmTpType.SRGRXPP;
340 srgType = OpenroadmTpType.SRGTXPP;
344 LOG.debug("getRdmSrgClient: Getting UNI Rx PP port ...");
345 srgType = OpenroadmTpType.SRGRXPP;
348 LOG.debug("getRdmSrgClient: Getting UNI Tx PP port ...");
349 srgType = OpenroadmTpType.SRGTXPP;
354 LOG.debug("getRdmSrgClient: Getting client PP for CP '{}'", tp);
355 if (this.availableSrgPp.isEmpty()) {
356 LOG.error("getRdmSrgClient: SRG TerminationPoint PP list is not available for node {}", this);
359 final OpenroadmTpType openType = srgType;
360 Optional<String> client = this.availableSrgPp.entrySet()
361 .stream().filter(pp -> pp.getValue().getName().equals(openType.getName()))
362 .map(Map.Entry::getKey).min(new SortPortsByName());
363 if (client.isEmpty()) {
364 LOG.error("getRdmSrgClient: ROADM {} doesn't have PP Client for CP {}", this, tp);
367 LOG.debug("getRdmSrgClient: client PP {} for CP {} found !", client, tp);
368 return client.orElseThrow();
372 public String getOperationalMode() {
373 Node1 node1 = this.node.augmentation(Node1.class);
375 LOG.warn("No openroadm node available for node {}", node);
378 switch (this.nodeType) {
380 if (node1.getSrgAttributes().getSupportedOperationalModes() == null
381 || node1.getSrgAttributes().getSupportedOperationalModes().stream().findFirst().isEmpty()) {
382 LOG.debug("getOperationalMode: SRG has no operational mode declared");
383 return StringConstants.UNKNOWN_MODE;
385 LOG.debug("getOperationalMode: SRG has operational mode declared {}",
386 node1.getSrgAttributes().getSupportedOperationalModes().stream().findFirst().toString());
387 return node1.getSrgAttributes().getSupportedOperationalModes().stream().findFirst().toString();
390 if (node1.getDegreeAttributes().getSupportedOperationalModes() == null
391 || node1.getDegreeAttributes().getSupportedOperationalModes().stream().findFirst().isEmpty()) {
392 LOG.debug("getOperationalMode: DEGREE has no operational mode declared");
393 return StringConstants.UNKNOWN_MODE;
395 LOG.debug("getOperationalMode: DEGREE has operational mode declared {}",
396 node1.getDegreeAttributes().getSupportedOperationalModes().stream().findFirst().toString());
397 return node1.getDegreeAttributes().getSupportedOperationalModes().stream().findFirst().toString();
400 LOG.debug("getOperationalMode: Did not succeed retrieving Operational Mode for the node");
406 public String getXponderOperationalMode(XpdrNetworkAttributes tp) {
407 if (tp.getSupportedOperationalModes() == null) {
408 LOG.warn("getOperationalMode: NetworkPort {} has no operational mode declared compatible with service type",
410 return StringConstants.UNKNOWN_MODE;
412 for (Map.Entry<OperationalModeKey, OperationalMode> mode : tp.getSupportedOperationalModes()
413 .getOperationalMode().entrySet()) {
414 if (mode.getKey().toString().contains(StringConstants.SERVICE_TYPE_RATE
415 .get(this.serviceType).toCanonicalString())) {
416 LOG.info("getOperationalMode: NetworkPort {} has {} operational mode declared", tp,
417 mode.getKey().toString());
418 return mode.getKey().toString();
421 LOG.warn("getOperationalMode: NetworkPort {} has no operational mode declared compatible with service type",
423 return StringConstants.UNKNOWN_MODE;
426 public void validateAZxponder(String anodeId, String znodeId, ServiceFormat serviceFormat) {
427 if (!isValid() || this.nodeType != OpenroadmNodeType.XPONDER) {
431 if (anodeId.contains(this.getSupNetworkNodeId()) || (znodeId.contains(this.getSupNetworkNodeId()))) {
432 LOG.info("validateAZxponder: A or Z node detected == {}", nodeId.getValue());
433 initXndrTps(serviceFormat);
436 LOG.debug("validateAZxponder: XPONDER == {} is ignored, supported by {} for aNodeId {} ", nodeId.getValue(),
437 this.getSupNetworkNodeId(), anodeId);
442 public boolean checkTP(String tp) {
443 return !this.usedXpndrNWTps.contains(tp);
446 public boolean isValid() {
447 if (node == null || nodeId == null || nodeType == null || this.getSupNetworkNodeId() == null
448 || this.getSupClliNodeId() == null || adminStates == null || state == null) {
449 LOG.error("PceNode {}, nodeId {} NodeType {} : one of parameters is not populated : nodeId, node type,"
450 + " supporting nodeId, admin state, operational state", deviceNodeId, nodeId, nodeType);
457 public List<PceLink> getOutgoingLinks() {
458 return outgoingLinks;
462 public AdminStates getAdminStates() {
467 public State getState() {
472 public NodeId getNodeId() {
477 public String toString() {
478 return "PceNode type=" + nodeType + " ID=" + nodeId.getValue() + " CLLI=" + this.getSupClliNodeId();
482 public String getPceNodeType() {
487 public String getSupNetworkNodeId() {
488 return MapUtils.getSupNetworkNode(this.node);
492 public String getSupClliNodeId() {
493 return MapUtils.getSupClliNode(this.node);
497 public void addOutgoingLink(PceLink outLink) {
498 this.outgoingLinks.add(outLink);
502 public String getXpdrClient(String tp) {
503 return this.clientPerNwTp.get(tp);
507 public Map<String, List<Uint16>> getAvailableTribPorts() {
512 public OpenroadmNodeType getORNodeType() {
513 return this.nodeType;
517 public Map<String, List<Uint16>> getAvailableTribSlots() {
524 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getBitSetData()
527 public BitSet getBitSetData() {
528 return this.frequenciesBitSet;
534 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getVersion()
537 public String getVersion() {
544 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getSlotWidthGranularity()
547 public BigDecimal getSlotWidthGranularity() {
548 return slotWidthGranularity;
554 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getCentralFreqGranularity()
557 public BigDecimal getCentralFreqGranularity() {
558 return centralFreqGranularity;
561 public void setEndpoints(Endpoints endpoints) {
562 this.endpoints = endpoints;