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.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.AToZDirectionBuilder;
16 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ZToADirectionBuilder;
17 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.atoz.direction.AToZ;
18 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.atoz.direction.AToZBuilder;
19 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.atoz.direction.AToZKey;
20 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ztoa.direction.ZToA;
21 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ztoa.direction.ZToABuilder;
22 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ztoa.direction.ZToAKey;
23 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.Resource;
24 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.ResourceBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.LinkBuilder;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.NodeBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.TerminationPoint;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.TerminationPointBuilder;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.LinkId;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 public class PcePathDescription {
35 private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
37 private List<PceLink> pathAtoZ = null;
40 public PceResult getReturnStructure() {
44 private Map<LinkId, PceLink> allPceLinks = null;
46 private List<PceLink> pathZtoA = null;
48 public PcePathDescription(List<PceLink> pathAtoZ, Map<LinkId, PceLink> allPceLinks, PceResult rc) {
50 this.allPceLinks = allPceLinks;
51 this.pathAtoZ = pathAtoZ;
55 public PceResult buildDescriptions() {
56 LOG.info("In buildDescriptions: AtoZ {}", this.pathAtoZ.toString());
57 List<AToZ> atozList = new ArrayList<AToZ>();
58 if (this.pathAtoZ == null) {
59 this.rc.setRC(ResponseCodes.RESPONSE_FAILED);
60 LOG.error("In buildDescriptions: there is empty AtoZ path");
64 buildAtoZ(atozList, this.pathAtoZ);
66 this.rc.setAtoZDirection(new AToZDirectionBuilder().setRate(this.rc.getRate())
67 .setAToZWavelengthNumber(this.rc.getResultWavelength()).setAToZ(atozList).build());
69 this.pathZtoA = ImmutableList.copyOf(this.pathAtoZ).reverse();
70 LOG.info("In buildDescriptions: ZtoA {}", this.pathZtoA.toString());
72 List<ZToA> ztoaList = new ArrayList<ZToA>();
73 if (this.pathZtoA == null) {
74 this.rc.setRC(ResponseCodes.RESPONSE_FAILED);
75 LOG.error("In buildDescriptions: there is empty ZtoA path");
78 buildZtoA(ztoaList, this.pathZtoA);
80 this.rc.setZtoADirection(new ZToADirectionBuilder().setRate(this.rc.getRate())
81 .setZToAWavelengthNumber(this.rc.getResultWavelength()).setZToA(ztoaList).build());
86 private void buildAtoZ(List<AToZ> etoeList, List<PceLink> path) {
89 PceLink lastLink = null;
90 AToZ lastResource = null;
92 // build A side Client TP
93 String tpName = path.get(0).getClient();
94 String xname = path.get(0).getSourceId().getValue();
95 TerminationPoint stp = new TerminationPointBuilder()
96 .setTpId(tpName).setTpNodeId(xname)
99 AToZKey clientKey = new AToZKey(index.toString());
100 Resource clientResource = new ResourceBuilder().setResource(stp).build();
101 AToZ firstResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
102 etoeList.add(firstResource);
106 for (PceLink pcelink : path) {
108 String srcName = pcelink.getSourceId().getValue();
111 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
112 .resource.resource.resource.Node sourceNode = new NodeBuilder()
117 AToZKey sourceKey = new AToZKey(index.toString());
118 Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).build();
119 AToZ srcResource = new AToZBuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
121 etoeList.add(srcResource);
124 tpName = pcelink.getSourceTP().toString();
125 stp = new TerminationPointBuilder()
126 .setTpNodeId(srcName).setTpId(tpName)
130 AToZKey srcTPKey = new AToZKey(index.toString());// tpName);
131 Resource tpResource1 = new ResourceBuilder().setResource(stp).build();
132 AToZ stpResource = new AToZBuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
134 etoeList.add(stpResource);
136 String linkName = pcelink.getLinkId().getValue();
138 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
139 .resource.resource.resource.Link atozLink = new LinkBuilder()
144 AToZKey linkKey = new AToZKey(index.toString());
145 Resource nodeResource2 = new ResourceBuilder().setResource(atozLink).build();
146 AToZ linkResource = new AToZBuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
148 etoeList.add(linkResource);
150 String destName = pcelink.getDestId().getValue();
152 tpName = pcelink.getDestTP().toString();
153 TerminationPoint dtp = new TerminationPointBuilder()
154 .setTpNodeId(destName).setTpId(tpName)
158 AToZKey destTPKey = new AToZKey(index.toString());
159 Resource tpResource2 = new ResourceBuilder().setResource(dtp).build();
160 AToZ ttpResource = new AToZBuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
162 etoeList.add(ttpResource);
164 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
165 .resource.resource.resource.Node targetNode = new NodeBuilder()
170 AToZKey targetKey = new AToZKey(index.toString());
171 Resource nodeResource3 = new ResourceBuilder().setResource(targetNode).build();
172 lastResource = new AToZBuilder().setId(destName).withKey(targetKey).setResource(nodeResource3).build();
177 etoeList.add(lastResource);
179 // build Z side Client TP
180 tpName = lastLink.getClient();
181 xname = lastLink.getDestId().getValue();
182 stp = new TerminationPointBuilder()
183 .setTpNodeId(xname).setTpId(tpName)
188 clientKey = new AToZKey(index.toString());
189 clientResource = new ResourceBuilder().setResource(stp).build();
190 lastResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
191 etoeList.add(lastResource);
195 private void buildZtoA(List<ZToA> etoelist, List<PceLink> path) {
197 PceLink lastLink = null;
198 ZToA lastResource = null;
200 // build Z size Client TP
201 PceLink pcelink = this.allPceLinks.get(path.get(0).getOppositeLink());
202 String tpName = pcelink.getClient();
203 String xname = pcelink.getSourceId().getValue();
204 TerminationPoint stp = new TerminationPointBuilder()
205 .setTpNodeId(xname).setTpId(tpName)
208 ZToAKey clientKey = new ZToAKey(index.toString());
209 Resource clientResource = new ResourceBuilder().setResource(stp).build();
210 ZToA firstResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
211 etoelist.add(firstResource);
214 for (PceLink pcelinkAtoZ : path) {
216 pcelink = this.allPceLinks.get(pcelinkAtoZ.getOppositeLink());
217 LOG.debug("link to oppsite: {} to {}", pcelinkAtoZ.toString(), pcelink.toString());
219 String srcName = pcelink.getSourceId().getValue();
223 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
224 .resource.resource.resource.Node sourceNode = new NodeBuilder()
225 .setNodeId(srcName).build();
229 ZToAKey sourceKey = new ZToAKey(index.toString());
230 Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).build();
231 ZToA srcResource = new ZToABuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
233 etoelist.add(srcResource);
236 tpName = pcelink.getSourceTP().toString();
237 stp = new TerminationPointBuilder()
238 .setTpNodeId(srcName).setTpId(tpName)
242 ZToAKey srcTPKey = new ZToAKey(index.toString());
243 Resource tpResource1 = new ResourceBuilder().setResource(stp).build();
244 ZToA stpResource = new ZToABuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
246 etoelist.add(stpResource);
248 String linkName = pcelink.getLinkId().getValue();
250 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
251 .resource.resource.resource.Link ztoaLink = new LinkBuilder()
252 .setLinkId(linkName).build();
255 ZToAKey linkKey = new ZToAKey(index.toString());
256 Resource nodeResource2 = new ResourceBuilder().setResource(ztoaLink).build();
257 ZToA linkResource = new ZToABuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
259 etoelist.add(linkResource);
261 String destName = pcelink.getDestId().getValue();
263 tpName = pcelink.getDestTP().toString();
264 TerminationPoint ttp = new TerminationPointBuilder()
265 .setTpNodeId(destName).setTpId(tpName).build();
268 ZToAKey destTPKey = new ZToAKey(index.toString());
269 Resource tpResource2 = new ResourceBuilder().setResource(ttp).build();
270 ZToA ttpResource = new ZToABuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
272 etoelist.add(ttpResource);
275 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
276 .resource.resource.resource.Node targetNode = new NodeBuilder()
277 .setNodeId(destName).build();
279 ZToAKey targetKey = new ZToAKey(index.toString());
280 Resource nodeResource3 = new ResourceBuilder().setResource(targetNode).build();
281 lastResource = new ZToABuilder().setId(destName).withKey(targetKey).setResource(nodeResource3).build();
285 etoelist.add(lastResource);
287 // build Z side Client TP
288 tpName = lastLink.getClient();
289 xname = lastLink.getDestId().getValue();
290 stp = new TerminationPointBuilder()
291 .setTpNodeId(xname).setTpId(tpName).build();
295 clientKey = new ZToAKey(index.toString());
296 clientResource = new ResourceBuilder().setResource(stp).build();
297 lastResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
298 etoelist.add(lastResource);