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.HashMap;
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 Map<AToZKey,AToZ> atozList = new HashMap<>();
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 Map<ZToAKey,ZToA> ztoaList = new HashMap<>();
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(Map<AToZKey, AToZ> atozList, 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 atozList.put(firstResource.key(),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 atozList.put(srcResource.key(),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 atozList.put(stpResource.key(),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 atozList.put(linkResource.key(),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 atozList.put(ttpResource.key(),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 if (lastResource != null) {
200 atozList.put(lastResource.key(),lastResource);
203 // build Z side Client TP
204 tpName = lastLink.getClient();
205 xname = lastLink.getDestId().getValue();
206 stp = new TerminationPointBuilder()
207 .setTpNodeId(xname).setTpId(tpName)
211 clientKey = new AToZKey(index.toString());
212 clientResource = new ResourceBuilder().setResource(stp).build();
213 lastResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
214 atozList.put(lastResource.key(),lastResource);
218 private void buildZtoA(Map<ZToAKey, ZToA> ztoaList, List<PceLink> path) {
220 PceLink lastLink = null;
221 ZToA lastResource = null;
223 // build Z size Client TP
224 PceLink pcelink = this.allPceLinks.get(path.get(0).getOppositeLink());
225 String tpName = pcelink.getClient();
226 String xname = pcelink.getSourceId().getValue();
227 TerminationPoint stp = new TerminationPointBuilder()
228 .setTpNodeId(xname).setTpId(tpName)
231 ZToAKey clientKey = new ZToAKey(index.toString());
232 Resource clientResource = new ResourceBuilder().setResource(stp).build();
233 ZToA firstResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
234 ztoaList.put(firstResource.key(),firstResource);
237 for (PceLink pcelinkAtoZ : path) {
239 pcelink = this.allPceLinks.get(pcelinkAtoZ.getOppositeLink());
240 LOG.debug("link to oppsite: {} to {}", pcelinkAtoZ, pcelink);
242 String srcName = pcelink.getSourceId().getValue();
246 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce
247 .resource.resource.resource.Node sourceNode = new NodeBuilder()
248 .setNodeId(srcName).build();
252 ZToAKey sourceKey = new ZToAKey(index.toString());
253 Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).build();
254 ZToA srcResource = new ZToABuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
256 ztoaList.put(srcResource.key(),srcResource);
259 tpName = pcelink.getSourceTP().toString();
260 stp = new TerminationPointBuilder()
261 .setTpNodeId(srcName).setTpId(tpName)
265 ZToAKey srcTPKey = new ZToAKey(index.toString());
266 Resource tpResource1 = new ResourceBuilder().setResource(stp).build();
267 ZToA stpResource = new ZToABuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
269 ztoaList.put(stpResource.key(),stpResource);
271 String linkName = pcelink.getLinkId().getValue();
273 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce
274 .resource.resource.resource.Link ztoaLink = new LinkBuilder()
275 .setLinkId(linkName).build();
278 ZToAKey linkKey = new ZToAKey(index.toString());
279 Resource nodeResource2 = new ResourceBuilder().setResource(ztoaLink).build();
280 ZToA linkResource = new ZToABuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
282 ztoaList.put(linkResource.key(),linkResource);
284 String destName = pcelink.getDestId().getValue();
286 tpName = pcelink.getDestTP().toString();
287 TerminationPoint ttp = new TerminationPointBuilder()
288 .setTpNodeId(destName).setTpId(tpName).build();
291 ZToAKey destTPKey = new ZToAKey(index.toString());
292 Resource tpResource2 = new ResourceBuilder().setResource(ttp).build();
293 ZToA ttpResource = new ZToABuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
295 ztoaList.put(ttpResource.key(),ttpResource);
298 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce
299 .resource.resource.resource.Node targetNode = new NodeBuilder()
300 .setNodeId(destName).build();
302 ZToAKey targetKey = new ZToAKey(index.toString());
303 Resource nodeResource3 = new ResourceBuilder().setResource(targetNode).build();
304 lastResource = new ZToABuilder().setId(destName).withKey(targetKey).setResource(nodeResource3).build();
308 if (lastResource != null) {
309 ztoaList.put(lastResource.key(),lastResource);
312 // build Z side Client TP
313 tpName = lastLink.getClient();
314 xname = lastLink.getDestId().getValue();
315 stp = new TerminationPointBuilder()
316 .setTpNodeId(xname).setTpId(tpName).build();
319 clientKey = new ZToAKey(index.toString());
320 clientResource = new ResourceBuilder().setResource(stp).build();
321 lastResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
322 ztoaList.put(lastResource.key(),lastResource);
325 public PceResult getReturnStructure() {