ConnectionManager proposal
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / connection / listener / HandshakeListenerImpl.java
1 /**
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  * 
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
7  */
8 package org.opendaylight.openflowplugin.impl.connection.listener;
9
10 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
11 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceConnectedHandler;
12 import org.opendaylight.openflowplugin.api.openflow.md.core.HandshakeListener;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 /**
18  * 
19  */
20 public class HandshakeListenerImpl implements HandshakeListener {
21     
22     private static final Logger LOG = LoggerFactory.getLogger(HandshakeListenerImpl.class);
23     
24     private ConnectionContext connectionContext;
25     private DeviceConnectedHandler deviceConnectedHandler;
26
27     /**
28      * @param connectionContext
29      * @param deviceConnectedHandler 
30      */
31     public HandshakeListenerImpl(ConnectionContext connectionContext, DeviceConnectedHandler deviceConnectedHandler) {
32         this.connectionContext = connectionContext;
33         this.deviceConnectedHandler = deviceConnectedHandler;
34     }
35
36     @Override
37     public void onHandshakeSuccessfull(GetFeaturesOutput featureOutput, Short version) {
38         connectionContext.setConnectionState(ConnectionContext.CONNECTION_STATE.WORKING);
39         connectionContext.setFeatures(featureOutput);
40         deviceConnectedHandler.deviceConnected(connectionContext); 
41     }
42
43     @Override
44     public void onHandshakeFailure() {
45         LOG.info("handshake failed: {}", connectionContext.getConnectionAdapter().getRemoteAddress());
46         connectionContext.setConnectionState(ConnectionContext.CONNECTION_STATE.RIP);
47         // TODO ensure that connection is closed
48     }
49 }