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;
52 private Long rpcRequestsQuota;
54 public OpenFlowPluginProviderImpl(final Long rpcRequestsQuota) {
55 this.rpcRequestsQuota = rpcRequestsQuota;
59 public void onSessionInitiated(final ProviderContext providerContextArg) {
60 providerContext = providerContextArg;
62 connectionManager = new ConnectionManagerImpl();
63 deviceManager = new DeviceManagerImpl(providerContext.getSALService(DataBroker.class));
64 statisticsManager = new StatisticsManagerImpl();
65 rpcManager = new RpcManagerImpl(providerContext, rpcRequestsQuota);
67 connectionManager.setDeviceConnectedHandler(deviceManager);
68 deviceManager.setDeviceInitializationPhaseHandler(statisticsManager);
69 statisticsManager.setDeviceInitializationPhaseHandler(rpcManager);
70 rpcManager.setDeviceInitializationPhaseHandler(deviceManager);
72 TranslatorLibraryUtil.setBasicTranslatorLibrary(deviceManager);
73 startSwitchConnections();
76 private void startSwitchConnections() {
77 final List<ListenableFuture<Boolean>> starterChain = new ArrayList<>(switchConnectionProviders.size());
78 for (final SwitchConnectionProvider switchConnectionPrv : switchConnectionProviders) {
79 switchConnectionPrv.setSwitchConnectionHandler(connectionManager);
80 final ListenableFuture<Boolean> isOnlineFuture = switchConnectionPrv.startup();
81 starterChain.add(isOnlineFuture);
84 final ListenableFuture<List<Boolean>> srvStarted = Futures.allAsList(starterChain);
85 Futures.addCallback(srvStarted, new FutureCallback<List<Boolean>>() {
87 public void onSuccess(final List<Boolean> result) {
88 LOG.info("All switchConnectionProviders are up and running ({}).",
93 public void onFailure(final Throwable t) {
94 LOG.warn("Some switchConnectionProviders failed to start.", t);
100 public void setSwitchConnectionProviders(final Collection<SwitchConnectionProvider> switchConnectionProviders) {
101 this.switchConnectionProviders = switchConnectionProviders;
105 public void setRole(final OfpRole role) {
111 public void setBindingAwareBroker(final BindingAwareBroker bindingAwareBroker) {
112 this.bindingAwareBroker = bindingAwareBroker;
117 public void initialize() {
118 Preconditions.checkNotNull(bindingAwareBroker, "missing bindingAwareBroker");
119 bindingAwareBroker.registerProvider(this);
123 public void close() throws Exception {
124 //TODO: close all contexts, switchConnections (, managers)