2 * Copyright © 2018 Orange Systems, Inc. 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.ArrayList;
12 import java.util.List;
13 import java.util.concurrent.ExecutionException;
14 import org.junit.Assert;
15 import org.junit.Test;
16 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
17 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
18 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
19 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
20 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
21 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
22 import org.opendaylight.transportpce.common.mapping.PortMapping;
23 import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
24 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
25 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
26 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
27 import org.opendaylight.transportpce.renderer.provisiondevice.servicepath.ServicePathDirection;
28 import org.opendaylight.transportpce.renderer.stub.MountPointServiceStub;
29 import org.opendaylight.transportpce.renderer.stub.MountPointStub;
30 import org.opendaylight.transportpce.renderer.utils.MountPointUtils;
31 import org.opendaylight.transportpce.renderer.utils.ServiceDataUtils;
32 import org.opendaylight.transportpce.test.AbstractTest;
33 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev170907.node.interfaces.NodeInterface;
34 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev170907.node.interfaces.NodeInterfaceBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev170907.node.interfaces.NodeInterfaceKey;
36 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev170907.olm.renderer.input.Nodes;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.RendererRollbackInput;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.RendererRollbackInputBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.RendererRollbackOutput;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.ServicePathInput;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.ServicePathOutput;
43 public class DeviceRendererServiceImplTest extends AbstractTest {
45 private MountPointService mountPointService;
47 private DeviceTransactionManager deviceTransactionManager;
49 private DeviceRendererService deviceRendererService;
51 private void setMountPoint(MountPoint mountPoint) {
52 this.mountPointService = new MountPointServiceStub(mountPoint);
53 this.deviceTransactionManager = new DeviceTransactionManagerImpl(this.mountPointService, 3000);
54 OpenRoadmInterfaces openRoadmInterfaces = new OpenRoadmInterfacesImpl(this.deviceTransactionManager);
55 PortMapping portMapping = new PortMappingImpl(this.getDataBroker(), this.deviceTransactionManager,
57 OpenRoadmInterfaceFactory openRoadmInterfaceFactory = new OpenRoadmInterfaceFactory(portMapping,
59 CrossConnect crossConnect = new CrossConnectImpl(this.deviceTransactionManager);
60 this.deviceRendererService = new DeviceRendererServiceImpl(this.getDataBroker(),
61 this.deviceTransactionManager, openRoadmInterfaceFactory, openRoadmInterfaces, crossConnect);
65 public void testSetupServiceWhenDeviceIsNotMounted() {
67 ServicePathInput servicePathInput = ServiceDataUtils.buildServicePathInputs();
68 for (ServicePathDirection servicePathDirection : ServicePathDirection.values()) {
69 ServicePathOutput servicePathOutput = deviceRendererService.setupServicePath(servicePathInput,
70 servicePathDirection);
71 Assert.assertFalse(servicePathOutput.isSuccess());
72 Assert.assertEquals("node1 is not mounted on the controller",
73 servicePathOutput.getResult());
78 public void testSetupServiceUsingCrossConnectEmptyPorts() throws ExecutionException, InterruptedException {
79 setMountPoint(MountPointUtils.getMountPoint(new ArrayList<>(), getDataBroker()));
80 testSetupService(true);
84 public void testSetupServiceUsingCrossConnectWithPorts() throws ExecutionException, InterruptedException {
85 setMountPoint(MountPointUtils.getMountPoint(new ArrayList<>(), getDataBroker()));
86 testSetupService(true);
90 public void testSetupServiceWithoutCrossConnect() throws ExecutionException, InterruptedException {
91 setMountPoint(new MountPointStub(getDataBroker()));
93 testSetupService(false);
96 private void testSetupService(boolean crossConnect) throws ExecutionException, InterruptedException {
97 String [] interfaceTokens = {
98 OpenRoadmInterfacesImpl.NETWORK_TOKEN,
99 OpenRoadmInterfacesImpl.CLIENT_TOKEN,
100 OpenRoadmInterfacesImpl.TTP_TOKEN,
101 OpenRoadmInterfacesImpl.PP_TOKEN,
105 String nodeId = "node1";
107 for (String srcToken : interfaceTokens) {
108 String srcTP = "src-" + srcToken;
109 MountPointUtils.writeMapping(nodeId, srcTP, this.deviceTransactionManager);
110 for (String dstToken : interfaceTokens) {
111 String dstTp = "dst-" + dstToken;
112 MountPointUtils.writeMapping(nodeId, dstTp, this.deviceTransactionManager);
114 boolean connectingUsingCrossConnect = true;
115 if (OpenRoadmInterfacesImpl.NETWORK_TOKEN.equals(srcToken)
116 || OpenRoadmInterfacesImpl.CLIENT_TOKEN.equals(srcToken)) {
117 connectingUsingCrossConnect = false;
119 if (OpenRoadmInterfacesImpl.NETWORK_TOKEN.equals(dstToken)
120 || OpenRoadmInterfacesImpl.CLIENT_TOKEN.equals(dstToken)) {
121 connectingUsingCrossConnect = false;
124 if (connectingUsingCrossConnect != crossConnect) {
128 List<Nodes> nodes = new ArrayList<>();
129 nodes.add(ServiceDataUtils.createNode(nodeId, srcTP, dstTp));
130 ServicePathInput servicePathInput = ServiceDataUtils.buildServicePathInputs(nodes);
132 for (ServicePathDirection servicePathDirection : ServicePathDirection.values()) {
133 ServicePathOutput servicePathOutput = deviceRendererService.setupServicePath(servicePathInput,
134 servicePathDirection);
135 Assert.assertTrue(servicePathOutput.isSuccess());
136 String expectedResult = "Roadm-connection successfully created for nodes: ";
138 expectedResult = expectedResult + nodeId;
140 Assert.assertEquals(expectedResult, servicePathOutput.getResult());
141 Assert.assertEquals(1, servicePathOutput.getNodeInterface().size());
142 Assert.assertEquals(nodeId, servicePathOutput.getNodeInterface().get(0).getNodeId());
149 public void testRollbackEmptyInterface() {
150 setMountPoint(new MountPointStub(getDataBroker()));
151 RendererRollbackInput rendererRollbackInput = ServiceDataUtils.buildRendererRollbackInput();
152 RendererRollbackOutput rendererRollbackOutput =
153 this.deviceRendererService.rendererRollback(rendererRollbackInput);
154 Assert.assertTrue(rendererRollbackOutput.isSuccess());
155 Assert.assertTrue(rendererRollbackOutput.getFailedToRollback().isEmpty());
159 public void testRollbackConnectionIdNotExist() {
160 setMountPoint(new MountPointStub(getDataBroker()));
162 NodeInterfaceBuilder nodeInterfaceBuilder = new NodeInterfaceBuilder();
163 nodeInterfaceBuilder.setNodeId("node1");
164 nodeInterfaceBuilder.withKey(new NodeInterfaceKey("node1"));
165 List<String> connectionID = new ArrayList<>();
166 connectionID.add("node1-PP");
167 nodeInterfaceBuilder.setConnectionId(connectionID);
168 List<NodeInterface> nodeInterfaces = new ArrayList<>();
169 nodeInterfaces.add(nodeInterfaceBuilder.build());
170 RendererRollbackInputBuilder rendererRollbackInputBuilder = new RendererRollbackInputBuilder();
171 rendererRollbackInputBuilder.setNodeInterface(nodeInterfaces);
173 RendererRollbackOutput rendererRollbackOutput =
174 this.deviceRendererService.rendererRollback(rendererRollbackInputBuilder.build());
175 Assert.assertFalse(rendererRollbackOutput.isSuccess());
176 Assert.assertEquals(1, rendererRollbackOutput.getFailedToRollback().size());
177 Assert.assertEquals("node1", rendererRollbackOutput.getFailedToRollback().get(0).getNodeId());