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.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.get.aggregate.flow.statistics.from.flow.table._for.given.match.output.AggregatedFlowStatisticsBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.multipart.reply.multipart.reply.body.MultipartReplyFlowAggregateStats;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.multipart.request.multipart.request.body.MultipartRequestFlowAggregateStatsBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.multipart.request.multipart.request.body.multipart.request.flow.aggregate.stats.FlowAggregateStatsBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReply;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartRequestBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
30 import org.opendaylight.yangtools.yang.common.RpcResult;
31 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
33 public class SingleLayerAggregateFlowMultipartService
34 extends AbstractAggregateFlowMultipartService<MultipartReply> {
36 public SingleLayerAggregateFlowMultipartService(final RequestContextStack requestContextStack,
37 final DeviceContext deviceContext) {
38 super(requestContextStack, deviceContext);
42 protected OfHeader buildRequest(final Xid xid,
43 final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
44 return new MultipartRequestBuilder()
45 .setXid(xid.getValue())
46 .setVersion(getVersion())
47 .setRequestMore(false)
48 .setMultipartRequestBody(new MultipartRequestFlowAggregateStatsBuilder()
49 .setFlowAggregateStats(new FlowAggregateStatsBuilder(input).build()).build())
54 public ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> handleAndReply(
55 final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
56 return Futures.transform(handleServiceCall(input), result -> {
57 if (Preconditions.checkNotNull(result).isSuccessful()) {
58 return RpcResultBuilder
59 .success(new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder()
60 .setAggregatedFlowStatistics(result
63 .map(MultipartReply::getMultipartReplyBody)
64 .filter(MultipartReplyFlowAggregateStats.class::isInstance)
65 .map(multipartReplyBody ->
66 new AggregatedFlowStatisticsBuilder(
67 (MultipartReplyFlowAggregateStats) multipartReplyBody)
69 .collect(Collectors.toList())))
73 return RpcResultBuilder
74 .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>failed()
75 .withRpcErrors(result.getErrors())
77 }, MoreExecutors.directExecutor());