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");
100 public void initSrgTps() {
101 this.availableSrgPp.clear();
102 this.availableSrgCp.clear();
106 LOG.debug("initSrgTpList: getting SRG tps from ROADM node {}", this.nodeId);
107 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
108 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
109 .ietf.network.topology.rev180226.Node1.class);
110 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
111 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
112 if (allTps.isEmpty()) {
113 LOG.error("initSrgTpList: ROADM TerminationPoint list is empty for node {}", this);
117 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
118 .node.TerminationPoint tp : allTps) {
119 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
120 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.TerminationPoint1 nttp1 = tp
121 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210
122 .TerminationPoint1.class);
123 OpenroadmTpType type = cntp1.getTpType();
124 LOG.debug("type = {} for tp {}", type.getName(), tp);
130 if (State.InService.equals(cntp1.getOperationalState())) {
131 LOG.debug("initSrgTpList: adding SRG-CP tp = {} ", tp.getTpId().getValue());
132 this.availableSrgCp.put(tp.getTpId().getValue(), cntp1.getTpType());
138 LOG.debug("initSrgTpList: SRG-PP tp = {} found", tp.getTpId().getValue());
139 if (isTerminationPointAvailable(nttp1)) {
140 LOG.debug("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
141 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
142 if (State.InService.equals(cntp1.getOperationalState())) {
143 LOG.debug("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
144 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
147 LOG.warn("initSrgTpList: SRG-PP tp = {} found is busy !!", tp.getTpId().getValue());
154 if (this.availableSrgPp.isEmpty() || this.availableSrgCp.isEmpty()) {
155 LOG.error("initSrgTpList: ROADM SRG TerminationPoint list is empty for node {}", this);
159 LOG.debug("initSrgTpList: availableSrgPp size = {} && availableSrgCp size = {} in {}",
160 this.availableSrgPp.size(), this.availableSrgCp.size(), this);
163 private boolean isTerminationPointAvailable(
164 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.TerminationPoint1 nttp1) {
165 byte[] availableByteArray = new byte[GridConstant.NB_OCTECTS];
166 Arrays.fill(availableByteArray, (byte) GridConstant.AVAILABLE_SLOT_VALUE);
167 return nttp1 == null || nttp1.getPpAttributes() == null
168 || nttp1.getPpAttributes().getAvailFreqMaps() == null
169 || !nttp1.getPpAttributes().getAvailFreqMaps().containsKey(freqMapKey)
170 || nttp1.getPpAttributes().getAvailFreqMaps().get(freqMapKey).getFreqMap() == null
171 || Arrays.equals(nttp1.getPpAttributes().getAvailFreqMaps().get(freqMapKey).getFreqMap(),
175 private boolean isTpWithGoodCapabilities(
176 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node
177 .TerminationPoint tp) {
178 Mapping mapping = this.portMapping.getMapping(deviceNodeId, tp.getTpId().getValue());
179 if (mapping == null || mapping.getSupportedInterfaceCapability() == null) {
182 switch (this.serviceType) {
184 for (SupportedIfCapability ifCap : mapping.getSupportedInterfaceCapability()) {
185 if (ifCap.equals(IfOtsiOtsigroup.VALUE)) {
191 return mapping.getSupportedInterfaceCapability().contains(IfOCH.VALUE)
192 || mapping.getSupportedInterfaceCapability().contains(IfOCHOTU4ODU4.VALUE);
198 public void initFrequenciesBitSet() {
202 Node1 node1 = this.node.augmentation(Node1.class);
203 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Node1 node11 =
204 this.node.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Node1
206 switch (this.nodeType) {
208 if (!State.InService.equals(node11.getOperationalState())) {
210 LOG.error("initWLlist: SRG node {} is OOS/degraded", this);
213 if (!node1.getSrgAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
214 LOG.error("initFrequenciesBitSet: SRG no cband available freq maps for node {}", this);
218 this.frequenciesBitSet = BitSet.valueOf(node1.getSrgAttributes()
219 .nonnullAvailFreqMaps().get(freqMapKey).getFreqMap());
222 if (!State.InService.equals(node11.getOperationalState())) {
224 LOG.error("initWLlist: Degree node {} is OOS/degraded", this);
227 if (!node1.getDegreeAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
228 LOG.error("initFrequenciesBitSet: DEG no cband available freq maps for node {}", this);
232 this.frequenciesBitSet = BitSet.valueOf(node1.getDegreeAttributes()
233 .nonnullAvailFreqMaps().get(freqMapKey).getFreqMap());
236 // at init all bits are set to false (unavailable)
237 this.frequenciesBitSet = new BitSet(GridConstant.EFFECTIVE_BITS);
238 //set all bits to true (available)
239 this.frequenciesBitSet.set(0, GridConstant.EFFECTIVE_BITS);
240 if (!State.InService.equals(node11.getOperationalState())) {
242 LOG.error("initWLlist: XPDR node {} is OOS/degraded", this);
246 LOG.error("initFrequenciesBitSet: unsupported node type {} in node {}", this.nodeType, this);
251 public void initXndrTps(ServiceFormat serviceFormat) {
252 LOG.debug("PceNod: initXndrTps for node : {}", this.nodeId);
257 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
258 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
259 .ietf.network.topology.rev180226.Node1.class);
260 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
261 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
262 if (allTps.isEmpty()) {
263 LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this);
266 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
267 .node.TerminationPoint tp : allTps) {
268 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
269 if (cntp1.getTpType() != OpenroadmTpType.XPONDERNETWORK) {
270 LOG.debug("initXndrTps: {} is not an Xponder network port", cntp1.getTpType().getName());
273 if (!isTpWithGoodCapabilities(tp)) {
274 LOG.warn("initXndrTps: {} network port has not correct if-capabilities", tp.getTpId().getValue());
277 if (!State.InService.equals(cntp1.getOperationalState())) {
278 LOG.warn("initXndrTps: XPONDER tp = {} is OOS/degraded", tp.getTpId().getValue());
281 if (endpoints == null
282 || (!endpoints.getAEndTp().equals(tp.getTpId().getValue())
283 && !endpoints.getZEndTp().equals(tp.getTpId().getValue()))) {
284 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.TerminationPoint1 nttp1 =
285 tp.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210
286 .TerminationPoint1.class);
287 if (nttp1 != null && nttp1.getXpdrNetworkAttributes().getWavelength() != null) {
288 this.usedXpndrNWTps.add(tp.getTpId().getValue());
289 LOG.debug("initXndrTps: XPONDER tp = {} is used", tp.getTpId().getValue());
293 // find Client of this network TP
294 if (cntp1.getAssociatedConnectionMapTp() != null) {
295 String client = cntp1.getAssociatedConnectionMapTp().iterator().next().getValue();
296 if (client != null) {
297 this.clientPerNwTp.put(tp.getTpId().getValue(), client);
300 LOG.error("Service Format {} not managed yet", serviceFormat.getName());
307 LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node {}", this);
312 public String getRdmSrgClient(String tp, String direction) {
313 LOG.debug("getRdmSrgClient: Getting PP client for tp '{}' on node : {}", tp, this.nodeId);
314 OpenroadmTpType srgType = null;
315 OpenroadmTpType cpType = this.availableSrgCp.get(tp);
316 if (cpType == null) {
317 LOG.error("getRdmSrgClient: tp {} not existed in SRG CPterminationPoint list", tp);
322 LOG.debug("getRdmSrgClient: Getting BI Directional PP port ...");
323 // Take the first-element in the available PP key set
324 if (availableSrgPp.entrySet().iterator().next().getKey()
325 // and check if the port is bidirectional
327 srgType = OpenroadmTpType.SRGTXRXPP;
328 } else if (direction.equalsIgnoreCase("aToz")) {
329 srgType = OpenroadmTpType.SRGRXPP;
331 srgType = OpenroadmTpType.SRGTXPP;
335 LOG.debug("getRdmSrgClient: Getting UNI Rx PP port ...");
336 srgType = OpenroadmTpType.SRGRXPP;
339 LOG.debug("getRdmSrgClient: Getting UNI Tx PP port ...");
340 srgType = OpenroadmTpType.SRGTXPP;
345 LOG.debug("getRdmSrgClient: Getting client PP for CP '{}'", tp);
346 if (this.availableSrgPp.isEmpty()) {
347 LOG.error("getRdmSrgClient: SRG TerminationPoint PP list is not available for node {}", this);
350 final OpenroadmTpType openType = srgType;
351 Optional<String> client = this.availableSrgPp.entrySet()
352 .stream().filter(pp -> pp.getValue().getName().equals(openType.getName()))
353 .map(Map.Entry::getKey).min(new SortPortsByName());
354 if (client.isEmpty()) {
355 LOG.error("getRdmSrgClient: ROADM {} doesn't have PP Client for CP {}", this, tp);
358 LOG.debug("getRdmSrgClient: client PP {} for CP {} found !", client, tp);
363 public void validateAZxponder(String anodeId, String znodeId, ServiceFormat serviceFormat) {
364 if (!isValid() || this.nodeType != OpenroadmNodeType.XPONDER) {
368 if (anodeId.contains(this.getSupNetworkNodeId()) || (znodeId.contains(this.getSupNetworkNodeId()))) {
369 LOG.info("validateAZxponder: A or Z node detected == {}", nodeId.getValue());
370 initXndrTps(serviceFormat);
373 LOG.debug("validateAZxponder: XPONDER is ignored == {}", nodeId.getValue());
378 public boolean checkTP(String tp) {
379 return !this.usedXpndrNWTps.contains(tp);
382 public boolean isValid() {
383 if (node == null || nodeId == null || nodeType == null || this.getSupNetworkNodeId() == null
384 || this.getSupClliNodeId() == null || adminStates == null || state == null) {
385 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, supporting nodeId, "
386 + "admin state, operational state");
393 public List<PceLink> getOutgoingLinks() {
394 return outgoingLinks;
398 public AdminStates getAdminStates() {
403 public State getState() {
408 public NodeId getNodeId() {
413 public String toString() {
414 return "PceNode type=" + nodeType + " ID=" + nodeId.getValue() + " CLLI=" + this.getSupClliNodeId();
418 public String getPceNodeType() {
423 public String getSupNetworkNodeId() {
424 return MapUtils.getSupNetworkNode(this.node);
428 public String getSupClliNodeId() {
429 return MapUtils.getSupClliNode(this.node);
433 public void addOutgoingLink(PceLink outLink) {
434 this.outgoingLinks.add(outLink);
438 public String getXpdrClient(String tp) {
439 return this.clientPerNwTp.get(tp);
443 public Map<String, List<Uint16>> getAvailableTribPorts() {
448 public Map<String, List<Uint16>> getAvailableTribSlots() {
455 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getBitSetData()
458 public BitSet getBitSetData() {
459 return this.frequenciesBitSet;
465 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getVersion()
468 public String getVersion() {
475 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getSlotWidthGranularity()
478 public BigDecimal getSlotWidthGranularity() {
479 return slotWidthGranularity;
485 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getCentralFreqGranularity()
488 public BigDecimal getCentralFreqGranularity() {
489 return centralFreqGranularity;
492 public void setEndpoints(Endpoints endpoints) {
493 this.endpoints = endpoints;