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.openflow.md.util.InventoryDataServiceUtil;
12 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
13 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceConnectedHandler;
14 import org.opendaylight.openflowplugin.api.openflow.md.core.HandshakeListener;
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;
30 * @param connectionContext
31 * @param deviceConnectedHandler
33 public HandshakeListenerImpl(ConnectionContext connectionContext, DeviceConnectedHandler deviceConnectedHandler) {
34 this.connectionContext = connectionContext;
35 this.deviceConnectedHandler = deviceConnectedHandler;
39 public void onHandshakeSuccessfull(GetFeaturesOutput featureOutput, Short version) {
40 connectionContext.setConnectionState(ConnectionContext.CONNECTION_STATE.WORKING);
41 connectionContext.setFeatures(featureOutput);
42 connectionContext.setNodeId(InventoryDataServiceUtil.nodeIdFromDatapathId(featureOutput.getDatapathId()));
43 deviceConnectedHandler.deviceConnected(connectionContext);
47 public void onHandshakeFailure() {
48 LOG.info("handshake failed: {}", connectionContext.getConnectionAdapter().getRemoteAddress());
49 connectionContext.setConnectionState(ConnectionContext.CONNECTION_STATE.RIP);
50 // TODO ensure that connection is closed