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.Iterator;
13 import java.util.List;
16 import java.util.TreeSet;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev170929.Node1;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev170929.TerminationPoint1;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev170929.network.node.termination.point.cp.attributes.UsedWavelengths;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev170929.OpenroadmNodeType;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev170929.OpenroadmTpType;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.NodeId;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.network.Node;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 public class PceNode {
30 private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
31 ////////////////////////// NODES ///////////////////////////
34 private boolean valid = true;
35 private final Node node;
36 private final NodeId nodeId;
37 private final OpenroadmNodeType nodeType;
38 // wavelength calculation per node type
39 private List<Long> availableWLindex = new ArrayList<Long>();
40 private Set<String> availableSrgPp = new TreeSet<String>();
41 private List<String> usedXpndrNWTps = new ArrayList<String>();
42 private List<String> usedRdmCpTps = new ArrayList<String>();
43 private List<PceLink> outgoingLinks = new ArrayList<PceLink>();
44 private Map<String, String> clientPerNwTp = new HashMap<String, String>();
45 private Map<String, String> clientPerPpTp = new HashMap<String, String>();
47 public PceNode(Node node, OpenroadmNodeType nodeType, NodeId nodeId) {
50 this.nodeType = nodeType;
51 if ((node == null) || (nodeId == null) || (nodeType == null)) {
52 LOG.error("PceNode: one of parameters is not populated : nodeId, node type");
57 public void initSrgPpList() {
58 this.availableSrgPp.clear();
62 LOG.info("getting SRG-PP tps from ROADM node {}", this.nodeId);
63 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.Node1 nodeTp =
64 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology
65 .rev150608.Node1.class);
66 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.network.node
67 .TerminationPoint> allTps = nodeTp.getTerminationPoint();
69 LOG.error("initXndrTps: 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.rev150608.network.node
74 .TerminationPoint tp : allTps) {
75 TerminationPoint1 tp1 = tp.augmentation(TerminationPoint1.class);
76 if (tp1.getTpType() == OpenroadmTpType.SRGTXRXPP) {
77 this.availableSrgPp.add(tp.getTpId().getValue());
80 if (this.availableSrgPp.isEmpty()) {
81 LOG.error("initSrgPpList: ROADM SRG PP TerminationPoint list is empty for node {}", this.toString());
85 LOG.info("initSrgPpList: availableSrgPp size = {} in {}", this.availableSrgPp.size(), this.toString());
89 public void initWLlist() {
90 this.availableWLindex.clear();
94 Node1 node1 = this.node.augmentation(Node1.class);
95 switch (this.nodeType) {
97 List<org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev170929.srg.node.attributes
98 .AvailableWavelengths> srgAvailableWL = node1.getSrgAttributes().getAvailableWavelengths();
99 if (srgAvailableWL == null) {
101 LOG.error("initWLlist: SRG AvailableWavelengths is empty for node {}", this.toString());
104 for (org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev170929.srg.node.attributes
105 .AvailableWavelengths awl : srgAvailableWL) {
106 this.availableWLindex.add(awl.getIndex());
107 LOG.debug("initWLlist: SRG next = {} in {}", awl.getIndex(), this.toString());
111 List<org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev170929.degree.node.attributes
112 .AvailableWavelengths> degAvailableWL =
113 node1.getDegreeAttributes().getAvailableWavelengths();
114 if (degAvailableWL == null) {
116 LOG.error("initWLlist: DEG AvailableWavelengths is empty for node {}", this.toString());
119 for (org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev170929.degree.node.attributes
120 .AvailableWavelengths awl : degAvailableWL) {
121 this.availableWLindex.add(awl.getIndex());
122 LOG.debug("initWLlist: DEGREE next = {} in {}", awl.getIndex(), this.toString());
127 for (long i = 1; i <= 96; i++) {
128 this.availableWLindex.add(i);
132 LOG.error("initWLlist: unsupported node type {} in node {}", this.nodeType, this.toString());
135 if (this.availableWLindex.size() == 0) {
136 LOG.debug("initWLlist: There are no available wavelengths in node {}", this.toString());
139 LOG.debug("initWLlist: availableWLindex size = {} in {}", this.availableWLindex.size(), this.toString());
143 public void initXndrTps() {
144 LOG.info("initXndrTps for node : {}", this.nodeId);
148 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.Node1 nodeTp =
149 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology
150 .rev150608.Node1.class);
151 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.network.node
152 .TerminationPoint> allTps = nodeTp.getTerminationPoint();
153 if (allTps == null) {
155 LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this.toString());
159 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.network.node
160 .TerminationPoint tp : allTps) {
161 TerminationPoint1 tp1 = tp.augmentation(TerminationPoint1.class);
162 if (tp1.getTpType() == OpenroadmTpType.XPONDERNETWORK) {
163 if (tp1.getXpdrNetworkAttributes().getWavelength() != null) {
164 this.usedXpndrNWTps.add(tp.getTpId().getValue());
165 LOG.debug("initXndrTps: XPONDER tp = {} is used", tp.getTpId().getValue());
169 // find Client of this network TP
170 String client = tp1.getXpdrNetworkAttributes().getTailEquipmentId();
171 if ((client.equals("")) || (client == null)) {
172 LOG.error("initXndrTps: XPONDER {} NW TP doesn't have defined Client {}", this.toString(), tp
173 .getTpId().getValue());
176 this.clientPerNwTp.put(tp.getTpId().getValue(), client);
180 LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node {}", this.toString());
185 public void initRdmSrgTps() {
186 LOG.info("initRdmSrgTps for node : {}", this.nodeId);
191 LOG.info("initRdmSrgTps: getting terminationPoint list for node {}", this.toString());
192 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.Node1 nodeTp =
193 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology
194 .rev150608.Node1.class);
195 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.network.node
196 .TerminationPoint> allTps = nodeTp.getTerminationPoint();
197 if (allTps == null) {
199 LOG.error("initRdmSrgTps: SRG TerminationPoint list is empty for node {}", this.toString());
203 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.network.node
204 .TerminationPoint tp : allTps) {
205 TerminationPoint1 tp1 = tp.augmentation(TerminationPoint1.class);
206 if (tp1.getTpType() == OpenroadmTpType.SRGTXRXCP) {
208 List<UsedWavelengths> usedWavelengths = tp1.getCpAttributes().getUsedWavelengths();
209 if (!usedWavelengths.isEmpty()) {
210 this.usedRdmCpTps.add(tp.getTpId().getValue());
211 LOG.warn("initRdmSrgTps: SRG-CP tp = {} is used", tp.getTpId().getValue());
213 LOG.info("initRdmSrgTps: SRG-CP tp = {} found", tp.getTpId().getValue());
216 } catch (NullPointerException e) {
217 LOG.warn("'usedWavelengths' for tp={} is null !", tp.getTpId().getValue());
221 if (tp1.getTpType() == OpenroadmTpType.SRGTXRXCP) {
222 // Find an available PP of this CP
223 if (!this.availableSrgPp.isEmpty()) {
224 LOG.info("finding PP for CP {}", tp.getTpId().getValue());
225 Iterator<String> iterator = this.availableSrgPp.iterator();
226 while (iterator.hasNext()) {
227 String client = iterator.next();
228 if ((client.equals("")) || (client == null)) {
229 LOG.error("initRdmSrgTps: ROADM {} doesn't have defined Client {}", this.toString(), tp
230 .getTpId().getValue());
234 this.clientPerPpTp.put(tp.getTpId().getValue(), client);
235 LOG.info("initRdmSrgTps: client PP {} for CP {} found !", client, tp.getTpId().getValue());
241 LOG.error("initRdmSrgTps: ROADM {} doesn't have available PP", this.nodeId.getValue());
248 LOG.error("initRdmSrgTps: SRG doesn't have available wavelengths for node {}", this.toString());
253 public void initNodeTps() {
257 switch (this.nodeType) {
267 LOG.warn("initNodeTps: Node TerminationPoints list is not SRG or XPONDER or DEGREE!");
272 public boolean checkTP(String tp) {
273 if (this.usedXpndrNWTps.contains(tp)) {
279 public boolean checkWL(long index) {
280 if (this.availableWLindex.contains(index)) {
286 public boolean isValid() {
290 public List<Long> getAvailableWLs() {
291 return this.availableWLindex;
294 public void addOutgoingLink(PceLink outLink) {
295 this.outgoingLinks.add(outLink);
298 public List<PceLink> getOutgoingLinks() {
299 return this.outgoingLinks;
302 public String getXpdrClient(String tp) {
303 return this.clientPerNwTp.get(tp);
306 public String getRdmSrgClient(String tp) {
307 LOG.info("Getting ROADM Client PP for CP {}", tp, this.clientPerPpTp.get(tp));
308 return this.clientPerPpTp.get(tp);
312 public String toString() {
313 return "PceNode type=" + this.nodeType + " ID=" + this.nodeId.getValue();