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 com.google.common.util.concurrent.ListeningExecutorService;
12 import com.google.common.util.concurrent.MoreExecutors;
13 import java.util.concurrent.Executors;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
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.ResponseCodes;
20 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
21 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
22 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
23 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
24 import org.opendaylight.transportpce.common.mapping.PortMapping;
25 import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
26 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
27 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
28 import org.opendaylight.transportpce.renderer.NetworkModelWavelengthService;
29 import org.opendaylight.transportpce.renderer.NetworkModelWavelengthServiceImpl;
30 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
31 import org.opendaylight.transportpce.renderer.stub.MountPointServiceStub;
32 import org.opendaylight.transportpce.renderer.stub.MountPointStub;
33 import org.opendaylight.transportpce.renderer.stub.OlmServiceStub;
34 import org.opendaylight.transportpce.renderer.utils.MountPointUtils;
35 import org.opendaylight.transportpce.renderer.utils.ServiceDataUtils;
36 import org.opendaylight.transportpce.test.AbstractTest;
37 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestInput;
38 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestOutput;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.OlmService;
43 public class RendererServiceOperationsImplTest extends AbstractTest {
45 private static final int NUMBER_OF_THREADS = 4;
46 private MountPointService mountPointService;
47 private DeviceTransactionManager deviceTransactionManager;
48 private RendererServiceOperationsImpl rendererServiceOperations;
49 private OpenRoadmInterfaces openRoadmInterfaces;
50 private DeviceRendererService deviceRenderer;
51 private PortMapping portMapping;
52 private OpenRoadmInterfaceFactory openRoadmInterfaceFactory;
53 private CrossConnect crossConnect;
54 private OlmService olmService;
55 private ListeningExecutorService executor;
56 private NetworkModelWavelengthService networkModelWavelengthService;
58 private void setMountPoint(MountPoint mountPoint) {
59 this.mountPointService = new MountPointServiceStub(mountPoint);
60 this.deviceTransactionManager = new DeviceTransactionManagerImpl(this.mountPointService, 3000);
61 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl(this.deviceTransactionManager);
62 this.portMapping = new PortMappingImpl(this.getDataBroker(), this.deviceTransactionManager,
64 this.openRoadmInterfaceFactory = new OpenRoadmInterfaceFactory(portMapping,
66 this.crossConnect = new CrossConnectImpl(this.deviceTransactionManager);
67 this.deviceRenderer = new DeviceRendererServiceImpl(this.getDataBroker(),
68 this.deviceTransactionManager, openRoadmInterfaceFactory, openRoadmInterfaces, crossConnect);
73 setMountPoint(new MountPointStub(getDataBroker()));
74 this.olmService = new OlmServiceStub();
75 this.executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUMBER_OF_THREADS));
76 this.networkModelWavelengthService = new NetworkModelWavelengthServiceImpl(getDataBroker());
77 this.rendererServiceOperations = new RendererServiceOperationsImpl(this.deviceRenderer, this.olmService,
78 getDataBroker(), this.networkModelWavelengthService);
84 public void serviceImplementationTerminationPointAsResourceTtp() {
86 ServiceImplementationRequestInput input = ServiceDataUtils
87 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.TTP_TOKEN);
88 writePortMapping(input, OpenRoadmInterfacesImpl.TTP_TOKEN);
89 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input);
90 Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
95 public void serviceImplementationTerminationPointAsResourcePp() {
97 ServiceImplementationRequestInput input = ServiceDataUtils
98 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.PP_TOKEN);
99 writePortMapping(input, OpenRoadmInterfacesImpl.PP_TOKEN);
100 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input);
101 Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
106 public void serviceImplementationTerminationPointAsResourceNetwork() {
108 ServiceImplementationRequestInput input = ServiceDataUtils
109 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN);
110 writePortMapping(input, OpenRoadmInterfacesImpl.NETWORK_TOKEN);
111 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input);
112 Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
117 public void serviceImplementationTerminationPointAsResourceClient() {
118 ServiceImplementationRequestInput input = ServiceDataUtils
119 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.CLIENT_TOKEN);
120 writePortMapping(input, OpenRoadmInterfacesImpl.CLIENT_TOKEN);
121 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input);
122 Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
126 public void serviceImplementationTerminationPointAsResourceNoMapping() {
127 String[] interfaceTokens = {
128 OpenRoadmInterfacesImpl.NETWORK_TOKEN,
129 OpenRoadmInterfacesImpl.CLIENT_TOKEN,
130 OpenRoadmInterfacesImpl.TTP_TOKEN,
131 OpenRoadmInterfacesImpl.PP_TOKEN
133 for (String tpToken : interfaceTokens) {
134 ServiceImplementationRequestInput input = ServiceDataUtils
135 .buildServiceImplementationRequestInputTerminationPointResource(tpToken);
136 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input);
137 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
138 result.getConfigurationResponseCommon().getResponseCode());
142 private void writePortMapping(ServiceImplementationRequestInput input, String tpToken) {
143 MountPointUtils.writeMapping(
144 input.getServiceAEnd().getNodeId(),
145 input.getServiceAEnd().getNodeId() + "-" + tpToken,
146 this.deviceTransactionManager
148 MountPointUtils.writeMapping(
149 input.getServiceZEnd().getNodeId(),
150 input.getServiceZEnd().getNodeId() + "-" + tpToken,
151 this.deviceTransactionManager
156 public void serviceImplementationLinkAsResource() {
157 ServiceImplementationRequestInput input = ServiceDataUtils.buildServiceImplementationRequestInputLinkResource();
158 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input);
159 Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
163 public void serviceImplementtionInvalidResource() {
165 ServiceImplementationRequestInput input = ServiceDataUtils
166 .buildServiceImplementationRequestInputInvalidResource();
167 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input);
168 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());