@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(U64.of(meterByteCount)) .setPacketInCount(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); assertEquals(bandByteCount, statsEntry.getByteInCount()); assertEquals(bandPacketCount, statsEntry.getPacketsInCount()); }
public MeterStatsData toMeterStatsData(List<OFMeterStatsReply> data, SwitchId switchId) { try { List<MeterStatsEntry> stats = data.stream() .flatMap(reply -> reply.getEntries().stream()) .map(this::toMeterStatsEntry) .filter(Objects::nonNull) .collect(toList()); return new MeterStatsData(switchId, stats); } catch (NullPointerException | UnsupportedOperationException | IllegalArgumentException e) { log.error(String.format("Could not convert meter stats data %s on switch %s", data, switchId), e); return null; } }
OfMeterStatsMapper { public MeterStatsData toMeterStatsData(List<OFMeterStatsReply> data, SwitchId switchId) { try { List<MeterStatsEntry> stats = data.stream() .flatMap(reply -> reply.getEntries().stream()) .map(this::toMeterStatsEntry) .filter(Objects::nonNull) .collect(toList()); return new MeterStatsData(switchId, stats); } catch (NullPointerException | UnsupportedOperationException | IllegalArgumentException e) { log.error(String.format("Could not convert meter stats data %s on switch %s", data, switchId), e); return null; } } }
OfMeterStatsMapper { public MeterStatsData toMeterStatsData(List<OFMeterStatsReply> data, SwitchId switchId) { try { List<MeterStatsEntry> stats = data.stream() .flatMap(reply -> reply.getEntries().stream()) .map(this::toMeterStatsEntry) .filter(Objects::nonNull) .collect(toList()); return new MeterStatsData(switchId, stats); } catch (NullPointerException | UnsupportedOperationException | IllegalArgumentException e) { log.error(String.format("Could not convert meter stats data %s on switch %s", data, switchId), e); return null; } }  }
OfMeterStatsMapper { public MeterStatsData toMeterStatsData(List<OFMeterStatsReply> data, SwitchId switchId) { try { List<MeterStatsEntry> stats = data.stream() .flatMap(reply -> reply.getEntries().stream()) .map(this::toMeterStatsEntry) .filter(Objects::nonNull) .collect(toList()); return new MeterStatsData(switchId, stats); } catch (NullPointerException | UnsupportedOperationException | IllegalArgumentException e) { log.error(String.format("Could not convert meter stats data %s on switch %s", data, switchId), e); return null; } }  MeterStatsData toMeterStatsData(List<OFMeterStatsReply> data, SwitchId switchId); MeterStatsEntry toMeterStatsEntry(OFMeterStats entry); }
OfMeterStatsMapper { public MeterStatsData toMeterStatsData(List<OFMeterStatsReply> data, SwitchId switchId) { try { List<MeterStatsEntry> stats = data.stream() .flatMap(reply -> reply.getEntries().stream()) .map(this::toMeterStatsEntry) .filter(Objects::nonNull) .collect(toList()); return new MeterStatsData(switchId, stats); } catch (NullPointerException | UnsupportedOperationException | IllegalArgumentException e) { log.error(String.format("Could not convert meter stats data %s on switch %s", data, switchId), e); return null; } }  MeterStatsData toMeterStatsData(List<OFMeterStatsReply> data, SwitchId switchId); MeterStatsEntry toMeterStatsEntry(OFMeterStats entry); static final OfMeterStatsMapper INSTANCE; }