Search in sources :

Example 11 with GetNodeConnectorStatisticsOutput

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

the class NodeConnectorDirectStatisticsServiceTest method testBuildReply.

@Override
public void testBuildReply() throws Exception {
    final MultipartReply reply = mock(MultipartReply.class);
    final MultipartReplyPortStatsCase nodeConnectorCase = mock(MultipartReplyPortStatsCase.class);
    final MultipartReplyPortStats nodeConnector = mock(MultipartReplyPortStats.class);
    final PortStats nodeConnectorStat = mock(PortStats.class);
    final List<PortStats> nodeConnectorStats = Collections.singletonList(nodeConnectorStat);
    final List<MultipartReply> input = Collections.singletonList(reply);
    when(nodeConnector.getPortStats()).thenReturn(nodeConnectorStats);
    when(nodeConnectorCase.getMultipartReplyPortStats()).thenReturn(nodeConnector);
    when(reply.getMultipartReplyBody()).thenReturn(nodeConnectorCase);
    when(nodeConnectorStat.getPortNo()).thenReturn(PORT_NO);
    when(nodeConnectorStat.getTxBytes()).thenReturn(BigInteger.ONE);
    when(nodeConnectorStat.getCollisions()).thenReturn(BigInteger.ONE);
    when(nodeConnectorStat.getRxBytes()).thenReturn(BigInteger.ONE);
    when(nodeConnectorStat.getRxCrcErr()).thenReturn(BigInteger.ONE);
    when(nodeConnectorStat.getRxDropped()).thenReturn(BigInteger.ONE);
    when(nodeConnectorStat.getRxErrors()).thenReturn(BigInteger.ONE);
    when(nodeConnectorStat.getRxFrameErr()).thenReturn(BigInteger.ONE);
    when(nodeConnectorStat.getRxOverErr()).thenReturn(BigInteger.ONE);
    when(nodeConnectorStat.getRxPackets()).thenReturn(BigInteger.ONE);
    when(nodeConnectorStat.getTxDropped()).thenReturn(BigInteger.ONE);
    when(nodeConnectorStat.getTxErrors()).thenReturn(BigInteger.ONE);
    final GetNodeConnectorStatisticsOutput output = service.buildReply(input, true);
    assertTrue(output.getNodeConnectorStatisticsAndPortNumberMap().size() > 0);
    final NodeConnectorStatisticsAndPortNumberMap stats = output.getNodeConnectorStatisticsAndPortNumberMap().get(0);
    assertEquals(stats.getNodeConnectorId(), nodeConnectorId);
}
Also used : MultipartReplyPortStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.MultipartReplyPortStats) MultipartReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply) MultipartReplyPortStatsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCase) GetNodeConnectorStatisticsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetNodeConnectorStatisticsOutput) MultipartRequestPortStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.port.stats._case.MultipartRequestPortStats) MultipartReplyPortStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.MultipartReplyPortStats) PortStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.multipart.reply.port.stats.PortStats) NodeConnectorStatisticsAndPortNumberMap(org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap)

Example 12 with GetNodeConnectorStatisticsOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetNodeConnectorStatisticsOutput in project genius by opendaylight.

the class NodeConnectorStatsImpl method processNodeConnectorStatistics.

/**
 * This method processes NodeConnectorStatistics RPC result.
 * It performs:
 * - fetches various OF Port counters values
 * - creates/updates new OF Port counters using Infrautils metrics API
 * - set counter with values fetched from NodeConnectorStatistics
 */
private void processNodeConnectorStatistics(GetNodeConnectorStatisticsOutput nodeConnectorStatisticsOutput, BigInteger dpid) {
    String port = "";
    String portUuid = "";
    List<NodeConnectorStatisticsAndPortNumberMap> ncStatsAndPortMapList = nodeConnectorStatisticsOutput.getNodeConnectorStatisticsAndPortNumberMap();
    // Parse NodeConnectorStatistics and create/update counters for them
    for (NodeConnectorStatisticsAndPortNumberMap ncStatsAndPortMap : ncStatsAndPortMapList) {
        NodeConnectorId nodeConnector = ncStatsAndPortMap.getNodeConnectorId();
        LOG.trace("Create/update metric counter for NodeConnector: {} of node: {}", nodeConnector, dpid.toString());
        port = nodeConnector.getValue();
        // update port name as per port name maintained in portNameCache
        String portNameInCache = "openflow" + ":" + dpid.toString() + ":" + port;
        java.util.Optional<String> portName = portNameCache.get(portNameInCache);
        if (portName.isPresent()) {
            Optional<List<InterfaceChildEntry>> interfaceChildEntries = interfaceChildCache.getInterfaceChildEntries(portName.get());
            if (interfaceChildEntries.isPresent()) {
                if (!interfaceChildEntries.get().isEmpty()) {
                    portUuid = interfaceChildEntries.get().get(0).getChildInterface();
                    LOG.trace("Retrieved portUuid {} for portname {}", portUuid, portName.get());
                } else {
                    LOG.trace("PortUuid is not found for portname {}. Skipping IFM counters publish for this port.", portName.get());
                    continue;
                }
            } else {
                LOG.trace("PortUuid is not found for portname {}. Skipping IFM counters publish for this port.", portName.get());
                continue;
            }
        }
        Counter counter = getCounter(CounterConstants.IFM_PORT_COUNTER_OFPORT_DURATION, dpid, port, portUuid, null);
        long ofPortDuration = ncStatsAndPortMap.getDuration().getSecond().getValue();
        updateCounter(counter, ofPortDuration);
        counter = getCounter(CounterConstants.IFM_PORT_COUNTER_OFPORT_PKT_RECVDROP, dpid, port, portUuid, null);
        long packetsPerOFPortReceiveDrop = ncStatsAndPortMap.getReceiveDrops().longValue();
        updateCounter(counter, packetsPerOFPortReceiveDrop);
        counter = getCounter(CounterConstants.IFM_PORT_COUNTER_OFPORT_PKT_RECVERROR, dpid, port, portUuid, null);
        long packetsPerOFPortReceiveError = ncStatsAndPortMap.getReceiveErrors().longValue();
        updateCounter(counter, packetsPerOFPortReceiveError);
        counter = getCounter(CounterConstants.IFM_PORT_COUNTER_OFPORT_PKT_SENT, dpid, port, portUuid, null);
        long packetsPerOFPortSent = ncStatsAndPortMap.getPackets().getTransmitted().longValue();
        updateCounter(counter, packetsPerOFPortSent);
        counter = getCounter(CounterConstants.IFM_PORT_COUNTER_OFPORT_PKT_RECV, dpid, port, portUuid, null);
        long packetsPerOFPortReceive = ncStatsAndPortMap.getPackets().getReceived().longValue();
        updateCounter(counter, packetsPerOFPortReceive);
        counter = getCounter(CounterConstants.IFM_PORT_COUNTER_OFPORT_BYTE_SENT, dpid, port, portUuid, null);
        long bytesPerOFPortSent = ncStatsAndPortMap.getBytes().getTransmitted().longValue();
        updateCounter(counter, bytesPerOFPortSent);
        counter = getCounter(CounterConstants.IFM_PORT_COUNTER_OFPORT_BYTE_RECV, dpid, port, portUuid, null);
        long bytesPerOFPortReceive = ncStatsAndPortMap.getBytes().getReceived().longValue();
        updateCounter(counter, bytesPerOFPortReceive);
    }
}
Also used : Counter(org.opendaylight.infrautils.metrics.Counter) NodeConnectorId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId) List(java.util.List) FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) NodeConnectorStatisticsAndPortNumberMap(org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap)

Aggregations

GetNodeConnectorStatisticsOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetNodeConnectorStatisticsOutput)8 NodeConnectorStatisticsAndPortNumberMap (org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap)8 ExecutionException (java.util.concurrent.ExecutionException)3 NodeConnectorId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId)3 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 GetNodeConnectorStatisticsInput (org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetNodeConnectorStatisticsInput)2 MultipartReply (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply)2 MultipartReplyPortStatsCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCase)2 MultipartReplyPortStats (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.MultipartReplyPortStats)2 PortStats (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.multipart.reply.port.stats.PortStats)2 NodeConnectorStatisticsAndPortNumberMapBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMapBuilder)2 BigInteger (java.math.BigInteger)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 TimeoutException (java.util.concurrent.TimeoutException)1 Counter (org.opendaylight.infrautils.metrics.Counter)1 Counter32 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32)1