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.statistics;
11 import com.google.common.util.concurrent.FutureCallback;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import com.google.common.util.concurrent.SettableFuture;
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.List;
18 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
19 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
20 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
21 import org.opendaylight.openflowplugin.impl.rpc.RequestContextImpl;
22 import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringService;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInputBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
31 import org.opendaylight.yangtools.yang.common.RpcResult;
34 * Created by Martin Bobak <mbobak@cisco.com> on 1.4.2015.
36 public class StatisticsContextImpl implements StatisticsContext {
38 private final List<RequestContext> requestContexts = new ArrayList();
39 private final DeviceContext deviceContext;
42 private final StatisticsGatheringService statisticsGatheringService;
44 public StatisticsContextImpl(DeviceContext deviceContext) {
45 this.deviceContext = deviceContext;
46 statisticsGatheringService = new StatisticsGatheringService(this, deviceContext);
50 private void pollFlowStatistics() {
51 final KeyedInstanceIdentifier<Node, NodeKey> nodeII = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(deviceContext.getPrimaryConnectionContext().getNodeId()));
52 final NodeRef nodeRef = new NodeRef(nodeII);
53 final GetAllFlowsStatisticsFromAllFlowTablesInputBuilder builder =
54 new GetAllFlowsStatisticsFromAllFlowTablesInputBuilder();
55 builder.setNode(nodeRef);
56 //TODO : process data from result
60 public ListenableFuture<Void> gatherDynamicData() {
61 ListenableFuture<Boolean> flowStatistics = StatisticsGatheringUtils.gatherStatistics(statisticsGatheringService, deviceContext, MultipartType.OFPMPFLOW);
62 ListenableFuture<Boolean> tableStatistics = StatisticsGatheringUtils.gatherStatistics(statisticsGatheringService, deviceContext, MultipartType.OFPMPTABLE);
63 ListenableFuture<Boolean> groupStatistics = StatisticsGatheringUtils.gatherStatistics(statisticsGatheringService, deviceContext, MultipartType.OFPMPGROUPDESC);
64 ListenableFuture<Boolean> meterStatistics = StatisticsGatheringUtils.gatherStatistics(statisticsGatheringService, deviceContext, MultipartType.OFPMPMETER);
65 ListenableFuture<Boolean> portStatistics = StatisticsGatheringUtils.gatherStatistics(statisticsGatheringService, deviceContext, MultipartType.OFPMPPORTSTATS);
66 ListenableFuture<Boolean> queueStatistics = StatisticsGatheringUtils.gatherStatistics(statisticsGatheringService, deviceContext, MultipartType.OFPMPQUEUE);
68 ListenableFuture<List<Boolean>> allFutures = Futures.allAsList(Arrays.asList(flowStatistics, tableStatistics, groupStatistics, meterStatistics, portStatistics, queueStatistics));
69 final SettableFuture<Void> resultingFuture = SettableFuture.create();
70 Futures.addCallback(allFutures, new FutureCallback<List<Boolean>>() {
72 public void onSuccess(final List<Boolean> booleans) {
73 resultingFuture.set(null);
77 public void onFailure(final Throwable throwable) {
78 resultingFuture.setException(throwable);
81 return resultingFuture;
85 public <T> void forgetRequestContext(final RequestContext<T> requestContext) {
86 requestContexts.remove(requestContexts);
90 public <T> SettableFuture<RpcResult<T>> storeOrFail(final RequestContext<T> data) {
91 requestContexts.add(data);
92 return data.getFuture();
96 public <T> RequestContext<T> createRequestContext() {
97 return new RequestContextImpl<>(this);