StatisticsManager holds StatisticsContext in ConcurrentHashMap instead of List
[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.openflow.md.util.InventoryDataServiceUtil;
11
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;
18
19 /**
20  *
21  */
22 public class HandshakeListenerImpl implements HandshakeListener {
23
24     private static final Logger LOG = LoggerFactory.getLogger(HandshakeListenerImpl.class);
25
26     private ConnectionContext connectionContext;
27     private DeviceConnectedHandler deviceConnectedHandler;
28
29     /**
30      * @param connectionContext
31      * @param deviceConnectedHandler
32      */
33     public HandshakeListenerImpl(ConnectionContext connectionContext, DeviceConnectedHandler deviceConnectedHandler) {
34         this.connectionContext = connectionContext;
35         this.deviceConnectedHandler = deviceConnectedHandler;
36     }
37
38     @Override
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);
44     }
45
46     @Override
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
51     }
52 }