2 * Copyright (c) 2013 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.openflow.md.core;
11 import java.net.InetAddress;
12 import java.util.concurrent.ScheduledThreadPoolExecutor;
13 import java.util.concurrent.TimeUnit;
15 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
16 import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;
17 import org.opendaylight.openflowplugin.api.openflow.md.core.ConnectionConductor;
18 import org.opendaylight.openflowplugin.api.openflow.md.core.ErrorHandler;
19 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
20 import org.opendaylight.openflowplugin.openflow.md.queue.QueueProcessorLightImpl;
21 import org.opendaylight.openflowplugin.api.openflow.statistics.MessageSpy;
22 import org.opendaylight.yangtools.yang.binding.DataContainer;
25 * basic interconnecting piece between plugin and library
27 public class SwitchConnectionHandlerImpl implements SwitchConnectionHandler {
29 private ScheduledThreadPoolExecutor spyPool;
31 private QueueProcessorLightImpl queueProcessor;
32 private ErrorHandler errorHandler;
33 private MessageSpy<DataContainer> messageSpy;
34 private int spyRate = 10;
39 public SwitchConnectionHandlerImpl() {
40 queueProcessor = new QueueProcessorLightImpl();
42 //TODO: implement shutdown invocation upon service stop event
43 spyPool = new ScheduledThreadPoolExecutor(1);
50 queueProcessor.setTranslatorMapping(OFSessionUtil.getTranslatorMap());
51 queueProcessor.setPopListenersMapping(OFSessionUtil.getPopListenerMapping());
52 queueProcessor.setMessageSpy(messageSpy);
54 queueProcessor.init();
56 spyPool.scheduleAtFixedRate(messageSpy, spyRate, spyRate, TimeUnit.SECONDS);
60 public boolean accept(InetAddress address) {
61 // TODO:: add policy derived rules
66 public void onSwitchConnected(ConnectionAdapter connectionAdapter) {
67 ConnectionConductor conductor = ConnectionConductorFactory.createConductor(
68 connectionAdapter, queueProcessor);
69 conductor.setErrorHandler(errorHandler);
73 * @param messageSpy the messageSpy to set
75 public void setMessageSpy(MessageSpy<DataContainer> messageSpy) {
76 this.messageSpy = messageSpy;
80 * @param errorHandler the errorHandler to set
82 public void setErrorHandler(ErrorHandler errorHandler) {
83 this.errorHandler = errorHandler;