2 * Copyright © 2019 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.renderer.provisiondevice;
10 import java.util.ArrayList;
11 import java.util.LinkedList;
12 import java.util.List;
13 import java.util.Optional;
14 import java.util.concurrent.ConcurrentLinkedQueue;
15 import java.util.concurrent.ExecutionException;
16 import java.util.concurrent.ForkJoinPool;
17 import java.util.concurrent.ForkJoinTask;
18 import java.util.concurrent.atomic.AtomicBoolean;
20 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
21 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
22 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
23 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
24 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.OtnServicePathInput;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.OtnServicePathOutput;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.OtnServicePathOutputBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.Interface;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev200128.node.interfaces.NodeInterface;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev200128.node.interfaces.NodeInterfaceBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev200128.node.interfaces.NodeInterfaceKey;
32 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev200128.otn.renderer.input.Nodes;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 public class OtnDeviceRendererServiceImpl implements OtnDeviceRendererService {
37 private static final Logger LOG = LoggerFactory.getLogger(OtnDeviceRendererServiceImpl.class);
38 private final OpenRoadmInterfaceFactory openRoadmInterfaceFactory;
39 private final CrossConnect crossConnect;
40 private final OpenRoadmInterfaces openRoadmInterfaces;
41 private final DeviceTransactionManager deviceTransactionManager;
44 public OtnDeviceRendererServiceImpl(OpenRoadmInterfaceFactory openRoadmInterfaceFactory, CrossConnect crossConnect,
45 OpenRoadmInterfaces openRoadmInterfaces,
46 DeviceTransactionManager deviceTransactionManager) {
47 this.openRoadmInterfaceFactory = openRoadmInterfaceFactory;
48 this.crossConnect = crossConnect;
49 this.openRoadmInterfaces = openRoadmInterfaces;
50 this.deviceTransactionManager = deviceTransactionManager;
54 public OtnServicePathOutput setupOtnServicePath(OtnServicePathInput input) {
55 LOG.info("Calling setup service path");
56 boolean success = true;
57 List<NodeInterface> nodeInterfaces = new ArrayList<>();
58 List<String> results = new ArrayList<>();
59 if (input.getServiceType().equals("Ethernet")) {
61 LOG.info("Calling Node interfaces {} {} {} {} {} {} {}",
62 input.getServiceRate(),input.getEthernetEncoding(),
63 input.getServiceType(),input.getOperation(),input.getTribPortNumber(),
64 input.getTribSlot(),input.getNodes());
65 nodeInterfaces = createInterface(input);
66 LOG.info("Node interfaces created just fine ");
68 catch (OpenRoadmInterfaceException e) {
70 LOG.warn("Set up service path failed {}", e.toString());
76 LOG.info("Result is success");
77 for (NodeInterface nodeInterface: nodeInterfaces) {
78 results.add("Otn Service path was set up successfully for node :" + nodeInterface.getNodeId());
80 //TODO Add otn topology links
82 OtnServicePathOutputBuilder otnServicePathOutputBuilder = new OtnServicePathOutputBuilder()
84 .setNodeInterface(nodeInterfaces)
85 .setResult(String.join("\n", results));
86 return otnServicePathOutputBuilder.build();
90 public OtnServicePathOutput deleteOtnServicePath(OtnServicePathInput input) {
91 List<Nodes> nodes = input.getNodes();
92 AtomicBoolean success = new AtomicBoolean(true);
93 ConcurrentLinkedQueue<String> results = new ConcurrentLinkedQueue<>();
94 ForkJoinPool forkJoinPool = new ForkJoinPool();
95 ForkJoinTask forkJoinTask = forkJoinPool.submit(() -> nodes.parallelStream().forEach(node -> {
96 List<String> interfacesToDelete = new LinkedList<>();
97 String nodeId = node.getNodeId();
98 LOG.info("Deleting service setup on node {}", nodeId);
99 String srcTp = node.getClientTp();
100 String destTp = node.getNetworkTp();
101 if ((srcTp == null) || (destTp == null) || input.getServiceRate() == null) {
102 LOG.error("Source ({}) or destination ({}) termination point is null.", srcTp, destTp);
105 // if the node is currently mounted then proceed.
106 if (this.deviceTransactionManager.isDeviceMounted(nodeId)) {
107 String connectionNumber = "";
108 switch (input.getServiceRate()) {
110 connectionNumber = srcTp + "-ODU2e-" + input.getServiceName() + "-x-" + destTp
111 + "-ODU2e-" + input.getServiceName();
114 connectionNumber = srcTp + "-ODU0-" + input.getServiceName() + "-x-" + destTp
115 + "-ODU2e-" + input.getServiceName();
118 LOG.error("service rate {} not managed yet", input.getServiceRate());
119 String result = input.getServiceRate() + " is not supported";
124 List<String> intToDelete = this.crossConnect.deleteCrossConnect(nodeId, connectionNumber, true);
125 if (intToDelete != null) {
126 for (String interf : intToDelete) {
127 if (!this.openRoadmInterfaceFactory.isUsedbyOtnXc(nodeId, interf, connectionNumber,
128 this.deviceTransactionManager)) {
129 interfacesToDelete.add(interf);
130 if (!getSupportedInterface(nodeId, interf).contains("ODU4")) {
131 interfacesToDelete.add(getSupportedInterface(nodeId, interf));
137 String result = nodeId + " is not mounted on the controller";
141 forkJoinPool.shutdown();
143 //TODO should deletion end here?
145 for (String interfaceId : interfacesToDelete) {
147 this.openRoadmInterfaces.deleteInterface(nodeId, interfaceId);
148 } catch (OpenRoadmInterfaceException e) {
149 String result = String.format("Failed to delete interface %s on node %s!", interfaceId, nodeId);
151 LOG.error(result, e);
158 } catch (InterruptedException | ExecutionException e) {
159 LOG.error("Error while deleting service paths!", e);
161 forkJoinPool.shutdown();
162 OtnServicePathOutputBuilder delServBldr = new OtnServicePathOutputBuilder();
163 delServBldr.setSuccess(success.get());
164 if (results.isEmpty()) {
165 return delServBldr.setResult("Request processed").build();
167 return delServBldr.setResult(String.join("\n", results)).build();
172 private String getSupportedInterface(String nodeId, String interf) {
173 Optional<Interface> supInterfOpt;
175 supInterfOpt = this.openRoadmInterfaces.getInterface(nodeId, interf);
176 if (supInterfOpt.isPresent()) {
177 return supInterfOpt.get().getSupportingInterface();
181 } catch (OpenRoadmInterfaceException e) {
182 LOG.error("error getting Supported Interface of {} - {}", interf, nodeId, e);
187 private List<NodeInterface> createInterface(OtnServicePathInput input) throws OpenRoadmInterfaceException {
188 List<NodeInterface> nodeInterfaces = new ArrayList<>();
189 LOG.info("Calling Create Interface entry for OTN service path");
190 if (input.getServiceRate() == null
191 || !("1G".equals(input.getServiceRate()) || "10G".equals(input.getServiceRate()))) {
192 LOG.error("Service rate {} not managed yet", input.getServiceRate());
194 createLowOrderInterfaces(input, nodeInterfaces);
196 return nodeInterfaces;
199 private Optional<String> postCrossConnect(List<String> createdOduInterfaces, Nodes node)
200 throws OpenRoadmInterfaceException {
201 return this.crossConnect.postOtnCrossConnect(createdOduInterfaces,node);
204 private void createLowOrderInterfaces(OtnServicePathInput input, List<NodeInterface> nodeInterfaces)
205 throws OpenRoadmInterfaceException {
206 for (Nodes node: input.getNodes()) {
207 //check if the node is mounted or not?
208 List<String> createdEthInterfaces = new ArrayList<>();
209 List<String> createdOduInterfaces = new ArrayList<>();
210 switch (input.getServiceRate()) {
212 LOG.info("Input service is 1G");
213 createdEthInterfaces.add(
214 openRoadmInterfaceFactory.createOpenRoadmEth1GInterface(node.getNodeId(), node.getClientTp()));
215 createdOduInterfaces.add(
216 //suppporting interface?, payload ?
217 openRoadmInterfaceFactory.createOpenRoadmOdu0Interface(node.getNodeId(), node.getClientTp(),
218 input.getServiceName(), "07", false, input.getTribPortNumber(), input.getTribSlot()));
219 createdOduInterfaces.add(
220 openRoadmInterfaceFactory.createOpenRoadmOdu0Interface(node.getNodeId(), node.getNetworkTp(),
221 input.getServiceName(), "07", true, input.getTribPortNumber(), input.getTribSlot()));
224 LOG.info("Input service is 10G");
225 createdEthInterfaces.add(
226 openRoadmInterfaceFactory.createOpenRoadmEth10GInterface(node.getNodeId(), node.getClientTp()));
227 createdOduInterfaces.add(
228 //suppporting interface?, payload ?
229 openRoadmInterfaceFactory.createOpenRoadmOdu2eInterface(node.getNodeId(), node.getClientTp(),
230 input.getServiceName(),"03", false ,input.getTribPortNumber(),input.getTribSlot()));
231 createdOduInterfaces.add(
232 // supporting interface? payload ?
233 openRoadmInterfaceFactory.createOpenRoadmOdu2eInterface(node.getNodeId(), node.getNetworkTp(),
234 input.getServiceName(),"03" , true ,input.getTribPortNumber(),input.getTribSlot()));
237 LOG.error("service rate {} not managed yet", input.getServiceRate());
241 //implement cross connect
242 List<String> createdConnections = new ArrayList<>();
243 if (!createdOduInterfaces.isEmpty()) {
244 Optional<String> connectionNameOpt = postCrossConnect(createdOduInterfaces, node);
245 createdConnections.add(connectionNameOpt.get());
246 LOG.info("Created cross connects");
248 NodeInterfaceBuilder nodeInterfaceBuilder = new NodeInterfaceBuilder()
249 .withKey(new NodeInterfaceKey(input.getServiceName() + "-" + node.getNodeId()))
250 .setNodeId(input.getServiceName() + "-" + node.getNodeId())
251 .setConnectionId(createdConnections)
252 .setEthInterfaceId(createdEthInterfaces)
253 .setOduInterfaceId(createdOduInterfaces);
254 nodeInterfaces.add(nodeInterfaceBuilder.build());