Search in sources :

Example 1 with GetFlowStatisticsOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput 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 GetFlowStatisticsOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput in project openflowplugin by opendaylight.

the class FlowDirectStatisticsServiceTest method testBuildReply.

@Override
public void testBuildReply() throws Exception {
    final MultipartReply reply = mock(MultipartReply.class);
    final MultipartReplyFlowCase flowCase = mock(MultipartReplyFlowCase.class);
    final MultipartReplyFlow flow = mock(MultipartReplyFlow.class);
    final FlowStats flowStat = new FlowStatsBuilder().setDurationSec(1L).setDurationNsec(1L).setTableId(TABLE_NO).setByteCount(BigInteger.ONE).setPacketCount(BigInteger.ONE).setFlags(mock(FlowModFlags.class)).setMatch(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder().setMatchEntry(Collections.emptyList()).build()).build();
    final List<FlowStats> flowStats = Collections.singletonList(flowStat);
    final List<MultipartReply> input = Collections.singletonList(reply);
    when(flow.getFlowStats()).thenReturn(flowStats);
    when(flowCase.getMultipartReplyFlow()).thenReturn(flow);
    when(reply.getMultipartReplyBody()).thenReturn(flowCase);
    final GetFlowStatisticsOutput output = service.buildReply(input, true);
    assertTrue(output.getFlowAndStatisticsMapList().size() > 0);
    final FlowAndStatisticsMap stats = output.getFlowAndStatisticsMapList().get(0);
    assertEquals(stats.getTableId(), TABLE_NO);
}
Also used : FlowModFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags) MultipartReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply) FlowAndStatisticsMap(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowAndStatisticsMap) MultipartReplyFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow) MultipartReplyFlowCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase) FlowStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats) FlowStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStatsBuilder) GetFlowStatisticsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)

Example 3 with GetFlowStatisticsOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput in project openflowplugin by opendaylight.

the class OpendaylightDirectStatisticsServiceImplTest method testGetFlowStatisticsFail.

@Test
public void testGetFlowStatisticsFail() throws Exception {
    RpcResult<GetFlowStatisticsOutput> result = emptyService.getFlowStatistics(getFlowStatisticsInput).get();
    assertFalse(result.isSuccessful());
    for (RpcError error : result.getErrors()) {
        assertTrue(error.getMessage().contains(AbstractFlowDirectStatisticsService.class.getSimpleName()));
    }
    verify(flowDirectStatisticsService, times(0)).handleAndReply(getFlowStatisticsInput);
}
Also used : RpcError(org.opendaylight.yangtools.yang.common.RpcError) GetFlowStatisticsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput) Test(org.junit.Test)

Example 4 with GetFlowStatisticsOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput in project openflowplugin by opendaylight.

the class FlowDirectStatisticsServiceTest method testBuildReply.

@Override
public void testBuildReply() throws Exception {
    final FlowAndStatisticsMapList flowStat = new FlowAndStatisticsMapListBuilder().setDuration(new DurationBuilder().setSecond(new Counter32(1L)).setNanosecond(new Counter32(1L)).build()).setTableId(TABLE_NO).setByteCount(new Counter64(BigInteger.ONE)).setPacketCount(new Counter64(BigInteger.ONE)).setFlags(new FlowModFlags(true, false, false, false, false)).setMatch(new MatchBuilder().build()).build();
    final MultipartReply reply = new MultipartReplyBuilder().setMultipartReplyBody(new MultipartReplyFlowStatsBuilder().setFlowAndStatisticsMapList(Collections.singletonList(flowStat)).build()).build();
    final List<MultipartReply> input = Collections.singletonList(reply);
    final GetFlowStatisticsOutput output = service.buildReply(input, true);
    assertTrue(output.getFlowAndStatisticsMapList().size() > 0);
    final FlowAndStatisticsMap stats = output.getFlowAndStatisticsMapList().get(0);
    assertEquals(stats.getTableId(), TABLE_NO);
}
Also used : FlowModFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags) MultipartReply(org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReply) FlowAndStatisticsMap(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowAndStatisticsMap) FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) FlowAndStatisticsMapListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder) Counter32(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32) Counter64(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64) MultipartReplyFlowStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.multipart.reply.multipart.reply.body.MultipartReplyFlowStatsBuilder) MultipartReplyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReplyBuilder) GetFlowStatisticsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) DurationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.duration.DurationBuilder)

Example 5 with GetFlowStatisticsOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput in project netvirt by opendaylight.

the class CounterRetriever method getSwitchFlowCountersDirect.

public CounterResultDataStructure getSwitchFlowCountersDirect(BigInteger dpId, Match match) {
    NodeRef nodeRef = new NodeRef(InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(new NodeId(CountersUtils.getNodeId(dpId)))).toInstance());
    GetFlowStatisticsInputBuilder gfsib = new GetFlowStatisticsInputBuilder();
    gfsib.setNode(nodeRef);
    gfsib.setMatch(match);
    gfsib.setStoreStats(false);
    Future<RpcResult<GetFlowStatisticsOutput>> rpcResultFuture = odlDirectStatsService.getFlowStatistics(gfsib.build());
    RpcResult<GetFlowStatisticsOutput> rpcResult = null;
    try {
        rpcResult = rpcResultFuture.get();
    } catch (InterruptedException | ExecutionException e) {
        counters.failedGettingFlowCounters.inc();
        LOG.warn("Unable to retrieve flow counters for match {}", match);
        return null;
    }
    if (rpcResult != null && rpcResult.isSuccessful() && rpcResult.getResult() != null) {
        GetFlowStatisticsOutput flowStatsOutput = rpcResult.getResult();
        return createSwitchFlowResultMapDirect(flowStatsOutput);
    } else {
        counters.failedGettingFlowCounters.inc();
        LOG.warn("Unable to retrieve flow counters for match {}", match);
        return null;
    }
}
Also used : NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) GetFlowStatisticsInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsInputBuilder) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) GetFlowStatisticsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput) ExecutionException(java.util.concurrent.ExecutionException) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)

Aggregations

GetFlowStatisticsOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput)9 FlowAndStatisticsMapList (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList)8 ArrayList (java.util.ArrayList)4 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)4 BigInteger (java.math.BigInteger)3 GetFlowStatisticsInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsInputBuilder)3 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)3 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)3 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 GetFlowStatisticsOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutputBuilder)2 FlowAndStatisticsMap (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowAndStatisticsMap)2 NodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)2 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)2 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)2 Optional (com.google.common.base.Optional)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 JdkFutureAdapters (com.google.common.util.concurrent.JdkFutureAdapters)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1