use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage in project openflowplugin by opendaylight.
the class MultipartRequestOnTheFlyCallbackTest method testOnSuccessWithNotMultiNoMultipart.
@Test
public void testOnSuccessWithNotMultiNoMultipart() throws Exception {
final HelloMessage mockedHelloMessage = mock(HelloMessage.class);
multipartRequestOnTheFlyCallback.onSuccess(mockedHelloMessage);
final RpcResult<List<MultipartReply>> expectedRpcResult = RpcResultBuilder.<List<MultipartReply>>failed().withError(RpcError.ErrorType.APPLICATION, String.format("Unexpected response type received: %s.", mockedHelloMessage.getClass())).build();
final RpcResult<List<MultipartReply>> actualResult = dummyRequestContext.getFuture().get();
assertNotNull(actualResult.getErrors());
assertEquals(1, actualResult.getErrors().size());
final RpcError actualError = actualResult.getErrors().iterator().next();
assertEquals(actualError.getMessage(), String.format("Unexpected response type received: %s.", mockedHelloMessage.getClass()));
assertEquals(actualError.getErrorType(), RpcError.ErrorType.APPLICATION);
assertEquals(expectedRpcResult.getResult(), actualResult.getResult());
assertEquals(expectedRpcResult.isSuccessful(), actualResult.isSuccessful());
Mockito.verify(mockedDeviceContext, Mockito.never()).writeToTransaction(Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.<InstanceIdentifier>any(), Matchers.<DataObject>any());
Mockito.verify(mockedDeviceContext).submitTransaction();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage in project openflowplugin by opendaylight.
the class OpenflowProtocolListenerFullImplTest method testOnHelloMessage.
/**
* Test method for
* {@link OpenflowProtocolListenerFullImpl#onHelloMessage(
* org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage)}.
*/
@Test
public void testOnHelloMessage() {
HelloMessage helloMessage = new HelloMessageBuilder().setVersion(OFConstants.OFP_VERSION_1_3).setXid(xid).build();
ofProtocolListener.onHelloMessage(helloMessage);
Mockito.verify(connectionAdapter).getRemoteAddress();
Mockito.verify(connectionAdapter).disconnect();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage in project openflowplugin by opendaylight.
the class HandshakeManagerImplTest method testVersionNegotiationNoCommonVersionInBitmapSwitchStarts.
/**
* Test of version negotiation Where bitmap version {0x05,0x02}.
*/
@Test
public void testVersionNegotiationNoCommonVersionInBitmapSwitchStarts() throws Exception {
LOG.debug("testVersionNegotiationNoCommonVersionInBitmap-ss");
Short version = (short) 0x05;
expectedErrors = 1;
handshakeManager.setUseVersionBitmap(true);
HelloMessageBuilder helloMessage = createHelloMessage(version, helloXid);
addVersionBitmap(Lists.newArrayList((short) 0x05, (short) 0x02), helloMessage);
handshakeManager.shake(null);
handshakeManager.shake(helloMessage.build());
Mockito.verify(handshakeListener, Mockito.never()).onHandshakeSuccessful(Matchers.any(GetFeaturesOutput.class), Matchers.anyShort());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage in project openflowplugin by opendaylight.
the class ConnectionManagerImplTest method testOnSwitchConnected1.
/**
* Test method for
* {@link org.opendaylight.openflowplugin.impl.connection.ConnectionManagerImpl#onSwitchConnected(
* org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter)}.
* invoking onConnectionReady first, scenario:
* <ol>
* <li>send hello to device (rpc with void output)</li>
* <li>receive hello from device (notification)</li>
* <li>send getFeature to device (rpc with getFeatureOutput)</li>
* <li>wait for rpc to finish with getFeatureOutput</li>
* </ol>
*
* @throws InterruptedException - interrupted exception
*/
@Test
public void testOnSwitchConnected1() throws Exception {
connectionManagerImpl.onSwitchConnected(connection);
Mockito.verify(connection).setConnectionReadyListener(connectionReadyListenerAC.capture());
Mockito.verify(connection).setMessageListener(ofpListenerAC.capture());
// prepare void reply (hello rpc output)
final SettableFuture<RpcResult<Void>> voidResponseFx = SettableFuture.<RpcResult<Void>>create();
Mockito.when(connection.hello(Matchers.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);
// fire handshake
connectionReadyListenerAC.getValue().onConnectionReady();
// deliver hello send output (void)
Thread.sleep(100L);
final RpcResult<Void> helloResponse = RpcResultBuilder.success((Void) null).build();
voidResponseFx.set(helloResponse);
// send hello reply
final HelloMessage hello = new HelloMessageBuilder().setVersion(OFConstants.OFP_VERSION_1_3).setXid(1L).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).build();
final RpcResult<GetFeaturesOutput> rpcFeaturesOutput = RpcResultBuilder.success(getFeatureOutput).build();
featureResponseFx.set(rpcFeaturesOutput);
Mockito.verify(deviceConnectedHandler, Mockito.timeout(500)).deviceConnected(Matchers.any(ConnectionContext.class));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage in project openflowplugin by opendaylight.
the class ConnectionManagerImplTest method testOnSwitchConnected2.
/**
* Test method for
* {@link org.opendaylight.openflowplugin.impl.connection.ConnectionManagerImpl#onSwitchConnected(
* org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter)}.
* invoking onHelloMessage, scenario:
* <ol>
* <li>receive hello from device (notification)</li>
* <li>send hello to device (rpc with void output)</li>
* <li>send getFeature to device (rpc with getFeatureOutput)</li>
* <li>wait for rpc to finish with getFeatureOutput</li>
* </ol>
*
* @throws InterruptedException - interrupted exception
*/
@Test
public void testOnSwitchConnected2() throws Exception {
connectionManagerImpl.onSwitchConnected(connection);
Mockito.verify(connection).setConnectionReadyListener(connectionReadyListenerAC.capture());
Mockito.verify(connection).setMessageListener(ofpListenerAC.capture());
// prepare void reply (hello rpc output)
final SettableFuture<RpcResult<Void>> voidResponseFx = SettableFuture.<RpcResult<Void>>create();
Mockito.when(connection.hello(Matchers.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);
// fire handshake - send hello reply
final HelloMessage hello = new HelloMessageBuilder().setVersion(OFConstants.OFP_VERSION_1_3).setXid(1L).build();
ofpListenerAC.getValue().onHelloMessage(hello);
// notify about connection ready
connectionReadyListenerAC.getValue().onConnectionReady();
// deliver hello send output (void)
Thread.sleep(100L);
final RpcResult<Void> helloResponse = RpcResultBuilder.success((Void) null).build();
voidResponseFx.set(helloResponse);
// 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).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));
}
Aggregations