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;
12 import java.util.ArrayList;
13 import java.util.List;
16 import org.opendaylight.transportpce.common.ResponseCodes;
17 import org.opendaylight.transportpce.pce.networkanalyzer.PceLink;
18 import org.opendaylight.transportpce.pce.networkanalyzer.PceResult;
19 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.AToZDirectionBuilder;
20 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ZToADirectionBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.atoz.direction.AToZ;
22 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.atoz.direction.AToZBuilder;
23 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.atoz.direction.AToZKey;
24 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ztoa.direction.ZToA;
25 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ztoa.direction.ZToABuilder;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ztoa.direction.ZToAKey;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.Resource;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.ResourceBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.LinkBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.NodeBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.TerminationPoint;
32 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.TerminationPointBuilder;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public class PcePathDescription {
39 private static final Logger LOG = LoggerFactory.getLogger(PcePathDescription.class);
41 private List<PceLink> pathAtoZ = null;
42 private List<PceLink> pathZtoA = null;
44 private Map<LinkId, PceLink> allPceLinks = null;
46 public PcePathDescription(List<PceLink> pathAtoZ, Map<LinkId, PceLink> allPceLinks, PceResult rc) {
48 this.allPceLinks = allPceLinks;
49 this.pathAtoZ = pathAtoZ;
53 public PceResult buildDescriptions() {
54 LOG.info("In buildDescriptions: AtoZ = {}", pathAtoZ);
55 List<AToZ> atozList = new ArrayList<>();
56 if (pathAtoZ == null) {
57 rc.setRC(ResponseCodes.RESPONSE_FAILED);
58 LOG.error("In buildDescriptions: there is empty AtoZ path");
62 buildAtoZ(atozList, pathAtoZ);
63 AToZDirectionBuilder atoZDirectionBldr = new AToZDirectionBuilder()
64 .setRate(rc.getRate())
66 if ("100GE".equals(rc.getServiceType()) || "OTU4".equals(rc.getServiceType())) {
67 atoZDirectionBldr.setAToZWavelengthNumber(rc.getResultWavelength());
68 } else if ("10GE".equals(rc.getServiceType()) || "1GE".equals(rc.getServiceType())
69 || "ODU4".equals(rc.getServiceType())) {
70 atoZDirectionBldr.setAToZWavelengthNumber(Long.valueOf(0));
72 rc.setAtoZDirection(atoZDirectionBldr.build());
73 pathZtoA = ImmutableList.copyOf(pathAtoZ).reverse();
74 LOG.info("In buildDescriptions: ZtoA {}", pathZtoA);
76 List<ZToA> ztoaList = new ArrayList<>();
77 if (pathZtoA == null) {
78 rc.setRC(ResponseCodes.RESPONSE_FAILED);
79 LOG.error("In buildDescriptions: there is empty ZtoA path");
82 buildZtoA(ztoaList, pathZtoA);
83 ZToADirectionBuilder ztoADirectionBldr = new ZToADirectionBuilder()
84 .setRate(rc.getRate())
86 if ("100GE".equals(rc.getServiceType()) || "OTU4".equals(rc.getServiceType())) {
87 ztoADirectionBldr.setZToAWavelengthNumber(rc.getResultWavelength());
88 } else if ("10GE".equals(rc.getServiceType()) || "1GE".equals(rc.getServiceType())
89 || "ODU4".equals(rc.getServiceType())) {
90 ztoADirectionBldr.setZToAWavelengthNumber(Long.valueOf(0));
92 rc.setZtoADirection(ztoADirectionBldr.build());
97 private void buildAtoZ(List<AToZ> etoeList, List<PceLink> path) {
99 PceLink lastLink = null;
100 AToZ lastResource = null;
102 // build A side Client TP
103 String tpName = path.get(0).getClient();
104 String xname = path.get(0).getSourceId().getValue();
105 TerminationPoint stp = new TerminationPointBuilder()
106 .setTpId(tpName).setTpNodeId(xname)
109 AToZKey clientKey = new AToZKey(index.toString());
110 Resource clientResource = new ResourceBuilder().setResource(stp).build();
111 AToZ firstResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
112 etoeList.add(firstResource);
114 for (PceLink pcelink : path) {
115 String srcName = pcelink.getSourceId().getValue();
117 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
118 .resource.resource.resource.Node sourceNode = new NodeBuilder()
123 AToZKey sourceKey = new AToZKey(index.toString());
124 Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).build();
125 AToZ srcResource = new AToZBuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
127 etoeList.add(srcResource);
130 tpName = pcelink.getSourceTP().toString();
131 stp = new TerminationPointBuilder()
132 .setTpNodeId(srcName).setTpId(tpName)
136 AToZKey srcTPKey = new AToZKey(index.toString());
137 Resource tpResource1 = new ResourceBuilder().setResource(stp).build();
138 AToZ stpResource = new AToZBuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
140 etoeList.add(stpResource);
142 String linkName = pcelink.getLinkId().getValue();
144 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
145 .resource.resource.resource.Link atozLink = new LinkBuilder()
150 AToZKey linkKey = new AToZKey(index.toString());
151 Resource nodeResource2 = new ResourceBuilder().setResource(atozLink).build();
152 AToZ linkResource = new AToZBuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
154 etoeList.add(linkResource);
156 String destName = pcelink.getDestId().getValue();
158 tpName = pcelink.getDestTP().toString();
159 TerminationPoint dtp = new TerminationPointBuilder()
160 .setTpNodeId(destName).setTpId(tpName)
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.rev171017.pce
171 .resource.resource.resource.Node targetNode = new NodeBuilder()
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 .setTpNodeId(xname).setTpId(tpName)
193 clientKey = new AToZKey(index.toString());
194 clientResource = new ResourceBuilder().setResource(stp).build();
195 lastResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
196 etoeList.add(lastResource);
200 private void buildZtoA(List<ZToA> etoelist, List<PceLink> path) {
202 PceLink lastLink = null;
203 ZToA lastResource = null;
205 // build Z size Client TP
206 PceLink pcelink = this.allPceLinks.get(path.get(0).getOppositeLink());
207 String tpName = pcelink.getClient();
208 String xname = pcelink.getSourceId().getValue();
209 TerminationPoint stp = new TerminationPointBuilder()
210 .setTpNodeId(xname).setTpId(tpName)
213 ZToAKey clientKey = new ZToAKey(index.toString());
214 Resource clientResource = new ResourceBuilder().setResource(stp).build();
215 ZToA firstResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
216 etoelist.add(firstResource);
219 for (PceLink pcelinkAtoZ : path) {
221 pcelink = this.allPceLinks.get(pcelinkAtoZ.getOppositeLink());
222 LOG.debug("link to oppsite: {} to {}", pcelinkAtoZ, pcelink);
224 String srcName = pcelink.getSourceId().getValue();
228 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
229 .resource.resource.resource.Node sourceNode = new NodeBuilder()
230 .setNodeId(srcName).build();
234 ZToAKey sourceKey = new ZToAKey(index.toString());
235 Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).build();
236 ZToA srcResource = new ZToABuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
238 etoelist.add(srcResource);
241 tpName = pcelink.getSourceTP().toString();
242 stp = new TerminationPointBuilder()
243 .setTpNodeId(srcName).setTpId(tpName)
247 ZToAKey srcTPKey = new ZToAKey(index.toString());
248 Resource tpResource1 = new ResourceBuilder().setResource(stp).build();
249 ZToA stpResource = new ZToABuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
251 etoelist.add(stpResource);
253 String linkName = pcelink.getLinkId().getValue();
255 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
256 .resource.resource.resource.Link ztoaLink = new LinkBuilder()
257 .setLinkId(linkName).build();
260 ZToAKey linkKey = new ZToAKey(index.toString());
261 Resource nodeResource2 = new ResourceBuilder().setResource(ztoaLink).build();
262 ZToA linkResource = new ZToABuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
264 etoelist.add(linkResource);
266 String destName = pcelink.getDestId().getValue();
268 tpName = pcelink.getDestTP().toString();
269 TerminationPoint ttp = new TerminationPointBuilder()
270 .setTpNodeId(destName).setTpId(tpName).build();
273 ZToAKey destTPKey = new ZToAKey(index.toString());
274 Resource tpResource2 = new ResourceBuilder().setResource(ttp).build();
275 ZToA ttpResource = new ZToABuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
277 etoelist.add(ttpResource);
280 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
281 .resource.resource.resource.Node targetNode = new NodeBuilder()
282 .setNodeId(destName).build();
284 ZToAKey targetKey = new ZToAKey(index.toString());
285 Resource nodeResource3 = new ResourceBuilder().setResource(targetNode).build();
286 lastResource = new ZToABuilder().setId(destName).withKey(targetKey).setResource(nodeResource3).build();
290 etoelist.add(lastResource);
292 // build Z side Client TP
293 tpName = lastLink.getClient();
294 xname = lastLink.getDestId().getValue();
295 stp = new TerminationPointBuilder()
296 .setTpNodeId(xname).setTpId(tpName).build();
299 clientKey = new ZToAKey(index.toString());
300 clientResource = new ResourceBuilder().setResource(stp).build();
301 lastResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
302 etoelist.add(lastResource);
305 public PceResult getReturnStructure() {