Simplify CommonService interface
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / services / AllFlowsInTableService.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.GetAllFlowStatisticsFromFlowTableInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
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.MultipartRequestFlowCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
24
25 public class AllFlowsInTableService extends AbstractSimpleService<GetAllFlowStatisticsFromFlowTableInput, GetAllFlowStatisticsFromFlowTableOutput> {
26
27     public AllFlowsInTableService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
28         super(requestContextStack, deviceContext, GetAllFlowStatisticsFromFlowTableOutput.class);
29     }
30
31     @Override
32     protected OfHeader buildRequest(final Xid xid, final GetAllFlowStatisticsFromFlowTableInput input) {
33         final MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
34         mprFlowRequestBuilder.setTableId(input.getTableId().getValue());
35         mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
36         mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
37         mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
38         mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
39
40         final short version = getVersion();
41         FlowCreatorUtil.setWildcardedFlowMatch(version, mprFlowRequestBuilder);
42
43         final MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
44         multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
45
46         final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
47                 MultipartType.OFPMPFLOW, xid.getValue(), version);
48
49         mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
50
51         return mprInput.build();
52     }
53 }