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
9 package org.opendaylight.transportpce.renderer.provisiondevice;
11 import com.google.common.base.Optional;
12 import com.google.common.util.concurrent.CheckedFuture;
14 import java.util.concurrent.ExecutionException;
15 import java.util.concurrent.Future;
17 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
18 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
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.binding.api.WriteTransaction;
22 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
23 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
24 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
25 import org.opendaylight.transportpce.renderer.mapping.PortMapping;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.OpticalControlMode;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.PowerDBm;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.GetConnectionPortTrailInputBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.GetConnectionPortTrailOutput;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OrgOpenroadmDeviceService;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.connection.DestinationBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.connection.SourceBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.get.connection.port.trail.output.Ports;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnections;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnectionsBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnectionsKey;
38 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
39 import org.opendaylight.yangtools.yang.common.RpcResult;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
43 public class CrossConnect {
45 private final DataBroker deviceDb;
46 private static final Logger LOG = LoggerFactory.getLogger(CrossConnect.class);
47 private final String connectionNumber;
48 private final InstanceIdentifier<RoadmConnections> rdmConnectionIID;
50 public CrossConnect(DataBroker deviceDb) {
51 this.deviceDb = deviceDb;
52 connectionNumber = null;
53 rdmConnectionIID = null;
56 public CrossConnect(DataBroker deviceDb, String connectionNumber) {
57 this.deviceDb = deviceDb;
58 this.connectionNumber = connectionNumber;
59 rdmConnectionIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(RoadmConnections.class,
60 new RoadmConnectionsKey(connectionNumber));
64 * This method return the RoadmConnection subtree for a given connection
67 * @return Roadm connection subtree from the device.
69 public RoadmConnections getCrossConnect() {
71 if (deviceDb != null && connectionNumber != null) {
72 ReadOnlyTransaction rtx = deviceDb.newReadOnlyTransaction();
73 Optional<RoadmConnections> roadmConnectionsObject;
75 roadmConnectionsObject = rtx.read(LogicalDatastoreType.OPERATIONAL, rdmConnectionIID).get();
76 if (roadmConnectionsObject.isPresent()) {
77 return roadmConnectionsObject.get();
79 } catch (InterruptedException | ExecutionException ex) {
80 LOG.info("Error getting roadm-connection subtree from the device for " + connectionNumber, ex);
88 * This method does a post(edit-config) on roadm connection subtree for a
89 * given connection number.
94 * Name of source termination point.
96 * Name of destination termination point.
97 * @return true/false based on status of operation.
99 public boolean postCrossConnect(Long waveNumber, String srcTp, String destTp) {
101 RoadmConnectionsBuilder rdmConnBldr = new RoadmConnectionsBuilder();
102 rdmConnBldr.setConnectionNumber(srcTp + "-" + destTp + "-" + waveNumber);
103 rdmConnBldr.setWavelengthNumber(waveNumber);
104 rdmConnBldr.setOpticalControlMode(OpticalControlMode.Off);
105 rdmConnBldr.setSource(new SourceBuilder().setSrcIf(srcTp + "-" + waveNumber.toString()).build());
106 rdmConnBldr.setDestination(new DestinationBuilder().setDstIf(destTp + "-" + waveNumber.toString()).build());
107 InstanceIdentifier<RoadmConnections> rdmConnectionIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
108 .child(RoadmConnections.class, new RoadmConnectionsKey(rdmConnBldr.getConnectionNumber()));
110 if (deviceDb != null) {
111 final WriteTransaction writeTransaction = deviceDb.newWriteOnlyTransaction();
112 // post the cross connect on the device
113 writeTransaction.put(LogicalDatastoreType.CONFIGURATION, rdmConnectionIID, rdmConnBldr.build());
114 final CheckedFuture<Void, TransactionCommitFailedException> submit = writeTransaction.submit();
117 LOG.info("Roadm-connection successfully created: " + srcTp + "-" + destTp + "-" + waveNumber);
119 } catch (TransactionCommitFailedException ex) {
120 LOG.info("Failed to post {} ", rdmConnBldr.build(), ex);
124 LOG.error("Invalid device databroker");
132 * This method does a delete(edit-config) on roadm connection subtree for a
133 * given connection number.
135 * @return true/false based on status of operation.
138 public boolean deleteCrossConnect() {
140 //Check if cross connect exists before delete
141 if (getCrossConnect() == null) {
142 LOG.info("Cross connect does not exist, halting delete");
145 if (deviceDb != null) {
146 final WriteTransaction writeTransaction = deviceDb.newWriteOnlyTransaction();
147 // post the cross connect on the device
148 writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, rdmConnectionIID);
149 final CheckedFuture<Void, TransactionCommitFailedException> submit = writeTransaction.submit();
152 LOG.info("Roadm connection successfully deleted ");
154 } catch (TransactionCommitFailedException ex) {
155 LOG.info("Failed to delete {} ", connectionNumber, ex);
159 LOG.error("Invalid device databroker");
167 * This method does an edit-config on roadm connection subtree for a given
168 * connection number in order to set power level for use by the optical
172 * Optical control modelcan be off, power or gainLoss.
174 * Power value in DBm.
175 * @return true/false based on status of operation.
177 public boolean setPowerLevel(OpticalControlMode mode, PowerDBm value) {
179 RoadmConnections rdmConn = getCrossConnect();
180 if (rdmConn != null) {
181 RoadmConnectionsBuilder rdmConnBldr = new RoadmConnectionsBuilder(rdmConn);
182 rdmConnBldr.setOpticalControlMode(mode);
183 rdmConnBldr.setTargetOutputPower(value);
184 if (deviceDb != null) {
185 final WriteTransaction writeTransaction = deviceDb.newWriteOnlyTransaction();
186 // post the cross connect on the device
187 writeTransaction.put(LogicalDatastoreType.CONFIGURATION, rdmConnectionIID, rdmConnBldr.build());
188 final CheckedFuture<Void, TransactionCommitFailedException> submit = writeTransaction.submit();
191 LOG.info("Roadm connection power level successfully set ");
193 } catch (TransactionCommitFailedException ex) {
194 LOG.info("Failed to post {} ", rdmConnBldr.build(), ex);
198 LOG.error("Invalid device databroker");
202 LOG.info("Roadm-Connection does not exist");
208 * This public method returns the list of ports (port-trail) for a roadm's
209 * cross connect. It calls rpc get-port-trail on device. To be used store
210 * detailed path description.
214 * @param mountService
215 * Reference to mount point service.
219 * Source logical connection point.
221 * Destination logical connection point.
223 * @return list of Ports object type.
225 public Ports getConnectionPortTrail(String nodeId, MountPointService mountService, Long waveNumber, String srcTp,
228 String connectionName = srcTp + "-" + destTp + "-" + waveNumber;
229 MountPoint mountPoint = PortMapping.getDeviceMountPoint(nodeId, mountService);
231 final Optional<RpcConsumerRegistry> service = mountPoint.getService(RpcConsumerRegistry.class);
232 if (!service.isPresent()) {
233 LOG.error("Failed to get RpcService for node {}", nodeId);
235 final OrgOpenroadmDeviceService rpcService = service.get().getRpcService(OrgOpenroadmDeviceService.class);
236 final GetConnectionPortTrailInputBuilder portTrainInputBuilder = new GetConnectionPortTrailInputBuilder();
237 portTrainInputBuilder.setConnectionNumber(connectionName);
238 final Future<RpcResult<GetConnectionPortTrailOutput>> portTrailOutput = rpcService.getConnectionPortTrail(
239 portTrainInputBuilder.build());
240 if (portTrailOutput != null) {
242 LOG.info("Getting port trail for node " + nodeId + "'s connection number " + connectionName);
243 for (Ports ports : portTrailOutput.get().getResult().getPorts()) {
244 LOG.info(nodeId + " - " + "Circuit pack " + ports.getCircuitPackName() + "- Port " + ports
247 } catch (InterruptedException | ExecutionException e) {
248 LOG.info("Exception caught", e);
251 LOG.info("Port trail is null");