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.api.openflow.device.handlers.DeviceConnectedHandler;
13 import org.opendaylight.openflowplugin.api.openflow.md.core.HandshakeListener;
14 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
22 public class HandshakeListenerImpl implements HandshakeListener {
24 private static final Logger LOG = LoggerFactory.getLogger(HandshakeListenerImpl.class);
26 private ConnectionContext connectionContext;
27 private DeviceConnectedHandler deviceConnectedHandler;
28 private HandshakeContext handshakeContext;
31 * @param connectionContext
32 * @param deviceConnectedHandler
34 public HandshakeListenerImpl(ConnectionContext connectionContext, DeviceConnectedHandler deviceConnectedHandler) {
35 this.connectionContext = connectionContext;
36 this.deviceConnectedHandler = deviceConnectedHandler;
40 public void onHandshakeSuccessfull(GetFeaturesOutput featureOutput, Short version) {
41 connectionContext.setConnectionState(ConnectionContext.CONNECTION_STATE.WORKING);
42 connectionContext.setFeatures(featureOutput);
43 connectionContext.setNodeId(InventoryDataServiceUtil.nodeIdFromDatapathId(featureOutput.getDatapathId()));
44 deviceConnectedHandler.deviceConnected(connectionContext);
48 public void onHandshakeFailure() {
49 LOG.info("handshake failed: {}", connectionContext.getConnectionAdapter().getRemoteAddress());
50 connectionContext.setConnectionState(ConnectionContext.CONNECTION_STATE.RIP);
52 handshakeContext.close();
53 } catch (Exception e) {
54 LOG.warn("Closing handshake context failed: {}", e.getMessage());
55 LOG.debug("Detail in hanshake context close:", e);
60 public void setHandshakeContext(HandshakeContext handshakeContext) {
61 this.handshakeContext = handshakeContext;