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.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.get.aggregate.flow.statistics.from.flow.table._for.given.match.output.AggregatedFlowStatistics;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase;
35 import org.opendaylight.yangtools.yang.common.RpcResult;
36 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
43 public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowStatisticsService {
44 private static final Logger LOG = LoggerFactory.getLogger(OpendaylightFlowStatisticsServiceImpl.class);
46 private final Function<RpcResult<List<MultipartReply>>, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> matchingConvertor =
47 new Function<RpcResult<List<MultipartReply>>, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>>() {
49 public RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> apply(final RpcResult<List<MultipartReply>> input) {
50 final DeviceContext deviceContext = matchingFlowsInTable.getDeviceContext();
51 TranslatorLibrary translatorLibrary = deviceContext.oook();
52 RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> rpcResult;
53 if (input.isSuccessful()) {
54 MultipartReply reply = input.getResult().get(0);
55 final TranslatorKey translatorKey = new TranslatorKey(reply.getVersion(), MultipartReplyAggregateCase.class.getName());
56 final MessageTranslator<MultipartReply, AggregatedFlowStatistics> messageTranslator = translatorLibrary.lookupTranslator(translatorKey);
57 List<AggregatedFlowStatistics> aggregStats = new ArrayList<AggregatedFlowStatistics>();
59 for (MultipartReply multipartReply : input.getResult()) {
60 aggregStats.add(messageTranslator.translate(multipartReply, deviceContext, null));
63 GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder =
64 new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder();
65 getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.setAggregatedFlowStatistics(aggregStats);
67 rpcResult = RpcResultBuilder
68 .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>success()
69 .withResult(getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.build())
73 rpcResult = RpcResultBuilder
74 .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>failed()
75 .withRpcErrors(input.getErrors())
82 private final AggregateFlowsInTableService aggregateFlowsInTable;
83 private final MatchingFlowsInTableService matchingFlowsInTable;
84 private final AllFlowsInAllTablesService allFlowsInAllTables;
85 private final AllFlowsInTableService allFlowsInTable;
86 private final FlowsInTableService flowsInTable;
88 public OpendaylightFlowStatisticsServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
89 aggregateFlowsInTable = new AggregateFlowsInTableService(requestContextStack, deviceContext);
90 allFlowsInAllTables = new AllFlowsInAllTablesService(requestContextStack, deviceContext);
91 allFlowsInTable = new AllFlowsInTableService(requestContextStack, deviceContext);
92 flowsInTable = new FlowsInTableService(requestContextStack, deviceContext);
93 matchingFlowsInTable = new MatchingFlowsInTableService(requestContextStack, deviceContext);
97 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> getAggregateFlowStatisticsFromFlowTableForAllFlows(
98 final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) {
99 return aggregateFlowsInTable.handleServiceCall(input);
103 public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> getAggregateFlowStatisticsFromFlowTableForGivenMatch(
104 final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
105 return Futures.transform(matchingFlowsInTable.handleServiceCall(input), matchingConvertor);
109 public Future<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable(
110 final GetAllFlowStatisticsFromFlowTableInput input) {
111 return allFlowsInTable.handleServiceCall(input);
115 public Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> getAllFlowsStatisticsFromAllFlowTables(
116 final GetAllFlowsStatisticsFromAllFlowTablesInput input) {
117 return allFlowsInAllTables.handleServiceCall(input);
121 public Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable(
122 final GetFlowStatisticsFromFlowTableInput input) {
123 return flowsInTable.handleServiceCall(input);