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 new TapiConnectivityImpl(rpcService, tapiContext, connectivityUtils,
146 tapipceNotificationHandler, tapirendererNotificationHandler, networkTransactionService);
147 LOG.info("setup done");
151 void createConnServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
152 when(rpcService.getRpc(any()))
153 .thenReturn(new CreateConnectivityServiceImpl(rpcService, tapiContext, connectivityUtils,
154 tapipceNotificationHandler, tapirendererNotificationHandler));
155 ListenableFuture<RpcResult<CreateConnectivityServiceOutput>> result = rpcService
156 .getRpc(CreateConnectivityService.class).invoke(new CreateConnectivityServiceInputBuilder().build());
157 result.addListener(new Runnable() {
160 endSignal.countDown();
166 RpcResult<CreateConnectivityServiceOutput> rpcResult = result.get();
167 assertEquals(ErrorType.RPC, rpcResult.getErrors().get(0).getErrorType());
171 void createConnServiceShouldBeSuccessfulWhenPerformPCESuccessful()
172 throws ExecutionException, InterruptedException {
173 ConfigurationResponseCommon crc = new ConfigurationResponseCommonBuilder()
174 .setRequestId("request 1")
175 .setResponseCode("OK")
176 .setAckFinalIndicator("requestProcessed").build();
177 when(rpcService.getRpc(any())).thenReturn(serviceCreate);
178 doReturn(RpcResultBuilder
179 .success(new ServiceCreateOutputBuilder()
180 .setConfigurationResponseCommon(crc)
183 .when(serviceCreate).invoke(any());
184 CreateConnectivityServiceInput input = TapiConnectivityDataUtils.buildConnServiceCreateInput();
186 ListenableFuture<RpcResult<CreateConnectivityServiceOutput>> result =
187 new CreateConnectivityServiceImpl(rpcService, tapiContext, connectivityUtils,
188 tapipceNotificationHandler, tapirendererNotificationHandler)
190 LOG.info("INPUT= {}", input.toString());
191 RpcResult<CreateConnectivityServiceOutput> rpcResult = result.get();
192 assertTrue(rpcResult.isSuccessful());
196 void deleteConnServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
197 when(rpcService.getRpc(any()))
198 .thenReturn(new DeleteConnectivityServiceImpl(rpcService, tapiContext, networkTransactionService));
199 ListenableFuture<RpcResult<DeleteConnectivityServiceOutput>> result = rpcService
200 .getRpc(DeleteConnectivityService.class).invoke(new DeleteConnectivityServiceInputBuilder().build());
201 result.addListener(new Runnable() {
204 endSignal.countDown();
210 RpcResult<DeleteConnectivityServiceOutput> rpcResult = result.get();
211 assertEquals(ErrorType.RPC, rpcResult.getErrors().get(0).getErrorType());
215 void deleteConnServiceShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
216 when(rpcService.getRpc(any()))
217 .thenReturn(new DeleteConnectivityServiceImpl(rpcService, tapiContext, networkTransactionService));
218 DeleteConnectivityServiceInput input = TapiConnectivityDataUtils.buildConnServiceDeleteInput1();
219 ListenableFuture<RpcResult<DeleteConnectivityServiceOutput>> result = rpcService
220 .getRpc(DeleteConnectivityService.class).invoke(input);
221 result.addListener(new Runnable() {
224 endSignal.countDown();
230 RpcResult<DeleteConnectivityServiceOutput> rpcResult = result.get();
231 assertEquals(ErrorType.RPC, rpcResult.getErrors().get(0).getErrorType());
235 void deleteConnServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
236 ConfigurationResponseCommon crc = new ConfigurationResponseCommonBuilder()
237 .setRequestId("request 1")
238 .setResponseCode("OK")
239 .setAckFinalIndicator("requestProcessed").build();
240 when(rpcService.getRpc(any())).thenReturn(serviceDelete);
241 doReturn(RpcResultBuilder
242 .success(new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526
243 .ServiceDeleteOutputBuilder()
244 .setConfigurationResponseCommon(crc)
247 .when(serviceDelete).invoke(any());
248 ServiceCreateInput createInput = TapiConnectivityDataUtils.buildServiceCreateInput();
249 serviceDataStoreOperations.createService(createInput);
250 tapiContext.updateConnectivityContext(TapiConnectivityDataUtils.createConnService(), new HashMap<>());
251 DeleteConnectivityServiceInput input = TapiConnectivityDataUtils.buildConnServiceDeleteInput();
252 ListenableFuture<RpcResult<DeleteConnectivityServiceOutput>> result =
253 new DeleteConnectivityServiceImpl(rpcService, tapiContext, networkTransactionService).invoke(input);
254 LOG.debug("RESULT = {}", result.toString());
255 RpcResult<DeleteConnectivityServiceOutput> rpcResult = result.get();
256 assertTrue(rpcResult.isSuccessful());