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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.api.types.rev150327.OfpRole;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 * Created by Martin Bobak <mbobak@cisco.com> on 27.3.2015.
38 public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider {
40 protected static final Logger LOG = LoggerFactory.getLogger(OpenFlowPluginProviderImpl.class);
42 private DeviceManager deviceManager;
43 private RpcManager rpcManager;
44 private StatisticsManager statisticsManager;
45 private ConnectionManager connectionManager;
46 private BindingAwareBroker bindingAwareBroker;
47 private ProviderContext providerContext;
49 private Collection<SwitchConnectionProvider> switchConnectionProviders;
52 public void onSessionInitiated(final ProviderContext providerContextArg) {
53 providerContext = providerContextArg;
54 connectionManager = new ConnectionManagerImpl();
55 rpcManager = new RpcManagerImpl(providerContext);
56 deviceManager = new DeviceManagerImpl(rpcManager, providerContext.getSALService(DataBroker.class));
57 connectionManager.setDeviceConnectedHandler(deviceManager);
58 //TODO : initialize statistics manager
59 //TODO : initialize translatorLibrary + inject into deviceMngr
60 startSwitchConnections();
64 * @param connectionManager2
66 private void startSwitchConnections() {
67 final List<ListenableFuture<Boolean>> starterChain = new ArrayList<>(switchConnectionProviders.size());
68 for (final SwitchConnectionProvider switchConnectionPrv : switchConnectionProviders) {
69 switchConnectionPrv.setSwitchConnectionHandler(connectionManager);
70 final ListenableFuture<Boolean> isOnlineFuture = switchConnectionPrv.startup();
71 starterChain.add(isOnlineFuture);
74 final ListenableFuture<List<Boolean>> srvStarted = Futures.allAsList(starterChain);
75 Futures.addCallback(srvStarted, new FutureCallback<List<Boolean>>() {
77 public void onSuccess(final List<Boolean> result) {
78 LOG.info("All switchConnectionProviders are up and running ({}).",
82 public void onFailure(final Throwable t) {
83 LOG.warn("Some switchConnectionProviders failed to start.", t);
89 public void setSwitchConnectionProviders(final Collection<SwitchConnectionProvider> switchConnectionProviders) {
90 this.switchConnectionProviders = switchConnectionProviders;
94 public void setRole(final OfpRole role) {
99 public void setBindingAwareBroker(final BindingAwareBroker bindingAwareBroker) {
100 this.bindingAwareBroker = bindingAwareBroker;
105 public void initialize() {
106 Preconditions.checkNotNull(bindingAwareBroker, "missing bindingAwareBroker");
107 bindingAwareBroker.registerProvider(this);
111 public void close() throws Exception {
112 //TODO: close all contexts, switchConnections (, managers)