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.Function;
11 import com.google.common.util.concurrent.Futures;
12 import java.util.ArrayList;
13 import java.util.List;
14 import java.util.concurrent.Future;
15 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
16 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
17 import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
18 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
19 import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
20 import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
21 import org.opendaylight.openflowplugin.api.openflow.statistics.compatibility.Delegator;
22 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.get.aggregate.flow.statistics.from.flow.table._for.given.match.output.AggregatedFlowStatistics;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase;
38 import org.opendaylight.yangtools.yang.common.RpcResult;
39 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
46 public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowStatisticsService, Delegator<OpendaylightFlowStatisticsService> {
48 private static final Logger LOG = LoggerFactory.getLogger(OpendaylightFlowStatisticsServiceImpl.class);
50 private final Function<RpcResult<List<MultipartReply>>, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> matchingConvertor =
51 new Function<RpcResult<List<MultipartReply>>, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>>() {
53 public RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> apply(final RpcResult<List<MultipartReply>> input) {
54 final DeviceInfo deviceInfo = matchingFlowsInTable.getDeviceInfo();
55 final RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> rpcResult;
56 if (input.isSuccessful()) {
57 MultipartReply reply = input.getResult().get(0);
58 final TranslatorKey translatorKey = new TranslatorKey(reply.getVersion(), MultipartReplyAggregateCase.class.getName());
59 final MessageTranslator<MultipartReply, AggregatedFlowStatistics> messageTranslator = translatorLibrary.lookupTranslator(translatorKey);
60 List<AggregatedFlowStatistics> aggregStats = new ArrayList<AggregatedFlowStatistics>();
62 for (MultipartReply multipartReply : input.getResult()) {
63 aggregStats.add(messageTranslator.translate(multipartReply, deviceInfo, null));
66 GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder =
67 new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder();
68 getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.setAggregatedFlowStatistics(aggregStats);
70 rpcResult = RpcResultBuilder
71 .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>success()
72 .withResult(getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.build())
76 rpcResult = RpcResultBuilder
77 .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>failed()
78 .withRpcErrors(input.getErrors())
85 private final MatchingFlowsInTableService matchingFlowsInTable;
86 private final TranslatorLibrary translatorLibrary;
87 private OpendaylightFlowStatisticsService delegate;
89 public static OpendaylightFlowStatisticsServiceImpl createWithOook(final RequestContextStack requestContextStack,
90 final DeviceContext deviceContext, final ConvertorExecutor convertorExecutor) {
91 return new OpendaylightFlowStatisticsServiceImpl(requestContextStack, deviceContext, deviceContext.oook(), convertorExecutor);
94 public OpendaylightFlowStatisticsServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext,
95 final TranslatorLibrary translatorLibrary, final ConvertorExecutor convertorExecutor) {
96 matchingFlowsInTable = new MatchingFlowsInTableService(requestContextStack, deviceContext, convertorExecutor);
97 this.translatorLibrary = translatorLibrary;
101 public void setDelegate(OpendaylightFlowStatisticsService delegate) {
102 this.delegate = delegate;
106 * @deprecated provided for Be-release as backward compatibility relic
110 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> getAggregateFlowStatisticsFromFlowTableForAllFlows(
111 final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) {
112 if (delegate != null) {
113 return delegate.getAggregateFlowStatisticsFromFlowTableForAllFlows(input);
115 throw new IllegalAccessError("no delegate available - service is currently out of order");
120 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> getAggregateFlowStatisticsFromFlowTableForGivenMatch(
121 final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
122 return Futures.transform(matchingFlowsInTable.handleServiceCall(input), matchingConvertor);
126 * @deprecated provided for Be-release as backward compatibility relic
130 public Future<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable(
131 final GetAllFlowStatisticsFromFlowTableInput input) {
132 if (delegate != null) {
133 return delegate.getAllFlowStatisticsFromFlowTable(input);
135 throw new IllegalAccessError("no delegate available - service is currently out of order");
140 * @deprecated provided for Be-release as backward compatibility relic
144 public Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> getAllFlowsStatisticsFromAllFlowTables(
145 final GetAllFlowsStatisticsFromAllFlowTablesInput input) {
146 if (delegate != null) {
147 return delegate.getAllFlowsStatisticsFromAllFlowTables(input);
149 throw new IllegalAccessError("no delegate available - service is currently out of order");
154 * @deprecated provided for Be-release as backward compatibility relic
158 public Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable(
159 final GetFlowStatisticsFromFlowTableInput input) {
160 if (delegate != null) {
161 return delegate.getFlowStatisticsFromFlowTable(input);
163 throw new IllegalAccessError("no delegate available - service is currently out of order");