Merge "Remove redundant type specifiers"
[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 java.util.List;
11 import java.util.concurrent.atomic.AtomicLong;
12 import org.opendaylight.openflowplugin.api.OFConstants;
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.util.RequestInputUtils;
17 import org.opendaylight.openflowplugin.impl.services.util.ServiceException;
18 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
19 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.FlowStatisticsToNotificationTransformer;
20 import org.opendaylight.openflowplugin.impl.util.FlowCreatorUtil;
21 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutputBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
33
34 public class AllFlowsInTableService extends AbstractCompatibleStatService<GetAllFlowStatisticsFromFlowTableInput,
35         GetAllFlowStatisticsFromFlowTableOutput, FlowsStatisticsUpdate> {
36
37     private final ConvertorExecutor convertorExecutor;
38
39     public AllFlowsInTableService(final RequestContextStack requestContextStack,
40                                   final DeviceContext deviceContext,
41                                   AtomicLong compatibilityXidSeed,
42                                   ConvertorExecutor convertorExecutor) {
43         super(requestContextStack, deviceContext, compatibilityXidSeed);
44         this.convertorExecutor = convertorExecutor;
45     }
46
47     @Override
48     protected OfHeader buildRequest(final Xid xid,
49                                     final GetAllFlowStatisticsFromFlowTableInput input) throws ServiceException {
50         final MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
51         mprFlowRequestBuilder.setTableId(input.getTableId().getValue());
52         mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
53         mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
54         mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
55         mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
56
57         final short version = getVersion();
58         FlowCreatorUtil.setWildcardedFlowMatch(version, mprFlowRequestBuilder);
59
60         final MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
61         multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
62
63         final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
64                 MultipartType.OFPMPFLOW, xid.getValue(), version);
65
66         mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
67
68         return mprInput.build();
69     }
70
71     @Override
72     public GetAllFlowStatisticsFromFlowTableOutput buildTxCapableResult(TransactionId emulatedTxId) {
73         return new GetAllFlowStatisticsFromFlowTableOutputBuilder()
74                 .setTransactionId(emulatedTxId)
75                 .build();
76     }
77
78     @Override
79     public FlowsStatisticsUpdate transformToNotification(List<MultipartReply> mpResult, TransactionId emulatedTxId) {
80         return FlowStatisticsToNotificationTransformer.transformToNotification(mpResult,
81                                                                                getDeviceInfo(),
82                                                                                getOfVersion(),
83                                                                                emulatedTxId,
84                                                                                convertorExecutor);
85     }
86 }