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;
14 import org.apache.commons.lang3.StringUtils;
15 import org.opendaylight.transportpce.stubpce.TpNodeTp;
16 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.Link;
17 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.LinkBuilder;
18 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.Node;
19 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.NodeBuilder;
20 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.TerminationPoint;
21 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.TerminationPointBuilder;
22 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.link.LinkIdentifierBuilder;
23 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.node.NodeIdentifierBuilder;
24 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.termination.point.TerminationPointIdentifierBuilder;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
30 * build all path with one resource
33 * @author <a href="mailto:martial.coulibaly@gfi.com">Martial Coulibaly</a> on
36 public class NodePath {
38 private static final Logger LOG = LoggerFactory.getLogger(NodePath.class);
39 /** element of Supernode. */
40 private org.opendaylight.transportpce.stubpce.topology.Resource resource;
41 /** <code>TpNodeTp</code> list. */
42 private List<TpNodeTp> tpNodeTps;
43 /** <code>Link</code> list. */
44 private List<Link> links;
45 /** SuperNode element nodeId. */
46 private String nodeId;
48 private String superNodeId;
49 /** boolean to determine if Supernode contains an XPDR. */
50 private boolean isXpdrSrgAbsent;
52 private List<Path> path;
55 *NodePath constructor.
57 * @param res element of Supernode
58 * @param superNodeId supernode Id
59 * @param isXpdrSrgAbsent boolean to determine if Supernode contains an XPDR
61 public NodePath(org.opendaylight.transportpce.stubpce.topology.Resource res,
62 String superNodeId, boolean isXpdrSrgAbsent) {
64 setNodeId(res.getNodeId());
65 setSuperNodeId(superNodeId);
66 setXpdrSrgAbsent(isXpdrSrgAbsent);
67 setLinks(new ArrayList<Link>());
68 setTpNodeTps(new ArrayList<TpNodeTp>());
69 setPath(new ArrayList<Path>());
73 public String toString() {
74 java.lang.String name = "NodePath [";
75 java.lang.StringBuilder builder = new java.lang.StringBuilder(name);
77 builder.append("nodeId= ");
78 builder.append(nodeId);
81 if (path.size() > 0) {
82 builder.append("Paths [");
83 builder.append(path.toString());
86 return builder.append(']').toString();
90 *get all resources (links,
91 *logicalConnectionpoints, nodeId)
92 *from Supernode element.
96 if (resource != null) {
97 String nodeid = resource.getNodeId();
98 List<String> resLinks = resource.getLinks();
99 List<LogicalConnectionPoint> resLcps = resource.getLcps();
100 for (String tmp : resLinks) {
101 Link link = new LinkBuilder()
102 .setLinkIdentifier(new LinkIdentifierBuilder()
108 if (nodeid.contains("XPDR")) {
109 LOG.info("building xpdr resource ...");
111 buildXpdrTopo(nodeid,resLinks,resLcps,xpdr);
112 links.add(new LinkBuilder()
113 .setLinkIdentifier(new LinkIdentifierBuilder()
114 .setLinkId("TAIL-LINKS")
118 if (nodeid.contains("SRG")) {
119 LOG.info("building SRG resource ...");
120 buildSRGTopo(nodeid, resLinks, resLcps);
122 if (nodeid.contains("DEG")) {
123 LOG.info("building DEG resource ...");
125 buildXpdrTopo(nodeid,resLinks,resLcps,xpdr);
126 links.add(new LinkBuilder()
127 .setLinkIdentifier(new LinkIdentifierBuilder()
128 .setLinkId("EXTERNAL-LINKS")
140 * @return TpNodeTp list
142 private List<TpNodeTp> reverseTpNodetpList() {
143 List<TpNodeTp> result = new ArrayList<TpNodeTp>();
144 for (TpNodeTp tpNodetp : tpNodeTps) {
145 TpNodeTp tmp = tpNodetp.reverse();
155 private void createDirection() {
156 /** create direction */
157 LOG.info("creating direction ...");
158 Path resourcePath = null;
159 List<TpNodeTp> direction = new ArrayList<TpNodeTp>();
160 for (Link link : links) {
161 String linkId = link.getLinkIdentifier().getLinkId();
162 LOG.info("LinkId : {}", linkId);
163 if (!isXpdrSrgAbsent) {
164 if (StringUtils.countMatches(link.getLinkIdentifier().getLinkId(), "ROADM") < 2) {
165 if ((linkId.contains("XPDR") && linkId.startsWith("ROADM"))
166 || ((linkId.startsWith("DEG") && linkId.contains("SRG")))
167 || (nodeId.contains("XPDR") && linkId.contains("TAIL-LINKS"))) {
168 LOG.info("reversing TpNodetp list for link '{}'", linkId);
169 direction = reverseTpNodetpList();
171 direction = tpNodeTps;
174 LOG.info("link is deg to deg link !");
177 if (StringUtils.countMatches(link.getLinkIdentifier().getLinkId(), "ROADM") == 2) {
178 direction = reverseTpNodetpList();
180 direction = tpNodeTps;
183 if (tpNodeTps.size() > 0) {
184 for (TpNodeTp tpNodeTp : direction) {
185 resourcePath = new Path(tpNodeTp, link);
186 LOG.info(resourcePath.toString());
187 path.add(resourcePath);
190 LOG.info("tpNodeTps is empty !");
197 * Termination Point in
199 * ordered in AToZdirection
200 * on a Supernode (XPDR to SRG)
201 * (ROADMA-DEG to ROADMZ-DEG).
203 * @param xpdr determine if it is an XPDR or not
204 * @param resLcps list of LogicalConnectionPoint
205 * @return String list of TerminationPoints
207 private List<String> getOrderedTps(boolean xpdr, List<LogicalConnectionPoint> resLcps) {
208 List<String> result = new ArrayList<String>();
210 for (LogicalConnectionPoint lcp : resLcps) {
211 String tmp = lcp.getTpId();
212 if (tmp.contains("CLIENT")) {
214 } else if (tmp.contains("NETWORK")) {
219 for (LogicalConnectionPoint lcp : resLcps) {
220 String tmp = lcp.getTpId();
221 if (tmp.contains("CTP")) {
223 } else if (tmp.contains("TTP")) {
236 * @param nodeid XPDR Id
237 * @param resLinks list of links
238 * @param resLcps list of LogicalConnectionPoints
239 * @param xpdr determine if it is an XPDR or not
241 private void buildXpdrTopo(String nodeid, List<String> resLinks, List<LogicalConnectionPoint> resLcps,
243 /** build TpNodetp .*/
244 TerminationPointBuilder in = null;
245 TerminationPointBuilder out = null;
246 List<String> lcps = getOrderedTps(xpdr,resLcps);
247 if (lcps.size() == 2) {
248 in = new TerminationPointBuilder()
249 .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
251 .setTpId(lcps.get(0))
253 out = new TerminationPointBuilder()
254 .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
256 .setTpId(lcps.get(1))
259 LOG.info("lcps size not equal to 2");
262 Node node = new NodeBuilder()
263 .setNodeIdentifier(new NodeIdentifierBuilder()
267 TpNodeTp tmp = new TpNodeTp(in.build(), out.build(), node);
276 * @param nodeid SRG nodeId
277 * @param resLinks list of links
278 * @param resLcps list of LogicalConnectionPoints
280 private void buildSRGTopo(String nodeid, List<String> resLinks,List<LogicalConnectionPoint> resLcps) {
281 /** build TpNodetp .*/
282 Node node = new NodeBuilder()
283 .setNodeIdentifier(new NodeIdentifierBuilder()
287 TerminationPoint out = new TerminationPointBuilder()
288 .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
290 .setTpId("SRG1-CP-TXRX")
293 for (LogicalConnectionPoint lcp : resLcps) {
294 if (lcp.getTpId().compareTo("SRG1-CP-TXRX") != 0) {
295 TerminationPoint in = new TerminationPointBuilder()
296 .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
298 .setTpId(lcp.getTpId())
301 tpNodeTps.add(new TpNodeTp(in, out, node));
306 public static void main(String[] args) {
307 Topology topo = new Topology();
309 Network net = topo.getNetwork();
311 SuperNode superNode = net.getSuperNodes().get(0);
312 LOG.info("SuperNode : {}", superNode.getSuperNodeId());
313 for (org.opendaylight.transportpce.stubpce.topology.Resource res :
314 superNode.getResources()) {
315 LOG.info(res.toString());
316 NodePath path = new NodePath(res, superNode.getSuperNodeId(), superNode.isXpdrSrgAbsent());
322 public org.opendaylight.transportpce.stubpce.topology.Resource getResource() {
326 public void setResource(org.opendaylight.transportpce.stubpce.topology.Resource resource) {
327 this.resource = resource;
330 public List<TpNodeTp> getTpNodeTps() {
334 public void setTpNodeTps(List<TpNodeTp> tpNodeTps) {
335 this.tpNodeTps = tpNodeTps;
338 public List<Link> getLinks() {
342 public void setLinks(List<Link> links) {
346 public List<Path> getPath() {
350 public void setPath(List<Path> path) {
354 public String getNodeId() {
358 public void setNodeId(String nodeId) {
359 this.nodeId = nodeId;
362 public String getSuperNodeId() {
366 public void setSuperNodeId(String superNodeId) {
367 this.superNodeId = superNodeId;
370 public boolean isXpdrSrgAbsent() {
371 return isXpdrSrgAbsent;
374 public void setXpdrSrgAbsent(boolean isXpdrSrgAbsent) {
375 this.isXpdrSrgAbsent = isXpdrSrgAbsent;