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.pce.SortPortsByName;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.TerminationPoint1;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.Node1;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmNodeType;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmTpType;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.available.freq.map.AvailFreqMapsKey;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.ServiceFormat;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
32 import org.opendaylight.yangtools.yang.common.Uint16;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 public class PceOpticalNode implements PceNode {
37 private static final Logger LOG = LoggerFactory.getLogger(PceOpticalNode.class);
39 private boolean valid = true;
42 private NodeId nodeId;
43 private OpenroadmNodeType nodeType;
44 private AdminStates adminStates;
47 private Map<String, OpenroadmTpType> availableSrgPp = new TreeMap<>();
48 private Map<String, OpenroadmTpType> availableSrgCp = new TreeMap<>();
49 private List<String> usedXpndrNWTps = new ArrayList<>();
50 private List<PceLink> outgoingLinks = new ArrayList<>();
51 private Map<String, String> clientPerNwTp = new HashMap<>();
52 private final AvailFreqMapsKey freqMapKey = new AvailFreqMapsKey(GridConstant.C_BAND);
53 private BitSet frequenciesBitSet;
54 private String version;
55 private BigDecimal slotWidthGranularity;
57 public PceOpticalNode(Node node, OpenroadmNodeType nodeType, String version, BigDecimal slotWidthGranularity) {
59 && node.getNodeId() != null
62 && slotWidthGranularity != null) {
64 this.nodeId = node.getNodeId();
65 this.nodeType = nodeType;
66 this.version = version;
67 this.slotWidthGranularity = slotWidthGranularity;
68 this.adminStates = node.augmentation(org.opendaylight.yang.gen.v1.http
69 .org.openroadm.common.network.rev200529.Node1.class).getAdministrativeState();
70 this.state = node.augmentation(org.opendaylight.yang.gen.v1.http
71 .org.openroadm.common.network.rev200529.Node1.class).getOperationalState();
73 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, slot width granularity");
78 public void initSrgTps() {
79 this.availableSrgPp.clear();
80 this.availableSrgCp.clear();
84 LOG.info("initSrgTpList: getting SRG tps from ROADM node {}", this.nodeId);
85 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
86 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
87 .ietf.network.topology.rev180226.Node1.class);
88 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
89 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
90 if (allTps.isEmpty()) {
91 LOG.error("initSrgTpList: ROADM TerminationPoint list is empty for node {}", this);
95 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
96 .node.TerminationPoint tp : allTps) {
97 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
98 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.TerminationPoint1 nttp1 = tp
99 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529
100 .TerminationPoint1.class);
101 OpenroadmTpType type = cntp1.getTpType();
102 LOG.info("type = {} for tp {}", type.getName(), tp);
108 if (State.InService.equals(cntp1.getOperationalState())) {
109 LOG.info("initSrgTpList: adding SRG-CP tp = {} ", tp.getTpId().getValue());
110 this.availableSrgCp.put(tp.getTpId().getValue(), cntp1.getTpType());
116 LOG.info("initSrgTpList: SRG-PP tp = {} found", tp.getTpId().getValue());
117 if (isTerminationPointAvailable(nttp1)) {
118 LOG.info("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
119 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
120 if (State.InService.equals(cntp1.getOperationalState())) {
121 LOG.info("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
122 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
125 LOG.warn("initSrgTpList: SRG-PP tp = {} found is busy !!", tp.getTpId().getValue());
132 if (this.availableSrgPp.isEmpty() || this.availableSrgCp.isEmpty()) {
133 LOG.error("initSrgTpList: ROADM SRG TerminationPoint list is empty for node {}", this);
137 LOG.info("initSrgTpList: availableSrgPp size = {} && availableSrgCp size = {} in {}",
138 this.availableSrgPp.size(), this.availableSrgCp.size(), this);
141 private boolean isTerminationPointAvailable(
142 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.TerminationPoint1 nttp1) {
143 byte[] availableByteArray = new byte[GridConstant.NB_OCTECTS];
144 Arrays.fill(availableByteArray, (byte) GridConstant.AVAILABLE_SLOT_VALUE);
145 return nttp1 == null || nttp1.getPpAttributes() == null
146 || nttp1.getPpAttributes().getAvailFreqMaps() == null
147 || !nttp1.getPpAttributes().getAvailFreqMaps().containsKey(freqMapKey)
148 || nttp1.getPpAttributes().getAvailFreqMaps().get(freqMapKey).getFreqMap() == null
149 || Arrays.equals(nttp1.getPpAttributes().getAvailFreqMaps().get(freqMapKey).getFreqMap(),
153 public void initFrequenciesBitSet() {
157 Node1 node1 = this.node.augmentation(Node1.class);
158 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Node1 node11 =
159 this.node.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Node1
161 switch (this.nodeType) {
163 if (!State.InService.equals(node11.getOperationalState())) {
165 LOG.error("initWLlist: SRG node {} is OOS/degraded", this);
168 if (!node1.getSrgAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
169 LOG.error("initFrequenciesBitSet: SRG no cband available freq maps for node {}", this);
173 this.frequenciesBitSet = BitSet.valueOf(node1.getSrgAttributes()
174 .nonnullAvailFreqMaps().get(freqMapKey).getFreqMap());
177 if (!State.InService.equals(node11.getOperationalState())) {
179 LOG.error("initWLlist: Degree node {} is OOS/degraded", this);
182 if (!node1.getDegreeAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
183 LOG.error("initFrequenciesBitSet: DEG no cband available freq maps for node {}", this);
187 this.frequenciesBitSet = BitSet.valueOf(node1.getDegreeAttributes()
188 .nonnullAvailFreqMaps().get(freqMapKey).getFreqMap());
191 // at init all bits are set to false (unavailable)
192 this.frequenciesBitSet = new BitSet(GridConstant.EFFECTIVE_BITS);
193 //set all bits to true (available)
194 this.frequenciesBitSet.set(0, GridConstant.EFFECTIVE_BITS);
195 if (!State.InService.equals(node11.getOperationalState())) {
197 LOG.error("initWLlist: XPDR node {} is OOS/degraded", this);
202 LOG.error("initFrequenciesBitSet: unsupported node type {} in node {}", this.nodeType, this);
207 public void initXndrTps(ServiceFormat serviceFormat) {
208 LOG.info("PceNod: initXndrTps for node : {}", this.nodeId);
212 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
213 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
214 .ietf.network.topology.rev180226.Node1.class);
215 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
216 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
217 if (allTps.isEmpty()) {
219 LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this);
223 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
224 .node.TerminationPoint tp : allTps) {
225 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
226 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.TerminationPoint1 nttp1 = tp
227 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529
228 .TerminationPoint1.class);
229 if (cntp1.getTpType() != OpenroadmTpType.XPONDERNETWORK) {
230 LOG.warn("initXndrTps: {} is not an Xponder network port", cntp1.getTpType().getName());
233 if (!State.InService.equals(cntp1.getOperationalState())) {
234 LOG.warn("initXndrTps: XPONDER tp = {} is OOS/degraded", tp.getTpId().getValue());
238 if (nttp1 != null && nttp1.getXpdrNetworkAttributes().getWavelength() != null) {
239 this.usedXpndrNWTps.add(tp.getTpId().getValue());
240 LOG.info("initXndrTps: XPONDER tp = {} is used", tp.getTpId().getValue());
244 // find Client of this network TP
246 org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.TerminationPoint1 tpceTp1 =
247 tp.augmentation(org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019
248 .TerminationPoint1.class);
249 if (tpceTp1 != null) {
250 client = tpceTp1.getAssociatedConnectionMapPort();
251 if (client != null) {
252 this.clientPerNwTp.put(tp.getTpId().getValue(), client);
255 LOG.error("Service Format {} not managed yet", serviceFormat.getName());
260 LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node {}", this);
265 public String getRdmSrgClient(String tp) {
266 LOG.info("getRdmSrgClient: Getting PP client for tp '{}' on node : {}", tp, this.nodeId);
267 OpenroadmTpType srgType = null;
268 OpenroadmTpType cpType = this.availableSrgCp.get(tp);
269 if (cpType == null) {
270 LOG.error("getRdmSrgClient: tp {} not existed in SRG CPterminationPoint list", tp);
275 LOG.info("getRdmSrgClient: Getting BI Directional PP port ...");
276 srgType = OpenroadmTpType.SRGTXRXPP;
279 LOG.info("getRdmSrgClient: Getting UNI Rx PP port ...");
280 srgType = OpenroadmTpType.SRGRXPP;
283 LOG.info("getRdmSrgClient: Getting UNI Tx PP port ...");
284 srgType = OpenroadmTpType.SRGTXPP;
289 LOG.info("getRdmSrgClient: Getting client PP for CP '{}'", tp);
290 if (!this.availableSrgPp.isEmpty()) {
291 Optional<String> client = null;
292 final OpenroadmTpType openType = srgType;
293 client = this.availableSrgPp.entrySet()
294 .stream().filter(pp -> pp.getValue().getName().equals(openType.getName()))
295 .map(Map.Entry::getKey)
296 .sorted(new SortPortsByName())
298 if (!client.isPresent()) {
299 LOG.error("getRdmSrgClient: ROADM {} doesn't have PP Client for CP {}", this, tp);
302 LOG.info("getRdmSrgClient: client PP {} for CP {} found !", client, tp);
305 LOG.error("getRdmSrgClient: SRG TerminationPoint PP list is not available for node {}", this);
311 public void validateAZxponder(String anodeId, String znodeId, ServiceFormat serviceFormat) {
315 if (this.nodeType != OpenroadmNodeType.XPONDER) {
319 if (this.getSupNetworkNodeId().equals(anodeId) || (this.getSupNetworkNodeId().equals(znodeId))) {
320 LOG.info("validateAZxponder: A or Z node detected == {}", nodeId.getValue());
321 initXndrTps(serviceFormat);
324 LOG.debug("validateAZxponder: XPONDER is ignored == {}", nodeId.getValue());
329 public boolean checkTP(String tp) {
330 return !this.usedXpndrNWTps.contains(tp);
333 public boolean isValid() {
334 if (node == null || nodeId == null || nodeType == null || this.getSupNetworkNodeId() == null
335 || this.getSupClliNodeId() == null || adminStates == null || state == null) {
336 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, supporting nodeId, "
337 + "admin state, operational state");
344 public List<PceLink> getOutgoingLinks() {
345 return outgoingLinks;
349 public AdminStates getAdminStates() {
354 public State getState() {
359 public NodeId getNodeId() {
364 public String toString() {
365 return "PceNode type=" + nodeType + " ID=" + nodeId.getValue() + " CLLI=" + this.getSupClliNodeId();
369 public String getPceNodeType() {
374 public String getSupNetworkNodeId() {
375 return MapUtils.getSupNetworkNode(this.node);
379 public String getSupClliNodeId() {
380 return MapUtils.getSupClliNode(this.node);
384 public void addOutgoingLink(PceLink outLink) {
385 this.outgoingLinks.add(outLink);
389 public String getXpdrClient(String tp) {
390 return this.clientPerNwTp.get(tp);
394 public Map<String, List<Uint16>> getAvailableTribPorts() {
399 public Map<String, List<Uint16>> getAvailableTribSlots() {
406 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getBitSetData()
409 public BitSet getBitSetData() {
410 return this.frequenciesBitSet;
416 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getVersion()
419 public String getVersion() {
426 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getSlotWidthGranularity()
429 public BigDecimal getSlotWidthGranularity() {
430 return slotWidthGranularity;