statistics manager initial commit
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / StatisticsContextImpl.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowplugin.impl.statistics;
10
11 import com.google.common.util.concurrent.ListenableFuture;
12 import com.google.common.util.concurrent.SettableFuture;
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.concurrent.Future;
16 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
17 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
18 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
19 import org.opendaylight.openflowplugin.impl.rpc.RequestContextImpl;
20 import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightFlowStatisticsServiceImpl;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInputBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
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.yangtools.yang.binding.InstanceIdentifier;
29 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
30 import org.opendaylight.yangtools.yang.common.RpcResult;
31
32 /**
33  * Created by Martin Bobak <mbobak@cisco.com> on 1.4.2015.
34  */
35 public class StatisticsContextImpl implements StatisticsContext {
36
37     private final List<RequestContext> requestContexts = new ArrayList();
38     private final DeviceContext deviceContext;
39     private final RequestContext requestContext;
40
41     private final OpendaylightFlowStatisticsService flowStatisticsService;
42
43     /**
44      * FIXME : Why we need RequestContext
45      * @param deviceContext
46      * @param requestContext
47      */
48     public StatisticsContextImpl(final DeviceContext deviceContext, final RequestContext requestContext) {
49         this.deviceContext = deviceContext;
50         this.requestContext = requestContext;
51         flowStatisticsService = new OpendaylightFlowStatisticsServiceImpl(this, deviceContext);
52
53     }
54
55     private void pollFlowStatistics() {
56         final KeyedInstanceIdentifier<Node, NodeKey> nodeII = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(deviceContext.getPrimaryConnectionContext().getNodeId()));
57         final NodeRef nodeRef = new NodeRef(nodeII);
58         final GetAllFlowsStatisticsFromAllFlowTablesInputBuilder builder =
59                 new GetAllFlowsStatisticsFromAllFlowTablesInputBuilder();
60         builder.setNode(nodeRef);
61         final Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> flowStatisticsResult = flowStatisticsService.getAllFlowsStatisticsFromAllFlowTables(builder.build());
62         //TODO : process data from result
63     }
64
65     @Override
66     public ListenableFuture<Void> gatherDynamicData() {
67         //TODO : call all necessary statistics services to gather data and store them in Oper DS
68         return null;
69     }
70
71     @Override
72     public <T> void forgetRequestContext(final RequestContext<T> requestContext) {
73         requestContexts.remove(requestContexts);
74     }
75
76     @Override
77     public <T> SettableFuture<RpcResult<T>> storeOrFail(final RequestContext<T> data) {
78         requestContexts.add(data);
79         return data.getFuture();
80     }
81
82     @Override
83     public <T> RequestContext<T> createRequestContext() {
84         return new RequestContextImpl<>(this);
85     }
86 }