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;
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.ListIterator;
16 import org.opendaylight.transportpce.stubpce.TpNodeTp;
17 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.AToZDirection;
18 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.AToZDirectionBuilder;
19 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ZToADirection;
20 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ZToADirectionBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.atoz.direction.AToZ;
22 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.atoz.direction.AToZBuilder;
23 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.atoz.direction.AToZKey;
24 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ztoa.direction.ZToA;
25 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ztoa.direction.ZToABuilder;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ztoa.direction.ZToAKey;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.Resource;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.ResourceBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.Link;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.LinkBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.TerminationPoint;
32 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.link.LinkIdentifierBuilder;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
37 * class to build all path between superNode elements
40 * @author <a href="mailto:martial.coulibaly@gfi.com">Martial Coulibaly</a> on
44 public class InterNodePath {
46 private static final Logger LOG = LoggerFactory.getLogger(InterNodePath.class);
47 private SuperNode superNode;
48 private List<NodePath> nodepaths;
49 private List<AToZDirection> atoz;
50 private List<ZToADirection> ztoa;
53 * InterNodePath constructor.
55 * @param supernode Supernode
57 public InterNodePath(SuperNode supernode) {
58 setSuperNode(supernode);
59 setNodepaths(new ArrayList<NodePath>());
60 setAtoz(new ArrayList<AToZDirection>());
61 setZtoa(new ArrayList<ZToADirection>());
65 * build AToZdirection.
67 * @param paths <code>Path</code> List
69 private void getAToZDirection(List<Path> paths) {
71 AToZDirectionBuilder atozDirection = new AToZDirectionBuilder();
72 List<AToZ> atozList = new ArrayList<AToZ>();
74 for (Path path : paths) {
75 tpNodeTp = path.getTpNodeTp();
76 tpNodeTp.createAToZListHop(order);
77 for (AToZ atoz : tpNodeTp.getAToZ()) {
81 Link link = path.getLink();
82 AToZKey atozKey = new AToZKey(Integer.toString(order));
83 Resource resource = new ResourceBuilder().setResource(link).build();
84 AToZ hop = new AToZBuilder().setId(atozKey.getId()).withKey(atozKey).setResource(resource).build();
88 atozDirection.setRate((long) 100).setAToZWavelengthNumber((long) 200).setAToZ(atozList);
89 this.atoz.add(atozDirection.build());
93 * build ZToAdirection.
95 * @param paths <code>Path</code> List
97 private void getZToADirection(List<Path> paths) {
99 ZToADirectionBuilder ztoaDirection = new ZToADirectionBuilder();
100 List<ZToA> ztoaList = new ArrayList<ZToA>();
102 for (Path path : paths) {
103 tpNodeTp = path.getTpNodeTp();
104 tpNodeTp.createZToAListHop(order);
105 for (ZToA ztoa : tpNodeTp.getZToA()) {
109 Link link = path.getLink();
110 ZToAKey ztoaKey = new ZToAKey(Integer.toString(order));
111 Resource resource = new ResourceBuilder().setResource(link).build();
112 ZToA hop = new ZToABuilder().setId(ztoaKey.getId()).withKey(ztoaKey).setResource(resource).build();
116 ztoaDirection.setRate((long) 100).setZToAWavelengthNumber((long) 200).setZToA(ztoaList);
117 this.ztoa.add(ztoaDirection.build());
121 * Build direction path
122 * for all Supernode elements.
124 * @param skip Boolean to specify an ROADM without XPDR
125 * @param nodeId Supernode element nodeId
126 * @param zend Supernode path ZEnd nodeId
128 public void build(Boolean skip, String nodeId,String zend) {
129 LOG.info("Building direction ...");
131 buildDegToDeg(false);
134 boolean reverse = false;
135 if (nodeId.contains(zend)) {
138 NodePath xpdr = null;
140 NodePath deg1 = null;
141 NodePath deg2 = null;
142 for (NodePath node : this.nodepaths) {
143 //LOG.info(node.toString());
144 String id = node.getNodeId();
145 if (id.contains("XPDR")) {
148 if (id.contains("SRG")) {
151 if (id.contains("DEG1")) {
154 if (id.contains("DEG2")) {
158 buildXpdrToSrgToDeg(xpdr,srg,deg1,deg2,reverse);
159 buildDegToSrgToXpdr(xpdr,srg,deg1,deg2,reverse);
164 * build direction path for
165 * Supernode element DEG1, DEG2.
167 * @param twotoOne boolean to determine direction
169 private void buildDegToDeg(boolean twotoOne) {
170 LOG.info("buildDegToDeg ...");
171 NodePath deg1 = null;
172 NodePath deg2 = null;
173 for (NodePath node : this.nodepaths) {
174 //LOG.info(node.toString());
175 String nodeId = node.getNodeId();
176 if (nodeId.contains("DEG1")) {
179 if (nodeId.contains("DEG2")) {
183 if ((deg1 != null) && (deg2 != null)) {
184 List<Path> result = new ArrayList<Path>();
191 for (Path deg1Path : deb.getPath()) {
192 TpNodeTp tmpdeg = deg1Path.getTpNodeTp();
193 if (tmpdeg.getTpIn().getTerminationPointIdentifier().getTpId().contains("TTP")) {
195 result.addAll(Lists.newArrayList(deg1Path));
197 getAToZDirection(result);
199 getZToADirection(result);
203 for (Path deg2Path : end.getPath()) {
204 TpNodeTp tmpdeg = deg2Path.getTpNodeTp();
205 if (tmpdeg.getTpIn().getTerminationPointIdentifier().getTpId().contains("CTP")) {
207 result.addAll(Lists.newArrayList(deg2Path));
209 getAToZDirection(result);
211 getZToADirection(result);
216 LOG.info("deg1 or/and deg2 is null !");
222 *Degree to SRG to XPDR
223 *in Supernode elements.
225 *@param xpdr NodePath XPDR
226 *@param srg NodePath SRG
227 *@param deg NodePath Degree
228 *@param reverse boolean to determine the direction
230 private void buildDeg(NodePath xpdr,NodePath srg,NodePath deg, Boolean reverse) {
231 List<Path> result = new ArrayList<Path>();
232 for (Path degPath : deg.getPath()) {
233 TpNodeTp tmpdeg = degPath.getTpNodeTp();
234 if (tmpdeg.getTpIn().getTerminationPointIdentifier().getTpId().contains("TTP")) {
235 for (Path srgPath : srg.getPath()) {
236 TpNodeTp tmpsrg = srgPath.getTpNodeTp();
237 if (tmpsrg.getTpIn().getTerminationPointIdentifier().getTpId().contains("CP")) {
238 for (Path xpdrPath : xpdr.getPath()) {
239 TpNodeTp tmpxpdr = xpdrPath.getTpNodeTp();
240 if (tmpxpdr.getTpIn().getTerminationPointIdentifier().getTpId().contains("NETWORK")) {
242 result.addAll(Lists.newArrayList(degPath,srgPath,xpdrPath));
244 getAToZDirection(result);
246 getZToADirection(result);
257 *build direction from
258 *DEG1 / DEG2 to SRG to XPDR
259 *in Supernode elements.
261 *@param xpdr NodePath XPDR
262 *@param srg NodePath SRG
263 *@param deg1 NodePath Degree 1
264 *@param deg2 NodePath Degree 2
265 *@param reverse boolean to determine the direction
267 private void buildDegToSrgToXpdr(NodePath xpdr,NodePath srg,NodePath deg1,NodePath deg2,boolean reverse) {
268 LOG.info("buildDegToSrgToXpr ...");
269 if ((xpdr != null) && (srg != null) && (deg1 != null) && (deg2 != null)) {
270 buildDeg(xpdr, srg, deg1, reverse);
271 buildDeg(xpdr, srg, deg2, reverse);
273 LOG.info("xpdr, deg or/and srg is null !");
278 *build direction from
280 *in Supernode elements.
282 *@param xpdr NodePath XPDR
283 *@param srg NodePath SRG
284 *@param deg1 NodePath Degree 1
285 *@param deg2 NodePath Degree 2
286 *@param reverse boolean to determine the direction
288 private void buildXpdrToSrgToDeg(NodePath xpdr,NodePath srg,NodePath deg1,NodePath deg2,boolean reverse) {
289 LOG.info("buildXpdrToSrgToDeg ...");
290 if ((xpdr != null) && (srg != null) && (deg1 != null) && (deg2 != null)) {
291 List<Path> result = new ArrayList<Path>();
292 for (Path xpdrPath : xpdr.getPath()) {
293 TpNodeTp tmpxpdr = xpdrPath.getTpNodeTp();
294 if (tmpxpdr.getTpIn().getTerminationPointIdentifier().getTpId().contains("CLIENT")) {
295 for (Path srgPath : srg.getPath()) {
296 TpNodeTp tmp = srgPath.getTpNodeTp();
297 Link srglink = srgPath.getLink();
298 if (tmp.getTpIn().getTerminationPointIdentifier().getTpId().contains("PP")) {
299 for (Path deg1Path : deg1.getPath()) {
300 TpNodeTp tmpdeg = deg1Path.getTpNodeTp();
301 if (tmpdeg.getTpIn().getTerminationPointIdentifier().getTpId().contains("CTP")
302 && srglink.getLinkIdentifier().getLinkId().contains("DEG1")) {
304 result.addAll(Lists.newArrayList(xpdrPath,srgPath,deg1Path));
306 getZToADirection(result);
308 getAToZDirection(result);
312 for (Path deg2Path : deg2.getPath()) {
313 TpNodeTp tmpdeg = deg2Path.getTpNodeTp();
314 if (tmpdeg.getTpIn().getTerminationPointIdentifier().getTpId().contains("CTP")
315 && srglink.getLinkIdentifier().getLinkId().contains("DEG2")) {
317 result.addAll(Lists.newArrayList(xpdrPath,srgPath,deg2Path));
319 getZToADirection(result);
321 getAToZDirection(result);
330 LOG.info("xpdr, deg or/and srg is null !");
335 * get all AToZdirection containing
336 * a list of <code>AToZ</code> end by
339 * @param endBy String
340 * @param atozDirection AToZdirection List
341 * @param index Integer to determine if it for last Link(1) or last TerminationPoint(2)
342 * @return <code>AToZDirection</code> List
344 public List<AToZDirection> getAToZDirectionEndBy(String endBy, List<AToZDirection> atozDirection, int index) {
345 List<AToZDirection> result = new ArrayList<AToZDirection>();
346 for (AToZDirection tmp : atozDirection) {
347 List<AToZ> atozList = tmp.getAToZ();
348 int size = atozList.size();
350 String id = Integer.toString(size - index);
351 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription
352 .rev170426.pce.resource.resource.Resource res = null;
353 for (AToZ atoz : atozList) {
354 if (atoz.getId().compareTo(id) == 0) {
355 res = atoz.getResource().getResource();
360 if (res instanceof Link) {
361 Link tp = (Link) res;
362 if ((tp != null) && tp.getLinkIdentifier().getLinkId().contains(endBy)) {
369 if (res instanceof TerminationPoint) {
370 TerminationPoint tp = (TerminationPoint) res;
371 if ((tp != null) && tp.getTerminationPointIdentifier().getTpId()
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()
429 .setLinkIdentifier(new LinkIdentifierBuilder()
433 AToZKey atozKey = new AToZKey(atoz.key());
434 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
435 .pathdescription.rev170426.pce.resource.Resource resource = new ResourceBuilder()
436 .setResource(link).build();
437 AToZ hop = new AToZBuilder().setId(atozKey.getId()).withKey(atozKey)
438 .setResource(resource).build();
450 LOG.info("getAToZDirectionEndBy size : {}", tmp.size());
456 *get all AToZdirection containing
457 * a list of <code>AToZ</code> begin by
460 * @param beginBy String
461 * @param atozDirection AToZdirection List
462 * @return <code>AToZDirection</code> List
464 public List<AToZDirection> getAToZDirectionBeginBy(String beginBy, List<AToZDirection> atozDirection) {
465 List<AToZDirection> result = new ArrayList<AToZDirection>();
466 for (AToZDirection tmp : atozDirection) {
467 List<AToZ> atozList = tmp.getAToZ();
468 int size = atozList.size();
470 String id = Integer.toString(0);
471 for (AToZ atoz : atozList) {
472 if (atoz.getId().compareTo(id) == 0) {
473 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription
474 .rev170426.pce.resource.resource.Resource res = atoz.getResource().getResource();
475 if ((res != null) && (res instanceof TerminationPoint)) {
476 TerminationPoint tp = (TerminationPoint) res;
477 if ((tp != null) && tp.getTerminationPointIdentifier().getTpId().contains(beginBy)) {
478 LOG.info("tmp : {}", tmp.toString());
486 LOG.info("result size : {}", result.size());
491 * first launch process to
492 * build/fill <code>NodePath</code>
493 * And after that, start building
494 * direction between Supernode
497 * @param zend path zend Supernode nodeId
499 public void buildPath(String zend) {
500 if (this.superNode != null) {
501 for (org.opendaylight.transportpce.stubpce.topology.Resource res : this.superNode.getResources()) {
502 NodePath path = new NodePath(res, this.superNode.getSuperNodeId(), this.superNode.isXpdrSrgAbsent());
504 this.nodepaths.add(path);
506 LOG.info("nodepaths size : {}", this.nodepaths.size());
507 build(this.superNode.isXpdrSrgAbsent(),this.superNode.getSuperNodeId(), zend);
511 public static void main(String[] args) {
512 Topology topo = new Topology();
514 Network net = topo.getNetwork();
516 SuperNode res = net.getSuperNodes().get(0);
517 String zend = "NodeZ";
518 LOG.info(res.getSuperNodeId().toString());
519 InterNodePath path = new InterNodePath(res);
520 path.buildPath(zend);
524 public SuperNode getSuperNode() {
525 return this.superNode;
528 public void setSuperNode(SuperNode superNode) {
529 this.superNode = superNode;
532 public List<AToZDirection> getAtoz() {
536 public void setAtoz(List<AToZDirection> atoz) {
540 public List<ZToADirection> getZtoa() {
544 public void setZtoa(List<ZToADirection> ztoa) {
548 public List<NodePath> getNodepaths() {
549 return this.nodepaths;
552 public void setNodepaths(List<NodePath> nodepaths) {
553 this.nodepaths = nodepaths;