2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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
9 package org.opendaylight.netvirt.aclservice.stats;
11 import com.google.common.util.concurrent.Futures;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import java.util.List;
14 import javax.inject.Inject;
15 import javax.inject.Singleton;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.OpendaylightDirectStatisticsService;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.AclLiveStatisticsService;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.Direction;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.GetAclPortStatisticsInput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.GetAclPortStatisticsOutput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.GetAclPortStatisticsOutputBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.AclPortStats;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.config.rev160806.AclserviceConfig;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.config.rev160806.AclserviceConfig.SecurityGroupMode;
26 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
27 import org.opendaylight.yangtools.yang.common.RpcResult;
28 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * The class provides RPC service implementation for
34 * {@link AclLiveStatisticsService}.
37 public class AclLiveStatisticsRpcServiceImpl implements AclLiveStatisticsService {
39 private static final Logger LOG = LoggerFactory.getLogger(AclLiveStatisticsRpcServiceImpl.class);
41 private final DataBroker dataBroker;
42 private final OpendaylightDirectStatisticsService odlDirectStatsService;
43 private final SecurityGroupMode securityGroupMode;
46 * Instantiates a new acl live statistics rpc service impl.
48 * @param config the config
49 * @param dataBroker the data broker
50 * @param odlDirectStatsService the odl direct stats service
53 public AclLiveStatisticsRpcServiceImpl(final AclserviceConfig config, final DataBroker dataBroker,
54 final OpendaylightDirectStatisticsService odlDirectStatsService) {
55 this.dataBroker = dataBroker;
56 this.odlDirectStatsService = odlDirectStatsService;
57 this.securityGroupMode = config == null ? SecurityGroupMode.Stateful : config.getSecurityGroupMode();
59 LOG.info("AclLiveStatisticsRpcServiceImpl initialized");
63 public ListenableFuture<RpcResult<GetAclPortStatisticsOutput>> getAclPortStatistics(
64 GetAclPortStatisticsInput input) {
65 LOG.trace("Get ACL port statistics for input: {}", input);
66 RpcResultBuilder<GetAclPortStatisticsOutput> rpcResultBuilder;
68 if (this.securityGroupMode != SecurityGroupMode.Stateful) {
69 rpcResultBuilder = RpcResultBuilder.failed();
70 rpcResultBuilder.withError(ErrorType.APPLICATION, "operation-not-supported",
71 "Operation not supported for ACL " + this.securityGroupMode + " mode");
72 return rpcResultBuilder.buildFuture();
74 // Default direction is Both
75 Direction direction = input.getDirection() == null ? Direction.Both : input.getDirection();
77 List<AclPortStats> lstAclInterfaceStats = AclLiveStatisticsHelper.getAclPortStats(direction,
78 input.getInterfaceNames(), this.odlDirectStatsService, this.dataBroker);
80 GetAclPortStatisticsOutputBuilder output =
81 new GetAclPortStatisticsOutputBuilder().setAclPortStats(lstAclInterfaceStats);
82 rpcResultBuilder = RpcResultBuilder.success();
83 rpcResultBuilder.withResult(output.build());
84 return Futures.immediateFuture(rpcResultBuilder.build());