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=cd127d6e16f68a03b3ba742049742e70c15a17e1;hb=1bad84906fffbc4c3a901712f8a803680bcd064f;hp=341c844b5f124c88b990a5a198c8be44175d6a97;hpb=84a73f70b5c2e95e2475216407b6bbb7392a52b5;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 341c844b5f..cd127d6e16 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 @@ -8,23 +8,21 @@ package org.opendaylight.openflowplugin.impl.statistics.services; import com.google.common.base.Function; -import com.google.common.util.concurrent.JdkFutureAdapters; -import com.google.common.util.concurrent.ListenableFuture; -import org.opendaylight.openflowplugin.api.OFConstants; +import com.google.common.util.concurrent.Futures; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Future; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; -import org.opendaylight.openflowplugin.api.openflow.device.RequestContext; +import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; -import org.opendaylight.openflowplugin.api.openflow.device.Xid; -import org.opendaylight.openflowplugin.impl.services.CommonService; -import org.opendaylight.openflowplugin.impl.services.DataCrate; -import org.opendaylight.openflowplugin.impl.services.RequestInputUtils; -import org.opendaylight.openflowplugin.impl.services.OFJResult2RequestCtxFuture; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor; -import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil; +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.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,248 +30,128 @@ 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.openflow.common.types.rev130731.MultipartType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder; +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; -import java.util.concurrent.Future; /** * @author joe */ -public class OpendaylightFlowStatisticsServiceImpl extends CommonService implements OpendaylightFlowStatisticsService { +public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowStatisticsService, Delegator { private static final Logger LOG = LoggerFactory.getLogger(OpendaylightFlowStatisticsServiceImpl.class); - public OpendaylightFlowStatisticsServiceImpl(final RequestContextStack requestContextStack, DeviceContext deviceContext) { - super(requestContextStack, deviceContext); - } - - @Override - public Future> getAggregateFlowStatisticsFromFlowTableForAllFlows( - final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) { - - - return this.handleServiceCall( - PRIMARY_CONNECTION, - new Function, ListenableFuture>>() { - - @Override - public ListenableFuture> apply(final DataCrate data) { + private final Function>, RpcResult> matchingConvertor = + new Function>, RpcResult>() { + @Override + public RpcResult apply(final RpcResult> input) { + final DeviceContext deviceContext = matchingFlowsInTable.getDeviceContext(); + TranslatorLibrary translatorLibrary = deviceContext.oook(); + 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, deviceContext, null)); + } - // Create multipart request body for fetch all the group stats - final MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder(); - final MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder(); - mprAggregateRequestBuilder.setTableId(input.getTableId().getValue()); - mprAggregateRequestBuilder.setOutPort(OFConstants.OFPP_ANY); - mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY); - mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE); - mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK); + GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder = + new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder(); + getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.setAggregatedFlowStatistics(aggregStats); - FlowCreatorUtil.setWildcardedFlowMatch(version, mprAggregateRequestBuilder); + rpcResult = RpcResultBuilder + .success() + .withResult(getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.build()) + .build(); - // Set request body to main multipart request - multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder - .build()); - final Xid xid = deviceContext.getNextXid(); - data.getRequestContext().setXid(xid); - final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader( - MultipartType.OFPMPAGGREGATE, xid.getValue(), version); + } else { + rpcResult = RpcResultBuilder + .failed() + .withRpcErrors(input.getErrors()) + .build(); + } + return rpcResult; + } + }; - mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build()); + private final MatchingFlowsInTableService matchingFlowsInTable; + private OpendaylightFlowStatisticsService delegate; - final Future> resultFromOFLib = deviceContext.getPrimaryConnectionContext() - .getConnectionAdapter().multipartRequest(mprInput.build()); + public OpendaylightFlowStatisticsServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) { + matchingFlowsInTable = new MatchingFlowsInTableService(requestContextStack, deviceContext); + } - return JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - } - }); + @Override + public void setDelegate(OpendaylightFlowStatisticsService delegate) { + this.delegate = delegate; + } + /** + * @deprecated provided for Be-release as backward compatibility relic + */ + @Override + @Deprecated + public Future> getAggregateFlowStatisticsFromFlowTableForAllFlows( + final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) { + if (delegate != null) { + return delegate.getAggregateFlowStatisticsFromFlowTableForAllFlows(input); + } else { + throw new IllegalAccessError("no delegate available - service is currently out of order"); + } } @Override public Future> getAggregateFlowStatisticsFromFlowTableForGivenMatch( final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) { - - - return this.handleServiceCall( - PRIMARY_CONNECTION, - new Function, ListenableFuture>>() { - - @Override - public ListenableFuture> apply(final DataCrate data) { - final MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder(); - final MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder(); - mprAggregateRequestBuilder.setTableId(input.getTableId()); - mprAggregateRequestBuilder.setOutPort(input.getOutPort().longValue()); - // TODO: repeating code - if (version == OFConstants.OFP_VERSION_1_3) { - mprAggregateRequestBuilder.setCookie(input.getCookie().getValue()); - mprAggregateRequestBuilder.setCookieMask(input.getCookieMask().getValue()); - mprAggregateRequestBuilder.setOutGroup(input.getOutGroup()); - } else { - mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY); - mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE); - mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK); - } - - MatchReactor.getInstance().convert(input.getMatch(), version, mprAggregateRequestBuilder, - deviceContext.getPrimaryConnectionContext().getFeatures().getDatapathId()); - - FlowCreatorUtil.setWildcardedFlowMatch(version, mprAggregateRequestBuilder); - - // Set request body to main multipart request - multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder - .build()); - - final Xid xid = deviceContext.getNextXid(); - data.getRequestContext().setXid(xid); - final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader( - MultipartType.OFPMPAGGREGATE, xid.getValue(), version); - - mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build()); - final Future> resultFromOFLib = deviceContext.getPrimaryConnectionContext() - .getConnectionAdapter().multipartRequest(mprInput.build()); - return JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - } - }); - + return Futures.transform(matchingFlowsInTable.handleServiceCall(input), matchingConvertor); } + /** + * @deprecated provided for Be-release as backward compatibility relic + */ @Override + @Deprecated public Future> getAllFlowStatisticsFromFlowTable( final GetAllFlowStatisticsFromFlowTableInput input) { - - return this.handleServiceCall(PRIMARY_CONNECTION, - new Function, ListenableFuture>>() { - - @Override - public ListenableFuture> apply(final DataCrate data) { - - final MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder(); - mprFlowRequestBuilder.setTableId(input.getTableId().getValue()); - mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY); - mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY); - mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE); - mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK); - FlowCreatorUtil.setWildcardedFlowMatch(version, mprFlowRequestBuilder); - - final MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder(); - multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build()); - - final Xid xid = deviceContext.getNextXid(); - data.getRequestContext().setXid(xid); - final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader( - MultipartType.OFPMPFLOW, xid.getValue(), version); - - mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build()); - final Future> resultFromOFLib = deviceContext.getPrimaryConnectionContext() - .getConnectionAdapter().multipartRequest(mprInput.build()); - return JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - } - }); + if (delegate != null) { + return delegate.getAllFlowStatisticsFromFlowTable(input); + } else { + throw new IllegalAccessError("no delegate available - service is currently out of order"); + } } + /** + * @deprecated provided for Be-release as backward compatibility relic + */ @Override + @Deprecated public Future> getAllFlowsStatisticsFromAllFlowTables( final GetAllFlowsStatisticsFromAllFlowTablesInput input) { - - - return this.handleServiceCall(PRIMARY_CONNECTION, - new Function, ListenableFuture>>() { - - @Override - public ListenableFuture> apply(final DataCrate data) { - - final MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder(); - final MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder(); - mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL); - mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY); - mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY); - mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE); - mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK); - FlowCreatorUtil.setWildcardedFlowMatch(version, mprFlowRequestBuilder); - - final Xid xid = deviceContext.getNextXid(); - data.getRequestContext().setXid(xid); - final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader( - MultipartType.OFPMPFLOW, xid.getValue(), version); - - multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build()); - mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build()); - final Future> resultFromOFLib = deviceContext.getPrimaryConnectionContext() - .getConnectionAdapter().multipartRequest(mprInput.build()); - return JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - } - }); + if (delegate != null) { + return delegate.getAllFlowsStatisticsFromAllFlowTables(input); + } else { + throw new IllegalAccessError("no delegate available - service is currently out of order"); + } } + /** + * @deprecated provided for Be-release as backward compatibility relic + */ @Override + @Deprecated public Future> getFlowStatisticsFromFlowTable( final GetFlowStatisticsFromFlowTableInput input) { - - - return this.handleServiceCall(PRIMARY_CONNECTION, - new Function, ListenableFuture>>() { - - @Override - public ListenableFuture> apply(final DataCrate data) { - - final MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder(); - final MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder(); - mprFlowRequestBuilder.setTableId(input.getTableId()); - - if (input.getOutPort() != null) { - mprFlowRequestBuilder.setOutPort(input.getOutPort().longValue()); - } else { - mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY); - } - - if (input.getOutGroup() != null) { - mprFlowRequestBuilder.setOutGroup(input.getOutGroup()); - } else { - mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY); - } - - if (input.getCookie() != null) { - mprFlowRequestBuilder.setCookie(input.getCookie().getValue()); - } else { - mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE); - } - - if (input.getCookieMask() != null) { - mprFlowRequestBuilder.setCookieMask(input.getCookieMask().getValue()); - } else { - mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK); - } - - // convert and inject match - MatchReactor.getInstance().convert(input.getMatch(), version, mprFlowRequestBuilder, - deviceContext.getPrimaryConnectionContext().getFeatures().getDatapathId()); - - // Set request body to main multipart request - multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build()); - final Xid xid = deviceContext.getNextXid(); - data.getRequestContext().setXid(xid); - final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader( - MultipartType.OFPMPFLOW, xid.getValue(), version); - mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build()); - final Future> resultFromOFLib = deviceContext.getPrimaryConnectionContext() - .getConnectionAdapter().multipartRequest(mprInput.build()); - return JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - } - }); + if (delegate != null) { + return delegate.getFlowStatisticsFromFlowTable(input); + } else { + throw new IllegalAccessError("no delegate available - service is currently out of order"); + } } - - private void convertRpcResultToRequestFuture(final RequestContext requestContext, - final ListenableFuture> futureResultFromOfLib) { - final OFJResult2RequestCtxFuture OFJResult2RequestCtxFuture = new OFJResult2RequestCtxFuture<>(requestContext, deviceContext); - OFJResult2RequestCtxFuture.processResultFromOfJava(futureResultFromOfLib); - } - }