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.network.topology.rev200529.Node1;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmNodeType;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmTpType;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.available.freq.map.AvailFreqMapsKey;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.ServiceFormat;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
30 import org.opendaylight.yangtools.yang.common.Uint16;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public class PceOpticalNode implements PceNode {
35 private static final Logger LOG = LoggerFactory.getLogger(PceOpticalNode.class);
37 private boolean valid = true;
40 private NodeId nodeId;
41 private OpenroadmNodeType nodeType;
43 private Map<String, OpenroadmTpType> availableSrgPp = new TreeMap<>();
44 private Map<String, OpenroadmTpType> availableSrgCp = new TreeMap<>();
45 private List<String> usedXpndrNWTps = new ArrayList<>();
46 private List<PceLink> outgoingLinks = new ArrayList<>();
47 private Map<String, String> clientPerNwTp = new HashMap<>();
48 private final AvailFreqMapsKey freqMapKey = new AvailFreqMapsKey(GridConstant.C_BAND);
49 private BitSet frequenciesBitSet;
50 private String version;
51 private BigDecimal slotWidthGranularity;
53 public PceOpticalNode(Node node, OpenroadmNodeType nodeType, String version, BigDecimal slotWidthGranularity) {
55 && node.getNodeId() != null
58 && slotWidthGranularity != null) {
60 this.nodeId = node.getNodeId();
61 this.nodeType = nodeType;
62 this.version = version;
63 this.slotWidthGranularity = slotWidthGranularity;
65 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, slot width granularity");
70 public void initSrgTps() {
71 this.availableSrgPp.clear();
72 this.availableSrgCp.clear();
76 LOG.info("initSrgTpList: getting SRG tps from ROADM node {}", this.nodeId);
77 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
78 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
79 .ietf.network.topology.rev180226.Node1.class);
80 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
81 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
82 if (allTps.isEmpty()) {
83 LOG.error("initSrgTpList: ROADM TerminationPoint list is empty for node {}", this);
87 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
88 .node.TerminationPoint tp : allTps) {
89 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
90 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.TerminationPoint1 nttp1 = tp
91 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529
92 .TerminationPoint1.class);
93 OpenroadmTpType type = cntp1.getTpType();
94 LOG.info("type = {} for tp {}", type.getName(), tp);
100 LOG.info("initSrgTpList: adding SRG-CP tp = {} ", tp.getTpId().getValue());
101 this.availableSrgCp.put(tp.getTpId().getValue(), cntp1.getTpType());
106 LOG.info("initSrgTpList: SRG-PP tp = {} found", tp.getTpId().getValue());
107 if (isTerminationPointAvailable(nttp1)) {
108 LOG.info("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
109 this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
111 LOG.warn("initSrgTpList: SRG-PP tp = {} found is busy !!", tp.getTpId().getValue());
118 if (this.availableSrgPp.isEmpty() || this.availableSrgCp.isEmpty()) {
119 LOG.error("initSrgTpList: ROADM SRG TerminationPoint list is empty for node {}", this);
123 LOG.info("initSrgTpList: availableSrgPp size = {} && availableSrgCp size = {} in {}",
124 this.availableSrgPp.size(), this.availableSrgCp.size(), this);
127 private boolean isTerminationPointAvailable(
128 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.TerminationPoint1 nttp1) {
129 byte[] availableByteArray = new byte[GridConstant.NB_OCTECTS];
130 Arrays.fill(availableByteArray, (byte) GridConstant.AVAILABLE_SLOT_VALUE);
131 return nttp1 == null || nttp1.getPpAttributes() == null
132 || nttp1.getPpAttributes().getAvailFreqMaps() == null
133 || !nttp1.getPpAttributes().getAvailFreqMaps().containsKey(freqMapKey)
134 || nttp1.getPpAttributes().getAvailFreqMaps().get(freqMapKey).getFreqMap() == null
135 || Arrays.equals(nttp1.getPpAttributes().getAvailFreqMaps().get(freqMapKey).getFreqMap(),
139 public void initFrequenciesBitSet() {
143 Node1 node1 = this.node.augmentation(Node1.class);
144 switch (this.nodeType) {
146 if (!node1.getSrgAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
147 LOG.error("initFrequenciesBitSet: SRG no cband available freq maps for node {}", this);
151 this.frequenciesBitSet = BitSet.valueOf(node1.getSrgAttributes()
152 .nonnullAvailFreqMaps().get(freqMapKey).getFreqMap());
155 if (!node1.getDegreeAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
156 LOG.error("initFrequenciesBitSet: DEG no cband available freq maps for node {}", this);
160 this.frequenciesBitSet = BitSet.valueOf(node1.getDegreeAttributes()
161 .nonnullAvailFreqMaps().get(freqMapKey).getFreqMap());
164 // at init all bits are set to false (unavailable)
165 this.frequenciesBitSet = new BitSet(GridConstant.EFFECTIVE_BITS);
166 //set all bits to true (available)
167 this.frequenciesBitSet.set(0, GridConstant.EFFECTIVE_BITS);
170 LOG.error("initFrequenciesBitSet: unsupported node type {} in node {}", this.nodeType, this);
175 public void initXndrTps(ServiceFormat serviceFormat) {
176 LOG.info("PceNod: initXndrTps for node : {}", this.nodeId);
180 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
181 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
182 .ietf.network.topology.rev180226.Node1.class);
183 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
184 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
185 if (allTps.isEmpty()) {
187 LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this);
191 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
192 .node.TerminationPoint tp : allTps) {
193 TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
194 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.TerminationPoint1 nttp1 = tp
195 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529
196 .TerminationPoint1.class);
197 if (cntp1.getTpType() == OpenroadmTpType.XPONDERNETWORK) {
198 if (nttp1 != null && nttp1.getXpdrNetworkAttributes().getWavelength() != null) {
199 this.usedXpndrNWTps.add(tp.getTpId().getValue());
200 LOG.info("initXndrTps: XPONDER tp = {} is used", tp.getTpId().getValue());
204 // find Client of this network TP
206 org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.TerminationPoint1 tpceTp1 =
207 tp.augmentation(org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019
208 .TerminationPoint1.class);
209 if (tpceTp1 != null) {
210 client = tpceTp1.getAssociatedConnectionMapPort();
211 if (client != null) {
212 this.clientPerNwTp.put(tp.getTpId().getValue(), client);
215 LOG.error("initXndrTps: XPONDER {} NW TP doesn't have defined Client {}",
216 this, tp.getTpId().getValue());
218 } else if (ServiceFormat.OTU.equals(serviceFormat)) {
219 LOG.info("Infrastructure OTU4 connection");
222 LOG.error("Service Format {} not managed yet", serviceFormat.getName());
227 LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node {}", this);
232 public String getRdmSrgClient(String tp) {
233 LOG.info("getRdmSrgClient: Getting PP client for tp '{}' on node : {}", tp, this.nodeId);
234 OpenroadmTpType srgType = null;
235 OpenroadmTpType cpType = this.availableSrgCp.get(tp);
236 if (cpType == null) {
237 LOG.error("getRdmSrgClient: tp {} not existed in SRG CPterminationPoint list", tp);
242 LOG.info("getRdmSrgClient: Getting BI Directional PP port ...");
243 srgType = OpenroadmTpType.SRGTXRXPP;
246 LOG.info("getRdmSrgClient: Getting UNI Rx PP port ...");
247 srgType = OpenroadmTpType.SRGRXPP;
250 LOG.info("getRdmSrgClient: Getting UNI Tx PP port ...");
251 srgType = OpenroadmTpType.SRGTXPP;
256 LOG.info("getRdmSrgClient: Getting client PP for CP '{}'", tp);
257 if (!this.availableSrgPp.isEmpty()) {
258 Optional<String> client = null;
259 final OpenroadmTpType openType = srgType;
260 client = this.availableSrgPp.entrySet()
261 .stream().filter(pp -> pp.getValue().getName().equals(openType.getName()))
262 .map(Map.Entry::getKey)
263 .sorted(new SortPortsByName())
265 if (!client.isPresent()) {
266 LOG.error("getRdmSrgClient: ROADM {} doesn't have PP Client for CP {}", this, tp);
269 LOG.info("getRdmSrgClient: client PP {} for CP {} found !", client, tp);
272 LOG.error("getRdmSrgClient: SRG TerminationPoint PP list is not available for node {}", this);
278 public void validateAZxponder(String anodeId, String znodeId, ServiceFormat serviceFormat) {
282 if (this.nodeType != OpenroadmNodeType.XPONDER) {
286 if (this.getSupNetworkNodeId().equals(anodeId) || (this.getSupNetworkNodeId().equals(znodeId))) {
287 LOG.info("validateAZxponder: A or Z node detected == {}", nodeId.getValue());
288 initXndrTps(serviceFormat);
291 LOG.debug("validateAZxponder: XPONDER is ignored == {}", nodeId.getValue());
296 public boolean checkTP(String tp) {
297 return !this.usedXpndrNWTps.contains(tp);
300 public boolean isValid() {
301 if (node == null || nodeId == null || nodeType == null || this.getSupNetworkNodeId() == null
302 || this.getSupClliNodeId() == null) {
303 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, supporting nodeId");
310 public List<PceLink> getOutgoingLinks() {
311 return outgoingLinks;
315 public NodeId getNodeId() {
320 public String toString() {
321 return "PceNode type=" + nodeType + " ID=" + nodeId.getValue() + " CLLI=" + this.getSupClliNodeId();
325 public String getPceNodeType() {
330 public String getSupNetworkNodeId() {
331 return MapUtils.getSupNetworkNode(this.node);
335 public String getSupClliNodeId() {
336 return MapUtils.getSupClliNode(this.node);
340 public void addOutgoingLink(PceLink outLink) {
341 this.outgoingLinks.add(outLink);
345 public String getXpdrClient(String tp) {
346 return this.clientPerNwTp.get(tp);
350 public Map<String, List<Uint16>> getAvailableTribPorts() {
355 public Map<String, List<Uint16>> getAvailableTribSlots() {
362 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getBitSetData()
365 public BitSet getBitSetData() {
366 return this.frequenciesBitSet;
372 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getVersion()
375 public String getVersion() {
382 * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getSlotWidthGranularity()
385 public BigDecimal getSlotWidthGranularity() {
386 return slotWidthGranularity;