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.CrossConnectImpl221;
24 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
25 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
26 import org.opendaylight.transportpce.common.fixedflex.FixedFlexImpl;
27 import org.opendaylight.transportpce.common.fixedflex.FixedFlexInterface;
28 import org.opendaylight.transportpce.common.mapping.MappingUtils;
29 import org.opendaylight.transportpce.common.mapping.PortMapping;
30 import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
31 import org.opendaylight.transportpce.common.mapping.PortMappingVersion121;
32 import org.opendaylight.transportpce.common.mapping.PortMappingVersion221;
33 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
34 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
35 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
36 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
37 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl221;
38 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterface121;
39 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterface22;
40 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
41 import org.opendaylight.transportpce.renderer.provisiondevice.servicepath.ServicePathDirection;
42 import org.opendaylight.transportpce.renderer.stub.MountPointServiceStub;
43 import org.opendaylight.transportpce.renderer.utils.MountPointUtils;
44 import org.opendaylight.transportpce.renderer.utils.ServiceImplementationDataUtils;
45 import org.opendaylight.transportpce.test.AbstractTest;
46 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.ServicePathInput;
47 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.ServicePathOutput;
48 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev170907.olm.renderer.input.Nodes;
50 public class DeviceRendererServiceImplSetupTest extends AbstractTest {
52 private DeviceTransactionManager deviceTransactionManager;
54 private DeviceRendererService deviceRendererService;
55 private CrossConnect crossConnect;
56 private PortMapping portMapping;
57 private OpenRoadmInterfaces openRoadmInterfaces;
58 private MappingUtils mappingUtils;
59 private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
60 private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl221;
61 private PortMappingVersion221 portMappingVersion22;
62 private PortMappingVersion121 portMappingVersion121;
63 private CrossConnectImpl121 crossConnectImpl121;
64 private CrossConnectImpl221 crossConnectImpl221;
67 private void setMountPoint(MountPoint mountPoint) {
68 MountPointService mountPointService = new MountPointServiceStub(mountPoint);
69 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
70 this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
71 this.openRoadmInterfacesImpl221 = new OpenRoadmInterfacesImpl221(deviceTransactionManager);
72 this.mappingUtils = Mockito.spy(MappingUtils.class);
74 Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(mappingUtils)
75 .getOpenRoadmVersion(Mockito.anyString());
77 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl(deviceTransactionManager, mappingUtils,
78 openRoadmInterfacesImpl121, openRoadmInterfacesImpl221);
79 this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
80 this.portMappingVersion22 =
81 new PortMappingVersion221(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
82 this.portMappingVersion121 =
83 new PortMappingVersion121(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
84 this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion22, this.mappingUtils,
85 this.portMappingVersion121);
86 this.portMapping = Mockito.spy(this.portMapping);
87 this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
88 this.crossConnectImpl221 = new CrossConnectImpl221(deviceTransactionManager);
89 this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
90 this.crossConnectImpl221);
91 this.crossConnect = Mockito.spy(this.crossConnect);
94 FixedFlexInterface fixedFlexInterface = new FixedFlexImpl();
95 OpenRoadmInterface121 openRoadmInterface121 = new OpenRoadmInterface121(portMapping,openRoadmInterfaces);
96 OpenRoadmInterface22 openRoadmInterface22 = new OpenRoadmInterface22(portMapping,openRoadmInterfaces,
98 OpenRoadmInterfaceFactory openRoadmInterfaceFactory = new OpenRoadmInterfaceFactory(this.mappingUtils,
99 openRoadmInterface121,openRoadmInterface22);
101 this.deviceRendererService = new DeviceRendererServiceImpl(this.getDataBroker(),
102 this.deviceTransactionManager, openRoadmInterfaceFactory, openRoadmInterfaces, crossConnect,
107 public void testSetupServiceWhenDeviceIsNotMounted() {
109 ServicePathInput servicePathInput = ServiceImplementationDataUtils.buildServicePathInputs();
110 for (ServicePathDirection servicePathDirection : ServicePathDirection.values()) {
111 ServicePathOutput servicePathOutput = deviceRendererService.setupServicePath(servicePathInput,
112 servicePathDirection);
113 Assert.assertFalse(servicePathOutput.isSuccess());
114 Assert.assertEquals("node1 is not mounted on the controller",
115 servicePathOutput.getResult());
120 public void testSetupServicemptyPorts() {
121 setMountPoint(MountPointUtils.getMountPoint(new ArrayList<>(), getDataBroker()));
122 String nodeId = "node1";
123 String srcTP = StringConstants.TTP_TOKEN;
124 String dstTp = StringConstants.PP_TOKEN;
125 List<Nodes> nodes = new ArrayList<>();
126 nodes.add(ServiceImplementationDataUtils.createNode(nodeId, srcTP, dstTp));
127 ServicePathInput servicePathInput = ServiceImplementationDataUtils.buildServicePathInputs(nodes);
128 for (ServicePathDirection servicePathDirection : ServicePathDirection.values()) {
129 ServicePathOutput servicePathOutput = deviceRendererService.setupServicePath(servicePathInput,
130 servicePathDirection);
131 Assert.assertFalse(servicePathOutput.isSuccess());
136 public void testSetupServiceCannotCrossConnect() {
137 setMountPoint(MountPointUtils.getMountPoint(new ArrayList<>(), getDataBroker()));
138 String nodeId = "node1";
139 String srcTP = StringConstants.TTP_TOKEN;
140 String dstTp = StringConstants.PP_TOKEN;
141 MountPointUtils.writeMapping(nodeId, srcTP, this.deviceTransactionManager);
142 MountPointUtils.writeMapping(nodeId, dstTp, this.deviceTransactionManager);
143 List<Nodes> nodes = new ArrayList<>();
144 nodes.add(ServiceImplementationDataUtils.createNode(nodeId, srcTP, dstTp));
145 ServicePathInput servicePathInput = ServiceImplementationDataUtils.buildServicePathInputs(nodes);
146 Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(this.mappingUtils)
147 .getOpenRoadmVersion("node1");
148 Mockito.doReturn(java.util.Optional.empty()).when(this.crossConnect).postCrossConnect(nodeId, 20L, srcTP,
150 ServicePathOutput servicePathOutput = deviceRendererService.setupServicePath(servicePathInput,
151 ServicePathDirection.A_TO_Z);
152 Assert.assertFalse(servicePathOutput.isSuccess());
156 public void testSetupService() throws OpenRoadmInterfaceException {
157 setMountPoint(MountPointUtils.getMountPoint(new ArrayList<>(), getDataBroker()));
158 Mockito.doNothing().when(this.openRoadmInterfaces).postEquipmentState(Mockito.anyString(),
159 Mockito.anyString(), Mockito.anyBoolean());
160 String [] interfaceTokens = {
161 StringConstants.NETWORK_TOKEN,
162 StringConstants.CLIENT_TOKEN,
163 StringConstants.TTP_TOKEN,
164 StringConstants.PP_TOKEN
167 String nodeId = "node1";
169 for (String srcToken : interfaceTokens) {
170 String srcTP = "src-" + srcToken;
171 MountPointUtils.writeMapping(nodeId, srcTP, this.deviceTransactionManager);
172 for (String dstToken : interfaceTokens) {
173 String dstTp = "dst-" + dstToken;
174 MountPointUtils.writeMapping(nodeId, dstTp, this.deviceTransactionManager);
176 boolean connectingUsingCrossConnect = true;
177 if (StringConstants.NETWORK_TOKEN.equals(srcToken)
178 || StringConstants.CLIENT_TOKEN.equals(srcToken)) {
179 connectingUsingCrossConnect = false;
181 if (StringConstants.NETWORK_TOKEN.equals(dstToken)
182 || StringConstants.CLIENT_TOKEN.equals(dstToken)) {
183 connectingUsingCrossConnect = false;
186 List<Nodes> nodes = new ArrayList<>();
187 nodes.add(ServiceImplementationDataUtils.createNode(nodeId, srcTP, dstTp));
188 ServicePathInput servicePathInput = ServiceImplementationDataUtils.buildServicePathInputs(nodes);
189 Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(this.mappingUtils)
190 .getOpenRoadmVersion("node1");
191 for (ServicePathDirection servicePathDirection : ServicePathDirection.values()) {
192 ServicePathOutput servicePathOutput = deviceRendererService.setupServicePath(servicePathInput,
193 servicePathDirection);
194 Assert.assertTrue(servicePathOutput.isSuccess());
195 String expectedResult = "Roadm-connection successfully created for nodes: ";
196 if (connectingUsingCrossConnect) {
197 expectedResult = expectedResult + nodeId;
199 Assert.assertEquals(expectedResult, servicePathOutput.getResult());
200 Assert.assertEquals(1, servicePathOutput.getNodeInterface().size());
201 Assert.assertEquals(nodeId, servicePathOutput.getNodeInterface().get(0).getNodeId());
202 if (!connectingUsingCrossConnect) { // No need to try both directions if not cross connect
211 public void testSetupServiceNulls() throws OpenRoadmInterfaceException {
212 setMountPoint(MountPointUtils.getMountPoint(new ArrayList<>(), getDataBroker()));
213 String nodeId = "node1";
216 boolean connectingUsingCrossConnect = true;
218 List<Nodes> nodes = new ArrayList<>();
219 nodes.add(ServiceImplementationDataUtils.createNode(nodeId, srcTP, dstTp));
220 ServicePathInput servicePathInput = ServiceImplementationDataUtils.buildServicePathInputs(nodes);
221 Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(this.mappingUtils)
222 .getOpenRoadmVersion("node1");
223 for (ServicePathDirection servicePathDirection : ServicePathDirection.values()) {
224 ServicePathOutput servicePathOutput = deviceRendererService.setupServicePath(servicePathInput,
225 servicePathDirection);
226 Assert.assertTrue(servicePathOutput.isSuccess());
227 String expectedResult = "Roadm-connection successfully created for nodes: ";
228 expectedResult = expectedResult + nodeId;
229 Assert.assertEquals(expectedResult, servicePathOutput.getResult());
230 Assert.assertEquals(1, servicePathOutput.getNodeInterface().size());
231 Assert.assertEquals(nodeId, servicePathOutput.getNodeInterface().get(0).getNodeId());