X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fstatistics%2Fservices%2FOpendaylightFlowStatisticsServiceImpl.java;h=f6f9878fae456d9c2236e314ece201d142a7e415;hb=73776c548ab153dee35ca4165ca0ef2413969704;hp=3ab8c8b21af044805919b78706c1ffe4a54fbefe;hpb=6e1e20dd97e1c7605cb5c8e619ace7dbb80f4781;p=openflowplugin.git diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl.java index 3ab8c8b21a..f6f9878fae 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the @@ -7,24 +7,18 @@ */ package org.opendaylight.openflowplugin.impl.statistics.services; -import com.google.common.base.Function; -import com.google.common.util.concurrent.Futures; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Future; +import com.google.common.util.concurrent.ListenableFuture; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; -import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo; -import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary; -import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey; import org.opendaylight.openflowplugin.api.openflow.statistics.compatibility.Delegator; +import org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerAggregateFlowMultipartService; +import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerAggregateFlowMultipartService; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput; @@ -32,69 +26,31 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.G import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.get.aggregate.flow.statistics.from.flow.table._for.given.match.output.AggregatedFlowStatistics; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase; import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.common.RpcResultBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -/** - * @author joe - */ -public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowStatisticsService, Delegator { - - private static final Logger LOG = LoggerFactory.getLogger(OpendaylightFlowStatisticsServiceImpl.class); - - private final Function>, RpcResult> matchingConvertor = - new Function>, RpcResult>() { - @Override - public RpcResult apply(final RpcResult> input) { - final DeviceInfo deviceInfo = matchingFlowsInTable.getDeviceInfo(); - final RpcResult rpcResult; - if (input.isSuccessful()) { - MultipartReply reply = input.getResult().get(0); - final TranslatorKey translatorKey = new TranslatorKey(reply.getVersion(), MultipartReplyAggregateCase.class.getName()); - final MessageTranslator messageTranslator = translatorLibrary.lookupTranslator(translatorKey); - List aggregStats = new ArrayList(); - - for (MultipartReply multipartReply : input.getResult()) { - aggregStats.add(messageTranslator.translate(multipartReply, deviceInfo, null)); - } - - GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder = - new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder(); - getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.setAggregatedFlowStatistics(aggregStats); - - rpcResult = RpcResultBuilder - .success() - .withResult(getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.build()) - .build(); - - } else { - rpcResult = RpcResultBuilder - .failed() - .withRpcErrors(input.getErrors()) - .build(); - } - return rpcResult; - } - }; +public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowStatisticsService, + Delegator { - private final MatchingFlowsInTableService matchingFlowsInTable; - private final TranslatorLibrary translatorLibrary; + private final SingleLayerAggregateFlowMultipartService singleLayerService; + private final MultiLayerAggregateFlowMultipartService multiLayerService; private OpendaylightFlowStatisticsService delegate; public static OpendaylightFlowStatisticsServiceImpl createWithOook(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, final ConvertorExecutor convertorExecutor) { - return new OpendaylightFlowStatisticsServiceImpl(requestContextStack, deviceContext, deviceContext.oook(), convertorExecutor); + final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor) { + return new OpendaylightFlowStatisticsServiceImpl(requestContextStack, + deviceContext, + deviceContext.oook(), + convertorExecutor); } - public OpendaylightFlowStatisticsServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, - final TranslatorLibrary translatorLibrary, final ConvertorExecutor convertorExecutor) { - matchingFlowsInTable = new MatchingFlowsInTableService(requestContextStack, deviceContext, convertorExecutor); - this.translatorLibrary = translatorLibrary; + public OpendaylightFlowStatisticsServiceImpl(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, + final TranslatorLibrary translatorLibrary, + final ConvertorExecutor convertorExecutor) { + singleLayerService = new SingleLayerAggregateFlowMultipartService(requestContextStack, deviceContext); + multiLayerService = new MultiLayerAggregateFlowMultipartService(requestContextStack, deviceContext, + convertorExecutor, translatorLibrary); } @Override @@ -103,12 +59,15 @@ public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowSt } /** - * @deprecated provided for Be-release as backward compatibility relic + * Get aggregate statistics. + * + * @deprecated provided for Be-release as backward compatibility relic. */ @Override @Deprecated - public Future> getAggregateFlowStatisticsFromFlowTableForAllFlows( - final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) { + public ListenableFuture> + getAggregateFlowStatisticsFromFlowTableForAllFlows( + final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) { if (delegate != null) { return delegate.getAggregateFlowStatisticsFromFlowTableForAllFlows(input); } else { @@ -117,17 +76,22 @@ public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowSt } @Override - public Future> getAggregateFlowStatisticsFromFlowTableForGivenMatch( - final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) { - return Futures.transform(matchingFlowsInTable.handleServiceCall(input), matchingConvertor); + public ListenableFuture> + getAggregateFlowStatisticsFromFlowTableForGivenMatch( + final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) { + return singleLayerService.canUseSingleLayerSerialization() + ? singleLayerService.handleAndReply(input) + : multiLayerService.handleAndReply(input); } /** - * @deprecated provided for Be-release as backward compatibility relic + * Get flow statistics. + * + * @deprecated provided for Be-release as backward compatibility relic. */ @Override @Deprecated - public Future> getAllFlowStatisticsFromFlowTable( + public ListenableFuture> getAllFlowStatisticsFromFlowTable( final GetAllFlowStatisticsFromFlowTableInput input) { if (delegate != null) { return delegate.getAllFlowStatisticsFromFlowTable(input); @@ -137,12 +101,14 @@ public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowSt } /** - * @deprecated provided for Be-release as backward compatibility relic + * Get flow statistics. + * + * @deprecated provided for Be-release as backward compatibility relic. */ @Override @Deprecated - public Future> getAllFlowsStatisticsFromAllFlowTables( - final GetAllFlowsStatisticsFromAllFlowTablesInput input) { + public ListenableFuture> + getAllFlowsStatisticsFromAllFlowTables(final GetAllFlowsStatisticsFromAllFlowTablesInput input) { if (delegate != null) { return delegate.getAllFlowsStatisticsFromAllFlowTables(input); } else { @@ -151,11 +117,13 @@ public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowSt } /** - * @deprecated provided for Be-release as backward compatibility relic + * Get flow statistics. + * + * @deprecated provided for Be-release as backward compatibility relic. */ @Override @Deprecated - public Future> getFlowStatisticsFromFlowTable( + public ListenableFuture> getFlowStatisticsFromFlowTable( final GetFlowStatisticsFromFlowTableInput input) { if (delegate != null) { return delegate.getFlowStatisticsFromFlowTable(input);