2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.impl.statistics.services;
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.RequestInputUtils;
17 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
18 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.FlowStatisticsToNotificationTransformer;
19 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
20 import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCase;
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;
34 public final class AllFlowsInAllTablesService extends AbstractCompatibleStatService<GetAllFlowsStatisticsFromAllFlowTablesInput,
35 GetAllFlowsStatisticsFromAllFlowTablesOutput, FlowsStatisticsUpdate> {
36 private final MultipartRequestFlowCase flowCase;
37 private final ConvertorExecutor convertorExecutor;
39 public AllFlowsInAllTablesService(final RequestContextStack requestContextStack, final DeviceContext deviceContext,
40 final AtomicLong compatibilityXidSeed, final ConvertorExecutor convertorExecutor) {
41 super(requestContextStack, deviceContext, compatibilityXidSeed);
42 this.convertorExecutor = convertorExecutor;
44 final MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
45 final MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
46 mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL);
47 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
48 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
49 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
50 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
51 FlowCreatorUtil.setWildcardedFlowMatch(getVersion(), mprFlowRequestBuilder);
52 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
54 flowCase = multipartRequestFlowCaseBuilder.build();
58 protected OfHeader buildRequest(final Xid xid, final GetAllFlowsStatisticsFromAllFlowTablesInput input) {
59 final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
60 MultipartType.OFPMPFLOW, xid.getValue(), getVersion());
61 mprInput.setMultipartRequestBody(flowCase);
63 return mprInput.build();
67 public GetAllFlowsStatisticsFromAllFlowTablesOutput buildTxCapableResult(TransactionId emulatedTxId) {
68 return new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder().setTransactionId(emulatedTxId).build();
72 public FlowsStatisticsUpdate transformToNotification(List<MultipartReply> result, TransactionId emulatedTxId) {
73 return FlowStatisticsToNotificationTransformer.transformToNotification(result, getDeviceInfo(), getOfVersion(), emulatedTxId, convertorExecutor);