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;
12 import com.google.common.base.Preconditions;
13 import com.google.common.util.concurrent.FutureCallback;
14 import com.google.common.util.concurrent.Futures;
15 import com.google.common.util.concurrent.ListenableFuture;
16 import java.util.ArrayList;
17 import java.util.Collection;
18 import java.util.List;
19 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
20 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
21 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
22 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
23 import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginProvider;
24 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionManager;
25 import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
26 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager;
27 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
28 import org.opendaylight.openflowplugin.impl.connection.ConnectionManagerImpl;
29 import org.opendaylight.openflowplugin.impl.device.DeviceManagerImpl;
30 import org.opendaylight.openflowplugin.impl.rpc.RpcManagerImpl;
31 import org.opendaylight.openflowplugin.impl.statistics.StatisticsManagerImpl;
32 import org.opendaylight.openflowplugin.impl.util.TranslatorLibraryUtil;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.api.types.rev150327.OfpRole;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
38 * Created by Martin Bobak <mbobak@cisco.com> on 27.3.2015.
40 public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider {
42 protected static final Logger LOG = LoggerFactory.getLogger(OpenFlowPluginProviderImpl.class);
44 private DeviceManager deviceManager;
45 private RpcManager rpcManager;
46 private StatisticsManager statisticsManager;
47 private ConnectionManager connectionManager;
48 private BindingAwareBroker bindingAwareBroker;
49 private ProviderContext providerContext;
51 private Collection<SwitchConnectionProvider> switchConnectionProviders;
54 public void onSessionInitiated(final ProviderContext providerContextArg) {
55 providerContext = providerContextArg;
57 connectionManager = new ConnectionManagerImpl();
58 deviceManager = new DeviceManagerImpl(providerContext.getSALService(DataBroker.class));
59 statisticsManager = new StatisticsManagerImpl();
60 rpcManager = new RpcManagerImpl(providerContext);
62 connectionManager.setDeviceConnectedHandler(deviceManager);
63 deviceManager.setDeviceInitializationPhaseHandler(statisticsManager);
64 statisticsManager.setDeviceInitializationPhaseHandler(rpcManager);
65 rpcManager.setDeviceInitializationPhaseHandler(deviceManager);
67 TranslatorLibraryUtil.setBasicTranslatorLibrary(deviceManager);
68 startSwitchConnections();
71 private void startSwitchConnections() {
72 final List<ListenableFuture<Boolean>> starterChain = new ArrayList<>(switchConnectionProviders.size());
73 for (final SwitchConnectionProvider switchConnectionPrv : switchConnectionProviders) {
74 switchConnectionPrv.setSwitchConnectionHandler(connectionManager);
75 final ListenableFuture<Boolean> isOnlineFuture = switchConnectionPrv.startup();
76 starterChain.add(isOnlineFuture);
79 final ListenableFuture<List<Boolean>> srvStarted = Futures.allAsList(starterChain);
80 Futures.addCallback(srvStarted, new FutureCallback<List<Boolean>>() {
82 public void onSuccess(final List<Boolean> result) {
83 LOG.info("All switchConnectionProviders are up and running ({}).",
88 public void onFailure(final Throwable t) {
89 LOG.warn("Some switchConnectionProviders failed to start.", t);
95 public void setSwitchConnectionProviders(final Collection<SwitchConnectionProvider> switchConnectionProviders) {
96 this.switchConnectionProviders = switchConnectionProviders;
100 public void setRole(final OfpRole role) {
105 public void setBindingAwareBroker(final BindingAwareBroker bindingAwareBroker) {
106 this.bindingAwareBroker = bindingAwareBroker;
111 public void initialize() {
112 Preconditions.checkNotNull(bindingAwareBroker, "missing bindingAwareBroker");
113 bindingAwareBroker.registerProvider(this);
117 public void close() throws Exception {
118 //TODO: close all contexts, switchConnections (, managers)