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 java.util.HashSet;
12 import java.util.List;
14 import java.util.concurrent.Future;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
18 import org.opendaylight.transportpce.renderer.mapping.PortMapping;
19 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaces;
20 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmOchInterface;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.RendererService;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.ServicePathInput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.ServicePathOutput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.ServicePathOutputBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.service.path.input.Nodes;
26 import org.opendaylight.yangtools.yang.common.RpcResult;
27 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public class DeviceRenderer implements RendererService {
33 private final DataBroker db;
34 private final MountPointService mps;
35 private static final Logger LOG = LoggerFactory.getLogger(RendererService.class);
36 private final Set<String> currentMountedDevice;
37 private final Set<String> nodesProvisioned;
39 public DeviceRenderer(DataBroker db, MountPointService mps, Set<String> currentMountedDevice) {
42 this.currentMountedDevice = currentMountedDevice;
43 this.nodesProvisioned = new HashSet<>();
47 * This method is the implementation of the 'service-path' RESTCONF service,
48 * which is one of the external APIs into the renderer application. The
49 * service provides two functions:
52 * 1. Create This operation results in provisioning the device for a given
53 * wavelength and a list of nodes with each node listing its termination
57 * 2. Delete This operation results in de-provisioning the device for a
58 * given wavelength and a list of nodes with each node listing its
62 * The signature for this method was generated by yang tools from the
66 * Input parameter from the service-path yang model
68 * @return Result of the request
71 public Future<RpcResult<ServicePathOutput>> servicePath(ServicePathInput input) {
73 if (input.getOperation().getIntValue() == 1) {
74 LOG.info("Create operation request received");
75 return RpcResultBuilder.success(setupServicePath(input)).buildFuture();
76 } else if (input.getOperation().getIntValue() == 2) {
77 LOG.info("Delete operation request received");
78 return RpcResultBuilder.success(deleteServicePath(input)).buildFuture();
80 return RpcResultBuilder.success(new ServicePathOutputBuilder().setResult("Invalid operation")).buildFuture();
84 * This method set's wavelength path based on following steps: For each
88 * 1. Create Och interface on source termination point. 2. Create Och
89 * interface on destination termination point. 3. Create cross connect
90 * between source and destination tps created in step 1 and 2.
93 * Naming convention used for OCH interfaces name : tp-wavenumber Naming
94 * convention used for cross connect name : src-dest-wavenumber
97 * Input parameter from the service-path yang model
99 * @return Result list of all nodes if request successful otherwise specific
102 public ServicePathOutputBuilder setupServicePath(ServicePathInput input) {
104 List<Nodes> nodes = input.getNodes();
105 ServicePathOutputBuilder setServBldr = new ServicePathOutputBuilder();
106 LOG.info(currentMountedDevice.toString());
107 for (Nodes n : nodes) {
108 LOG.info("Starting provisioning for node : " + n.getNodeId());
109 String nodeId = n.getNodeId();
110 // if the node is currently mounted then proceed
111 if (currentMountedDevice.contains(n.getNodeId())) {
112 String srcTp = n.getSrcTp();
113 String destTp = n.getDestTp();
115 Long waveNumber = input.getWaveNumber();
116 String srcIf = new OpenRoadmOchInterface(db, mps, nodeId, srcTp).createInterface(waveNumber);
117 // if source interface creation was successful then proceed
120 LOG.warn("Unable to create OCH interface on " + nodeId + " at " + srcTp);
121 return setServBldr.setResult("Unable to create OCH interface on " + nodeId + " at " + srcTp);
123 // if destination interface creation was then proceed otherwise
125 String dstIf = new OpenRoadmOchInterface(db, mps, nodeId, destTp).createInterface(waveNumber);
127 LOG.warn("Unable to create OCH interface on " + nodeId + " at " + destTp);
128 return setServBldr.setResult("Unable to create OCH interface on " + nodeId + " at " + destTp);
130 LOG.info("Creating cross connect between source :" + srcTp + " destination " + destTp + " for node " + n
132 DataBroker netconfNodeDataBroker = PortMapping.getDeviceDataBroker(nodeId, mps);
133 CrossConnect roadmConnections = new CrossConnect(netconfNodeDataBroker);
134 if (roadmConnections.postCrossConnect(waveNumber, srcTp, destTp) == true) {
135 nodesProvisioned.add(nodeId);
136 roadmConnections.getConnectionPortTrail(nodeId, mps, waveNumber, srcTp, destTp);
139 return setServBldr.setResult("Unable to post Roadm-connection for node " + nodeId);
142 LOG.warn(nodeId + " is not mounted on the controller");
143 return setServBldr.setResult(nodeId + " is not mounted on the controller");
146 return setServBldr.setResult("Roadm-connection successfully created for nodes " + nodesProvisioned.toString());
150 * This method removes wavelength path based on following steps: For each
154 * 1. Delete Cross connect between source and destination tps. 2. Delete Och
155 * interface on source termination point. 3. Delete Och interface on
156 * destination termination point.
159 * Naming convention used for OCH interfaces name : tp-wavenumber Naming
160 * convention used for cross connect name : src-dest-wavenumber
163 * Input parameter from the service-path yang model
165 * @return Result result of the request.
167 public ServicePathOutputBuilder deleteServicePath(ServicePathInput input) {
168 List<Nodes> nodes = input.getNodes();
169 ServicePathOutputBuilder delServBldr = new ServicePathOutputBuilder();
170 LOG.info(currentMountedDevice.toString());
171 for (Nodes n : nodes) {
173 String nodeId = n.getNodeId();
174 LOG.info("Deleting service setup on node " + nodeId);
175 String srcTp = n.getSrcTp();
176 String destTp = n.getDestTp();
177 Long waveNumber = input.getWaveNumber();
179 // if the node is currently mounted then proceed.
180 if (currentMountedDevice.contains(nodeId)) {
181 String connectionNumber = srcTp + "-" + destTp + "-" + waveNumber;
182 CrossConnect roadmConnection = new CrossConnect(PortMapping.getDeviceDataBroker(nodeId, mps),
184 if (!roadmConnection.deleteCrossConnect()) {
185 LOG.error("Failed to delete {} ", srcTp + "-" + destTp + "-" + waveNumber);
187 // Deleting interface on source termination point
188 if (new OpenRoadmInterfaces(db, mps, nodeId, srcTp).deleteInterface(srcTp + "-" + waveNumber
189 .toString()) == false) {
190 LOG.error("Failed to delete interface " + srcTp + "-" + waveNumber.toString());
193 // Deleting interface on destination termination point
194 if (new OpenRoadmInterfaces(db, mps, nodeId, srcTp).deleteInterface(destTp + "-" + waveNumber
195 .toString()) == false) {
196 LOG.error("Failed to delete interface " + srcTp + "-" + waveNumber.toString());
199 LOG.warn(nodeId + " is not mounted on the controller");
200 return delServBldr.setResult(nodeId + " is not mounted on the controller");
203 return delServBldr.setResult("Request processed");