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.portmapping.rev220316.mapping.Mapping;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.TerminationPoint1;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.Node1;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmNodeType;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmTpType;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.available.freq.map.AvailFreqMapsKey;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.IfOCH;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.IfOCHOTU4ODU4;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.IfOtsiOtsigroup;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.SupportedIfCapability;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev191129.ServiceFormat;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
38 import org.opendaylight.yangtools.yang.common.Uint16;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
42 public class PceOpticalNode implements PceNode {
43 private static final Logger LOG = LoggerFactory.getLogger(PceOpticalNode.class);
45 private boolean valid = true;
48 private NodeId nodeId;
49 private String deviceNodeId;
50 private OpenroadmNodeType nodeType;
51 private AdminStates adminStates;
53 private String serviceType;
54 private PortMapping portMapping;
56 private Map<String, OpenroadmTpType> availableSrgPp = new TreeMap<>();
57 private Map<String, OpenroadmTpType> availableSrgCp = new TreeMap<>();
58 private List<String> usedXpndrNWTps = new ArrayList<>();
59 private List<PceLink> outgoingLinks = new ArrayList<>();
60 private Map<String, String> clientPerNwTp = new HashMap<>();
61 private final AvailFreqMapsKey freqMapKey = new AvailFreqMapsKey(GridConstant.C_BAND);
62 private BitSet frequenciesBitSet;
63 private String version;
64 private BigDecimal slotWidthGranularity;
65 private BigDecimal centralFreqGranularity;
67 public PceOpticalNode(String deviceNodeId, String serviceType, PortMapping portMapping, Node node,
68 OpenroadmNodeType nodeType, String version, BigDecimal slotWidthGranularity,
69 BigDecimal centralFreqGranularity) {
71 if (deviceNodeId != null
72 && serviceType != null
73 && portMapping != null
75 && node.getNodeId() != null
78 && slotWidthGranularity != null) {
79 this.deviceNodeId = deviceNodeId;
80 this.serviceType = serviceType;
81 this.portMapping = portMapping;
83 this.nodeId = node.getNodeId();
84 this.nodeType = nodeType;
85 this.version = version;
86 this.slotWidthGranularity = slotWidthGranularity;
87 this.centralFreqGranularity = centralFreqGranularity;
88 this.adminStates = node.augmentation(org.opendaylight.yang.gen.v1.http
89 .org.openroadm.common.network.rev211210.Node1.class).getAdministrativeState();
90 this.state = node.augmentation(org.opendaylight.yang.gen.v1.http
91 .org.openroadm.common.network.rev211210.Node1.class).getOperationalState();
93 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, slot width granularity");
98 public void initSrgTps() {
99 this.availableSrgPp.clear();
100 this.availableSrgCp.clear();
104 LOG.debug("initSrgTpList: getting SRG tps from ROADM node {}", this.nodeId);
105 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
106 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
107 .ietf.network.topology.rev180226.Node1.class);
108 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
109 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
110 if (allTps.isEmpty()) {
111 LOG.error("initSrgTpList: ROADM TerminationPoint list is empty for node {}", this);
115 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
116 .node.TerminationPoint tp : allTps) {
117 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
118 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.TerminationPoint1 nttp1 = tp
119 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210
120 .TerminationPoint1.class);
121 OpenroadmTpType type = cntp1.getTpType();
122 LOG.debug("type = {} for tp {}", type.getName(), tp);
128 if (State.InService.equals(cntp1.getOperationalState())) {
129 LOG.debug("initSrgTpList: adding SRG-CP tp = {} ", tp.getTpId().getValue());
130 this.availableSrgCp.put(tp.getTpId().getValue(), cntp1.getTpType());
136 LOG.debug("initSrgTpList: SRG-PP tp = {} found", tp.getTpId().getValue());
137 if (isTerminationPointAvailable(nttp1)) {
138 LOG.debug("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
139 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
140 if (State.InService.equals(cntp1.getOperationalState())) {
141 LOG.debug("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
142 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
145 LOG.warn("initSrgTpList: SRG-PP tp = {} found is busy !!", tp.getTpId().getValue());
152 if (this.availableSrgPp.isEmpty() || this.availableSrgCp.isEmpty()) {
153 LOG.error("initSrgTpList: ROADM SRG TerminationPoint list is empty for node {}", this);
157 LOG.debug("initSrgTpList: availableSrgPp size = {} && availableSrgCp size = {} in {}",
158 this.availableSrgPp.size(), this.availableSrgCp.size(), this);
161 private boolean isTerminationPointAvailable(
162 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.TerminationPoint1 nttp1) {
163 byte[] availableByteArray = new byte[GridConstant.NB_OCTECTS];
164 Arrays.fill(availableByteArray, (byte) GridConstant.AVAILABLE_SLOT_VALUE);
165 return nttp1 == null || nttp1.getPpAttributes() == null
166 || nttp1.getPpAttributes().getAvailFreqMaps() == null
167 || !nttp1.getPpAttributes().getAvailFreqMaps().containsKey(freqMapKey)
168 || nttp1.getPpAttributes().getAvailFreqMaps().get(freqMapKey).getFreqMap() == null
169 || Arrays.equals(nttp1.getPpAttributes().getAvailFreqMaps().get(freqMapKey).getFreqMap(),
173 private boolean isTpWithGoodCapabilities(
174 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node
175 .TerminationPoint tp) {
176 Mapping mapping = this.portMapping.getMapping(deviceNodeId, tp.getTpId().getValue());
177 if (mapping == null || mapping.getSupportedInterfaceCapability() == null) {
180 switch (this.serviceType) {
182 for (Class<? extends SupportedIfCapability> ifCap : mapping.getSupportedInterfaceCapability()) {
183 if (ifCap.equals(IfOtsiOtsigroup.class)) {
189 return mapping.getSupportedInterfaceCapability().contains(IfOCH.class)
190 || mapping.getSupportedInterfaceCapability().contains(IfOCHOTU4ODU4.class);
196 public void initFrequenciesBitSet() {
200 Node1 node1 = this.node.augmentation(Node1.class);
201 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Node1 node11 =
202 this.node.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Node1
204 switch (this.nodeType) {
206 if (!State.InService.equals(node11.getOperationalState())) {
208 LOG.error("initWLlist: SRG node {} is OOS/degraded", this);
211 if (!node1.getSrgAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
212 LOG.error("initFrequenciesBitSet: SRG no cband available freq maps for node {}", this);
216 this.frequenciesBitSet = BitSet.valueOf(node1.getSrgAttributes()
217 .nonnullAvailFreqMaps().get(freqMapKey).getFreqMap());
220 if (!State.InService.equals(node11.getOperationalState())) {
222 LOG.error("initWLlist: Degree node {} is OOS/degraded", this);
225 if (!node1.getDegreeAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
226 LOG.error("initFrequenciesBitSet: DEG no cband available freq maps for node {}", this);
230 this.frequenciesBitSet = BitSet.valueOf(node1.getDegreeAttributes()
231 .nonnullAvailFreqMaps().get(freqMapKey).getFreqMap());
234 // at init all bits are set to false (unavailable)
235 this.frequenciesBitSet = new BitSet(GridConstant.EFFECTIVE_BITS);
236 //set all bits to true (available)
237 this.frequenciesBitSet.set(0, GridConstant.EFFECTIVE_BITS);
238 if (!State.InService.equals(node11.getOperationalState())) {
240 LOG.error("initWLlist: XPDR node {} is OOS/degraded", this);
244 LOG.error("initFrequenciesBitSet: unsupported node type {} in node {}", this.nodeType, this);
249 public void initXndrTps(ServiceFormat serviceFormat) {
250 LOG.debug("PceNod: initXndrTps for node : {}", this.nodeId);
255 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
256 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
257 .ietf.network.topology.rev180226.Node1.class);
258 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
259 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
260 if (allTps.isEmpty()) {
261 LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this);
264 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
265 .node.TerminationPoint tp : allTps) {
266 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
267 if (cntp1.getTpType() != OpenroadmTpType.XPONDERNETWORK) {
268 LOG.debug("initXndrTps: {} is not an Xponder network port", cntp1.getTpType().getName());
271 if (!isTpWithGoodCapabilities(tp)) {
272 LOG.warn("initXndrTps: {} network port has not correct if-capabilities", tp.getTpId().getValue());
275 if (!State.InService.equals(cntp1.getOperationalState())) {
276 LOG.warn("initXndrTps: XPONDER tp = {} is OOS/degraded", tp.getTpId().getValue());
279 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.TerminationPoint1 nttp1 = tp
280 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210
281 .TerminationPoint1.class);
282 if (nttp1 != null && nttp1.getXpdrNetworkAttributes().getWavelength() != null) {
283 this.usedXpndrNWTps.add(tp.getTpId().getValue());
284 LOG.debug("initXndrTps: XPONDER tp = {} is used", tp.getTpId().getValue());
287 // find Client of this network TP
288 if (cntp1.getAssociatedConnectionMapTp() != null) {
289 String client = cntp1.getAssociatedConnectionMapTp().iterator().next().getValue();
290 if (client != null) {
291 this.clientPerNwTp.put(tp.getTpId().getValue(), client);
294 LOG.error("Service Format {} not managed yet", serviceFormat.getName());
301 LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node {}", this);
306 public String getRdmSrgClient(String tp, String direction) {
307 LOG.debug("getRdmSrgClient: Getting PP client for tp '{}' on node : {}", tp, this.nodeId);
308 OpenroadmTpType srgType = null;
309 OpenroadmTpType cpType = this.availableSrgCp.get(tp);
310 if (cpType == null) {
311 LOG.error("getRdmSrgClient: tp {} not existed in SRG CPterminationPoint list", tp);
316 LOG.debug("getRdmSrgClient: Getting BI Directional PP port ...");
317 // Take the first-element in the available PP key set
318 if (availableSrgPp.entrySet().iterator().next().getKey()
319 // and check if the port is bidirectional
321 srgType = OpenroadmTpType.SRGTXRXPP;
322 } else if (direction.equalsIgnoreCase("aToz")) {
323 srgType = OpenroadmTpType.SRGRXPP;
325 srgType = OpenroadmTpType.SRGTXPP;
329 LOG.debug("getRdmSrgClient: Getting UNI Rx PP port ...");
330 srgType = OpenroadmTpType.SRGRXPP;
333 LOG.debug("getRdmSrgClient: Getting UNI Tx PP port ...");
334 srgType = OpenroadmTpType.SRGTXPP;
339 LOG.debug("getRdmSrgClient: Getting client PP for CP '{}'", tp);
340 if (this.availableSrgPp.isEmpty()) {
341 LOG.error("getRdmSrgClient: SRG TerminationPoint PP list is not available for node {}", this);
344 final OpenroadmTpType openType = srgType;
345 Optional<String> client = this.availableSrgPp.entrySet()
346 .stream().filter(pp -> pp.getValue().getName().equals(openType.getName()))
347 .map(Map.Entry::getKey).min(new SortPortsByName());
348 if (client.isEmpty()) {
349 LOG.error("getRdmSrgClient: ROADM {} doesn't have PP Client for CP {}", this, tp);
352 LOG.debug("getRdmSrgClient: client PP {} for CP {} found !", client, tp);
357 public void validateAZxponder(String anodeId, String znodeId, ServiceFormat serviceFormat) {
358 if (!isValid() || this.nodeType != OpenroadmNodeType.XPONDER) {
362 if (anodeId.contains(this.getSupNetworkNodeId()) || (znodeId.contains(this.getSupNetworkNodeId()))) {
363 LOG.info("validateAZxponder: A or Z node detected == {}", nodeId.getValue());
364 initXndrTps(serviceFormat);
367 LOG.debug("validateAZxponder: XPONDER is ignored == {}", nodeId.getValue());
372 public boolean checkTP(String tp) {
373 return !this.usedXpndrNWTps.contains(tp);
376 public boolean isValid() {
377 if (node == null || nodeId == null || nodeType == null || this.getSupNetworkNodeId() == null
378 || this.getSupClliNodeId() == null || adminStates == null || state == null) {
379 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, supporting nodeId, "
380 + "admin state, operational state");
387 public List<PceLink> getOutgoingLinks() {
388 return outgoingLinks;
392 public AdminStates getAdminStates() {
397 public State getState() {
402 public NodeId getNodeId() {
407 public String toString() {
408 return "PceNode type=" + nodeType + " ID=" + nodeId.getValue() + " CLLI=" + this.getSupClliNodeId();
412 public String getPceNodeType() {
417 public String getSupNetworkNodeId() {
418 return MapUtils.getSupNetworkNode(this.node);
422 public String getSupClliNodeId() {
423 return MapUtils.getSupClliNode(this.node);
427 public void addOutgoingLink(PceLink outLink) {
428 this.outgoingLinks.add(outLink);
432 public String getXpdrClient(String tp) {
433 return this.clientPerNwTp.get(tp);
437 public Map<String, List<Uint16>> getAvailableTribPorts() {
442 public Map<String, List<Uint16>> getAvailableTribSlots() {
449 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getBitSetData()
452 public BitSet getBitSetData() {
453 return this.frequenciesBitSet;
459 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getVersion()
462 public String getVersion() {
469 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getSlotWidthGranularity()
472 public BigDecimal getSlotWidthGranularity() {
473 return slotWidthGranularity;
479 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getCentralFreqGranularity()
482 public BigDecimal getCentralFreqGranularity() {
483 return centralFreqGranularity;