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.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
38 * class to build all path between superNode elements
41 * @author <a href="mailto:martial.coulibaly@gfi.com">Martial Coulibaly</a> on
45 public class InterNodePath {
47 private static final Logger LOG = LoggerFactory.getLogger(InterNodePath.class);
48 private SuperNode superNode;
49 private List<NodePath> nodepaths;
50 private List<AToZDirection> atoz;
51 private List<ZToADirection> ztoa;
54 * InterNodePath constructor.
56 * @param supernode Supernode
58 public InterNodePath(SuperNode supernode) {
59 setSuperNode(supernode);
60 setNodepaths(new ArrayList<NodePath>());
61 setAtoz(new ArrayList<AToZDirection>());
62 setZtoa(new ArrayList<ZToADirection>());
66 * build AToZdirection.
68 * @param paths <code>Path</code> List
70 private void getAToZDirection(List<Path> paths) {
72 AToZDirectionBuilder atozDirection = new AToZDirectionBuilder();
73 List<AToZ> atozList = new ArrayList<AToZ>();
75 for (Path path : paths) {
76 tpNodeTp = path.getTpNodeTp();
77 tpNodeTp.createAToZListHop(order);
78 for (AToZ atoz : tpNodeTp.getAToZ()) {
82 Link link = path.getLink();
83 AToZKey atozKey = new AToZKey(Integer.toString(order));
84 Resource resource = new ResourceBuilder().setResource(link).build();
85 AToZ hop = new AToZBuilder().setId(atozKey.getId()).setKey(atozKey).setResource(resource).build();
89 atozDirection.setRate((long) 100).setAToZWavelengthNumber((long) 200).setAToZ(atozList);
90 atoz.add(atozDirection.build());
94 * build ZToAdirection.
96 * @param paths <code>Path</code> List
98 private void getZToADirection(List<Path> paths) {
100 ZToADirectionBuilder ztoaDirection = new ZToADirectionBuilder();
101 List<ZToA> ztoaList = new ArrayList<ZToA>();
103 for (Path path : paths) {
104 tpNodeTp = path.getTpNodeTp();
105 tpNodeTp.createZToAListHop(order);
106 for (ZToA ztoa : tpNodeTp.getZToA()) {
110 Link link = path.getLink();
111 ZToAKey ztoaKey = new ZToAKey(Integer.toString(order));
112 Resource resource = new ResourceBuilder().setResource(link).build();
113 ZToA hop = new ZToABuilder().setId(ztoaKey.getId()).setKey(ztoaKey).setResource(resource).build();
117 ztoaDirection.setRate((long) 100).setZToAWavelengthNumber((long) 200).setZToA(ztoaList);
118 ztoa.add(ztoaDirection.build());
122 * Build direction path
123 * for all Supernode elements.
125 * @param skip Boolean to specify an ROADM without XPDR
126 * @param nodeId Supernode element nodeId
127 * @param zend Supernode path ZEnd nodeId
129 public void build(Boolean skip, String nodeId,String zend) {
130 LOG.info("Building direction ...");
132 buildDegToDeg(false);
135 boolean reverse = false;
136 if (nodeId.contains(zend)) {
139 NodePath xpdr = null;
141 NodePath deg1 = null;
142 NodePath deg2 = null;
143 for (NodePath node : nodepaths) {
144 //LOG.info(node.toString());
145 String id = node.getNodeId();
146 if (id.contains("XPDR")) {
149 if (id.contains("SRG")) {
152 if (id.contains("DEG1")) {
155 if (id.contains("DEG2")) {
159 buildXpdrToSrgToDeg(xpdr,srg,deg1,deg2,reverse);
160 buildDegToSrgToXpdr(xpdr,srg,deg1,deg2,reverse);
165 * build direction path for
166 * Supernode element DEG1, DEG2.
168 * @param twotoOne boolean to determine direction
170 private void buildDegToDeg(boolean twotoOne) {
171 LOG.info("buildDegToDeg ...");
172 NodePath deg1 = null;
173 NodePath deg2 = null;
174 for (NodePath node : nodepaths) {
175 //LOG.info(node.toString());
176 String nodeId = node.getNodeId();
177 if (nodeId.contains("DEG1")) {
180 if (nodeId.contains("DEG2")) {
184 if (deg1 != null && deg2 != null) {
185 List<Path> result = new ArrayList<Path>();
192 for (Path deg1Path : deb.getPath()) {
193 TpNodeTp tmpdeg = deg1Path.getTpNodeTp();
194 if (tmpdeg.getTpIn().getTpId().contains("TTP")) {
196 result.addAll(Lists.newArrayList(deg1Path));
198 getAToZDirection(result);
200 getZToADirection(result);
204 for (Path deg2Path : end.getPath()) {
205 TpNodeTp tmpdeg = deg2Path.getTpNodeTp();
206 if (tmpdeg.getTpIn().getTpId().contains("CTP")) {
208 result.addAll(Lists.newArrayList(deg2Path));
210 getAToZDirection(result);
212 getZToADirection(result);
217 LOG.info("deg1 or/and deg2 is null !");
223 *Degree to SRG to XPDR
224 *in Supernode elements.
226 *@param xpdr NodePath XPDR
227 *@param srg NodePath SRG
228 *@param deg NodePath Degree
229 *@param reverse boolean to determine the direction
231 private void buildDeg(NodePath xpdr,NodePath srg,NodePath deg, Boolean reverse) {
232 List<Path> result = new ArrayList<Path>();
233 for (Path degPath : deg.getPath()) {
234 TpNodeTp tmpdeg = degPath.getTpNodeTp();
235 if (tmpdeg.getTpIn().getTpId().contains("TTP")) {
236 for (Path srgPath : srg.getPath()) {
237 TpNodeTp tmpsrg = srgPath.getTpNodeTp();
238 if (tmpsrg.getTpIn().getTpId().contains("CP")) {
239 for (Path xpdrPath : xpdr.getPath()) {
240 TpNodeTp tmpxpdr = xpdrPath.getTpNodeTp();
241 if (tmpxpdr.getTpIn().getTpId().contains("NETWORK")) {
243 result.addAll(Lists.newArrayList(degPath,srgPath,xpdrPath));
245 getAToZDirection(result);
247 getZToADirection(result);
258 *build direction from
259 *DEG1 / DEG2 to SRG to XPDR
260 *in Supernode elements.
262 *@param xpdr NodePath XPDR
263 *@param srg NodePath SRG
264 *@param deg1 NodePath Degree 1
265 *@param deg2 NodePath Degree 2
266 *@param reverse boolean to determine the direction
268 private void buildDegToSrgToXpdr(NodePath xpdr,NodePath srg,NodePath deg1,NodePath deg2,boolean reverse) {
269 LOG.info("buildDegToSrgToXpr ...");
270 if (xpdr != null && srg != null && deg1 != null && deg2 != null) {
271 buildDeg(xpdr, srg, deg1, reverse);
272 buildDeg(xpdr, srg, deg2, reverse);
274 LOG.info("xpdr, deg or/and srg is null !");
279 *build direction from
281 *in Supernode elements.
283 *@param xpdr NodePath XPDR
284 *@param srg NodePath SRG
285 *@param deg1 NodePath Degree 1
286 *@param deg2 NodePath Degree 2
287 *@param reverse boolean to determine the direction
289 private void buildXpdrToSrgToDeg(NodePath xpdr,NodePath srg,NodePath deg1,NodePath deg2,boolean reverse) {
290 LOG.info("buildXpdrToSrgToDeg ...");
291 if (xpdr != null && srg != null && deg1 != null && deg2 != null) {
292 List<Path> result = new ArrayList<Path>();
293 for (Path xpdrPath : xpdr.getPath()) {
294 TpNodeTp tmpxpdr = xpdrPath.getTpNodeTp();
295 if (tmpxpdr.getTpIn().getTpId().contains("CLIENT")) {
296 for (Path srgPath : srg.getPath()) {
297 TpNodeTp tmp = srgPath.getTpNodeTp();
298 Link srglink = srgPath.getLink();
299 if (tmp.getTpIn().getTpId().contains("PP")) {
300 for (Path deg1Path : deg1.getPath()) {
301 TpNodeTp tmpdeg = deg1Path.getTpNodeTp();
302 if (tmpdeg.getTpIn().getTpId().contains("CTP")
303 && srglink.getLinkId().contains("DEG1")) {
305 result.addAll(Lists.newArrayList(xpdrPath,srgPath,deg1Path));
307 getZToADirection(result);
309 getAToZDirection(result);
313 for (Path deg2Path : deg2.getPath()) {
314 TpNodeTp tmpdeg = deg2Path.getTpNodeTp();
315 if (tmpdeg.getTpIn().getTpId().contains("CTP")
316 && srglink.getLinkId().contains("DEG2")) {
318 result.addAll(Lists.newArrayList(xpdrPath,srgPath,deg2Path));
320 getZToADirection(result);
322 getAToZDirection(result);
331 LOG.info("xpdr, deg or/and srg is null !");
336 * get all AToZdirection containing
337 * a list of <code>AToZ</code> end by
340 * @param endBy String
341 * @param atozDirection AToZdirection List
342 * @param index Integer to determine if it for last Link(1) or last TerminationPoint(2)
343 * @return <code>AToZDirection</code> List
345 public List<AToZDirection> getAToZDirectionEndBy(String endBy, List<AToZDirection> atozDirection, int index) {
346 List<AToZDirection> result = new ArrayList<AToZDirection>();
347 for (AToZDirection tmp : atozDirection) {
348 List<AToZ> atozList = tmp.getAToZ();
349 int size = atozList.size();
351 String id = Integer.toString(size - index);
352 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription
353 .rev170426.pce.resource.resource.Resource res = null;
354 for (AToZ atoz : atozList) {
355 if (atoz.getId().compareTo(id) == 0) {
356 res = atoz.getResource().getResource();
361 if (res instanceof Link) {
362 Link tp = (Link) res;
363 if (tp != null && tp.getLinkId().contains(endBy)) {
370 if (res instanceof TerminationPoint) {
371 TerminationPoint tp = (TerminationPoint) res;
372 if (tp != null && tp.getTpId().contains(endBy)) {
385 LOG.info("firstnodeTpId is null !");
388 LOG.info("getAToZDirectionEndBy result size : {}\n{}", result.size(),result.toString());
393 * replace or remove in
394 * Link in <code>AToZ</code> list
395 * containing in AToZdirection.
397 * @param endBy String
398 * @param beginBy String
399 * @param atozLink name of ROAMDTOROAMD link
400 * @param atozDirection AToZdirection List
401 * @param remove boolean to determine if removing or not
402 * @return <code>AToZDirection</code> List
404 public List<AToZDirection> replaceOrRemoveAToZDirectionEndLink(String endBy,String beginBy,String atozLink,
405 List<AToZDirection> atozDirection, boolean remove) {
406 List<AToZDirection> result = new ArrayList<AToZDirection>();
407 List<AToZDirection> tmp = new ArrayList<AToZDirection>();
409 tmp = getAToZDirectionEndBy(endBy, atozDirection, 1);
410 if (!tmp.isEmpty()) {
411 tmp = getAToZDirectionBeginBy(beginBy, tmp);
414 tmp = getAToZDirectionEndBy(endBy, atozDirection,2);
416 if (!tmp.isEmpty()) {
417 for (AToZDirection atozdir : tmp) {
418 List<AToZ> atozList = atozdir.getAToZ();
419 int size = atozList.size();
421 String id = Integer.toString(size - 1);
422 for (ListIterator<AToZ> it = atozList.listIterator(); it.hasNext();) {
423 AToZ atoz = it.next();
424 if (atoz.getId().compareTo(id) == 0) {
425 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription
426 .rev170426.pce.resource.resource.Resource res = atoz.getResource().getResource();
427 if (res != null && res instanceof Link) {
428 Link link = new LinkBuilder()
431 AToZKey atozKey = new AToZKey(atoz.getKey());
432 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
433 .pathdescription.rev170426.pce.resource.Resource resource = new ResourceBuilder()
434 .setResource(link).build();
435 AToZ hop = new AToZBuilder().setId(atozKey.getId()).setKey(atozKey)
436 .setResource(resource).build();
448 LOG.info("getAToZDirectionEndBy size : {}", tmp.size());
454 *get all AToZdirection containing
455 * a list of <code>AToZ</code> begin by
458 * @param beginBy String
459 * @param atozDirection AToZdirection List
460 * @return <code>AToZDirection</code> List
462 public List<AToZDirection> getAToZDirectionBeginBy(String beginBy, List<AToZDirection> atozDirection) {
463 List<AToZDirection> result = new ArrayList<AToZDirection>();
464 for (AToZDirection tmp : atozDirection) {
465 List<AToZ> atozList = tmp.getAToZ();
466 int size = atozList.size();
468 String id = Integer.toString(0);
469 for (AToZ atoz : atozList) {
470 if (atoz.getId().compareTo(id) == 0) {
471 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription
472 .rev170426.pce.resource.resource.Resource res = atoz.getResource().getResource();
473 if (res != null && res instanceof TerminationPoint) {
474 TerminationPoint tp = (TerminationPoint) res;
475 if (tp != null && tp.getTpId().contains(beginBy)) {
476 LOG.info("tmp : {}", tmp.toString());
484 LOG.info("result size : {}", result.size());
489 * first launch process to
490 * build/fill <code>NodePath</code>
491 * And after that, start building
492 * direction between Supernode
495 * @param zend path zend Supernode nodeId
497 public void buildPath(String zend) {
498 if (superNode != null) {
499 for (org.opendaylight.transportpce.stubpce.topology.Resource res : superNode.getResources()) {
500 NodePath path = new NodePath(res, superNode.getSuperNodeId(), superNode.isXpdrSrgAbsent());
504 LOG.info("nodepaths size : {}", nodepaths.size());
505 build(superNode.isXpdrSrgAbsent(),superNode.getSuperNodeId(), zend);
509 public static void main(String[] args) {
510 Topology topo = new Topology();
512 Network net = topo.getNetwork();
514 SuperNode res = net.getSuperNodes().get(0);
515 String zend = "NodeZ";
516 LOG.info(res.getSuperNodeId().toString());
517 InterNodePath path = new InterNodePath(res);
518 path.buildPath(zend);
522 public SuperNode getSuperNode() {
526 public void setSuperNode(SuperNode superNode) {
527 this.superNode = superNode;
530 public List<AToZDirection> getAtoz() {
534 public void setAtoz(List<AToZDirection> atoz) {
538 public List<ZToADirection> getZtoa() {
542 public void setZtoa(List<ZToADirection> ztoa) {
546 public List<NodePath> getNodepaths() {
550 public void setNodepaths(List<NodePath> nodepaths) {
551 this.nodepaths = nodepaths;