2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.services.singlelayer;
11 import com.google.common.base.Preconditions;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import com.google.common.util.concurrent.MoreExecutors;
15 import java.util.stream.Collectors;
16 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
17 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
18 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
19 import org.opendaylight.openflowplugin.impl.services.AbstractAggregateFlowMultipartService;
20 import org.opendaylight.openflowplugin.impl.services.util.ServiceException;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.get.aggregate.flow.statistics.from.flow.table._for.given.match.output.AggregatedFlowStatisticsBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.multipart.reply.multipart.reply.body.MultipartReplyFlowAggregateStats;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.multipart.request.multipart.request.body.MultipartRequestFlowAggregateStatsBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.multipart.request.multipart.request.body.multipart.request.flow.aggregate.stats.FlowAggregateStatsBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReply;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartRequestBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
31 import org.opendaylight.yangtools.yang.common.RpcResult;
32 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
34 public class SingleLayerAggregateFlowMultipartService
35 extends AbstractAggregateFlowMultipartService<MultipartReply> {
37 public SingleLayerAggregateFlowMultipartService(final RequestContextStack requestContextStack,
38 final DeviceContext deviceContext) {
39 super(requestContextStack, deviceContext);
43 protected OfHeader buildRequest(final Xid xid,
44 final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input)
45 throws ServiceException {
46 return new MultipartRequestBuilder()
47 .setXid(xid.getValue())
48 .setVersion(getVersion())
49 .setRequestMore(false)
50 .setMultipartRequestBody(new MultipartRequestFlowAggregateStatsBuilder()
51 .setFlowAggregateStats(new FlowAggregateStatsBuilder(input).build()).build())
56 public ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> handleAndReply(
57 final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
58 return Futures.transform(handleServiceCall(input), result -> {
59 if (Preconditions.checkNotNull(result).isSuccessful()) {
60 return RpcResultBuilder
61 .success(new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder()
62 .setAggregatedFlowStatistics(result
65 .map(MultipartReply::getMultipartReplyBody)
66 .filter(MultipartReplyFlowAggregateStats.class::isInstance)
67 .map(multipartReplyBody ->
68 new AggregatedFlowStatisticsBuilder(
69 MultipartReplyFlowAggregateStats.class
70 .cast(multipartReplyBody))
72 .collect(Collectors.toList())))
76 return RpcResultBuilder
77 .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>failed()
78 .withRpcErrors(result.getErrors())
80 }, MoreExecutors.directExecutor());