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;
14 import org.junit.Assert;
15 import org.junit.Test;
16 import org.mockito.Mockito;
17 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
18 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
19 import org.opendaylight.transportpce.common.StringConstants;
20 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
21 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
22 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl121;
23 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl22;
24 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
25 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
26 import org.opendaylight.transportpce.common.mapping.MappingUtils;
27 import org.opendaylight.transportpce.common.mapping.MappingUtilsImpl;
28 import org.opendaylight.transportpce.common.mapping.PortMapping;
29 import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
30 import org.opendaylight.transportpce.common.mapping.PortMappingVersion121;
31 import org.opendaylight.transportpce.common.mapping.PortMappingVersion22;
32 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
33 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
34 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
35 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
36 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl22;
37 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
38 import org.opendaylight.transportpce.renderer.provisiondevice.servicepath.ServicePathDirection;
39 import org.opendaylight.transportpce.renderer.stub.MountPointServiceStub;
40 import org.opendaylight.transportpce.renderer.utils.MountPointUtils;
41 import org.opendaylight.transportpce.renderer.utils.ServiceImplementationDataUtils;
42 import org.opendaylight.transportpce.test.AbstractTest;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.ServicePathInput;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.ServicePathOutput;
45 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev170907.olm.renderer.input.Nodes;
47 public class DeviceRendererServiceImplSetupTest extends AbstractTest {
49 private DeviceTransactionManager deviceTransactionManager;
51 private DeviceRendererService deviceRendererService;
52 private CrossConnect crossConnect;
53 private PortMapping portMapping;
54 private OpenRoadmInterfaces openRoadmInterfaces;
55 private MappingUtils mappingUtils;
56 private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
57 private OpenRoadmInterfacesImpl22 openRoadmInterfacesImpl22;
58 private PortMappingVersion22 portMappingVersion22;
59 private PortMappingVersion121 portMappingVersion121;
60 private CrossConnectImpl121 crossConnectImpl121;
61 private CrossConnectImpl22 crossConnectImpl22;
64 private void setMountPoint(MountPoint mountPoint) {
65 MountPointService mountPointService = new MountPointServiceStub(mountPoint);
66 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
67 this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
68 this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl22(deviceTransactionManager);
69 this.mappingUtils = new MappingUtilsImpl(getDataBroker());
70 this.mappingUtils = Mockito.spy(this.mappingUtils);
71 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl(deviceTransactionManager, mappingUtils,
72 openRoadmInterfacesImpl121, openRoadmInterfacesImpl22);
73 this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
74 this.portMappingVersion22 =
75 new PortMappingVersion22(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
76 this.portMappingVersion121 =
77 new PortMappingVersion121(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
78 this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion22, this.mappingUtils,
79 this.portMappingVersion121);
80 this.portMapping = Mockito.spy(this.portMapping);
81 this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
82 this.crossConnectImpl22 = new CrossConnectImpl22(deviceTransactionManager);
83 this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
84 this.crossConnectImpl22);
85 this.crossConnect = Mockito.spy(this.crossConnect);
86 OpenRoadmInterfaceFactory openRoadmInterfaceFactory =
87 new OpenRoadmInterfaceFactory(this.portMapping, this.openRoadmInterfaces);
88 this.deviceRendererService = new DeviceRendererServiceImpl(this.getDataBroker(),
89 this.deviceTransactionManager, openRoadmInterfaceFactory, openRoadmInterfaces, crossConnect,
94 public void testSetupServiceWhenDeviceIsNotMounted() {
96 ServicePathInput servicePathInput = ServiceImplementationDataUtils.buildServicePathInputs();
97 for (ServicePathDirection servicePathDirection : ServicePathDirection.values()) {
98 ServicePathOutput servicePathOutput = deviceRendererService.setupServicePath(servicePathInput,
99 servicePathDirection);
100 Assert.assertFalse(servicePathOutput.isSuccess());
101 Assert.assertEquals("node1 is not mounted on the controller",
102 servicePathOutput.getResult());
107 public void testSetupServicemptyPorts() {
108 setMountPoint(MountPointUtils.getMountPoint(new ArrayList<>(), getDataBroker()));
109 String nodeId = "node1";
110 String srcTP = OpenRoadmInterfacesImpl.TTP_TOKEN;
111 String dstTp = OpenRoadmInterfacesImpl.PP_TOKEN;
112 List<Nodes> nodes = new ArrayList<>();
113 nodes.add(ServiceImplementationDataUtils.createNode(nodeId, srcTP, dstTp));
114 ServicePathInput servicePathInput = ServiceImplementationDataUtils.buildServicePathInputs(nodes);
115 for (ServicePathDirection servicePathDirection : ServicePathDirection.values()) {
116 ServicePathOutput servicePathOutput = deviceRendererService.setupServicePath(servicePathInput,
117 servicePathDirection);
118 Assert.assertFalse(servicePathOutput.isSuccess());
123 public void testSetupServiceCannotCrossConnect() {
124 setMountPoint(MountPointUtils.getMountPoint(new ArrayList<>(), getDataBroker()));
125 String nodeId = "node1";
126 String srcTP = OpenRoadmInterfacesImpl.TTP_TOKEN;
127 String dstTp = OpenRoadmInterfacesImpl.PP_TOKEN;
128 MountPointUtils.writeMapping(nodeId, srcTP, this.deviceTransactionManager);
129 MountPointUtils.writeMapping(nodeId, dstTp, this.deviceTransactionManager);
130 List<Nodes> nodes = new ArrayList<>();
131 nodes.add(ServiceImplementationDataUtils.createNode(nodeId, srcTP, dstTp));
132 ServicePathInput servicePathInput = ServiceImplementationDataUtils.buildServicePathInputs(nodes);
133 Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(this.mappingUtils)
134 .getOpenRoadmVersion("node1");
135 Mockito.doReturn(java.util.Optional.empty()).when(this.crossConnect).postCrossConnect(nodeId, 20L, srcTP,
137 ServicePathOutput servicePathOutput = deviceRendererService.setupServicePath(servicePathInput,
138 ServicePathDirection.A_TO_Z);
139 Assert.assertFalse(servicePathOutput.isSuccess());
143 public void testSetupService() throws OpenRoadmInterfaceException {
144 setMountPoint(MountPointUtils.getMountPoint(new ArrayList<>(), getDataBroker()));
145 Mockito.doNothing().when(this.openRoadmInterfaces).postEquipmentState(Mockito.anyString(),
146 Mockito.anyString(), Mockito.anyBoolean());
147 String [] interfaceTokens = {
148 OpenRoadmInterfacesImpl.NETWORK_TOKEN,
149 OpenRoadmInterfacesImpl.CLIENT_TOKEN,
150 OpenRoadmInterfacesImpl.TTP_TOKEN,
151 OpenRoadmInterfacesImpl.PP_TOKEN
154 String nodeId = "node1";
156 for (String srcToken : interfaceTokens) {
157 String srcTP = "src-" + srcToken;
158 MountPointUtils.writeMapping(nodeId, srcTP, this.deviceTransactionManager);
159 for (String dstToken : interfaceTokens) {
160 String dstTp = "dst-" + dstToken;
161 MountPointUtils.writeMapping(nodeId, dstTp, this.deviceTransactionManager);
163 boolean connectingUsingCrossConnect = true;
164 if (OpenRoadmInterfacesImpl.NETWORK_TOKEN.equals(srcToken)
165 || OpenRoadmInterfacesImpl.CLIENT_TOKEN.equals(srcToken)) {
166 connectingUsingCrossConnect = false;
168 if (OpenRoadmInterfacesImpl.NETWORK_TOKEN.equals(dstToken)
169 || OpenRoadmInterfacesImpl.CLIENT_TOKEN.equals(dstToken)) {
170 connectingUsingCrossConnect = false;
173 List<Nodes> nodes = new ArrayList<>();
174 nodes.add(ServiceImplementationDataUtils.createNode(nodeId, srcTP, dstTp));
175 ServicePathInput servicePathInput = ServiceImplementationDataUtils.buildServicePathInputs(nodes);
176 Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(this.mappingUtils)
177 .getOpenRoadmVersion("node1");
178 for (ServicePathDirection servicePathDirection : ServicePathDirection.values()) {
179 ServicePathOutput servicePathOutput = deviceRendererService.setupServicePath(servicePathInput,
180 servicePathDirection);
181 Assert.assertTrue(servicePathOutput.isSuccess());
182 String expectedResult = "Roadm-connection successfully created for nodes: ";
183 if (connectingUsingCrossConnect) {
184 expectedResult = expectedResult + nodeId;
186 Assert.assertEquals(expectedResult, servicePathOutput.getResult());
187 Assert.assertEquals(1, servicePathOutput.getNodeInterface().size());
188 Assert.assertEquals(nodeId, servicePathOutput.getNodeInterface().get(0).getNodeId());
189 if (!connectingUsingCrossConnect) { // No need to try both directions if not cross connect
198 public void testSetupServiceNulls() throws OpenRoadmInterfaceException {
199 setMountPoint(MountPointUtils.getMountPoint(new ArrayList<>(), getDataBroker()));
200 String nodeId = "node1";
203 boolean connectingUsingCrossConnect = true;
205 List<Nodes> nodes = new ArrayList<>();
206 nodes.add(ServiceImplementationDataUtils.createNode(nodeId, srcTP, dstTp));
207 ServicePathInput servicePathInput = ServiceImplementationDataUtils.buildServicePathInputs(nodes);
208 Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(this.mappingUtils)
209 .getOpenRoadmVersion("node1");
210 for (ServicePathDirection servicePathDirection : ServicePathDirection.values()) {
211 ServicePathOutput servicePathOutput = deviceRendererService.setupServicePath(servicePathInput,
212 servicePathDirection);
213 Assert.assertTrue(servicePathOutput.isSuccess());
214 String expectedResult = "Roadm-connection successfully created for nodes: ";
215 expectedResult = expectedResult + nodeId;
216 Assert.assertEquals(expectedResult, servicePathOutput.getResult());
217 Assert.assertEquals(1, servicePathOutput.getNodeInterface().size());
218 Assert.assertEquals(nodeId, servicePathOutput.getNodeInterface().get(0).getNodeId());