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.collect.Lists;
17 import com.google.common.util.concurrent.Futures;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.mockito.Matchers;
22 import org.mockito.Mock;
23 import org.mockito.junit.MockitoJUnitRunner;
24 import org.opendaylight.infrautils.ready.SystemReadyMonitor;
25 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
26 import org.opendaylight.mdsal.binding.api.RpcProviderService;
27 import org.opendaylight.mdsal.binding.api.WriteTransaction;
28 import org.opendaylight.mdsal.common.api.CommitInfo;
29 import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipListenerRegistration;
30 import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService;
31 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
32 import org.opendaylight.openflowjava.protocol.api.connection.OpenflowDiagStatusProvider;
33 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
34 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProviderList;
35 import org.opendaylight.openflowplugin.api.openflow.FlowGroupCacheManager;
36 import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationProperty;
37 import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService;
38 import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManager;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.sm.control.rev150812.StatisticsManagerControlService;
40 import org.opendaylight.yangtools.concepts.ObjectRegistration;
41 import org.opendaylight.yangtools.yang.common.Uint16;
42 import org.opendaylight.yangtools.yang.common.Uint32;
44 @RunWith(MockitoJUnitRunner.class)
45 public class OpenFlowPluginProviderImplTest {
48 PingPongDataBroker dataBroker;
51 RpcProviderService rpcProviderRegistry;
54 NotificationPublishService notificationPublishService;
57 OpenflowDiagStatusProvider ofPluginDiagstatusProvider;
60 SystemReadyMonitor systemReadyMonitor;
63 WriteTransaction writeTransaction;
66 EntityOwnershipService entityOwnershipService;
69 EntityOwnershipListenerRegistration entityOwnershipListenerRegistration;
72 ObjectRegistration<StatisticsManagerControlService> controlServiceRegistration;
75 SwitchConnectionProvider switchConnectionProvider;
78 ClusterSingletonServiceProvider clusterSingletonServiceProvider;
81 ConfigurationService configurationService;
84 MastershipChangeServiceManager mastershipChangeServiceManager;
87 FlowGroupCacheManager flowGroupCacheManager;
89 private static final int RPC_REQUESTS_QUOTA = 500;
90 private static final long GLOBAL_NOTIFICATION_QUOTA = 131072;
91 private static final Uint16 THREAD_POOL_MIN_THREADS = Uint16.ONE;
92 private static final int THREAD_POOL_MAX_THREADS = 32000;
93 private static final Uint32 THREAD_POOL_TIMEOUT = Uint32.valueOf(60);
94 private static final long BASIC_TIMER_DELAY = 1L;
95 private static final boolean USE_SINGLE_LAYER_SERIALIZATION = false;
96 private static final Uint16 DEVICE_CONNECTION_RATE_LIMIT_PER_MIN = Uint16.ZERO;
97 private static final Uint16 DEVICE_CONNECTION_HOLD_TIME_IN_SECONDS = Uint16.valueOf(60);
100 public void setUp() {
101 when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
102 doReturn(CommitInfo.emptyFluentFuture()).when(writeTransaction).commit();
103 when(entityOwnershipService.registerListener(any(), any())).thenReturn(entityOwnershipListenerRegistration);
104 when(rpcProviderRegistry.registerRpcImplementation(eq(StatisticsManagerControlService.class), any()))
105 .thenReturn(controlServiceRegistration);
106 when(switchConnectionProvider.startup()).thenReturn(Futures.immediateFuture(true));
107 when(switchConnectionProvider.shutdown()).thenReturn(Futures.immediateFuture(true));
108 when(configurationService.getProperty(eq(ConfigurationProperty.USE_SINGLE_LAYER_SERIALIZATION.toString()),
109 any())).thenReturn(USE_SINGLE_LAYER_SERIALIZATION);
110 when(configurationService.getProperty(eq(ConfigurationProperty.THREAD_POOL_MIN_THREADS.toString()), any()))
111 .thenReturn(THREAD_POOL_MIN_THREADS);
112 when(configurationService.getProperty(eq(ConfigurationProperty.THREAD_POOL_MAX_THREADS.toString()), any()))
113 .thenReturn(THREAD_POOL_MAX_THREADS);
114 when(configurationService.getProperty(eq(ConfigurationProperty.THREAD_POOL_TIMEOUT.toString()), any()))
115 .thenReturn(THREAD_POOL_TIMEOUT);
116 when(configurationService.getProperty(eq(ConfigurationProperty.DEVICE_CONNECTION_RATE_LIMIT_PER_MIN.toString()),
117 any())).thenReturn(DEVICE_CONNECTION_RATE_LIMIT_PER_MIN);
118 when(configurationService.getProperty(
119 Matchers.eq(ConfigurationProperty.DEVICE_CONNECTION_HOLD_TIME_IN_SECONDS.toString()),
120 Matchers.any())).thenReturn(DEVICE_CONNECTION_HOLD_TIME_IN_SECONDS);
124 public void testInitializeAndClose() {
125 final OpenFlowPluginProviderImpl provider = new OpenFlowPluginProviderImpl(
126 configurationService,
127 new SwitchConnectionProviderList(Lists.newArrayList(switchConnectionProvider)),
130 notificationPublishService,
131 clusterSingletonServiceProvider,
132 entityOwnershipService,
133 mastershipChangeServiceManager,
134 ofPluginDiagstatusProvider,
136 flowGroupCacheManager);
138 provider.initialize();
139 // Calling the onSystemBootReady() callback
140 provider.onSystemBootReady();
141 verify(switchConnectionProvider).startup();
143 verify(switchConnectionProvider).shutdown();