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.when;
15 import com.google.common.util.concurrent.Futures;
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.transportpce.common.InstanceIdentifiers;
31 import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
32 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
33 import org.opendaylight.transportpce.pce.service.PathComputationService;
34 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
35 import org.opendaylight.transportpce.servicehandler.catalog.CatalogDataStoreOperations;
36 import org.opendaylight.transportpce.servicehandler.impl.ServicehandlerImpl;
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.listeners.TapiPceNotificationHandler;
43 import org.opendaylight.transportpce.tapi.listeners.TapiRendererNotificationHandler;
44 import org.opendaylight.transportpce.tapi.listeners.TapiServiceNotificationHandler;
45 import org.opendaylight.transportpce.tapi.topology.TopologyUtils;
46 import org.opendaylight.transportpce.tapi.utils.TapiConnectivityDataUtils;
47 import org.opendaylight.transportpce.tapi.utils.TapiContext;
48 import org.opendaylight.transportpce.tapi.utils.TapiInitialORMapping;
49 import org.opendaylight.transportpce.tapi.utils.TapiLink;
50 import org.opendaylight.transportpce.tapi.utils.TapiLinkImpl;
51 import org.opendaylight.transportpce.tapi.utils.TapiTopologyDataUtils;
52 import org.opendaylight.transportpce.test.AbstractTest;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.OrgOpenroadmServiceService;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateInput;
55 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.CreateConnectivityServiceInput;
56 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.CreateConnectivityServiceInputBuilder;
57 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.CreateConnectivityServiceOutput;
58 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.DeleteConnectivityServiceInput;
59 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.DeleteConnectivityServiceInputBuilder;
60 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.DeleteConnectivityServiceOutput;
61 import org.opendaylight.yangtools.yang.common.ErrorType;
62 import org.opendaylight.yangtools.yang.common.RpcResult;
63 import org.slf4j.Logger;
64 import org.slf4j.LoggerFactory;
66 @ExtendWith(MockitoExtension.class)
67 public class TapiConnectivityImplTest extends AbstractTest {
70 private PathComputationService pathComputationService;
72 private RendererServiceOperations rendererServiceOperations;
74 private NotificationPublishService notificationPublishService;
76 private TapiPceNotificationHandler tapipceNotificationHandler;
78 private TapiRendererNotificationHandler tapirendererNotificationHandler;
80 private TapiServiceNotificationHandler tapiserviceNotificationHandler;
82 private PceListener pceListenerImpl;
84 private RendererListener rendererListenerImpl;
86 private NetworkListener networkModelListenerImpl;
88 public CatalogDataStoreOperations catalogDataStoreOperations;
90 private RpcProviderService rpcProviderService;
92 private static final Logger LOG = LoggerFactory.getLogger(TapiConnectivityImplTest.class);
93 private static ServiceDataStoreOperations serviceDataStoreOperations;
94 private static TapiContext tapiContext;
95 private static TopologyUtils topologyUtils;
96 private static ConnectivityUtils connectivityUtils;
97 private static TapiInitialORMapping tapiInitialORMapping;
98 private static NetworkTransactionService networkTransactionService;
99 private static TapiLink tapilink;
100 private ListeningExecutorService executorService;
101 private CountDownLatch endSignal;
102 private static final int NUM_THREADS = 5;
105 void setUp() throws InterruptedException, ExecutionException {
106 executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
107 endSignal = new CountDownLatch(1);
108 // Need to have datastore populated to enable the mapping from TAPI to OR
109 TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
110 TapiTopologyDataUtils.OPENROADM_TOPOLOGY_FILE, InstanceIdentifiers.OVERLAY_NETWORK_II);
111 TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
112 TapiTopologyDataUtils.OPENROADM_NETWORK_FILE, InstanceIdentifiers.UNDERLAY_NETWORK_II);
113 TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
114 TapiTopologyDataUtils.OTN_TOPOLOGY_FILE, InstanceIdentifiers.OTN_NETWORK_II);
115 TopologyDataUtils.writePortmappingFromFileToDatastore(getDataStoreContextUtil(),
116 TapiTopologyDataUtils.PORTMAPPING_FILE);
118 networkTransactionService = new NetworkTransactionImpl(getDataBroker());
119 tapilink = new TapiLinkImpl(networkTransactionService);
120 serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(getDataStoreContextUtil().getDataBroker());
121 tapiContext = new TapiContext(networkTransactionService);
122 topologyUtils = new TopologyUtils(networkTransactionService, getDataStoreContextUtil().getDataBroker(),
124 connectivityUtils = new ConnectivityUtils(serviceDataStoreOperations, new HashMap<>(), tapiContext,
125 networkTransactionService);
126 tapiInitialORMapping = new TapiInitialORMapping(topologyUtils, connectivityUtils,
127 tapiContext, serviceDataStoreOperations);
128 tapiInitialORMapping.performTopoInitialMapping();
129 LOG.info("setup done");
133 void createConnServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
134 OrgOpenroadmServiceService serviceHandler = new ServicehandlerImpl(rpcProviderService, pathComputationService,
135 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
136 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
138 TapiConnectivityImpl tapiConnectivity = new TapiConnectivityImpl(serviceHandler, tapiContext, connectivityUtils,
139 tapipceNotificationHandler, tapirendererNotificationHandler, networkTransactionService);
141 ListenableFuture<RpcResult<CreateConnectivityServiceOutput>> result =
142 tapiConnectivity.createConnectivityService(new CreateConnectivityServiceInputBuilder().build());
143 result.addListener(new Runnable() {
146 endSignal.countDown();
152 RpcResult<CreateConnectivityServiceOutput> rpcResult = result.get();
153 assertEquals(ErrorType.RPC, rpcResult.getErrors().get(0).getErrorType());
157 void createConnServiceShouldBeSuccessfulWhenPerformPCESuccessful()
158 throws ExecutionException, InterruptedException {
159 OrgOpenroadmServiceService serviceHandler = new ServicehandlerImpl(rpcProviderService, pathComputationService,
160 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
161 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
163 CreateConnectivityServiceInput input = TapiConnectivityDataUtils.buildConnServiceCreateInput();
165 when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
167 TapiConnectivityImpl tapiConnectivity = new TapiConnectivityImpl(serviceHandler, tapiContext, connectivityUtils,
168 tapipceNotificationHandler, tapirendererNotificationHandler, networkTransactionService);
169 ListenableFuture<RpcResult<CreateConnectivityServiceOutput>> result =
170 tapiConnectivity.createConnectivityService(input);
171 result.addListener(new Runnable() {
174 endSignal.countDown();
180 RpcResult<CreateConnectivityServiceOutput> rpcResult = result.get();
181 assertTrue(rpcResult.isSuccessful());
185 void deleteConnServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
186 OrgOpenroadmServiceService serviceHandler = new ServicehandlerImpl(rpcProviderService, pathComputationService,
187 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
188 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
190 TapiConnectivityImpl tapiConnectivity = new TapiConnectivityImpl(serviceHandler, tapiContext, connectivityUtils,
191 tapipceNotificationHandler, tapirendererNotificationHandler, networkTransactionService);
193 ListenableFuture<RpcResult<DeleteConnectivityServiceOutput>> result =
194 tapiConnectivity.deleteConnectivityService(new DeleteConnectivityServiceInputBuilder().build());
195 result.addListener(new Runnable() {
198 endSignal.countDown();
204 RpcResult<DeleteConnectivityServiceOutput> rpcResult = result.get();
205 assertEquals(ErrorType.RPC, rpcResult.getErrors().get(0).getErrorType());
209 void deleteConnServiceShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
210 DeleteConnectivityServiceInput input = TapiConnectivityDataUtils.buildConnServiceDeleteInput1();
211 OrgOpenroadmServiceService serviceHandler = new ServicehandlerImpl(rpcProviderService, pathComputationService,
212 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
213 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
215 TapiConnectivityImpl tapiConnectivity = new TapiConnectivityImpl(serviceHandler, tapiContext, connectivityUtils,
216 tapipceNotificationHandler, tapirendererNotificationHandler, networkTransactionService);
217 ListenableFuture<RpcResult<DeleteConnectivityServiceOutput>> result =
218 tapiConnectivity.deleteConnectivityService(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 when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
236 OrgOpenroadmServiceService serviceHandler = new ServicehandlerImpl(rpcProviderService, pathComputationService,
237 rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
238 networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations);
240 TapiConnectivityImpl tapiConnectivity = new TapiConnectivityImpl(serviceHandler, tapiContext, connectivityUtils,
241 tapipceNotificationHandler, tapirendererNotificationHandler, networkTransactionService);
243 ServiceCreateInput createInput = TapiConnectivityDataUtils.buildServiceCreateInput();
244 serviceDataStoreOperations.createService(createInput);
245 tapiContext.updateConnectivityContext(TapiConnectivityDataUtils.createConnService(), new HashMap<>());
247 DeleteConnectivityServiceInput input = TapiConnectivityDataUtils.buildConnServiceDeleteInput();
248 ListenableFuture<RpcResult<DeleteConnectivityServiceOutput>> result =
249 tapiConnectivity.deleteConnectivityService(input);
250 result.addListener(new Runnable() {
253 endSignal.countDown();
259 RpcResult<DeleteConnectivityServiceOutput> rpcResult = result.get();
260 assertTrue(rpcResult.isSuccessful());