2 * Copyright © 2017 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
10 package org.opendaylight.transportpce.stubpce.topology;
12 import com.google.common.collect.Lists;
14 import java.util.ArrayList;
15 import java.util.List;
16 import java.util.ListIterator;
18 import org.opendaylight.transportpce.stubpce.TpNodeTp;
19 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.AToZDirection;
20 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.AToZDirectionBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ZToADirection;
22 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ZToADirectionBuilder;
23 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.atoz.direction.AToZ;
24 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.atoz.direction.AToZBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.atoz.direction.AToZKey;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ztoa.direction.ZToA;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ztoa.direction.ZToABuilder;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ztoa.direction.ZToAKey;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.Resource;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.ResourceBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.Link;
32 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.LinkBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.TerminationPoint;
34 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.link.LinkIdentifierBuilder;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
39 * class to build all path between superNode elements
42 * @author <a href="mailto:martial.coulibaly@gfi.com">Martial Coulibaly</a> on
46 public class InterNodePath {
48 private static final Logger LOG = LoggerFactory.getLogger(InterNodePath.class);
49 private SuperNode superNode;
50 private List<NodePath> nodepaths;
51 private List<AToZDirection> atoz;
52 private List<ZToADirection> ztoa;
55 * InterNodePath constructor.
57 * @param supernode Supernode
59 public InterNodePath(SuperNode supernode) {
60 setSuperNode(supernode);
61 setNodepaths(new ArrayList<NodePath>());
62 setAtoz(new ArrayList<AToZDirection>());
63 setZtoa(new ArrayList<ZToADirection>());
67 * build AToZdirection.
69 * @param paths <code>Path</code> List
71 private void getAToZDirection(List<Path> paths) {
73 AToZDirectionBuilder atozDirection = new AToZDirectionBuilder();
74 List<AToZ> atozList = new ArrayList<AToZ>();
76 for (Path path : paths) {
77 tpNodeTp = path.getTpNodeTp();
78 tpNodeTp.createAToZListHop(order);
79 for (AToZ atoz : tpNodeTp.getAToZ()) {
83 Link link = path.getLink();
84 AToZKey atozKey = new AToZKey(Integer.toString(order));
85 Resource resource = new ResourceBuilder().setResource(link).build();
86 AToZ hop = new AToZBuilder().setId(atozKey.getId()).setKey(atozKey).setResource(resource).build();
90 atozDirection.setRate((long) 100).setAToZWavelengthNumber((long) 200).setAToZ(atozList);
91 atoz.add(atozDirection.build());
95 * build ZToAdirection.
97 * @param paths <code>Path</code> List
99 private void getZToADirection(List<Path> paths) {
101 ZToADirectionBuilder ztoaDirection = new ZToADirectionBuilder();
102 List<ZToA> ztoaList = new ArrayList<ZToA>();
104 for (Path path : paths) {
105 tpNodeTp = path.getTpNodeTp();
106 tpNodeTp.createZToAListHop(order);
107 for (ZToA ztoa : tpNodeTp.getZToA()) {
111 Link link = path.getLink();
112 ZToAKey ztoaKey = new ZToAKey(Integer.toString(order));
113 Resource resource = new ResourceBuilder().setResource(link).build();
114 ZToA hop = new ZToABuilder().setId(ztoaKey.getId()).setKey(ztoaKey).setResource(resource).build();
118 ztoaDirection.setRate((long) 100).setZToAWavelengthNumber((long) 200).setZToA(ztoaList);
119 ztoa.add(ztoaDirection.build());
123 * Build direction path
124 * for all Supernode elements.
126 * @param skip Boolean to specify an ROADM without XPDR
127 * @param nodeId Supernode element nodeId
128 * @param zend Supernode path ZEnd nodeId
130 public void build(Boolean skip, String nodeId,String zend) {
131 LOG.info("Building direction ...");
133 buildDegToDeg(false);
136 boolean reverse = false;
137 if (nodeId.contains(zend)) {
140 NodePath xpdr = null;
142 NodePath deg1 = null;
143 NodePath deg2 = null;
144 for (NodePath node : nodepaths) {
145 //LOG.info(node.toString());
146 String id = node.getNodeId();
147 if (id.contains("XPDR")) {
150 if (id.contains("SRG")) {
153 if (id.contains("DEG1")) {
156 if (id.contains("DEG2")) {
160 buildXpdrToSrgToDeg(xpdr,srg,deg1,deg2,reverse);
161 buildDegToSrgToXpdr(xpdr,srg,deg1,deg2,reverse);
166 * build direction path for
167 * Supernode element DEG1, DEG2.
169 * @param twotoOne boolean to determine direction
171 private void buildDegToDeg(boolean twotoOne) {
172 LOG.info("buildDegToDeg ...");
173 NodePath deg1 = null;
174 NodePath deg2 = null;
175 for (NodePath node : nodepaths) {
176 //LOG.info(node.toString());
177 String nodeId = node.getNodeId();
178 if (nodeId.contains("DEG1")) {
181 if (nodeId.contains("DEG2")) {
185 if (deg1 != null && deg2 != null) {
186 List<Path> result = new ArrayList<Path>();
193 for (Path deg1Path : deb.getPath()) {
194 TpNodeTp tmpdeg = deg1Path.getTpNodeTp();
195 if (tmpdeg.getTpIn().getTerminationPointIdentifier().getTpId().contains("TTP")) {
197 result.addAll(Lists.newArrayList(deg1Path));
199 getAToZDirection(result);
201 getZToADirection(result);
205 for (Path deg2Path : end.getPath()) {
206 TpNodeTp tmpdeg = deg2Path.getTpNodeTp();
207 if (tmpdeg.getTpIn().getTerminationPointIdentifier().getTpId().contains("CTP")) {
209 result.addAll(Lists.newArrayList(deg2Path));
211 getAToZDirection(result);
213 getZToADirection(result);
218 LOG.info("deg1 or/and deg2 is null !");
224 *Degree to SRG to XPDR
225 *in Supernode elements.
227 *@param xpdr NodePath XPDR
228 *@param srg NodePath SRG
229 *@param deg NodePath Degree
230 *@param reverse boolean to determine the direction
232 private void buildDeg(NodePath xpdr,NodePath srg,NodePath deg, Boolean reverse) {
233 List<Path> result = new ArrayList<Path>();
234 for (Path degPath : deg.getPath()) {
235 TpNodeTp tmpdeg = degPath.getTpNodeTp();
236 if (tmpdeg.getTpIn().getTerminationPointIdentifier().getTpId().contains("TTP")) {
237 for (Path srgPath : srg.getPath()) {
238 TpNodeTp tmpsrg = srgPath.getTpNodeTp();
239 if (tmpsrg.getTpIn().getTerminationPointIdentifier().getTpId().contains("CP")) {
240 for (Path xpdrPath : xpdr.getPath()) {
241 TpNodeTp tmpxpdr = xpdrPath.getTpNodeTp();
242 if (tmpxpdr.getTpIn().getTerminationPointIdentifier().getTpId().contains("NETWORK")) {
244 result.addAll(Lists.newArrayList(degPath,srgPath,xpdrPath));
246 getAToZDirection(result);
248 getZToADirection(result);
259 *build direction from
260 *DEG1 / DEG2 to SRG to XPDR
261 *in Supernode elements.
263 *@param xpdr NodePath XPDR
264 *@param srg NodePath SRG
265 *@param deg1 NodePath Degree 1
266 *@param deg2 NodePath Degree 2
267 *@param reverse boolean to determine the direction
269 private void buildDegToSrgToXpdr(NodePath xpdr,NodePath srg,NodePath deg1,NodePath deg2,boolean reverse) {
270 LOG.info("buildDegToSrgToXpr ...");
271 if (xpdr != null && srg != null && deg1 != null && deg2 != null) {
272 buildDeg(xpdr, srg, deg1, reverse);
273 buildDeg(xpdr, srg, deg2, reverse);
275 LOG.info("xpdr, deg or/and srg is null !");
280 *build direction from
282 *in Supernode elements.
284 *@param xpdr NodePath XPDR
285 *@param srg NodePath SRG
286 *@param deg1 NodePath Degree 1
287 *@param deg2 NodePath Degree 2
288 *@param reverse boolean to determine the direction
290 private void buildXpdrToSrgToDeg(NodePath xpdr,NodePath srg,NodePath deg1,NodePath deg2,boolean reverse) {
291 LOG.info("buildXpdrToSrgToDeg ...");
292 if (xpdr != null && srg != null && deg1 != null && deg2 != null) {
293 List<Path> result = new ArrayList<Path>();
294 for (Path xpdrPath : xpdr.getPath()) {
295 TpNodeTp tmpxpdr = xpdrPath.getTpNodeTp();
296 if (tmpxpdr.getTpIn().getTerminationPointIdentifier().getTpId().contains("CLIENT")) {
297 for (Path srgPath : srg.getPath()) {
298 TpNodeTp tmp = srgPath.getTpNodeTp();
299 Link srglink = srgPath.getLink();
300 if (tmp.getTpIn().getTerminationPointIdentifier().getTpId().contains("PP")) {
301 for (Path deg1Path : deg1.getPath()) {
302 TpNodeTp tmpdeg = deg1Path.getTpNodeTp();
303 if (tmpdeg.getTpIn().getTerminationPointIdentifier().getTpId().contains("CTP")
304 && srglink.getLinkIdentifier().getLinkId().contains("DEG1")) {
306 result.addAll(Lists.newArrayList(xpdrPath,srgPath,deg1Path));
308 getZToADirection(result);
310 getAToZDirection(result);
314 for (Path deg2Path : deg2.getPath()) {
315 TpNodeTp tmpdeg = deg2Path.getTpNodeTp();
316 if (tmpdeg.getTpIn().getTerminationPointIdentifier().getTpId().contains("CTP")
317 && srglink.getLinkIdentifier().getLinkId().contains("DEG2")) {
319 result.addAll(Lists.newArrayList(xpdrPath,srgPath,deg2Path));
321 getZToADirection(result);
323 getAToZDirection(result);
332 LOG.info("xpdr, deg or/and srg is null !");
337 * get all AToZdirection containing
338 * a list of <code>AToZ</code> end by
341 * @param endBy String
342 * @param atozDirection AToZdirection List
343 * @param index Integer to determine if it for last Link(1) or last TerminationPoint(2)
344 * @return <code>AToZDirection</code> List
346 public List<AToZDirection> getAToZDirectionEndBy(String endBy, List<AToZDirection> atozDirection, int index) {
347 List<AToZDirection> result = new ArrayList<AToZDirection>();
348 for (AToZDirection tmp : atozDirection) {
349 List<AToZ> atozList = tmp.getAToZ();
350 int size = atozList.size();
352 String id = Integer.toString(size - index);
353 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription
354 .rev170426.pce.resource.resource.Resource res = null;
355 for (AToZ atoz : atozList) {
356 if (atoz.getId().compareTo(id) == 0) {
357 res = atoz.getResource().getResource();
362 if (res instanceof Link) {
363 Link tp = (Link) res;
364 if (tp != null && tp.getLinkIdentifier().getLinkId().contains(endBy)) {
371 if (res instanceof TerminationPoint) {
372 TerminationPoint tp = (TerminationPoint) res;
373 if (tp != null && tp.getTerminationPointIdentifier().getTpId()
387 LOG.info("firstnodeTpId is null !");
390 LOG.info("getAToZDirectionEndBy result size : {}\n{}", result.size(),result.toString());
395 * replace or remove in
396 * Link in <code>AToZ</code> list
397 * containing in AToZdirection.
399 * @param endBy String
400 * @param beginBy String
401 * @param atozLink name of ROAMDTOROAMD link
402 * @param atozDirection AToZdirection List
403 * @param remove boolean to determine if removing or not
404 * @return <code>AToZDirection</code> List
406 public List<AToZDirection> replaceOrRemoveAToZDirectionEndLink(String endBy,String beginBy,String atozLink,
407 List<AToZDirection> atozDirection, boolean remove) {
408 List<AToZDirection> result = new ArrayList<AToZDirection>();
409 List<AToZDirection> tmp = new ArrayList<AToZDirection>();
411 tmp = getAToZDirectionEndBy(endBy, atozDirection, 1);
412 if (!tmp.isEmpty()) {
413 tmp = getAToZDirectionBeginBy(beginBy, tmp);
416 tmp = getAToZDirectionEndBy(endBy, atozDirection,2);
418 if (!tmp.isEmpty()) {
419 for (AToZDirection atozdir : tmp) {
420 List<AToZ> atozList = atozdir.getAToZ();
421 int size = atozList.size();
423 String id = Integer.toString(size - 1);
424 for (ListIterator<AToZ> it = atozList.listIterator(); it.hasNext();) {
425 AToZ atoz = it.next();
426 if (atoz.getId().compareTo(id) == 0) {
427 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription
428 .rev170426.pce.resource.resource.Resource res = atoz.getResource().getResource();
429 if (res != null && res instanceof Link) {
430 Link link = new LinkBuilder()
431 .setLinkIdentifier(new LinkIdentifierBuilder()
435 AToZKey atozKey = new AToZKey(atoz.getKey());
436 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
437 .pathdescription.rev170426.pce.resource.Resource resource = new ResourceBuilder()
438 .setResource(link).build();
439 AToZ hop = new AToZBuilder().setId(atozKey.getId()).setKey(atozKey)
440 .setResource(resource).build();
452 LOG.info("getAToZDirectionEndBy size : {}", tmp.size());
458 *get all AToZdirection containing
459 * a list of <code>AToZ</code> begin by
462 * @param beginBy String
463 * @param atozDirection AToZdirection List
464 * @return <code>AToZDirection</code> List
466 public List<AToZDirection> getAToZDirectionBeginBy(String beginBy, List<AToZDirection> atozDirection) {
467 List<AToZDirection> result = new ArrayList<AToZDirection>();
468 for (AToZDirection tmp : atozDirection) {
469 List<AToZ> atozList = tmp.getAToZ();
470 int size = atozList.size();
472 String id = Integer.toString(0);
473 for (AToZ atoz : atozList) {
474 if (atoz.getId().compareTo(id) == 0) {
475 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription
476 .rev170426.pce.resource.resource.Resource res = atoz.getResource().getResource();
477 if (res != null && res instanceof TerminationPoint) {
478 TerminationPoint tp = (TerminationPoint) res;
479 if (tp != null && tp.getTerminationPointIdentifier().getTpId().contains(beginBy)) {
480 LOG.info("tmp : {}", tmp.toString());
488 LOG.info("result size : {}", result.size());
493 * first launch process to
494 * build/fill <code>NodePath</code>
495 * And after that, start building
496 * direction between Supernode
499 * @param zend path zend Supernode nodeId
501 public void buildPath(String zend) {
502 if (superNode != null) {
503 for (org.opendaylight.transportpce.stubpce.topology.Resource res : superNode.getResources()) {
504 NodePath path = new NodePath(res, superNode.getSuperNodeId(), superNode.isXpdrSrgAbsent());
508 LOG.info("nodepaths size : {}", nodepaths.size());
509 build(superNode.isXpdrSrgAbsent(),superNode.getSuperNodeId(), zend);
513 public static void main(String[] args) {
514 Topology topo = new Topology();
516 Network net = topo.getNetwork();
518 SuperNode res = net.getSuperNodes().get(0);
519 String zend = "NodeZ";
520 LOG.info(res.getSuperNodeId().toString());
521 InterNodePath path = new InterNodePath(res);
522 path.buildPath(zend);
526 public SuperNode getSuperNode() {
530 public void setSuperNode(SuperNode superNode) {
531 this.superNode = superNode;
534 public List<AToZDirection> getAtoz() {
538 public void setAtoz(List<AToZDirection> atoz) {
542 public List<ZToADirection> getZtoa() {
546 public void setZtoa(List<ZToADirection> ztoa) {
550 public List<NodePath> getNodepaths() {
554 public void setNodepaths(List<NodePath> nodepaths) {
555 this.nodepaths = nodepaths;