From 2e2964a9bdafc85b4bac752230681442d99c7bbf Mon Sep 17 00:00:00 2001 From: Vaclav Demcak Date: Thu, 2 Apr 2015 20:10:53 +0200 Subject: [PATCH] statistics context implements statistic services calls Change-Id: Ifcda7a4e41369cbe0077e36f80354ceb339a6e13 Signed-off-by: Martin Bobak Signed-off-by: Vaclav Demcak --- .../statistics/StatisticsContextImpl.java | 30 ++- .../statistics/StatisticsGatheringUtils.java | 200 ++++++++++++++++++ 2 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtils.java diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImpl.java index af41538661..496ea9ac30 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImpl.java @@ -18,13 +18,23 @@ import org.opendaylight.openflowplugin.api.openflow.device.RequestContext; import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext; import org.opendaylight.openflowplugin.impl.rpc.RequestContextImpl; import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightFlowStatisticsServiceImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightFlowTableStatisticsServiceImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightGroupStatisticsServiceImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightMeterStatisticsServiceImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightPortStatisticsServiceImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightQueueStatisticsServiceImpl; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsService; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.OpendaylightQueueStatisticsService; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; @@ -38,7 +48,14 @@ public class StatisticsContextImpl implements StatisticsContext { private final DeviceContext deviceContext; private final RequestContext requestContext; + private final OpendaylightFlowStatisticsService flowStatisticsService; + private final OpendaylightFlowTableStatisticsService flowTableStatisticsService; + private final OpendaylightGroupStatisticsService groupStatisticsService; + private final OpendaylightMeterStatisticsService meterStatisticsService; + private final OpendaylightPortStatisticsService portStatisticsService; + private final OpendaylightQueueStatisticsService queueStatisticsService; + /** * FIXME : Why we need RequestContext @@ -48,7 +65,13 @@ public class StatisticsContextImpl implements StatisticsContext { public StatisticsContextImpl(final DeviceContext deviceContext, final RequestContext requestContext) { this.deviceContext = deviceContext; this.requestContext = requestContext; + flowStatisticsService = new OpendaylightFlowStatisticsServiceImpl(this, deviceContext); + flowTableStatisticsService = new OpendaylightFlowTableStatisticsServiceImpl(this, deviceContext); + groupStatisticsService = new OpendaylightGroupStatisticsServiceImpl(this, deviceContext); + meterStatisticsService = new OpendaylightMeterStatisticsServiceImpl(this, deviceContext); + portStatisticsService = new OpendaylightPortStatisticsServiceImpl(this, deviceContext); + queueStatisticsService = new OpendaylightQueueStatisticsServiceImpl(this, deviceContext); } @@ -64,7 +87,12 @@ public class StatisticsContextImpl implements StatisticsContext { @Override public ListenableFuture gatherDynamicData() { - //TODO : call all necessary statistics services to gather data and store them in Oper DS + final ListenableFuture flowStatistics = StatisticsGatheringUtils.gatherFlowStatistics(flowStatisticsService, deviceContext); + final ListenableFuture tableStatistics = StatisticsGatheringUtils.gatherTableStatistics(flowTableStatisticsService, deviceContext); + final ListenableFuture groupStatistics = StatisticsGatheringUtils.gatherGroupStatistics(groupStatisticsService, deviceContext); + final ListenableFuture meterStatistics = StatisticsGatheringUtils.gatherMeterStatistics(meterStatisticsService, deviceContext); + final ListenableFuture portStatistics = StatisticsGatheringUtils.gatherPortStatistics(portStatisticsService, deviceContext); + final ListenableFuture queueStatistics = StatisticsGatheringUtils.gatherQueueStatistics(queueStatisticsService, deviceContext); return null; } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtils.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtils.java new file mode 100644 index 0000000000..8b24201063 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtils.java @@ -0,0 +1,200 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.statistics; + +import com.google.common.base.Function; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.JdkFutureAdapters; +import com.google.common.util.concurrent.ListenableFuture; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.OpendaylightQueueStatisticsService; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; +import org.opendaylight.yangtools.yang.common.RpcResult; +import javax.annotation.Nullable; +import java.util.List; + +/** + * Created by Martin Bobak <mbobak@cisco.com> on 2.4.2015. + */ +public final class StatisticsGatheringUtils { + + private StatisticsGatheringUtils() { + throw new IllegalStateException("This class should not be instantiated."); + } + + private static NodeRef createNodeRef(DeviceContext deviceContext) { + final KeyedInstanceIdentifier nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(deviceContext.getPrimaryConnectionContext().getNodeId())); + return new NodeRef(nodeInstanceIdentifier); + } + + public static ListenableFuture gatherQueueStatistics(OpendaylightQueueStatisticsService queueStatisticsService, DeviceContext deviceContext) { + + final GetAllQueuesStatisticsFromAllPortsInputBuilder builder = + new GetAllQueuesStatisticsFromAllPortsInputBuilder(); + + builder.setNode(createNodeRef(deviceContext)); + + ListenableFuture> statisticsDataInFuture = + JdkFutureAdapters. + listenInPoolThread(queueStatisticsService. + getAllQueuesStatisticsFromAllPorts(builder.build())); + + return Futures.transform(statisticsDataInFuture, new Function, Boolean>() { + @Nullable + @Override + public Boolean apply(final RpcResult rpcResult) { + if (rpcResult.isSuccessful()) { + //TODO : implement data read and put them into transaction chain + return Boolean.TRUE; + } + return Boolean.FALSE; + } + }); + } + + + public static ListenableFuture gatherPortStatistics(OpendaylightPortStatisticsService portStatisticsService, DeviceContext deviceContext) { + + final GetAllNodeConnectorsStatisticsInputBuilder builder = + new GetAllNodeConnectorsStatisticsInputBuilder(); + + builder.setNode(createNodeRef(deviceContext)); + + ListenableFuture> statisticsDataInFuture = + JdkFutureAdapters. + listenInPoolThread(portStatisticsService. + getAllNodeConnectorsStatistics(builder.build())); + + return Futures.transform(statisticsDataInFuture, new Function, Boolean>() { + @Nullable + @Override + public Boolean apply(final RpcResult rpcResult) { + if (rpcResult.isSuccessful()) { + //TODO : implement data read and put them into transaction chain + return Boolean.TRUE; + } + return Boolean.FALSE; + } + }); + } + + public static ListenableFuture gatherMeterStatistics(OpendaylightMeterStatisticsService meterStatisticsService, DeviceContext deviceContext) { + + final GetAllMeterStatisticsInputBuilder builder = + new GetAllMeterStatisticsInputBuilder(); + + builder.setNode(createNodeRef(deviceContext)); + + ListenableFuture> statisticsDataInFuture = + JdkFutureAdapters. + listenInPoolThread(meterStatisticsService. + getAllMeterStatistics(builder.build())); + + return Futures.transform(statisticsDataInFuture, new Function, Boolean>() { + @Nullable + @Override + public Boolean apply(final RpcResult rpcResult) { + if (rpcResult.isSuccessful()) { + //TODO : implement data read and put them into transaction chain + return Boolean.TRUE; + } + return Boolean.FALSE; + } + }); + } + + + public static ListenableFuture gatherGroupStatistics(OpendaylightGroupStatisticsService groupStatisticsService, DeviceContext deviceContext) { + final GetAllGroupStatisticsInputBuilder builder = + new GetAllGroupStatisticsInputBuilder(); + builder.setNode(createNodeRef(deviceContext)); + ListenableFuture> allFlowTablesDataInFuture = + JdkFutureAdapters. + listenInPoolThread(groupStatisticsService. + getAllGroupStatistics(builder.build())); + + return Futures.transform(allFlowTablesDataInFuture, new Function, Boolean>() { + @Nullable + @Override + public Boolean apply(final RpcResult rpcResult) { + if (rpcResult.isSuccessful()) { + //TODO : implement data read and put them into transaction chain + return Boolean.TRUE; + } + return Boolean.FALSE; + } + }); + } + + public static ListenableFuture gatherFlowStatistics(OpendaylightFlowStatisticsService flowStatisticsService, DeviceContext deviceContext) { + final GetAllFlowsStatisticsFromAllFlowTablesInputBuilder builder = + new GetAllFlowsStatisticsFromAllFlowTablesInputBuilder(); + builder.setNode(createNodeRef(deviceContext)); + ListenableFuture> allFlowTablesDataInFuture = + JdkFutureAdapters. + listenInPoolThread(flowStatisticsService. + getAllFlowsStatisticsFromAllFlowTables(builder.build())); + + return Futures.transform(allFlowTablesDataInFuture, new Function, Boolean>() { + @Nullable + @Override + public Boolean apply(final RpcResult rpcResult) { + if (rpcResult.isSuccessful()) { + List flowAndStatsList = rpcResult.getResult().getFlowAndStatisticsMapList(); + //TODO : implement data read and put them into transaction chain + for (FlowAndStatisticsMapList flowAndStatisticsMap : flowAndStatsList) { + } + return Boolean.TRUE; + } + return Boolean.FALSE; + } + }); + } + + public static ListenableFuture gatherTableStatistics(OpendaylightFlowTableStatisticsService flowTableStatisticsService, DeviceContext deviceContext) { + GetFlowTablesStatisticsInputBuilder getFlowTablesStatisticsInputBuilder = new GetFlowTablesStatisticsInputBuilder(); + getFlowTablesStatisticsInputBuilder.setNode(createNodeRef(deviceContext)); + ListenableFuture> flowTableStaticsDataInFuture = JdkFutureAdapters.listenInPoolThread(flowTableStatisticsService.getFlowTablesStatistics(getFlowTablesStatisticsInputBuilder.build())); + return Futures.transform(flowTableStaticsDataInFuture, new Function, Boolean>() { + @Nullable + @Override + public Boolean apply( + final RpcResult rpcResult) { + if (rpcResult.isSuccessful()) { + //TODO : implement data read and put them into transaction chain + return Boolean.TRUE; + } + return Boolean.FALSE; + } + }); + } +} -- 2.36.6