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.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
27 * build all path with one resource
30 * @author <a href="mailto:martial.coulibaly@gfi.com">Martial Coulibaly</a> on
33 public class NodePath {
35 private static final Logger LOG = LoggerFactory.getLogger(NodePath.class);
36 /** element of Supernode. */
37 private org.opendaylight.transportpce.stubpce.topology.Resource resource;
38 /** <code>TpNodeTp</code> list. */
39 private List<TpNodeTp> tpNodeTps;
40 /** <code>Link</code> list. */
41 private List<Link> links;
42 /** SuperNode element nodeId. */
43 private String nodeId;
45 private String superNodeId;
46 /** boolean to determine if Supernode contains an XPDR. */
47 private boolean isXpdrSrgAbsent;
49 private List<Path> path;
52 *NodePath constructor.
54 * @param res element of Supernode
55 * @param superNodeId supernode Id
56 * @param isXpdrSrgAbsent boolean to determine if Supernode contains an XPDR
58 public NodePath(org.opendaylight.transportpce.stubpce.topology.Resource res,
59 String superNodeId, boolean isXpdrSrgAbsent) {
61 setNodeId(res.getNodeId());
62 setSuperNodeId(superNodeId);
63 setXpdrSrgAbsent(isXpdrSrgAbsent);
64 setLinks(new ArrayList<Link>());
65 setTpNodeTps(new ArrayList<TpNodeTp>());
66 setPath(new ArrayList<Path>());
70 public String toString() {
71 java.lang.String name = "NodePath [";
72 java.lang.StringBuilder builder = new java.lang.StringBuilder(name);
74 builder.append("nodeId= ");
75 builder.append(nodeId);
78 if (path.size() > 0) {
79 builder.append("Paths [");
80 builder.append(path.toString());
83 return builder.append(']').toString();
87 *get all resources (links,
88 *logicalConnectionpoints, nodeId)
89 *from Supernode element.
93 if (resource != null) {
94 String nodeid = resource.getNodeId();
95 List<String> resLinks = resource.getLinks();
96 List<LogicalConnectionPoint> resLcps = resource.getLcps();
97 for (String tmp : resLinks) {
98 Link link = new LinkBuilder()
103 if (nodeid.contains("XPDR")) {
104 LOG.info("building xpdr resource ...");
106 buildXpdrTopo(nodeid,resLinks,resLcps,xpdr);
107 links.add(new LinkBuilder()
108 .setLinkId("TAIL-LINKS")
111 if (nodeid.contains("SRG")) {
112 LOG.info("building SRG resource ...");
113 buildSRGTopo(nodeid, resLinks, resLcps);
115 if (nodeid.contains("DEG")) {
116 LOG.info("building DEG resource ...");
118 buildXpdrTopo(nodeid,resLinks,resLcps,xpdr);
119 links.add(new LinkBuilder()
120 .setLinkId("EXTERNAL-LINKS")
131 * @return TpNodeTp list
133 private List<TpNodeTp> reverseTpNodetpList() {
134 List<TpNodeTp> result = new ArrayList<TpNodeTp>();
135 for (TpNodeTp tpNodetp : tpNodeTps) {
136 TpNodeTp tmp = tpNodetp.reverse();
146 private void createDirection() {
147 /** create direction */
148 LOG.info("creating direction ...");
149 Path resourcePath = null;
150 List<TpNodeTp> direction = new ArrayList<TpNodeTp>();
151 for (Link link : links) {
152 String linkId = link.getLinkId();
153 LOG.info("LinkId : {}", linkId);
154 if (!isXpdrSrgAbsent) {
155 if (StringUtils.countMatches(link.getLinkId(), "ROADM") < 2) {
156 if ((linkId.contains("XPDR") && linkId.startsWith("ROADM"))
157 || ((linkId.startsWith("DEG") && linkId.contains("SRG")))
158 || (nodeId.contains("XPDR") && linkId.contains("TAIL-LINKS"))) {
159 LOG.info("reversing TpNodetp list for link '{}'", linkId);
160 direction = reverseTpNodetpList();
162 direction = tpNodeTps;
165 LOG.info("link is deg to deg link !");
168 if (StringUtils.countMatches(link.getLinkId(), "ROADM") == 2) {
169 direction = reverseTpNodetpList();
171 direction = tpNodeTps;
174 if (tpNodeTps.size() > 0) {
175 for (TpNodeTp tpNodeTp : direction) {
176 resourcePath = new Path(tpNodeTp, link);
177 LOG.info(resourcePath.toString());
178 path.add(resourcePath);
181 LOG.info("tpNodeTps is empty !");
188 * Termination Point in
190 * ordered in AToZdirection
191 * on a Supernode (XPDR to SRG)
192 * (ROADMA-DEG to ROADMZ-DEG).
194 * @param xpdr determine if it is an XPDR or not
195 * @param resLcps list of LogicalConnectionPoint
196 * @return String list of TerminationPoints
198 private List<String> getOrderedTps(boolean xpdr, List<LogicalConnectionPoint> resLcps) {
199 List<String> result = new ArrayList<String>();
201 for (LogicalConnectionPoint lcp : resLcps) {
202 String tmp = lcp.getTpId();
203 if (tmp.contains("CLIENT")) {
205 } else if (tmp.contains("NETWORK")) {
210 for (LogicalConnectionPoint lcp : resLcps) {
211 String tmp = lcp.getTpId();
212 if (tmp.contains("CTP")) {
214 } else if (tmp.contains("TTP")) {
227 * @param nodeid XPDR Id
228 * @param resLinks list of links
229 * @param resLcps list of LogicalConnectionPoints
230 * @param xpdr determine if it is an XPDR or not
232 private void buildXpdrTopo(String nodeid, List<String> resLinks, List<LogicalConnectionPoint> resLcps,
234 /** build TpNodetp .*/
235 TerminationPointBuilder in = null;
236 TerminationPointBuilder out = null;
237 List<String> lcps = getOrderedTps(xpdr,resLcps);
238 if (lcps.size() == 2) {
239 in = new TerminationPointBuilder()
241 .setTpId(lcps.get(0));
242 out = new TerminationPointBuilder()
244 .setTpId(lcps.get(1));
246 LOG.info("lcps size not equal to 2");
249 Node node = new NodeBuilder()
252 TpNodeTp tmp = new TpNodeTp(in.build(), out.build(), node);
261 * @param nodeid SRG nodeId
262 * @param resLinks list of links
263 * @param resLcps list of LogicalConnectionPoints
265 private void buildSRGTopo(String nodeid, List<String> resLinks,List<LogicalConnectionPoint> resLcps) {
266 /** build TpNodetp .*/
267 Node node = new NodeBuilder()
270 TerminationPoint out = new TerminationPointBuilder()
272 .setTpId("SRG1-CP-TXRX")
275 for (LogicalConnectionPoint lcp : resLcps) {
276 if (lcp.getTpId().compareTo("SRG1-CP-TXRX") != 0) {
277 TerminationPoint in = new TerminationPointBuilder()
279 .setTpId(lcp.getTpId())
281 tpNodeTps.add(new TpNodeTp(in, out, node));
286 public static void main(String[] args) {
287 Topology topo = new Topology();
289 Network net = topo.getNetwork();
291 SuperNode superNode = net.getSuperNodes().get(0);
292 LOG.info("SuperNode : {}", superNode.getSuperNodeId());
293 for (org.opendaylight.transportpce.stubpce.topology.Resource res :
294 superNode.getResources()) {
295 LOG.info(res.toString());
296 NodePath path = new NodePath(res, superNode.getSuperNodeId(), superNode.isXpdrSrgAbsent());
302 public org.opendaylight.transportpce.stubpce.topology.Resource getResource() {
306 public void setResource(org.opendaylight.transportpce.stubpce.topology.Resource resource) {
307 this.resource = resource;
310 public List<TpNodeTp> getTpNodeTps() {
314 public void setTpNodeTps(List<TpNodeTp> tpNodeTps) {
315 this.tpNodeTps = tpNodeTps;
318 public List<Link> getLinks() {
322 public void setLinks(List<Link> links) {
326 public List<Path> getPath() {
330 public void setPath(List<Path> path) {
334 public String getNodeId() {
338 public void setNodeId(String nodeId) {
339 this.nodeId = nodeId;
342 public String getSuperNodeId() {
346 public void setSuperNodeId(String superNodeId) {
347 this.superNodeId = superNodeId;
350 public boolean isXpdrSrgAbsent() {
351 return isXpdrSrgAbsent;
354 public void setXpdrSrgAbsent(boolean isXpdrSrgAbsent) {
355 this.isXpdrSrgAbsent = isXpdrSrgAbsent;