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 final RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> rpcResult;
54 if (input.isSuccessful()) {
55 MultipartReply reply = input.getResult().get(0);
56 final TranslatorKey translatorKey = new TranslatorKey(reply.getVersion(), MultipartReplyAggregateCase.class.getName());
57 final MessageTranslator<MultipartReply, AggregatedFlowStatistics> messageTranslator = translatorLibrary.lookupTranslator(translatorKey);
58 List<AggregatedFlowStatistics> aggregStats = new ArrayList<AggregatedFlowStatistics>();
60 for (MultipartReply multipartReply : input.getResult()) {
61 aggregStats.add(messageTranslator.translate(multipartReply, deviceContext.getDeviceState(), null));
64 GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder =
65 new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder();
66 getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.setAggregatedFlowStatistics(aggregStats);
68 rpcResult = RpcResultBuilder
69 .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>success()
70 .withResult(getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.build())
74 rpcResult = RpcResultBuilder
75 .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>failed()
76 .withRpcErrors(input.getErrors())
83 private final MatchingFlowsInTableService matchingFlowsInTable;
84 private final TranslatorLibrary translatorLibrary;
85 private OpendaylightFlowStatisticsService delegate;
87 public static OpendaylightFlowStatisticsServiceImpl createWithOook(final RequestContextStack requestContextStack,
88 final DeviceContext deviceContext) {
89 return new OpendaylightFlowStatisticsServiceImpl(requestContextStack, deviceContext, deviceContext.oook());
92 public OpendaylightFlowStatisticsServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext,
93 final TranslatorLibrary translatorLibrary) {
94 matchingFlowsInTable = new MatchingFlowsInTableService(requestContextStack, deviceContext);
95 this.translatorLibrary = translatorLibrary;
99 public void setDelegate(OpendaylightFlowStatisticsService delegate) {
100 this.delegate = delegate;
104 * @deprecated provided for Be-release as backward compatibility relic
108 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> getAggregateFlowStatisticsFromFlowTableForAllFlows(
109 final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) {
110 if (delegate != null) {
111 return delegate.getAggregateFlowStatisticsFromFlowTableForAllFlows(input);
113 throw new IllegalAccessError("no delegate available - service is currently out of order");
118 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> getAggregateFlowStatisticsFromFlowTableForGivenMatch(
119 final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
120 return Futures.transform(matchingFlowsInTable.handleServiceCall(input), matchingConvertor);
124 * @deprecated provided for Be-release as backward compatibility relic
128 public Future<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable(
129 final GetAllFlowStatisticsFromFlowTableInput input) {
130 if (delegate != null) {
131 return delegate.getAllFlowStatisticsFromFlowTable(input);
133 throw new IllegalAccessError("no delegate available - service is currently out of order");
138 * @deprecated provided for Be-release as backward compatibility relic
142 public Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> getAllFlowsStatisticsFromAllFlowTables(
143 final GetAllFlowsStatisticsFromAllFlowTablesInput input) {
144 if (delegate != null) {
145 return delegate.getAllFlowsStatisticsFromAllFlowTables(input);
147 throw new IllegalAccessError("no delegate available - service is currently out of order");
152 * @deprecated provided for Be-release as backward compatibility relic
156 public Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable(
157 final GetFlowStatisticsFromFlowTableInput input) {
158 if (delegate != null) {
159 return delegate.getFlowStatisticsFromFlowTable(input);
161 throw new IllegalAccessError("no delegate available - service is currently out of order");