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.MessageTranslator;
17 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
18 import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
19 import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
20 import org.opendaylight.openflowplugin.api.openflow.statistics.compatibility.Delegator;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.get.aggregate.flow.statistics.from.flow.table._for.given.match.output.AggregatedFlowStatistics;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase;
36 import org.opendaylight.yangtools.yang.common.RpcResult;
37 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
44 public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowStatisticsService, Delegator<OpendaylightFlowStatisticsService> {
46 private static final Logger LOG = LoggerFactory.getLogger(OpendaylightFlowStatisticsServiceImpl.class);
48 private final Function<RpcResult<List<MultipartReply>>, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> matchingConvertor =
49 new Function<RpcResult<List<MultipartReply>>, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>>() {
51 public RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> apply(final RpcResult<List<MultipartReply>> input) {
52 final DeviceContext deviceContext = matchingFlowsInTable.getDeviceContext();
53 TranslatorLibrary translatorLibrary = deviceContext.oook();
54 final RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> rpcResult;
55 if (input.isSuccessful()) {
56 MultipartReply reply = input.getResult().get(0);
57 final TranslatorKey translatorKey = new TranslatorKey(reply.getVersion(), MultipartReplyAggregateCase.class.getName());
58 final MessageTranslator<MultipartReply, AggregatedFlowStatistics> messageTranslator = translatorLibrary.lookupTranslator(translatorKey);
59 List<AggregatedFlowStatistics> aggregStats = new ArrayList<AggregatedFlowStatistics>();
61 for (MultipartReply multipartReply : input.getResult()) {
62 aggregStats.add(messageTranslator.translate(multipartReply, deviceContext, null));
65 GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder =
66 new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder();
67 getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.setAggregatedFlowStatistics(aggregStats);
69 rpcResult = RpcResultBuilder
70 .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>success()
71 .withResult(getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.build())
75 rpcResult = RpcResultBuilder
76 .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>failed()
77 .withRpcErrors(input.getErrors())
84 private final MatchingFlowsInTableService matchingFlowsInTable;
85 private OpendaylightFlowStatisticsService delegate;
87 public OpendaylightFlowStatisticsServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
88 matchingFlowsInTable = new MatchingFlowsInTableService(requestContextStack, deviceContext);
92 public void setDelegate(OpendaylightFlowStatisticsService delegate) {
93 this.delegate = delegate;
97 * @deprecated provided for Be-release as backward compatibility relic
101 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> getAggregateFlowStatisticsFromFlowTableForAllFlows(
102 final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) {
103 if (delegate != null) {
104 return delegate.getAggregateFlowStatisticsFromFlowTableForAllFlows(input);
106 throw new IllegalAccessError("no delegate available - service is currently out of order");
111 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> getAggregateFlowStatisticsFromFlowTableForGivenMatch(
112 final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
113 return Futures.transform(matchingFlowsInTable.handleServiceCall(input), matchingConvertor);
117 * @deprecated provided for Be-release as backward compatibility relic
121 public Future<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable(
122 final GetAllFlowStatisticsFromFlowTableInput input) {
123 if (delegate != null) {
124 return delegate.getAllFlowStatisticsFromFlowTable(input);
126 throw new IllegalAccessError("no delegate available - service is currently out of order");
131 * @deprecated provided for Be-release as backward compatibility relic
135 public Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> getAllFlowsStatisticsFromAllFlowTables(
136 final GetAllFlowsStatisticsFromAllFlowTablesInput input) {
137 if (delegate != null) {
138 return delegate.getAllFlowsStatisticsFromAllFlowTables(input);
140 throw new IllegalAccessError("no delegate available - service is currently out of order");
145 * @deprecated provided for Be-release as backward compatibility relic
149 public Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable(
150 final GetFlowStatisticsFromFlowTableInput input) {
151 if (delegate != null) {
152 return delegate.getFlowStatisticsFromFlowTable(input);
154 throw new IllegalAccessError("no delegate available - service is currently out of order");