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;
11 import java.net.InetAddress;
12 import java.util.concurrent.ThreadPoolExecutor;
13 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
14 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener;
15 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
16 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionManager;
17 import org.opendaylight.openflowplugin.api.openflow.connection.HandshakeContext;
18 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceConnectedHandler;
19 import org.opendaylight.openflowplugin.api.openflow.md.core.ConnectionConductor;
20 import org.opendaylight.openflowplugin.api.openflow.md.core.HandshakeListener;
21 import org.opendaylight.openflowplugin.api.openflow.md.core.HandshakeManager;
22 import org.opendaylight.openflowplugin.impl.connection.listener.ConnectionReadyListenerImpl;
23 import org.opendaylight.openflowplugin.impl.connection.listener.HandshakeListenerImpl;
24 import org.opendaylight.openflowplugin.impl.connection.listener.OpenflowProtocolListenerInitialImpl;
25 import org.opendaylight.openflowplugin.impl.connection.listener.SystemNotificationsListenerImpl;
26 import org.opendaylight.openflowplugin.openflow.md.core.ErrorHandlerSimpleImpl;
27 import org.opendaylight.openflowplugin.openflow.md.core.HandshakeManagerImpl;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OpenflowProtocolListener;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SystemNotificationsListener;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
36 public class ConnectionManagerImpl implements ConnectionManager {
38 private static final Logger LOG = LoggerFactory.getLogger(ConnectionManagerImpl.class);
39 private static final boolean BITMAP_NEGOTIATION_ENABLED = true;
40 private DeviceConnectedHandler deviceConnectedHandler;
41 private final long echoReplyTimeout;
42 private final ThreadPoolExecutor threadPool;
44 public ConnectionManagerImpl(long echoReplyTimeout, final ThreadPoolExecutor threadPool) {
45 this.echoReplyTimeout = echoReplyTimeout;
46 this.threadPool = threadPool;
50 public void onSwitchConnected(final ConnectionAdapter connectionAdapter) {
51 LOG.trace("prepare connection context");
52 final ConnectionContext connectionContext = new ConnectionContextImpl(connectionAdapter);
54 HandshakeListener handshakeListener = new HandshakeListenerImpl(connectionContext, deviceConnectedHandler);
55 final HandshakeManager handshakeManager = createHandshakeManager(connectionAdapter, handshakeListener);
57 LOG.trace("prepare handshake context");
58 HandshakeContext handshakeContext = new HandshakeContextImpl(threadPool, handshakeManager);
59 handshakeListener.setHandshakeContext(handshakeContext);
60 connectionContext.setHandshakeContext(handshakeContext);
62 LOG.trace("prepare connection listeners");
63 final ConnectionReadyListener connectionReadyListener = new ConnectionReadyListenerImpl(
64 connectionContext, handshakeContext);
65 connectionAdapter.setConnectionReadyListener(connectionReadyListener);
67 final OpenflowProtocolListener ofMessageListener =
68 new OpenflowProtocolListenerInitialImpl(connectionContext, handshakeContext);
69 connectionAdapter.setMessageListener(ofMessageListener);
71 final SystemNotificationsListener systemListener = new SystemNotificationsListenerImpl(connectionContext, echoReplyTimeout, threadPool);
72 connectionAdapter.setSystemListener(systemListener);
74 LOG.trace("connection ballet finished");
78 * @param connectionAdapter
79 * @param handshakeListener
82 private HandshakeManager createHandshakeManager(final ConnectionAdapter connectionAdapter,
83 final HandshakeListener handshakeListener) {
84 HandshakeManagerImpl handshakeManager = new HandshakeManagerImpl(connectionAdapter,
85 ConnectionConductor.versionOrder.get(0),
86 ConnectionConductor.versionOrder);
87 handshakeManager.setUseVersionBitmap(BITMAP_NEGOTIATION_ENABLED);
88 handshakeManager.setHandshakeListener(handshakeListener);
89 handshakeManager.setErrorHandler(new ErrorHandlerSimpleImpl());
91 return handshakeManager;
95 public boolean accept(final InetAddress switchAddress) {
96 // TODO add connection accept logic based on address
101 public void setDeviceConnectedHandler(final DeviceConnectedHandler deviceConnectedHandler) {
102 this.deviceConnectedHandler = deviceConnectedHandler;