2 * Copyright © 2021 Nokia, 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
8 package org.opendaylight.transportpce.tapi.connectivity;
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertTrue;
12 import static org.mockito.ArgumentMatchers.any;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.when;
16 import com.google.common.util.concurrent.ListenableFuture;
17 import com.google.common.util.concurrent.ListeningExecutorService;
18 import com.google.common.util.concurrent.MoreExecutors;
19 import java.util.HashMap;
20 import java.util.concurrent.CountDownLatch;
21 import java.util.concurrent.ExecutionException;
22 import java.util.concurrent.Executors;
23 import org.junit.jupiter.api.BeforeEach;
24 import org.junit.jupiter.api.Test;
25 import org.junit.jupiter.api.extension.ExtendWith;
26 import org.mockito.Mock;
27 import org.mockito.junit.jupiter.MockitoExtension;
28 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
29 import org.opendaylight.mdsal.binding.api.RpcProviderService;
30 import org.opendaylight.mdsal.binding.api.RpcService;
31 import org.opendaylight.transportpce.common.InstanceIdentifiers;
32 import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
33 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
34 import org.opendaylight.transportpce.pce.service.PathComputationService;
35 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
36 import org.opendaylight.transportpce.servicehandler.catalog.CatalogDataStoreOperations;
37 import org.opendaylight.transportpce.servicehandler.listeners.NetworkListener;
38 import org.opendaylight.transportpce.servicehandler.listeners.PceListener;
39 import org.opendaylight.transportpce.servicehandler.listeners.RendererListener;
40 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
41 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl;
42 import org.opendaylight.transportpce.tapi.impl.rpc.CreateConnectivityServiceImpl;
43 import org.opendaylight.transportpce.tapi.impl.rpc.DeleteConnectivityServiceImpl;
44 import org.opendaylight.transportpce.tapi.listeners.TapiPceNotificationHandler;
45 import org.opendaylight.transportpce.tapi.listeners.TapiRendererNotificationHandler;
46 import org.opendaylight.transportpce.tapi.listeners.TapiServiceNotificationHandler;
47 import org.opendaylight.transportpce.tapi.topology.TopologyUtils;
48 import org.opendaylight.transportpce.tapi.utils.TapiConnectivityDataUtils;
49 import org.opendaylight.transportpce.tapi.utils.TapiContext;
50 import org.opendaylight.transportpce.tapi.utils.TapiInitialORMapping;
51 import org.opendaylight.transportpce.tapi.utils.TapiLink;
52 import org.opendaylight.transportpce.tapi.utils.TapiLinkImpl;
53 import org.opendaylight.transportpce.tapi.utils.TapiTopologyDataUtils;
54 import org.opendaylight.transportpce.test.AbstractTest;
55 import org.opendaylight.transportpce.test.utils.TopologyDataUtils;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.configuration.response.common.ConfigurationResponseCommon;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.configuration.response.common.ConfigurationResponseCommonBuilder;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreate;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateInput;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateOutputBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceDelete;
62 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.CreateConnectivityService;
63 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.CreateConnectivityServiceInput;
64 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.CreateConnectivityServiceInputBuilder;
65 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.CreateConnectivityServiceOutput;
66 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.DeleteConnectivityService;
67 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.DeleteConnectivityServiceInput;
68 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.DeleteConnectivityServiceInputBuilder;
69 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.DeleteConnectivityServiceOutput;
70 import org.opendaylight.yangtools.yang.common.ErrorType;
71 import org.opendaylight.yangtools.yang.common.RpcResult;
72 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
73 import org.slf4j.Logger;
74 import org.slf4j.LoggerFactory;
76 @ExtendWith(MockitoExtension.class)
77 public class TapiConnectivityImplTest extends AbstractTest {
80 private PathComputationService pathComputationService;
82 private RendererServiceOperations rendererServiceOperations;
84 private NotificationPublishService notificationPublishService;
86 private TapiPceNotificationHandler tapipceNotificationHandler;
88 private TapiRendererNotificationHandler tapirendererNotificationHandler;
90 private TapiServiceNotificationHandler tapiserviceNotificationHandler;
92 private PceListener pceListenerImpl;
94 private RendererListener rendererListenerImpl;
96 private NetworkListener networkModelListenerImpl;
98 public CatalogDataStoreOperations catalogDataStoreOperations;
100 private RpcProviderService rpcProviderService;
102 private RpcService rpcService;
104 private ServiceCreate serviceCreate;
106 private ServiceDelete serviceDelete;
108 private static final Logger LOG = LoggerFactory.getLogger(TapiConnectivityImplTest.class);
109 private static ServiceDataStoreOperations serviceDataStoreOperations;
110 private static TapiContext tapiContext;
111 private static TopologyUtils topologyUtils;
112 private static ConnectivityUtils connectivityUtils;
113 private static TapiInitialORMapping tapiInitialORMapping;
114 private static NetworkTransactionService networkTransactionService;
115 private static TapiLink tapilink;
116 private ListeningExecutorService executorService;
117 private CountDownLatch endSignal;
118 private static final int NUM_THREADS = 5;
121 void setUp() throws InterruptedException, ExecutionException {
122 executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
123 endSignal = new CountDownLatch(1);
124 // Need to have datastore populated to enable the mapping from TAPI to OR
125 TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
126 TapiTopologyDataUtils.OPENROADM_TOPOLOGY_FILE, InstanceIdentifiers.OVERLAY_NETWORK_II);
127 TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
128 TapiTopologyDataUtils.OPENROADM_NETWORK_FILE, InstanceIdentifiers.UNDERLAY_NETWORK_II);
129 TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
130 TapiTopologyDataUtils.OTN_TOPOLOGY_FILE, InstanceIdentifiers.OTN_NETWORK_II);
131 TopologyDataUtils.writePortmappingFromFileToDatastore(getDataStoreContextUtil(),
132 TapiTopologyDataUtils.PORTMAPPING_FILE);
134 networkTransactionService = new NetworkTransactionImpl(getDataBroker());
135 tapilink = new TapiLinkImpl(networkTransactionService);
136 serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(getDataStoreContextUtil().getDataBroker());
137 tapiContext = new TapiContext(networkTransactionService);
138 topologyUtils = new TopologyUtils(networkTransactionService, getDataStoreContextUtil().getDataBroker(),
140 connectivityUtils = new ConnectivityUtils(serviceDataStoreOperations, new HashMap<>(), tapiContext,
141 networkTransactionService);
142 tapiInitialORMapping = new TapiInitialORMapping(topologyUtils, connectivityUtils,
143 tapiContext, serviceDataStoreOperations);
144 tapiInitialORMapping.performTopoInitialMapping();
145 LOG.info("setup done");
149 void createConnServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
150 when(rpcService.getRpc(any()))
151 .thenReturn(new CreateConnectivityServiceImpl(rpcService, tapiContext, connectivityUtils,
152 tapipceNotificationHandler, tapirendererNotificationHandler));
153 ListenableFuture<RpcResult<CreateConnectivityServiceOutput>> result = rpcService
154 .getRpc(CreateConnectivityService.class).invoke(new CreateConnectivityServiceInputBuilder().build());
155 result.addListener(new Runnable() {
158 endSignal.countDown();
164 RpcResult<CreateConnectivityServiceOutput> rpcResult = result.get();
165 assertEquals(ErrorType.RPC, rpcResult.getErrors().get(0).getErrorType());
169 void createConnServiceShouldBeSuccessfulWhenPerformPCESuccessful()
170 throws ExecutionException, InterruptedException {
171 ConfigurationResponseCommon crc = new ConfigurationResponseCommonBuilder()
172 .setRequestId("request 1")
173 .setResponseCode("OK")
174 .setAckFinalIndicator("requestProcessed").build();
175 when(rpcService.getRpc(any())).thenReturn(serviceCreate);
176 doReturn(RpcResultBuilder
177 .success(new ServiceCreateOutputBuilder()
178 .setConfigurationResponseCommon(crc)
181 .when(serviceCreate).invoke(any());
182 CreateConnectivityServiceInput input = TapiConnectivityDataUtils.buildConnServiceCreateInput();
184 ListenableFuture<RpcResult<CreateConnectivityServiceOutput>> result =
185 new CreateConnectivityServiceImpl(rpcService, tapiContext, connectivityUtils,
186 tapipceNotificationHandler, tapirendererNotificationHandler)
188 LOG.info("INPUT= {}", input.toString());
189 RpcResult<CreateConnectivityServiceOutput> rpcResult = result.get();
190 assertTrue(rpcResult.isSuccessful());
194 void deleteConnServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
195 when(rpcService.getRpc(any()))
196 .thenReturn(new DeleteConnectivityServiceImpl(rpcService, tapiContext, networkTransactionService));
197 ListenableFuture<RpcResult<DeleteConnectivityServiceOutput>> result = rpcService
198 .getRpc(DeleteConnectivityService.class).invoke(new DeleteConnectivityServiceInputBuilder().build());
199 result.addListener(new Runnable() {
202 endSignal.countDown();
208 RpcResult<DeleteConnectivityServiceOutput> rpcResult = result.get();
209 assertEquals(ErrorType.RPC, rpcResult.getErrors().get(0).getErrorType());
213 void deleteConnServiceShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
214 when(rpcService.getRpc(any()))
215 .thenReturn(new DeleteConnectivityServiceImpl(rpcService, tapiContext, networkTransactionService));
216 DeleteConnectivityServiceInput input = TapiConnectivityDataUtils.buildConnServiceDeleteInput1();
217 ListenableFuture<RpcResult<DeleteConnectivityServiceOutput>> result = rpcService
218 .getRpc(DeleteConnectivityService.class).invoke(input);
219 result.addListener(new Runnable() {
222 endSignal.countDown();
228 RpcResult<DeleteConnectivityServiceOutput> rpcResult = result.get();
229 assertEquals(ErrorType.RPC, rpcResult.getErrors().get(0).getErrorType());
233 void deleteConnServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
234 ConfigurationResponseCommon crc = new ConfigurationResponseCommonBuilder()
235 .setRequestId("request 1")
236 .setResponseCode("OK")
237 .setAckFinalIndicator("requestProcessed").build();
238 when(rpcService.getRpc(any())).thenReturn(serviceDelete);
239 doReturn(RpcResultBuilder
240 .success(new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526
241 .ServiceDeleteOutputBuilder()
242 .setConfigurationResponseCommon(crc)
245 .when(serviceDelete).invoke(any());
246 ServiceCreateInput createInput = TapiConnectivityDataUtils.buildServiceCreateInput();
247 serviceDataStoreOperations.createService(createInput);
248 tapiContext.updateConnectivityContext(TapiConnectivityDataUtils.createConnService(), new HashMap<>());
249 DeleteConnectivityServiceInput input = TapiConnectivityDataUtils.buildConnServiceDeleteInput();
250 ListenableFuture<RpcResult<DeleteConnectivityServiceOutput>> result =
251 new DeleteConnectivityServiceImpl(rpcService, tapiContext, networkTransactionService).invoke(input);
252 LOG.debug("RESULT = {}", result.toString());
253 RpcResult<DeleteConnectivityServiceOutput> rpcResult = result.get();
254 assertTrue(rpcResult.isSuccessful());