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;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev200327.xpdr.odu.switching.pools.OduSwitchingPools;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev200327.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingList;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmNodeType;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmTpType;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.xpdr.tp.supported.interfaces.SupportedInterfaceCapability;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODTU4TsAllocated;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529.Node1;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529.TerminationPoint1;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529.networks.network.node.SwitchingPools;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If100GEODU4;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If10GEODU2e;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If1GEODU0;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.IfOCHOTU4ODU4;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.TpId;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPoint;
36 import org.opendaylight.yangtools.yang.common.Uint16;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
40 public class PceOtnNode implements PceNode {
42 private static final Logger LOG = LoggerFactory.getLogger(PceOtnNode.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;
55 private String modeType;
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();
100 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp
101 = this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
102 .ietf.network.topology.rev180226.Node1.class);
103 List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
104 .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
106 if (allTps.isEmpty()) {
107 LOG.error("PceOtnNode: initXndrTps: XPONDER TerminationPoint list is empty for node {}", this);
111 for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
112 .node.TerminationPoint tp : allTps) {
113 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.@Nullable TerminationPoint1 ocnTp1
114 = tp.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529
115 .TerminationPoint1.class);
116 //TODO many nested if-structures below, this needs to be reworked
117 if (OpenroadmTpType.XPONDERNETWORK.equals(ocnTp1.getTpType()) && this.otnServiceType.equals("ODU4")) {
118 TerminationPoint1 ontTp1;
119 if (tp.augmentation(TerminationPoint1.class) != null) {
120 ontTp1 = tp.augmentation(TerminationPoint1.class);
124 if (checkTpForOdtuTermination(ontTp1)) {
125 LOG.info("TP {} of XPONDER {} is validated", tp.getTpId(), node.getNodeId().getValue());
126 this.availableXpdrNWTps.add(tp.getTpId());
128 LOG.error("TP {} of {} does not allow ODU4 termination creation", tp.getTpId().getValue(),
129 node.getNodeId().getValue());
131 } else if (OpenroadmTpType.XPONDERNETWORK.equals(ocnTp1.getTpType())
132 && (this.otnServiceType.equals("10GE") || this.otnServiceType.equals("1GE"))) {
133 TerminationPoint1 ontTp1;
134 if (tp.augmentation(TerminationPoint1.class) != null) {
135 ontTp1 = tp.augmentation(TerminationPoint1.class);
139 if ("10GE".equals(otnServiceType) && checkOdtuTTPforLoOduCreation(ontTp1, 10)
140 || "1GE".equals(otnServiceType) && checkOdtuTTPforLoOduCreation(ontTp1, 1)) {
141 LOG.info("TP {} of XPONDER {} is validated", tp.getTpId(), node.getNodeId().getValue());
142 this.availableXpdrNWTps.add(tp.getTpId());
144 if ("10GE".equals(otnServiceType)) {
145 LOG.error("TP {} of {} does not allow OD2e termination creation", tp.getTpId().getValue(),
146 node.getNodeId().getValue());
147 } else if ("1GE".equals(otnServiceType)) {
148 LOG.error("TP {} of {} does not allow ODU0 termination creation", tp.getTpId().getValue(),
149 node.getNodeId().getValue());
151 LOG.error("TP {} of {} does not allow any termination creation", tp.getTpId().getValue(),
152 node.getNodeId().getValue());
155 } else if (OpenroadmTpType.XPONDERCLIENT.equals(ocnTp1.getTpType())
156 && (this.otnServiceType.equals("10GE") || this.otnServiceType.equals("1GE"))) {
157 TerminationPoint1 ontTp1;
158 if (tp.augmentation(TerminationPoint1.class) != null) {
159 ontTp1 = tp.augmentation(TerminationPoint1.class);
163 if (checkClientTp(ontTp1)) {
164 LOG.info("TP {} of XPONDER {} is validated", tp.getTpId(), node.getNodeId().getValue());
165 this.availableXpdrClientTps.add(tp.getTpId());
167 LOG.error("TP {} of {} does not allow lo-ODU (ODU2e or ODU0) termination creation",
168 tp.getTpId().getValue(), node.getNodeId().getValue());
173 if ((this.otnServiceType.equals("ODU4") && mode.equals("AZ"))
174 || ((this.otnServiceType.equals("10GE") || this.otnServiceType.equals("1GE"))
175 && ((mode.equals("AZ") && checkSwPool(availableXpdrClientTps, availableXpdrNWTps, 1, 1))
176 || (mode.equals("intermediate") && checkSwPool(null, availableXpdrNWTps, 0, 2)))
184 private boolean checkSwPool(List<TpId> clientTps, List<TpId> netwTps, int nbClient, int nbNetw) {
185 if (clientTps != null && netwTps != null && nbClient == 1 && nbNetw == 1) {
186 clientTps.sort(Comparator.comparing(TpId::getValue));
187 netwTps.sort(Comparator.comparing(TpId::getValue));
188 for (TpId nwTp : netwTps) {
189 for (TpId clTp : clientTps) {
191 List<NonBlockingList> nblList = new ArrayList<>(node.augmentation(Node1.class).getSwitchingPools()
192 .nonnullOduSwitchingPools().values().stream().findFirst().get().getNonBlockingList().values());
193 for (NonBlockingList nbl : nblList) {
194 if (nbl.getTpList().contains(clTp) && nbl.getTpList().contains(nwTp)) {
195 usableXpdrClientTps.add(clTp);
196 usableXpdrNWTps.add(nwTp);
198 if (usableXpdrClientTps.size() >= nbClient && usableXpdrNWTps.size() >= nbNetw) {
199 clientPerNwTp.put(nwTp.getValue(), clTp.getValue());
207 if (clientTps == null && netwTps != null && nbClient == 0 && nbNetw == 2) {
208 netwTps.sort(Comparator.comparing(TpId::getValue));
210 List<NonBlockingList> nblList = new ArrayList<>(node.augmentation(Node1.class).getSwitchingPools()
211 .nonnullOduSwitchingPools().values().stream().findFirst().get().getNonBlockingList().values());
212 for (NonBlockingList nbl : nblList) {
213 for (TpId nwTp : netwTps) {
214 if (nbl.getTpList().contains(nwTp)) {
215 usableXpdrNWTps.add(nwTp);
217 if (usableXpdrNWTps.size() >= nbNetw) {
226 private boolean checkTpForOdtuTermination(TerminationPoint1 ontTp1) {
227 for (SupportedInterfaceCapability sic : ontTp1.getTpSupportedInterfaces().getSupportedInterfaceCapability()
229 LOG.debug("in checkTpForOduTermination - sic = {}", sic.getIfCapType());
230 if (sic.getIfCapType().equals(IfOCHOTU4ODU4.class)
231 && ontTp1.getXpdrTpPortConnectionAttributes().getTsPool() == null) {
238 private boolean checkOdtuTTPforLoOduCreation(TerminationPoint1 ontTp1, int tsNb) {
239 if (ontTp1.getXpdrTpPortConnectionAttributes() != null
240 && ontTp1.getXpdrTpPortConnectionAttributes().getTsPool() != null
241 && ontTp1.getXpdrTpPortConnectionAttributes().getOdtuTpnPool() != null
242 && ontTp1.getXpdrTpPortConnectionAttributes().getOdtuTpnPool().values()
243 .stream().findFirst().get().getOdtuType()
244 .equals(ODTU4TsAllocated.class)
245 && !ontTp1.getXpdrTpPortConnectionAttributes().getOdtuTpnPool().values()
246 .stream().findFirst().get().getTpnPool().isEmpty()
247 && (ontTp1.getXpdrTpPortConnectionAttributes().getTsPool().size() >= tsNb)) {
253 private boolean checkClientTp(TerminationPoint1 ontTp1) {
254 for (SupportedInterfaceCapability sic : ontTp1.getTpSupportedInterfaces().getSupportedInterfaceCapability()
256 LOG.debug("in checkTpForOduTermination - sic = {}", sic.getIfCapType());
257 switch (otnServiceType) {
259 // we could also check the administrative status of the tp
260 if (sic.getIfCapType().equals(If1GEODU0.class)) {
265 if (sic.getIfCapType().equals(If10GEODU2e.class)) {
270 if (sic.getIfCapType().equals(If100GEODU4.class)) {
281 public void validateXponder(String anodeId, String znodeId) {
285 if (OpenroadmNodeType.SWITCH.equals(this.nodeType)) {
286 initXndrTps("intermediate");
288 if (this.nodeId.getValue().equals(anodeId) || (this.nodeId.getValue().equals(znodeId))) {
291 LOG.info("validateAZxponder: XPONDER is ignored == {}", nodeId.getValue());
296 public boolean validateSwitchingPoolBandwidth(
297 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
298 .ietf.network.topology.rev180226.networks.network.node.TerminationPoint tp1,
299 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
300 .ietf.network.topology.rev180226.networks.network.node.TerminationPoint tp2,
302 if (this.nodeType != OpenroadmNodeType.TPDR) {
305 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529.Node1 node1 =
307 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529.Node1.class);
308 SwitchingPools sp = node1.getSwitchingPools();
309 List<OduSwitchingPools> osp = new ArrayList<>(sp.nonnullOduSwitchingPools().values());
310 for (OduSwitchingPools ospx : osp) {
311 List<NonBlockingList> nbl = new ArrayList<>(ospx.nonnullNonBlockingList().values());
312 for (NonBlockingList nbll : nbl) {
313 if (nbll.getAvailableInterconnectBandwidth().toJava() >= neededBW && nbll.getTpList() != null
314 && nbll.getTpList().contains(tp1.getTpId()) && nbll.getTpList().contains(tp2.getTpId())) {
315 LOG.debug("validateSwitchingPoolBandwidth: couple of tp {} x {} valid for crossconnection",
316 tp1.getTpId(), tp2.getTpId());
322 LOG.debug("validateSwitchingPoolBandwidth: No valid Switching pool for crossconnecting tp {} and {}",
323 tp1.getTpId(), tp2.getTpId());
328 public void validateIntermediateSwitch() {
332 if (this.nodeType != OpenroadmNodeType.SWITCH) {
335 // Validate switch for use as an intermediate XPONDER on the path
336 initXndrTps("intermediate");
338 LOG.debug("validateIntermediateSwitch: Switch unusable for transit == {}", nodeId.getValue());
340 LOG.info("validateIntermediateSwitch: Switch usable for transit == {}", nodeId.getValue());
344 public void checkAvailableTribPort() {
345 List<TerminationPoint> networkTpList = node.augmentation(
346 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1.class)
347 .getTerminationPoint().values().stream()
350 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.TerminationPoint1.class)
351 .getTpType().equals(OpenroadmTpType.XPONDERNETWORK))
352 .collect(Collectors.toList());
354 for (TerminationPoint tp : networkTpList) {
355 if (tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes().getOdtuTpnPool() != null
356 && tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes().getOdtuTpnPool()
357 .values().stream().findFirst().get().getOdtuType().equals(ODTU4TsAllocated.class)) {
359 List<Uint16> tpnPool = tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes()
360 .getOdtuTpnPool().values().stream().findFirst().get().getTpnPool();
361 if (tpnPool != null) {
362 tpAvailableTribPort.put(tp.getTpId().getValue(), tpnPool);
368 public void checkAvailableTribSlot() {
369 List<TerminationPoint> networkTpList = node.augmentation(
370 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1.class)
371 .getTerminationPoint().values().stream()
374 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.TerminationPoint1.class)
375 .getTpType().equals(OpenroadmTpType.XPONDERNETWORK))
376 .collect(Collectors.toList());
378 for (TerminationPoint tp : networkTpList) {
379 if (tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes().getTsPool() != null) {
381 List<Uint16> tsPool = tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes()
383 tpAvailableTribSlot.put(tp.getTpId().getValue(), tsPool);
388 public boolean isValid() {
389 if ((node == null) || (nodeId == null) || (nodeType == null) || (this.getSupNetworkNodeId() == null)
390 || (this.getSupClliNodeId() == null)) {
391 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, supporting nodeId");
397 public boolean isPceOtnNodeValid(final PceOtnNode pceOtnNode) {
398 if (pceOtnNode == null || pceOtnNode.node == null
399 || pceOtnNode.getNodeId() == null || pceOtnNode.nodeType == null || pceOtnNode.getSupNetworkNodeId() == null
400 || pceOtnNode.getSupClliNodeId() == null || pceOtnNode.otnServiceType == null) {
402 "PceOtnNode: one of parameters is not populated : nodeId, node type, supporting nodeId, otnServiceType"
407 if (!isNodeTypeValid(pceOtnNode)) {
408 LOG.error("PceOtnNode node type: node type isn't one of MUXPDR or SWITCH or TPDR");
412 return isOtnServiceTypeValid(pceOtnNode);
415 private boolean isOtnServiceTypeValid(PceOtnNode pceOtnNode) {
416 if (pceOtnNode.modeType == null) {
420 //Todo refactor Strings (mode and otnServiceType ) to enums
421 if ((pceOtnNode.otnServiceType.equals("ODU4") && pceOtnNode.modeType.equals("AZ"))) {
425 if ((pceOtnNode.otnServiceType.equals("10GE") || pceOtnNode.otnServiceType.equals("1GE"))
426 && (isAz(pceOtnNode) || isIntermediate(pceOtnNode))) {
433 private boolean isIntermediate(PceOtnNode pceOtnNode) {
434 return pceOtnNode.modeType.equals("intermediate")
435 && checkSwPool(null, pceOtnNode.availableXpdrNWTps, 0, 2);
438 private boolean isAz(PceOtnNode pceOtnNode) {
439 return pceOtnNode.modeType.equals("AZ")
440 && checkSwPool(pceOtnNode.availableXpdrClientTps, pceOtnNode.availableXpdrNWTps, 1, 1);
443 private boolean isNodeTypeValid(final PceOtnNode pceOtnNode) {
444 return (pceOtnNode.nodeType == OpenroadmNodeType.MUXPDR)
445 || (pceOtnNode.nodeType == OpenroadmNodeType.SWITCH)
446 || (pceOtnNode.nodeType == OpenroadmNodeType.TPDR);
450 public void addOutgoingLink(PceLink outLink) {
451 this.outgoingLinks.add(outLink);
455 public List<PceLink> getOutgoingLinks() {
456 return outgoingLinks;
460 public String getXpdrClient(String tp) {
461 return this.clientPerNwTp.get(tp);
465 public String toString() {
466 return "PceNode type=" + nodeType + " ID=" + nodeId.getValue() + " CLLI=" + this.getSupClliNodeId();
469 public void printLinksOfNode() {
470 LOG.info(" outgoing links of node {} : {} ", nodeId.getValue(), this.getOutgoingLinks());
474 public Map<String, List<Uint16>> getAvailableTribPorts() {
475 return tpAvailableTribPort;
479 public Map<String, List<Uint16>> getAvailableTribSlots() {
480 return tpAvailableTribSlot;
483 public List<TpId> getUsableXpdrNWTps() {
484 return usableXpdrNWTps;
487 public List<TpId> getUsableXpdrClientTps() {
488 return usableXpdrClientTps;
492 public String getPceNodeType() {
493 return this.pceNodeType;
497 public String getSupNetworkNodeId() {
498 return MapUtils.getSupNetworkNode(this.node);
502 public String getSupClliNodeId() {
503 return MapUtils.getSupClliNode(this.node);
507 public String getRdmSrgClient(String tp) {
512 public NodeId getNodeId() {
517 public boolean checkTP(String tp) {
522 public boolean checkWL(long index) {