-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
*/
package org.opendaylight.openflowplugin.impl.connection;
+import static org.mockito.ArgumentMatchers.any;
+
import com.google.common.util.concurrent.SettableFuture;
import java.math.BigInteger;
import java.net.InetSocketAddress;
+import java.time.LocalDateTime;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
+import org.mockito.ArgumentMatchers;
import org.mockito.Captor;
-import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.NotificationPublishService;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener;
-import org.opendaylight.openflowplugin.api.OFConstants;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceConnectedHandler;
import org.opendaylight.openflowplugin.impl.util.ThreadPoolLoggingExecutor;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfigBuilder;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
/**
* Test of {@link ConnectionManagerImpl} - lightweight version, using basic ways (TDD).
private ConnectionAdapter connection;
@Mock
private DeviceConnectedHandler deviceConnectedHandler;
+ @Mock
+ private NotificationPublishService notificationPublishService;
@Captor
private ArgumentCaptor<ConnectionReadyListener> connectionReadyListenerAC;
@Captor
private ArgumentCaptor<OpenflowProtocolListener> ofpListenerAC;
+ @Mock
+ DataBroker dataBroker;
- private static final long ECHO_REPLY_TIMEOUT = 500;
- private static final int DEVICE_CONNECTION_RATE_LIMIT_PER_MIN = 0;
+ private static final Uint32 ECHO_REPLY_TIMEOUT = Uint32.valueOf(500);
+ private static final Uint16 DEVICE_CONNECTION_RATE_LIMIT_PER_MIN = Uint16.ZERO;
+ private static final Uint16 DEVICE_CONNECTION_HOLD_TIME_IN_SECONDS = Uint16.valueOf(60);
+ private static final boolean ENABLE_CUSTOM_TRUST_MANAGER = false;
@Before
public void setUp() {
connectionManagerImpl = new ConnectionManagerImpl(new OpenflowProviderConfigBuilder()
.setEchoReplyTimeout(new NonZeroUint32Type(ECHO_REPLY_TIMEOUT))
.setDeviceConnectionRateLimitPerMin(DEVICE_CONNECTION_RATE_LIMIT_PER_MIN)
- .build(), threadPool);
+ .setDeviceConnectionHoldTimeInSeconds(DEVICE_CONNECTION_HOLD_TIME_IN_SECONDS)
+ .setEnableCustomTrustManager(ENABLE_CUSTOM_TRUST_MANAGER)
+ .build(), threadPool, dataBroker, notificationPublishService);
connectionManagerImpl.setDeviceConnectedHandler(deviceConnectedHandler);
final InetSocketAddress deviceAddress = InetSocketAddress.createUnresolved("yahoo", 42);
Mockito.when(connection.getRemoteAddress()).thenReturn(deviceAddress);
Mockito.when(connection.isAlive()).thenReturn(true);
- Mockito.when(connection.barrier(Matchers.<BarrierInput>any()))
+ Mockito.when(connection.barrier(ArgumentMatchers.any()))
.thenReturn(RpcResultBuilder.success(new BarrierOutputBuilder().build()).buildFuture());
}
// prepare void reply (hello rpc output)
final SettableFuture<RpcResult<HelloOutput>> voidResponseFx = SettableFuture.create();
- Mockito.when(connection.hello(Matchers.any(HelloInput.class))).thenReturn(voidResponseFx);
+ Mockito.when(connection.hello(any(HelloInput.class))).thenReturn(voidResponseFx);
// prepare getFeature reply (getFeture rpc output)
final SettableFuture<RpcResult<GetFeaturesOutput>> featureResponseFx =
- SettableFuture.<RpcResult<GetFeaturesOutput>>create();
- Mockito.when(connection.getFeatures(Matchers.any(GetFeaturesInput.class))).thenReturn(featureResponseFx);
+ SettableFuture.create();
+ Mockito.when(connection.getFeatures(any(GetFeaturesInput.class))).thenReturn(featureResponseFx);
// fire handshake
final RpcResult<HelloOutput> helloResponse = RpcResultBuilder.success((HelloOutput) null).build();
voidResponseFx.set(helloResponse);
+ //set dpn last connected time to be before dpn hold time seconds from now
+ connectionManagerImpl.getDeviceConnectionStatusProvider().addDeviceLastConnectionTime(BigInteger.TEN,
+ LocalDateTime.now().minusSeconds(DEVICE_CONNECTION_HOLD_TIME_IN_SECONDS.toJava()));
+
// send hello reply
- final HelloMessage hello = new HelloMessageBuilder().setVersion(OFConstants.OFP_VERSION_1_3).setXid(1L).build();
+ final HelloMessage hello = new HelloMessageBuilder()
+ .setVersion(EncodeConstants.OF_VERSION_1_3)
+ .setXid(Uint32.ONE)
+ .build();
ofpListenerAC.getValue().onHelloMessage(hello);
// deliver getFeature output
Thread.sleep(100L);
final GetFeaturesOutput getFeatureOutput = new GetFeaturesOutputBuilder()
- .setDatapathId(BigInteger.TEN)
- .setVersion(OFConstants.OFP_VERSION_1_3)
- .setXid(2L)
- .setTables((short) 15)
+ .setDatapathId(Uint64.TEN)
+ .setVersion(EncodeConstants.OF_VERSION_1_3)
+ .setXid(Uint32.TWO)
+ .setTables(Uint8.valueOf(15))
.build();
final RpcResult<GetFeaturesOutput> rpcFeaturesOutput = RpcResultBuilder.success(getFeatureOutput).build();
featureResponseFx.set(rpcFeaturesOutput);
Mockito.verify(deviceConnectedHandler,
- Mockito.timeout(500)).deviceConnected(Matchers.any(ConnectionContext.class));
+ Mockito.timeout(500)).deviceConnected(any(ConnectionContext.class));
}
/**
// prepare void reply (hello rpc output)
final SettableFuture<RpcResult<HelloOutput>> voidResponseFx = SettableFuture.create();
- Mockito.when(connection.hello(Matchers.any(HelloInput.class))).thenReturn(voidResponseFx);
+ Mockito.when(connection.hello(any(HelloInput.class))).thenReturn(voidResponseFx);
// prepare getFeature reply (getFeture rpc output)
final SettableFuture<RpcResult<GetFeaturesOutput>> featureResponseFx =
- SettableFuture.<RpcResult<GetFeaturesOutput>>create();
- Mockito.when(connection.getFeatures(Matchers.any(GetFeaturesInput.class))).thenReturn(featureResponseFx);
+ SettableFuture.create();
+ Mockito.when(connection.getFeatures(any(GetFeaturesInput.class))).thenReturn(featureResponseFx);
+ //set dpn last connected time to be before dpn hold time seconds from now
+ connectionManagerImpl.getDeviceConnectionStatusProvider().addDeviceLastConnectionTime(BigInteger.TEN,
+ LocalDateTime.now().minusSeconds(DEVICE_CONNECTION_HOLD_TIME_IN_SECONDS.toJava()));
// fire handshake - send hello reply
- final HelloMessage hello = new HelloMessageBuilder().setVersion(OFConstants.OFP_VERSION_1_3).setXid(1L).build();
+ final HelloMessage hello = new HelloMessageBuilder()
+ .setVersion(EncodeConstants.OF_VERSION_1_3)
+ .setXid(Uint32.ONE)
+ .build();
ofpListenerAC.getValue().onHelloMessage(hello);
// notify about connection ready
// deliver getFeature output
Thread.sleep(100L);
final GetFeaturesOutput getFeatureOutput = new GetFeaturesOutputBuilder()
- .setDatapathId(BigInteger.TEN)
- .setVersion(OFConstants.OFP_VERSION_1_3)
- .setXid(2L)
- .setTables((short) 15)
+ .setDatapathId(Uint64.TEN)
+ .setVersion(EncodeConstants.OF_VERSION_1_3)
+ .setXid(Uint32.TWO)
+ .setTables(Uint8.valueOf(15))
.build();
final RpcResult<GetFeaturesOutput> rpcFeaturesOutput = RpcResultBuilder.success(getFeatureOutput).build();
featureResponseFx.set(rpcFeaturesOutput);
Mockito.verify(deviceConnectedHandler,
- Mockito.timeout(FINAL_STEP_TIMEOUT)).deviceConnected(Matchers.any(ConnectionContext.class));
+ Mockito.timeout(FINAL_STEP_TIMEOUT)).deviceConnected(any(ConnectionContext.class));
}
}