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 com.google.common.base.MoreObjects;
11 import org.opendaylight.openflowplugin.api.OFConstants;
12 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
13 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
14 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
15 import org.opendaylight.openflowplugin.impl.services.AbstractMultipartService;
16 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
17 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
18 import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
26 final class MatchingFlowsInTableService extends AbstractMultipartService<GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput> {
28 public MatchingFlowsInTableService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
29 super(requestContextStack, deviceContext);
33 protected OfHeader buildRequest(final Xid xid, final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
34 final DeviceContext deviceContext = getDeviceContext();
35 final MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
36 final MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
37 final short tableId = MoreObjects.firstNonNull(input.getTableId(), OFConstants.OFPTT_ALL).shortValue();
38 mprAggregateRequestBuilder.setTableId(tableId);
39 long outputPortValue = MoreObjects.firstNonNull(input.getOutPort(), OFConstants.OFPP_ANY).longValue();
40 mprAggregateRequestBuilder.setOutPort(outputPortValue);
42 final short version = getVersion();
43 if (version == OFConstants.OFP_VERSION_1_3) {
45 if (input.getCookie() == null) {
46 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
48 mprAggregateRequestBuilder.setCookie(MoreObjects.firstNonNull(input.getCookie().getValue(), OFConstants.DEFAULT_COOKIE));
51 if (input.getCookieMask() == null) {
52 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
54 mprAggregateRequestBuilder.setCookieMask(MoreObjects.firstNonNull(input.getCookieMask().getValue(), OFConstants.DEFAULT_COOKIE_MASK));
56 long outGroup = MoreObjects.firstNonNull(input.getOutGroup(), OFConstants.OFPG_ANY).longValue();
57 mprAggregateRequestBuilder.setOutGroup(outGroup);
59 mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
60 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
61 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
64 MatchReactor.getInstance().convert(input.getMatch(), version, mprAggregateRequestBuilder, getDatapathId());
66 FlowCreatorUtil.setWildcardedFlowMatch(version, mprAggregateRequestBuilder);
68 // Set request body to main multipart request
69 multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder
72 final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
73 MultipartType.OFPMPAGGREGATE, xid.getValue(), version);
75 mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
77 return mprInput.build();