Search in sources :

Example 1 with MeterStatsData

use of org.openkilda.messaging.info.stats.MeterStatsData in project open-kilda by telstra.

the class OfMeterStatsMapperTest method testToPortStatsDataV13.

@Test
public void testToPortStatsDataV13() {
    OFFactoryVer13 factory = new OFFactoryVer13();
    OFMeterBandStats bandStats = factory.meterBandStats(U64.of(bandPacketCount), U64.of(bandByteCount));
    OFMeterStats meterStats = factory.buildMeterStats().setMeterId(meterId).setByteInCount(// we will put meter byte/packet count
    U64.of(meterByteCount)).setPacketInCount(// but we will expect to get band byte/packet count
    U64.of(meterPacketCount)).setBandStats(Collections.singletonList(bandStats)).build();
    OFMeterStatsReply reply = factory.buildMeterStatsReply().setEntries(Collections.singletonList(meterStats)).build();
    MeterStatsData data = OfMeterStatsMapper.INSTANCE.toMeterStatsData(Collections.singletonList(reply), switchId);
    assertEquals(switchId, data.getSwitchId());
    assertEquals(1, data.getStats().size());
    MeterStatsEntry statsEntry = data.getStats().get(0);
    // expected band byte/packet count instead of
    assertEquals(bandByteCount, statsEntry.getByteInCount());
    // meter byte/packet count
    assertEquals(bandPacketCount, statsEntry.getPacketsInCount());
}
Also used : OFMeterBandStats(org.projectfloodlight.openflow.protocol.OFMeterBandStats) MeterStatsData(org.openkilda.messaging.info.stats.MeterStatsData) OFMeterStats(org.projectfloodlight.openflow.protocol.OFMeterStats) OFFactoryVer13(org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13) OFMeterStatsReply(org.projectfloodlight.openflow.protocol.OFMeterStatsReply) MeterStatsEntry(org.openkilda.messaging.info.stats.MeterStatsEntry) Test(org.junit.Test)

Example 2 with MeterStatsData

use of org.openkilda.messaging.info.stats.MeterStatsData in project open-kilda by telstra.

the class StatsTopologyTest method meterSystemRulesStatsTest.

@Test
public void meterSystemRulesStatsTest() {
    long meterId = MeterId.createMeterIdForDefaultRule(VERIFICATION_BROADCAST_RULE_COOKIE).getValue();
    MeterStatsEntry meterStats = new MeterStatsEntry(meterId, 400L, 500L);
    sendStatsMessage(new MeterStatsData(SWITCH_ID_1, Collections.singletonList(meterStats)));
    List<Datapoint> datapoints = pollDatapoints(3);
    Map<String, Datapoint> datapointMap = createDatapointMap(datapoints);
    assertEquals(meterStats.getPacketsInCount(), datapointMap.get(METRIC_PREFIX + "switch.flow.system.meter.packets").getValue().longValue());
    assertEquals(meterStats.getByteInCount(), datapointMap.get(METRIC_PREFIX + "switch.flow.system.meter.bytes").getValue().longValue());
    assertEquals(meterStats.getByteInCount() * 8, datapointMap.get(METRIC_PREFIX + "switch.flow.system.meter.bits").getValue().longValue());
    datapoints.forEach(datapoint -> {
        assertEquals(3, datapoint.getTags().size());
        assertEquals(SWITCH_ID_1.toOtsdFormat(), datapoint.getTags().get("switchid"));
        assertEquals(String.valueOf(meterId), datapoint.getTags().get("meterid"));
        assertEquals(Cookie.toString(VERIFICATION_BROADCAST_RULE_COOKIE), datapoint.getTags().get("cookieHex"));
        assertEquals(timestamp, datapoint.getTime().longValue());
    });
}
Also used : MeterStatsData(org.openkilda.messaging.info.stats.MeterStatsData) Datapoint(org.openkilda.messaging.info.Datapoint) MeterStatsEntry(org.openkilda.messaging.info.stats.MeterStatsEntry) AbstractStormTest(org.openkilda.wfm.AbstractStormTest) Test(org.junit.Test)

Example 3 with MeterStatsData

use of org.openkilda.messaging.info.stats.MeterStatsData in project open-kilda by telstra.

the class StatsTopologyTest method meterFlowRulesStatsTest.

@Test
public void meterFlowRulesStatsTest() {
    Flow flow = createOneSwitchFlow(SWITCH_ID_1);
    FlowPath flowPath = flow.getForwardPath();
    sendUpdateFlowPathInfo(flowPath);
    MeterStatsEntry meterStats = new MeterStatsEntry(flowPath.getMeterId().getValue(), 500L, 700L);
    sendStatsMessage(new MeterStatsData(SWITCH_ID_1, Collections.singletonList(meterStats)));
    List<Datapoint> datapoints = pollDatapoints(3);
    Map<String, Datapoint> datapointMap = createDatapointMap(datapoints);
    assertEquals(meterStats.getPacketsInCount(), datapointMap.get(METRIC_PREFIX + "flow.meter.packets").getValue().longValue());
    assertEquals(meterStats.getByteInCount(), datapointMap.get(METRIC_PREFIX + "flow.meter.bytes").getValue().longValue());
    assertEquals(meterStats.getByteInCount() * 8, datapointMap.get(METRIC_PREFIX + "flow.meter.bits").getValue().longValue());
    datapoints.forEach(datapoint -> {
        assertEquals(6, datapoint.getTags().size());
        assertEquals(SWITCH_ID_1.toOtsdFormat(), datapoint.getTags().get("switchid"));
        assertEquals(String.valueOf(flowPath.getMeterId().getValue()), datapoint.getTags().get("meterid"));
        assertEquals("forward", datapoint.getTags().get("direction"));
        assertEquals("false", datapoint.getTags().get("is_y_flow_subflow"));
        assertEquals(flowId, datapoint.getTags().get("flowid"));
        assertEquals(String.valueOf(flowPath.getCookie().getValue()), datapoint.getTags().get("cookie"));
        assertEquals(timestamp, datapoint.getTime().longValue());
    });
}
Also used : MeterStatsData(org.openkilda.messaging.info.stats.MeterStatsData) Datapoint(org.openkilda.messaging.info.Datapoint) FlowPath(org.openkilda.model.FlowPath) MeterStatsEntry(org.openkilda.messaging.info.stats.MeterStatsEntry) Flow(org.openkilda.model.Flow) AbstractStormTest(org.openkilda.wfm.AbstractStormTest) Test(org.junit.Test)

Example 4 with MeterStatsData

use of org.openkilda.messaging.info.stats.MeterStatsData in project open-kilda by telstra.

the class SpeakerStatsRouterBolt method handleInput.

@Override
protected void handleInput(Tuple tuple) throws Exception {
    log.debug("Ingoing tuple: {}", tuple);
    if (active) {
        Message message = pullValue(tuple, FIELD_ID_PAYLOAD, Message.class);
        if (!(message instanceof InfoMessage)) {
            return;
        }
        InfoMessage infoMessage = (InfoMessage) message;
        final InfoData data = infoMessage.getData();
        if (data instanceof PortStatsData) {
            log.debug("Port stats message: {}", infoMessage);
            emitWithContext(PORT_STATS_STREAM, tuple, new Values(infoMessage));
        } else if (data instanceof MeterConfigStatsData) {
            log.debug("Meter config stats message: {}", infoMessage);
            emitWithContext(METER_CFG_STATS_STREAM, tuple, new Values(infoMessage));
        } else if (data instanceof MeterStatsData) {
            log.debug("Meter stats message: {}", infoMessage);
            emitWithContext(TO_CACHE_STREAM, tuple, new Values(data));
        } else if (data instanceof FlowStatsData) {
            log.debug("Flow stats message: {}", infoMessage);
            ImmutablePair<FlowStatsData, FlowStatsData> splitData = splitSystemRuleStatsAndFlowStats((FlowStatsData) data);
            emitWithContext(SYSTEM_RULES_STATS_STREAM, tuple, new Values(splitData.getKey()));
            emitWithContext(TO_CACHE_STREAM, tuple, new Values(splitData.getValue()));
        } else if (data instanceof SwitchTableStatsData) {
            log.debug("Table stats message: {}", infoMessage);
            emitWithContext(TABLE_STATS_STREAM, tuple, new Values(data));
        } else if (data instanceof GetPacketInOutStatsResponse) {
            log.debug("Packet in out stats message: {}", infoMessage);
            emitWithContext(PACKET_IN_OUT_STATS_STREAM, tuple, new Values(data));
        } else {
        // FIXME (ncherevko): we might receive few unexpected messages here,
        // need to fix it and uncomment below line
        // unhandledInput(tuple);
        }
    }
}
Also used : MeterStatsData(org.openkilda.messaging.info.stats.MeterStatsData) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) GetPacketInOutStatsResponse(org.openkilda.messaging.info.grpc.GetPacketInOutStatsResponse) MeterConfigStatsData(org.openkilda.messaging.info.stats.MeterConfigStatsData) FlowStatsData(org.openkilda.messaging.info.stats.FlowStatsData) InfoMessage(org.openkilda.messaging.info.InfoMessage) InfoData(org.openkilda.messaging.info.InfoData) Values(org.apache.storm.tuple.Values) PortStatsData(org.openkilda.messaging.info.stats.PortStatsData) SwitchTableStatsData(org.openkilda.messaging.info.stats.SwitchTableStatsData)

Example 5 with MeterStatsData

use of org.openkilda.messaging.info.stats.MeterStatsData in project open-kilda by telstra.

the class KildaEntryCacheServiceTest method shouldCacheServiceRefreshMeterCache.

@Test
public void shouldCacheServiceRefreshMeterCache() {
    Flow flow = buildFlow();
    when(flowRepository.findAll()).thenReturn(Collections.singletonList(flow));
    service.refreshCache();
    MeterStatsData statsOriginSrc = getMeterStatsDataSrcSwitch();
    service.completeAndForwardMeterStats(statsOriginSrc);
    final MeterId forwardMeterId = flow.getForwardPath().getMeterId();
    @SuppressWarnings({ "ConstantConditions" }) final MeterId forwardProtectedMeterId = flow.getProtectedForwardPath().getMeterId();
    verify(carrier, atLeastOnce()).emitMeterStats(meterCacheCaptor.capture());
    List<MeterStatsAndDescriptor> statsEntries = meterCacheCaptor.getValue().getStatsEntries();
    assertDescriptionPopulation(statsEntries, statsOriginSrc.getStats().size(), 2);
    assertMeterCache(statsEntries, forwardMeterId.getValue(), new CommonFlowDescriptor(flow.getSrcSwitchId(), INGRESS, flow.getFlowId(), flow.getForwardPath().getCookie(), forwardMeterId));
    assertMeterCache(statsEntries, forwardProtectedMeterId.getValue(), new CommonFlowDescriptor(flow.getSrcSwitchId(), INGRESS, flow.getFlowId(), flow.getProtectedForwardPath().getCookie(), forwardProtectedMeterId));
    MeterStatsData statsOriginDst = getMeterStatsDataDstSwitch();
    service.completeAndForwardMeterStats(statsOriginDst);
    verify(carrier, atLeastOnce()).emitMeterStats(meterCacheCaptor.capture());
    statsEntries = meterCacheCaptor.getValue().getStatsEntries();
    assertDescriptionPopulation(statsEntries, statsOriginDst.getStats().size(), 2);
    final MeterId reverseMeterId = flow.getReversePath().getMeterId();
    assertMeterCache(statsEntries, reverseMeterId.getValue(), new CommonFlowDescriptor(flow.getDestSwitchId(), INGRESS, flow.getFlowId(), flow.getReversePath().getCookie(), reverseMeterId));
    final MeterId reverseProtectedMeterId = flow.getProtectedReversePath().getMeterId();
    assertMeterCache(statsEntries, reverseProtectedMeterId.getValue(), new CommonFlowDescriptor(flow.getDestSwitchId(), INGRESS, flow.getFlowId(), flow.getProtectedReversePath().getCookie(), reverseProtectedMeterId));
}
Also used : MeterStatsData(org.openkilda.messaging.info.stats.MeterStatsData) MeterStatsAndDescriptor(org.openkilda.wfm.topology.stats.model.MeterStatsAndDescriptor) CommonFlowDescriptor(org.openkilda.wfm.topology.stats.model.CommonFlowDescriptor) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) MeterId(org.openkilda.model.MeterId) Test(org.junit.Test)

Aggregations

MeterStatsData (org.openkilda.messaging.info.stats.MeterStatsData)9 Test (org.junit.Test)8 MeterStatsEntry (org.openkilda.messaging.info.stats.MeterStatsEntry)5 Flow (org.openkilda.model.Flow)5 YFlow (org.openkilda.model.YFlow)4 MeterStatsAndDescriptor (org.openkilda.wfm.topology.stats.model.MeterStatsAndDescriptor)4 Datapoint (org.openkilda.messaging.info.Datapoint)3 FlowPath (org.openkilda.model.FlowPath)3 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)3 CommonFlowDescriptor (org.openkilda.wfm.topology.stats.model.CommonFlowDescriptor)3 UpdateFlowPathInfo (org.openkilda.messaging.info.stats.UpdateFlowPathInfo)2 MeterId (org.openkilda.model.MeterId)2 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 Values (org.apache.storm.tuple.Values)1 Message (org.openkilda.messaging.Message)1 InfoData (org.openkilda.messaging.info.InfoData)1 InfoMessage (org.openkilda.messaging.info.InfoMessage)1 GetPacketInOutStatsResponse (org.openkilda.messaging.info.grpc.GetPacketInOutStatsResponse)1 FlowStatsData (org.openkilda.messaging.info.stats.FlowStatsData)1 MeterConfigStatsData (org.openkilda.messaging.info.stats.MeterConfigStatsData)1