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.rev170426.path.description.AToZDirectionBuilder;
16 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ZToADirectionBuilder;
17 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.atoz.direction.AToZ;
18 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.atoz.direction.AToZBuilder;
19 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.atoz.direction.AToZKey;
20 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ztoa.direction.ZToA;
21 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ztoa.direction.ZToABuilder;
22 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ztoa.direction.ZToAKey;
23 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.Resource;
24 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.ResourceBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.LinkBuilder;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.NodeBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.TerminationPoint;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.TerminationPointBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.link.LinkIdentifierBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.node.NodeIdentifierBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.termination.point.TerminationPointIdentifierBuilder;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.LinkId;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 public class PcePathDescription {
38 private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
40 private List<PceLink> pathAtoZ = null;
43 public PceResult getReturnStructure() {
47 private Map<LinkId, PceLink> allPceLinks = null;
49 private List<PceLink> pathZtoA = null;
51 public PcePathDescription(List<PceLink> pathAtoZ, Map<LinkId, PceLink> allPceLinks, PceResult rc) {
53 this.allPceLinks = allPceLinks;
54 this.pathAtoZ = pathAtoZ;
58 public PceResult buildDescriptions() {
59 LOG.info("In buildDescriptions: AtoZ {}", this.pathAtoZ.toString());
60 List<AToZ> atozList = new ArrayList<AToZ>();
61 if (this.pathAtoZ == null) {
62 this.rc.setRC(ResponseCodes.RESPONSE_FAILED);
63 LOG.error("In buildDescriptions: there is empty AtoZ path");
67 buildAtoZ(atozList, this.pathAtoZ);
69 this.rc.setAtoZDirection(new AToZDirectionBuilder().setRate(this.rc.getRate())
70 .setAToZWavelengthNumber(this.rc.getResultWavelength()).setAToZ(atozList).build());
72 this.pathZtoA = ImmutableList.copyOf(this.pathAtoZ).reverse();
73 LOG.info("In buildDescriptions: ZtoA {}", this.pathZtoA.toString());
75 List<ZToA> ztoaList = new ArrayList<ZToA>();
76 if (this.pathZtoA == null) {
77 this.rc.setRC(ResponseCodes.RESPONSE_FAILED);
78 LOG.error("In buildDescriptions: there is empty ZtoA path");
81 buildZtoA(ztoaList, this.pathZtoA);
83 this.rc.setZtoADirection(new ZToADirectionBuilder().setRate(this.rc.getRate())
84 .setZToAWavelengthNumber(this.rc.getResultWavelength()).setZToA(ztoaList).build());
89 private void buildAtoZ(List<AToZ> etoeList, List<PceLink> path) {
92 PceLink lastLink = null;
93 AToZ lastResource = null;
95 // build A side Client TP
96 String tpName = path.get(0).getClient();
97 String xname = path.get(0).getSourceId().getValue();
98 TerminationPoint stp = new TerminationPointBuilder()
99 .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
100 .setNodeId(xname).setTpId(tpName).build())
103 AToZKey clientKey = new AToZKey(index.toString());
104 Resource clientResource = new ResourceBuilder().setResource(stp).build();
105 AToZ firstResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
106 etoeList.add(firstResource);
110 for (PceLink pcelink : path) {
112 String srcName = pcelink.getSourceId().getValue();
115 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce
116 .resource.resource.resource.Node sourceNode = new NodeBuilder()
117 .setNodeIdentifier(new NodeIdentifierBuilder().setNodeId(srcName).build())
121 AToZKey sourceKey = new AToZKey(index.toString());
122 Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).build();
123 AToZ srcResource = new AToZBuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
125 etoeList.add(srcResource);
128 tpName = pcelink.getSourceTP().toString();
129 stp = new TerminationPointBuilder()
130 .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
131 .setNodeId(srcName).setTpId(tpName).build())
135 AToZKey srcTPKey = new AToZKey(index.toString());// tpName);
136 Resource tpResource1 = new ResourceBuilder().setResource(stp).build();
137 AToZ stpResource = new AToZBuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
139 etoeList.add(stpResource);
141 String linkName = pcelink.getLinkId().getValue();
143 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce
144 .resource.resource.resource.Link atozLink = new LinkBuilder()
145 .setLinkIdentifier(new LinkIdentifierBuilder().setLinkId(linkName).build())
149 AToZKey linkKey = new AToZKey(index.toString());
150 Resource nodeResource2 = new ResourceBuilder().setResource(atozLink).build();
151 AToZ linkResource = new AToZBuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
153 etoeList.add(linkResource);
155 String destName = pcelink.getDestId().getValue();
157 tpName = pcelink.getDestTP().toString();
158 TerminationPoint dtp = new TerminationPointBuilder()
159 .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
160 .setNodeId(destName).setTpId(tpName).build())
164 AToZKey destTPKey = new AToZKey(index.toString());
165 Resource tpResource2 = new ResourceBuilder().setResource(dtp).build();
166 AToZ ttpResource = new AToZBuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
168 etoeList.add(ttpResource);
170 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce
171 .resource.resource.resource.Node targetNode = new NodeBuilder()
172 .setNodeIdentifier(new NodeIdentifierBuilder().setNodeId(destName).build())
176 AToZKey targetKey = new AToZKey(index.toString());
177 Resource nodeResource3 = new ResourceBuilder().setResource(targetNode).build();
178 lastResource = new AToZBuilder().setId(destName).withKey(targetKey).setResource(nodeResource3).build();
183 etoeList.add(lastResource);
185 // build Z side Client TP
186 tpName = lastLink.getClient();
187 xname = lastLink.getDestId().getValue();
188 stp = new TerminationPointBuilder()
189 .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
190 .setNodeId(xname).setTpId(tpName).build())
195 clientKey = new AToZKey(index.toString());
196 clientResource = new ResourceBuilder().setResource(stp).build();
197 lastResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
198 etoeList.add(lastResource);
202 private void buildZtoA(List<ZToA> etoelist, List<PceLink> path) {
204 PceLink lastLink = null;
205 ZToA lastResource = null;
207 // build Z size Client TP
208 PceLink pcelink = this.allPceLinks.get(path.get(0).getOppositeLink());
209 String tpName = pcelink.getClient();
210 String xname = pcelink.getSourceId().getValue();
211 TerminationPoint stp = new TerminationPointBuilder()
212 .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
213 .setNodeId(xname).setTpId(tpName).build())
216 ZToAKey clientKey = new ZToAKey(index.toString());
217 Resource clientResource = new ResourceBuilder().setResource(stp).build();
218 ZToA firstResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
219 etoelist.add(firstResource);
222 for (PceLink pcelinkAtoZ : path) {
224 pcelink = this.allPceLinks.get(pcelinkAtoZ.getOppositeLink());
225 LOG.debug("link to oppsite: {} to {}", pcelinkAtoZ.toString(), pcelink.toString());
227 String srcName = pcelink.getSourceId().getValue();
231 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce
232 .resource.resource.resource.Node sourceNode = new NodeBuilder()
233 .setNodeIdentifier(new NodeIdentifierBuilder().setNodeId(srcName).build()).build();
238 ZToAKey sourceKey = new ZToAKey(index.toString());
239 Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).build();
240 ZToA srcResource = new ZToABuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
242 etoelist.add(srcResource);
245 tpName = pcelink.getSourceTP().toString();
246 stp = new TerminationPointBuilder()
247 .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
248 .setNodeId(srcName).setTpId(tpName).build())
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.rev170426.pce
261 .resource.resource.resource.Link ztoaLink = new LinkBuilder()
262 .setLinkIdentifier(new LinkIdentifierBuilder().setLinkId(linkName).build()).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 .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
276 .setNodeId(destName).setTpId(tpName).build())
280 ZToAKey destTPKey = new ZToAKey(index.toString());
281 Resource tpResource2 = new ResourceBuilder().setResource(ttp).build();
282 ZToA ttpResource = new ZToABuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
284 etoelist.add(ttpResource);
287 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce
288 .resource.resource.resource.Node targetNode = new NodeBuilder()
289 .setNodeIdentifier(new NodeIdentifierBuilder().setNodeId(destName).build()).build();
291 ZToAKey targetKey = new ZToAKey(index.toString());
292 Resource nodeResource3 = new ResourceBuilder().setResource(targetNode).build();
293 lastResource = new ZToABuilder().setId(destName).withKey(targetKey).setResource(nodeResource3).build();
297 etoelist.add(lastResource);
299 // build Z side Client TP
300 tpName = lastLink.getClient();
301 xname = lastLink.getDestId().getValue();
302 stp = new TerminationPointBuilder()
303 .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
304 .setNodeId(xname).setTpId(tpName).build())
309 clientKey = new ZToAKey(index.toString());
310 clientResource = new ResourceBuilder().setResource(stp).build();
311 lastResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
312 etoelist.add(lastResource);