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.power.PowerMgmt;
23 import org.opendaylight.transportpce.olm.spanloss.RoadmLinks;
24 import org.opendaylight.transportpce.olm.spanloss.SpanLoss;
25 import org.opendaylight.transportpce.renderer.mapping.PortMapping;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.CurrentPmlist;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.Measurements;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.currentpmlist.CurrentPm;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev161014.PmNamesEnum;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.GetPmInput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.GetPmOutput;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.GetPmOutputBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.OlmService;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.ServicePowerSetupInput;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.ServicePowerSetupOutput;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.ServicePowerSetupOutputBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.ServicePowerTurndownInput;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.ServicePowerTurndownOutput;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.ServicePowerTurndownOutputBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.get.pm.output.MeasurementsBuilder;
41 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
42 import org.opendaylight.yangtools.yang.common.RpcResult;
43 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
48 * The Class OlmPowerSetupImpl.
50 public class OlmPowerSetupImpl implements OlmService {
52 /** The Constant LOG. */
53 private static final Logger LOG = LoggerFactory.getLogger(OlmPowerSetupImpl.class);
56 private final DataBroker db;
59 private final MountPointService mps;
62 * Instantiates a new olm power setup impl.
69 public OlmPowerSetupImpl(DataBroker db, MountPointService mps) {
75 * This method is the implementation of the 'get-pm' RESTCONF service, which
76 * is one of the external APIs into the olm application.
79 * 1. get-pm This operation traverse through current PM list and gets PM for
80 * given NodeId and Resource name
83 * The signature for this method was generated by yang tools from the
87 * Input parameter from the olm yang model
89 * @return Result of the request
92 public Future<RpcResult<GetPmOutput>> getPm(GetPmInput input) {
93 LOG.info("Getting PM Data for NodeId: {} ResouceType: {} ResourceName: {}",
94 input.getNodeId(),input.getResourceType(),input.getResourceName());
95 new PortMapping(db, mps, input.getNodeId());
96 DataBroker deviceDb = PortMapping.getDeviceDataBroker(input.getNodeId(), mps);
97 InstanceIdentifier<CurrentPmlist> currentPmsIID = InstanceIdentifier.create(CurrentPmlist.class);
98 ReadOnlyTransaction rtx = deviceDb.newReadOnlyTransaction();
99 Optional<CurrentPmlist> currentPmList;
100 String methodName = "";
101 List<CurrentPm> currentPms = new ArrayList<>();
102 GetPmOutputBuilder pmOutputBuilder = new GetPmOutputBuilder();
103 List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.get.pm.output.Measurements>
104 measrements = new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418
105 .get.pm.output.Measurements>();
107 currentPmList = rtx.read(LogicalDatastoreType.OPERATIONAL, currentPmsIID).get();
108 if (currentPmList.isPresent()) {
109 currentPms.addAll(currentPmList.get().getCurrentPm());
110 for (CurrentPm pm : currentPms) {
111 MeasurementsBuilder measurement = new MeasurementsBuilder();
112 if (pm.getResource().getResourceType().getType().toString().equals(input.getResourceType())) {
114 switch (pm.getResource().getResourceType().getType()) {
116 methodName = "getCircuitPackName";
119 methodName = "getConnectionNumber";
122 methodName = "getDegreeNumber";
125 methodName = "getInterfaceName";
128 methodName = "getInternalLinkName";
131 methodName = "getPhysicalLinkName";
134 methodName = "getServiceName";
137 methodName = "getShelfName";
139 case SharedRiskGroup:
140 methodName = "getSrgNumber";
143 methodName = "getPort";
148 String pmResourceId = pm.getResource().getResource().getResource().getImplementedInterface()
149 .getMethod(methodName).invoke(pm.getResource().getResource().getResource()).toString();
150 if (pmResourceId.equals(input.getResourceName()) && pm.getGranularity() != null) {
151 if (pm.getGranularity().getName().equals(input.getGranularity())) {
152 for (Measurements measure : pm.getMeasurements()) {
153 if (!measure.getMeasurement().getPmParameterName().getType().equals(
154 PmNamesEnum.VendorExtension)) {
155 measurement.setPmparameterName(measure.getMeasurement().getPmParameterName()
156 .getType().toString());
157 measurement.setPmparameterValue(measure.getMeasurement()
158 .getPmParameterValue().getDecimal64().toString());
159 measrements.add(measurement.build());
165 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
166 | NoSuchMethodException | SecurityException ex) {
167 LOG.warn("Unable to find PM for NodeID: {} ResourceName: {} ",input.getNodeId(),
168 input.getResourceName(),ex);
172 if (measrements.size() > 0) {
173 pmOutputBuilder.setNodeId(input.getNodeId()).setResourceType(input.getResourceType()).setResourceId(
174 input.getResourceName()).setGranularity(input.getGranularity()).setMeasurements(measrements);
178 LOG.info("Device PM Data is not available");
181 } catch (InterruptedException | ExecutionException ex) {
182 LOG.warn("Unable to get currentPmList for NodeID: {}",input.getNodeId(),ex);
184 LOG.info("PM Data found successfully for {}-{}",pmOutputBuilder.getNodeId(),pmOutputBuilder.getResourceId());
185 return RpcResultBuilder.success(pmOutputBuilder).buildFuture();
190 * This method is the implementation of the 'service-power-setup' RESTCONF service, which
191 * is one of the external APIs into the olm application.
194 * 1. service-power-setup: This operation performs following steps:
195 * Step1: Calculate Spanloss on all links which are part of service.
196 * TODO Step2: Calculate power levels for each Tp-Id
197 * TODO Step3: Post power values on roadm connections
200 * The signature for this method was generated by yang tools from the
201 * renderer API model.
204 * Input parameter from the olm yang model
205 * Input will contain nodeId and termination point
207 * @return Result of the request
210 public Future<org.opendaylight.yangtools.yang.common.RpcResult<ServicePowerSetupOutput>> servicePowerSetup(
211 ServicePowerSetupInput input) {
212 List<RoadmLinks> roadmLinks = new ArrayList<RoadmLinks>();
213 ServicePowerSetupOutputBuilder output = new ServicePowerSetupOutputBuilder();
214 //Finds degree TpID from node and generates a list of links
215 for (int i = 0; i < input.getNodes().size(); i++) {
216 if (input.getNodes().get(i).getDestTp().toLowerCase().contains("deg")) {
217 RoadmLinks rdmLink = new RoadmLinks();
218 rdmLink.setSrcNodeId(input.getNodes().get(i).getNodeId());
219 rdmLink.setSrcTpId(input.getNodes().get(i).getDestTp());
220 rdmLink.setDestNodeId(input.getNodes().get(i + 1).getNodeId());
221 rdmLink.setDestTpid(input.getNodes().get(i + 1).getSrcTp());
222 roadmLinks.add(rdmLink);
225 boolean successValSpanCalculation = new SpanLoss(db, mps).getLinkSpanloss(roadmLinks);
226 boolean successValPowerCalculation = new PowerMgmt(db,mps).setPower(input);
228 if (successValSpanCalculation && successValPowerCalculation) {
229 output.setResult("Success");
231 output.setResult("Failed");
234 return RpcResultBuilder.success(output).buildFuture();
239 * This method is the implementation of the 'service-power-trundown' RESTCONF service, which
240 * is one of the external APIs into the olm application.
243 * 1. service-power-turndown: This operation performs following steps:
244 * Step1: For each TP within Node sets interface outofservice .
245 * Step2: For each roam-connection sets power to -60dbm
246 * Step3: Turns power mode off
249 * The signature for this method was generated by yang tools from the
250 * renderer API model.
253 * Input parameter from the olm yang model
254 * Input will contain nodeId and termination point
256 * @return Result of the request
259 public Future<RpcResult<ServicePowerTurndownOutput>> servicePowerTurndown(ServicePowerTurndownInput input) {
260 ServicePowerTurndownOutputBuilder output = new ServicePowerTurndownOutputBuilder();
261 if (new PowerMgmt(db,mps).powerTurnDown(input)) {
262 output.setResult("Success");
264 output.setResult("Failed");
266 return RpcResultBuilder.success(output).buildFuture();