Search in sources :

Example 1 with HandshakeStepWrapper

use of org.opendaylight.openflowplugin.impl.connection.HandshakeStepWrapper in project openflowplugin by opendaylight.

the class ConnectionReadyListenerImpl method onConnectionReady.

@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public void onConnectionReady() {
    if (LOG.isDebugEnabled()) {
        LOG.debug("device is connected and ready-to-use (pipeline prepared): {}", connectionContext.getConnectionAdapter().getRemoteAddress());
    }
    if (connectionContext.getConnectionState() == null) {
        synchronized (connectionContext) {
            if (connectionContext.getConnectionState() == null) {
                connectionContext.changeStateToHandshaking();
                HandshakeStepWrapper handshakeStepWrapper = new HandshakeStepWrapper(null, handshakeContext.getHandshakeManager(), connectionContext.getConnectionAdapter());
                final Future<?> handshakeResult = handshakeContext.getHandshakePool().submit(handshakeStepWrapper);
                try {
                    // As we run not in netty thread,
                    // need to remain in sync lock until initial handshake step processed.
                    handshakeResult.get();
                } catch (Exception e) {
                    LOG.error("failed to process onConnectionReady event on device {}, reason {}", connectionContext.getConnectionAdapter().getRemoteAddress(), e);
                    connectionContext.closeConnection(false);
                    handshakeContext.close();
                }
            } else {
                LOG.debug("already touched by hello message from device {} after second check", connectionContext.getConnectionAdapter().getRemoteAddress());
            }
        }
    } else {
        LOG.debug("already touched by hello message from device {} after first check", connectionContext.getConnectionAdapter().getRemoteAddress());
    }
}
Also used : HandshakeStepWrapper(org.opendaylight.openflowplugin.impl.connection.HandshakeStepWrapper)

Example 2 with HandshakeStepWrapper

use of org.opendaylight.openflowplugin.impl.connection.HandshakeStepWrapper in project openflowplugin by opendaylight.

the class OpenflowProtocolListenerInitialImpl method onHelloMessage.

@Override
public void onHelloMessage(final HelloMessage hello) {
    LOG.debug("processing HELLO.xid: {} from device {}", hello.getXid(), connectionContext.getConnectionAdapter().getRemoteAddress());
    final ConnectionContext.CONNECTION_STATE connectionState = connectionContext.getConnectionState();
    if (connectionState == null || ConnectionContext.CONNECTION_STATE.HANDSHAKING.equals(connectionState)) {
        synchronized (connectionContext) {
            if (connectionContext.getConnectionState() == null) {
                // got here before connection ready notification
                connectionContext.changeStateToHandshaking();
            }
            if (checkState(ConnectionContext.CONNECTION_STATE.HANDSHAKING)) {
                final HandshakeStepWrapper handshakeStepWrapper = new HandshakeStepWrapper(hello, handshakeContext.getHandshakeManager(), connectionContext.getConnectionAdapter());
                // use up netty thread
                handshakeStepWrapper.run();
            } else {
                LOG.debug("already out of handshake phase but still received hello message from device {}", connectionContext.getConnectionAdapter().getRemoteAddress());
            }
        }
    } else {
        // TODO: consider disconnecting of bad behaving device
        LOG.warn("Hello message received outside handshake phase:{} ", hello);
        LOG.debug("already touched by onConnectionReady event from device {} (or finished handshake)", connectionContext.getConnectionAdapter().getRemoteAddress());
    }
}
Also used : ConnectionContext(org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext) HandshakeStepWrapper(org.opendaylight.openflowplugin.impl.connection.HandshakeStepWrapper)

Aggregations

HandshakeStepWrapper (org.opendaylight.openflowplugin.impl.connection.HandshakeStepWrapper)2 ConnectionContext (org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext)1