X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fconnection%2Flistener%2FOpenflowProtocolListenerInitialImpl.java;h=d31cef0087f2d84de87cad39ab6d56852e4634e9;hb=b7a5e5d534f1345d75aa998f8d7feee70c0b9d62;hp=fb6cdcb0282033028ac05529287a3b2b4244edb7;hpb=acf2b5630ca4460bac2343bccc72f37da12f6e0d;p=openflowplugin.git diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/listener/OpenflowProtocolListenerInitialImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/listener/OpenflowProtocolListenerInitialImpl.java index fb6cdcb028..d31cef0087 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/listener/OpenflowProtocolListenerInitialImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/listener/OpenflowProtocolListenerInitialImpl.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the @@ -7,11 +7,15 @@ */ package org.opendaylight.openflowplugin.impl.connection.listener; -import com.google.common.base.Objects; +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.MoreExecutors; +import java.util.Objects; import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext; import org.opendaylight.openflowplugin.api.openflow.connection.HandshakeContext; -import org.opendaylight.openflowplugin.openflow.md.core.HandshakeStepWrapper; +import org.opendaylight.openflowplugin.impl.connection.HandshakeStepWrapper; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage; @@ -21,22 +25,21 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OpenflowProtocolListener; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage; +import org.opendaylight.yangtools.yang.common.RpcResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * - */ public class OpenflowProtocolListenerInitialImpl implements OpenflowProtocolListener { - private static final Logger LOG = LoggerFactory.getLogger(OpenflowProtocolListenerInitialImpl.class); private final ConnectionContext connectionContext; private final HandshakeContext handshakeContext; /** - * @param connectionContext - * @param handshakeContext + * Constructor. + * + * @param connectionContext - connection context + * @param handshakeContext - handshake context */ public OpenflowProtocolListenerInitialImpl(final ConnectionContext connectionContext, final HandshakeContext handshakeContext) { @@ -46,15 +49,21 @@ public class OpenflowProtocolListenerInitialImpl implements OpenflowProtocolList @Override public void onEchoRequestMessage(final EchoRequestMessage echoRequestMessage) { - if (LOG.isDebugEnabled()) { - LOG.debug("echo request received: {}", echoRequestMessage.getXid()); - } - EchoReplyInputBuilder builder = new EchoReplyInputBuilder(); - builder.setVersion(echoRequestMessage.getVersion()); - builder.setXid(echoRequestMessage.getXid()); - builder.setData(echoRequestMessage.getData()); + final var xid = echoRequestMessage.getXid(); + LOG.debug("echo request received: {}", xid); + Futures.addCallback(connectionContext.getConnectionAdapter().echoReply( + new EchoReplyInputBuilder().setXid(xid).setData(echoRequestMessage.getData()).build()), + new FutureCallback<>() { + @Override + public void onSuccess(final RpcResult result) { + LOG.debug("echo reply sent: {}", xid); + } - connectionContext.getConnectionAdapter().echoReply(builder.build()); + @Override + public void onFailure(final Throwable cause) { + LOG.debug("echo reply failed: {}", xid, cause); + } + }, MoreExecutors.directExecutor()); } @Override @@ -119,11 +128,13 @@ public class OpenflowProtocolListenerInitialImpl implements OpenflowProtocolList } /** - * @param expectedState + * Check state of the connection context. + * + * @param expectedState - the expected state */ protected boolean checkState(final ConnectionContext.CONNECTION_STATE expectedState) { boolean verdict = true; - if (! Objects.equal(connectionContext.getConnectionState(), expectedState)) { + if (!Objects.equals(connectionContext.getConnectionState(), expectedState)) { verdict = false; LOG.info("Expected state: {}, actual state: {}", expectedState, connectionContext.getConnectionState());