Simplify CommonService interface
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / services / AggregateFlowsInTableService.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 org.opendaylight.openflowplugin.api.OFConstants;
11 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
12 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
13 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
14 import org.opendaylight.openflowplugin.impl.services.AbstractSimpleService;
15 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
16 import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
24
25 final class AggregateFlowsInTableService extends AbstractSimpleService<GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput, GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput> {
26     public AggregateFlowsInTableService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
27         super(requestContextStack, deviceContext, GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput.class);
28     }
29
30     @Override
31     protected OfHeader buildRequest(final Xid xid, final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) {
32         // Create multipart request body for fetch all the group stats
33         final MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
34         final MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
35         mprAggregateRequestBuilder.setTableId(input.getTableId().getValue());
36         mprAggregateRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
37         mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
38         mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
39         mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
40         final short version = getVersion();
41         FlowCreatorUtil.setWildcardedFlowMatch(version, mprAggregateRequestBuilder);
42
43         // Set request body to main multipart request
44         multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder
45                 .build());
46         final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
47                 MultipartType.OFPMPAGGREGATE, xid.getValue(), version);
48
49         mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
50
51         return mprInput.build();
52     }
53 }