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.openflow.md.core.session.OFSessionUtil;
18 import org.opendaylight.openflowplugin.openflow.md.queue.MessageSpy;
19 import org.opendaylight.openflowplugin.openflow.md.queue.QueueKeeperLightImpl;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
21 import org.opendaylight.yangtools.yang.binding.DataObject;
24 * basic interconnecting piece between plugin and library
26 public class SwitchConnectionHandlerImpl implements SwitchConnectionHandler {
28 private ScheduledThreadPoolExecutor spyPool;
30 private QueueKeeperLightImpl queueKeeper;
31 private ErrorHandler errorHandler;
32 private MessageSpy<OfHeader, DataObject> messageSpy;
33 private int spyRate = 10;
38 public SwitchConnectionHandlerImpl() {
39 queueKeeper = new QueueKeeperLightImpl();
41 //TODO: implement shutdown invocation upon service stop event
42 spyPool = new ScheduledThreadPoolExecutor(1);
49 queueKeeper.setTranslatorMapping(OFSessionUtil.getTranslatorMap());
50 queueKeeper.setPopListenersMapping(OFSessionUtil.getPopListenerMapping());
51 queueKeeper.setMessageSpy(messageSpy);
55 spyPool.scheduleAtFixedRate(messageSpy, spyRate, spyRate, TimeUnit.SECONDS);
59 public boolean accept(InetAddress address) {
60 // TODO:: add policy derived rules
65 public void onSwitchConnected(ConnectionAdapter connectionAdapter) {
66 ConnectionConductor conductor = ConnectionConductorFactory.createConductor(
67 connectionAdapter, queueKeeper);
68 conductor.setErrorHandler(errorHandler);
72 * @param messageSpy the messageSpy to set
74 public void setMessageSpy(MessageSpy<OfHeader, DataObject> messageSpy) {
75 this.messageSpy = messageSpy;
79 * @param errorHandler the errorHandler to set
81 public void setErrorHandler(ErrorHandler errorHandler) {
82 this.errorHandler = errorHandler;