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.state.types.rev191129.State;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.ModulationFormat;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev181130.OpucnTribSlotDef;
23 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.AToZDirectionBuilder;
24 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ZToADirectionBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZ;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZKey;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ztoa.direction.ZToA;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ztoa.direction.ZToABuilder;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ztoa.direction.ZToAKey;
31 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.Resource;
32 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.ResourceBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.LinkBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.NodeBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.TerminationPoint;
36 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.TerminationPointBuilder;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
38 import org.opendaylight.yangtools.yang.common.Uint32;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
42 public class PcePathDescription {
44 private static final Logger LOG = LoggerFactory.getLogger(PcePathDescription.class);
46 private List<PceLink> pathAtoZ = null;
48 private Map<LinkId, PceLink> allPceLinks = null;
50 public PcePathDescription(List<PceLink> pathAtoZ, Map<LinkId, PceLink> allPceLinks, PceResult rc) {
52 this.allPceLinks = allPceLinks;
53 this.pathAtoZ = pathAtoZ;
57 public PceResult buildDescriptions() {
58 LOG.info("In buildDescriptions: AtoZ = {}", pathAtoZ);
59 Map<AToZKey,AToZ> atozMap = new HashMap<>();
60 if (pathAtoZ == null) {
61 rc.setRC(ResponseCodes.RESPONSE_FAILED);
62 LOG.error("In buildDescriptions: there is empty AtoZ path");
66 buildAtoZ(atozMap, pathAtoZ);
67 rc.setAtoZDirection(buildAtoZDirection(atozMap).build());
68 List<PceLink> pathZtoA = ImmutableList.copyOf(pathAtoZ).reverse();
69 LOG.info("In buildDescriptions: ZtoA {}", pathZtoA);
71 Map<ZToAKey,ZToA> ztoaMap = new HashMap<>();
72 if (pathZtoA == null) {
73 rc.setRC(ResponseCodes.RESPONSE_FAILED);
74 LOG.error("In buildDescriptions: there is empty ZtoA path");
77 buildZtoA(ztoaMap, pathZtoA);
78 rc.setZtoADirection(buildZtoADirection(ztoaMap).build());
84 * Create a builder for AtoZDirection object.
85 * @param atozMap Map of AToZ object
86 * @return a builder for AtoZDirection object
88 private AToZDirectionBuilder buildAtoZDirection(Map<AToZKey, AToZ> atozMap) {
89 AToZDirectionBuilder atoZDirectionBldr = new AToZDirectionBuilder()
90 .setRate(Uint32.valueOf(rc.getRate()))
91 .setModulationFormat(GridConstant.RATE_MODULATION_FORMAT_MAP
92 .getOrDefault(Uint32.valueOf(rc.getRate()), ModulationFormat.DpQpsk).getName())
94 switch (rc.getServiceType()) {
95 case StringConstants.SERVICE_TYPE_400GE:
96 case StringConstants.SERVICE_TYPE_OTUC2:
97 case StringConstants.SERVICE_TYPE_OTUC3:
98 case StringConstants.SERVICE_TYPE_OTUC4:
99 case StringConstants.SERVICE_TYPE_100GE_T:
100 case StringConstants.SERVICE_TYPE_OTU4:
101 atoZDirectionBldr.setAToZMaxFrequency(new FrequencyTHz(rc.getMaxFreq()));
102 atoZDirectionBldr.setAToZMinFrequency(new FrequencyTHz(rc.getMinFreq()));
103 atoZDirectionBldr.setAToZWavelengthNumber(Uint32.valueOf(rc.getResultWavelength()));
105 case StringConstants.SERVICE_TYPE_100GE_M:
106 case StringConstants.SERVICE_TYPE_100GE_S:
107 case StringConstants.SERVICE_TYPE_10GE:
108 case StringConstants.SERVICE_TYPE_1GE:
109 case StringConstants.SERVICE_TYPE_ODU4:
110 case StringConstants.SERVICE_TYPE_ODUC2:
111 case StringConstants.SERVICE_TYPE_ODUC3:
112 case StringConstants.SERVICE_TYPE_ODUC4:
113 if (rc.getResultTribPortTribSlot() != null && rc.getResultTribPortTribSlot().get(0) != null
114 && rc.getResultTribPortTribSlot().get(1) != null) {
115 atoZDirectionBldr.setAToZWavelengthNumber(Uint32.valueOf(0))
116 .setMinTribSlot(rc.getResultTribPortTribSlot().get(0))
117 .setMaxTribSlot(rc.getResultTribPortTribSlot().get(1));
119 LOG.warn("Trib port and trib slot number should be present");
120 atoZDirectionBldr.setMinTribSlot(new OpucnTribSlotDef("0.0"))
121 .setMaxTribSlot(new OpucnTribSlotDef("0.0"));
125 LOG.warn("unknown service type : unable to set Min/Max frequencies or trib-port/trib-slot");
128 return atoZDirectionBldr;
132 * Create a builder for ZtoADirection object.
133 * @param ztoaMap Map of ZToA object
134 * @return a builder for ZtoADirection object
136 private ZToADirectionBuilder buildZtoADirection(Map<ZToAKey, ZToA> ztoaMap) {
137 ZToADirectionBuilder ztoADirectionBldr = new ZToADirectionBuilder().setRate(Uint32.valueOf(rc.getRate()))
138 .setModulationFormat(GridConstant.RATE_MODULATION_FORMAT_MAP
139 .getOrDefault(Uint32.valueOf(rc.getRate()), ModulationFormat.DpQpsk).getName())
141 switch (rc.getServiceType()) {
142 case StringConstants.SERVICE_TYPE_400GE:
143 case StringConstants.SERVICE_TYPE_OTUC2:
144 case StringConstants.SERVICE_TYPE_OTUC3:
145 case StringConstants.SERVICE_TYPE_OTUC4:
146 case StringConstants.SERVICE_TYPE_100GE_T:
147 case StringConstants.SERVICE_TYPE_OTU4:
148 ztoADirectionBldr.setZToAMaxFrequency(new FrequencyTHz(rc.getMaxFreq()));
149 ztoADirectionBldr.setZToAMinFrequency(new FrequencyTHz(rc.getMinFreq()));
150 ztoADirectionBldr.setZToAWavelengthNumber(Uint32.valueOf(rc.getResultWavelength()));
152 case StringConstants.SERVICE_TYPE_100GE_M:
153 case StringConstants.SERVICE_TYPE_100GE_S:
154 case StringConstants.SERVICE_TYPE_10GE:
155 case StringConstants.SERVICE_TYPE_1GE:
156 case StringConstants.SERVICE_TYPE_ODU4:
157 case StringConstants.SERVICE_TYPE_ODUC2:
158 case StringConstants.SERVICE_TYPE_ODUC3:
159 case StringConstants.SERVICE_TYPE_ODUC4:
160 if (rc.getResultTribPortTribSlot() != null && rc.getResultTribPortTribSlot().get(0) != null
161 && rc.getResultTribPortTribSlot().get(1) != null) {
162 ztoADirectionBldr.setZToAWavelengthNumber(Uint32.valueOf(0))
163 .setMinTribSlot(rc.getResultTribPortTribSlot().get(0))
164 .setMaxTribSlot(rc.getResultTribPortTribSlot().get(1));
166 LOG.warn("Trib port and trib slot number should be present");
167 ztoADirectionBldr.setMinTribSlot(new OpucnTribSlotDef("0.0"))
168 .setMaxTribSlot(new OpucnTribSlotDef("0.0"));
172 LOG.warn("unknown service type : unable to set Min/Max frequencies");
175 return ztoADirectionBldr;
178 @SuppressWarnings("java:S138")
179 //sonar issue This method has 77 lines, which is greater than the 75 lines authorized. Split it into smaller
180 //ignore as it's not relevant to split it from functional point
181 private void buildAtoZ(Map<AToZKey, AToZ> atozMap, List<PceLink> path) {
183 PceLink lastLink = null;
184 AToZ lastResource = null;
186 // build A side Client TP
187 String tpName = path.get(0).getClient();
188 String xname = path.get(0).getSourceId().getValue();
189 TerminationPoint stp = new TerminationPointBuilder()
190 .setTpId(tpName).setTpNodeId(xname)
193 AToZKey clientKey = new AToZKey(index.toString());
194 Resource clientResource = new ResourceBuilder().setResource(stp).setState(State.InService).build();
195 AToZ firstResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
196 atozMap.put(firstResource.key(),firstResource);
198 for (PceLink pcelink : path) {
199 String srcName = pcelink.getSourceId().getValue();
201 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce
202 .resource.resource.resource.Node sourceNode = new NodeBuilder()
207 AToZKey sourceKey = new AToZKey(index.toString());
208 Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).setState(State.InService).build();
209 AToZ srcResource = new AToZBuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
211 atozMap.put(srcResource.key(),srcResource);
214 tpName = pcelink.getSourceTP().getValue();
215 stp = new TerminationPointBuilder()
216 .setTpNodeId(srcName).setTpId(tpName)
220 AToZKey srcTPKey = new AToZKey(index.toString());
221 Resource tpResource1 = new ResourceBuilder().setResource(stp).setState(State.InService).build();
222 AToZ stpResource = new AToZBuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
224 atozMap.put(stpResource.key(),stpResource);
226 String linkName = pcelink.getLinkId().getValue();
228 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce
229 .resource.resource.resource.Link atozLink = new LinkBuilder()
234 AToZKey linkKey = new AToZKey(index.toString());
235 Resource nodeResource2 = new ResourceBuilder().setResource(atozLink).setState(pcelink.getState()).build();
236 AToZ linkResource = new AToZBuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
238 atozMap.put(linkResource.key(),linkResource);
240 String destName = pcelink.getDestId().getValue();
242 tpName = pcelink.getDestTP().getValue();
243 TerminationPoint dtp = new TerminationPointBuilder()
244 .setTpNodeId(destName).setTpId(tpName)
248 AToZKey destTPKey = new AToZKey(index.toString());
249 Resource tpResource2 = new ResourceBuilder().setResource(dtp).setState(State.InService).build();
250 AToZ ttpResource = new AToZBuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
252 atozMap.put(ttpResource.key(),ttpResource);
254 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce
255 .resource.resource.resource.Node targetNode = new NodeBuilder()
260 AToZKey targetKey = new AToZKey(index.toString());
261 Resource nodeResource3 = new ResourceBuilder().setResource(targetNode).setState(State.InService).build();
262 lastResource = new AToZBuilder().setId(destName).withKey(targetKey).setResource(nodeResource3).build();
267 if (lastResource != null) {
268 atozMap.put(lastResource.key(),lastResource);
271 // build Z side Client TP
272 tpName = lastLink.getClient();
273 xname = lastLink.getDestId().getValue();
274 stp = new TerminationPointBuilder()
275 .setTpNodeId(xname).setTpId(tpName)
279 clientKey = new AToZKey(index.toString());
280 clientResource = new ResourceBuilder().setResource(stp).setState(State.InService).build();
281 lastResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
282 atozMap.put(lastResource.key(),lastResource);
286 private void buildZtoA(Map<ZToAKey, ZToA> ztoaList, List<PceLink> path) {
288 PceLink lastLink = null;
289 ZToA lastResource = null;
291 // build Z size Client TP
292 PceLink pcelink = this.allPceLinks.get(path.get(0).getOppositeLink());
293 String tpName = pcelink.getClient();
294 String xname = pcelink.getSourceId().getValue();
295 TerminationPoint stp = new TerminationPointBuilder()
296 .setTpNodeId(xname).setTpId(tpName)
299 ZToAKey clientKey = new ZToAKey(index.toString());
300 Resource clientResource = new ResourceBuilder().setResource(stp).setState(State.InService).build();
301 ZToA firstResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
302 ztoaList.put(firstResource.key(),firstResource);
305 for (PceLink pcelinkAtoZ : path) {
307 pcelink = this.allPceLinks.get(pcelinkAtoZ.getOppositeLink());
308 LOG.debug("link to oppsite: {} to {}", pcelinkAtoZ, pcelink);
310 String srcName = pcelink.getSourceId().getValue();
314 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce
315 .resource.resource.resource.Node sourceNode = new NodeBuilder()
316 .setNodeId(srcName).build();
320 ZToAKey sourceKey = new ZToAKey(index.toString());
321 Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).setState(State.InService).build();
322 ZToA srcResource = new ZToABuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
324 ztoaList.put(srcResource.key(),srcResource);
327 tpName = pcelink.getSourceTP().getValue();
328 stp = new TerminationPointBuilder()
329 .setTpNodeId(srcName).setTpId(tpName)
333 ZToAKey srcTPKey = new ZToAKey(index.toString());
334 Resource tpResource1 = new ResourceBuilder().setResource(stp).setState(State.InService).build();
335 ZToA stpResource = new ZToABuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
337 ztoaList.put(stpResource.key(),stpResource);
339 String linkName = pcelink.getLinkId().getValue();
341 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce
342 .resource.resource.resource.Link ztoaLink = new LinkBuilder()
343 .setLinkId(linkName).build();
346 ZToAKey linkKey = new ZToAKey(index.toString());
347 Resource nodeResource2 = new ResourceBuilder().setResource(ztoaLink).setState(State.InService).build();
348 ZToA linkResource = new ZToABuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
350 ztoaList.put(linkResource.key(),linkResource);
352 String destName = pcelink.getDestId().getValue();
354 tpName = pcelink.getDestTP().getValue();
355 TerminationPoint ttp = new TerminationPointBuilder()
356 .setTpNodeId(destName).setTpId(tpName).build();
359 ZToAKey destTPKey = new ZToAKey(index.toString());
360 Resource tpResource2 = new ResourceBuilder().setResource(ttp).setState(State.InService).build();
361 ZToA ttpResource = new ZToABuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
363 ztoaList.put(ttpResource.key(),ttpResource);
366 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce
367 .resource.resource.resource.Node targetNode = new NodeBuilder()
368 .setNodeId(destName).build();
370 ZToAKey targetKey = new ZToAKey(index.toString());
371 Resource nodeResource3 = new ResourceBuilder().setResource(targetNode).setState(State.InService).build();
372 lastResource = new ZToABuilder().setId(destName).withKey(targetKey).setResource(nodeResource3).build();
376 if (lastResource != null) {
377 ztoaList.put(lastResource.key(),lastResource);
380 // build Z side Client TP
381 tpName = lastLink.getClient();
382 xname = lastLink.getDestId().getValue();
383 stp = new TerminationPointBuilder()
384 .setTpNodeId(xname).setTpId(tpName).build();
387 clientKey = new ZToAKey(index.toString());
388 clientResource = new ResourceBuilder().setResource(stp).setState(State.InService).build();
389 lastResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
390 ztoaList.put(lastResource.key(),lastResource);
393 public PceResult getReturnStructure() {