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 org.opendaylight.openflowplugin.api.OFConstants;
11 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
12 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
13 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
14 import org.opendaylight.openflowplugin.impl.services.AbstractSimpleService;
15 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
16 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
25 final class FlowsInTableService extends AbstractSimpleService<GetFlowStatisticsFromFlowTableInput, GetFlowStatisticsFromFlowTableOutput> {
26 FlowsInTableService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
27 super(requestContextStack, deviceContext, GetFlowStatisticsFromFlowTableOutput.class);
31 protected OfHeader buildRequest(final Xid xid, final GetFlowStatisticsFromFlowTableInput input) {
32 final MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
33 final MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
34 mprFlowRequestBuilder.setTableId(input.getTableId());
36 if (input.getOutPort() != null) {
37 mprFlowRequestBuilder.setOutPort(input.getOutPort().longValue());
39 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
42 if (input.getOutGroup() != null) {
43 mprFlowRequestBuilder.setOutGroup(input.getOutGroup());
45 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
48 if (input.getCookie() != null) {
49 mprFlowRequestBuilder.setCookie(input.getCookie().getValue());
51 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
54 if (input.getCookieMask() != null) {
55 mprFlowRequestBuilder.setCookieMask(input.getCookieMask().getValue());
57 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
60 // convert and inject match
61 final short version = getVersion();
62 final DeviceContext deviceContext = getDeviceContext();
63 MatchReactor.getInstance().convert(input.getMatch(), version, mprFlowRequestBuilder,
64 deviceContext.getPrimaryConnectionContext().getFeatures().getDatapathId());
66 // Set request body to main multipart request
67 multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
68 final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
69 MultipartType.OFPMPFLOW, xid.getValue(), version);
70 mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
72 return mprInput.build();