2 * Copyright (c) 2015 Cisco Systems, Inc. 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
8 package org.opendaylight.openflowplugin.impl.statistics.services;
10 import com.google.common.base.Function;
11 import com.google.common.util.concurrent.JdkFutureAdapters;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
14 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
15 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
16 import org.opendaylight.openflowplugin.impl.services.CommonService;
17 import org.opendaylight.openflowplugin.impl.services.DataCrate;
18 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder;
26 import org.opendaylight.yangtools.yang.common.RpcResult;
27 import java.util.concurrent.Future;
32 public class OpendaylightFlowTableStatisticsServiceImpl extends CommonService implements
33 OpendaylightFlowTableStatisticsService {
35 public OpendaylightFlowTableStatisticsServiceImpl(final RequestContextStack requestContextStack, DeviceContext deviceContext) {
36 super(requestContextStack, deviceContext);
40 public Future<RpcResult<GetFlowTablesStatisticsOutput>> getFlowTablesStatistics(
41 final GetFlowTablesStatisticsInput input) {
44 return this.<GetFlowTablesStatisticsOutput, Void>handleServiceCall(PRIMARY_CONNECTION,
45 new Function<DataCrate<GetFlowTablesStatisticsOutput>, ListenableFuture<RpcResult<Void>>>() {
48 public ListenableFuture<RpcResult<Void>> apply(final DataCrate<GetFlowTablesStatisticsOutput> data) {
50 // Create multipart request body for fetch all the group stats
51 final MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder();
52 final MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
53 multipartRequestTableBuilder.setEmpty(true);
54 multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build());
56 // Set request body to main multipart request
57 final Xid xid = deviceContext.getNextXid();
58 data.getRequestContext().setXid(xid);
59 final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
60 MultipartType.OFPMPFLOW, xid.getValue(), version);
62 mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
63 final Future<RpcResult<Void>> resultFromOFLib = deviceContext.getPrimaryConnectionContext()
64 .getConnectionAdapter().multipartRequest(mprInput.build());
66 return JdkFutureAdapters.listenInPoolThread(resultFromOFLib);