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.rev170929.Node1;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev170929.TerminationPoint1;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev170929.network.node.termination.point.cp.attributes.UsedWavelengths;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev170929.OpenroadmNodeType;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev170929.OpenroadmTpType;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.NodeId;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.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 Set<String> availableSrgPp = new TreeSet<String>();
40 private Map<String, OpenroadmTpType> availableSrgPp = new TreeMap<String, OpenroadmTpType>();
41 private Map<String, OpenroadmTpType> availableSrgCp = new TreeMap<String, OpenroadmTpType>();
42 private List<String> usedXpndrNWTps = new ArrayList<String>();
43 private List<String> usedSrgPP = new ArrayList<String>();
44 private List<PceLink> outgoingLinks = new ArrayList<PceLink>();
45 private Map<String, String> clientPerNwTp = new HashMap<String, String>();
46 private Map<String, String> clientPerPpTp = new HashMap<String, String>();
48 public PceNode(Node node, OpenroadmNodeType nodeType, NodeId nodeId) {
51 this.nodeType = nodeType;
52 if ((node == null) || (nodeId == null) || (nodeType == null)) {
53 LOG.error("PceNode: one of parameters is not populated : nodeId, node type");
58 public void initSrgTpList() {
59 this.availableSrgPp.clear();
60 this.availableSrgCp.clear();
64 LOG.info("initSrgTpList: getting SRG tps from ROADM node {}", this.nodeId);
65 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.Node1 nodeTp =
66 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology
67 .rev150608.Node1.class);
68 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.network.node
69 .TerminationPoint> allTps =
70 nodeTp.getTerminationPoint();
72 LOG.error("initSrgTpList: ROADM TerminationPoint list is empty for node {}", this.toString());
77 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.network.node
78 .TerminationPoint tp : allTps) {
80 TerminationPoint1 tp1 = tp.augmentation(TerminationPoint1.class);
82 List<UsedWavelengths> usedWavelengths = tp1.getCpAttributes().getUsedWavelengths();
83 if (usedWavelengths.isEmpty()) {
84 LOG.info("initSrgTpList: SRG-CP tp = {} found", tp.getTpId().getValue());
87 } catch (NullPointerException e) {
88 LOG.warn("initSrgTpList: 'usedWavelengths' for tp={} is null !", tp.getTpId().getValue());
92 if (tp1.getTpType().getName().contains("-PP")) {
93 LOG.info("initSrgTpList: adding tp '{}'", tp1.getTpType());
94 this.availableSrgPp.put(tp.getTpId().getValue(), tp1.getTpType());
95 } else if (tp1.getTpType().getName().contains("-CP")) {
96 this.availableSrgCp.put(tp.getTpId().getValue(), tp1.getTpType());
100 if (this.availableSrgPp.isEmpty() && this.availableSrgCp.isEmpty()) {
101 LOG.error("initSrgTpList: ROADM SRG TerminationPoint list is empty for node {}", this.toString());
105 LOG.info("initSrgTpList: availableSrgPp size = {} && availableSrgCp size = {} in {}", this.availableSrgPp
106 .size(), this.availableSrgCp.size(), this.toString());
110 public void initWLlist() {
111 this.availableWLindex.clear();
115 Node1 node1 = this.node.augmentation(Node1.class);
116 switch (this.nodeType) {
118 List<org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev170929.srg.node.attributes
119 .AvailableWavelengths> srgAvailableWL =
120 node1.getSrgAttributes().getAvailableWavelengths();
121 if (srgAvailableWL == null) {
123 LOG.error("initWLlist: SRG AvailableWavelengths is empty for node {}", this.toString());
126 for (org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev170929.srg.node.attributes
127 .AvailableWavelengths awl : srgAvailableWL) {
128 this.availableWLindex.add(awl.getIndex());
129 LOG.debug("initWLlist: SRG next = {} in {}", awl.getIndex(), this.toString());
133 List<org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev170929.degree.node.attributes
134 .AvailableWavelengths> degAvailableWL = node1.getDegreeAttributes().getAvailableWavelengths();
135 if (degAvailableWL == null) {
137 LOG.error("initWLlist: DEG AvailableWavelengths is empty for node {}", this.toString());
140 for (org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev170929.degree.node.attributes
141 .AvailableWavelengths awl : degAvailableWL) {
142 this.availableWLindex.add(awl.getIndex());
143 LOG.debug("initWLlist: DEGREE next = {} in {}", awl.getIndex(), this.toString());
148 for (long i = 1; i <= 96; i++) {
149 this.availableWLindex.add(i);
153 LOG.error("initWLlist: unsupported node type {} in node {}", this.nodeType, this.toString());
156 if (this.availableWLindex.size() == 0) {
157 LOG.debug("initWLlist: There are no available wavelengths in node {}", this.toString());
160 LOG.debug("initWLlist: availableWLindex size = {} in {}", this.availableWLindex.size(), this.toString());
164 public void initXndrTps() {
165 LOG.info("initXndrTps for node : {}", this.nodeId);
169 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.Node1 nodeTp =
170 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology
171 .rev150608.Node1.class);
172 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.network.node
173 .TerminationPoint> allTps = nodeTp.getTerminationPoint();
174 if (allTps == null) {
176 LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this.toString());
180 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.network.node
181 .TerminationPoint tp : allTps) {
182 TerminationPoint1 tp1 = tp.augmentation(TerminationPoint1.class);
183 if (tp1.getTpType() == OpenroadmTpType.XPONDERNETWORK) {
184 if (tp1.getXpdrNetworkAttributes().getWavelength() != null) {
185 this.usedXpndrNWTps.add(tp.getTpId().getValue());
186 LOG.debug("initXndrTps: XPONDER tp = {} is used", tp.getTpId().getValue());
190 // find Client of this network TP
191 String client = tp1.getXpdrNetworkAttributes().getTailEquipmentId();
192 if ((client.equals("")) || (client == null)) {
193 LOG.error("initXndrTps: XPONDER {} NW TP doesn't have defined Client {}", this.toString(), tp
194 .getTpId().getValue());
197 this.clientPerNwTp.put(tp.getTpId().getValue(), client);
201 LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node {}", this.toString());
206 public void initRdmSrgTps(Boolean aend) {
207 LOG.info("initRdmSrgTps for node : {}", this.nodeId);
213 Optional<String> optTp = null;
214 OpenroadmTpType srgType = OpenroadmTpType.SRGTXRXPP;
215 OpenroadmTpType oppositeSrgType = null;
216 Optional<String> oppositeTp = null;
217 boolean unidir = false;
218 optTp = this.availableSrgCp.entrySet().stream().filter(cp -> cp.getValue() == OpenroadmTpType.SRGTXRXCP)
219 .map(Map.Entry::getKey).findFirst();
220 if (!optTp.isPresent()) {
223 LOG.info("UNI Directional ports ...");
225 LOG.info("Tx port ...");
226 optTp = this.availableSrgCp.entrySet().stream().filter(cp -> cp.getValue() == OpenroadmTpType.SRGTXCP)
227 .map(Map.Entry::getKey).findFirst();
228 srgType = OpenroadmTpType.SRGRXPP;
229 oppositeSrgType = OpenroadmTpType.SRGTXPP;
230 oppositeTp = this.availableSrgCp.entrySet().stream()
231 .filter(cp -> cp.getValue() == OpenroadmTpType.SRGRXCP).map(Map.Entry::getKey).findFirst();
233 LOG.info("Rx port ...");
234 optTp = this.availableSrgCp.entrySet().stream().filter(cp -> cp.getValue() == OpenroadmTpType.SRGRXCP)
235 .map(Map.Entry::getKey).findFirst();
236 srgType = OpenroadmTpType.SRGTXPP;
237 oppositeSrgType = OpenroadmTpType.SRGRXPP;
238 oppositeTp = this.availableSrgCp.entrySet().stream()
239 .filter(cp -> cp.getValue() == OpenroadmTpType.SRGTXCP).map(Map.Entry::getKey).findFirst();
242 LOG.info("BI Directional ports ...");
244 if (optTp.isPresent() && (srgType != null)) {
245 String tp = optTp.get();
246 if (!this.availableSrgPp.isEmpty()) {
247 LOG.info("finding PP for CP {}", optTp.get());
248 Optional<String> client = null;
249 final OpenroadmTpType openType = srgType;
250 client = this.availableSrgPp.entrySet().stream().filter(pp -> pp.getValue() == openType)
251 .map(Map.Entry::getKey).findFirst();
252 if (!client.isPresent()) {
253 LOG.error("initRdmSrgTps: ROADM {} doesn't have defined Client {}", this.toString(), tp);
258 final OpenroadmTpType oppositeOpType = oppositeSrgType;
259 String opTp = oppositeTp.get();
260 Optional<String> oppositeClient = this.availableSrgPp.entrySet().stream()
261 .filter(pp -> pp.getValue() == oppositeOpType)
262 .map(Map.Entry::getKey).findFirst();
263 if (!oppositeClient.isPresent()) {
264 LOG.error("initRdmSrgTps: ROADM {} doesn't have defined opposite Client {}",
265 this.toString(), tp);
269 this.clientPerPpTp.put(opTp, oppositeClient.get());
270 LOG.info("initRdmSrgTps: client PP {} for oposite CP {} found !", client, tp);
273 this.clientPerPpTp.put(tp, client.get());
274 LOG.info("initRdmSrgTps: client PP {} for CP {} found !", client, tp);
279 LOG.error("initRdmSrgTps: SRG TerminationPoint list is empty for node {}", this.toString());
284 public boolean checkTP(String tp) {
285 if (this.usedXpndrNWTps.contains(tp)) {
291 public boolean checkWL(long index) {
292 if (this.availableWLindex.contains(index)) {
298 public boolean isValid() {
302 public List<Long> getAvailableWLs() {
303 return this.availableWLindex;
306 public void addOutgoingLink(PceLink outLink) {
307 this.outgoingLinks.add(outLink);
310 public List<PceLink> getOutgoingLinks() {
311 return this.outgoingLinks;
314 public String getXpdrClient(String tp) {
315 return this.clientPerNwTp.get(tp);
318 public String getRdmSrgClient(String tp) {
319 LOG.info("Getting ROADM Client PP for CP {} : {}", tp, this.clientPerPpTp.get(tp));
320 return this.clientPerPpTp.get(tp);
324 public String toString() {
325 return "PceNode type=" + this.nodeType + " ID=" + this.nodeId.getValue();