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.direct;
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.registry.flow.FlowRegistryKey;
15 import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider;
16 import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory;
17 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
18 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsData;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsDataBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatisticsBuilder;
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.OfHeader;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.MultipartRequestBody;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
34 * The Flow direct statistics service.
36 public abstract class AbstractFlowDirectStatisticsService<T extends OfHeader>
37 extends AbstractDirectStatisticsService<GetFlowStatisticsInput, GetFlowStatisticsOutput, T> {
39 protected AbstractFlowDirectStatisticsService(final RequestContextStack requestContextStack,
40 final DeviceContext deviceContext,
41 final ConvertorExecutor convertorExecutor,
42 final MultipartWriterProvider statisticsWriterProvider) {
43 super(MultipartType.OFPMPFLOW, requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider);
47 public MultipartRequestBody buildRequestBody(GetFlowStatisticsInput input) {
48 final MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
50 if (input.getTableId() != null) {
51 mprFlowRequestBuilder.setTableId(input.getTableId());
53 mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL);
56 if (input.getOutPort() != null) {
57 mprFlowRequestBuilder.setOutPort(input.getOutPort().longValue());
59 mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
62 if (input.getOutGroup() != null) {
63 mprFlowRequestBuilder.setOutGroup(input.getOutGroup());
65 mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
68 if (input.getCookie() != null) {
69 mprFlowRequestBuilder.setCookie(input.getCookie().getValue());
71 mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
74 if (input.getCookieMask() != null) {
75 mprFlowRequestBuilder.setCookieMask(input.getCookieMask().getValue());
77 mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
80 MatchReactor.getInstance().convert(input.getMatch(), getVersion(), mprFlowRequestBuilder, getConvertorExecutor());
82 return new MultipartRequestFlowCaseBuilder()
83 .setMultipartRequestFlow(mprFlowRequestBuilder.build())
88 * Get flow ID from #{@link org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry} or
90 * @param flowStatistics flow statistics
91 * @return generated flow ID
93 protected FlowId generateFlowId(FlowAndStatisticsMapList flowStatistics) {
94 final FlowStatisticsDataBuilder flowStatisticsDataBld = new FlowStatisticsDataBuilder()
95 .setFlowStatistics(new FlowStatisticsBuilder(flowStatistics).build());
97 final FlowBuilder flowBuilder = new FlowBuilder(flowStatistics)
98 .addAugmentation(FlowStatisticsData.class, flowStatisticsDataBld.build());
100 final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(getVersion(), flowBuilder.build());
102 getDeviceRegistry().getDeviceFlowRegistry().store(flowRegistryKey);
103 return getDeviceRegistry().getDeviceFlowRegistry().retrieveDescriptor(flowRegistryKey).getFlowId();