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.rev200629.path.description.AToZDirectionBuilder;
18 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.ZToADirectionBuilder;
19 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.atoz.direction.AToZ;
20 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.atoz.direction.AToZBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.atoz.direction.AToZKey;
22 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.ztoa.direction.ZToA;
23 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.ztoa.direction.ZToABuilder;
24 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.ztoa.direction.ZToAKey;
25 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce.resource.Resource;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce.resource.ResourceBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce.resource.resource.resource.LinkBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce.resource.resource.resource.NodeBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce.resource.resource.resource.TerminationPoint;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.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.opendaylight.yangtools.yang.common.Uint16;
33 import org.opendaylight.yangtools.yang.common.Uint32;
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(Uint32.valueOf(rc.getRate()))
66 if ("100GE".equals(rc.getServiceType()) || "OTU4".equals(rc.getServiceType())) {
67 atoZDirectionBldr.setAToZWavelengthNumber(Uint32.valueOf(rc.getResultWavelength()));
68 } else if ("10GE".equals(rc.getServiceType()) || "1GE".equals(rc.getServiceType())
69 || "ODU4".equals(rc.getServiceType())) {
70 if (rc.getResultTribSlot() != null && rc.getResultTribPort() != null) {
71 List<Uint16> tribSlotList = (List<Uint16>) rc.getResultTribSlot().values().toArray()[0];
72 atoZDirectionBldr.setAToZWavelengthNumber(Uint32.valueOf(0))
73 .setTribPortNumber(Uint16.valueOf(rc.getResultTribPort().values().toArray()[0].toString()))
74 .setTribSlotNumber(tribSlotList.get(0));
76 LOG.error("Trib port and trib slot number should be present");
77 atoZDirectionBldr.setTribSlotNumber(Uint16.valueOf(0)).setTribPortNumber(Uint16.valueOf(0));
80 rc.setAtoZDirection(atoZDirectionBldr.build());
81 pathZtoA = ImmutableList.copyOf(pathAtoZ).reverse();
82 LOG.info("In buildDescriptions: ZtoA {}", pathZtoA);
84 List<ZToA> ztoaList = new ArrayList<>();
85 if (pathZtoA == null) {
86 rc.setRC(ResponseCodes.RESPONSE_FAILED);
87 LOG.error("In buildDescriptions: there is empty ZtoA path");
90 buildZtoA(ztoaList, pathZtoA);
91 ZToADirectionBuilder ztoADirectionBldr = new ZToADirectionBuilder()
92 .setRate(Uint32.valueOf(rc.getRate()))
94 if ("100GE".equals(rc.getServiceType()) || "OTU4".equals(rc.getServiceType())) {
95 ztoADirectionBldr.setZToAWavelengthNumber(Uint32.valueOf(rc.getResultWavelength()));
96 } else if ("10GE".equals(rc.getServiceType()) || "1GE".equals(rc.getServiceType())
97 || "ODU4".equals(rc.getServiceType())) {
98 if (rc.getResultTribSlot() != null && rc.getResultTribPort() != null) {
99 List<Uint16> tribSlotList = (List<Uint16>) rc.getResultTribSlot().values().toArray()[0];
100 ztoADirectionBldr.setZToAWavelengthNumber(Uint32.valueOf(0))
101 .setTribPortNumber(Uint16.valueOf(rc.getResultTribPort().values().toArray()[0].toString()))
102 .setTribSlotNumber(tribSlotList.get(0));
104 LOG.error("Trib port and trib slot number should be present");
105 ztoADirectionBldr.setTribSlotNumber(Uint16.valueOf(0)).setTribPortNumber(Uint16.valueOf(0));
108 rc.setZtoADirection(ztoADirectionBldr.build());
113 private void buildAtoZ(List<AToZ> etoeList, List<PceLink> path) {
115 PceLink lastLink = null;
116 AToZ lastResource = null;
118 // build A side Client TP
119 String tpName = path.get(0).getClient();
120 String xname = path.get(0).getSourceId().getValue();
121 TerminationPoint stp = new TerminationPointBuilder()
122 .setTpId(tpName).setTpNodeId(xname)
125 AToZKey clientKey = new AToZKey(index.toString());
126 Resource clientResource = new ResourceBuilder().setResource(stp).build();
127 AToZ firstResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
128 etoeList.add(firstResource);
130 for (PceLink pcelink : path) {
131 String srcName = pcelink.getSourceId().getValue();
133 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce
134 .resource.resource.resource.Node sourceNode = new NodeBuilder()
139 AToZKey sourceKey = new AToZKey(index.toString());
140 Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).build();
141 AToZ srcResource = new AToZBuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
143 etoeList.add(srcResource);
146 tpName = pcelink.getSourceTP().toString();
147 stp = new TerminationPointBuilder()
148 .setTpNodeId(srcName).setTpId(tpName)
152 AToZKey srcTPKey = new AToZKey(index.toString());
153 Resource tpResource1 = new ResourceBuilder().setResource(stp).build();
154 AToZ stpResource = new AToZBuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
156 etoeList.add(stpResource);
158 String linkName = pcelink.getLinkId().getValue();
160 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce
161 .resource.resource.resource.Link atozLink = new LinkBuilder()
166 AToZKey linkKey = new AToZKey(index.toString());
167 Resource nodeResource2 = new ResourceBuilder().setResource(atozLink).build();
168 AToZ linkResource = new AToZBuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
170 etoeList.add(linkResource);
172 String destName = pcelink.getDestId().getValue();
174 tpName = pcelink.getDestTP().toString();
175 TerminationPoint dtp = new TerminationPointBuilder()
176 .setTpNodeId(destName).setTpId(tpName)
180 AToZKey destTPKey = new AToZKey(index.toString());
181 Resource tpResource2 = new ResourceBuilder().setResource(dtp).build();
182 AToZ ttpResource = new AToZBuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
184 etoeList.add(ttpResource);
186 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce
187 .resource.resource.resource.Node targetNode = new NodeBuilder()
192 AToZKey targetKey = new AToZKey(index.toString());
193 Resource nodeResource3 = new ResourceBuilder().setResource(targetNode).build();
194 lastResource = new AToZBuilder().setId(destName).withKey(targetKey).setResource(nodeResource3).build();
199 etoeList.add(lastResource);
201 // build Z side Client TP
202 tpName = lastLink.getClient();
203 xname = lastLink.getDestId().getValue();
204 stp = new TerminationPointBuilder()
205 .setTpNodeId(xname).setTpId(tpName)
209 clientKey = new AToZKey(index.toString());
210 clientResource = new ResourceBuilder().setResource(stp).build();
211 lastResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
212 etoeList.add(lastResource);
216 private void buildZtoA(List<ZToA> etoelist, List<PceLink> path) {
218 PceLink lastLink = null;
219 ZToA lastResource = null;
221 // build Z size Client TP
222 PceLink pcelink = this.allPceLinks.get(path.get(0).getOppositeLink());
223 String tpName = pcelink.getClient();
224 String xname = pcelink.getSourceId().getValue();
225 TerminationPoint stp = new TerminationPointBuilder()
226 .setTpNodeId(xname).setTpId(tpName)
229 ZToAKey clientKey = new ZToAKey(index.toString());
230 Resource clientResource = new ResourceBuilder().setResource(stp).build();
231 ZToA firstResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
232 etoelist.add(firstResource);
235 for (PceLink pcelinkAtoZ : path) {
237 pcelink = this.allPceLinks.get(pcelinkAtoZ.getOppositeLink());
238 LOG.debug("link to oppsite: {} to {}", pcelinkAtoZ, pcelink);
240 String srcName = pcelink.getSourceId().getValue();
244 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce
245 .resource.resource.resource.Node sourceNode = new NodeBuilder()
246 .setNodeId(srcName).build();
250 ZToAKey sourceKey = new ZToAKey(index.toString());
251 Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).build();
252 ZToA srcResource = new ZToABuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
254 etoelist.add(srcResource);
257 tpName = pcelink.getSourceTP().toString();
258 stp = new TerminationPointBuilder()
259 .setTpNodeId(srcName).setTpId(tpName)
263 ZToAKey srcTPKey = new ZToAKey(index.toString());
264 Resource tpResource1 = new ResourceBuilder().setResource(stp).build();
265 ZToA stpResource = new ZToABuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
267 etoelist.add(stpResource);
269 String linkName = pcelink.getLinkId().getValue();
271 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce
272 .resource.resource.resource.Link ztoaLink = new LinkBuilder()
273 .setLinkId(linkName).build();
276 ZToAKey linkKey = new ZToAKey(index.toString());
277 Resource nodeResource2 = new ResourceBuilder().setResource(ztoaLink).build();
278 ZToA linkResource = new ZToABuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
280 etoelist.add(linkResource);
282 String destName = pcelink.getDestId().getValue();
284 tpName = pcelink.getDestTP().toString();
285 TerminationPoint ttp = new TerminationPointBuilder()
286 .setTpNodeId(destName).setTpId(tpName).build();
289 ZToAKey destTPKey = new ZToAKey(index.toString());
290 Resource tpResource2 = new ResourceBuilder().setResource(ttp).build();
291 ZToA ttpResource = new ZToABuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
293 etoelist.add(ttpResource);
296 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce
297 .resource.resource.resource.Node targetNode = new NodeBuilder()
298 .setNodeId(destName).build();
300 ZToAKey targetKey = new ZToAKey(index.toString());
301 Resource nodeResource3 = new ResourceBuilder().setResource(targetNode).build();
302 lastResource = new ZToABuilder().setId(destName).withKey(targetKey).setResource(nodeResource3).build();
306 etoelist.add(lastResource);
308 // build Z side Client TP
309 tpName = lastLink.getClient();
310 xname = lastLink.getDestId().getValue();
311 stp = new TerminationPointBuilder()
312 .setTpNodeId(xname).setTpId(tpName).build();
315 clientKey = new ZToAKey(index.toString());
316 clientResource = new ResourceBuilder().setResource(stp).build();
317 lastResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
318 etoelist.add(lastResource);
321 public PceResult getReturnStructure() {