use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder in project openflowplugin by opendaylight.
the class FlowStatsResponseConvertor method convert.
@Override
public List<FlowAndStatisticsMapList> convert(List<FlowStats> source, FlowStatsResponseConvertorData data) {
final List<FlowAndStatisticsMapList> result = new ArrayList<>();
for (FlowStats flowStats : source) {
// Convert Openflow switch specific flow statistics to the MD-SAL format flow statistics
FlowAndStatisticsMapListBuilder salFlowStatsBuilder = new FlowAndStatisticsMapListBuilder();
salFlowStatsBuilder.setByteCount(new Counter64(flowStats.getByteCount()));
if (flowStats.getCookie() != null) {
salFlowStatsBuilder.setCookie(new FlowCookie(flowStats.getCookie()));
}
DurationBuilder time = new DurationBuilder();
time.setSecond(new Counter32(flowStats.getDurationSec()));
time.setNanosecond(new Counter32(flowStats.getDurationNsec()));
salFlowStatsBuilder.setDuration(time.build());
salFlowStatsBuilder.setHardTimeout(flowStats.getHardTimeout());
salFlowStatsBuilder.setIdleTimeout(flowStats.getIdleTimeout());
salFlowStatsBuilder.setPacketCount(new Counter64(flowStats.getPacketCount()));
salFlowStatsBuilder.setPriority(flowStats.getPriority());
salFlowStatsBuilder.setTableId(flowStats.getTableId());
Short ipProtocol = null;
if (flowStats.getMatchV10() != null) {
final Optional<MatchBuilder> matchBuilderOptional = getConvertorExecutor().convert(flowStats.getMatchV10(), data);
if (matchBuilderOptional.isPresent()) {
if (Objects.nonNull(matchBuilderOptional.get().getIpMatch())) {
ipProtocol = matchBuilderOptional.get().getIpMatch().getIpProtocol();
}
salFlowStatsBuilder.setMatch(matchBuilderOptional.get().build());
}
if (flowStats.getAction() != null && flowStats.getAction().size() != 0) {
salFlowStatsBuilder.setInstructions(wrapOF10ActionsToInstruction(flowStats.getAction(), data.getVersion(), ipProtocol));
}
}
if (flowStats.getMatch() != null) {
final Optional<MatchBuilder> matchBuilderOptional = getConvertorExecutor().convert(flowStats.getMatch(), data);
if (matchBuilderOptional.isPresent()) {
final MatchBuilder matchBuilder = matchBuilderOptional.get();
final AugmentTuple<Match> matchExtensionWrap = MatchExtensionHelper.processAllExtensions(flowStats.getMatch().getMatchEntry(), OpenflowVersion.get(data.getVersion()), data.getMatchPath());
if (matchExtensionWrap != null) {
matchBuilder.addAugmentation(matchExtensionWrap.getAugmentationClass(), matchExtensionWrap.getAugmentationObject());
}
salFlowStatsBuilder.setMatch(matchBuilder.build());
}
salFlowStatsBuilder.setFlags(new FlowModFlags(flowStats.getFlags().isOFPFFCHECKOVERLAP(), flowStats.getFlags().isOFPFFRESETCOUNTS(), flowStats.getFlags().isOFPFFNOPKTCOUNTS(), flowStats.getFlags().isOFPFFNOBYTCOUNTS(), flowStats.getFlags().isOFPFFSENDFLOWREM()));
}
if (flowStats.getInstruction() != null) {
final VersionConvertorData simpleConvertorData = new VersionConvertorData(data.getVersion());
final Optional<Instructions> instructions = getConvertorExecutor().convert(flowStats.getInstruction(), simpleConvertorData);
salFlowStatsBuilder.setInstructions(instructions.orElse(new InstructionsBuilder().setInstruction(Collections.emptyList()).build()));
}
result.add(salFlowStatsBuilder.build());
}
return result;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder in project openflowplugin by opendaylight.
the class FlowStatNotificationSupplierImpl method createNotification.
@Override
public FlowsStatisticsUpdate createNotification(final FlowStatistics flowStatistics, final InstanceIdentifier<FlowStatistics> path) {
Preconditions.checkArgument(flowStatistics != null);
Preconditions.checkArgument(path != null);
final FlowAndStatisticsMapListBuilder fsmlBuilder = new FlowAndStatisticsMapListBuilder(flowStatistics);
fsmlBuilder.setFlowId(new FlowId(path.firstKeyOf(Flow.class, FlowKey.class).getId().getValue()));
final FlowsStatisticsUpdateBuilder builder = new FlowsStatisticsUpdateBuilder();
builder.setId(getNodeId(path));
builder.setMoreReplies(Boolean.FALSE);
// NOTE : fix if it needs, but we have to ask DataStore for the NodeConnector list
builder.setNodeConnector(Collections.<NodeConnector>emptyList());
builder.setFlowAndStatisticsMapList(Collections.singletonList(fsmlBuilder.build()));
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder in project openflowplugin by opendaylight.
the class StatisticsGatheringUtilsTest method prepareFlowStatisticsData.
private Iterable<FlowsStatisticsUpdate> prepareFlowStatisticsData() {
final FlowAndStatisticsMapListBuilder flowAndStatsMapListBld = new FlowAndStatisticsMapListBuilder();
flowAndStatsMapListBld.setTableId((short) 42);
flowAndStatsMapListBld.setMatch(new MatchBuilder().build());
final FlowsStatisticsUpdateBuilder flowStatsUpdateBld1 = new FlowsStatisticsUpdateBuilder();
flowStatsUpdateBld1.setFlowAndStatisticsMapList(Lists.newArrayList(flowAndStatsMapListBld.build()));
return Lists.newArrayList(flowStatsUpdateBld1.build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder in project openflowplugin by opendaylight.
the class FlowDirectStatisticsServiceTest method testBuildReply.
@Override
public void testBuildReply() throws Exception {
final FlowAndStatisticsMapList flowStat = new FlowAndStatisticsMapListBuilder().setDuration(new DurationBuilder().setSecond(new Counter32(1L)).setNanosecond(new Counter32(1L)).build()).setTableId(TABLE_NO).setByteCount(new Counter64(BigInteger.ONE)).setPacketCount(new Counter64(BigInteger.ONE)).setFlags(new FlowModFlags(true, false, false, false, false)).setMatch(new MatchBuilder().build()).build();
final MultipartReply reply = new MultipartReplyBuilder().setMultipartReplyBody(new MultipartReplyFlowStatsBuilder().setFlowAndStatisticsMapList(Collections.singletonList(flowStat)).build()).build();
final List<MultipartReply> input = Collections.singletonList(reply);
final GetFlowStatisticsOutput output = service.buildReply(input, true);
assertTrue(output.getFlowAndStatisticsMapList().size() > 0);
final FlowAndStatisticsMap stats = output.getFlowAndStatisticsMapList().get(0);
assertEquals(stats.getTableId(), TABLE_NO);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder in project openflowplugin by opendaylight.
the class FlowRegistryKeyFactoryTest method testEqualsNegative.
@Test
public void testEqualsNegative() throws Exception {
final FlowAndStatisticsMapList flowStatisticsMapList1 = TestFlowHelper.createFlowAndStatisticsMapListBuilder(1).build();
final FlowRegistryKey key1 = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flowStatisticsMapList1);
FlowRegistryKey key2;
FlowAndStatisticsMapListBuilder flowStatisticsMapListBld2;
// different priority
flowStatisticsMapListBld2 = new FlowAndStatisticsMapListBuilder(flowStatisticsMapList1);
flowStatisticsMapListBld2.setPriority(flowStatisticsMapListBld2.getPriority() + 1);
key2 = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flowStatisticsMapListBld2.build());
Assert.assertFalse(key1.equals(key2));
// different match
flowStatisticsMapListBld2 = new FlowAndStatisticsMapListBuilder(flowStatisticsMapList1);
flowStatisticsMapListBld2.setMatch(new MatchBuilder().build());
key2 = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flowStatisticsMapListBld2.build());
Assert.assertFalse(key1.equals(key2));
// different tableId
flowStatisticsMapListBld2 = new FlowAndStatisticsMapListBuilder(flowStatisticsMapList1);
flowStatisticsMapListBld2.setTableId((short) (flowStatisticsMapListBld2.getTableId() + 1));
key2 = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flowStatisticsMapListBld2.build());
Assert.assertFalse(key1.equals(key2));
Assert.assertFalse(key1.equals(null));
}
Aggregations