-
-
- ListenableFuture<RpcResult<List<MultipartReply>>> rpcResultListenableFuture = handleServiceCall(
- new Function<RequestContext<List<MultipartReply>>, ListenableFuture<RpcResult<List<MultipartReply>>>>() {
-
- @Override
- public ListenableFuture<RpcResult<List<MultipartReply>>> apply(final RequestContext<List<MultipartReply>> requestContext) {
- final Xid xid = requestContext.getXid();
- final DeviceContext deviceContext = getDeviceContext();
- final MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
- final MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
- final short tableId = MoreObjects.firstNonNull(input.getTableId(), OFConstants.OFPTT_ALL).shortValue();
- mprAggregateRequestBuilder.setTableId(tableId);
- long outputPortValue = MoreObjects.firstNonNull(input.getOutPort(), OFConstants.OFPP_ANY).longValue();
- mprAggregateRequestBuilder.setOutPort(outputPortValue);
- // TODO: repeating code
-
- final short version = getVersion();
- if (version == OFConstants.OFP_VERSION_1_3) {
-
- if (input.getCookie() == null) {
- mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
- } else {
- mprAggregateRequestBuilder.setCookie(MoreObjects.firstNonNull(input.getCookie().getValue(), OFConstants.DEFAULT_COOKIE));
- }
-
- if (input.getCookieMask() == null) {
- mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
- } else {
- mprAggregateRequestBuilder.setCookieMask(MoreObjects.firstNonNull(input.getCookieMask().getValue(), OFConstants.DEFAULT_COOKIE_MASK));
- }
- long outGroup = MoreObjects.firstNonNull(input.getOutGroup(), OFConstants.OFPG_ANY).longValue();
- mprAggregateRequestBuilder.setOutGroup(outGroup);
- } 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 MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
- MultipartType.OFPMPAGGREGATE, xid.getValue(), version);
-
- mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
- return StatisticsServiceUtil.getRpcResultListenableFuture(xid, mprInput.build(), getDeviceContext());
- }
- });
-
- return Futures.transform(rpcResultListenableFuture, new Function<RpcResult<List<MultipartReply>>, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>>() {
- @Nullable
- @Override
- public RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> apply(final RpcResult<List<MultipartReply>> input) {
- final DeviceContext deviceContext = getDeviceContext();
- TranslatorLibrary translatorLibrary = deviceContext.oook();
- RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> rpcResult;
- if (input.isSuccessful()) {
- MultipartReply reply = input.getResult().get(0);
- final TranslatorKey translatorKey = new TranslatorKey(reply.getVersion(), MultipartReplyAggregateCase.class.getName());
- final MessageTranslator<MultipartReply, AggregatedFlowStatistics> messageTranslator = translatorLibrary.lookupTranslator(translatorKey);
- List<AggregatedFlowStatistics> aggregStats = new ArrayList<AggregatedFlowStatistics>();
-
- for (MultipartReply multipartReply : input.getResult()) {
- aggregStats.add(messageTranslator.translate(multipartReply, deviceContext, null));
- }
-
- GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder =
- new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder();
- getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.setAggregatedFlowStatistics(aggregStats);
-
- rpcResult = RpcResultBuilder
- .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>success()
- .withResult(getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.build())
- .build();
-
- } else {
- rpcResult = RpcResultBuilder
- .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>failed()
- .withRpcErrors(input.getErrors())
- .build();
- }
- return rpcResult;
- }
- });
-