CommonService exposes more methods and parameters
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / services / OpendaylightFlowTableStatisticsServiceImpl.java
1 /**
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.openflowplugin.impl.statistics.services;
9
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;
27
28 /**
29  * @author joe
30  */
31 public class OpendaylightFlowTableStatisticsServiceImpl extends CommonService implements
32         OpendaylightFlowTableStatisticsService {
33
34     public OpendaylightFlowTableStatisticsServiceImpl(final RequestContextStack requestContextStack, DeviceContext deviceContext) {
35         super(requestContextStack, deviceContext);
36     }
37
38     @Override
39     public Future<RpcResult<GetFlowTablesStatisticsOutput>> getFlowTablesStatistics(
40             final GetFlowTablesStatisticsInput input) {
41
42
43         return this.<GetFlowTablesStatisticsOutput, Void>handleServiceCall(PRIMARY_CONNECTION,
44                 new Function<DataCrate<GetFlowTablesStatisticsOutput>, Future<RpcResult<Void>>>() {
45
46                     @Override
47                     public Future<RpcResult<Void>> apply(final DataCrate<GetFlowTablesStatisticsOutput> data) {
48
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());
54
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);
60
61                         mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
62                         final Future<RpcResult<Void>> resultFromOFLib = deviceContext.getPrimaryConnectionContext()
63                                 .getConnectionAdapter().multipartRequest(mprInput.build());
64
65                         return JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
66                     }
67                 });
68     }
69
70 }