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.ArrayList;
14 import java.util.List;
15 import javax.inject.Inject;
16 import javax.inject.Singleton;
17 import org.eclipse.jdt.annotation.Nullable;
18 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.OpendaylightDirectStatisticsService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.AclLiveStatisticsService;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.Direction;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.GetAclPortStatisticsInput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.GetAclPortStatisticsOutput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.GetAclPortStatisticsOutputBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.AclPortStats;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.config.rev160806.AclserviceConfig;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.config.rev160806.AclserviceConfig.SecurityGroupMode;
28 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
29 import org.opendaylight.yangtools.yang.common.RpcResult;
30 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
35 * The class provides RPC service implementation for
36 * {@link AclLiveStatisticsService}.
39 public class AclLiveStatisticsRpcServiceImpl implements AclLiveStatisticsService {
41 private static final Logger LOG = LoggerFactory.getLogger(AclLiveStatisticsRpcServiceImpl.class);
43 private final DataBroker dataBroker;
44 private final OpendaylightDirectStatisticsService odlDirectStatsService;
45 private final SecurityGroupMode securityGroupMode;
48 * Instantiates a new acl live statistics rpc service impl.
50 * @param config the config
51 * @param dataBroker the data broker
52 * @param odlDirectStatsService the odl direct stats service
55 public AclLiveStatisticsRpcServiceImpl(final AclserviceConfig config, final DataBroker dataBroker,
56 final OpendaylightDirectStatisticsService odlDirectStatsService) {
57 this.dataBroker = dataBroker;
58 this.odlDirectStatsService = odlDirectStatsService;
59 this.securityGroupMode = config == null ? SecurityGroupMode.Stateful : config.getSecurityGroupMode();
61 LOG.info("AclLiveStatisticsRpcServiceImpl initialized");
65 public ListenableFuture<RpcResult<GetAclPortStatisticsOutput>> getAclPortStatistics(
66 GetAclPortStatisticsInput input) {
67 LOG.trace("Get ACL port statistics for input: {}", input);
68 RpcResultBuilder<GetAclPortStatisticsOutput> rpcResultBuilder;
70 if (this.securityGroupMode != SecurityGroupMode.Stateful) {
71 rpcResultBuilder = RpcResultBuilder.failed();
72 rpcResultBuilder.withError(ErrorType.APPLICATION, "operation-not-supported",
73 "Operation not supported for ACL " + this.securityGroupMode + " mode");
74 return rpcResultBuilder.buildFuture();
76 // Default direction is Both
77 Direction direction = input.getDirection() == null ? Direction.Both : input.getDirection();
79 @Nullable List<String> interfaceNames = input.getInterfaceNames();
80 List<AclPortStats> lstAclInterfaceStats =
81 interfaceNames != null ? AclLiveStatisticsHelper.getAclPortStats(direction, interfaceNames,
82 this.odlDirectStatsService, this.dataBroker) : new ArrayList<>();
84 GetAclPortStatisticsOutputBuilder output =
85 new GetAclPortStatisticsOutputBuilder().setAclPortStats(lstAclInterfaceStats);
86 rpcResultBuilder = RpcResultBuilder.success();
87 rpcResultBuilder.withResult(output.build());
88 return Futures.immediateFuture(rpcResultBuilder.build());