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 org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
13 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
14 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
15 import org.opendaylight.openflowplugin.impl.services.CommonService;
16 import org.opendaylight.openflowplugin.impl.services.DataCrate;
17 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder;
25 import org.opendaylight.yangtools.yang.common.RpcResult;
26 import java.util.concurrent.Future;
31 public class OpendaylightFlowTableStatisticsServiceImpl extends CommonService implements
32 OpendaylightFlowTableStatisticsService {
34 public OpendaylightFlowTableStatisticsServiceImpl(final RequestContextStack requestContextStack, DeviceContext deviceContext) {
35 super(requestContextStack, deviceContext);
39 public Future<RpcResult<GetFlowTablesStatisticsOutput>> getFlowTablesStatistics(
40 final GetFlowTablesStatisticsInput input) {
43 return this.<GetFlowTablesStatisticsOutput, Void>handleServiceCall(PRIMARY_CONNECTION,
44 new Function<DataCrate<GetFlowTablesStatisticsOutput>, Future<RpcResult<Void>>>() {
47 public Future<RpcResult<Void>> apply(final DataCrate<GetFlowTablesStatisticsOutput> data) {
49 // Create multipart request body for fetch all the group stats
50 final MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder();
51 final MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
52 multipartRequestTableBuilder.setEmpty(true);
53 multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build());
55 // Set request body to main multipart request
56 final Xid xid = deviceContext.getNextXid();
57 data.getRequestContext().setXid(xid);
58 final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
59 MultipartType.OFPMPFLOW, xid.getValue(), version);
61 mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
62 final Future<RpcResult<Void>> resultFromOFLib = deviceContext.getPrimaryConnectionContext()
63 .getConnectionAdapter().multipartRequest(mprInput.build());
65 return JdkFutureAdapters.listenInPoolThread(resultFromOFLib);