2 * Copyright (c) 2016 Cisco 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
8 package org.opendaylight.openflowplugin.impl;
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.ArgumentMatchers.eq;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.verify;
14 import static org.mockito.Mockito.when;
16 import com.google.common.util.concurrent.Futures;
17 import java.util.List;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.mockito.Mock;
22 import org.mockito.junit.MockitoJUnitRunner;
23 import org.opendaylight.infrautils.ready.SystemReadyMonitor;
24 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
25 import org.opendaylight.mdsal.binding.api.RpcProviderService;
26 import org.opendaylight.mdsal.binding.api.WriteTransaction;
27 import org.opendaylight.mdsal.common.api.CommitInfo;
28 import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService;
29 import org.opendaylight.mdsal.singleton.api.ClusterSingletonServiceProvider;
30 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
31 import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationProperty;
32 import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService;
33 import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManager;
34 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
35 import org.opendaylight.yangtools.concepts.Registration;
36 import org.opendaylight.yangtools.yang.common.Uint16;
37 import org.opendaylight.yangtools.yang.common.Uint32;
39 @RunWith(MockitoJUnitRunner.class)
40 public class OpenFlowPluginProviderImplTest {
42 PingPongDataBroker dataBroker;
44 RpcProviderService rpcProviderRegistry;
46 NotificationPublishService notificationPublishService;
48 DiagStatusProvider ofPluginDiagstatusProvider;
50 SystemReadyMonitor systemReadyMonitor;
52 WriteTransaction writeTransaction;
54 EntityOwnershipService entityOwnershipService;
56 Registration entityOwnershipListenerRegistration;
58 SwitchConnectionProvider switchConnectionProvider;
60 ClusterSingletonServiceProvider clusterSingletonServiceProvider;
62 ConfigurationService configurationService;
64 MastershipChangeServiceManager mastershipChangeServiceManager;
66 MessageIntelligenceAgency messageIntelligenceAgency;
68 private static final Uint16 THREAD_POOL_MIN_THREADS = Uint16.ONE;
69 private static final Uint16 THREAD_POOL_MAX_THREADS = Uint16.valueOf(32000);
70 private static final Uint32 THREAD_POOL_TIMEOUT = Uint32.valueOf(60);
71 private static final boolean USE_SINGLE_LAYER_SERIALIZATION = false;
72 private static final Uint16 DEVICE_CONNECTION_RATE_LIMIT_PER_MIN = Uint16.ZERO;
73 private static final Uint16 DEVICE_CONNECTION_HOLD_TIME_IN_SECONDS = Uint16.valueOf(60);
77 when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
78 doReturn(CommitInfo.emptyFluentFuture()).when(writeTransaction).commit();
79 when(entityOwnershipService.registerListener(any(), any())).thenReturn(entityOwnershipListenerRegistration);
80 when(switchConnectionProvider.startup()).thenReturn(Futures.immediateFuture(true));
81 when(switchConnectionProvider.shutdown()).thenReturn(Futures.immediateFuture(true));
82 when(configurationService.getProperty(eq(ConfigurationProperty.USE_SINGLE_LAYER_SERIALIZATION.toString()),
83 any())).thenReturn(USE_SINGLE_LAYER_SERIALIZATION);
84 when(configurationService.getProperty(eq(ConfigurationProperty.THREAD_POOL_MIN_THREADS.toString()), any()))
85 .thenReturn(THREAD_POOL_MIN_THREADS);
86 when(configurationService.getProperty(eq(ConfigurationProperty.THREAD_POOL_MAX_THREADS.toString()), any()))
87 .thenReturn(THREAD_POOL_MAX_THREADS);
88 when(configurationService.getProperty(eq(ConfigurationProperty.THREAD_POOL_TIMEOUT.toString()), any()))
89 .thenReturn(THREAD_POOL_TIMEOUT);
90 when(configurationService.getProperty(eq(ConfigurationProperty.DEVICE_CONNECTION_RATE_LIMIT_PER_MIN.toString()),
91 any())).thenReturn(DEVICE_CONNECTION_RATE_LIMIT_PER_MIN);
92 when(configurationService.getProperty(
93 eq(ConfigurationProperty.DEVICE_CONNECTION_HOLD_TIME_IN_SECONDS.toString()), any()))
94 .thenReturn(DEVICE_CONNECTION_HOLD_TIME_IN_SECONDS);
98 public void testInitializeAndClose() {
99 try (var provider = new OpenFlowPluginProviderImpl(configurationService, List.of(switchConnectionProvider),
100 dataBroker, rpcProviderRegistry, notificationPublishService, clusterSingletonServiceProvider,
101 entityOwnershipService, mastershipChangeServiceManager, messageIntelligenceAgency,
102 ofPluginDiagstatusProvider, systemReadyMonitor)) {
103 // Calling the onSystemBootReady() callback
104 provider.onSystemBootReady();
105 verify(switchConnectionProvider).startup();
107 verify(switchConnectionProvider).shutdown();