Merge "Fix codestyle"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / services / AllFlowsInAllTablesService.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.openflow.md.core.sal.convertor.ConvertorExecutor;
21 import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
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.GetAllFlowsStatisticsFromAllFlowTablesInput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder;
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.MultipartRequestFlowCase;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
34
35 public final class AllFlowsInAllTablesService extends
36         AbstractCompatibleStatService<GetAllFlowsStatisticsFromAllFlowTablesInput,
37                                       GetAllFlowsStatisticsFromAllFlowTablesOutput,
38                                       FlowsStatisticsUpdate> {
39     private final MultipartRequestFlowCase flowCase;
40     private final ConvertorExecutor convertorExecutor;
41
42     public AllFlowsInAllTablesService(final RequestContextStack requestContextStack,
43                                       final DeviceContext deviceContext,
44                                       final AtomicLong compatibilityXidSeed,
45                                       final ConvertorExecutor convertorExecutor) {
46         super(requestContextStack, deviceContext, compatibilityXidSeed);
47         this.convertorExecutor = convertorExecutor;
48
49         final MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
50         final MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
51         mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL);
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         FlowCreatorUtil.setWildcardedFlowMatch(getVersion(), mprFlowRequestBuilder);
57         multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
58
59         flowCase = multipartRequestFlowCaseBuilder.build();
60     }
61
62     @Override
63     protected OfHeader buildRequest(final Xid xid,
64                                     final GetAllFlowsStatisticsFromAllFlowTablesInput input) throws ServiceException {
65         final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
66                 MultipartType.OFPMPFLOW, xid.getValue(), getVersion());
67         mprInput.setMultipartRequestBody(flowCase);
68
69         return mprInput.build();
70     }
71
72     @Override
73     public GetAllFlowsStatisticsFromAllFlowTablesOutput buildTxCapableResult(TransactionId emulatedTxId) {
74         return new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder().setTransactionId(emulatedTxId).build();
75     }
76
77     @Override
78     public FlowsStatisticsUpdate transformToNotification(List<MultipartReply> result, TransactionId emulatedTxId) {
79         return FlowStatisticsToNotificationTransformer.transformToNotification(result,
80                                                                                getDeviceInfo(),
81                                                                                getOfVersion(),
82                                                                                emulatedTxId,
83                                                                                convertorExecutor);
84     }
85 }