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.transportpce.pce.networkanalyzer.port.Preference;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev240205.path.computation.reroute.request.input.Endpoints;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.mapping.Mapping;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.TerminationPoint1;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.Node1;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.networks.network.node.termination.point.XpdrNetworkAttributes;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmNodeType;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmTpType;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.available.freq.map.AvailFreqMapsKey;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev230526.IfOCH;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev230526.IfOCHOTU4ODU4;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev230526.IfOtsiOtsigroup;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev230526.SupportedIfCapability;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev191129.ServiceFormat;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.xponder.rev230526.xpdr.mode.attributes.supported.operational.modes.OperationalMode;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.xponder.rev230526.xpdr.mode.attributes.supported.operational.modes.OperationalModeKey;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
44 import org.opendaylight.yangtools.yang.common.Uint16;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
48 public class PceOpticalNode implements PceNode {
49 private static final Logger LOG = LoggerFactory.getLogger(PceOpticalNode.class);
51 private boolean valid = true;
54 private NodeId nodeId;
55 private String deviceNodeId;
56 private OpenroadmNodeType nodeType;
57 private AdminStates adminStates;
59 private String serviceType;
60 private PortMapping portMapping;
62 private Map<String, OpenroadmTpType> availableSrgPp = new TreeMap<>();
63 private Map<String, OpenroadmTpType> availableSrgCp = new TreeMap<>();
64 private List<String> usedXpndrNWTps = new ArrayList<>();
65 private List<PceLink> outgoingLinks = new ArrayList<>();
66 private Map<String, String> clientPerNwTp = new HashMap<>();
67 private final AvailFreqMapsKey freqMapKey = new AvailFreqMapsKey(GridConstant.C_BAND);
68 private BitSet frequenciesBitSet;
69 private String version;
70 private BigDecimal slotWidthGranularity;
71 private BigDecimal centralFreqGranularity;
72 private Endpoints endpoints;
74 public PceOpticalNode(String deviceNodeId, String serviceType, PortMapping portMapping, Node node,
75 OpenroadmNodeType nodeType, String version, BigDecimal slotWidthGranularity,
76 BigDecimal centralFreqGranularity) {
78 if (deviceNodeId != null
79 && serviceType != null
80 && portMapping != null
82 && node.getNodeId() != null
85 && slotWidthGranularity != null) {
86 this.deviceNodeId = deviceNodeId;
87 this.serviceType = serviceType;
88 this.portMapping = portMapping;
90 this.nodeId = node.getNodeId();
91 this.nodeType = nodeType;
92 this.version = version;
93 this.slotWidthGranularity = slotWidthGranularity;
94 this.centralFreqGranularity = centralFreqGranularity;
95 this.adminStates = node.augmentation(org.opendaylight.yang.gen.v1.http
96 .org.openroadm.common.network.rev230526.Node1.class).getAdministrativeState();
97 this.state = node.augmentation(org.opendaylight.yang.gen.v1.http
98 .org.openroadm.common.network.rev230526.Node1.class).getOperationalState();
100 LOG.error("PceNode {} : one of parameters is not populated : nodeId, node type, slot width granularity",
106 public void initSrgTps(Preference portPreference) {
107 this.availableSrgPp.clear();
108 this.availableSrgCp.clear();
112 LOG.debug("initSrgTpList: getting SRG tps from ROADM node {}", this.nodeId);
113 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
114 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
115 .ietf.network.topology.rev180226.Node1.class);
116 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
117 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
118 if (allTps.isEmpty()) {
119 LOG.error("initSrgTpList: ROADM TerminationPoint list is empty for node {}", this);
123 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
124 .node.TerminationPoint tp : allTps) {
125 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
126 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.TerminationPoint1 nttp1 = tp
127 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526
128 .TerminationPoint1.class);
129 OpenroadmTpType type = cntp1.getTpType();
130 LOG.debug("type = {} for tp {}", type.getName(), tp);
136 if (State.InService.equals(cntp1.getOperationalState())) {
137 LOG.debug("initSrgTpList: adding SRG-CP tp = {} ", tp.getTpId().getValue());
138 this.availableSrgCp.put(tp.getTpId().getValue(), cntp1.getTpType());
144 LOG.debug("initSrgTpList: SRG-PP tp = {} found", tp.getTpId().getValue());
145 if (!portPreference.isPreferredPort(nodeId.getValue(), tp.getTpId().getValue())) {
146 LOG.warn("initSrgTpList: SRG-PP tp = {} is rejected by the client", tp.getTpId().getValue());
149 if (isTerminationPointAvailable(nttp1)) {
150 LOG.debug("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
151 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
152 if (State.InService.equals(cntp1.getOperationalState())) {
153 LOG.debug("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
154 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
157 LOG.warn("initSrgTpList: SRG-PP tp = {} found is busy !!", tp.getTpId().getValue());
164 if (this.availableSrgPp.isEmpty() || this.availableSrgCp.isEmpty()) {
165 LOG.error("initSrgTpList: ROADM SRG TerminationPoint list is empty for node {}", this);
169 LOG.debug("initSrgTpList: availableSrgPp size = {} && availableSrgCp size = {} in {}",
170 this.availableSrgPp.size(), this.availableSrgCp.size(), this);
173 private boolean isTerminationPointAvailable(
174 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.TerminationPoint1 nttp1) {
175 byte[] availableByteArray = new byte[GridConstant.NB_OCTECTS];
176 Arrays.fill(availableByteArray, (byte) GridConstant.AVAILABLE_SLOT_VALUE);
177 return nttp1 == null || nttp1.getPpAttributes() == null
178 || nttp1.getPpAttributes().getAvailFreqMaps() == null
179 || !nttp1.getPpAttributes().getAvailFreqMaps().containsKey(freqMapKey)
180 || nttp1.getPpAttributes().getAvailFreqMaps().get(freqMapKey).getFreqMap() == null
181 || Arrays.equals(nttp1.getPpAttributes().getAvailFreqMaps().get(freqMapKey).getFreqMap(),
185 private boolean isTpWithGoodCapabilities(
186 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node
187 .TerminationPoint tp) {
188 Mapping mapping = this.portMapping.getMapping(deviceNodeId, tp.getTpId().getValue());
189 if (mapping == null || mapping.getSupportedInterfaceCapability() == null) {
192 switch (this.serviceType) {
194 for (SupportedIfCapability ifCap : mapping.getSupportedInterfaceCapability()) {
195 if (ifCap.equals(IfOtsiOtsigroup.VALUE)) {
201 return mapping.getSupportedInterfaceCapability().contains(IfOCH.VALUE)
202 || mapping.getSupportedInterfaceCapability().contains(IfOCHOTU4ODU4.VALUE);
208 public void initFrequenciesBitSet() {
212 Node1 node1 = this.node.augmentation(Node1.class);
213 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.Node1 node11 =
214 this.node.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.Node1
216 switch (this.nodeType) {
218 if (!State.InService.equals(node11.getOperationalState())) {
220 LOG.error("initWLlist: SRG node {} is OOS/degraded", this);
223 if (!node1.getSrgAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
224 LOG.error("initFrequenciesBitSet: SRG no cband available freq maps for node {}", this);
228 this.frequenciesBitSet = BitSet.valueOf(node1.getSrgAttributes()
229 .nonnullAvailFreqMaps().get(freqMapKey).getFreqMap());
232 if (!State.InService.equals(node11.getOperationalState())) {
234 LOG.error("initWLlist: Degree node {} is OOS/degraded", this);
237 if (!node1.getDegreeAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
238 LOG.error("initFrequenciesBitSet: DEG no cband available freq maps for node {}", this);
242 this.frequenciesBitSet = BitSet.valueOf(node1.getDegreeAttributes()
243 .nonnullAvailFreqMaps().get(freqMapKey).getFreqMap());
246 // at init all bits are set to false (unavailable)
247 this.frequenciesBitSet = new BitSet(GridConstant.EFFECTIVE_BITS);
248 //set all bits to true (available)
249 this.frequenciesBitSet.set(0, GridConstant.EFFECTIVE_BITS);
250 if (!State.InService.equals(node11.getOperationalState())) {
252 LOG.error("initWLlist: XPDR node {} is OOS/degraded", this);
256 LOG.error("initFrequenciesBitSet: unsupported node type {} in node {}", this.nodeType, this);
261 public void initXndrTps(ServiceFormat serviceFormat) {
262 LOG.debug("PceNod: initXndrTps for node : {}", this.nodeId);
267 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
268 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
269 .ietf.network.topology.rev180226.Node1.class);
270 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
271 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
272 if (allTps.isEmpty()) {
273 LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this);
276 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
277 .node.TerminationPoint tp : allTps) {
278 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
280 LOG.error("initXndrTps: {} - {} has no tp type", this.nodeId, tp.getTpId().toString());
283 if (cntp1.getTpType() != OpenroadmTpType.XPONDERNETWORK) {
284 LOG.debug("initXndrTps: {} is not an Xponder network port", cntp1.getTpType().getName());
287 if (!isTpWithGoodCapabilities(tp)) {
288 LOG.warn("initXndrTps: {} network port has not correct if-capabilities", tp.getTpId().getValue());
291 if (!State.InService.equals(cntp1.getOperationalState())) {
292 LOG.warn("initXndrTps: XPONDER tp = {} is OOS/degraded", tp.getTpId().getValue());
295 if (endpoints == null
296 || (!endpoints.getAEndTp().equals(tp.getTpId().getValue())
297 && !endpoints.getZEndTp().equals(tp.getTpId().getValue()))) {
298 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.TerminationPoint1 nttp1 =
299 tp.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526
300 .TerminationPoint1.class);
301 if (nttp1 != null && nttp1.getXpdrNetworkAttributes().getWavelength() != null) {
302 this.usedXpndrNWTps.add(tp.getTpId().getValue());
303 LOG.debug("initXndrTps: XPONDER tp = {} is used", tp.getTpId().getValue());
307 // find Client of this network TP
308 if (cntp1.getAssociatedConnectionMapTp() != null) {
309 String client = cntp1.getAssociatedConnectionMapTp().iterator().next().getValue();
310 if (client != null) {
311 this.clientPerNwTp.put(tp.getTpId().getValue(), client);
314 LOG.error("Service Format {} not managed yet", serviceFormat.getName());
321 LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node {}", this);
326 public String getRdmSrgClient(String tp, String direction) {
327 LOG.debug("getRdmSrgClient: Getting PP client for tp '{}' on node : {}", tp, this.nodeId);
328 OpenroadmTpType srgType = null;
329 OpenroadmTpType cpType = this.availableSrgCp.get(tp);
330 if (cpType == null) {
331 LOG.error("getRdmSrgClient: tp {} not existed in SRG CPterminationPoint list", tp);
336 LOG.debug("getRdmSrgClient: Getting BI Directional PP port ...");
337 // Take the first-element in the available PP key set
338 if (availableSrgPp.entrySet().iterator().next().getKey()
339 // and check if the port is bidirectional
341 srgType = OpenroadmTpType.SRGTXRXPP;
342 } else if (direction.equalsIgnoreCase("aToz")) {
343 srgType = OpenroadmTpType.SRGRXPP;
345 srgType = OpenroadmTpType.SRGTXPP;
349 LOG.debug("getRdmSrgClient: Getting UNI Rx PP port ...");
350 srgType = OpenroadmTpType.SRGRXPP;
353 LOG.debug("getRdmSrgClient: Getting UNI Tx PP port ...");
354 srgType = OpenroadmTpType.SRGTXPP;
359 LOG.debug("getRdmSrgClient: Getting client PP for CP '{}'", tp);
360 if (this.availableSrgPp.isEmpty()) {
361 LOG.error("getRdmSrgClient: SRG TerminationPoint PP list is not available for node {}", this);
364 final OpenroadmTpType openType = srgType;
365 Optional<String> client = this.availableSrgPp.entrySet()
366 .stream().filter(pp -> pp.getValue().getName().equals(openType.getName()))
367 .map(Map.Entry::getKey).min(new SortPortsByName());
368 if (client.isEmpty()) {
369 LOG.error("getRdmSrgClient: ROADM {} doesn't have PP Client for CP {}", this, tp);
372 LOG.debug("getRdmSrgClient: client PP {} for CP {} found !", client, tp);
373 return client.orElseThrow();
377 public String getOperationalMode() {
378 Node1 node1 = this.node.augmentation(Node1.class);
380 LOG.warn("No openroadm node available for node {}", node);
383 switch (this.nodeType) {
385 if (node1.getSrgAttributes().getSupportedOperationalModes() == null
386 || node1.getSrgAttributes().getSupportedOperationalModes().stream().findFirst().isEmpty()) {
387 LOG.debug("getOperationalMode: SRG has no operational mode declared");
388 return StringConstants.UNKNOWN_MODE;
390 LOG.debug("getOperationalMode: SRG has operational mode declared {}",
391 node1.getSrgAttributes().getSupportedOperationalModes().stream().findFirst().toString());
392 return node1.getSrgAttributes().getSupportedOperationalModes().stream().findFirst().toString();
395 if (node1.getDegreeAttributes().getSupportedOperationalModes() == null
396 || node1.getDegreeAttributes().getSupportedOperationalModes().stream().findFirst().isEmpty()) {
397 LOG.debug("getOperationalMode: DEGREE has no operational mode declared");
398 return StringConstants.UNKNOWN_MODE;
400 LOG.debug("getOperationalMode: DEGREE has operational mode declared {}",
401 node1.getDegreeAttributes().getSupportedOperationalModes().stream().findFirst().toString());
402 return node1.getDegreeAttributes().getSupportedOperationalModes().stream().findFirst().toString();
405 LOG.debug("getOperationalMode: Did not succeed retrieving Operational Mode for the node");
411 public String getXponderOperationalMode(XpdrNetworkAttributes tp) {
412 if (tp.getSupportedOperationalModes() == null) {
413 LOG.warn("getOperationalMode: NetworkPort {} has no operational mode declared compatible with service type",
415 return StringConstants.UNKNOWN_MODE;
417 for (Map.Entry<OperationalModeKey, OperationalMode> mode : tp.getSupportedOperationalModes()
418 .getOperationalMode().entrySet()) {
419 if (mode.getKey().toString().contains(StringConstants.SERVICE_TYPE_RATE
420 .get(this.serviceType).toCanonicalString())) {
421 LOG.info("getOperationalMode: NetworkPort {} has {} operational mode declared", tp,
422 mode.getKey().toString());
423 return mode.getKey().toString();
426 LOG.warn("getOperationalMode: NetworkPort {} has no operational mode declared compatible with service type",
428 return StringConstants.UNKNOWN_MODE;
431 public void validateAZxponder(String anodeId, String znodeId, ServiceFormat serviceFormat) {
432 if (!isValid() || this.nodeType != OpenroadmNodeType.XPONDER) {
436 if (anodeId.contains(this.getSupNetworkNodeId()) || (znodeId.contains(this.getSupNetworkNodeId()))) {
437 LOG.info("validateAZxponder: A or Z node detected == {}", nodeId.getValue());
438 initXndrTps(serviceFormat);
441 LOG.debug("validateAZxponder: XPONDER == {} is ignored, supported by {} for aNodeId {} ", nodeId.getValue(),
442 this.getSupNetworkNodeId(), anodeId);
447 public boolean checkTP(String tp) {
448 return !this.usedXpndrNWTps.contains(tp);
451 public boolean isValid() {
452 if (node == null || nodeId == null || nodeType == null || this.getSupNetworkNodeId() == null
453 || this.getSupClliNodeId() == null || adminStates == null || state == null) {
454 LOG.error("PceNode {}, nodeId {} NodeType {} : one of parameters is not populated : nodeId, node type,"
455 + " supporting nodeId, admin state, operational state", deviceNodeId, nodeId, nodeType);
462 public List<PceLink> getOutgoingLinks() {
463 return outgoingLinks;
467 public AdminStates getAdminStates() {
472 public State getState() {
477 public NodeId getNodeId() {
482 public String toString() {
483 return "PceNode type=" + nodeType + " ID=" + nodeId.getValue() + " CLLI=" + this.getSupClliNodeId();
487 public String getPceNodeType() {
492 public String getSupNetworkNodeId() {
493 return MapUtils.getSupNetworkNode(this.node);
497 public String getSupClliNodeId() {
498 return MapUtils.getSupClliNode(this.node);
502 public void addOutgoingLink(PceLink outLink) {
503 this.outgoingLinks.add(outLink);
507 public String getXpdrClient(String tp) {
508 return this.clientPerNwTp.get(tp);
512 public Map<String, List<Uint16>> getAvailableTribPorts() {
517 public OpenroadmNodeType getORNodeType() {
518 return this.nodeType;
522 public Map<String, List<Uint16>> getAvailableTribSlots() {
529 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getBitSetData()
532 public BitSet getBitSetData() {
533 return this.frequenciesBitSet;
539 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getVersion()
542 public String getVersion() {
549 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getSlotWidthGranularity()
552 public BigDecimal getSlotWidthGranularity() {
553 return slotWidthGranularity;
559 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getCentralFreqGranularity()
562 public BigDecimal getCentralFreqGranularity() {
563 return centralFreqGranularity;
566 public void setEndpoints(Endpoints endpoints) {
567 this.endpoints = endpoints;