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;
40 private List<PceLink> pathZtoA = null;
42 private Map<LinkId, PceLink> allPceLinks = null;
44 public PcePathDescription(List<PceLink> pathAtoZ, Map<LinkId, PceLink> allPceLinks, PceResult rc) {
46 this.allPceLinks = allPceLinks;
47 this.pathAtoZ = pathAtoZ;
51 public PceResult buildDescriptions() {
52 LOG.info("In buildDescriptions: AtoZ = {}", pathAtoZ);
53 List<AToZ> atozList = new ArrayList<>();
54 if (pathAtoZ == null) {
55 rc.setRC(ResponseCodes.RESPONSE_FAILED);
56 LOG.error("In buildDescriptions: there is empty AtoZ path");
60 buildAtoZ(atozList, pathAtoZ);
61 AToZDirectionBuilder atoZDirectionBldr = new AToZDirectionBuilder()
62 .setRate(rc.getRate())
64 if ("100GE".equals(rc.getServiceType()) || "OTU4".equals(rc.getServiceType())) {
65 atoZDirectionBldr.setAToZWavelengthNumber(rc.getResultWavelength());
66 } else if ("10GE".equals(rc.getServiceType()) || "1GE".equals(rc.getServiceType())
67 || "ODU4".equals(rc.getServiceType())) {
68 atoZDirectionBldr.setAToZWavelengthNumber(Long.valueOf(0));
70 rc.setAtoZDirection(atoZDirectionBldr.build());
71 pathZtoA = ImmutableList.copyOf(pathAtoZ).reverse();
72 LOG.info("In buildDescriptions: ZtoA {}", pathZtoA);
74 List<ZToA> ztoaList = new ArrayList<>();
75 if (pathZtoA == null) {
76 rc.setRC(ResponseCodes.RESPONSE_FAILED);
77 LOG.error("In buildDescriptions: there is empty ZtoA path");
80 buildZtoA(ztoaList, pathZtoA);
81 ZToADirectionBuilder ztoADirectionBldr = new ZToADirectionBuilder()
82 .setRate(rc.getRate())
84 if ("100GE".equals(rc.getServiceType()) || "OTU4".equals(rc.getServiceType())) {
85 ztoADirectionBldr.setZToAWavelengthNumber(rc.getResultWavelength());
86 } else if ("10GE".equals(rc.getServiceType()) || "1GE".equals(rc.getServiceType())
87 || "ODU4".equals(rc.getServiceType())) {
88 ztoADirectionBldr.setZToAWavelengthNumber(Long.valueOf(0));
90 rc.setZtoADirection(ztoADirectionBldr.build());
95 private void buildAtoZ(List<AToZ> etoeList, List<PceLink> path) {
97 PceLink lastLink = null;
98 AToZ lastResource = null;
100 // build A side Client TP
101 String tpName = path.get(0).getClient();
102 String xname = path.get(0).getSourceId().getValue();
103 TerminationPoint stp = new TerminationPointBuilder()
104 .setTpId(tpName).setTpNodeId(xname)
107 AToZKey clientKey = new AToZKey(index.toString());
108 Resource clientResource = new ResourceBuilder().setResource(stp).build();
109 AToZ firstResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
110 etoeList.add(firstResource);
112 for (PceLink pcelink : path) {
113 String srcName = pcelink.getSourceId().getValue();
115 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
116 .resource.resource.resource.Node sourceNode = new NodeBuilder()
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 .setTpNodeId(srcName).setTpId(tpName)
134 AToZKey srcTPKey = new AToZKey(index.toString());
135 Resource tpResource1 = new ResourceBuilder().setResource(stp).build();
136 AToZ stpResource = new AToZBuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
138 etoeList.add(stpResource);
140 String linkName = pcelink.getLinkId().getValue();
142 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
143 .resource.resource.resource.Link atozLink = new LinkBuilder()
148 AToZKey linkKey = new AToZKey(index.toString());
149 Resource nodeResource2 = new ResourceBuilder().setResource(atozLink).build();
150 AToZ linkResource = new AToZBuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
152 etoeList.add(linkResource);
154 String destName = pcelink.getDestId().getValue();
156 tpName = pcelink.getDestTP().toString();
157 TerminationPoint dtp = new TerminationPointBuilder()
158 .setTpNodeId(destName).setTpId(tpName)
162 AToZKey destTPKey = new AToZKey(index.toString());
163 Resource tpResource2 = new ResourceBuilder().setResource(dtp).build();
164 AToZ ttpResource = new AToZBuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
166 etoeList.add(ttpResource);
168 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
169 .resource.resource.resource.Node targetNode = new NodeBuilder()
174 AToZKey targetKey = new AToZKey(index.toString());
175 Resource nodeResource3 = new ResourceBuilder().setResource(targetNode).build();
176 lastResource = new AToZBuilder().setId(destName).withKey(targetKey).setResource(nodeResource3).build();
181 etoeList.add(lastResource);
183 // build Z side Client TP
184 tpName = lastLink.getClient();
185 xname = lastLink.getDestId().getValue();
186 stp = new TerminationPointBuilder()
187 .setTpNodeId(xname).setTpId(tpName)
191 clientKey = new AToZKey(index.toString());
192 clientResource = new ResourceBuilder().setResource(stp).build();
193 lastResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
194 etoeList.add(lastResource);
198 private void buildZtoA(List<ZToA> etoelist, List<PceLink> path) {
200 PceLink lastLink = null;
201 ZToA lastResource = null;
203 // build Z size Client TP
204 PceLink pcelink = this.allPceLinks.get(path.get(0).getOppositeLink());
205 String tpName = pcelink.getClient();
206 String xname = pcelink.getSourceId().getValue();
207 TerminationPoint stp = new TerminationPointBuilder()
208 .setTpNodeId(xname).setTpId(tpName)
211 ZToAKey clientKey = new ZToAKey(index.toString());
212 Resource clientResource = new ResourceBuilder().setResource(stp).build();
213 ZToA firstResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
214 etoelist.add(firstResource);
217 for (PceLink pcelinkAtoZ : path) {
219 pcelink = this.allPceLinks.get(pcelinkAtoZ.getOppositeLink());
220 LOG.debug("link to oppsite: {} to {}", pcelinkAtoZ, pcelink);
222 String srcName = pcelink.getSourceId().getValue();
226 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
227 .resource.resource.resource.Node sourceNode = new NodeBuilder()
228 .setNodeId(srcName).build();
232 ZToAKey sourceKey = new ZToAKey(index.toString());
233 Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).build();
234 ZToA srcResource = new ZToABuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
236 etoelist.add(srcResource);
239 tpName = pcelink.getSourceTP().toString();
240 stp = new TerminationPointBuilder()
241 .setTpNodeId(srcName).setTpId(tpName)
245 ZToAKey srcTPKey = new ZToAKey(index.toString());
246 Resource tpResource1 = new ResourceBuilder().setResource(stp).build();
247 ZToA stpResource = new ZToABuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
249 etoelist.add(stpResource);
251 String linkName = pcelink.getLinkId().getValue();
253 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
254 .resource.resource.resource.Link ztoaLink = new LinkBuilder()
255 .setLinkId(linkName).build();
258 ZToAKey linkKey = new ZToAKey(index.toString());
259 Resource nodeResource2 = new ResourceBuilder().setResource(ztoaLink).build();
260 ZToA linkResource = new ZToABuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
262 etoelist.add(linkResource);
264 String destName = pcelink.getDestId().getValue();
266 tpName = pcelink.getDestTP().toString();
267 TerminationPoint ttp = new TerminationPointBuilder()
268 .setTpNodeId(destName).setTpId(tpName).build();
271 ZToAKey destTPKey = new ZToAKey(index.toString());
272 Resource tpResource2 = new ResourceBuilder().setResource(ttp).build();
273 ZToA ttpResource = new ZToABuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
275 etoelist.add(ttpResource);
278 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
279 .resource.resource.resource.Node targetNode = new NodeBuilder()
280 .setNodeId(destName).build();
282 ZToAKey targetKey = new ZToAKey(index.toString());
283 Resource nodeResource3 = new ResourceBuilder().setResource(targetNode).build();
284 lastResource = new ZToABuilder().setId(destName).withKey(targetKey).setResource(nodeResource3).build();
288 etoelist.add(lastResource);
290 // build Z side Client TP
291 tpName = lastLink.getClient();
292 xname = lastLink.getDestId().getValue();
293 stp = new TerminationPointBuilder()
294 .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);
303 public PceResult getReturnStructure() {