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);
68 rc.setAtoZDirection(new AToZDirectionBuilder()
69 .setRate(rc.getRate())
70 .setAToZWavelengthNumber(rc.getResultWavelength())
71 .setAToZ(atozList).build());
73 pathZtoA = ImmutableList.copyOf(pathAtoZ).reverse();
74 LOG.info("In buildDescriptions: ZtoA {}", pathZtoA.toString());
76 List<ZToA> ztoaList = new ArrayList<ZToA>();
77 if (pathZtoA == null) {
78 rc.setRC(ResponseCodes.RESPONSE_FAILED);
79 LOG.error("In buildDescriptions: there is empty ZtoA path");
82 buildZtoA(ztoaList, pathZtoA);
84 rc.setZtoADirection(new ZToADirectionBuilder()
85 .setRate(rc.getRate())
86 .setZToAWavelengthNumber(rc.getResultWavelength())
87 .setZToA(ztoaList).build());
92 private void buildAtoZ(List<AToZ> etoeList, List<PceLink> path) {
95 PceLink lastLink = null;
96 AToZ lastResource = null;
98 // build A side Client TP
99 String tpName = path.get(0).getClient();
100 String xname = path.get(0).getSourceId().getValue();
101 TerminationPoint stp = new TerminationPointBuilder()
102 .setTpId(tpName).setTpNodeId(xname)
105 AToZKey clientKey = new AToZKey(index.toString());
106 Resource clientResource = new ResourceBuilder().setResource(stp).build();
107 AToZ firstResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
108 etoeList.add(firstResource);
110 for (PceLink pcelink : path) {
111 String srcName = pcelink.getSourceId().getValue();
113 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
114 .resource.resource.resource.Node sourceNode = new NodeBuilder()
119 AToZKey sourceKey = new AToZKey(index.toString());
120 Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).build();
121 AToZ srcResource = new AToZBuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
123 etoeList.add(srcResource);
126 tpName = pcelink.getSourceTP().toString();
127 stp = new TerminationPointBuilder()
128 .setTpNodeId(srcName).setTpId(tpName)
132 AToZKey srcTPKey = new AToZKey(index.toString());
133 Resource tpResource1 = new ResourceBuilder().setResource(stp).build();
134 AToZ stpResource = new AToZBuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
136 etoeList.add(stpResource);
138 String linkName = pcelink.getLinkId().getValue();
140 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
141 .resource.resource.resource.Link atozLink = new LinkBuilder()
146 AToZKey linkKey = new AToZKey(index.toString());
147 Resource nodeResource2 = new ResourceBuilder().setResource(atozLink).build();
148 AToZ linkResource = new AToZBuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
150 etoeList.add(linkResource);
152 String destName = pcelink.getDestId().getValue();
154 tpName = pcelink.getDestTP().toString();
155 TerminationPoint dtp = new TerminationPointBuilder()
156 .setTpNodeId(destName).setTpId(tpName)
160 AToZKey destTPKey = new AToZKey(index.toString());
161 Resource tpResource2 = new ResourceBuilder().setResource(dtp).build();
162 AToZ ttpResource = new AToZBuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
164 etoeList.add(ttpResource);
166 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
167 .resource.resource.resource.Node targetNode = new NodeBuilder()
172 AToZKey targetKey = new AToZKey(index.toString());
173 Resource nodeResource3 = new ResourceBuilder().setResource(targetNode).build();
174 lastResource = new AToZBuilder().setId(destName).withKey(targetKey).setResource(nodeResource3).build();
179 etoeList.add(lastResource);
181 // build Z side Client TP
182 tpName = lastLink.getClient();
183 xname = lastLink.getDestId().getValue();
184 stp = new TerminationPointBuilder()
185 .setTpNodeId(xname).setTpId(tpName)
190 clientKey = new AToZKey(index.toString());
191 clientResource = new ResourceBuilder().setResource(stp).build();
192 lastResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
193 etoeList.add(lastResource);
197 private void buildZtoA(List<ZToA> etoelist, List<PceLink> path) {
199 PceLink lastLink = null;
200 ZToA lastResource = null;
202 // build Z size Client TP
203 PceLink pcelink = this.allPceLinks.get(path.get(0).getOppositeLink());
204 String tpName = pcelink.getClient();
205 String xname = pcelink.getSourceId().getValue();
206 TerminationPoint stp = new TerminationPointBuilder()
207 .setTpNodeId(xname).setTpId(tpName)
210 ZToAKey clientKey = new ZToAKey(index.toString());
211 Resource clientResource = new ResourceBuilder().setResource(stp).build();
212 ZToA firstResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
213 etoelist.add(firstResource);
216 for (PceLink pcelinkAtoZ : path) {
218 pcelink = this.allPceLinks.get(pcelinkAtoZ.getOppositeLink());
219 LOG.debug("link to oppsite: {} to {}", pcelinkAtoZ.toString(), pcelink.toString());
221 String srcName = pcelink.getSourceId().getValue();
225 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
226 .resource.resource.resource.Node sourceNode = new NodeBuilder()
227 .setNodeId(srcName).build();
231 ZToAKey sourceKey = new ZToAKey(index.toString());
232 Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).build();
233 ZToA srcResource = new ZToABuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
235 etoelist.add(srcResource);
238 tpName = pcelink.getSourceTP().toString();
239 stp = new TerminationPointBuilder()
240 .setTpNodeId(srcName).setTpId(tpName)
244 ZToAKey srcTPKey = new ZToAKey(index.toString());
245 Resource tpResource1 = new ResourceBuilder().setResource(stp).build();
246 ZToA stpResource = new ZToABuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
248 etoelist.add(stpResource);
250 String linkName = pcelink.getLinkId().getValue();
252 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
253 .resource.resource.resource.Link ztoaLink = new LinkBuilder()
254 .setLinkId(linkName).build();
257 ZToAKey linkKey = new ZToAKey(index.toString());
258 Resource nodeResource2 = new ResourceBuilder().setResource(ztoaLink).build();
259 ZToA linkResource = new ZToABuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
261 etoelist.add(linkResource);
263 String destName = pcelink.getDestId().getValue();
265 tpName = pcelink.getDestTP().toString();
266 TerminationPoint ttp = new TerminationPointBuilder()
267 .setTpNodeId(destName).setTpId(tpName).build();
270 ZToAKey destTPKey = new ZToAKey(index.toString());
271 Resource tpResource2 = new ResourceBuilder().setResource(ttp).build();
272 ZToA ttpResource = new ZToABuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
274 etoelist.add(ttpResource);
277 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
278 .resource.resource.resource.Node targetNode = new NodeBuilder()
279 .setNodeId(destName).build();
281 ZToAKey targetKey = new ZToAKey(index.toString());
282 Resource nodeResource3 = new ResourceBuilder().setResource(targetNode).build();
283 lastResource = new ZToABuilder().setId(destName).withKey(targetKey).setResource(nodeResource3).build();
287 etoelist.add(lastResource);
289 // build Z side Client TP
290 tpName = lastLink.getClient();
291 xname = lastLink.getDestId().getValue();
292 stp = new TerminationPointBuilder()
293 .setTpNodeId(xname).setTpId(tpName).build();
297 clientKey = new ZToAKey(index.toString());
298 clientResource = new ResourceBuilder().setResource(stp).build();
299 lastResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
300 etoelist.add(lastResource);