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.rev181130.xpdr.odu.switching.pools.OduSwitchingPools;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev181130.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingList;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmNodeType;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmTpType;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.xpdr.tp.supported.interfaces.SupportedInterfaceCapability;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev181130.ODTU4TsAllocated;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130.Node1;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130.TerminationPoint1;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130.networks.network.node.SwitchingPools;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev181130.If100GEODU4;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev181130.If10GEODU2e;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev181130.If1GEODU0;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev181130.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;
56 private Map<String, List<Uint16>> tpAvailableTribPort = new TreeMap<>();
57 private Map<String, List<Uint16>> tpAvailableTribSlot = new TreeMap<>();
58 private Map<String, OpenroadmTpType> availableXponderTp = new TreeMap<>();
59 private List<String> usedXpdrNWTps = new ArrayList<>();
60 private List<TpId> availableXpdrNWTps;
61 private List<TpId> usableXpdrNWTps;
62 private List<String> usedXpdrClientTps = new ArrayList<>();
63 private List<TpId> availableXpdrClientTps;
64 private List<TpId> usableXpdrClientTps;
66 private List<PceLink> outgoingLinks = new ArrayList<>();
67 private Map<String, String> clientPerNwTp = new HashMap<>();
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<>();
78 this.usableXpdrNWTps = new ArrayList<>();
79 this.usedXpdrClientTps.clear();
80 this.availableXpdrClientTps = new ArrayList<>();
81 this.usableXpdrClientTps = new ArrayList<>();
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);
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().isEmpty()
241 && (ontTp1.getXpdrTpPortConnectionAttributes().getTsPool().size() >= tsNb)) {
247 private boolean checkClientTp(TerminationPoint1 ontTp1) {
248 for (SupportedInterfaceCapability sic : ontTp1.getTpSupportedInterfaces().getSupportedInterfaceCapability()) {
249 LOG.debug("in checkTpForOduTermination - sic = {}", sic.getIfCapType());
250 switch (otnServiceType) {
252 // we could also check the administrative status of the tp
253 if (sic.getIfCapType().equals(If1GEODU0.class)) {
258 if (sic.getIfCapType().equals(If10GEODU2e.class)) {
263 if (sic.getIfCapType().equals(If100GEODU4.class)) {
274 public void validateXponder(String anodeId, String znodeId) {
278 if (OpenroadmNodeType.SWITCH.equals(this.nodeType)) {
279 initXndrTps("intermediate");
281 if (this.nodeId.getValue().equals(anodeId) || (this.nodeId.getValue().equals(znodeId))) {
284 LOG.info("validateAZxponder: XPONDER is ignored == {}", nodeId.getValue());
289 public boolean validateSwitchingPoolBandwidth(
290 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
291 .ietf.network.topology.rev180226.networks.network.node.TerminationPoint tp1,
292 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
293 .ietf.network.topology.rev180226.networks.network.node.TerminationPoint tp2,
295 if (this.nodeType != OpenroadmNodeType.TPDR) {
298 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130.Node1 node1 =
300 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130.Node1.class);
301 SwitchingPools sp = node1.getSwitchingPools();
302 List<OduSwitchingPools> osp = sp.getOduSwitchingPools();
303 for (OduSwitchingPools ospx : osp) {
304 List<NonBlockingList> nbl = ospx.getNonBlockingList();
305 for (NonBlockingList nbll : nbl) {
306 if (nbll.getAvailableInterconnectBandwidth().toJava() >= neededBW && nbll.getTpList() != null
307 && nbll.getTpList().contains(tp1.getTpId()) && nbll.getTpList().contains(tp2.getTpId())) {
308 LOG.debug("validateSwitchingPoolBandwidth: couple of tp {} x {} valid for crossconnection",
309 tp1.getTpId(), tp2.getTpId());
315 LOG.debug("validateSwitchingPoolBandwidth: No valid Switching pool for crossconnecting tp {} and {}",
316 tp1.getTpId(), tp2.getTpId());
321 public void validateIntermediateSwitch() {
325 if (this.nodeType != OpenroadmNodeType.SWITCH) {
328 // Validate switch for use as an intermediate XPONDER on the path
329 initXndrTps("intermediate");
331 LOG.debug("validateIntermediateSwitch: Switch unusable for transit == {}", nodeId.getValue());
333 LOG.info("validateIntermediateSwitch: Switch usable for transit == {}", nodeId.getValue());
337 public void checkAvailableTribPort() {
338 List<TerminationPoint> networkTpList = node.augmentation(
339 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1.class)
340 .getTerminationPoint().stream()
343 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.TerminationPoint1.class)
344 .getTpType().equals(OpenroadmTpType.XPONDERNETWORK))
345 .collect(Collectors.toList());
347 for (TerminationPoint tp : networkTpList) {
348 if (tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes().getOdtuTpnPool() != null
349 && tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes().getOdtuTpnPool().get(0)
350 .getOdtuType().equals(ODTU4TsAllocated.class)) {
352 List<Uint16> tpnPool = tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes()
353 .getOdtuTpnPool().get(0).getTpnPool();
354 if (tpnPool != null) {
355 tpAvailableTribPort.put(tp.getTpId().getValue(), tpnPool);
361 public void checkAvailableTribSlot() {
362 List<TerminationPoint> networkTpList = node.augmentation(
363 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1.class)
364 .getTerminationPoint().stream()
367 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.TerminationPoint1.class)
368 .getTpType().equals(OpenroadmTpType.XPONDERNETWORK))
369 .collect(Collectors.toList());
371 for (TerminationPoint tp : networkTpList) {
372 if (tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes().getTsPool() != null) {
374 List<Uint16> tsPool = tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes()
376 tpAvailableTribSlot.put(tp.getTpId().getValue(), tsPool);
381 public boolean isValid() {
382 if ((node == null) || (nodeId == null) || (nodeType == null) || (this.getSupNetworkNodeId() == null)
383 || (this.getSupClliNodeId() == null)) {
384 LOG.error("PceNode: one of parameters is not populated : nodeId, node type, supporting nodeId");
391 public void addOutgoingLink(PceLink outLink) {
392 this.outgoingLinks.add(outLink);
396 public List<PceLink> getOutgoingLinks() {
397 return outgoingLinks;
401 public String getXpdrClient(String tp) {
402 return this.clientPerNwTp.get(tp);
406 public String toString() {
407 return "PceNode type=" + nodeType + " ID=" + nodeId.getValue() + " CLLI=" + this.getSupClliNodeId();
410 public void printLinksOfNode() {
411 LOG.info(" outgoing links of node {} : {} ", nodeId.getValue(), this.getOutgoingLinks());
415 public Map<String, List<Uint16>> getAvailableTribPorts() {
416 return tpAvailableTribPort;
420 public Map<String, List<Uint16>> getAvailableTribSlots() {
421 return tpAvailableTribSlot;
424 public List<TpId> getUsableXpdrNWTps() {
425 return usableXpdrNWTps;
428 public List<TpId> getUsableXpdrClientTps() {
429 return usableXpdrClientTps;
433 public String getPceNodeType() {
434 return this.pceNodeType;
438 public String getSupNetworkNodeId() {
439 return MapUtils.getSupNetworkNode(this.node);
443 public String getSupClliNodeId() {
444 return MapUtils.getSupClliNode(this.node);
448 public String getRdmSrgClient(String tp) {
453 public NodeId getNodeId() {
458 public boolean checkTP(String tp) {
463 public boolean checkWL(long index) {