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.opendaylight.yangtools.yang.common.Uint16;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
41 public class PceOtnNode implements PceNode {
43 private static final Logger LOG = LoggerFactory.getLogger(PceOtnNode.class);
44 ////////////////////////// OTN NODES ///////////////////////////
46 * For This Class the node passed shall be at the otn-openroadm Layer
49 private boolean valid = true;
51 private final Node node;
52 private final NodeId nodeId;
53 private final OpenroadmNodeType nodeType;
54 private final String pceNodeType;
55 private final String otnServiceType;
57 private Map<String, List<Uint16>> tpAvailableTribPort = new TreeMap<>();
58 private Map<String, List<Uint16>> tpAvailableTribSlot = new TreeMap<>();
59 private Map<String, OpenroadmTpType> availableXponderTp = new TreeMap<>();
60 private List<String> usedXpdrNWTps = new ArrayList<>();
61 private List<TpId> availableXpdrNWTps;
62 private List<TpId> usableXpdrNWTps;
63 private List<String> usedXpdrClientTps = new ArrayList<>();
64 private List<TpId> availableXpdrClientTps;
65 private List<TpId> usableXpdrClientTps;
67 private List<PceLink> outgoingLinks = new ArrayList<>();
68 private Map<String, String> clientPerNwTp = new HashMap<>();
70 public PceOtnNode(Node node, OpenroadmNodeType nodeType, NodeId nodeId, String pceNodeType, String serviceType) {
73 this.nodeType = nodeType;
74 this.pceNodeType = pceNodeType;
75 this.otnServiceType = serviceType;
76 this.tpAvailableTribSlot.clear();
77 this.usedXpdrNWTps.clear();
78 this.availableXpdrNWTps = new ArrayList<>();
79 this.usableXpdrNWTps = new ArrayList<>();
80 this.usedXpdrClientTps.clear();
81 this.availableXpdrClientTps = new ArrayList<>();
82 this.usableXpdrClientTps = new ArrayList<>();
83 this.tpAvailableTribPort.clear();
84 checkAvailableTribPort();
85 this.tpAvailableTribSlot.clear();
86 checkAvailableTribSlot();
87 if ((node == null) || (nodeId == null) || (nodeType != OpenroadmNodeType.MUXPDR)
88 && (nodeType != OpenroadmNodeType.SWITCH) && (nodeType != OpenroadmNodeType.TPDR)) {
89 LOG.error("PceOtnNode: one of parameters is not populated : nodeId, node type");
94 public void initXndrTps(String mode) {
95 LOG.info("PceOtnNode: initXndrTps for node {}", this.nodeId.getValue());
96 this.availableXponderTp.clear();
98 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp
99 = this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
100 .ietf.network.topology.rev180226.Node1.class);
101 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
102 .node.TerminationPoint> allTps = nodeTp.getTerminationPoint();
104 if (allTps == null) {
105 LOG.error("PceOtnNode: initXndrTps: XPONDER TerminationPoint list is empty for node {}", this);
109 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
110 .node.TerminationPoint tp : allTps) {
111 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.@Nullable TerminationPoint1 ocnTp1
112 = tp.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130
113 .TerminationPoint1.class);
114 //TODO many nested if-structures below, this needs to be reworked
115 if (OpenroadmTpType.XPONDERNETWORK.equals(ocnTp1.getTpType()) && this.otnServiceType.equals("ODU4")) {
116 TerminationPoint1 ontTp1;
117 if (tp.augmentation(TerminationPoint1.class) != null) {
118 ontTp1 = tp.augmentation(TerminationPoint1.class);
122 if (checkTpForOdtuTermination(ontTp1)) {
123 LOG.info("TP {} of XPONDER {} is validated", tp.getTpId(), node.getNodeId().getValue());
124 this.availableXpdrNWTps.add(tp.getTpId());
126 LOG.error("TP {} of {} does not allow ODU4 termination creation", tp.getTpId().getValue(),
127 node.getNodeId().getValue());
129 } else if (OpenroadmTpType.XPONDERNETWORK.equals(ocnTp1.getTpType())
130 && (this.otnServiceType.equals("10GE") || this.otnServiceType.equals("1GE"))) {
131 TerminationPoint1 ontTp1;
132 if (tp.augmentation(TerminationPoint1.class) != null) {
133 ontTp1 = tp.augmentation(TerminationPoint1.class);
137 if ("10GE".equals(otnServiceType) && checkOdtuTTPforLoOduCreation(ontTp1, 10)
138 || "1GE".equals(otnServiceType) && checkOdtuTTPforLoOduCreation(ontTp1, 1)) {
139 LOG.info("TP {} of XPONDER {} is validated", tp.getTpId(), node.getNodeId().getValue());
140 this.availableXpdrNWTps.add(tp.getTpId());
142 if ("10GE".equals(otnServiceType)) {
143 LOG.error("TP {} of {} does not allow OD2e termination creation", tp.getTpId().getValue(),
144 node.getNodeId().getValue());
145 } else if ("1GE".equals(otnServiceType)) {
146 LOG.error("TP {} of {} does not allow ODU0 termination creation", tp.getTpId().getValue(),
147 node.getNodeId().getValue());
149 LOG.error("TP {} of {} does not allow any termination creation", tp.getTpId().getValue(),
150 node.getNodeId().getValue());
153 } else if (OpenroadmTpType.XPONDERCLIENT.equals(ocnTp1.getTpType())
154 && (this.otnServiceType.equals("10GE") || this.otnServiceType.equals("1GE"))) {
155 TerminationPoint1 ontTp1;
156 if (tp.augmentation(TerminationPoint1.class) != null) {
157 ontTp1 = tp.augmentation(TerminationPoint1.class);
161 if (checkClientTp(ontTp1)) {
162 LOG.info("TP {} of XPONDER {} is validated", tp.getTpId(), node.getNodeId().getValue());
163 this.availableXpdrClientTps.add(tp.getTpId());
165 LOG.error("TP {} of {} does not allow lo-ODU (ODU2e or ODU0) termination creation",
166 tp.getTpId().getValue(), node.getNodeId().getValue());
171 if ((this.otnServiceType.equals("ODU4") && mode.equals("AZ"))
172 || ((this.otnServiceType.equals("10GE") || this.otnServiceType.equals("1GE"))
173 && mode.equals("AZ") && checkSwPool(availableXpdrClientTps, availableXpdrNWTps, 1, 1))
174 || ((this.otnServiceType.equals("10GE") || this.otnServiceType.equals("1GE"))
175 && mode.equals("intermediate") && checkSwPool(null, availableXpdrNWTps, 0, 2))) {
182 private boolean checkSwPool(List<TpId> clientTps, List<TpId> netwTps, int nbClient, int nbNetw) {
183 if (clientTps != null && netwTps != null && nbClient == 1 && nbNetw == 1) {
184 clientTps.sort(Comparator.comparing(TpId::getValue));
185 netwTps.sort(Comparator.comparing(TpId::getValue));
186 for (TpId nwTp : netwTps) {
187 for (TpId clTp : clientTps) {
189 List<NonBlockingList> nblList = node.augmentation(Node1.class).getSwitchingPools()
190 .getOduSwitchingPools().get(0).getNonBlockingList();
191 for (NonBlockingList nbl : nblList) {
192 if (nbl.getTpList().contains(clTp) && nbl.getTpList().contains(nwTp)) {
193 usableXpdrClientTps.add(clTp);
194 usableXpdrNWTps.add(nwTp);
196 if (usableXpdrClientTps.size() >= nbClient && usableXpdrNWTps.size() >= nbNetw) {
197 clientPerNwTp.put(nwTp.getValue(), clTp.getValue());
205 if (clientTps == null && netwTps != null && nbClient == 0 && nbNetw == 2) {
206 netwTps.sort(Comparator.comparing(TpId::getValue));
208 List<NonBlockingList> nblList = node.augmentation(Node1.class).getSwitchingPools().getOduSwitchingPools()
209 .get(0).getNonBlockingList();
210 for (NonBlockingList nbl : nblList) {
211 for (TpId nwTp : netwTps) {
212 if (nbl.getTpList().contains(nwTp)) {
213 usableXpdrNWTps.add(nwTp);
215 if (usableXpdrNWTps.size() >= nbNetw) {
224 private boolean checkTpForOdtuTermination(TerminationPoint1 ontTp1) {
225 for (SupportedInterfaceCapability sic : ontTp1.getTpSupportedInterfaces().getSupportedInterfaceCapability()) {
226 LOG.debug("in checkTpForOduTermination - sic = {}", sic.getIfCapType());
227 if (sic.getIfCapType().equals(IfOCHOTU4ODU4.class)
228 && ontTp1.getXpdrTpPortConnectionAttributes().getTsPool() == null) {
235 private boolean checkOdtuTTPforLoOduCreation(TerminationPoint1 ontTp1, int tsNb) {
236 if (ontTp1.getXpdrTpPortConnectionAttributes() != null
237 && ontTp1.getXpdrTpPortConnectionAttributes().getTsPool() != null
238 && ontTp1.getXpdrTpPortConnectionAttributes().getOdtuTpnPool() != null
239 && ontTp1.getXpdrTpPortConnectionAttributes().getOdtuTpnPool().get(0).getOdtuType()
240 .equals(ODTU4TsAllocated.class)
241 && ontTp1.getXpdrTpPortConnectionAttributes().getOdtuTpnPool().get(0).getTpnPool().isEmpty()
242 && (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 = sp.getOduSwitchingPools();
365 for (OduSwitchingPools ospx : osp) {
366 List<NonBlockingList> nbl = ospx.getNonBlockingList();
367 for (NonBlockingList nbll : nbl) {
368 if (nbll.getAvailableInterconnectBandwidth().toJava() >= neededBW && nbll.getTpList() != null
369 && nbll.getTpList().contains(tp1.getTpId()) && nbll.getTpList().contains(tp2.getTpId())) {
370 LOG.debug("validateSwitchingPoolBandwidth: couple of tp {} x {} valid for crossconnection",
371 tp1.getTpId(), tp2.getTpId());
377 LOG.debug("validateSwitchingPoolBandwidth: No valid Switching pool for crossconnecting tp {} and {}",
378 tp1.getTpId(), tp2.getTpId());
383 public void validateIntermediateSwitch() {
387 if (this.nodeType != OpenroadmNodeType.SWITCH) {
390 // Validate switch for use as an intermediate XPONDER on the path
391 initXndrTps("intermediate");
393 LOG.debug("validateIntermediateSwitch: Switch unusable for transit == {}", nodeId.getValue());
395 LOG.info("validateIntermediateSwitch: Switch usable for transit == {}", nodeId.getValue());
399 public void checkAvailableTribPort() {
400 List<TerminationPoint> networkTpList = node.augmentation(
401 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1.class)
402 .getTerminationPoint().stream()
405 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.TerminationPoint1.class)
406 .getTpType().equals(OpenroadmTpType.XPONDERNETWORK))
407 .collect(Collectors.toList());
409 for (TerminationPoint tp : networkTpList) {
410 if (tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes().getOdtuTpnPool() != null
411 && tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes().getOdtuTpnPool().get(0)
412 .getOdtuType().equals(ODTU4TsAllocated.class)) {
414 List<Uint16> tpnPool = tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes()
415 .getOdtuTpnPool().get(0).getTpnPool();
416 if (tpnPool != null) {
417 tpAvailableTribPort.put(tp.getTpId().getValue(), tpnPool);
423 public void checkAvailableTribSlot() {
424 List<TerminationPoint> networkTpList = node.augmentation(
425 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1.class)
426 .getTerminationPoint().stream()
429 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.TerminationPoint1.class)
430 .getTpType().equals(OpenroadmTpType.XPONDERNETWORK))
431 .collect(Collectors.toList());
433 for (TerminationPoint tp : networkTpList) {
434 if (tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes().getTsPool() != null) {
436 List<Uint16> tsPool = tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes()
438 tpAvailableTribSlot.put(tp.getTpId().getValue(), tsPool);
443 public boolean isValid() {
444 if ((node == null) || (nodeId == null) || (nodeType == null) || (this.getSupNetworkNodeId() == null)
445 || (this.getSupClliNodeId() == null)) {
446 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, supporting nodeId");
453 public void addOutgoingLink(PceLink outLink) {
454 this.outgoingLinks.add(outLink);
458 public List<PceLink> getOutgoingLinks() {
459 return outgoingLinks;
463 public String getXpdrClient(String tp) {
464 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());
477 public Map<String, List<Uint16>> getAvailableTribPorts() {
478 return tpAvailableTribPort;
482 public Map<String, List<Uint16>> 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) {
515 public NodeId getNodeId() {
520 public boolean checkTP(String tp) {
525 public boolean checkWL(long index) {