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.rev180226.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());
132 Resource tpResource1 = new ResourceBuilder().setResource(stp).build();
133 AToZ stpResource = new AToZBuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
135 etoeList.add(stpResource);
137 String linkName = pcelink.getLinkId().getValue();
139 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
140 .resource.resource.resource.Link atozLink = new LinkBuilder()
145 AToZKey linkKey = new AToZKey(index.toString());
146 Resource nodeResource2 = new ResourceBuilder().setResource(atozLink).build();
147 AToZ linkResource = new AToZBuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
149 etoeList.add(linkResource);
151 String destName = pcelink.getDestId().getValue();
153 tpName = pcelink.getDestTP().toString();
154 TerminationPoint dtp = new TerminationPointBuilder()
155 .setTpNodeId(destName).setTpId(tpName)
159 AToZKey destTPKey = new AToZKey(index.toString());
160 Resource tpResource2 = new ResourceBuilder().setResource(dtp).build();
161 AToZ ttpResource = new AToZBuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
163 etoeList.add(ttpResource);
165 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
166 .resource.resource.resource.Node targetNode = new NodeBuilder()
171 AToZKey targetKey = new AToZKey(index.toString());
172 Resource nodeResource3 = new ResourceBuilder().setResource(targetNode).build();
173 lastResource = new AToZBuilder().setId(destName).withKey(targetKey).setResource(nodeResource3).build();
178 etoeList.add(lastResource);
180 // build Z side Client TP
181 tpName = lastLink.getClient();
182 xname = lastLink.getDestId().getValue();
183 stp = new TerminationPointBuilder()
184 .setTpNodeId(xname).setTpId(tpName)
189 clientKey = new AToZKey(index.toString());
190 clientResource = new ResourceBuilder().setResource(stp).build();
191 lastResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
192 etoeList.add(lastResource);
196 private void buildZtoA(List<ZToA> etoelist, List<PceLink> path) {
198 PceLink lastLink = null;
199 ZToA lastResource = null;
201 // build Z size Client TP
202 PceLink pcelink = this.allPceLinks.get(path.get(0).getOppositeLink());
203 String tpName = pcelink.getClient();
204 String xname = pcelink.getSourceId().getValue();
205 TerminationPoint stp = new TerminationPointBuilder()
206 .setTpNodeId(xname).setTpId(tpName)
209 ZToAKey clientKey = new ZToAKey(index.toString());
210 Resource clientResource = new ResourceBuilder().setResource(stp).build();
211 ZToA firstResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
212 etoelist.add(firstResource);
215 for (PceLink pcelinkAtoZ : path) {
217 pcelink = this.allPceLinks.get(pcelinkAtoZ.getOppositeLink());
218 LOG.debug("link to oppsite: {} to {}", pcelinkAtoZ.toString(), pcelink.toString());
220 String srcName = pcelink.getSourceId().getValue();
224 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
225 .resource.resource.resource.Node sourceNode = new NodeBuilder()
226 .setNodeId(srcName).build();
230 ZToAKey sourceKey = new ZToAKey(index.toString());
231 Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).build();
232 ZToA srcResource = new ZToABuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
234 etoelist.add(srcResource);
237 tpName = pcelink.getSourceTP().toString();
238 stp = new TerminationPointBuilder()
239 .setTpNodeId(srcName).setTpId(tpName)
243 ZToAKey srcTPKey = new ZToAKey(index.toString());
244 Resource tpResource1 = new ResourceBuilder().setResource(stp).build();
245 ZToA stpResource = new ZToABuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
247 etoelist.add(stpResource);
249 String linkName = pcelink.getLinkId().getValue();
251 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
252 .resource.resource.resource.Link ztoaLink = new LinkBuilder()
253 .setLinkId(linkName).build();
256 ZToAKey linkKey = new ZToAKey(index.toString());
257 Resource nodeResource2 = new ResourceBuilder().setResource(ztoaLink).build();
258 ZToA linkResource = new ZToABuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
260 etoelist.add(linkResource);
262 String destName = pcelink.getDestId().getValue();
264 tpName = pcelink.getDestTP().toString();
265 TerminationPoint ttp = new TerminationPointBuilder()
266 .setTpNodeId(destName).setTpId(tpName).build();
269 ZToAKey destTPKey = new ZToAKey(index.toString());
270 Resource tpResource2 = new ResourceBuilder().setResource(ttp).build();
271 ZToA ttpResource = new ZToABuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
273 etoelist.add(ttpResource);
276 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
277 .resource.resource.resource.Node targetNode = new NodeBuilder()
278 .setNodeId(destName).build();
280 ZToAKey targetKey = new ZToAKey(index.toString());
281 Resource nodeResource3 = new ResourceBuilder().setResource(targetNode).build();
282 lastResource = new ZToABuilder().setId(destName).withKey(targetKey).setResource(nodeResource3).build();
286 etoelist.add(lastResource);
288 // build Z side Client TP
289 tpName = lastLink.getClient();
290 xname = lastLink.getDestId().getValue();
291 stp = new TerminationPointBuilder()
292 .setTpNodeId(xname).setTpId(tpName).build();
296 clientKey = new ZToAKey(index.toString());
297 clientResource = new ResourceBuilder().setResource(stp).build();
298 lastResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
299 etoelist.add(lastResource);