2 * Copyright © 2017 AT&T, 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
8 package org.opendaylight.transportpce.pce;
10 import com.google.common.collect.ImmutableList;
11 import java.util.ArrayList;
12 import java.util.List;
14 import org.opendaylight.transportpce.common.ResponseCodes;
15 import org.opendaylight.transportpce.pce.networkanalyzer.PceLink;
16 import org.opendaylight.transportpce.pce.networkanalyzer.PceResult;
17 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.AToZDirectionBuilder;
18 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ZToADirectionBuilder;
19 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.atoz.direction.AToZ;
20 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.atoz.direction.AToZBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.atoz.direction.AToZKey;
22 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ztoa.direction.ZToA;
23 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ztoa.direction.ZToABuilder;
24 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ztoa.direction.ZToAKey;
25 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.Resource;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.ResourceBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.LinkBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.NodeBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.TerminationPoint;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.TerminationPointBuilder;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 public class PcePathDescription {
37 private static final Logger LOG = LoggerFactory.getLogger(PcePathDescription.class);
39 private List<PceLink> pathAtoZ = null;
42 public PceResult getReturnStructure() {
46 private Map<LinkId, PceLink> allPceLinks = null;
48 private List<PceLink> pathZtoA = null;
50 public PcePathDescription(List<PceLink> pathAtoZ, Map<LinkId, PceLink> allPceLinks, PceResult rc) {
52 this.allPceLinks = allPceLinks;
53 this.pathAtoZ = pathAtoZ;
57 public PceResult buildDescriptions() {
58 LOG.info("In buildDescriptions: AtoZ = {}", pathAtoZ.toString());
59 List<AToZ> atozList = new ArrayList<AToZ>();
60 if (pathAtoZ == null) {
61 rc.setRC(ResponseCodes.RESPONSE_FAILED);
62 LOG.error("In buildDescriptions: there is empty AtoZ path");
66 buildAtoZ(atozList, pathAtoZ);
67 AToZDirectionBuilder atoZDirectionBldr = new AToZDirectionBuilder()
68 .setRate(rc.getRate())
70 if ("100GE".equals(rc.getServiceType()) || "OTU4".equals(rc.getServiceType())) {
71 atoZDirectionBldr.setAToZWavelengthNumber(rc.getResultWavelength());
72 } else if ("10GE".equals(rc.getServiceType()) || "1GE".equals(rc.getServiceType())
73 || "ODU4".equals(rc.getServiceType())) {
74 atoZDirectionBldr.setAToZWavelengthNumber(Long.valueOf(0));
76 rc.setAtoZDirection(atoZDirectionBldr.build());
77 pathZtoA = ImmutableList.copyOf(pathAtoZ).reverse();
78 LOG.info("In buildDescriptions: ZtoA {}", pathZtoA.toString());
80 List<ZToA> ztoaList = new ArrayList<ZToA>();
81 if (pathZtoA == null) {
82 rc.setRC(ResponseCodes.RESPONSE_FAILED);
83 LOG.error("In buildDescriptions: there is empty ZtoA path");
86 buildZtoA(ztoaList, pathZtoA);
87 ZToADirectionBuilder ztoADirectionBldr = new ZToADirectionBuilder()
88 .setRate(rc.getRate())
90 if ("100GE".equals(rc.getServiceType()) || "OTU4".equals(rc.getServiceType())) {
91 ztoADirectionBldr.setZToAWavelengthNumber(rc.getResultWavelength());
92 } else if ("10GE".equals(rc.getServiceType()) || "1GE".equals(rc.getServiceType())
93 || "ODU4".equals(rc.getServiceType())) {
94 ztoADirectionBldr.setZToAWavelengthNumber(Long.valueOf(0));
96 rc.setZtoADirection(ztoADirectionBldr.build());
101 private void buildAtoZ(List<AToZ> etoeList, List<PceLink> path) {
103 PceLink lastLink = null;
104 AToZ lastResource = null;
106 // build A side Client TP
107 String tpName = path.get(0).getClient();
108 String xname = path.get(0).getSourceId().getValue();
109 TerminationPoint stp = new TerminationPointBuilder()
110 .setTpId(tpName).setTpNodeId(xname)
113 AToZKey clientKey = new AToZKey(index.toString());
114 Resource clientResource = new ResourceBuilder().setResource(stp).build();
115 AToZ firstResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
116 etoeList.add(firstResource);
118 for (PceLink pcelink : path) {
119 String srcName = pcelink.getSourceId().getValue();
121 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
122 .resource.resource.resource.Node sourceNode = new NodeBuilder()
127 AToZKey sourceKey = new AToZKey(index.toString());
128 Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).build();
129 AToZ srcResource = new AToZBuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
131 etoeList.add(srcResource);
134 tpName = pcelink.getSourceTP().toString();
135 stp = new TerminationPointBuilder()
136 .setTpNodeId(srcName).setTpId(tpName)
140 AToZKey srcTPKey = new AToZKey(index.toString());
141 Resource tpResource1 = new ResourceBuilder().setResource(stp).build();
142 AToZ stpResource = new AToZBuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
144 etoeList.add(stpResource);
146 String linkName = pcelink.getLinkId().getValue();
148 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
149 .resource.resource.resource.Link atozLink = new LinkBuilder()
154 AToZKey linkKey = new AToZKey(index.toString());
155 Resource nodeResource2 = new ResourceBuilder().setResource(atozLink).build();
156 AToZ linkResource = new AToZBuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
158 etoeList.add(linkResource);
160 String destName = pcelink.getDestId().getValue();
162 tpName = pcelink.getDestTP().toString();
163 TerminationPoint dtp = new TerminationPointBuilder()
164 .setTpNodeId(destName).setTpId(tpName)
168 AToZKey destTPKey = new AToZKey(index.toString());
169 Resource tpResource2 = new ResourceBuilder().setResource(dtp).build();
170 AToZ ttpResource = new AToZBuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
172 etoeList.add(ttpResource);
174 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
175 .resource.resource.resource.Node targetNode = new NodeBuilder()
180 AToZKey targetKey = new AToZKey(index.toString());
181 Resource nodeResource3 = new ResourceBuilder().setResource(targetNode).build();
182 lastResource = new AToZBuilder().setId(destName).withKey(targetKey).setResource(nodeResource3).build();
187 etoeList.add(lastResource);
189 // build Z side Client TP
190 tpName = lastLink.getClient();
191 xname = lastLink.getDestId().getValue();
192 stp = new TerminationPointBuilder()
193 .setTpNodeId(xname).setTpId(tpName)
198 clientKey = new AToZKey(index.toString());
199 clientResource = new ResourceBuilder().setResource(stp).build();
200 lastResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
201 etoeList.add(lastResource);
205 private void buildZtoA(List<ZToA> etoelist, List<PceLink> path) {
207 PceLink lastLink = null;
208 ZToA lastResource = null;
210 // build Z size Client TP
211 PceLink pcelink = this.allPceLinks.get(path.get(0).getOppositeLink());
212 String tpName = pcelink.getClient();
213 String xname = pcelink.getSourceId().getValue();
214 TerminationPoint stp = new TerminationPointBuilder()
215 .setTpNodeId(xname).setTpId(tpName)
218 ZToAKey clientKey = new ZToAKey(index.toString());
219 Resource clientResource = new ResourceBuilder().setResource(stp).build();
220 ZToA firstResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
221 etoelist.add(firstResource);
224 for (PceLink pcelinkAtoZ : path) {
226 pcelink = this.allPceLinks.get(pcelinkAtoZ.getOppositeLink());
227 LOG.debug("link to oppsite: {} to {}", pcelinkAtoZ.toString(), pcelink.toString());
229 String srcName = pcelink.getSourceId().getValue();
233 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
234 .resource.resource.resource.Node sourceNode = new NodeBuilder()
235 .setNodeId(srcName).build();
239 ZToAKey sourceKey = new ZToAKey(index.toString());
240 Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).build();
241 ZToA srcResource = new ZToABuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
243 etoelist.add(srcResource);
246 tpName = pcelink.getSourceTP().toString();
247 stp = new TerminationPointBuilder()
248 .setTpNodeId(srcName).setTpId(tpName)
252 ZToAKey srcTPKey = new ZToAKey(index.toString());
253 Resource tpResource1 = new ResourceBuilder().setResource(stp).build();
254 ZToA stpResource = new ZToABuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
256 etoelist.add(stpResource);
258 String linkName = pcelink.getLinkId().getValue();
260 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
261 .resource.resource.resource.Link ztoaLink = new LinkBuilder()
262 .setLinkId(linkName).build();
265 ZToAKey linkKey = new ZToAKey(index.toString());
266 Resource nodeResource2 = new ResourceBuilder().setResource(ztoaLink).build();
267 ZToA linkResource = new ZToABuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
269 etoelist.add(linkResource);
271 String destName = pcelink.getDestId().getValue();
273 tpName = pcelink.getDestTP().toString();
274 TerminationPoint ttp = new TerminationPointBuilder()
275 .setTpNodeId(destName).setTpId(tpName).build();
278 ZToAKey destTPKey = new ZToAKey(index.toString());
279 Resource tpResource2 = new ResourceBuilder().setResource(ttp).build();
280 ZToA ttpResource = new ZToABuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
282 etoelist.add(ttpResource);
285 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
286 .resource.resource.resource.Node targetNode = new NodeBuilder()
287 .setNodeId(destName).build();
289 ZToAKey targetKey = new ZToAKey(index.toString());
290 Resource nodeResource3 = new ResourceBuilder().setResource(targetNode).build();
291 lastResource = new ZToABuilder().setId(destName).withKey(targetKey).setResource(nodeResource3).build();
295 etoelist.add(lastResource);
297 // build Z side Client TP
298 tpName = lastLink.getClient();
299 xname = lastLink.getDestId().getValue();
300 stp = new TerminationPointBuilder()
301 .setTpNodeId(xname).setTpId(tpName).build();
305 clientKey = new ZToAKey(index.toString());
306 clientResource = new ResourceBuilder().setResource(stp).build();
307 lastResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
308 etoelist.add(lastResource);