2 * Copyright © 2017 AT&T 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.olm;
10 import com.google.common.base.Optional;
12 import java.lang.reflect.InvocationTargetException;
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.concurrent.ExecutionException;
16 import java.util.concurrent.Future;
18 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
19 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
20 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
21 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
22 import org.opendaylight.transportpce.olm.spanloss.RoadmLinks;
23 import org.opendaylight.transportpce.olm.spanloss.SpanLoss;
24 import org.opendaylight.transportpce.renderer.mapping.PortMapping;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.CurrentPmlist;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.Measurements;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.currentpmlist.CurrentPm;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev161014.PmNamesEnum;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.GetPmInput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.GetPmOutput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.GetPmOutputBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.OlmService;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.ServicePowerSetupInput;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.ServicePowerSetupOutput;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.ServicePowerSetupOutputBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.get.pm.output.MeasurementsBuilder;
37 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
38 import org.opendaylight.yangtools.yang.common.RpcResult;
39 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
44 * The Class OlmPowerSetupImpl.
46 public class OlmPowerSetupImpl implements OlmService {
48 /** The Constant LOG. */
49 private static final Logger LOG = LoggerFactory.getLogger(OlmPowerSetupImpl.class);
52 private final DataBroker db;
55 private final MountPointService mps;
58 * Instantiates a new olm power setup impl.
65 public OlmPowerSetupImpl(DataBroker db, MountPointService mps) {
71 * This method is the implementation of the 'get-pm' RESTCONF service, which
72 * is one of the external APIs into the olm application.
75 * 1. get-pm This operation traverse through current PM list and gets PM for
76 * given NodeId and Resource name
79 * The signature for this method was generated by yang tools from the
83 * Input parameter from the olm yang model
85 * @return Result of the request
88 public Future<RpcResult<GetPmOutput>> getPm(GetPmInput input) {
89 LOG.info("Getting PM Data for NodeId: {} ResouceType: {} ResourceName: {}",
90 input.getNodeId(),input.getResourceType(),input.getResourceName());
91 new PortMapping(db, mps, input.getNodeId());
92 DataBroker deviceDb = PortMapping.getDeviceDataBroker(input.getNodeId(), mps);
93 InstanceIdentifier<CurrentPmlist> currentPmsIID = InstanceIdentifier.create(CurrentPmlist.class);
94 ReadOnlyTransaction rtx = deviceDb.newReadOnlyTransaction();
95 Optional<CurrentPmlist> currentPmList;
96 String methodName = "";
97 List<CurrentPm> currentPms = new ArrayList<>();
98 GetPmOutputBuilder pmOutputBuilder = new GetPmOutputBuilder();
99 List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.get.pm.output.Measurements>
100 measrements = new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418
101 .get.pm.output.Measurements>();
103 currentPmList = rtx.read(LogicalDatastoreType.OPERATIONAL, currentPmsIID).get();
104 if (currentPmList.isPresent()) {
105 currentPms.addAll(currentPmList.get().getCurrentPm());
106 for (CurrentPm pm : currentPms) {
107 MeasurementsBuilder measurement = new MeasurementsBuilder();
108 if (pm.getResource().getResourceType().getType().toString().equals(input.getResourceType())) {
110 switch (pm.getResource().getResourceType().getType()) {
112 methodName = "getCircuitPackName";
115 methodName = "getConnectionNumber";
118 methodName = "getDegreeNumber";
121 methodName = "getInterfaceName";
124 methodName = "getInternalLinkName";
127 methodName = "getPhysicalLinkName";
130 methodName = "getServiceName";
133 methodName = "getShelfName";
135 case SharedRiskGroup:
136 methodName = "getSrgNumber";
139 methodName = "getPort";
144 String pmResourceId = pm.getResource().getResource().getResource().getImplementedInterface()
145 .getMethod(methodName).invoke(pm.getResource().getResource().getResource()).toString();
146 if (pmResourceId.equals(input.getResourceName()) && pm.getGranularity() != null) {
147 if (pm.getGranularity().getName().equals(input.getGranularity())) {
148 for (Measurements measure : pm.getMeasurements()) {
149 if (!measure.getMeasurement().getPmParameterName().getType().equals(
150 PmNamesEnum.VendorExtension)) {
151 measurement.setPmparameterName(measure.getMeasurement().getPmParameterName()
152 .getType().toString());
153 measurement.setPmparameterValue(measure.getMeasurement()
154 .getPmParameterValue().getDecimal64().toString());
155 measrements.add(measurement.build());
161 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
162 | NoSuchMethodException | SecurityException ex) {
163 LOG.warn("Unable to find PM for NodeID: {} ResourceName: {} ",input.getNodeId(),
164 input.getResourceName(),ex);
168 if (measrements.size() > 0) {
169 pmOutputBuilder.setNodeId(input.getNodeId()).setResourceType(input.getResourceType()).setResourceId(
170 input.getResourceName()).setGranularity(input.getGranularity()).setMeasurements(measrements);
174 LOG.info("Device PM Data is not available");
177 } catch (InterruptedException | ExecutionException ex) {
178 LOG.warn("Unable to get currentPmList for NodeID: {}",input.getNodeId(),ex);
180 LOG.info("PM Data found successfully for {}-{}",pmOutputBuilder.getNodeId(),pmOutputBuilder.getResourceId());
181 return RpcResultBuilder.success(pmOutputBuilder).buildFuture();
186 * This method is the implementation of the 'service-power-setup' RESTCONF service, which
187 * is one of the external APIs into the olm application.
190 * 1. service-power-setup: This operation performs following steps:
191 * Step1: Calculate Spanloss on all links which are part of service.
192 * TODO Step2: Calculate power levels for each Tp-Id
193 * TODO Step3: Post power values on roadm connections
196 * The signature for this method was generated by yang tools from the
197 * renderer API model.
200 * Input parameter from the olm yang model
201 * Input will contain nodeId and termination point
203 * @return Result of the request
206 public Future<org.opendaylight.yangtools.yang.common.RpcResult<ServicePowerSetupOutput>> servicePowerSetup(
207 ServicePowerSetupInput input) {
208 List<RoadmLinks> roadmLinks = new ArrayList<RoadmLinks>();
209 ServicePowerSetupOutputBuilder output = new ServicePowerSetupOutputBuilder();
210 //Finds degree TpID from node and generates a list of links
211 for (int i = 0; i < input.getNodes().size(); i++) {
212 if (input.getNodes().get(i).getDestTp().toLowerCase().contains("deg")) {
213 RoadmLinks rdmLink = new RoadmLinks();
214 rdmLink.setSrcNodeId(input.getNodes().get(i).getNodeId());
215 rdmLink.setSrcTpId(input.getNodes().get(i).getDestTp());
216 rdmLink.setDestNodeId(input.getNodes().get(i + 1).getNodeId());
217 rdmLink.setDestTpid(input.getNodes().get(i + 1).getSrcTp());
218 roadmLinks.add(rdmLink);
221 boolean successVal = new SpanLoss(db, mps).getLinkSpanloss(roadmLinks);
224 output.setResult("Success");
226 output.setResult("Failed");
229 return RpcResultBuilder.success(output).buildFuture();