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.rev220114.mapping.Mapping;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.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.rev200529.Node1;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmNodeType;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmTpType;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.available.freq.map.AvailFreqMapsKey;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.IfOCH;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.IfOCHOTU4ODU4;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.IfOtsiOtsigroup;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.ServiceFormat;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
37 import org.opendaylight.yangtools.yang.common.Uint16;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
41 public class PceOpticalNode implements PceNode {
42 private static final Logger LOG = LoggerFactory.getLogger(PceOpticalNode.class);
44 private boolean valid = true;
47 private NodeId nodeId;
48 private String deviceNodeId;
49 private OpenroadmNodeType nodeType;
50 private AdminStates adminStates;
52 private String serviceType;
53 private PortMapping portMapping;
55 private Map<String, OpenroadmTpType> availableSrgPp = new TreeMap<>();
56 private Map<String, OpenroadmTpType> availableSrgCp = new TreeMap<>();
57 private List<String> usedXpndrNWTps = new ArrayList<>();
58 private List<PceLink> outgoingLinks = new ArrayList<>();
59 private Map<String, String> clientPerNwTp = new HashMap<>();
60 private final AvailFreqMapsKey freqMapKey = new AvailFreqMapsKey(GridConstant.C_BAND);
61 private BitSet frequenciesBitSet;
62 private String version;
63 private BigDecimal slotWidthGranularity;
64 private BigDecimal centralFreqGranularity;
66 public PceOpticalNode(String deviceNodeId, String serviceType, PortMapping portMapping, Node node,
67 OpenroadmNodeType nodeType, String version, BigDecimal slotWidthGranularity,
68 BigDecimal centralFreqGranularity) {
70 if (deviceNodeId != null
71 && serviceType != null
72 && portMapping != null
74 && node.getNodeId() != null
77 && slotWidthGranularity != null) {
78 this.deviceNodeId = deviceNodeId;
79 this.serviceType = serviceType;
80 this.portMapping = portMapping;
82 this.nodeId = node.getNodeId();
83 this.nodeType = nodeType;
84 this.version = version;
85 this.slotWidthGranularity = slotWidthGranularity;
86 this.centralFreqGranularity = centralFreqGranularity;
87 this.adminStates = node.augmentation(org.opendaylight.yang.gen.v1.http
88 .org.openroadm.common.network.rev200529.Node1.class).getAdministrativeState();
89 this.state = node.augmentation(org.opendaylight.yang.gen.v1.http
90 .org.openroadm.common.network.rev200529.Node1.class).getOperationalState();
92 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, slot width granularity");
97 public void initSrgTps() {
98 this.availableSrgPp.clear();
99 this.availableSrgCp.clear();
103 LOG.info("initSrgTpList: getting SRG tps from ROADM node {}", this.nodeId);
104 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
105 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
106 .ietf.network.topology.rev180226.Node1.class);
107 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
108 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
109 if (allTps.isEmpty()) {
110 LOG.error("initSrgTpList: ROADM TerminationPoint list is empty for node {}", this);
114 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
115 .node.TerminationPoint tp : allTps) {
116 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
117 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.TerminationPoint1 nttp1 = tp
118 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529
119 .TerminationPoint1.class);
120 OpenroadmTpType type = cntp1.getTpType();
121 LOG.info("type = {} for tp {}", type.getName(), tp);
127 if (State.InService.equals(cntp1.getOperationalState())) {
128 LOG.info("initSrgTpList: adding SRG-CP tp = {} ", tp.getTpId().getValue());
129 this.availableSrgCp.put(tp.getTpId().getValue(), cntp1.getTpType());
135 LOG.info("initSrgTpList: SRG-PP tp = {} found", tp.getTpId().getValue());
136 if (isTerminationPointAvailable(nttp1)) {
137 LOG.info("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
138 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
139 if (State.InService.equals(cntp1.getOperationalState())) {
140 LOG.info("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
141 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
144 LOG.warn("initSrgTpList: SRG-PP tp = {} found is busy !!", tp.getTpId().getValue());
151 if (this.availableSrgPp.isEmpty() || this.availableSrgCp.isEmpty()) {
152 LOG.error("initSrgTpList: ROADM SRG TerminationPoint list is empty for node {}", this);
156 LOG.info("initSrgTpList: availableSrgPp size = {} && availableSrgCp size = {} in {}",
157 this.availableSrgPp.size(), this.availableSrgCp.size(), this);
160 private boolean isTerminationPointAvailable(
161 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.TerminationPoint1 nttp1) {
162 byte[] availableByteArray = new byte[GridConstant.NB_OCTECTS];
163 Arrays.fill(availableByteArray, (byte) GridConstant.AVAILABLE_SLOT_VALUE);
164 return nttp1 == null || nttp1.getPpAttributes() == null
165 || nttp1.getPpAttributes().getAvailFreqMaps() == null
166 || !nttp1.getPpAttributes().getAvailFreqMaps().containsKey(freqMapKey)
167 || nttp1.getPpAttributes().getAvailFreqMaps().get(freqMapKey).getFreqMap() == null
168 || Arrays.equals(nttp1.getPpAttributes().getAvailFreqMaps().get(freqMapKey).getFreqMap(),
172 private boolean isTpWithGoodCapabilities(
173 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node
174 .TerminationPoint tp) {
175 Mapping mapping = this.portMapping.getMapping(deviceNodeId, tp.getTpId().getValue());
176 if (mapping == null || mapping.getSupportedInterfaceCapability() == null) {
179 switch (this.serviceType) {
181 if (mapping.getSupportedInterfaceCapability().contains(IfOtsiOtsigroup.class)) {
187 if (mapping.getSupportedInterfaceCapability().contains(
188 org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev181019.IfOCH.class)
189 || mapping.getSupportedInterfaceCapability().contains(IfOCH.class)
190 || mapping.getSupportedInterfaceCapability().contains(IfOCHOTU4ODU4.class)) {
200 public void initFrequenciesBitSet() {
204 Node1 node1 = this.node.augmentation(Node1.class);
205 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Node1 node11 =
206 this.node.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Node1
208 switch (this.nodeType) {
210 if (!State.InService.equals(node11.getOperationalState())) {
212 LOG.error("initWLlist: SRG node {} is OOS/degraded", this);
215 if (!node1.getSrgAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
216 LOG.error("initFrequenciesBitSet: SRG no cband available freq maps for node {}", this);
220 this.frequenciesBitSet = BitSet.valueOf(node1.getSrgAttributes()
221 .nonnullAvailFreqMaps().get(freqMapKey).getFreqMap());
224 if (!State.InService.equals(node11.getOperationalState())) {
226 LOG.error("initWLlist: Degree node {} is OOS/degraded", this);
229 if (!node1.getDegreeAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
230 LOG.error("initFrequenciesBitSet: DEG no cband available freq maps for node {}", this);
234 this.frequenciesBitSet = BitSet.valueOf(node1.getDegreeAttributes()
235 .nonnullAvailFreqMaps().get(freqMapKey).getFreqMap());
238 // at init all bits are set to false (unavailable)
239 this.frequenciesBitSet = new BitSet(GridConstant.EFFECTIVE_BITS);
240 //set all bits to true (available)
241 this.frequenciesBitSet.set(0, GridConstant.EFFECTIVE_BITS);
242 if (!State.InService.equals(node11.getOperationalState())) {
244 LOG.error("initWLlist: XPDR node {} is OOS/degraded", this);
249 LOG.error("initFrequenciesBitSet: unsupported node type {} in node {}", this.nodeType, this);
254 public void initXndrTps(ServiceFormat serviceFormat) {
255 LOG.info("PceNod: initXndrTps for node : {}", this.nodeId);
259 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
260 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
261 .ietf.network.topology.rev180226.Node1.class);
262 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
263 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
264 if (allTps.isEmpty()) {
266 LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this);
270 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
271 .node.TerminationPoint tp : allTps) {
272 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
273 if (cntp1.getTpType() != OpenroadmTpType.XPONDERNETWORK) {
274 LOG.warn("initXndrTps: {} is not an Xponder network port", cntp1.getTpType().getName());
277 if (!isTpWithGoodCapabilities(tp)) {
278 LOG.warn("initXndrTps: {} network port has not correct if-capabilities", tp.getTpId().getValue());
281 if (!State.InService.equals(cntp1.getOperationalState())) {
282 LOG.warn("initXndrTps: XPONDER tp = {} is OOS/degraded", tp.getTpId().getValue());
286 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.TerminationPoint1 nttp1 = tp
287 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529
288 .TerminationPoint1.class);
289 if (nttp1 != null && nttp1.getXpdrNetworkAttributes().getWavelength() != null) {
290 this.usedXpndrNWTps.add(tp.getTpId().getValue());
291 LOG.info("initXndrTps: XPONDER tp = {} is used", tp.getTpId().getValue());
295 // find Client of this network TP
297 org.opendaylight.yang.gen.v1.http.transportpce.topology.rev220123.TerminationPoint1 tpceTp1 =
298 tp.augmentation(org.opendaylight.yang.gen.v1.http.transportpce.topology.rev220123
299 .TerminationPoint1.class);
300 if (tpceTp1 != null) {
301 client = tpceTp1.getAssociatedConnectionMapPort();
302 if (client != null) {
303 this.clientPerNwTp.put(tp.getTpId().getValue(), client);
306 LOG.error("Service Format {} not managed yet", serviceFormat.getName());
311 LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node {}", this);
316 public String getRdmSrgClient(String tp, String direction) {
317 LOG.info("getRdmSrgClient: Getting PP client for tp '{}' on node : {}", tp, this.nodeId);
318 OpenroadmTpType srgType = null;
319 OpenroadmTpType cpType = this.availableSrgCp.get(tp);
320 if (cpType == null) {
321 LOG.error("getRdmSrgClient: tp {} not existed in SRG CPterminationPoint list", tp);
326 LOG.info("getRdmSrgClient: Getting BI Directional PP port ...");
327 // Take the first-element in the available PP key set
328 if (availableSrgPp.entrySet().iterator().next().getKey()
329 // and check if the port is bidirectional
331 srgType = OpenroadmTpType.SRGTXRXPP;
332 } else if (direction.equalsIgnoreCase("aToz")) {
333 srgType = OpenroadmTpType.SRGRXPP;
335 srgType = OpenroadmTpType.SRGTXPP;
339 LOG.info("getRdmSrgClient: Getting UNI Rx PP port ...");
340 srgType = OpenroadmTpType.SRGRXPP;
343 LOG.info("getRdmSrgClient: Getting UNI Tx PP port ...");
344 srgType = OpenroadmTpType.SRGTXPP;
349 LOG.info("getRdmSrgClient: Getting client PP for CP '{}'", tp);
350 if (!this.availableSrgPp.isEmpty()) {
351 Optional<String> client = null;
352 final OpenroadmTpType openType = srgType;
353 client = this.availableSrgPp.entrySet()
354 .stream().filter(pp -> pp.getValue().getName().equals(openType.getName()))
355 .map(Map.Entry::getKey)
356 .sorted(new SortPortsByName())
358 if (!client.isPresent()) {
359 LOG.error("getRdmSrgClient: ROADM {} doesn't have PP Client for CP {}", this, tp);
362 LOG.info("getRdmSrgClient: client PP {} for CP {} found !", client, tp);
365 LOG.error("getRdmSrgClient: SRG TerminationPoint PP list is not available for node {}", this);
371 public void validateAZxponder(String anodeId, String znodeId, ServiceFormat serviceFormat) {
375 if (this.nodeType != OpenroadmNodeType.XPONDER) {
379 if (anodeId.contains(this.getSupNetworkNodeId()) || (znodeId.contains(this.getSupNetworkNodeId()))) {
380 LOG.info("validateAZxponder: A or Z node detected == {}", nodeId.getValue());
381 initXndrTps(serviceFormat);
384 LOG.debug("validateAZxponder: XPONDER is ignored == {}", nodeId.getValue());
389 public boolean checkTP(String tp) {
390 return !this.usedXpndrNWTps.contains(tp);
393 public boolean isValid() {
394 if (node == null || nodeId == null || nodeType == null || this.getSupNetworkNodeId() == null
395 || this.getSupClliNodeId() == null || adminStates == null || state == null) {
396 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, supporting nodeId, "
397 + "admin state, operational state");
404 public List<PceLink> getOutgoingLinks() {
405 return outgoingLinks;
409 public AdminStates getAdminStates() {
414 public State getState() {
419 public NodeId getNodeId() {
424 public String toString() {
425 return "PceNode type=" + nodeType + " ID=" + nodeId.getValue() + " CLLI=" + this.getSupClliNodeId();
429 public String getPceNodeType() {
434 public String getSupNetworkNodeId() {
435 return MapUtils.getSupNetworkNode(this.node);
439 public String getSupClliNodeId() {
440 return MapUtils.getSupClliNode(this.node);
444 public void addOutgoingLink(PceLink outLink) {
445 this.outgoingLinks.add(outLink);
449 public String getXpdrClient(String tp) {
450 return this.clientPerNwTp.get(tp);
454 public Map<String, List<Uint16>> getAvailableTribPorts() {
459 public Map<String, List<Uint16>> getAvailableTribSlots() {
466 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getBitSetData()
469 public BitSet getBitSetData() {
470 return this.frequenciesBitSet;
476 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getVersion()
479 public String getVersion() {
486 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getSlotWidthGranularity()
489 public BigDecimal getSlotWidthGranularity() {
490 return slotWidthGranularity;
496 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getCentralFreqGranularity()
499 public BigDecimal getCentralFreqGranularity() {
500 return centralFreqGranularity;