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
9 package org.opendaylight.openflowplugin.impl.connection.listener;
11 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
12 import org.opendaylight.openflowplugin.api.openflow.connection.HandshakeContext;
13 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceConnectedHandler;
14 import org.opendaylight.openflowplugin.api.openflow.md.core.HandshakeListener;
15 import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.SessionStatistics;
16 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
24 public class HandshakeListenerImpl implements HandshakeListener {
26 private static final Logger LOG = LoggerFactory.getLogger(HandshakeListenerImpl.class);
28 private ConnectionContext connectionContext;
29 private DeviceConnectedHandler deviceConnectedHandler;
30 private HandshakeContext handshakeContext;
33 * @param connectionContext
34 * @param deviceConnectedHandler
36 public HandshakeListenerImpl(ConnectionContext connectionContext, DeviceConnectedHandler deviceConnectedHandler) {
37 this.connectionContext = connectionContext;
38 this.deviceConnectedHandler = deviceConnectedHandler;
42 public void onHandshakeSuccessfull(GetFeaturesOutput featureOutput, Short version) {
43 LOG.debug("handshake succeeded: {}", connectionContext.getConnectionAdapter().getRemoteAddress());
44 closeHandshakeContext();
45 connectionContext.changeStateToWorking();
46 connectionContext.setFeatures(featureOutput);
47 connectionContext.setNodeId(InventoryDataServiceUtil.nodeIdFromDatapathId(featureOutput.getDatapathId()));
48 deviceConnectedHandler.deviceConnected(connectionContext);
49 SessionStatistics.countEvent(connectionContext.getNodeId().toString(), SessionStatistics.ConnectionStatus.CONNECTION_CREATED);
53 public void onHandshakeFailure() {
54 LOG.debug("handshake failed: {}", connectionContext.getConnectionAdapter().getRemoteAddress());
55 closeHandshakeContext();
56 connectionContext.closeConnection(false);
59 private void closeHandshakeContext() {
61 handshakeContext.close();
62 } catch (Exception e) {
63 LOG.warn("Closing handshake context failed: {}", e.getMessage());
64 LOG.debug("Detail in hanshake context close:", e);
69 public void setHandshakeContext(HandshakeContext handshakeContext) {
70 this.handshakeContext = handshakeContext;