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.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.get.aggregate.flow.statistics.from.flow.table._for.given.match.output.AggregatedFlowStatistics;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase;
37 import org.opendaylight.yangtools.yang.common.RpcResult;
38 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
45 public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowStatisticsService, Delegator<OpendaylightFlowStatisticsService> {
47 private static final Logger LOG = LoggerFactory.getLogger(OpendaylightFlowStatisticsServiceImpl.class);
49 private final Function<RpcResult<List<MultipartReply>>, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> matchingConvertor =
50 new Function<RpcResult<List<MultipartReply>>, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>>() {
52 public RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> apply(final RpcResult<List<MultipartReply>> input) {
53 final DeviceInfo deviceInfo = matchingFlowsInTable.getDeviceInfo();
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, deviceInfo, 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 final TranslatorLibrary translatorLibrary;
86 private OpendaylightFlowStatisticsService delegate;
88 public static OpendaylightFlowStatisticsServiceImpl createWithOook(final RequestContextStack requestContextStack,
89 final DeviceContext deviceContext) {
90 return new OpendaylightFlowStatisticsServiceImpl(requestContextStack, deviceContext, deviceContext.oook());
93 public OpendaylightFlowStatisticsServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext,
94 final TranslatorLibrary translatorLibrary) {
95 matchingFlowsInTable = new MatchingFlowsInTableService(requestContextStack, deviceContext);
96 this.translatorLibrary = translatorLibrary;
100 public void setDelegate(OpendaylightFlowStatisticsService delegate) {
101 this.delegate = delegate;
105 * @deprecated provided for Be-release as backward compatibility relic
109 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> getAggregateFlowStatisticsFromFlowTableForAllFlows(
110 final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) {
111 if (delegate != null) {
112 return delegate.getAggregateFlowStatisticsFromFlowTableForAllFlows(input);
114 throw new IllegalAccessError("no delegate available - service is currently out of order");
119 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> getAggregateFlowStatisticsFromFlowTableForGivenMatch(
120 final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
121 return Futures.transform(matchingFlowsInTable.handleServiceCall(input), matchingConvertor);
125 * @deprecated provided for Be-release as backward compatibility relic
129 public Future<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable(
130 final GetAllFlowStatisticsFromFlowTableInput input) {
131 if (delegate != null) {
132 return delegate.getAllFlowStatisticsFromFlowTable(input);
134 throw new IllegalAccessError("no delegate available - service is currently out of order");
139 * @deprecated provided for Be-release as backward compatibility relic
143 public Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> getAllFlowsStatisticsFromAllFlowTables(
144 final GetAllFlowsStatisticsFromAllFlowTablesInput input) {
145 if (delegate != null) {
146 return delegate.getAllFlowsStatisticsFromAllFlowTables(input);
148 throw new IllegalAccessError("no delegate available - service is currently out of order");
153 * @deprecated provided for Be-release as backward compatibility relic
157 public Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable(
158 final GetFlowStatisticsFromFlowTableInput input) {
159 if (delegate != null) {
160 return delegate.getFlowStatisticsFromFlowTable(input);
162 throw new IllegalAccessError("no delegate available - service is currently out of order");