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());
}
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());
});
}
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());
});
}
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);
}
}
}
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));
}
Aggregations