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
9 package org.opendaylight.openflowplugin.impl.statistics.services;
11 import java.util.List;
12 import java.util.concurrent.atomic.AtomicLong;
13 import org.opendaylight.openflowplugin.api.OFConstants;
14 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
15 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
16 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
17 import org.opendaylight.openflowplugin.impl.services.util.RequestInputUtils;
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.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;
35 public final class AllFlowsInAllTablesService extends
36 AbstractCompatibleStatService<GetAllFlowsStatisticsFromAllFlowTablesInput,
37 GetAllFlowsStatisticsFromAllFlowTablesOutput, FlowsStatisticsUpdate> {
38 private final MultipartRequestFlowCase flowCase;
39 private final ConvertorExecutor convertorExecutor;
41 public AllFlowsInAllTablesService(final RequestContextStack requestContextStack, final DeviceContext deviceContext,
42 final AtomicLong compatibilityXidSeed,
43 final ConvertorExecutor convertorExecutor) {
44 super(requestContextStack, deviceContext, compatibilityXidSeed);
45 this.convertorExecutor = convertorExecutor;
47 final MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
48 final MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
49 mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL);
50 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
51 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
52 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
53 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
54 FlowCreatorUtil.setWildcardedFlowMatch(getVersion(), mprFlowRequestBuilder);
55 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
57 flowCase = multipartRequestFlowCaseBuilder.build();
61 protected OfHeader buildRequest(final Xid xid,
62 final GetAllFlowsStatisticsFromAllFlowTablesInput input) {
63 final MultipartRequestInputBuilder mprInput = RequestInputUtils
64 .createMultipartHeader(MultipartType.OFPMPFLOW, xid.getValue(), getVersion());
65 mprInput.setMultipartRequestBody(flowCase);
67 return mprInput.build();
71 public GetAllFlowsStatisticsFromAllFlowTablesOutput buildTxCapableResult(TransactionId emulatedTxId) {
72 return new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder().setTransactionId(emulatedTxId).build();
76 public FlowsStatisticsUpdate transformToNotification(List<MultipartReply> result, TransactionId emulatedTxId) {
77 return FlowStatisticsToNotificationTransformer
78 .transformToNotification(result, getDeviceInfo(), getOfVersion(), emulatedTxId, convertorExecutor);