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
9 package org.opendaylight.transportpce.stubpce.topology;
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.apache.commons.lang3.StringUtils;
14 import org.opendaylight.transportpce.stubpce.TpNodeTp;
15 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.Link;
16 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.LinkBuilder;
17 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.Node;
18 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.NodeBuilder;
19 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.TerminationPoint;
20 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.TerminationPointBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.link.LinkIdentifierBuilder;
22 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.node.NodeIdentifierBuilder;
23 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.termination.point.TerminationPointIdentifierBuilder;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
29 * build all path with one resource
32 * @author <a href="mailto:martial.coulibaly@gfi.com">Martial Coulibaly</a> on
35 public class NodePath {
37 private static final Logger LOG = LoggerFactory.getLogger(NodePath.class);
38 /** element of Supernode. */
39 private org.opendaylight.transportpce.stubpce.topology.Resource resource;
40 /** <code>TpNodeTp</code> list. */
41 private List<TpNodeTp> tpNodeTps;
42 /** <code>Link</code> list. */
43 private List<Link> links;
44 /** SuperNode element nodeId. */
45 private String nodeId;
47 private String superNodeId;
48 /** boolean to determine if Supernode contains an XPDR. */
49 private boolean isXpdrSrgAbsent;
51 private List<Path> path;
54 *NodePath constructor.
56 * @param res element of Supernode
57 * @param superNodeId supernode Id
58 * @param isXpdrSrgAbsent boolean to determine if Supernode contains an XPDR
60 public NodePath(org.opendaylight.transportpce.stubpce.topology.Resource res,
61 String superNodeId, boolean isXpdrSrgAbsent) {
63 setNodeId(res.getNodeId());
64 setSuperNodeId(superNodeId);
65 setXpdrSrgAbsent(isXpdrSrgAbsent);
66 setLinks(new ArrayList<Link>());
67 setTpNodeTps(new ArrayList<TpNodeTp>());
68 setPath(new ArrayList<Path>());
72 public String toString() {
73 java.lang.String name = "NodePath [";
74 java.lang.StringBuilder builder = new java.lang.StringBuilder(name);
76 builder.append("nodeId= ");
77 builder.append(nodeId);
80 if (path.size() > 0) {
81 builder.append("Paths [");
82 builder.append(path.toString());
85 return builder.append(']').toString();
89 *get all resources (links,
90 *logicalConnectionpoints, nodeId)
91 *from Supernode element.
95 if (resource != null) {
96 String nodeid = resource.getNodeId();
97 List<String> resLinks = resource.getLinks();
98 List<LogicalConnectionPoint> resLcps = resource.getLcps();
99 for (String tmp : resLinks) {
100 Link link = new LinkBuilder()
101 .setLinkIdentifier(new LinkIdentifierBuilder()
107 if (nodeid.contains("XPDR")) {
108 LOG.info("building xpdr resource ...");
110 buildXpdrTopo(nodeid,resLinks,resLcps,xpdr);
111 links.add(new LinkBuilder()
112 .setLinkIdentifier(new LinkIdentifierBuilder()
113 .setLinkId("TAIL-LINKS")
117 if (nodeid.contains("SRG")) {
118 LOG.info("building SRG resource ...");
119 buildSRGTopo(nodeid, resLinks, resLcps);
121 if (nodeid.contains("DEG")) {
122 LOG.info("building DEG resource ...");
124 buildXpdrTopo(nodeid,resLinks,resLcps,xpdr);
125 links.add(new LinkBuilder()
126 .setLinkIdentifier(new LinkIdentifierBuilder()
127 .setLinkId("EXTERNAL-LINKS")
139 * @return TpNodeTp list
141 private List<TpNodeTp> reverseTpNodetpList() {
142 List<TpNodeTp> result = new ArrayList<TpNodeTp>();
143 for (TpNodeTp tpNodetp : tpNodeTps) {
144 TpNodeTp tmp = tpNodetp.reverse();
154 private void createDirection() {
155 /** create direction */
156 LOG.info("creating direction ...");
157 Path resourcePath = null;
158 List<TpNodeTp> direction = new ArrayList<TpNodeTp>();
159 for (Link link : links) {
160 String linkId = link.getLinkIdentifier().getLinkId();
161 LOG.info("LinkId : {}", linkId);
162 if (!isXpdrSrgAbsent) {
163 if (StringUtils.countMatches(link.getLinkIdentifier().getLinkId(), "ROADM") < 2) {
164 if ((linkId.contains("XPDR") && linkId.startsWith("ROADM"))
165 || ((linkId.startsWith("DEG") && linkId.contains("SRG")))
166 || (nodeId.contains("XPDR") && linkId.contains("TAIL-LINKS"))) {
167 LOG.info("reversing TpNodetp list for link '{}'", linkId);
168 direction = reverseTpNodetpList();
170 direction = tpNodeTps;
173 LOG.info("link is deg to deg link !");
176 if (StringUtils.countMatches(link.getLinkIdentifier().getLinkId(), "ROADM") == 2) {
177 direction = reverseTpNodetpList();
179 direction = tpNodeTps;
182 if (tpNodeTps.size() > 0) {
183 for (TpNodeTp tpNodeTp : direction) {
184 resourcePath = new Path(tpNodeTp, link);
185 LOG.info(resourcePath.toString());
186 path.add(resourcePath);
189 LOG.info("tpNodeTps is empty !");
196 * Termination Point in
198 * ordered in AToZdirection
199 * on a Supernode (XPDR to SRG)
200 * (ROADMA-DEG to ROADMZ-DEG).
202 * @param xpdr determine if it is an XPDR or not
203 * @param resLcps list of LogicalConnectionPoint
204 * @return String list of TerminationPoints
206 private List<String> getOrderedTps(boolean xpdr, List<LogicalConnectionPoint> resLcps) {
207 List<String> result = new ArrayList<String>();
209 for (LogicalConnectionPoint lcp : resLcps) {
210 String tmp = lcp.getTpId();
211 if (tmp.contains("CLIENT")) {
213 } else if (tmp.contains("NETWORK")) {
218 for (LogicalConnectionPoint lcp : resLcps) {
219 String tmp = lcp.getTpId();
220 if (tmp.contains("CTP")) {
222 } else if (tmp.contains("TTP")) {
235 * @param nodeid XPDR Id
236 * @param resLinks list of links
237 * @param resLcps list of LogicalConnectionPoints
238 * @param xpdr determine if it is an XPDR or not
240 private void buildXpdrTopo(String nodeid, List<String> resLinks, List<LogicalConnectionPoint> resLcps,
242 /** build TpNodetp .*/
243 TerminationPointBuilder in = null;
244 TerminationPointBuilder out = null;
245 List<String> lcps = getOrderedTps(xpdr,resLcps);
246 if (lcps.size() == 2) {
247 in = new TerminationPointBuilder()
248 .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
250 .setTpId(lcps.get(0))
252 out = new TerminationPointBuilder()
253 .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
255 .setTpId(lcps.get(1))
258 LOG.info("lcps size not equal to 2");
261 Node node = new NodeBuilder()
262 .setNodeIdentifier(new NodeIdentifierBuilder()
266 TpNodeTp tmp = new TpNodeTp(in.build(), out.build(), node);
275 * @param nodeid SRG nodeId
276 * @param resLinks list of links
277 * @param resLcps list of LogicalConnectionPoints
279 private void buildSRGTopo(String nodeid, List<String> resLinks,List<LogicalConnectionPoint> resLcps) {
280 /** build TpNodetp .*/
281 Node node = new NodeBuilder()
282 .setNodeIdentifier(new NodeIdentifierBuilder()
286 TerminationPoint out = new TerminationPointBuilder()
287 .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
289 .setTpId("SRG1-CP-TXRX")
292 for (LogicalConnectionPoint lcp : resLcps) {
293 if (lcp.getTpId().compareTo("SRG1-CP-TXRX") != 0) {
294 TerminationPoint in = new TerminationPointBuilder()
295 .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
297 .setTpId(lcp.getTpId())
300 tpNodeTps.add(new TpNodeTp(in, out, node));
305 public static void main(String[] args) {
306 Topology topo = new Topology();
308 Network net = topo.getNetwork();
310 SuperNode superNode = net.getSuperNodes().get(0);
311 LOG.info("SuperNode : {}", superNode.getSuperNodeId());
312 for (org.opendaylight.transportpce.stubpce.topology.Resource res :
313 superNode.getResources()) {
314 LOG.info(res.toString());
315 NodePath path = new NodePath(res, superNode.getSuperNodeId(), superNode.isXpdrSrgAbsent());
321 public org.opendaylight.transportpce.stubpce.topology.Resource getResource() {
325 public void setResource(org.opendaylight.transportpce.stubpce.topology.Resource resource) {
326 this.resource = resource;
329 public List<TpNodeTp> getTpNodeTps() {
333 public void setTpNodeTps(List<TpNodeTp> tpNodeTps) {
334 this.tpNodeTps = tpNodeTps;
337 public List<Link> getLinks() {
341 public void setLinks(List<Link> links) {
345 public List<Path> getPath() {
349 public void setPath(List<Path> path) {
353 public String getNodeId() {
357 public void setNodeId(String nodeId) {
358 this.nodeId = nodeId;
361 public String getSuperNodeId() {
365 public void setSuperNodeId(String superNodeId) {
366 this.superNodeId = superNodeId;
369 public boolean isXpdrSrgAbsent() {
370 return isXpdrSrgAbsent;
373 public void setXpdrSrgAbsent(boolean xpdrSrgAbsent) {
374 this.isXpdrSrgAbsent = xpdrSrgAbsent;