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.base.Function;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.JdkFutureAdapters;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInputBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInputBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInputBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsService;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInputBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutput;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsService;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInputBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutput;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsService;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInputBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutput;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.OpendaylightQueueStatisticsService;
39 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
40 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
41 import org.opendaylight.yangtools.yang.common.RpcResult;
42 import javax.annotation.Nullable;
43 import java.util.List;
46 * Created by Martin Bobak <mbobak@cisco.com> on 2.4.2015.
48 public final class StatisticsGatheringUtils {
50 private StatisticsGatheringUtils() {
51 throw new IllegalStateException("This class should not be instantiated.");
54 private static NodeRef createNodeRef(DeviceContext deviceContext) {
55 final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(deviceContext.getPrimaryConnectionContext().getNodeId()));
56 return new NodeRef(nodeInstanceIdentifier);
59 public static ListenableFuture<Boolean> gatherQueueStatistics(OpendaylightQueueStatisticsService queueStatisticsService, DeviceContext deviceContext) {
61 final GetAllQueuesStatisticsFromAllPortsInputBuilder builder =
62 new GetAllQueuesStatisticsFromAllPortsInputBuilder();
64 builder.setNode(createNodeRef(deviceContext));
66 ListenableFuture<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> statisticsDataInFuture =
68 listenInPoolThread(queueStatisticsService.
69 getAllQueuesStatisticsFromAllPorts(builder.build()));
71 return Futures.transform(statisticsDataInFuture, new Function<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>, Boolean>() {
74 public Boolean apply(final RpcResult<GetAllQueuesStatisticsFromAllPortsOutput> rpcResult) {
75 if (rpcResult.isSuccessful()) {
76 //TODO : implement data read and put them into transaction chain
85 public static ListenableFuture<Boolean> gatherPortStatistics(OpendaylightPortStatisticsService portStatisticsService, DeviceContext deviceContext) {
87 final GetAllNodeConnectorsStatisticsInputBuilder builder =
88 new GetAllNodeConnectorsStatisticsInputBuilder();
90 builder.setNode(createNodeRef(deviceContext));
92 ListenableFuture<RpcResult<GetAllNodeConnectorsStatisticsOutput>> statisticsDataInFuture =
94 listenInPoolThread(portStatisticsService.
95 getAllNodeConnectorsStatistics(builder.build()));
97 return Futures.transform(statisticsDataInFuture, new Function<RpcResult<GetAllNodeConnectorsStatisticsOutput>, Boolean>() {
100 public Boolean apply(final RpcResult<GetAllNodeConnectorsStatisticsOutput> rpcResult) {
101 if (rpcResult.isSuccessful()) {
102 //TODO : implement data read and put them into transaction chain
105 return Boolean.FALSE;
110 public static ListenableFuture<Boolean> gatherMeterStatistics(OpendaylightMeterStatisticsService meterStatisticsService, DeviceContext deviceContext) {
112 final GetAllMeterStatisticsInputBuilder builder =
113 new GetAllMeterStatisticsInputBuilder();
115 builder.setNode(createNodeRef(deviceContext));
117 ListenableFuture<RpcResult<GetAllMeterStatisticsOutput>> statisticsDataInFuture =
119 listenInPoolThread(meterStatisticsService.
120 getAllMeterStatistics(builder.build()));
122 return Futures.transform(statisticsDataInFuture, new Function<RpcResult<GetAllMeterStatisticsOutput>, Boolean>() {
125 public Boolean apply(final RpcResult<GetAllMeterStatisticsOutput> rpcResult) {
126 if (rpcResult.isSuccessful()) {
127 //TODO : implement data read and put them into transaction chain
130 return Boolean.FALSE;
136 public static ListenableFuture<Boolean> gatherGroupStatistics(OpendaylightGroupStatisticsService groupStatisticsService, DeviceContext deviceContext) {
137 final GetAllGroupStatisticsInputBuilder builder =
138 new GetAllGroupStatisticsInputBuilder();
139 builder.setNode(createNodeRef(deviceContext));
140 ListenableFuture<RpcResult<GetAllGroupStatisticsOutput>> allFlowTablesDataInFuture =
142 listenInPoolThread(groupStatisticsService.
143 getAllGroupStatistics(builder.build()));
145 return Futures.transform(allFlowTablesDataInFuture, new Function<RpcResult<GetAllGroupStatisticsOutput>, Boolean>() {
148 public Boolean apply(final RpcResult<GetAllGroupStatisticsOutput> rpcResult) {
149 if (rpcResult.isSuccessful()) {
150 //TODO : implement data read and put them into transaction chain
153 return Boolean.FALSE;
158 public static ListenableFuture<Boolean> gatherFlowStatistics(OpendaylightFlowStatisticsService flowStatisticsService, DeviceContext deviceContext) {
159 final GetAllFlowsStatisticsFromAllFlowTablesInputBuilder builder =
160 new GetAllFlowsStatisticsFromAllFlowTablesInputBuilder();
161 builder.setNode(createNodeRef(deviceContext));
162 ListenableFuture<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> allFlowTablesDataInFuture =
164 listenInPoolThread(flowStatisticsService.
165 getAllFlowsStatisticsFromAllFlowTables(builder.build()));
167 return Futures.transform(allFlowTablesDataInFuture, new Function<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>, Boolean>() {
170 public Boolean apply(final RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput> rpcResult) {
171 if (rpcResult.isSuccessful()) {
172 List<FlowAndStatisticsMapList> flowAndStatsList = rpcResult.getResult().getFlowAndStatisticsMapList();
173 //TODO : implement data read and put them into transaction chain
174 for (FlowAndStatisticsMapList flowAndStatisticsMap : flowAndStatsList) {
178 return Boolean.FALSE;
183 public static ListenableFuture<Boolean> gatherTableStatistics(OpendaylightFlowTableStatisticsService flowTableStatisticsService, DeviceContext deviceContext) {
184 GetFlowTablesStatisticsInputBuilder getFlowTablesStatisticsInputBuilder = new GetFlowTablesStatisticsInputBuilder();
185 getFlowTablesStatisticsInputBuilder.setNode(createNodeRef(deviceContext));
186 ListenableFuture<RpcResult<GetFlowTablesStatisticsOutput>> flowTableStaticsDataInFuture = JdkFutureAdapters.listenInPoolThread(flowTableStatisticsService.getFlowTablesStatistics(getFlowTablesStatisticsInputBuilder.build()));
187 return Futures.transform(flowTableStaticsDataInFuture, new Function<RpcResult<GetFlowTablesStatisticsOutput>, Boolean>() {
190 public Boolean apply(
191 final RpcResult<GetFlowTablesStatisticsOutput> rpcResult) {
192 if (rpcResult.isSuccessful()) {
193 //TODO : implement data read and put them into transaction chain
196 return Boolean.FALSE;