use of org.openkilda.messaging.info.stats.MeterStatsEntry 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.MeterStatsEntry 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.MeterStatsEntry 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.MeterStatsEntry in project open-kilda by telstra.
the class KildaEntryCacheService method completeAndForwardMeterStats.
/**
* Process the provided {@link MeterStatsData} by completing it with cached data and forwarding it.
*
* @param data the data to process.
*/
public void completeAndForwardMeterStats(MeterStatsData data) {
SwitchMeterStats stats = new SwitchMeterStats(data.getSwitchId());
for (MeterStatsEntry entry : data.getStats()) {
MeterCacheKey key = new MeterCacheKey(data.getSwitchId(), entry.getMeterId());
stats.add(entry, switchAndMeterToFlow.get(key));
}
carrier.emitMeterStats(stats);
}
use of org.openkilda.messaging.info.stats.MeterStatsEntry in project open-kilda by telstra.
the class StatsTopologyTest method lldpMeterStatsTest.
@Test
public void lldpMeterStatsTest() {
long lldpMeterId = MeterId.MIN_FLOW_METER_ID;
MeterStatsEntry meterStats = new MeterStatsEntry(lldpMeterId, 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 + "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(5, datapoint.getTags().size());
assertEquals(SWITCH_ID_1.toOtsdFormat(), datapoint.getTags().get("switchid"));
assertEquals(String.valueOf(lldpMeterId), datapoint.getTags().get("meterid"));
assertEquals("unknown", datapoint.getTags().get("direction"));
assertEquals("unknown", datapoint.getTags().get("cookie"));
assertEquals("unknown", datapoint.getTags().get("flowid"));
assertEquals(timestamp, datapoint.getTime().longValue());
});
}
Aggregations