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 org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
11 import org.opendaylight.openflowplugin.api.openflow.connection.HandshakeContext;
12 import org.opendaylight.openflowplugin.openflow.md.core.HandshakeStepWrapper;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OpenflowProtocolListener;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 import com.google.common.base.Objects;
30 public class OpenflowProtocolListenerImpl implements OpenflowProtocolListener {
32 private static final Logger LOG = LoggerFactory.getLogger(OpenflowProtocolListenerImpl.class);
34 private ConnectionContext connectionContext;
35 private HandshakeContext handshakeContext;
38 * @param connectionContext
39 * @param handshakeContext
41 public OpenflowProtocolListenerImpl(ConnectionContext connectionContext,
42 HandshakeContext handshakeContext) {
43 this.connectionContext = connectionContext;
44 this.handshakeContext = handshakeContext;
48 public void onEchoRequestMessage(EchoRequestMessage notification) {
49 // TODO Auto-generated method stub
54 public void onErrorMessage(ErrorMessage notification) {
55 // TODO Auto-generated method stub
60 public void onExperimenterMessage(ExperimenterMessage notification) {
61 // TODO Auto-generated method stub
66 public void onFlowRemovedMessage(FlowRemovedMessage notification) {
67 // TODO Auto-generated method stub
72 public void onHelloMessage(HelloMessage hello) {
73 LOG.debug("processing HELLO.xid: {}", hello.getXid());
74 if (connectionContext.getConnectionState() == null) {
75 connectionContext.setConnectionState(ConnectionContext.CONNECTION_STATE.HANDSHAKING);
78 if (checkState(ConnectionContext.CONNECTION_STATE.HANDSHAKING)) {
79 HandshakeStepWrapper handshakeStepWrapper = new HandshakeStepWrapper(
80 hello, handshakeContext.getHandshakeManager(), connectionContext.getConnectionAdapter());
81 handshakeContext.getHandshakePool().submit(handshakeStepWrapper);
83 //TODO: consider disconnecting of bad behaving device
89 public void onMultipartReplyMessage(MultipartReplyMessage notification) {
90 // TODO Auto-generated method stub
95 public void onPacketInMessage(PacketInMessage notification) {
96 // TODO Auto-generated method stub
101 public void onPortStatusMessage(PortStatusMessage notification) {
102 // TODO Auto-generated method stub
107 * @param expectedState
109 protected boolean checkState(ConnectionContext.CONNECTION_STATE expectedState) {
110 boolean verdict = true;
111 if (! Objects.equal(connectionContext.getConnectionState(), expectedState)) {
113 LOG.info("Expected state: {}, actual state: {}", expectedState,
114 connectionContext.getConnectionState());