2 * Copyright © 2017 AT&T, 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
8 package org.opendaylight.transportpce.pce;
10 import java.util.ArrayList;
11 import java.util.HashMap;
12 import java.util.List;
14 import java.util.Optional;
15 import java.util.TreeMap;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Node1;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.TerminationPoint1;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.networks.network.node.termination.point.pp.attributes.UsedWavelength;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmNodeType;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmTpType;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public class PceNode {
29 private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
30 ////////////////////////// NODES ///////////////////////////
33 private boolean valid = true;
34 private final Node node;
35 private final NodeId nodeId;
36 private final OpenroadmNodeType nodeType;
37 // wavelength calculation per node type
38 private List<Long> availableWLindex = new ArrayList<Long>();
39 private Map<String, OpenroadmTpType> availableSrgPp = new TreeMap<String, OpenroadmTpType>();
40 private Map<String, OpenroadmTpType> availableSrgCp = new TreeMap<String, OpenroadmTpType>();
41 private List<String> usedXpndrNWTps = new ArrayList<String>();
42 private List<PceLink> outgoingLinks = new ArrayList<PceLink>();
43 private Map<String, String> clientPerNwTp = new HashMap<String, String>();
45 public PceNode(Node node, OpenroadmNodeType nodeType, NodeId nodeId) {
48 this.nodeType = nodeType;
49 if ((node == null) || (nodeId == null) || (nodeType == null)) {
50 LOG.error("PceNode: one of parameters is not populated : nodeId, node type");
55 public void initSrgTps() {
56 this.availableSrgPp.clear();
57 this.availableSrgCp.clear();
61 LOG.info("initSrgTpList: getting SRG tps from ROADM node {}", this.nodeId);
62 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
63 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology
64 .rev180226.Node1.class);
65 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
66 .node.TerminationPoint> allTps =
67 nodeTp.getTerminationPoint();
69 LOG.error("initSrgTpList: ROADM TerminationPoint list is empty for node {}", this.toString());
73 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
74 .node.TerminationPoint tp : allTps) {
75 TerminationPoint1 tp1 = tp.augmentation(TerminationPoint1.class);
76 OpenroadmTpType type = tp1.getTpType();
81 LOG.info("initSrgTpList: adding SRG-CP tp = {} ", tp.getTpId().getValue());
82 this.availableSrgCp.put(tp.getTpId().getValue(), tp1.getTpType());
88 LOG.info("initSrgTpList: SRG-PP tp = {} found", tp.getTpId().getValue());
90 List<UsedWavelength> usedWavelengths = tp1.getPpAttributes().getUsedWavelength();
91 if (usedWavelengths.isEmpty()) {
94 } catch (NullPointerException e) {
95 LOG.warn("initSrgTpList: 'usedWavelengths' for tp={} is null !", tp.getTpId().getValue());
99 LOG.info("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
100 this.availableSrgPp.put(tp.getTpId().getValue(), tp1.getTpType());
102 LOG.warn("initSrgTpList: SRG-PP tp = {} found is busy !!");
109 if (this.availableSrgPp.isEmpty() && this.availableSrgCp.isEmpty()) {
110 LOG.error("initSrgTpList: ROADM SRG TerminationPoint list is empty for node {}", this.toString());
114 LOG.info("initSrgTpList: availableSrgPp size = {} && availableSrgCp size = {} in {}", this.availableSrgPp
115 .size(), this.availableSrgCp.size(), this.toString());
119 public void initWLlist() {
120 this.availableWLindex.clear();
124 Node1 node1 = this.node.augmentation(Node1.class);
125 switch (this.nodeType) {
127 List<org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev181130.srg.node.attributes
128 .AvailableWavelengths> srgAvailableWL =
129 node1.getSrgAttributes().getAvailableWavelengths();
130 if (srgAvailableWL == null) {
132 LOG.error("initWLlist: SRG AvailableWavelengths is empty for node {}", this.toString());
135 for (org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev181130.srg.node.attributes
136 .AvailableWavelengths awl : srgAvailableWL) {
137 this.availableWLindex.add(awl.getIndex());
138 LOG.debug("initWLlist: SRG next = {} in {}", awl.getIndex(), this.toString());
142 List<org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev181130.degree.node.attributes
143 .AvailableWavelengths> degAvailableWL = node1.getDegreeAttributes().getAvailableWavelengths();
144 if (degAvailableWL == null) {
146 LOG.error("initWLlist: DEG AvailableWavelengths is empty for node {}", this.toString());
149 for (org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev181130.degree.node.attributes
150 .AvailableWavelengths awl : degAvailableWL) {
151 this.availableWLindex.add(awl.getIndex());
152 LOG.debug("initWLlist: DEGREE next = {} in {}", awl.getIndex(), this.toString());
157 for (long i = 1; i <= 96; i++) {
158 this.availableWLindex.add(i);
162 LOG.error("initWLlist: unsupported node type {} in node {}", this.nodeType, this.toString());
165 if (this.availableWLindex.size() == 0) {
166 LOG.debug("initWLlist: There are no available wavelengths in node {}", this.toString());
169 LOG.debug("initWLlist: availableWLindex size = {} in {}", this.availableWLindex.size(), this.toString());
173 public void initXndrTps() {
174 LOG.info("initXndrTps for node : {}", this.nodeId);
178 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
179 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology
180 .rev180226.Node1.class);
181 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
182 .node.TerminationPoint> allTps = nodeTp.getTerminationPoint();
183 if (allTps == null) {
185 LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this.toString());
189 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
190 .node.TerminationPoint tp : allTps) {
191 TerminationPoint1 tp1 = tp.augmentation(TerminationPoint1.class);
192 if (tp1.getTpType() == OpenroadmTpType.XPONDERNETWORK) {
193 if (tp1.getXpdrNetworkAttributes().getWavelength() != null) {
194 this.usedXpndrNWTps.add(tp.getTpId().getValue());
195 LOG.debug("initXndrTps: XPONDER tp = {} is used", tp.getTpId().getValue());
199 // find Client of this network TP
200 String client = tp1.getXpdrNetworkAttributes().getTailEquipmentId();
201 if ((client.equals("")) || (client == null)) {
202 LOG.error("initXndrTps: XPONDER {} NW TP doesn't have defined Client {}", this.toString(), tp
203 .getTpId().getValue());
206 this.clientPerNwTp.put(tp.getTpId().getValue(), client);
210 LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node {}", this.toString());
215 public String getRdmSrgClient(String tp, Boolean aend) {
216 LOG.info("getRdmSrgClient: Getting PP client for tp '{}' on node : {}", tp, this.nodeId);
217 OpenroadmTpType srgType = null;
218 OpenroadmTpType cpType = this.availableSrgCp.get(tp);
219 if (cpType == null) {
220 LOG.error("getRdmSrgClient: tp {} not existed in SRG CPterminationPoint list");
225 LOG.info("getRdmSrgClient: Getting BI Directional PP port ...");
226 srgType = OpenroadmTpType.SRGTXRXPP;
229 LOG.info("getRdmSrgClient: Getting UNI Rx PP port ...");
230 srgType = OpenroadmTpType.SRGRXPP;
233 LOG.info("getRdmSrgClient: Getting UNI Tx PP port ...");
234 srgType = OpenroadmTpType.SRGTXPP;
239 LOG.info("getRdmSrgClient: Getting client PP for CP '{}'", tp);
240 if (!this.availableSrgPp.isEmpty()) {
241 Optional<String> client = null;
242 final OpenroadmTpType openType = srgType;
243 client = this.availableSrgPp.entrySet().stream().filter(pp -> pp.getValue().getName() == openType.getName())
244 .map(Map.Entry::getKey)
245 .sorted(new SortPortsByName())
247 if (!client.isPresent()) {
248 LOG.error("getRdmSrgClient: ROADM {} doesn't have PP Client for CP {}", this.toString(), tp);
251 LOG.info("getRdmSrgClient: client PP {} for CP {} found !", client, tp);
254 LOG.error("getRdmSrgClient: SRG TerminationPoint PP list is not available for node {}", this.toString());
259 public boolean checkTP(String tp) {
260 return !(this.usedXpndrNWTps.contains(tp));
263 public boolean checkWL(long index) {
264 return (this.availableWLindex.contains(index));
267 public boolean isValid() {
271 public List<Long> getAvailableWLs() {
272 return this.availableWLindex;
275 public void addOutgoingLink(PceLink outLink) {
276 this.outgoingLinks.add(outLink);
279 public List<PceLink> getOutgoingLinks() {
280 return this.outgoingLinks;
283 public String getXpdrClient(String tp) {
284 return this.clientPerNwTp.get(tp);
288 public String toString() {
289 return "PceNode type=" + this.nodeType + " ID=" + this.nodeId.getValue();