2 * Copyright (c) 2015 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.connection.listener;
10 import com.google.common.base.Objects;
11 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
12 import org.opendaylight.openflowplugin.api.openflow.connection.HandshakeContext;
13 import org.opendaylight.openflowplugin.openflow.md.core.HandshakeStepWrapper;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.*;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
21 public class OpenflowProtocolListenerInitialImpl implements OpenflowProtocolListener {
23 private static final Logger LOG = LoggerFactory.getLogger(OpenflowProtocolListenerInitialImpl.class);
25 private final ConnectionContext connectionContext;
26 private final HandshakeContext handshakeContext;
29 * @param connectionContext
30 * @param handshakeContext
32 public OpenflowProtocolListenerInitialImpl(final ConnectionContext connectionContext,
33 final HandshakeContext handshakeContext) {
34 this.connectionContext = connectionContext;
35 this.handshakeContext = handshakeContext;
39 public void onEchoRequestMessage(final EchoRequestMessage echoRequestMessage) {
40 LOG.debug("echo request received: {}", echoRequestMessage.getXid());
41 EchoReplyInputBuilder builder = new EchoReplyInputBuilder();
42 builder.setVersion(echoRequestMessage.getVersion());
43 builder.setXid(echoRequestMessage.getXid());
44 builder.setData(echoRequestMessage.getData());
46 connectionContext.getConnectionAdapter().echoReply(builder.build());
50 public void onErrorMessage(final ErrorMessage notification) {
55 public void onExperimenterMessage(final ExperimenterMessage notification) {
61 public void onFlowRemovedMessage(final FlowRemovedMessage notification) {
66 public void onHelloMessage(final HelloMessage hello) {
67 LOG.debug("processing HELLO.xid: {}", hello.getXid());
68 if (connectionContext.getConnectionState() == null) {
69 connectionContext.setConnectionState(ConnectionContext.CONNECTION_STATE.HANDSHAKING);
72 if (checkState(ConnectionContext.CONNECTION_STATE.HANDSHAKING)) {
73 final HandshakeStepWrapper handshakeStepWrapper = new HandshakeStepWrapper(
74 hello, handshakeContext.getHandshakeManager(), connectionContext.getConnectionAdapter());
75 handshakeContext.getHandshakePool().submit(handshakeStepWrapper);
77 //TODO: consider disconnecting of bad behaving device
83 public void onMultipartReplyMessage(final MultipartReplyMessage notification) {
88 public void onPacketInMessage(final PacketInMessage notification) {
93 public void onPortStatusMessage(final PortStatusMessage notification) {
98 * @param expectedState
100 protected boolean checkState(final ConnectionContext.CONNECTION_STATE expectedState) {
101 boolean verdict = true;
102 if (! Objects.equal(connectionContext.getConnectionState(), expectedState)) {
104 LOG.info("Expected state: {}, actual state: {}", expectedState,
105 connectionContext.getConnectionState());