2 * Copyright © 2019 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.util.ArrayList;
12 import java.util.Comparator;
13 import java.util.HashMap;
14 import java.util.List;
16 import java.util.TreeMap;
17 import java.util.stream.Collectors;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev181130.xpdr.odu.switching.pools.OduSwitchingPools;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev181130.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingList;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmNodeType;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmTpType;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.xpdr.tp.supported.interfaces.SupportedInterfaceCapability;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev181130.ODTU4TsAllocated;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130.Node1;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130.TerminationPoint1;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130.networks.network.node.SwitchingPools;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev181130.If100GEODU4;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev181130.If10GEODU2e;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev181130.If1GEODU0;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev181130.IfOCHOTU4ODU4;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.TpId;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPoint;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
40 public class PceOtnNode implements PceNode {
42 private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
43 ////////////////////////// OTN NODES ///////////////////////////
45 * For This Class the node passed shall be at the otn-openroadm Layer
48 private boolean valid = true;
50 private final Node node;
51 private final NodeId nodeId;
52 private final OpenroadmNodeType nodeType;
53 private final String pceNodeType;
54 private final String otnServiceType;
56 private Map<String, List<Integer>> tpAvailableTribPort = new TreeMap<String, List<Integer>>();
57 private Map<String, List<Integer>> tpAvailableTribSlot = new TreeMap<String, List<Integer>>();
58 private Map<String, OpenroadmTpType> availableXponderTp = new TreeMap<String, OpenroadmTpType>();
59 private List<String> usedXpdrNWTps = new ArrayList<String>();
60 private List<TpId> availableXpdrNWTps;
61 private List<TpId> usableXpdrNWTps;
62 private List<String> usedXpdrClientTps = new ArrayList<String>();
63 private List<TpId> availableXpdrClientTps;
64 private List<TpId> usableXpdrClientTps;
66 private List<PceLink> outgoingLinks = new ArrayList<PceLink>();
67 private Map<String, String> clientPerNwTp = new HashMap<String, String>();
69 public PceOtnNode(Node node, OpenroadmNodeType nodeType, NodeId nodeId, String pceNodeType, String serviceType) {
72 this.nodeType = nodeType;
73 this.pceNodeType = pceNodeType;
74 this.otnServiceType = serviceType;
75 this.tpAvailableTribSlot.clear();
76 this.usedXpdrNWTps.clear();
77 this.availableXpdrNWTps = new ArrayList<TpId>();
78 this.usableXpdrNWTps = new ArrayList<TpId>();
79 this.usedXpdrClientTps.clear();
80 this.availableXpdrClientTps = new ArrayList<TpId>();
81 this.usableXpdrClientTps = new ArrayList<TpId>();
82 this.tpAvailableTribPort.clear();
83 checkAvailableTribPort();
84 this.tpAvailableTribSlot.clear();
85 checkAvailableTribSlot();
86 if ((node == null) || (nodeId == null) || (nodeType != OpenroadmNodeType.MUXPDR)
87 && (nodeType != OpenroadmNodeType.SWITCH) && (nodeType != OpenroadmNodeType.TPDR)) {
88 LOG.error("PceOtnNode: one of parameters is not populated : nodeId, node type");
93 public void initXndrTps(String mode) {
94 LOG.info("PceOtnNode: initXndrTps for node {}", this.nodeId.getValue());
95 this.availableXponderTp.clear();
97 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp
98 = this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
99 .ietf.network.topology.rev180226.Node1.class);
100 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
101 .node.TerminationPoint> allTps = nodeTp.getTerminationPoint();
103 if (allTps == null) {
104 LOG.error("PceOtnNode: initXndrTps: XPONDER TerminationPoint list is empty for node {}", this.toString());
108 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
109 .node.TerminationPoint tp : allTps) {
110 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.@Nullable TerminationPoint1 ocnTp1
111 = tp.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130
112 .TerminationPoint1.class);
113 //TODO many nested if-structures below, this needs to be reworked
114 if (OpenroadmTpType.XPONDERNETWORK.equals(ocnTp1.getTpType()) && this.otnServiceType.equals("ODU4")) {
115 TerminationPoint1 ontTp1;
116 if (tp.augmentation(TerminationPoint1.class) != null) {
117 ontTp1 = tp.augmentation(TerminationPoint1.class);
121 if (checkTpForOdtuTermination(ontTp1)) {
122 LOG.info("TP {} of XPONDER {} is validated", tp.getTpId(), node.getNodeId().getValue());
123 this.availableXpdrNWTps.add(tp.getTpId());
125 LOG.error("TP {} of {} does not allow ODU4 termination creation", tp.getTpId().getValue(),
126 node.getNodeId().getValue());
128 } else if (OpenroadmTpType.XPONDERNETWORK.equals(ocnTp1.getTpType())
129 && (this.otnServiceType.equals("10GE") || this.otnServiceType.equals("1GE"))) {
130 TerminationPoint1 ontTp1;
131 if (tp.augmentation(TerminationPoint1.class) != null) {
132 ontTp1 = tp.augmentation(TerminationPoint1.class);
136 if ("10GE".equals(otnServiceType) && checkOdtuTTPforLoOduCreation(ontTp1, 10)
137 || "1GE".equals(otnServiceType) && checkOdtuTTPforLoOduCreation(ontTp1, 1)) {
138 LOG.info("TP {} of XPONDER {} is validated", tp.getTpId(), node.getNodeId().getValue());
139 this.availableXpdrNWTps.add(tp.getTpId());
141 if ("10GE".equals(otnServiceType)) {
142 LOG.error("TP {} of {} does not allow OD2e termination creation", tp.getTpId().getValue(),
143 node.getNodeId().getValue());
144 } else if ("1GE".equals(otnServiceType)) {
145 LOG.error("TP {} of {} does not allow ODU0 termination creation", tp.getTpId().getValue(),
146 node.getNodeId().getValue());
148 LOG.error("TP {} of {} does not allow any termination creation", tp.getTpId().getValue(),
149 node.getNodeId().getValue());
152 } else if (OpenroadmTpType.XPONDERCLIENT.equals(ocnTp1.getTpType())
153 && (this.otnServiceType.equals("10GE") || this.otnServiceType.equals("1GE"))) {
154 TerminationPoint1 ontTp1;
155 if (tp.augmentation(TerminationPoint1.class) != null) {
156 ontTp1 = tp.augmentation(TerminationPoint1.class);
160 if (checkClientTp(ontTp1)) {
161 LOG.info("TP {} of XPONDER {} is validated", tp.getTpId(), node.getNodeId().getValue());
162 this.availableXpdrClientTps.add(tp.getTpId());
164 LOG.error("TP {} of {} does not allow lo-ODU (ODU2e or ODU0) termination creation",
165 tp.getTpId().getValue(), node.getNodeId().getValue());
170 if ((this.otnServiceType.equals("ODU4") && mode.equals("AZ"))
171 || ((this.otnServiceType.equals("10GE") || this.otnServiceType.equals("1GE"))
172 && mode.equals("AZ") && checkSwPool(availableXpdrClientTps, availableXpdrNWTps, 1, 1))
173 || ((this.otnServiceType.equals("10GE") || this.otnServiceType.equals("1GE"))
174 && mode.equals("intermediate") && checkSwPool(null, availableXpdrNWTps, 0, 2))) {
181 private boolean checkSwPool(List<TpId> clientTps, List<TpId> netwTps, int nbClient, int nbNetw) {
182 if (clientTps != null && netwTps != null && nbClient == 1 && nbNetw == 1) {
183 clientTps.sort(Comparator.comparing(TpId::getValue));
184 netwTps.sort(Comparator.comparing(TpId::getValue));
185 for (TpId nwTp : netwTps) {
186 for (TpId clTp : clientTps) {
188 List<NonBlockingList> nblList = node.augmentation(Node1.class).getSwitchingPools()
189 .getOduSwitchingPools().get(0).getNonBlockingList();
190 for (NonBlockingList nbl : nblList) {
191 if (nbl.getTpList().contains(clTp) && nbl.getTpList().contains(nwTp)) {
192 usableXpdrClientTps.add(clTp);
193 usableXpdrNWTps.add(nwTp);
195 if (usableXpdrClientTps.size() >= nbClient && usableXpdrNWTps.size() >= nbNetw) {
196 clientPerNwTp.put(nwTp.getValue(), clTp.getValue());
204 if (clientTps == null && netwTps != null && nbClient == 0 && nbNetw == 2) {
205 netwTps.sort(Comparator.comparing(TpId::getValue));
207 List<NonBlockingList> nblList = node.augmentation(Node1.class).getSwitchingPools().getOduSwitchingPools()
208 .get(0).getNonBlockingList();
209 for (NonBlockingList nbl : nblList) {
210 for (TpId nwTp : netwTps) {
211 if (nbl.getTpList().contains(nwTp)) {
212 usableXpdrNWTps.add(nwTp);
214 if (usableXpdrNWTps.size() >= nbNetw) {
223 private boolean checkTpForOdtuTermination(TerminationPoint1 ontTp1) {
224 for (SupportedInterfaceCapability sic : ontTp1.getTpSupportedInterfaces().getSupportedInterfaceCapability()) {
225 LOG.debug("in checkTpForOduTermination - sic = {}", sic.getIfCapType());
226 if (sic.getIfCapType().equals(IfOCHOTU4ODU4.class)
227 && ontTp1.getXpdrTpPortConnectionAttributes().getTsPool() == null) {
234 private boolean checkOdtuTTPforLoOduCreation(TerminationPoint1 ontTp1, int tsNb) {
235 if (ontTp1.getXpdrTpPortConnectionAttributes() != null
236 && ontTp1.getXpdrTpPortConnectionAttributes().getTsPool() != null
237 && ontTp1.getXpdrTpPortConnectionAttributes().getOdtuTpnPool() != null
238 && ontTp1.getXpdrTpPortConnectionAttributes().getOdtuTpnPool().get(0).getOdtuType()
239 .equals(ODTU4TsAllocated.class)
240 && ontTp1.getXpdrTpPortConnectionAttributes().getOdtuTpnPool().get(0).getTpnPool().size() >= 1
241 && ontTp1.getXpdrTpPortConnectionAttributes().getTsPool().size() >= tsNb) {
248 private boolean checkClientTp(TerminationPoint1 ontTp1) {
249 for (SupportedInterfaceCapability sic : ontTp1.getTpSupportedInterfaces().getSupportedInterfaceCapability()) {
250 LOG.debug("in checkTpForOduTermination - sic = {}", sic.getIfCapType());
251 switch (otnServiceType) {
253 // we could also check the administrative status of the tp
254 if (sic.getIfCapType().equals(If1GEODU0.class)) {
259 if (sic.getIfCapType().equals(If10GEODU2e.class)) {
264 if (sic.getIfCapType().equals(If100GEODU4.class)) {
275 private Boolean findClientCompliantInterface(List<SupportedInterfaceCapability> sic) {
276 boolean compliant = false;
277 for (SupportedInterfaceCapability sit : sic) {
278 String interfacetype = sit.getIfCapType().getName();
279 switch (interfacetype) {
282 if ("1GE".equals(this.otnServiceType)) {
288 if ("10GE".equals(this.otnServiceType)) {
294 if ("100GE".equals(this.otnServiceType)) {
299 case "IfOCHOTU4ODU4":
300 if ("OTU4".equals(this.otnServiceType) || "ODU4".equals(this.otnServiceType)) {
312 private Boolean findNetworkCompliantInterface(List<SupportedInterfaceCapability> sic) {
313 boolean compliant = false;
314 for (SupportedInterfaceCapability sit : sic) {
315 String interfacetype = sit.getIfCapType().toString();
316 switch (interfacetype) {
318 case "IfOCHOTU4ODU4":
322 case "IfOCHOTU2ODU2":
323 if (("1GE".equals(this.otnServiceType)) || ("10GE".equals(this.otnServiceType))) {
327 // add all use case with higher rate interfaces when it shows up
336 public void validateXponder(String anodeId, String znodeId) {
340 if (OpenroadmNodeType.SWITCH.equals(this.nodeType)) {
341 initXndrTps("intermediate");
343 if (this.nodeId.getValue().equals(anodeId) || (this.nodeId.getValue().equals(znodeId))) {
346 LOG.info("validateAZxponder: XPONDER is ignored == {}", nodeId.getValue());
351 public boolean validateSwitchingPoolBandwidth(
352 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
353 .ietf.network.topology.rev180226.networks.network.node.TerminationPoint tp1,
354 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
355 .ietf.network.topology.rev180226.networks.network.node.TerminationPoint tp2,
357 if (this.nodeType != OpenroadmNodeType.TPDR) {
360 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130.Node1 node1 =
362 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130.Node1.class);
363 SwitchingPools sp = node1.getSwitchingPools();
364 List<OduSwitchingPools> osp = new ArrayList<OduSwitchingPools>();
365 osp = sp.getOduSwitchingPools();
366 for (OduSwitchingPools ospx : osp) {
367 List<NonBlockingList> nbl = ospx.getNonBlockingList();
368 for (NonBlockingList nbll : nbl) {
369 if (nbll.getAvailableInterconnectBandwidth() >= neededBW) {
370 List<TpId> tplist = new ArrayList<TpId>(nbll.getTpList());
371 if ((tplist.contains(tp1.getTpId())) & (tplist.contains(tp2.getTpId()))) {
372 LOG.debug("validateSwitchingPoolBandwidth: couple of tp {} x {} valid for crossconnection",
373 tp1.getTpId().toString(), tp2.getTpId().toString());
379 LOG.debug("validateSwitchingPoolBandwidth: No valid Switching pool for crossconnecting tp {} and {}",
380 tp1.getTpId().toString(), tp2.getTpId().toString());
385 public void validateIntermediateSwitch() {
389 if (this.nodeType != OpenroadmNodeType.SWITCH) {
392 // Validate switch for use as an intermediate XPONDER on the path
393 initXndrTps("intermediate");
395 LOG.debug("validateIntermediateSwitch: Switch unusable for transit == {}", nodeId.getValue());
397 LOG.info("validateIntermediateSwitch: Switch usable for transit == {}", nodeId.getValue());
402 public void checkAvailableTribPort() {
403 List<TerminationPoint> networkTpList = node.augmentation(
404 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1.class)
405 .getTerminationPoint().stream()
408 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.TerminationPoint1.class)
409 .getTpType().equals(OpenroadmTpType.XPONDERNETWORK))
410 .collect(Collectors.toList());
412 for (TerminationPoint tp : networkTpList) {
413 if (tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes().getOdtuTpnPool() != null
414 && tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes().getOdtuTpnPool().get(0)
415 .getOdtuType().equals(ODTU4TsAllocated.class)) {
417 List<Integer> tpnPool = tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes()
418 .getOdtuTpnPool().get(0).getTpnPool();
419 if (tpnPool != null) {
420 tpAvailableTribPort.put(tp.getTpId().getValue(), tpnPool);
426 public void checkAvailableTribSlot() {
427 List<TerminationPoint> networkTpList = node.augmentation(
428 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1.class)
429 .getTerminationPoint().stream()
432 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.TerminationPoint1.class)
433 .getTpType().equals(OpenroadmTpType.XPONDERNETWORK))
434 .collect(Collectors.toList());
436 for (TerminationPoint tp : networkTpList) {
437 if (tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes().getTsPool() != null) {
439 List<Integer> tsPool = tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes()
441 tpAvailableTribSlot.put(tp.getTpId().getValue(), tsPool);
446 public boolean isValid() {
447 if ((node == null) || (nodeId == null) || (nodeType == null) || (this.getSupNetworkNodeId() == null)
448 || (this.getSupClliNodeId() == null)) {
449 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, supporting nodeId");
455 public void addOutgoingLink(PceLink outLink) {
456 this.outgoingLinks.add(outLink);
459 public List<PceLink> getOutgoingLinks() {
460 return outgoingLinks;
464 public String getXpdrClient(String tp) {
465 return this.clientPerNwTp.get(tp);
468 public String toString() {
469 return "PceNode type=" + nodeType + " ID=" + nodeId.getValue() + " CLLI=" + this.getSupClliNodeId();
472 public void printLinksOfNode() {
473 LOG.info(" outgoing links of node {} : {} ", nodeId.getValue(), this.getOutgoingLinks().toString());
477 public Map<String, List<Integer>> getAvailableTribPorts() {
478 return tpAvailableTribPort;
482 public Map<String, List<Integer>> getAvailableTribSlots() {
483 return tpAvailableTribSlot;
486 public List<TpId> getUsableXpdrNWTps() {
487 return usableXpdrNWTps;
490 public List<TpId> getUsableXpdrClientTps() {
491 return usableXpdrClientTps;
495 public String getPceNodeType() {
496 return this.pceNodeType;
500 public String getSupNetworkNodeId() {
501 return MapUtils.getSupNetworkNode(this.node);
505 public String getSupClliNodeId() {
506 return MapUtils.getSupClliNode(this.node);
510 public String getRdmSrgClient(String tp) {
511 // TODO Auto-generated method stub
516 public NodeId getNodeId() {
521 public boolean checkTP(String tp) {
522 // TODO Auto-generated method stub
527 public boolean checkWL(long index) {
528 // TODO Auto-generated method stub