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.common.StringConstants;
16 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
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.openroadm.common.optical.channel.types.rev200529.FrequencyTHz;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.ModulationFormat;
21 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.path.description.AToZDirectionBuilder;
22 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.path.description.ZToADirectionBuilder;
23 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.path.description.atoz.direction.AToZ;
24 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.path.description.atoz.direction.AToZBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.path.description.atoz.direction.AToZKey;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.path.description.ztoa.direction.ZToA;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.path.description.ztoa.direction.ZToABuilder;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.path.description.ztoa.direction.ZToAKey;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.pce.resource.Resource;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.pce.resource.ResourceBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.pce.resource.resource.resource.LinkBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.pce.resource.resource.resource.NodeBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.pce.resource.resource.resource.TerminationPoint;
34 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.pce.resource.resource.resource.TerminationPointBuilder;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
36 import org.opendaylight.yangtools.yang.common.Uint16;
37 import org.opendaylight.yangtools.yang.common.Uint32;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
41 public class PcePathDescription {
43 private static final Logger LOG = LoggerFactory.getLogger(PcePathDescription.class);
45 private List<PceLink> pathAtoZ = null;
47 private Map<LinkId, PceLink> allPceLinks = null;
49 public PcePathDescription(List<PceLink> pathAtoZ, Map<LinkId, PceLink> allPceLinks, PceResult rc) {
51 this.allPceLinks = allPceLinks;
52 this.pathAtoZ = pathAtoZ;
56 public PceResult buildDescriptions() {
57 LOG.info("In buildDescriptions: AtoZ = {}", pathAtoZ);
58 Map<AToZKey,AToZ> atozMap = new HashMap<>();
59 if (pathAtoZ == null) {
60 rc.setRC(ResponseCodes.RESPONSE_FAILED);
61 LOG.error("In buildDescriptions: there is empty AtoZ path");
65 buildAtoZ(atozMap, pathAtoZ);
66 rc.setAtoZDirection(buildAtoZDirection(atozMap).build());
67 List<PceLink> pathZtoA = ImmutableList.copyOf(pathAtoZ).reverse();
68 LOG.info("In buildDescriptions: ZtoA {}", pathZtoA);
70 Map<ZToAKey,ZToA> ztoaMap = new HashMap<>();
71 if (pathZtoA == null) {
72 rc.setRC(ResponseCodes.RESPONSE_FAILED);
73 LOG.error("In buildDescriptions: there is empty ZtoA path");
76 buildZtoA(ztoaMap, pathZtoA);
77 rc.setZtoADirection(buildZtoADirection(ztoaMap).build());
83 * Create a builder for AtoZDirection object.
84 * @param atozMap Map of AToZ object
85 * @return a builder for AtoZDirection object
87 private AToZDirectionBuilder buildAtoZDirection(Map<AToZKey, AToZ> atozMap) {
88 AToZDirectionBuilder atoZDirectionBldr = new AToZDirectionBuilder()
89 .setRate(Uint32.valueOf(rc.getRate()))
90 .setModulationFormat(GridConstant.RATE_MODULATION_FORMAT_MAP
91 .getOrDefault(Uint32.valueOf(rc.getRate()), ModulationFormat.DpQpsk).getName())
93 switch (rc.getServiceType()) {
94 case StringConstants.SERVICE_TYPE_100GE:
95 case StringConstants.SERVICE_TYPE_OTU4:
96 atoZDirectionBldr.setAToZMaxFrequency(new FrequencyTHz(rc.getMaxFreq()));
97 atoZDirectionBldr.setAToZMinFrequency(new FrequencyTHz(rc.getMinFreq()));
98 atoZDirectionBldr.setAToZWavelengthNumber(Uint32.valueOf(rc.getResultWavelength()));
100 case StringConstants.SERVICE_TYPE_10GE:
101 case StringConstants.SERVICE_TYPE_1GE:
102 case StringConstants.SERVICE_TYPE_ODU4:
103 if (rc.getResultTribSlot() != null && rc.getResultTribPort() != null) {
104 @SuppressWarnings("unchecked")
105 List<Uint16> tribSlotList = (List<Uint16>) rc.getResultTribSlot().values().toArray()[0];
106 atoZDirectionBldr.setAToZWavelengthNumber(Uint32.valueOf(0))
107 .setTribPortNumber(Uint16.valueOf(rc.getResultTribPort().values().toArray()[0].toString()))
108 .setTribSlotNumber(tribSlotList.get(0));
110 LOG.error("Trib port and trib slot number should be present");
111 atoZDirectionBldr.setTribSlotNumber(Uint16.valueOf(0)).setTribPortNumber(Uint16.valueOf(0));
117 return atoZDirectionBldr;
121 * Create a builder for ZtoADirection object.
122 * @param ztoaMap Map of ZToA object
123 * @return a builder for ZtoADirection object
125 private ZToADirectionBuilder buildZtoADirection(Map<ZToAKey, ZToA> ztoaMap) {
126 ZToADirectionBuilder ztoADirectionBldr = new ZToADirectionBuilder().setRate(Uint32.valueOf(rc.getRate()))
127 .setModulationFormat(GridConstant.RATE_MODULATION_FORMAT_MAP
128 .getOrDefault(Uint32.valueOf(rc.getRate()), ModulationFormat.DpQpsk).getName())
130 switch (rc.getServiceType()) {
131 case StringConstants.SERVICE_TYPE_100GE:
132 case StringConstants.SERVICE_TYPE_OTU4:
133 ztoADirectionBldr.setZToAMaxFrequency(new FrequencyTHz(rc.getMaxFreq()));
134 ztoADirectionBldr.setZToAMinFrequency(new FrequencyTHz(rc.getMinFreq()));
135 ztoADirectionBldr.setZToAWavelengthNumber(Uint32.valueOf(rc.getResultWavelength()));
137 case StringConstants.SERVICE_TYPE_10GE:
138 case StringConstants.SERVICE_TYPE_1GE:
139 case StringConstants.SERVICE_TYPE_ODU4:
140 if (rc.getResultTribSlot() != null && rc.getResultTribPort() != null) {
141 @SuppressWarnings("unchecked")
142 List<Uint16> tribSlotList = (List<Uint16>) rc.getResultTribSlot().values().toArray()[0];
143 ztoADirectionBldr.setZToAWavelengthNumber(Uint32.valueOf(0))
144 .setTribPortNumber(Uint16.valueOf(rc.getResultTribPort().values().toArray()[0].toString()))
145 .setTribSlotNumber(tribSlotList.get(0));
147 LOG.error("Trib port and trib slot number should be present");
148 ztoADirectionBldr.setTribSlotNumber(Uint16.valueOf(0)).setTribPortNumber(Uint16.valueOf(0));
154 return ztoADirectionBldr;
157 @SuppressWarnings("java:S138")
158 //sonar issue This method has 77 lines, which is greater than the 75 lines authorized. Split it into smaller
159 //ignore as it's not relevant to split it from functional point
160 private void buildAtoZ(Map<AToZKey, AToZ> atozMap, List<PceLink> path) {
162 PceLink lastLink = null;
163 AToZ lastResource = null;
165 // build A side Client TP
166 String tpName = path.get(0).getClient();
167 String xname = path.get(0).getSourceId().getValue();
168 TerminationPoint stp = new TerminationPointBuilder()
169 .setTpId(tpName).setTpNodeId(xname)
172 AToZKey clientKey = new AToZKey(index.toString());
173 Resource clientResource = new ResourceBuilder().setResource(stp).build();
174 AToZ firstResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
175 atozMap.put(firstResource.key(),firstResource);
177 for (PceLink pcelink : path) {
178 String srcName = pcelink.getSourceId().getValue();
180 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.pce
181 .resource.resource.resource.Node sourceNode = new NodeBuilder()
186 AToZKey sourceKey = new AToZKey(index.toString());
187 Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).build();
188 AToZ srcResource = new AToZBuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
190 atozMap.put(srcResource.key(),srcResource);
193 tpName = pcelink.getSourceTP().toString();
194 stp = new TerminationPointBuilder()
195 .setTpNodeId(srcName).setTpId(tpName)
199 AToZKey srcTPKey = new AToZKey(index.toString());
200 Resource tpResource1 = new ResourceBuilder().setResource(stp).build();
201 AToZ stpResource = new AToZBuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
203 atozMap.put(stpResource.key(),stpResource);
205 String linkName = pcelink.getLinkId().getValue();
207 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.pce
208 .resource.resource.resource.Link atozLink = new LinkBuilder()
213 AToZKey linkKey = new AToZKey(index.toString());
214 Resource nodeResource2 = new ResourceBuilder().setResource(atozLink).build();
215 AToZ linkResource = new AToZBuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
217 atozMap.put(linkResource.key(),linkResource);
219 String destName = pcelink.getDestId().getValue();
221 tpName = pcelink.getDestTP().toString();
222 TerminationPoint dtp = new TerminationPointBuilder()
223 .setTpNodeId(destName).setTpId(tpName)
227 AToZKey destTPKey = new AToZKey(index.toString());
228 Resource tpResource2 = new ResourceBuilder().setResource(dtp).build();
229 AToZ ttpResource = new AToZBuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
231 atozMap.put(ttpResource.key(),ttpResource);
233 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.pce
234 .resource.resource.resource.Node targetNode = new NodeBuilder()
239 AToZKey targetKey = new AToZKey(index.toString());
240 Resource nodeResource3 = new ResourceBuilder().setResource(targetNode).build();
241 lastResource = new AToZBuilder().setId(destName).withKey(targetKey).setResource(nodeResource3).build();
246 if (lastResource != null) {
247 atozMap.put(lastResource.key(),lastResource);
250 // build Z side Client TP
251 tpName = lastLink.getClient();
252 xname = lastLink.getDestId().getValue();
253 stp = new TerminationPointBuilder()
254 .setTpNodeId(xname).setTpId(tpName)
258 clientKey = new AToZKey(index.toString());
259 clientResource = new ResourceBuilder().setResource(stp).build();
260 lastResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
261 atozMap.put(lastResource.key(),lastResource);
265 private void buildZtoA(Map<ZToAKey, ZToA> ztoaList, List<PceLink> path) {
267 PceLink lastLink = null;
268 ZToA lastResource = null;
270 // build Z size Client TP
271 PceLink pcelink = this.allPceLinks.get(path.get(0).getOppositeLink());
272 String tpName = pcelink.getClient();
273 String xname = pcelink.getSourceId().getValue();
274 TerminationPoint stp = new TerminationPointBuilder()
275 .setTpNodeId(xname).setTpId(tpName)
278 ZToAKey clientKey = new ZToAKey(index.toString());
279 Resource clientResource = new ResourceBuilder().setResource(stp).build();
280 ZToA firstResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
281 ztoaList.put(firstResource.key(),firstResource);
284 for (PceLink pcelinkAtoZ : path) {
286 pcelink = this.allPceLinks.get(pcelinkAtoZ.getOppositeLink());
287 LOG.debug("link to oppsite: {} to {}", pcelinkAtoZ, pcelink);
289 String srcName = pcelink.getSourceId().getValue();
293 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.pce
294 .resource.resource.resource.Node sourceNode = new NodeBuilder()
295 .setNodeId(srcName).build();
299 ZToAKey sourceKey = new ZToAKey(index.toString());
300 Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).build();
301 ZToA srcResource = new ZToABuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
303 ztoaList.put(srcResource.key(),srcResource);
306 tpName = pcelink.getSourceTP().toString();
307 stp = new TerminationPointBuilder()
308 .setTpNodeId(srcName).setTpId(tpName)
312 ZToAKey srcTPKey = new ZToAKey(index.toString());
313 Resource tpResource1 = new ResourceBuilder().setResource(stp).build();
314 ZToA stpResource = new ZToABuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
316 ztoaList.put(stpResource.key(),stpResource);
318 String linkName = pcelink.getLinkId().getValue();
320 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.pce
321 .resource.resource.resource.Link ztoaLink = new LinkBuilder()
322 .setLinkId(linkName).build();
325 ZToAKey linkKey = new ZToAKey(index.toString());
326 Resource nodeResource2 = new ResourceBuilder().setResource(ztoaLink).build();
327 ZToA linkResource = new ZToABuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
329 ztoaList.put(linkResource.key(),linkResource);
331 String destName = pcelink.getDestId().getValue();
333 tpName = pcelink.getDestTP().toString();
334 TerminationPoint ttp = new TerminationPointBuilder()
335 .setTpNodeId(destName).setTpId(tpName).build();
338 ZToAKey destTPKey = new ZToAKey(index.toString());
339 Resource tpResource2 = new ResourceBuilder().setResource(ttp).build();
340 ZToA ttpResource = new ZToABuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
342 ztoaList.put(ttpResource.key(),ttpResource);
345 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.pce
346 .resource.resource.resource.Node targetNode = new NodeBuilder()
347 .setNodeId(destName).build();
349 ZToAKey targetKey = new ZToAKey(index.toString());
350 Resource nodeResource3 = new ResourceBuilder().setResource(targetNode).build();
351 lastResource = new ZToABuilder().setId(destName).withKey(targetKey).setResource(nodeResource3).build();
355 if (lastResource != null) {
356 ztoaList.put(lastResource.key(),lastResource);
359 // build Z side Client TP
360 tpName = lastLink.getClient();
361 xname = lastLink.getDestId().getValue();
362 stp = new TerminationPointBuilder()
363 .setTpNodeId(xname).setTpId(tpName).build();
366 clientKey = new ZToAKey(index.toString());
367 clientResource = new ResourceBuilder().setResource(stp).build();
368 lastResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
369 ztoaList.put(lastResource.key(),lastResource);
372 public PceResult getReturnStructure() {