Search in sources :

Example 1 with AclPortStats

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.AclPortStats in project netvirt by opendaylight.

the class AclLiveStatisticsHelper method getAclPortStats.

/**
 * Gets the acl port stats.
 *
 * @param direction the direction
 * @param interfaceNames the interface names
 * @param odlDirectStatsService the odl direct stats service
 * @param dataBroker the data broker
 * @return the acl port stats
 */
public static List<AclPortStats> getAclPortStats(Direction direction, List<String> interfaceNames, OpendaylightDirectStatisticsService odlDirectStatsService, DataBroker dataBroker) {
    LOG.trace("Get ACL port stats for direction {} and interfaces {}", direction, interfaceNames);
    List<AclPortStats> lstAclPortStats = new ArrayList<>();
    Short tableId = getTableId(direction);
    FlowCookie aclDropFlowCookie = new FlowCookie(AclConstants.COOKIE_ACL_DROP_FLOW);
    FlowCookie aclDropFlowCookieMask = new FlowCookie(COOKIE_ACL_DROP_FLOW_MASK);
    for (String interfaceName : interfaceNames) {
        AclPortStatsBuilder aclStatsBuilder = new AclPortStatsBuilder().setInterfaceName(interfaceName);
        Interface interfaceState = AclServiceUtils.getInterfaceStateFromOperDS(dataBroker, interfaceName);
        if (interfaceState == null) {
            String errMsg = "Interface not found in datastore.";
            addError(lstAclPortStats, aclStatsBuilder, errMsg);
            continue;
        }
        BigInteger dpId = AclServiceUtils.getDpIdFromIterfaceState(interfaceState);
        if (dpId == null) {
            String errMsg = "Failed to find device for the interface.";
            addError(lstAclPortStats, aclStatsBuilder, errMsg);
            continue;
        }
        NodeRef nodeRef = buildNodeRef(dpId);
        Integer lportTag = interfaceState.getIfIndex();
        Match metadataMatch = buildMetadataMatch(lportTag);
        GetFlowStatisticsInputBuilder input = new GetFlowStatisticsInputBuilder().setNode(nodeRef).setCookie(aclDropFlowCookie).setCookieMask(aclDropFlowCookieMask).setMatch(metadataMatch).setStoreStats(false);
        if (direction != Direction.Both) {
            input.setTableId(tableId);
        }
        Future<RpcResult<GetFlowStatisticsOutput>> rpcResultFuture = odlDirectStatsService.getFlowStatistics(input.build());
        RpcResult<GetFlowStatisticsOutput> rpcResult = null;
        try {
            rpcResult = rpcResultFuture.get();
        } catch (InterruptedException | ExecutionException e) {
            String errMsg = "Unable to retrieve drop counts due to error: " + e.getMessage();
            addError(lstAclPortStats, aclStatsBuilder, errMsg);
            LOG.error("Exception occurred during get flow statistics for interface {}", interfaceName, e);
        }
        if (rpcResult != null && rpcResult.isSuccessful() && rpcResult.getResult() != null) {
            GetFlowStatisticsOutput flowStatsOutput = rpcResult.getResult();
            getAclDropStats(direction, aclStatsBuilder, flowStatsOutput);
            lstAclPortStats.add(aclStatsBuilder.build());
        } else {
            handleRpcErrors(lstAclPortStats, aclStatsBuilder, rpcResult);
        }
    }
    return lstAclPortStats;
}
Also used : AclPortStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.AclPortStatsBuilder) ArrayList(java.util.ArrayList) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match) BigInteger(java.math.BigInteger) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) GetFlowStatisticsInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsInputBuilder) AclPortStats(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.AclPortStats) BigInteger(java.math.BigInteger) GetFlowStatisticsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput) ExecutionException(java.util.concurrent.ExecutionException) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface)

Example 2 with AclPortStats

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.AclPortStats in project netvirt by opendaylight.

the class AclLiveStatisticsRpcServiceImpl method getAclPortStatistics.

@Override
public Future<RpcResult<GetAclPortStatisticsOutput>> getAclPortStatistics(GetAclPortStatisticsInput input) {
    LOG.trace("Get ACL port statistics for input: {}", input);
    RpcResultBuilder<GetAclPortStatisticsOutput> rpcResultBuilder;
    if (this.securityGroupMode != SecurityGroupMode.Stateful) {
        rpcResultBuilder = RpcResultBuilder.failed();
        rpcResultBuilder.withError(ErrorType.APPLICATION, "operation-not-supported", "Operation not supported for ACL " + this.securityGroupMode + " mode");
        return Futures.immediateFuture(rpcResultBuilder.build());
    }
    // Default direction is Both
    Direction direction = input.getDirection() == null ? Direction.Both : input.getDirection();
    List<AclPortStats> lstAclInterfaceStats = AclLiveStatisticsHelper.getAclPortStats(direction, input.getInterfaceNames(), this.odlDirectStatsService, this.dataBroker);
    GetAclPortStatisticsOutputBuilder output = new GetAclPortStatisticsOutputBuilder().setAclPortStats(lstAclInterfaceStats);
    rpcResultBuilder = RpcResultBuilder.success();
    rpcResultBuilder.withResult(output.build());
    return Futures.immediateFuture(rpcResultBuilder.build());
}
Also used : GetAclPortStatisticsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.GetAclPortStatisticsOutput) GetAclPortStatisticsOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.GetAclPortStatisticsOutputBuilder) AclPortStats(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.AclPortStats) Direction(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.Direction)

Example 3 with AclPortStats

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.AclPortStats in project netvirt by opendaylight.

the class AclLiveStatisticsRpcServiceTest method assertStatsOutput.

private void assertStatsOutput(RpcResult<GetAclPortStatisticsOutput> output, Direction inputDirection) {
    assertNotNull(output);
    GetAclPortStatisticsOutput aclPortStats = output.getResult();
    assertNotNull(aclPortStats);
    List<AclPortStats> lstAclPortStats = aclPortStats.getAclPortStats();
    assertNotNull(lstAclPortStats);
    assertFalse(lstAclPortStats.isEmpty());
    for (AclPortStats stats : lstAclPortStats) {
        List<AclDropStats> aclDropStats = stats.getAclDropStats();
        if (stats.getInterfaceName().equals(PORT_1)) {
            assertNotNull(aclDropStats);
            assertTrue(!aclDropStats.isEmpty());
            if (inputDirection == Direction.Both) {
                assertTrue(aclDropStats.size() == 2);
            } else {
                assertTrue(aclDropStats.size() == 1);
            }
            for (AclDropStats dropStats : aclDropStats) {
                if (inputDirection != Direction.Both) {
                    Assert.assertEquals(dropStats.getDirection(), inputDirection);
                }
                assertTrue(dropStats.getBytes().getDropCount().intValue() > 0);
                assertTrue(dropStats.getBytes().getInvalidDropCount().intValue() > 0);
                assertTrue(dropStats.getPackets().getDropCount().intValue() > 0);
                assertTrue(dropStats.getPackets().getInvalidDropCount().intValue() > 0);
            }
            assertNull(stats.getError());
        } else {
            // Other than port1, error is returned in the output
            assertNull(aclDropStats);
            assertNotNull(stats.getError());
        }
    }
}
Also used : GetAclPortStatisticsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.GetAclPortStatisticsOutput) AclDropStats(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.acl.port.stats.AclDropStats) AclPortStats(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.AclPortStats)

Example 4 with AclPortStats

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.AclPortStats in project netvirt by opendaylight.

the class AclLiveStatisticsHelper method addError.

/**
 * Adds the error.
 *
 * @param lstAclPortStats the lst acl port stats
 * @param aclStatsBuilder the acl stats builder
 * @param errMsg the error message
 */
private static void addError(List<AclPortStats> lstAclPortStats, AclPortStatsBuilder aclStatsBuilder, String errMsg) {
    aclStatsBuilder.setError(new ErrorBuilder().setErrorMessage(errMsg).build());
    lstAclPortStats.add(aclStatsBuilder.build());
}
Also used : ErrorBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.acl.port.stats.ErrorBuilder)

Aggregations

AclPortStats (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.AclPortStats)3 GetAclPortStatisticsOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.GetAclPortStatisticsOutput)2 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 Interface (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface)1 GetFlowStatisticsInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsInputBuilder)1 GetFlowStatisticsOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput)1 FlowCookie (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie)1 Match (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match)1 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)1 Direction (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.Direction)1 GetAclPortStatisticsOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.GetAclPortStatisticsOutputBuilder)1 AclPortStatsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.AclPortStatsBuilder)1 AclDropStats (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.acl.port.stats.AclDropStats)1 ErrorBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.acl.port.stats.ErrorBuilder)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1